added spdlog, started to dev on 3.0 now... still need to workout

relocs...
3.0
_xeroxz 3 years ago
parent e028a5877b
commit dd78f5309a

3
.gitmodules vendored

@ -10,3 +10,6 @@
[submodule "dependencies/mbuild"]
path = dependencies/mbuild
url = https://github.com/intelxed/mbuild.git
[submodule "dependencies/spdlog"]
path = dependencies/spdlog
url = https://github.com/gabime/spdlog.git

@ -90,6 +90,7 @@ target_include_directories(Theodosius PUBLIC
target_link_libraries(Theodosius PUBLIC
linux-pe
spdlog
)
unset(CMKR_TARGET)

@ -11,4 +11,4 @@ sources = ["include/**.hpp", "src/theo/**.cpp"]
include-directories = ["include"]
compile-features = ["cxx_std_20"]
compile-definitions = ["NOMINMAX"]
link-libraries = ["linux-pe"]
link-libraries = ["linux-pe", "spdlog"]

@ -6,6 +6,16 @@ if(CMKR_ROOT_PROJECT)
configure_file(cmake.toml cmake.toml COPYONLY)
endif()
# spdlog
set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
if(CMAKE_FOLDER)
set(CMAKE_FOLDER "${CMAKE_FOLDER}/spdlog")
else()
set(CMAKE_FOLDER spdlog)
endif()
add_subdirectory(spdlog)
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})
# Target linux-pe
set(CMKR_TARGET linux-pe)
set(linux-pe_SOURCES "")

@ -1,3 +1,5 @@
[target.linux-pe]
type = "interface"
include-directories = ["linux-pe/includes/"]
[subdir.spdlog]

@ -0,0 +1 @@
Subproject commit fc51c095bae108490bf62c3345a5e3b37a5e7630

@ -3,28 +3,29 @@
#include <decomp/decomp.hpp>
namespace theo::comp {
using resolve_t = std::function<std::uintptr_t(std::string&&)>;
using copy_t = std::function<void(void*, std::uint32_t)>;
using alloc_t = std::function<std::uintptr_t(std::uint32_t,
using resolver_t = std::function<std::uintptr_t(std::string&&)>;
using copier_t = std::function<void(void*, std::uint32_t)>;
using allocator_t =
std::function<std::uintptr_t(std::uint32_t,
coff::section_characteristics_t)>;
class comp_t {
public:
explicit comp_t(decomp::decomp_t& dcmp, comp::symbol_table_t syms);
explicit comp_t(decomp::decomp_t& dcmp,
comp::symbol_table_t syms,
alloc_t alloc,
copy_t copy,
resolve_t resolve);
explicit comp_t(decomp::decomp_t* dcmp);
explicit comp_t(decomp::decomp_t* dcmp,
allocator_t alloc,
copier_t copy,
resolver_t resolve);
void allocator(alloc_t alloc);
void copier(copy_t copy);
void resolver(resolve_t resolve);
void allocator(allocator_t alloc);
void copier(copier_t copy);
void resolver(resolver_t resolve);
std::uintptr_t resolve(std::string&& sym);
private:
resolve_t m_resolver;
copy_t m_copier;
alloc_t m_allocator;
decomp::decomp_t* m_dcmp;
resolver_t m_resolver;
copier_t m_copier;
allocator_t m_allocator;
};
} // namespace theo::comp

@ -18,6 +18,8 @@ class symbol_table_t {
void update(std::string& name, std::uintptr_t location);
void for_each(std::function<bool(decomp::symbol_t& sym)> fn);
std::uint32_t size();
private:
std::map<std::string, decomp::symbol_t> m_table;
};

@ -3,22 +3,27 @@
#include <cstdint>
#include <linuxpe>
#include <vector>
#include <optional>
#include <decomp/routine.hpp>
#include <comp/symbol_table.hpp>
#include <decomp/routine.hpp>
namespace theo::decomp {
class decomp_t {
public:
explicit decomp_t(std::vector<std::uint8_t>& lib_data);
std::vector<routine>& rtns();
std::vector<std::uint8_t>& lib();
std::vector<coff::image_t>& objs();
explicit decomp_t(std::vector<std::uint8_t>& lib_data,
comp::symbol_table_t* syms);
std::vector<routine_t> rtns();
std::vector<std::uint8_t> lib();
std::vector<coff::image_t> objs();
comp::symbol_table_t* syms();
std::optional<comp::symbol_table_t*> decompose();
private:
void decompose();
std::vector<std::uint8_t> m_lib_data;
std::vector<coff::image_t> m_obj_imgs;
std::vector<routine> m_rtns;
std::vector<routine_t> m_rtns;
comp::symbol_table_t* m_syms;
};
} // namespace theo::decomp

@ -6,18 +6,16 @@
#include "symbol.hpp"
namespace theo::decomp {
class routine {
class routine_t {
public:
explicit routine(coff::section_header_t scn_hdr,
explicit routine_t(coff::section_header_t scn_hdr,
std::vector<std::uint8_t>& rtn_data);
std::vector<decomp::symbol_t> syms();
std::vector<decomp::symbol_t> decompose();
coff::section_header_t scn_hdr();
std::vector<std::uint8_t> data();
private:
void decompose();
std::vector<std::uint8_t> m_data;
std::vector<decomp::symbol_t> m_orig_syms;
coff::section_header_t m_scn_hdr;
};
} // namespace theo::decomp

@ -1,3 +1,27 @@
#pragma once
#include <comp/comp.hpp>
#include <decomp/decomp.hpp>
#include <spdlog/spdlog.h>
#include <optional>
#include <vector>
#include <tuple>
namespace theo {
using lnk_fns_t =
std::tuple<comp::allocator_t, comp::copier_t, comp::resolver_t>;
class theo_t {
public:
explicit theo_t(
std::vector<std::uint8_t>& lib, lnk_fns_t lnkr_fns);
std::optional<std::uint32_t> decompose();
std::uintptr_t compose(const std::string&& entry_sym);
std::uintptr_t resolve(const std::string&& sym);
private:
decomp::decomp_t m_dcmp;
comp::comp_t m_cmp;
comp::symbol_table_t m_sym_tbl;
};
} // namespace theo

@ -57,6 +57,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${usermode-demo_SOURCES})
target_link_libraries(usermode-demo PRIVATE
Theodosius
spdlog
)
unset(CMKR_TARGET)

@ -5,4 +5,4 @@ name = "usermode-demo"
type = "executable"
sources = ["*.cpp"]
link-libraries = ["Theodosius"]
link-libraries = ["Theodosius", "spdlog"]

@ -0,0 +1,33 @@
#include <Windows.h>
#include <filesystem>
#include <fstream>
#include <spdlog/spdlog.h>
#include <theo.hpp>
namespace fs = std::filesystem;
int main(int argc, char* argv[]) {
spdlog::info("this is info...");
spdlog::error("this is an error...");
if (argc < 2)
return -1;
// read in lib file...
std::ifstream f(argv[1], std::ios::binary);
auto fsize = fs::file_size(fs::path(argv[1]));
std::vector<std::uint8_t> fdata;
fdata.resize(fsize);
f.read((char*)fdata.data(), fsize);
theo::theo_t t(fdata, {});
auto res = t.decompose();
if (!res.has_value()) {
spdlog::error("decomposition failed...\n");
return -1;
}
spdlog::info("decomposed {1} symbols...", res.value());
}

@ -0,0 +1,18 @@
#include <theo.hpp>
namespace theo {
theo_t::theo_t(std::vector<std::uint8_t>& lib, lnk_fns_t lnkr_fns)
: m_dcmp(lib, &m_sym_tbl), m_cmp(&m_dcmp) {}
std::optional<std::uint32_t> theo_t::decompose() {
auto res = m_dcmp.decompose();
if (!res.has_value()) {
spdlog::error("failed to decompose...\n");
return {};
}
spdlog::info("decompose successful... {1} symbols", res.value()->size());
return res.value()->size();
}
} // namespace theo
Loading…
Cancel
Save