More cleanup and fixes

This commit is contained in:
momo5502
2024-08-21 20:40:18 +02:00
parent c66ada8470
commit e98aa7ba07
4 changed files with 15 additions and 24 deletions

View File

@@ -34,6 +34,7 @@ public:
virtual void read_raw_register(int reg, void* value, size_t size) = 0;
virtual void write_raw_register(int reg, const void* value, size_t size) = 0;
virtual bool try_map_memory(uint64_t address, size_t size, memory_permission permissions) = 0;
virtual void map_memory(uint64_t address, size_t size, memory_permission permissions) = 0;
virtual void unmap_memory(uint64_t address, size_t size) = 0;

View File

@@ -53,10 +53,11 @@ namespace unicorn
this->uc_ = obj.uc_;
this->hook_ = obj.hook_;
obj.hook_ = {};
obj.uc_ = {};
}
return *this;
}

View File

@@ -148,6 +148,7 @@ namespace unicorn
~unicorn_x64_emulator() override
{
this->hooks_.clear();
uc_close(this->uc_);
}
@@ -196,6 +197,11 @@ namespace unicorn
uce(uc_mem_map(*this, address, size, static_cast<uint32_t>(permissions)));
}
bool try_map_memory(const uint64_t address, const size_t size, memory_permission permissions) override
{
return uc_mem_map(*this, address, size, static_cast<uint32_t>(permissions)) == UC_ERR_OK;
}
void unmap_memory(const uint64_t address, const size_t size) override
{
uce(uc_mem_unmap(*this, address, size));

View File

@@ -400,21 +400,13 @@ namespace
while (true)
{
try
succeeded = emu.try_map_memory(allocation_base, allocation_bytes, protection);
if (succeeded || !allocate_anywhere)
{
emu.map_memory(allocation_base, allocation_bytes, protection);
succeeded = true;
break;
}
catch (...)
{
if (!allocate_anywhere)
{
break;
}
allocation_base += allocation_granularity;
}
allocation_base += allocation_granularity;
}
base_address.write(allocation_base);
@@ -463,22 +455,13 @@ namespace
while (true)
{
try
succeeded = emu.try_map_memory(allocation_base, allocation_bytes, protection);
if (succeeded || !allocate_anywhere)
{
emu.map_memory(allocation_base, allocation_bytes, protection);
succeeded = true;
break;
}
catch (...)
{
succeeded = false;
if (!allocate_anywhere)
{
break;
}
allocation_base += allocation_granularity;
}
allocation_base += allocation_granularity;
}
base_address.write(allocation_base);