How to convert a 68k executable back to C source code?

6 posts / 0 new
Last post
jap
jap's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-06-04 05:53
How to convert a 68k executable back to C source code?

Hello,

I'd like to port/remake an old Classic Amiga game for AmigaOS 4. The game was programmed with C for AmigaOS 1.3 in the late 80's but the source code is now lost. All that remains is an executable.

Any recommendations how I could turn that executable back to C source code?

kas1e
kas1e's picture
Offline
Last seen: 1 year 5 months ago
Joined: 2010-11-30 15:30
Re: How to convert a 68k executable back to C source code?

The only for real working 68k reassembler is : IRA (on os4depot).

I.e. you use IRA to disassemble 68k binary to produce 68k assembly code (of course, not as original, but working one), which you can then compile back to the new 68k "exe" by vasm or phass, or devpac, etc. I doing so when made patches for Foundation and Exodus. Of course it is not native os4 binary, but it can be fixed to be more os4 system friendly.

In brief that what i do when want to patch some 68k game sources of which i do not have:

1). disasembly binary by IRA to 68k assembler code
2). then by hands imrove it for better readability (shift chunks, call names, replace library calls on proper lvo names for better readability, etc). And always recompile it back to check that binary still works.
3). then work start : you then found parts you need to fix, and fix them. It's not mean you need to wrote all fixes in assembler , you can use C of course too= like i do in Foundation : i just set a call from assembler to my C function where need it, and made necessary C based fucntions as different object, which a link together when compile reassembled assembly code back to 68k binary.

Yeah, it mean that your binary will still be 68k, but at least you can imrpove broken parts and made it be more os4 friendly (like by replacing all custom or chips graphics stuff on system friendly one). For example in Napalm, it was a matter to replace all old graphics calls on proper WritePixelArrays and stuff to have all renders correctly. In Exodus it was a matter of fully replace drawing functions as they wasn't done correctly in terms of alignment. In Foundation game - i replace in whole Mod player which originaly were writte with usage of CIA to play mods, and i just made C player playng mods over ptplay.library, which i made as independent object file which link together with main one on linking strage.

So generatly speaking, if some 68k game almost works, but need some fixes that very possible to do with help of IRA. Or if you know how game coded, just loose sources it also will help. But to just overwrite fully it to OS4 to have OS4 binary : then that probably better to write from scratch.

Update: There is also IDA with it's plugins to disassemble from 68k binary to pseudo C code, but this C code is much worse in compare with assembler output (as names of functions most of time lost, name of variables too, etc, making it all looks a bit messy).

jap
jap's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-06-04 05:53
Re: How to convert a 68k executable back to C source code?

It starts to look like that remake is the best option for me. My Classic Amiga hardware knowledge is close to zero, so fixing the 68k binary is not an option.

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: How to convert a 68k executable back to C source code?

That's like asking how to convert a song back into the backing tracks. LOL. You coulld use ReSource as well. Then PPC680x0 to assemble the 68K as PPC. But, that's still not source. Even so, converting ASM to C will end up as an ugly mess. At least, it does for x86. 68K may be better but it still has to duplicate what it's doing. A sophisticated one would be able to detect what compiler was used, how it writes code, and use pattern matching with that knowledge and some AI neural nets to recreate what it would have looked like.

billt
billt's picture
Offline
Last seen: 1 year 5 months ago
Joined: 2011-02-04 18:54
Re: How to convert a 68k executable back to C source code?

Has anyone used anything like radare2, ghidra, or IDA on Amiga binaries?

kas1e
kas1e's picture
Offline
Last seen: 1 year 5 months ago
Joined: 2010-11-30 15:30
Re: How to convert a 68k executable back to C source code?

Yes, i use IDA and tried ghidra as well, both good for 68k binaries.

Log in or register to post comments