aboutsummaryrefslogtreecommitdiff
path: root/client/src/util
diff options
context:
space:
mode:
authorauth12 <[email protected]>2020-07-24 10:56:14 -0700
committerauth12 <[email protected]>2020-07-24 10:56:14 -0700
commite487ffe1671ba807528d4039ef66f8f8f7eeb853 (patch)
treec65cc4dd529f8e37f9cca81d38c749dece13a574 /client/src/util
parentInjection and server changes. (diff)
downloadloader-e487ffe1671ba807528d4039ef66f8f8f7eeb853.tar.xz
loader-e487ffe1671ba807528d4039ef66f8f8f7eeb853.zip
Injection process changes and server improvements.
Diffstat (limited to 'client/src/util')
-rw-r--r--client/src/util/io.cpp22
-rw-r--r--client/src/util/io.h1
-rw-r--r--client/src/util/pe.h57
-rw-r--r--client/src/util/syscalls.cpp2
-rw-r--r--client/src/util/util.cpp28
-rw-r--r--client/src/util/util.h7
6 files changed, 37 insertions, 80 deletions
diff --git a/client/src/util/io.cpp b/client/src/util/io.cpp
index 019ec3f..f6048ba 100644
--- a/client/src/util/io.cpp
+++ b/client/src/util/io.cpp
@@ -10,3 +10,25 @@ void io::init() {
logger = std::make_shared<spdlog::logger>("client", sink);
}
+
+bool io::read_file(const std::string_view name, std::vector<char>& out) {
+ std::ifstream file(name.data(), std::ios::binary);
+ if (!file.good()) {
+ io::logger->error("{} isnt valid.", name);
+ return false;
+ }
+
+ file.unsetf(std::ios::skipws);
+
+ file.seekg(0, std::ios::end);
+ const size_t size = file.tellg();
+ file.seekg(0, std::ios::beg);
+
+ out.resize(size);
+
+ file.read(&out[0], size);
+
+ file.close();
+
+ return true;
+}
diff --git a/client/src/util/io.h b/client/src/util/io.h
index a69940e..0678e9f 100644
--- a/client/src/util/io.h
+++ b/client/src/util/io.h
@@ -8,4 +8,5 @@ namespace io {
extern std::shared_ptr<spdlog::logger> logger;
void init();
+ bool read_file(const std::string_view name, std::vector<char>& out);
}; // namespace io
diff --git a/client/src/util/pe.h b/client/src/util/pe.h
deleted file mode 100644
index 4ae4326..0000000
--- a/client/src/util/pe.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#pragma once
-
-#include <linux-pe/linuxpe>
-
-namespace pe {
-
- class virtual_image {
- std::unordered_map<std::string, uintptr_t> m_exports;
-
- IMAGE_NT_HEADERS64* m_nt;
- uintptr_t m_base;
- bool m_valid;
-
- public:
- virtual_image() {};
- virtual_image(const uintptr_t base) : m_valid{ false }, m_base{ base }, m_nt{ nullptr } {
- auto dos = reinterpret_cast<IMAGE_DOS_HEADER*>(base);
- if (!dos || dos->e_magic != IMAGE_DOS_SIGNATURE) {
- return;
- }
-
- m_nt = reinterpret_cast<IMAGE_NT_HEADERS64*>(base + dos->e_lfanew);
- if (m_nt->Signature != IMAGE_NT_SIGNATURE) {
- return;
- }
-
- m_valid = true;
- }
-
- void parse_exports() {
- auto dir = m_nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT];
- auto exp =
- reinterpret_cast<IMAGE_EXPORT_DIRECTORY*>(m_base + dir.VirtualAddress);
-
- if (exp->NumberOfFunctions == 0) return;
-
- auto names = reinterpret_cast<uint32_t*>(m_base + exp->AddressOfNames);
- auto funcs = reinterpret_cast<uint32_t*>(m_base + exp->AddressOfFunctions);
- auto ords =
- reinterpret_cast<uint16_t*>(m_base + exp->AddressOfNameOrdinals);
-
- if (!names || !funcs || !ords) return;
-
- for (size_t i{}; i < exp->NumberOfFunctions; i++) {
- uintptr_t va = m_base + funcs[ords[i]];
- std::string name = reinterpret_cast<const char*>(m_base + names[i]);
-
- m_exports[name] = va;
- }
- }
-
- auto& exports() { return m_exports; }
-
- operator bool() { return m_valid; }
- };
-
-}; // namespace pe \ No newline at end of file
diff --git a/client/src/util/syscalls.cpp b/client/src/util/syscalls.cpp
index f1d9261..d7d4254 100644
--- a/client/src/util/syscalls.cpp
+++ b/client/src/util/syscalls.cpp
@@ -35,7 +35,7 @@ void syscalls::init() {
}
}
- io::logger->info("{:x}", uintptr_t(m_call_table));
+ io::logger->info("call table : {:x}", uintptr_t(m_call_table));
for (auto& syscall : m_indexes) {
auto idx = syscall.second.first;
diff --git a/client/src/util/util.cpp b/client/src/util/util.cpp
index 3dba550..b79f6cd 100644
--- a/client/src/util/util.cpp
+++ b/client/src/util/util.cpp
@@ -7,45 +7,37 @@ std::unordered_map<std::string, pe::virtual_image> util::loaded_modules;
std::string util::wide_to_multibyte(const std::wstring& str) {
std::string ret;
- int32_t str_len;
+ size_t str_len;
// check if not empty str
if (str.empty())
return{};
// count size
- str_len = WideCharToMultiByte(CP_UTF8, 0, &str[0], (int32_t)str.size(), 0, 0, 0, 0);
+ str_len = WideCharToMultiByte(CP_UTF8, 0, &str[0], str.size(), 0, 0, 0, 0);
// setup return value
ret = std::string(str_len, 0);
// final conversion
- WideCharToMultiByte(CP_UTF8, 0, &str[0], (int32_t)str.size(), &ret[0], str_len, 0, 0);
+ WideCharToMultiByte(CP_UTF8, 0, &str[0], str.size(), &ret[0], str_len, 0, 0);
return ret;
}
-std::wstring util::multibyte_to_wide(const std::string &str) {
- std::wstring ret;
- int32_t size;
- wchar_t *wstr;
- const char *buf = str.c_str();
+std::wstring util::multibyte_to_wide(const std::string& str) {
+ size_t size;
+ std::wstring out;
// get size
- size = MultiByteToWideChar(CP_UTF8, 0, buf, int32_t(strlen(buf) + 1), 0, 0);
+ size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size() + 1, 0, 0);
- // alloc new wchars
- wstr = new wchar_t[size];
+ out.resize(size);
// finally convert
- MultiByteToWideChar(CP_UTF8, 0, buf, int32_t(strlen(buf) + 1), wstr, size);
+ MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size() + 1, &out[0], size);
- // construct return string
- ret = std::wstring(wstr);
-
- // cleanup
- delete[] wstr;
- return ret;
+ return out;
}
diff --git a/client/src/util/util.h b/client/src/util/util.h
index a4ff8c9..8734bd9 100644
--- a/client/src/util/util.h
+++ b/client/src/util/util.h
@@ -1,14 +1,14 @@
#pragma once
#include "native.h"
-#include "pe.h"
+#include "../injection/pe.h"
namespace util {
extern std::unordered_map<std::string, pe::virtual_image> loaded_modules;
std::string wide_to_multibyte(const std::wstring& str);
- std::wstring multibyte_to_wide(const std::string &str);
+ std::wstring multibyte_to_wide(const std::string& str);
native::_PEB* cur_peb();
@@ -25,5 +25,4 @@ namespace util {
bool close_handle(HANDLE handle);
-}; // namespace util
-
+}; // namespace util \ No newline at end of file