Skip to content

Commit

Permalink
object: Translation for PE32
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Aug 7, 2023
1 parent 6698a59 commit b944f11
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/adbg/v2/object/format/elf.d
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ AdbgMachine adbg_object_elf_machine(ushort machine) {
switch (machine) {
case ELF_EM_M32: return AdbgMachine.we32100;
case ELF_EM_SPARC: return AdbgMachine.sparc;
case ELF_EM_386: return AdbgMachine.x86_32;
case ELF_EM_386: return AdbgMachine.x86;
case ELF_EM_68K: return AdbgMachine.m68k;
case ELF_EM_88K: return AdbgMachine.m88k;
case ELF_EM_MCU: return AdbgMachine.mcu;
Expand Down Expand Up @@ -675,7 +675,7 @@ AdbgMachine adbg_object_elf_machine(ushort machine) {
case ELF_EM_ME16: return AdbgMachine.me16;
case ELF_EM_ST100: return AdbgMachine.st100;
case ELF_EM_TINYJ: return AdbgMachine.tinyj;
case ELF_EM_X86_64: return AdbgMachine.x86_64;
case ELF_EM_X86_64: return AdbgMachine.amd64;
case ELF_EM_PDSP: return AdbgMachine.sonydsp;
case ELF_EM_PDP10: return AdbgMachine.pdp10;
case ELF_EM_PDP11: return AdbgMachine.pdp11;
Expand Down
2 changes: 1 addition & 1 deletion src/adbg/v2/object/format/macho.d
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ AdbgMachine adbg_object_macho_machine(uint type) {
case MACHO_CPUTYPE_NS32332:
case MACHO_CPUTYPE_NS32532: return AdbgMachine.ns32k;
case MACHO_CPUTYPE_I386: return AdbgMachine.x86;
case MACHO_CPUTYPE_X86_64: return AdbgMachine.x86_64;
case MACHO_CPUTYPE_X86_64: return AdbgMachine.amd64;
case MACHO_CPUTYPE_MIPS: return AdbgMachine.mips;
case MACHO_CPUTYPE_MC680x0: return AdbgMachine.m68k;
case MACHO_CPUTYPE_HPPA: return AdbgMachine.parisc;
Expand Down
36 changes: 36 additions & 0 deletions src/adbg/v2/object/format/pe.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module adbg.v2.object.format.pe;
import core.stdc.inttypes;
import adbg.error;
import adbg.v2.object.server : AdbgObject, adbg_object_t;
import adbg.v2.object.machines : AdbgMachine;
import adbg.utils.uid : UID;
import adbg.utils.bit : CHAR32;

Expand Down Expand Up @@ -589,6 +590,41 @@ int adbg_object_pe_load(adbg_object_t *obj) {
return 0;
}

AdbgMachine adbg_object_pe_machine(ushort machine) {
switch (machine) {
case PE_MACHINE_I386: return AdbgMachine.x86;
case PE_MACHINE_AMD64: return AdbgMachine.amd64;
case PE_MACHINE_ALPHAOLD, PE_MACHINE_ALPHA: return AdbgMachine.alpha;
case PE_MACHINE_ALPHA64: return AdbgMachine.alpha64;
case PE_MACHINE_AM33: return AdbgMachine.am33;
case PE_MACHINE_ARM:
case PE_MACHINE_ARMNT: return AdbgMachine.arm;
case PE_MACHINE_ARM64: return AdbgMachine.aarch64;
case PE_MACHINE_EBC: return AdbgMachine.ebc;
case PE_MACHINE_IA64: return AdbgMachine.ia64;
case PE_MACHINE_M32R: return AdbgMachine.m32r;
case PE_MACHINE_MIPS16: return AdbgMachine.mips16;
case PE_MACHINE_MIPSFPU: return AdbgMachine.mipsfpu;
case PE_MACHINE_MIPSFPU16: return AdbgMachine.mips16fpu;
case PE_MACHINE_POWERPC: return AdbgMachine.ppc;
case PE_MACHINE_POWERPCFP: return AdbgMachine.ppcfpu;
case PE_MACHINE_R3000: return AdbgMachine.mips;
case PE_MACHINE_R4000: return AdbgMachine.mipsii;
case PE_MACHINE_R10000: return AdbgMachine.mipsiv;
case PE_MACHINE_RISCV32: return AdbgMachine.riscv32;
case PE_MACHINE_RISCV64: return AdbgMachine.riscv64;
case PE_MACHINE_RISCV128: return AdbgMachine.riscv128;
case PE_MACHINE_SH3: return AdbgMachine.sh3;
case PE_MACHINE_SH3DSP: return AdbgMachine.sh3dsp;
case PE_MACHINE_SH4: return AdbgMachine.sh4;
case PE_MACHINE_SH5: return AdbgMachine.sh5;
case PE_MACHINE_THUMB: return AdbgMachine.thumb;
case PE_MACHINE_WCEMIPSV2: return AdbgMachine.mipswcele;
case PE_MACHINE_CLR: return AdbgMachine.clr;
default: return AdbgMachine.unknown;
}
}

const(char) *adbg_object_pe_machine_string(ushort machine) {
switch (machine) {
case PE_MACHINE_UNKNOWN: return "None";
Expand Down
17 changes: 10 additions & 7 deletions src/adbg/v2/object/machines.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum AdbgMachine {
/// Intel x86 32-bit (i386)
x86,
/// Intel x86 64-bit (amd64)
x86_64,
amd64,
/// Intel MCU
mcu,
/// Intel i860
Expand Down Expand Up @@ -80,16 +80,18 @@ enum AdbgMachine {

/// Stanford MIPS-X
mipsx,
/// MIPS I (RS3000)
/// MIPS I (R3000)
mips,
/// MIPS I (RS3000) with FPU
/// MIPS I (R3000) with FPU
mipsfpu,
/// MIPS I (RS3000) Little-Endian
/// MIPS I (R3000) Little-Endian
mipsle,
/// MIPS16
mips16,
/// MIPS16 with FPU
mips16fpu,
/// MIPS II (R4000)
mipsii,
/// MIPS III (R4000)
mipsiii,
/// MIPS IV (R10000)
Expand Down Expand Up @@ -462,9 +464,9 @@ struct adbg_machine_t {
/// List of known machines.
immutable adbg_machine_t[] machines = [
// Intel
{ AdbgMachine.i8086, "x86_16", "8086", "Intel 8086" },
{ AdbgMachine.x86, "x86_32", "x86", "Intel x86" },
{ AdbgMachine.x86_64, "x86_64", "amd64", "Intel x86 (64-bit)" },
{ AdbgMachine.i8086, "8086", "x86_16", "Intel 8086" },
{ AdbgMachine.x86, "x86", "x86_32", "Intel x86" },
{ AdbgMachine.amd64, "amd64", "x86_64", "Intel x86 (64-bit)" },
{ AdbgMachine.mcu, "mcu", null, "Intel MCU" },
{ AdbgMachine.i860, "i860", null, "Intel i860" },
{ AdbgMachine.i960, "i960", null, "Intel i960" },
Expand Down Expand Up @@ -507,6 +509,7 @@ immutable adbg_machine_t[] machines = [
{ AdbgMachine.mipsle, "mipsle", null, "MIPS I (RS3000) Little-Endian" },
{ AdbgMachine.mips16, "mips16", null, "MIPS16" },
{ AdbgMachine.mips16fpu, "mips16fpu", null, "MIPS16 with FPU" },
{ AdbgMachine.mipsii, "mipsii", null, "MIPS II (R3000)" },
{ AdbgMachine.mipsiii, "mipsiii", null, "MIPS III (R4000)" },
{ AdbgMachine.mipsiv, "mipsiv", null, "MIPS IV (R10000)" },
{ AdbgMachine.mipswcele, "mipswcele", null, "MIPS little-endian WCE v2" },
Expand Down
2 changes: 1 addition & 1 deletion src/adbg/v2/object/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ AdbgMachine adbg_object_machine(adbg_object_t *obj) {

switch (obj.type) with (AdbgObject) {
case mz: return AdbgMachine.i8086;
//case pe: return adbg_object_pe_machine(obj.i.pe.header.Machine);
case pe: return adbg_object_pe_machine(obj.i.pe.header.Machine);
// NOTE: Both fat and header matches the header structure
case macho: return adbg_object_macho_machine(obj.i.macho.header.cputype);
case elf: return adbg_object_elf_machine(obj.i.elf32.e_header.e_machine);
Expand Down

0 comments on commit b944f11

Please sign in to comment.