Skip to content

Commit

Permalink
object: Add adbg_object_format_type and Summary view
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed May 2, 2024
1 parent dba4cd6 commit 48fc772
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 19 deletions.
15 changes: 12 additions & 3 deletions dumper/dumper.d
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ int dump(const(char)* path) {

// If anything was selected to dump specifically
if (opt_selected) {
// If not in any "extract" mode, print file info
if (setting_extract_any() == 0) {
print_string("filename", path);
print_u64("filesize", o.file_size);
Expand All @@ -150,16 +151,24 @@ int dump(const(char)* path) {
}

// Otherwise, make a basic summary
printf("%s: %s (%s)\n", path,
adbg_object_format_name(o), adbg_object_format_shortname(o));
printf("%s: %s (%s), %s\n", path,
adbg_object_format_name(o), adbg_object_format_shortname(o),
adbg_object_format_kind_string(o));

AdbgMachine mach = adbg_object_machine(o);
if (mach)
printf(", for %s (%s) machines",
adbg_object_machine_string(o), adbg_machine_alias(mach));

putchar('\n');
return 0;
}

private immutable {
/// Padding spacing to use in characters
// PE32 has fields like MinorOperatingSystemVersion (27 chars)
int __field_padding = -28;
/// Number of columns to produce in hexdumps.
/// Number of columns to produce in hexdumps, in bytes.
int __columns = 16;
}

Expand Down
5 changes: 1 addition & 4 deletions dumper/format/dmp.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ private:
void dump_dmp_header(adbg_object_t *o) {
print_header("Header");

bool is64 = o.i.dmp.header.ValidDumpInt == PAGEDUMP64_VALID;

dmp64_header *hdr64 = cast(dmp64_header*)o.i.dmp.header;
if (is64) with (hdr64) {
if (o.i.dmp.header.ValidDumpInt == PAGEDUMP64_VALID) with (o.i.dmp.header64) {
print_x32l("Signature", SignatureInt, Signature.ptr, 4);
print_x32l("ValidDump", ValidDumpInt, ValidDump.ptr, 4);
print_u32("MajorVersion", MajorVersion);
Expand Down
2 changes: 1 addition & 1 deletion src/adbg/disassembler.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import adbg.include.capstone;
import adbg.include.c.stdarg;
import adbg.error;
import adbg.debugger.process : adbg_process_t;
import adbg.machines : AdbgMachine, adbg_object_machine_alias;
import adbg.machines : AdbgMachine;
import adbg.debugger.exception : adbg_exception_t;
import adbg.debugger.memory : adbg_memory_read;
import core.stdc.string : memcpy;
Expand Down
2 changes: 1 addition & 1 deletion src/adbg/machines.d
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ immutable(adbg_machine_t)* adbg_machine(AdbgMachine mach) {
/// Get machine alias from enumeration value.
/// Params: mach = Machine value.
/// Returns: Machine name, or null if invalid.
const(char)* adbg_object_machine_alias(AdbgMachine mach) {
const(char)* adbg_machine_alias(AdbgMachine mach) {
immutable(adbg_machine_t)* m = adbg_machine(mach);
if (m == null) // Error already set.
return null;
Expand Down
2 changes: 2 additions & 0 deletions src/adbg/object/format/mz.d
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ int adbg_object_mz_load(adbg_object_t *o) {
}

o.format = AdbgObject.mz;

//TODO: Use internal API to get location
with (o.i.mz)
if (header.e_lfarlc && header.e_crlc && header.e_lfarlc < o.file_size) {
relocs = cast(mz_reloc*)(o.buffer + header.e_lfarlc);
Expand Down
62 changes: 52 additions & 10 deletions src/adbg/object/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import adbg.error;
import adbg.utils.bit;
import adbg.utils.math;
import adbg.object.formats;
import adbg.machines : AdbgMachine;
import adbg.machines : AdbgMachine, adbg_machine_name;
import adbg.debugger.process : adbg_process_t;
import adbg.debugger.memory : adbg_memory_map_t, adbg_memory_read;
import core.stdc.string;
Expand Down Expand Up @@ -99,11 +99,6 @@ enum AdbgObjectOrigin {
//TODO: user buffer (memory)
}

/// Object server options.
enum AdbgObjectLoadOption {
partial = 1,
}

package
enum AdbgObjectInternalFlags {
/// Object has its fields swapped because of its target endianness.
Expand Down Expand Up @@ -300,6 +295,7 @@ struct adbg_object_t {

struct dmp_t {
dmp_header *header;
dmp64_header *header64;
}
dmp_t dmp;

Expand Down Expand Up @@ -416,6 +412,11 @@ bool adbg_object_offsett(T)(adbg_object_t *o, T* dst, ulong offset) {
return false;
}

/// Object server options.
enum AdbgObjectLoadOption {
partial = 1,
}

/// Load an object from disk into memory.
///
/// This function allocates memory.
Expand Down Expand Up @@ -747,13 +748,17 @@ AdbgMachine adbg_object_machine(adbg_object_t *o) {
default: return AdbgMachine.unknown;
}
}
const(char)* adbg_object_machine_string(adbg_object_t *o) {
AdbgMachine mach = adbg_object_machine(o);
return mach ? adbg_machine_name(mach) : `Unknown`;
}

/// Get the short name of the loaded object format.
/// Params: o = Object instance.
/// Returns: Object format name.
const(char)* adbg_object_format_shortname(adbg_object_t *o) {
if (o == null)
goto L_UNKNOWN;
goto Lunknown;
final switch (o.format) with (AdbgObject) {
case mz: return "mz";
case ne: return "ne";
Expand All @@ -768,7 +773,7 @@ const(char)* adbg_object_format_shortname(adbg_object_t *o) {
case archive: return "archive";
case coff: return "coff";
case mscoff: return "mscoff";
L_UNKNOWN:
Lunknown:
case unknown: return "unknown";
}
}
Expand All @@ -778,7 +783,7 @@ const(char)* adbg_object_format_shortname(adbg_object_t *o) {
/// Returns: Object format name.
const(char)* adbg_object_format_name(adbg_object_t *o) {
if (o == null)
goto L_UNKNOWN;
goto Lunknown;
final switch (o.format) with (AdbgObject) {
case mz: return `Mark Zbikowski`;
case ne: return `New Executable`;
Expand All @@ -793,8 +798,45 @@ const(char)* adbg_object_format_name(adbg_object_t *o) {
case archive: return `Common Object File Format Library Archive`;
case coff: return `Common Object File Format`;
case mscoff: return `Microsoft Common Object File Format`;
L_UNKNOWN:
Lunknown:
case unknown: return "Unknown";
}
}

/*enum AdbgObjectKind {
unknown,
executable,
sharedObject,
}
AdbgObjectKind adbg_object_format_kind(adbg_object_t *o)*/

const(char)* adbg_object_format_kind_string(adbg_object_t *o) {
if (o == null)
goto Lunknown;
switch (o.format) with (AdbgObject) {
case mz:
return o.i.mz.header.e_ovno ? `Overlayed Executable` : `Executable`;
case ne:
return o.i.ne.header.ne_flags & NE_HFLAG_LIBMODULE ? `Library Module` : `Executable`;
case lx:
return adbg_object_lx_modtype_string(o.i.lx.header.mflags);
case pe:
return o.i.pe.header.Characteristics & PE_CHARACTERISTIC_DLL ? `Dynamically Linked Library` : `Executable`;
case macho:
if (o.i.macho.fat) return `Fat Executable`;
return adbg_object_macho_filetype_string(o.i.macho.header.filetype);
case elf:
return o.i.elf32.ehdr.e_type == ELF_ET_DYN ? `Shared Object` : `Executable`;
case pdb20, pdb70:
return `Debug Database`;
case mdmp, dmp:
return `Memory Dump`;
case archive:
return `Library`;
case coff, mscoff:
return `Object`;
default: Lunknown:
return `Unknown`;
}
}

0 comments on commit 48fc772

Please sign in to comment.