From 292fc6ce67507cc8d845da1600520980b22c86af Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 9 Aug 2025 17:38:20 +0200 Subject: [PATCH] Fix compilation --- .../icicle-emulator/icicle_x86_64_emulator.cpp | 3 +++ .../unicorn-emulator/unicorn_x86_64_emulator.cpp | 2 +- src/common/platform/win_pefile.hpp | 10 +++++----- src/common/utils/object.hpp | 8 ++++++++ src/windows-emulator/module/module_mapping.cpp | 4 ++-- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/backends/icicle-emulator/icicle_x86_64_emulator.cpp b/src/backends/icicle-emulator/icicle_x86_64_emulator.cpp index b63b8aa6..b01ed360 100644 --- a/src/backends/icicle-emulator/icicle_x86_64_emulator.cpp +++ b/src/backends/icicle-emulator/icicle_x86_64_emulator.cpp @@ -103,6 +103,9 @@ namespace icicle ~icicle_x86_64_emulator() override { + reset_object_with_delayed_destruction(this->hooks_); + reset_object_with_delayed_destruction(this->storage_); + if (this->emu_) { icicle_destroy_emulator(this->emu_); diff --git a/src/backends/unicorn-emulator/unicorn_x86_64_emulator.cpp b/src/backends/unicorn-emulator/unicorn_x86_64_emulator.cpp index 000027e5..0ffa5b46 100644 --- a/src/backends/unicorn-emulator/unicorn_x86_64_emulator.cpp +++ b/src/backends/unicorn-emulator/unicorn_x86_64_emulator.cpp @@ -206,7 +206,7 @@ namespace unicorn ~unicorn_x86_64_emulator() override { - this->hooks_.clear(); + reset_object_with_delayed_destruction(this->hooks_); uc_close(this->uc_); } diff --git a/src/common/platform/win_pefile.hpp b/src/common/platform/win_pefile.hpp index b154a8b5..d2c83b60 100644 --- a/src/common/platform/win_pefile.hpp +++ b/src/common/platform/win_pefile.hpp @@ -298,11 +298,11 @@ typedef struct _IMAGE_IMPORT_BY_NAME typedef struct _IMAGE_IMPORT_DESCRIPTOR { - union - { - DWORD Characteristics; // 0 for terminating null import descriptor - DWORD OriginalFirstThunk; // RVA to original unbound IAT (PIMAGE_THUNK_DATA) - } DUMMYUNIONNAME; + // union + //{ + // DWORD Characteristics; // 0 for terminating null import descriptor + DWORD OriginalFirstThunk; // RVA to original unbound IAT (PIMAGE_THUNK_DATA) + //} DUMMYUNIONNAME; DWORD TimeDateStamp; // 0 if not bound, // -1 if bound, and real date\time stamp // in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND) diff --git a/src/common/utils/object.hpp b/src/common/utils/object.hpp index e0cc9a84..e1f206f7 100644 --- a/src/common/utils/object.hpp +++ b/src/common/utils/object.hpp @@ -12,4 +12,12 @@ namespace utils object& operator=(object&&) = default; object& operator=(const object&) = default; }; + + template + void reset_object_with_delayed_destruction(T& obj) + { + T new_obj{}; + const auto old = std::move(obj); + obj = std::move(new_obj); + } } diff --git a/src/windows-emulator/module/module_mapping.cpp b/src/windows-emulator/module/module_mapping.cpp index bfedf783..496d89b8 100644 --- a/src/windows-emulator/module/module_mapping.cpp +++ b/src/windows-emulator/module/module_mapping.cpp @@ -52,7 +52,6 @@ namespace auto& imports = binary.imports[module_name]; auto original_thunk_data = buffer.as(descriptor.FirstThunk); - if (descriptor.OriginalFirstThunk) { original_thunk_data = buffer.as(descriptor.OriginalFirstThunk); @@ -79,7 +78,8 @@ namespace } else { - sym.name = buffer.as_string(original_thunk.u1.AddressOfData + offsetof(IMAGE_IMPORT_BY_NAME, Name)); + sym.name = buffer.as_string( + static_cast(original_thunk.u1.AddressOfData + offsetof(IMAGE_IMPORT_BY_NAME, Name))); } imports.push_back(std::move(sym));