mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-11 16:46:16 +00:00
Small optimizations
This commit is contained in:
@@ -10,7 +10,7 @@ struct emulator_hook;
|
||||
|
||||
using memory_operation = memory_permission;
|
||||
|
||||
using instruction_hook_callback = std::function<void(uint64_t address)>;
|
||||
using hook_callback = std::function<void()>;
|
||||
|
||||
using simple_memory_hook_callback = std::function<void(uint64_t address, size_t size)>;
|
||||
using complex_memory_hook_callback = std::function<void(uint64_t address, size_t size, memory_operation operation)>;
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
virtual emulator_hook* hook_memory_access(uint64_t address, size_t size, memory_operation filter,
|
||||
complex_memory_hook_callback callback) = 0;
|
||||
virtual emulator_hook* hook_instruction(int instruction_type, instruction_hook_callback callback) = 0;
|
||||
virtual emulator_hook* hook_instruction(int instruction_type, hook_callback callback) = 0;
|
||||
|
||||
virtual void delete_hook(emulator_hook* hook) = 0;
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "emulator.hpp"
|
||||
|
||||
using simple_instruction_hook_callback = std::function<void()>;
|
||||
|
||||
template <typename PointerType, typename Register, Register InstructionPointer, Register
|
||||
StackPointer, typename HookableInstructions>
|
||||
class typed_emulator : public emulator
|
||||
@@ -62,23 +60,13 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
emulator_hook* hook_instruction(hookable_instructions instruction_type, instruction_hook_callback callback)
|
||||
emulator_hook* hook_instruction(hookable_instructions instruction_type, hook_callback callback)
|
||||
{
|
||||
return this->hook_instruction(instruction_type, [this, c = std::move(callback)]
|
||||
{
|
||||
const auto ip = static_cast<uint64_t>(this->read_instruction_pointer());
|
||||
c(ip);
|
||||
});
|
||||
return this->hook_instruction(static_cast<int>(instruction_type), std::move(callback));
|
||||
}
|
||||
|
||||
virtual emulator_hook* hook_instruction(hookable_instructions instruction_type,
|
||||
simple_instruction_hook_callback callback) = 0;
|
||||
|
||||
private:
|
||||
emulator_hook* hook_instruction(int instruction_type, instruction_hook_callback callback) override
|
||||
{
|
||||
return this->hook_instruction(static_cast<hookable_instructions>(instruction_type), std::move(callback));
|
||||
}
|
||||
emulator_hook* hook_instruction(int instruction_type, hook_callback callback) override = 0;
|
||||
|
||||
void read_raw_register(int reg, void* value, size_t size) override = 0;
|
||||
void write_raw_register(int reg, const void* value, size_t size) override = 0;
|
||||
|
||||
@@ -243,10 +243,11 @@ namespace unicorn
|
||||
return result;
|
||||
}
|
||||
|
||||
emulator_hook* hook_instruction(x64_hookable_instructions instruction_type,
|
||||
simple_instruction_hook_callback callback)
|
||||
emulator_hook* hook_instruction(int instruction_type,
|
||||
hook_callback callback)
|
||||
{
|
||||
const auto uc_instruction = map_hookable_instruction(instruction_type);
|
||||
const auto uc_instruction = map_hookable_instruction(
|
||||
static_cast<x64_hookable_instructions>(instruction_type));
|
||||
|
||||
function_wrapper<void, uc_engine*> wrapper([c = std::move(callback)](uc_engine*)
|
||||
{
|
||||
|
||||
@@ -507,7 +507,7 @@ namespace
|
||||
|
||||
void handle_syscall(x64_emulator& emu, process_context& context)
|
||||
{
|
||||
const auto address = emu.reg(x64_register::rip);
|
||||
const auto address = emu.read_instruction_pointer();
|
||||
const auto syscall_id = emu.reg<uint32_t>(x64_register::eax);
|
||||
|
||||
printf("Handling syscall: %X (%llX)\n", syscall_id, address);
|
||||
|
||||
Reference in New Issue
Block a user