Search code examples
assemblydisassemblyi386powerpcotool

Dumped i386 assembly code and recompile as PPC?


I used the Apple built-in "otool" command with "-Vvtd" switches to dump a Mach-O i386 binary, redirected to a .s file. I have tried unsuccessfully to use nasm and GAS assemblers to recompile the code on a PPC machine ("as"-binary in the i386 directory of gcc/darwin and "as"-binary in the ppc directory as well). The output reads something like:

some_topmost_label:
(__TEXT,__text) section
_default_pager:
00112000    pushl   %ebp
00112001    movl    %esp,%ebp
00112003    pushl   %edi
00112004    pushl   %esi
00112005    pushl   %ebx
00112006    subl    $0x3c,%esp
00112009    movl    _default_pager_internal_count,%ebx
0011200f    addl    _default_pager_external_count,%ebx
00112015    leal    0x00000004(,%ebx,4),%ebx

There is a data section as well, going like:

...

(__DATA,__data) section
00421000    02 00 00 00 04 00 00 00 00 40 00 00 28 64 65 66

...

00449bc0    50 00 3d 00 00 00 00 00 00 00 00 00 00 00 00 00 
00449bd0    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

...

I am intent on running the binary in Mac on PPC, hence the recompiling effort; I have tried removing the addresses in the leftmost column to make the syntax more "AT&T"-style, leaving them, etc. I DO NOT want to make any edits to the existing code structure (this is not exactly a reverse-engineering effort, per se, just some customization). However, if I have to do any editing, I would very much like it to be strictly for making the existing, unadulterated code for i386 run as is on PPC.

I will very much appreciate your help.

Regards


Solution

  • Decompilers can produce C files (as I have tried) which can be used to compile from source on a different architecture (which I have also tried). The experience was dicey at best. I'm still working on it and will likely still be for some time.

    As an alternative, emulation can be implemented to run a binary/executable for i386 on ppc. This is a quick, but potentially less effective, route.

    In addition, I feel it confirmed that assembly-to-assembly would be the most painful route as opposed to using the C programming language as an intermediate (by decompiling the i386 binary to C and recompiling the C on the target architecture).

    In the case of decompiling: what if it produces a quarter-million lines of code? You may need a team :)