Skip to content

Commit

Permalink
Add adbg_object_format, rename some PE functions for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Jan 2, 2025
1 parent 82769bc commit e78c561
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
10 changes: 5 additions & 5 deletions dumper/format/pe.d
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void dump_pe_exports(adbg_object_t *o) {
print_x32("Timestamp", Timestamp);
print_x16("MajorVersion", MajorVersion);
print_x16("MinorVersion", MinorVersion);
print_x32("Name", Name, adbg_object_pe_export_module_name(o, export_));
print_x32("Name", Name, adbg_object_pe_export_name(o, export_));
print_x32("OrdinalBase", OrdinalBase);
print_x32("AddressTableEntries", AddressTableEntries);
print_x32("NumberOfNamePointers", NumberOfNamePointers);
Expand All @@ -523,8 +523,8 @@ void dump_pe_exports(adbg_object_t *o) {

pe_export_entry_t *entry = void;
size_t ie;
while ((entry = adbg_object_pe_export_entry_name(o, export_, ie++)) != null) {
print_x32("Export", entry.Export, adbg_object_pe_export_name_string(o, export_, entry));
while ((entry = adbg_object_pe_export_entry(o, export_, ie++)) != null) {
print_x32("Export", entry.Export, adbg_object_pe_export_entry_symbol(o, export_, entry));
}
}

Expand All @@ -534,7 +534,7 @@ void dump_pe_imports(adbg_object_t *o) {
size_t i;
while ((import_ = adbg_object_pe_import(o, i)) != null) with (import_) {
i++;
const(char)* module_name = adbg_object_pe_import_module_name(o, import_);
const(char)* module_name = adbg_object_pe_import_name(o, import_);
if (module_name == null)
panic_adbg();

Expand All @@ -554,7 +554,7 @@ void dump_pe_imports(adbg_object_t *o) {
print_stringf("Import", "0x%08x 0x%04x %s",
adbg_object_pe_import_entry_rva(o, import_, entry),
adbg_object_pe_import_entry_hint(o, import_, entry),
adbg_object_pe_import_entry_string(o, import_, entry));
adbg_object_pe_import_entry_symbol(o, import_, entry));
}
// A PE32 image with an import table and no symbols would be weird
if (i2 == 0)
Expand Down
25 changes: 16 additions & 9 deletions src/adbg/objects/pe.d
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ struct pe_import_entry64_t { align(1):
}
}

union pe_import_entry_t { align(1):
pe_import_entry32_t entry32;
pe_import_entry64_t entry64;
}

//
// ANCHOR Debug information
//
Expand Down Expand Up @@ -1537,7 +1542,7 @@ pe_export_descriptor_t* adbg_object_pe_export(adbg_object_t *o) {
return internal.export_directory;
}

const(char)* adbg_object_pe_export_module_name(adbg_object_t *o, pe_export_descriptor_t *export_) {
const(char)* adbg_object_pe_export_name(adbg_object_t *o, pe_export_descriptor_t *export_) {
if (o == null || export_ == null) {
adbg_oops(AdbgError.invalidArgument);
return null;
Expand Down Expand Up @@ -1566,7 +1571,7 @@ const(char)* adbg_object_pe_export_module_name(adbg_object_t *o, pe_export_descr
return cast(const(char)*)base;
}

pe_export_entry_t* adbg_object_pe_export_entry_name(adbg_object_t *o, pe_export_descriptor_t *export_, size_t index) {
pe_export_entry_t* adbg_object_pe_export_entry(adbg_object_t *o, pe_export_descriptor_t *export_, size_t index) {
if (o == null || export_ == null) {
adbg_oops(AdbgError.invalidArgument);
return null;
Expand Down Expand Up @@ -1604,15 +1609,17 @@ pe_export_entry_t* adbg_object_pe_export_entry_name(adbg_object_t *o, pe_export_
return null;
}

if (o.status & AdbgObjectInternalFlags.reversed && internal.r_export_entries[index] == false) with (entry) {
// Bswap entry if necessary
if (o.status & AdbgObjectInternalFlags.reversed &&
internal.r_export_entries[index] == false) with (entry) {
entry.Export = adbg_bswap32(entry.Export);
internal.r_export_entries[index] = true;
}

return entry;
}

const(char)* adbg_object_pe_export_name_string(adbg_object_t *o,
const(char)* adbg_object_pe_export_entry_symbol(adbg_object_t *o,
pe_export_descriptor_t *export_, pe_export_entry_t *entry) {
if (o == null || export_ == null || entry == null) {
adbg_oops(AdbgError.invalidArgument);
Expand Down Expand Up @@ -1761,7 +1768,7 @@ pe_import_descriptor_t* adbg_object_pe_import(adbg_object_t *o, size_t index) {
}

// get module name out of import descriptor
const(char)* adbg_object_pe_import_module_name(adbg_object_t *o, pe_import_descriptor_t *import_) {
const(char)* adbg_object_pe_import_name(adbg_object_t *o, pe_import_descriptor_t *import_) {
if (o == null || import_ == null) {
adbg_oops(AdbgError.invalidArgument);
return null;
Expand Down Expand Up @@ -1928,7 +1935,7 @@ pe_import_entry64_t* adbg_object_pe_import_entry64(adbg_object_t *o, pe_import_d
// Classless functions
// TODO: Optimize these, maybe cache the last result in internals

void* adbg_object_pe_import_entry(adbg_object_t *o, pe_import_descriptor_t *import_, size_t index) {
pe_import_entry_t* adbg_object_pe_import_entry(adbg_object_t *o, pe_import_descriptor_t *import_, size_t index) {
if (o == null || import_ == null) {
adbg_oops(AdbgError.invalidArgument);
return null;
Expand All @@ -1947,9 +1954,9 @@ void* adbg_object_pe_import_entry(adbg_object_t *o, pe_import_descriptor_t *impo

switch (internal.optheader.Magic) {
case PE_CLASS_32:
return adbg_object_pe_import_entry32(o, import_, index);
return cast(pe_import_entry_t*)adbg_object_pe_import_entry32(o, import_, index);
case PE_CLASS_64:
return adbg_object_pe_import_entry64(o, import_, index);
return cast(pe_import_entry_t*)adbg_object_pe_import_entry64(o, import_, index);
default:
adbg_oops(AdbgError.objectInvalidClass);
return null;
Expand Down Expand Up @@ -2047,7 +2054,7 @@ ushort adbg_object_pe_import_entry_hint(adbg_object_t *o, pe_import_descriptor_t
return *hint;
}

const(char)* adbg_object_pe_import_entry_string(adbg_object_t *o, pe_import_descriptor_t *import_, void *entry) {
const(char)* adbg_object_pe_import_entry_symbol(adbg_object_t *o, pe_import_descriptor_t *import_, void *entry) {
if (o == null || import_ == null || entry == null) {
adbg_oops(AdbgError.invalidArgument);
return null;
Expand Down
13 changes: 13 additions & 0 deletions src/adbg/objectserver.d
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,18 @@ const(char)* adbg_object_machine_string(adbg_object_t *o) {
return adbg_machine_name( adbg_object_machine(o) );
}

/// Get the object format.
/// Params: o = Object instance.
/// Returns: Object format, see AdbgObject enum.
int adbg_object_format(adbg_object_t *o) {
if (o == null)
return 0;
return o.format;
}

// TODO: Rename to adbg_object_format_shortname
// "Type" is better attributed to object type,
// as in "executable", "dynamic library", etc.
/// Get the short name of the loaded object type.
/// Params: o = Object instance.
/// Returns: Object type name.
Expand Down Expand Up @@ -746,6 +758,7 @@ Lunknown:
}
}

// TODO: Rename to adbg_object_format_name
/// Get the full name of the loaded object type.
/// Params: o = Object instance.
/// Returns: Object type name.
Expand Down

0 comments on commit e78c561

Please sign in to comment.