From b098fa6de7192a7c077a77f26e7163f8a9f25e62 Mon Sep 17 00:00:00 2001 From: W4ZM <82101268+W4ZM@users.noreply.github.com> Date: Sun, 24 Aug 2025 20:08:52 +0100 Subject: [PATCH 1/4] fixed bug --- .vscode/settings.json | 5 +++++ src/main.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a3b2b51 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "vector": "cpp" + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 515d28a..881f5ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,14 +139,14 @@ int main(int argc, char *argv[]) { // calculate the section size for storage in the PE file auto section_size = static_cast(packed.size() + sizeof(std::size_t)); - // re-acquire an NT header pointer since our buffer likely changed addresses - // from the resize - nt_header = reinterpret_cast(stub_data.data() + e_lfanew); - // pad the section data with 0s if we aren't on the file alignment boundary if (stub_data.size() % file_alignment != 0) stub_data.resize(align(stub_data.size(), file_alignment)); + // re-acquire an NT header pointer since our buffer likely changed addresses + // from the resize + nt_header = reinterpret_cast(stub_data.data() + e_lfanew); + // increment the number of sections in the file header auto section_index = nt_header->FileHeader.NumberOfSections; ++nt_header->FileHeader.NumberOfSections; From ad855df53b2e2c62c4aa89f15ef76d573b8f1b4f Mon Sep 17 00:00:00 2001 From: W4ZM <82101268+W4ZM@users.noreply.github.com> Date: Mon, 25 Aug 2025 09:44:18 +0100 Subject: [PATCH 2/4] Delete .vscode/settings.json --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index a3b2b51..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "vector": "cpp" - } -} \ No newline at end of file From f8a3b2a02a2be25ba9bc404b20e02e2366294bb5 Mon Sep 17 00:00:00 2001 From: W4ZM <82101268+W4ZM@users.noreply.github.com> Date: Thu, 28 Aug 2025 12:10:05 +0100 Subject: [PATCH 3/4] Update main.cpp --- stub/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stub/src/main.cpp b/stub/src/main.cpp index 4bc465f..fc41170 100644 --- a/stub/src/main.cpp +++ b/stub/src/main.cpp @@ -135,7 +135,7 @@ void load_imports(std::uint8_t *image) { // if the top-most bit is set, this is a function ordinal. // otherwise, it's an import by name. - if (lookup_address & IMAGE_ORDINAL_FLAG64 != 0) + if ((lookup_address & IMAGE_ORDINAL_FLAG64) != 0) { // get the function ordinal by masking the lower 32-bits of the lookup address. function = GetProcAddress(dll_import, @@ -178,7 +178,7 @@ void relocate(std::uint8_t *image) { // then this image probably isn't prepared for relocating. auto nt_header = get_nt_headers(image); - if (nt_header->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE == 0) + if ((nt_header->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) == 0) { std::cerr << "Error: image cannot be relocated." << std::endl; ExitProcess(7); From ae03cc855cb4b4623a93383d5c5af80042340729 Mon Sep 17 00:00:00 2001 From: W4ZM <82101268+W4ZM@users.noreply.github.com> Date: Thu, 28 Aug 2025 12:36:24 +0100 Subject: [PATCH 4/4] no change --- stub/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stub/src/main.cpp b/stub/src/main.cpp index fc41170..4bc465f 100644 --- a/stub/src/main.cpp +++ b/stub/src/main.cpp @@ -135,7 +135,7 @@ void load_imports(std::uint8_t *image) { // if the top-most bit is set, this is a function ordinal. // otherwise, it's an import by name. - if ((lookup_address & IMAGE_ORDINAL_FLAG64) != 0) + if (lookup_address & IMAGE_ORDINAL_FLAG64 != 0) { // get the function ordinal by masking the lower 32-bits of the lookup address. function = GetProcAddress(dll_import, @@ -178,7 +178,7 @@ void relocate(std::uint8_t *image) { // then this image probably isn't prepared for relocating. auto nt_header = get_nt_headers(image); - if ((nt_header->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) == 0) + if (nt_header->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE == 0) { std::cerr << "Error: image cannot be relocated." << std::endl; ExitProcess(7);