Skip to content

Commit

Permalink
More fixes to symbol use in output.
Browse files Browse the repository at this point in the history
  • Loading branch information
OmniBlade committed Feb 15, 2024
1 parent 416b3d6 commit 7bb83ba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ unassemblize::Executable::Executable(const char *file_name, OutputFormats format
m_dataAlignment(sizeof(uint32_t)),
m_codePad(0x90), // NOP
m_dataPad(0x00),
m_verbose(verbose)
m_verbose(verbose),
m_addBase(false)
{
if (m_verbose) {
printf("Loading section info...\n");
}

bool checked_image_base = false;
bool add_image_base = false;

for (auto it = m_binary->sections().begin(); it != m_binary->sections().end(); ++it) {
if (!it->name().empty() && it->size() != 0) {
Expand All @@ -47,11 +47,11 @@ unassemblize::Executable::Executable(const char *file_name, OutputFormats format

// Check on first section incase binary is huge and later sections start higher than imagebase.
if (!checked_image_base && it->virtual_address() <= m_binary->imagebase()) {
add_image_base = true;
m_addBase = true;
}

// For PE format virtual_address appears to be an offset, in ELF/Mach-O it appears to be absolute.
if (add_image_base) {
if (m_addBase) {
section.address = m_binary->imagebase() + it->virtual_address();
} else {
section.address = it->virtual_address();
Expand Down
1 change: 1 addition & 0 deletions executable.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class Executable
uint8_t m_codePad;
uint8_t m_dataPad;
bool m_verbose;
bool m_addBase;

static const char s_symbolSection[];
static const char s_sectionsSection[];
Expand Down
5 changes: 5 additions & 0 deletions function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ static ZyanStatus UnasmFormatterFormatOperandMEM(
char hex_buff[32];
const unassemblize::Executable::Symbol &symbol = func->executable().get_symbol(address);

if ((context->operand->mem.type == ZYDIS_MEMOP_TYPE_MEM) || (context->operand->mem.type == ZYDIS_MEMOP_TYPE_VSIB)) {
ZYAN_CHECK(formatter->func_print_typecast(formatter, buffer, context));
}
ZYAN_CHECK(formatter->func_print_segment(formatter, buffer, context));

if (!symbol.name.empty()) {
ZYAN_CHECK(ZydisFormatterBufferAppend(buffer, ZYDIS_TOKEN_SYMBOL));
ZyanString *string;
Expand Down

0 comments on commit 7bb83ba

Please sign in to comment.