diff options
| author | auth <[email protected]> | 2020-07-03 14:30:26 +0200 |
|---|---|---|
| committer | auth <[email protected]> | 2020-07-03 14:30:26 +0200 |
| commit | 40025e07ca06f48d21b583adc9f78b7b10d90995 (patch) | |
| tree | 08cc6c5fff5953e0f61b851615d4ebdf93dc7733 | |
| parent | Added client timeout. (diff) | |
| download | loader-40025e07ca06f48d21b583adc9f78b7b10d90995.tar.xz loader-40025e07ca06f48d21b583adc9f78b7b10d90995.zip | |
Started asmjit wrapper for easier manipulation.
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | CMakeLists.txt | 3 | ||||
| -rw-r--r-- | client/src/assembler/assembler.cpp | 21 | ||||
| -rw-r--r-- | client/src/assembler/assembler.h | 33 | ||||
| -rw-r--r-- | client/src/assembler/opcodes.h | 9 | ||||
| -rw-r--r-- | client/src/main.cpp | 10 | ||||
| m--------- | shared/asmjit | 0 |
7 files changed, 78 insertions, 1 deletions
diff --git a/.gitmodules b/.gitmodules index ef18434..17bf5ab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "shared/linux-pe"] path = shared/linux-pe url = https://github.com/authentification/linux-pe.git +[submodule "shared/asmjit"] + path = shared/asmjit + url = https://github.com/asmjit/asmjit.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c1c15da..35b4f7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ set(OPENSSL_USE_STATIC_LIBS TRUE) add_subdirectory(shared/spdlog) add_subdirectory(shared/cpr) +add_subdirectory(shared/asmjit) add_subdirectory(server) add_subdirectory(client) @@ -35,4 +36,4 @@ target_link_libraries(server PRIVATE spdlog ${OPENSSL_LIBRARIES} ${CPR_LIBRARIES target_precompile_headers(server PRIVATE ${PROJECT_SOURCE_DIR}/shared/linux-pe/linuxpe) target_include_directories(client PRIVATE ${PROJECT_SOURCE_DIR}/shared ${OPENSSL_INCLUDE_DIR}) -target_link_libraries(client PRIVATE spdlog ${OPENSSL_LIBRARIES}) +target_link_libraries(client PRIVATE spdlog asmjit ${OPENSSL_LIBRARIES}) diff --git a/client/src/assembler/assembler.cpp b/client/src/assembler/assembler.cpp new file mode 100644 index 0000000..43816fd --- /dev/null +++ b/client/src/assembler/assembler.cpp @@ -0,0 +1,21 @@ +#include "../include.h" +#include "assembler.h" + +void assembler::assembler::push(const std::vector<uintptr_t>& args) { + for (auto it = args.rbegin(); it != args.rend(); ++it) { + m_assembler.push(*it); + } +} + +void assembler::assembler::end() { + // epilogue here + + void* func; + m_runtime.add(&func, &m_code); + + const size_t size = m_code.codeSize(); + + m_buf.resize(size); + + std::memcpy(&m_buf[0], func, size); +}
\ No newline at end of file diff --git a/client/src/assembler/assembler.h b/client/src/assembler/assembler.h new file mode 100644 index 0000000..34096a5 --- /dev/null +++ b/client/src/assembler/assembler.h @@ -0,0 +1,33 @@ +#pragma once + +#include <asmjit/src/asmjit/asmjit.h> + +using namespace asmjit; + +namespace assembler { + +class assembler { + std::vector<std::byte> m_buf; + + CodeHolder m_code; + JitRuntime m_runtime; + x86::Assembler m_assembler; + + public: + assembler(const bool x64 = false) { + Environment env(x64 ? Environment::kArchX64 : Environment::kArchX86); + + m_code.init(env); + m_code.attach(&m_assembler); + } + void start(); + void push(const std::vector<uintptr_t> &args); + void call(const uintptr_t addr); + void save_ret(const uintptr_t addr); + void end(); + + auto &operator()() const { return m_buf; } + auto &operator->() const { return m_assembler; } +}; + +}; // namespace assembler
\ No newline at end of file diff --git a/client/src/assembler/opcodes.h b/client/src/assembler/opcodes.h new file mode 100644 index 0000000..cc21ef0 --- /dev/null +++ b/client/src/assembler/opcodes.h @@ -0,0 +1,9 @@ +#pragma once + + +namespace assembler { + enum opcodes : uint8_t { + nop = 0x90, + ret = 0xc3S + }; +};
\ No newline at end of file diff --git a/client/src/main.cpp b/client/src/main.cpp index 61b97d5..f68ef6a 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -1,10 +1,20 @@ #include "include.h" #include "util/io.h" #include "client/client.h" +#include "assembler/assembler.h" int main(int argc, char* argv[]) { io::init(); + assembler::assembler a; + a.push({1, 2, 3, 7, 9}); + a.end(); + for(auto &b : a()) { + io::logger->info("{:x}", int(b)); + } + + + std::cin.get(); tcp::client client; std::thread t{tcp::client::monitor, std::ref(client)}; diff --git a/shared/asmjit b/shared/asmjit new file mode 160000 +Subproject ba30278d66438815981b7c0ca9ed4ebb11266d3 |