mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-21 04:33:56 +00:00
Support concise debugger output
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <memory_region.hpp>
|
||||
|
||||
struct exported_symbol
|
||||
{
|
||||
@@ -11,6 +12,12 @@ struct exported_symbol
|
||||
using exported_symbols = std::vector<exported_symbol>;
|
||||
using address_name_mapping = std::map<uint64_t, std::string>;
|
||||
|
||||
struct mapped_section
|
||||
{
|
||||
std::string name{};
|
||||
basic_memory_region region{};
|
||||
};
|
||||
|
||||
struct mapped_module
|
||||
{
|
||||
std::string name{};
|
||||
@@ -23,6 +30,8 @@ struct mapped_module
|
||||
exported_symbols exports{};
|
||||
address_name_mapping address_names{};
|
||||
|
||||
std::vector<mapped_section> sections{};
|
||||
|
||||
bool is_within(const uint64_t address) const
|
||||
{
|
||||
return address >= this->image_base && address < (this->image_base + this->size_of_image);
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace
|
||||
return nt_headers_offset + (first_section_absolute - absolute_base);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> read_mapped_memory(emulator& emu, const mapped_module& binary)
|
||||
std::vector<uint8_t> read_mapped_memory(const emulator& emu, const mapped_module& binary)
|
||||
{
|
||||
std::vector<uint8_t> memory{};
|
||||
memory.resize(binary.size_of_image);
|
||||
@@ -132,7 +132,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void map_sections(emulator& emu, const mapped_module& binary,
|
||||
void map_sections(emulator& emu, mapped_module& binary,
|
||||
const utils::safe_buffer_accessor<const uint8_t> buffer,
|
||||
const IMAGE_NT_HEADERS& nt_headers, const uint64_t nt_headers_offset)
|
||||
{
|
||||
@@ -171,6 +171,18 @@ namespace
|
||||
const auto size_of_section = page_align_up(std::max(section.SizeOfRawData, section.Misc.VirtualSize));
|
||||
|
||||
emu.protect_memory(target_ptr, 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.permissions = permissions;
|
||||
|
||||
for (size_t j = 0; j < sizeof(section.Name) && section.Name[j]; ++j)
|
||||
{
|
||||
section_info.name.push_back(static_cast<char>(section.Name[j]));
|
||||
}
|
||||
|
||||
binary.sections.push_back(std::move(section_info));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -800,7 +800,7 @@ namespace
|
||||
: (region_info.is_reserved
|
||||
? MEM_RESERVE
|
||||
: MEM_FREE);
|
||||
image_info.Protect = map_emulator_to_nt_protection(region_info.pemissions);
|
||||
image_info.Protect = map_emulator_to_nt_protection(region_info.permissions);
|
||||
image_info.Type = MEM_PRIVATE;
|
||||
});
|
||||
|
||||
@@ -1259,6 +1259,24 @@ namespace
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (info_class == ProcessTimes)
|
||||
{
|
||||
if (return_length)
|
||||
{
|
||||
return_length.write(sizeof(KERNEL_USER_TIMES));
|
||||
}
|
||||
|
||||
if (process_information_length != sizeof(KERNEL_USER_TIMES))
|
||||
{
|
||||
return STATUS_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
const emulator_object<KERNEL_USER_TIMES> info{c.emu, process_information};
|
||||
info.write(KERNEL_USER_TIMES{});
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (info_class == ProcessBasicInformation)
|
||||
{
|
||||
if (return_length)
|
||||
|
||||
@@ -875,8 +875,15 @@ void windows_emulator::setup_hooks()
|
||||
process.previous_ip = process.current_ip;
|
||||
process.current_ip = this->emu().read_instruction_pointer();
|
||||
|
||||
const auto is_main_exe = process.executable->is_within(address);
|
||||
const auto is_interesting_call = process.executable->is_within(
|
||||
process.previous_ip) || process.executable->is_within(address);
|
||||
process.previous_ip) || is_main_exe;
|
||||
|
||||
if (this->silent_until_main_ && is_main_exe)
|
||||
{
|
||||
this->silent_until_main_ = false;
|
||||
this->logger.disable_output(false);
|
||||
}
|
||||
|
||||
if (!this->verbose && !this->verbose_calls && !is_interesting_call)
|
||||
{
|
||||
@@ -887,15 +894,6 @@ void windows_emulator::setup_hooks()
|
||||
|
||||
if (binary)
|
||||
{
|
||||
const auto is_entry_point = address == binary->entry_point;
|
||||
|
||||
if (this->silent_until_main_ && is_entry_point && binary == this->process_
|
||||
.executable)
|
||||
{
|
||||
this->silent_until_main_ = false;
|
||||
this->logger.disable_output(false);
|
||||
}
|
||||
|
||||
const auto export_entry = binary->address_names.find(address);
|
||||
if (export_entry != binary->address_names.end())
|
||||
{
|
||||
@@ -904,7 +902,7 @@ void windows_emulator::setup_hooks()
|
||||
binary->name.c_str(),
|
||||
export_entry->second.c_str(), address);
|
||||
}
|
||||
else if (is_entry_point)
|
||||
else if (address == binary->entry_point)
|
||||
{
|
||||
logger.print(is_interesting_call ? color::yellow : color::gray,
|
||||
"Executing entry point: %s (0x%llX)\n",
|
||||
|
||||
Reference in New Issue
Block a user