mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-20 20:23:57 +00:00
Try upgrading unicorn
This commit is contained in:
2
deps/unicorn
vendored
2
deps/unicorn
vendored
Submodule deps/unicorn updated: 1cdd062a45...2c320ce510
@@ -2,12 +2,13 @@
|
||||
#include "unicorn_x86_64_emulator.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <ranges>
|
||||
#include <optional>
|
||||
|
||||
#include "unicorn_memory_regions.hpp"
|
||||
#include "unicorn_hook.hpp"
|
||||
|
||||
#include "function_wrapper.hpp"
|
||||
#include <ranges>
|
||||
|
||||
namespace unicorn
|
||||
{
|
||||
@@ -212,8 +213,9 @@ namespace unicorn
|
||||
|
||||
void start(const size_t count) override
|
||||
{
|
||||
this->has_violation_ = false;
|
||||
const auto start = this->read_instruction_pointer();
|
||||
const auto start = this->violation_ip_.value_or(this->read_instruction_pointer());
|
||||
this->violation_ip_ = std::nullopt;
|
||||
|
||||
constexpr auto end = std::numeric_limits<uint64_t>::max();
|
||||
const auto res = uc_emu_start(*this, start, end, 0, count);
|
||||
if (res == UC_ERR_OK)
|
||||
@@ -229,7 +231,7 @@ namespace unicorn
|
||||
res == UC_ERR_WRITE_PROT || //
|
||||
res == UC_ERR_FETCH_PROT;
|
||||
|
||||
if (!is_violation || !this->has_violation_)
|
||||
if (!is_violation || !this->has_violation())
|
||||
{
|
||||
uce(res);
|
||||
}
|
||||
@@ -381,8 +383,22 @@ namespace unicorn
|
||||
|
||||
if (inst_type == x86_hookable_instructions::invalid)
|
||||
{
|
||||
function_wrapper<int, uc_engine*> wrapper([c = std::move(callback)](uc_engine*) {
|
||||
return (c() == instruction_hook_continuation::skip_instruction) ? 1 : 0;
|
||||
function_wrapper<int, uc_engine*> wrapper([this, c = std::move(callback)](uc_engine*) {
|
||||
const auto ip = this->read_instruction_pointer();
|
||||
const auto skip = c() == instruction_hook_continuation::skip_instruction;
|
||||
const auto new_ip = this->read_instruction_pointer();
|
||||
const auto has_ip_changed = ip != new_ip;
|
||||
|
||||
if (skip && has_ip_changed)
|
||||
{
|
||||
// this->violation_ip_ = new_ip;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->violation_ip_ = std::nullopt;
|
||||
}
|
||||
|
||||
return skip ? 1 : 0;
|
||||
});
|
||||
|
||||
uce(uc_hook_add(*this, hook.make_reference(), UC_HOOK_INSN_INVALID, wrapper.get_function(),
|
||||
@@ -477,14 +493,22 @@ namespace unicorn
|
||||
const auto resume = c(address, static_cast<uint64_t>(size), operation, violation) ==
|
||||
memory_violation_continuation::resume;
|
||||
|
||||
const auto has_ip_changed = ip != this->read_instruction_pointer();
|
||||
const auto new_ip = this->read_instruction_pointer();
|
||||
const auto has_ip_changed = ip != new_ip;
|
||||
|
||||
if (!resume)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this->has_violation_ = resume && has_ip_changed;
|
||||
if (resume && has_ip_changed)
|
||||
{
|
||||
this->violation_ip_ = new_ip;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->violation_ip_ = std::nullopt;
|
||||
}
|
||||
|
||||
if (has_ip_changed)
|
||||
{
|
||||
@@ -657,7 +681,7 @@ namespace unicorn
|
||||
|
||||
bool has_violation() const override
|
||||
{
|
||||
return this->has_violation_;
|
||||
return this->violation_ip_.has_value();
|
||||
}
|
||||
|
||||
std::string get_name() const override
|
||||
@@ -668,7 +692,7 @@ namespace unicorn
|
||||
private:
|
||||
mutable bool has_snapshots_{false};
|
||||
uc_engine* uc_{};
|
||||
bool has_violation_{false};
|
||||
std::optional<uint64_t> violation_ip_{};
|
||||
std::vector<std::unique_ptr<hook_object>> hooks_{};
|
||||
std::unordered_map<uint64_t, mmio_callbacks> mmio_{};
|
||||
};
|
||||
|
||||
@@ -451,11 +451,14 @@ void windows_emulator::setup_hooks()
|
||||
const auto ticks = this->clock_->timestamp_counter();
|
||||
this->emu().reg(x86_register::rax, ticks & 0xFFFFFFFF);
|
||||
this->emu().reg(x86_register::rdx, (ticks >> 32) & 0xFFFFFFFF);
|
||||
|
||||
return instruction_hook_continuation::skip_instruction;
|
||||
});
|
||||
|
||||
// TODO: Unicorn needs this - This should be handled in the backend
|
||||
this->emu().hook_instruction(x86_hookable_instructions::invalid, [&] {
|
||||
// TODO: Unify icicle & unicorn handling
|
||||
dispatch_illegal_instruction_violation(this->emu(), this->process);
|
||||
return instruction_hook_continuation::skip_instruction; //
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user