More fixes

This commit is contained in:
Maurice Heumann
2025-07-17 18:55:16 +02:00
parent 3c05c7a607
commit 6e71e495bc
2 changed files with 31 additions and 28 deletions

View File

@@ -21,17 +21,41 @@ namespace
}
return ss.str();
}
void parse_and_accumulate_changes(const std::string& line, std::map<std::string, std::string>& changes)
{
size_t start = 0;
while (start < line.length())
{
size_t end = line.find(',', start);
if (end == std::string::npos)
{
end = line.length();
}
std::string pair_str = line.substr(start, end - start);
size_t equals_pos = pair_str.find('=');
if (equals_pos != std::string::npos)
{
std::string key = pair_str.substr(0, equals_pos);
std::string value = pair_str.substr(equals_pos + 1);
changes[key] = value;
}
start = end + 1;
}
}
}
TenetTracer::TenetTracer(windows_emulator& win_emu, const std::string& log_filename)
: m_win_emu(win_emu),
m_log_file(log_filename)
{
if (!m_log_file.is_open())
if (!m_log_file)
{
throw std::runtime_error("TenetTracer: Failed to open log file -> " + log_filename);
}
// Set up memory hooks.
auto& emu = m_win_emu.emu();
auto* read_hook = emu.hook_memory_read(0, 0xFFFFFFFFFFFFFFFF, [this](uint64_t a, const void* d, size_t s) {
this->log_memory_read(a, d, s); //
@@ -48,7 +72,6 @@ TenetTracer::TenetTracer(windows_emulator& win_emu, const std::string& log_filen
TenetTracer::~TenetTracer()
{
// Filter and write the buffer when the program ends.
filter_and_write_buffer();
if (m_log_file.is_open())
@@ -57,31 +80,6 @@ TenetTracer::~TenetTracer()
}
}
// Helper function: Parses a log line and adds register changes to the map.
static void parse_and_accumulate_changes(const std::string& line, std::map<std::string, std::string>& changes)
{
size_t start = 0;
while (start < line.length())
{
size_t end = line.find(',', start);
if (end == std::string::npos)
{
end = line.length();
}
std::string pair_str = line.substr(start, end - start);
size_t equals_pos = pair_str.find('=');
if (equals_pos != std::string::npos)
{
std::string key = pair_str.substr(0, equals_pos);
std::string value = pair_str.substr(equals_pos + 1);
changes[key] = value; // Updates existing or adds a new one.
}
start = end + 1;
}
}
void TenetTracer::filter_and_write_buffer()
{
if (m_raw_log_buffer.empty())

View File

@@ -38,6 +38,11 @@ class TenetTracer
TenetTracer(windows_emulator& win_emu, const std::string& log_filename);
~TenetTracer();
TenetTracer(TenetTracer&) = delete;
TenetTracer(const TenetTracer&) = delete;
TenetTracer& operator=(TenetTracer&) = delete;
TenetTracer& operator=(const TenetTracer&) = delete;
void process_instruction(uint64_t address);
private: