diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5a8713ad..4492d05c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ if (NOT MOMO_BUILD_AS_LIBRARY) add_subdirectory(fuzzing-engine) add_subdirectory(fuzzer) add_subdirectory(windows-emulator-test) - if(WIN32) + if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8) momo_add_subdirectory_and_get_targets("tools" TOOL_TARGETS) momo_targets_set_folder("tools" ${TOOL_TARGETS}) diff --git a/src/analyzer/object_watching.hpp b/src/analyzer/object_watching.hpp index df8ab871..4d700d4c 100644 --- a/src/analyzer/object_watching.hpp +++ b/src/analyzer/object_watching.hpp @@ -10,7 +10,7 @@ emulator_hook* watch_object(windows_emulator& emu, const std::set info{}; return emu.emu().hook_memory_read( - object.value(), object.size(), + object.value(), static_cast(object.size()), [i = std::move(info), object, &emu, cache_logging, modules](const uint64_t address, const void*, size_t) { const auto rip = emu.emu().read_instruction_pointer(); const auto* mod = emu.mod_manager.find_by_address(rip); @@ -33,6 +33,7 @@ emulator_hook* watch_object(windows_emulator& emu, const std::setname.c_str() : ""); + i.get_member_name(static_cast(offset)).c_str(), rip, + mod ? mod->name.c_str() : ""); }); } diff --git a/src/analyzer/reflect_type_info.hpp b/src/analyzer/reflect_type_info.hpp index 0bfd8075..0a6059a9 100644 --- a/src/analyzer/reflect_type_info.hpp +++ b/src/analyzer/reflect_type_info.hpp @@ -11,9 +11,18 @@ #pragma clang diagnostic ignored "-Wunused-private-field" #endif +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4308) +#endif + #include "reflect_extension.hpp" #include +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #if defined(__clang__) #pragma clang diagnostic pop #endif diff --git a/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt b/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt index 4836948a..73ea9f1d 100644 --- a/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt +++ b/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt @@ -13,7 +13,9 @@ endif() set(CARGO_TRIPLE) set(CARGO_OPTIONS) -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(CARGO_TRIPLE "i686-pc-windows-msvc") +elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(CARGO_TRIPLE "aarch64-apple-ios") elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") if(CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a") diff --git a/src/common/platform/compiler.hpp b/src/common/platform/compiler.hpp index 34c1cc4d..5cece6a8 100644 --- a/src/common/platform/compiler.hpp +++ b/src/common/platform/compiler.hpp @@ -2,6 +2,13 @@ #if defined(_WIN32) || defined(_WIN64) #define OS_WINDOWS + +#if defined(_WIN64) +#define OS_WINDOWS_64 +#else +#define OS_WINDOWS_32 +#endif + #elif defined(__APPLE__) || defined(__MACH__) #define OS_MAC #elif defined(__linux__) diff --git a/src/common/platform/kernel_mapped.hpp b/src/common/platform/kernel_mapped.hpp index 83dd548e..5dca4e62 100644 --- a/src/common/platform/kernel_mapped.hpp +++ b/src/common/platform/kernel_mapped.hpp @@ -583,7 +583,7 @@ typedef struct _TEB64 ARRAY_CONTAINER Rcu; } TEB64, *PTEB64; -#ifdef OS_WINDOWS +#if defined(OS_WINDOWS) && defined(_WIN64) inline TEB64* NtCurrentTeb64() { return reinterpret_cast(__readgsqword(FIELD_OFFSET(EMU_NT_TIB64, Self))); diff --git a/src/common/platform/memory.hpp b/src/common/platform/memory.hpp index bf213b91..44e37103 100644 --- a/src/common/platform/memory.hpp +++ b/src/common/platform/memory.hpp @@ -66,8 +66,8 @@ typedef enum _SECTION_INHERIT typedef struct DECLSPEC_ALIGN(16) _EMU_MEMORY_BASIC_INFORMATION64 { - void* BaseAddress; - void* AllocationBase; + uint64_t BaseAddress; + uint64_t AllocationBase; DWORD AllocationProtect; WORD PartitionId; std::int64_t RegionSize; diff --git a/src/common/platform/process.hpp b/src/common/platform/process.hpp index 85b1a1a0..e02d8f99 100644 --- a/src/common/platform/process.hpp +++ b/src/common/platform/process.hpp @@ -553,13 +553,15 @@ struct SYSTEM_PROCESSOR_INFORMATION64 ULONG ProcessorFeatureBits; }; -#ifndef OS_WINDOWS +#if !defined(OS_WINDOWS) || !defined(_WIN64) +#if !defined(OS_WINDOWS) typedef struct _M128A { ULONGLONG Low; LONGLONG High; } M128A, *PM128A; +#endif typedef struct _XMM_SAVE_AREA32 { diff --git a/src/emulator/serialization.hpp b/src/emulator/serialization.hpp index 981d3b51..8bf66af7 100644 --- a/src/emulator/serialization.hpp +++ b/src/emulator/serialization.hpp @@ -378,7 +378,7 @@ namespace utils { const auto size = this->read(); result.clear(); - result.reserve(size); + result.reserve(static_cast(size)); for (uint64_t i = 0; i < size; ++i) { @@ -447,7 +447,7 @@ namespace utils const auto size = this->read(); result.clear(); - result.reserve(size); + result.reserve(static_cast(size)); for (uint64_t i = 0; i < size; ++i) { diff --git a/src/fuzzer/main.cpp b/src/fuzzer/main.cpp index 237d357c..24f9fc9f 100644 --- a/src/fuzzer/main.cpp +++ b/src/fuzzer/main.cpp @@ -5,6 +5,10 @@ #include "utils/finally.hpp" +#ifdef _MSC_VER +#pragma warning(disable : 4702) +#endif + bool use_gdb = false; namespace @@ -63,12 +67,6 @@ namespace utils::buffer_deserializer deserializer{emulator_data}; emu.deserialize(deserializer); emu.save_snapshot(); - - const auto ret = emu.emu().read_stack(0); - - emu.emu().hook_memory_execution(ret, [&](uint64_t) { - emu.emu().stop(); // - }); } void restore_emulator() @@ -87,8 +85,9 @@ namespace restore_emulator(); - const auto memory = emu.memory.allocate_memory(page_align_up(std::max(data.size(), static_cast(1))), - memory_permission::read_write); + const auto memory = emu.memory.allocate_memory( + static_cast(page_align_up(std::max(data.size(), static_cast(1)))), + memory_permission::read_write); emu.emu().write_memory(memory, data.data(), data.size()); emu.emu().reg(x64_register::rcx, memory); diff --git a/src/windows-emulator-test/CMakeLists.txt b/src/windows-emulator-test/CMakeLists.txt index 7bf36845..8bea4b26 100644 --- a/src/windows-emulator-test/CMakeLists.txt +++ b/src/windows-emulator-test/CMakeLists.txt @@ -16,7 +16,7 @@ target_link_libraries(windows-emulator-test PRIVATE windows-emulator ) -if(WIN32) +if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8) add_dependencies(windows-emulator-test test-sample) endif() diff --git a/src/windows-emulator-test/emulation_test.cpp b/src/windows-emulator-test/emulation_test.cpp index dc600f92..d5c60363 100644 --- a/src/windows-emulator-test/emulation_test.cpp +++ b/src/windows-emulator-test/emulation_test.cpp @@ -34,7 +34,7 @@ namespace test constexpr auto offset = 1; const auto instructionsToExecute = executedInstructions - offset; - new_emu.start(instructionsToExecute); + new_emu.start(static_cast(instructionsToExecute)); ASSERT_EQ(new_emu.get_executed_instructions(), instructionsToExecute); ASSERT_NOT_TERMINATED(new_emu); diff --git a/src/windows-emulator-test/emulation_test_utils.hpp b/src/windows-emulator-test/emulation_test_utils.hpp index 5437aec1..a399702c 100644 --- a/src/windows-emulator-test/emulation_test_utils.hpp +++ b/src/windows-emulator-test/emulation_test_utils.hpp @@ -155,7 +155,7 @@ namespace test return s1.get_diff(s2).has_value(); }; - if (!has_diff_after_count(limit)) + if (!has_diff_after_count(static_cast(limit))) { puts("Emulation has no diff"); } @@ -170,7 +170,7 @@ namespace test const auto diff = (upper_bound - lower_bound); const auto pivot = lower_bound + (diff / 2); - const auto has_diff = has_diff_after_count(pivot); + const auto has_diff = has_diff_after_count(static_cast(pivot)); auto* bound = has_diff ? &upper_bound : &lower_bound; *bound = pivot; @@ -178,7 +178,7 @@ namespace test printf("Bounds: %" PRIx64 " - %" PRIx64 "\n", lower_bound, upper_bound); } - (void)get_state_for_count(lower_bound); + (void)get_state_for_count(static_cast(lower_bound)); const auto rip = emu.emu().read_instruction_pointer(); diff --git a/src/windows-emulator/apiset/apiset.cpp b/src/windows-emulator/apiset/apiset.cpp index d0b32c7e..7006f4a7 100644 --- a/src/windows-emulator/apiset/apiset.cpp +++ b/src/windows-emulator/apiset/apiset.cpp @@ -57,7 +57,7 @@ namespace apiset { switch (location) { -#ifdef OS_WINDOWS +#ifdef OS_WINDOWS_64 case location::host: { const auto apiSetMap = reinterpret_cast(NtCurrentTeb64()->ProcessEnvironmentBlock->ApiSetMap); diff --git a/src/windows-emulator/emulator_thread.cpp b/src/windows-emulator/emulator_thread.cpp index 144bcbcd..6425a1d7 100644 --- a/src/windows-emulator/emulator_thread.cpp +++ b/src/windows-emulator/emulator_thread.cpp @@ -93,7 +93,7 @@ emulator_thread::emulator_thread(memory_manager& memory, const process_context& suspended(suspended), last_registers(context.default_register_set) { - this->stack_base = memory.allocate_memory(this->stack_size, memory_permission::read_write); + this->stack_base = memory.allocate_memory(static_cast(this->stack_size), memory_permission::read_write); this->gs_segment = emulator_allocator{ memory, @@ -214,7 +214,7 @@ void emulator_thread::setup_registers(x64_emulator& emu, const process_context& throw std::runtime_error("Missing GS segment"); } - setup_stack(emu, this->stack_base, this->stack_size); + setup_stack(emu, this->stack_base, static_cast(this->stack_size)); emu.set_segment_base(x64_register::gs, this->gs_segment->get_base()); CONTEXT64 ctx{}; diff --git a/src/windows-emulator/emulator_thread.hpp b/src/windows-emulator/emulator_thread.hpp index eab80c8c..07e3ed12 100644 --- a/src/windows-emulator/emulator_thread.hpp +++ b/src/windows-emulator/emulator_thread.hpp @@ -227,7 +227,7 @@ class emulator_thread : public ref_counted_object throw std::runtime_error("Emulator was never assigned!"); } - this->memory_ptr->release_memory(this->stack_base, this->stack_size); + this->memory_ptr->release_memory(this->stack_base, static_cast(this->stack_size)); this->stack_base = 0; } diff --git a/src/windows-emulator/emulator_utils.hpp b/src/windows-emulator/emulator_utils.hpp index b0e71ece..e32c803c 100644 --- a/src/windows-emulator/emulator_utils.hpp +++ b/src/windows-emulator/emulator_utils.hpp @@ -300,7 +300,8 @@ class emulator_allocator { if (this->address_ && this->size_) { - manager.release_memory(this->address_, this->size_); + // TODO: Make all sizes uint64_t + manager.release_memory(this->address_, static_cast(this->size_)); this->address_ = 0; this->size_ = 0; } diff --git a/src/windows-emulator/exception_dispatch.cpp b/src/windows-emulator/exception_dispatch.cpp index 96c5b9e8..3eae5182 100644 --- a/src/windows-emulator/exception_dispatch.cpp +++ b/src/windows-emulator/exception_dispatch.cpp @@ -109,7 +109,7 @@ namespace assert(total_size >= allocation_size); std::vector zero_memory{}; - zero_memory.resize(total_size, 0); + zero_memory.resize(static_cast(total_size), 0); emu.write_memory(new_sp, zero_memory.data(), zero_memory.size()); diff --git a/src/windows-emulator/kusd_mmio.cpp b/src/windows-emulator/kusd_mmio.cpp index 856d7187..95eadfa5 100644 --- a/src/windows-emulator/kusd_mmio.cpp +++ b/src/windows-emulator/kusd_mmio.cpp @@ -144,7 +144,7 @@ void kusd_mmio::read(const uint64_t addr, void* data, const size_t size) const auto real_size = valid_end - addr; const auto* kusd_buffer = reinterpret_cast(&this->kusd_); - memcpy(data, kusd_buffer + addr, real_size); + memcpy(data, kusd_buffer + addr, static_cast(real_size)); } uint64_t kusd_mmio::address() diff --git a/src/windows-emulator/memory_manager.cpp b/src/windows-emulator/memory_manager.cpp index 7c1a3de8..98268bef 100644 --- a/src/windows-emulator/memory_manager.cpp +++ b/src/windows-emulator/memory_manager.cpp @@ -22,9 +22,10 @@ namespace const auto first_length = split_point - i->first; const auto second_length = i->second.length - first_length; - i->second.length = first_length; + i->second.length = static_cast(first_length); - regions[split_point] = memory_manager::committed_region{second_length, i->second.permissions}; + regions[split_point] = + memory_manager::committed_region{static_cast(second_length), i->second.permissions}; } } } @@ -312,8 +313,8 @@ bool memory_manager::commit_memory(const uint64_t address, const size_t size, co if (map_length > 0) { - this->map_memory(map_start, map_length, permissions); - committed_regions[map_start] = committed_region{map_length, permissions}; + this->map_memory(map_start, static_cast(map_length), permissions); + committed_regions[map_start] = committed_region{static_cast(map_length), permissions}; } last_region_start = sub_region.first; @@ -326,8 +327,8 @@ bool memory_manager::commit_memory(const uint64_t address, const size_t size, co const auto map_start = last_region ? (last_region_start + last_region->length) : address; const auto map_length = end - map_start; - this->map_memory(map_start, map_length, permissions); - committed_regions[map_start] = committed_region{map_length, permissions}; + this->map_memory(map_start, static_cast(map_length), permissions); + committed_regions[map_start] = committed_region{static_cast(map_length), permissions}; } merge_regions(committed_regions); @@ -398,7 +399,7 @@ bool memory_manager::release_memory(const uint64_t address, size_t size) size = entry->second.length; } - size = page_align_up(size); + size = static_cast(page_align_up(size)); if (size > entry->second.length) { @@ -498,7 +499,7 @@ region_info memory_manager::get_region_info(const uint64_t address) { region_info result{}; result.start = MIN_ALLOCATION_ADDRESS; - result.length = MAX_ALLOCATION_ADDRESS - result.start; + result.length = static_cast(MAX_ALLOCATION_ADDRESS - result.start); result.permissions = memory_permission::none; result.initial_permissions = memory_permission::none; result.allocation_base = {}; @@ -514,7 +515,7 @@ region_info memory_manager::get_region_info(const uint64_t address) auto upper_bound = this->reserved_regions_.upper_bound(address); if (upper_bound == this->reserved_regions_.begin()) { - result.length = upper_bound->first - result.start; + result.length = static_cast(upper_bound->first - result.start); return result; } @@ -523,7 +524,7 @@ region_info memory_manager::get_region_info(const uint64_t address) if (lower_end <= address) { result.start = lower_end; - result.length = MAX_ALLOCATION_ADDRESS - result.start; + result.length = static_cast(MAX_ALLOCATION_ADDRESS - result.start); return result; } @@ -546,7 +547,7 @@ region_info memory_manager::get_region_info(const uint64_t address) auto committed_bound = committed_regions.upper_bound(address); if (committed_bound == committed_regions.begin()) { - result.length = committed_bound->first - result.start; + result.length = static_cast(committed_bound->first - result.start); return result; } @@ -555,7 +556,7 @@ region_info memory_manager::get_region_info(const uint64_t address) if (committed_lower_end <= address) { result.start = committed_lower_end; - result.length = lower_end - result.start; + result.length = static_cast(lower_end - result.start); return result; } diff --git a/src/windows-emulator/module/module_mapping.cpp b/src/windows-emulator/module/module_mapping.cpp index 939705e8..84c3ccd0 100644 --- a/src/windows-emulator/module/module_mapping.cpp +++ b/src/windows-emulator/module/module_mapping.cpp @@ -10,9 +10,9 @@ namespace uint64_t get_first_section_offset(const PENTHeaders_t& nt_headers, const uint64_t nt_headers_offset) { const auto* nt_headers_addr = reinterpret_cast(&nt_headers); - size_t optional_header_offset = + const size_t optional_header_offset = reinterpret_cast(&(nt_headers.OptionalHeader)) - reinterpret_cast(&nt_headers); - size_t optional_header_size = nt_headers.FileHeader.SizeOfOptionalHeader; + const size_t optional_header_size = nt_headers.FileHeader.SizeOfOptionalHeader; const auto* first_section_addr = nt_headers_addr + optional_header_offset + optional_header_size; const auto first_section_absolute = reinterpret_cast(first_section_addr); @@ -23,7 +23,7 @@ namespace std::vector read_mapped_memory(const memory_manager& memory, const mapped_module& binary) { std::vector mem{}; - mem.resize(binary.size_of_image); + mem.resize(static_cast(binary.size_of_image)); memory.read_memory(binary.image_base, mem.data(), mem.size()); return mem; @@ -73,7 +73,7 @@ namespace void apply_relocation(const utils::safe_buffer_accessor buffer, const uint64_t offset, const uint64_t delta) { - const auto obj = buffer.as(offset); + const auto obj = buffer.as(static_cast(offset)); const auto value = obj.get(); const auto new_value = value + static_cast(delta); obj.set(new_value); @@ -146,7 +146,7 @@ namespace const PENTHeaders_t& nt_headers, const uint64_t nt_headers_offset) { const auto first_section_offset = get_first_section_offset(nt_headers, nt_headers_offset); - const auto sections = buffer.as(first_section_offset); + const auto sections = buffer.as(static_cast(first_section_offset)); for (size_t i = 0; i < nt_headers.FileHeader.NumberOfSections; ++i) { @@ -179,11 +179,11 @@ namespace const auto size_of_section = page_align_up(std::max(section.SizeOfRawData, section.Misc.VirtualSize)); - memory.protect_memory(target_ptr, size_of_section, permissions, nullptr); + memory.protect_memory(target_ptr, static_cast(size_of_section), permissions, nullptr); mapped_section section_info{}; section_info.region.start = target_ptr; - section_info.region.length = size_of_section; + section_info.region.length = static_cast(size_of_section); section_info.region.permissions = permissions; for (size_t j = 0; j < sizeof(section.Name) && section.Name[j]; ++j) @@ -219,21 +219,22 @@ mapped_module map_module_from_data(memory_manager& memory, const std::span(binary.size_of_image), memory_permission::all)) { - binary.image_base = memory.find_free_allocation_base(binary.size_of_image); + binary.image_base = memory.find_free_allocation_base(static_cast(binary.size_of_image)); const auto is_dll = nt_headers.FileHeader.Characteristics & IMAGE_FILE_DLL; const auto has_dynamic_base = optional_header.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE; const auto is_relocatable = is_dll || has_dynamic_base; - if (!is_relocatable || !memory.allocate_memory(binary.image_base, binary.size_of_image, memory_permission::all)) + if (!is_relocatable || !memory.allocate_memory(binary.image_base, static_cast(binary.size_of_image), + memory_permission::all)) { throw std::runtime_error("Memory range not allocatable"); } } // TODO: Make sure to match kernel allocation patterns to attain correct initial permissions! - memory.protect_memory(binary.image_base, binary.size_of_image, memory_permission::read); + memory.protect_memory(binary.image_base, static_cast(binary.size_of_image), memory_permission::read); binary.entry_point = binary.image_base + optional_header.AddressOfEntryPoint; @@ -266,5 +267,5 @@ mapped_module map_module_from_file(memory_manager& memory, std::filesystem::path bool unmap_module(memory_manager& memory, const mapped_module& mod) { - return memory.release_memory(mod.image_base, mod.size_of_image); + return memory.release_memory(mod.image_base, static_cast(mod.size_of_image)); } diff --git a/src/windows-emulator/syscall_utils.hpp b/src/windows-emulator/syscall_utils.hpp index eb61b630..697e13e8 100644 --- a/src/windows-emulator/syscall_utils.hpp +++ b/src/windows-emulator/syscall_utils.hpp @@ -54,7 +54,8 @@ inline std::optional extract_syscall_id(const exported_symbol& symbol, const auto instruction_rva = symbol.rva + instruction_offset; - if (data.size() < (instruction_rva + instruction_size) || data[instruction_rva] != instruction_opcode) + if (data.size() < (instruction_rva + instruction_size) || + data[static_cast(instruction_rva)] != instruction_opcode) { return std::nullopt; } diff --git a/src/windows-emulator/syscalls/file.cpp b/src/windows-emulator/syscalls/file.cpp index 0cad972c..8b291a22 100644 --- a/src/windows-emulator/syscalls/file.cpp +++ b/src/windows-emulator/syscalls/file.cpp @@ -130,7 +130,7 @@ namespace syscalls auto& enum_state = *f->enumeration_state; - size_t current_offset{0}; + uint64_t current_offset{0}; emulator_object object{c.emu}; size_t current_index = enum_state.current_index; @@ -400,7 +400,8 @@ namespace syscalls std::cin.readsome(temp_buffer.data(), static_cast(temp_buffer.size())); const auto count = std::max(read_count, static_cast(0)); - commit_file_data(std::string_view(temp_buffer.data(), count), c.emu, io_status_block, buffer); + commit_file_data(std::string_view(temp_buffer.data(), static_cast(count)), c.emu, io_status_block, + buffer); return STATUS_SUCCESS; } @@ -848,4 +849,4 @@ namespace syscalls return STATUS_NOT_SUPPORTED; } -} \ No newline at end of file +} diff --git a/src/windows-emulator/syscalls/locale.cpp b/src/windows-emulator/syscalls/locale.cpp index 418993bb..c1768148 100644 --- a/src/windows-emulator/syscalls/locale.cpp +++ b/src/windows-emulator/syscalls/locale.cpp @@ -17,7 +17,7 @@ namespace syscalls return STATUS_FILE_INVALID; } - const auto size = page_align_up(locale_file.size()); + const auto size = static_cast(page_align_up(locale_file.size())); const auto base = c.win_emu.memory.allocate_memory(size, memory_permission::read); c.emu.write_memory(base, locale_file.data(), locale_file.size()); @@ -58,4 +58,4 @@ namespace syscalls { return STATUS_NOT_SUPPORTED; } -} \ No newline at end of file +} diff --git a/src/windows-emulator/syscalls/memory.cpp b/src/windows-emulator/syscalls/memory.cpp index 7e12521d..26d3cb98 100644 --- a/src/windows-emulator/syscalls/memory.cpp +++ b/src/windows-emulator/syscalls/memory.cpp @@ -41,8 +41,8 @@ namespace syscalls assert(!region_info.is_committed || region_info.is_reserved); const auto state = region_info.is_reserved ? MEM_RESERVE : MEM_FREE; image_info.State = region_info.is_committed ? MEM_COMMIT : state; - image_info.BaseAddress = reinterpret_cast(region_info.start); - image_info.AllocationBase = reinterpret_cast(region_info.allocation_base); + image_info.BaseAddress = region_info.start; + image_info.AllocationBase = region_info.allocation_base; image_info.PartitionId = 0; image_info.RegionSize = static_cast(region_info.length); @@ -151,7 +151,8 @@ namespace syscalls try { - c.win_emu.memory.protect_memory(aligned_start, aligned_length, requested_protection, &old_protection_value); + c.win_emu.memory.protect_memory(aligned_start, static_cast(aligned_length), requested_protection, + &old_protection_value); } catch (...) { @@ -183,7 +184,7 @@ namespace syscalls auto potential_base = base_address.read(); if (!potential_base) { - potential_base = c.win_emu.memory.find_free_allocation_base(allocation_bytes); + potential_base = c.win_emu.memory.find_free_allocation_base(static_cast(allocation_bytes)); } if (!potential_base) @@ -203,7 +204,8 @@ namespace syscalls throw std::runtime_error("Unsupported allocation type!"); } - if (commit && !reserve && c.win_emu.memory.commit_memory(potential_base, allocation_bytes, protection)) + if (commit && !reserve && + c.win_emu.memory.commit_memory(potential_base, static_cast(allocation_bytes), protection)) { c.win_emu.log.print(color::dark_gray, "--> Committed 0x%" PRIx64 " - 0x%" PRIx64 "\n", potential_base, potential_base + allocation_bytes); @@ -214,7 +216,8 @@ namespace syscalls c.win_emu.log.print(color::dark_gray, "--> Allocated 0x%" PRIx64 " - 0x%" PRIx64 "\n", potential_base, potential_base + allocation_bytes); - return c.win_emu.memory.allocate_memory(potential_base, allocation_bytes, protection, !commit) + return c.win_emu.memory.allocate_memory(potential_base, static_cast(allocation_bytes), protection, + !commit) ? STATUS_SUCCESS : STATUS_MEMORY_NOT_ALLOCATED; } @@ -242,14 +245,16 @@ namespace syscalls if (free_type & MEM_RELEASE) { - return c.win_emu.memory.release_memory(allocation_base, allocation_size) ? STATUS_SUCCESS - : STATUS_MEMORY_NOT_ALLOCATED; + return c.win_emu.memory.release_memory(allocation_base, static_cast(allocation_size)) + ? STATUS_SUCCESS + : STATUS_MEMORY_NOT_ALLOCATED; } if (free_type & MEM_DECOMMIT) { - return c.win_emu.memory.decommit_memory(allocation_base, allocation_size) ? STATUS_SUCCESS - : STATUS_MEMORY_NOT_ALLOCATED; + return c.win_emu.memory.decommit_memory(allocation_base, static_cast(allocation_size)) + ? STATUS_SUCCESS + : STATUS_MEMORY_NOT_ALLOCATED; } throw std::runtime_error("Bad free type"); @@ -284,4 +289,4 @@ namespace syscalls { return STATUS_NOT_SUPPORTED; } -} \ No newline at end of file +} diff --git a/src/windows-emulator/syscalls/port.cpp b/src/windows-emulator/syscalls/port.cpp index 28e91e8b..bfade094 100644 --- a/src/windows-emulator/syscalls/port.cpp +++ b/src/windows-emulator/syscalls/port.cpp @@ -27,7 +27,8 @@ namespace syscalls } client_shared_memory.access([&](PORT_VIEW64& view) { - p.view_base = c.win_emu.memory.allocate_memory(view.ViewSize, memory_permission::read_write); + p.view_base = + c.win_emu.memory.allocate_memory(static_cast(view.ViewSize), memory_permission::read_write); view.ViewBase = p.view_base; view.ViewRemoteBase = view.ViewBase; }); @@ -76,4 +77,4 @@ namespace syscalls { return STATUS_NOT_SUPPORTED; } -} \ No newline at end of file +} diff --git a/src/windows-emulator/syscalls/section.cpp b/src/windows-emulator/syscalls/section.cpp index 415206dd..fab75901 100644 --- a/src/windows-emulator/syscalls/section.cpp +++ b/src/windows-emulator/syscalls/section.cpp @@ -227,7 +227,7 @@ namespace syscalls const auto reserve_only = section_entry->allocation_attributes == SEC_RESERVE; const auto protection = map_nt_to_emulator_protection(section_entry->section_page_protection); - const auto address = c.win_emu.memory.allocate_memory(size, protection, reserve_only); + const auto address = c.win_emu.memory.allocate_memory(static_cast(size), protection, reserve_only); if (!reserve_only && !file_data.empty()) { @@ -289,4 +289,4 @@ namespace syscalls { return handle_NtUnmapViewOfSection(c, process_handle, base_address); } -} \ No newline at end of file +} diff --git a/src/windows-emulator/windows_emulator.cpp b/src/windows-emulator/windows_emulator.cpp index 30bf3123..4cb8b45f 100644 --- a/src/windows-emulator/windows_emulator.cpp +++ b/src/windows-emulator/windows_emulator.cpp @@ -341,8 +341,8 @@ void windows_emulator::setup_process(const application_settings& app_settings) this->process.setup(this->emu(), this->memory, app_settings, *executable, *ntdll, apiset_data); - const auto ntdll_data = emu.read_memory(ntdll->image_base, ntdll->size_of_image); - const auto win32u_data = emu.read_memory(win32u->image_base, win32u->size_of_image); + const auto ntdll_data = emu.read_memory(ntdll->image_base, static_cast(ntdll->size_of_image)); + const auto win32u_data = emu.read_memory(win32u->image_base, static_cast(win32u->size_of_image)); this->dispatcher.setup(ntdll->exports, ntdll_data, win32u->exports, win32u_data); @@ -601,7 +601,7 @@ void windows_emulator::start(size_t count) break; } - count = target_instructions - current_instructions; + count = static_cast(target_instructions - current_instructions); } } } diff --git a/src/windows-gdb-stub/x64_gdb_stub_handler.hpp b/src/windows-gdb-stub/x64_gdb_stub_handler.hpp index aa519acd..3fb33992 100644 --- a/src/windows-gdb-stub/x64_gdb_stub_handler.hpp +++ b/src/windows-gdb-stub/x64_gdb_stub_handler.hpp @@ -10,7 +10,7 @@ struct breakpoint_key { - size_t addr{}; + uint64_t addr{}; size_t size{}; gdb_stub::breakpoint_type type{}; @@ -25,7 +25,7 @@ struct std::hash { std::size_t operator()(const breakpoint_key& k) const noexcept { - return ((std::hash()(k.addr) ^ (std::hash()(k.size) << 1)) >> 1) ^ + return ((std::hash()(k.addr) ^ (std::hash()(k.size) << 1)) >> 1) ^ (std::hash()(static_cast(k.type)) << 1); } };