15 February 2024, 20:58 | #21 |
Registered User
Join Date: Jul 2009
Location: Lala Land
Posts: 608
|
I've tried my first export of my Federation of Free Traders project to assembler, and it's painful to say the least. Ghidra clips mnemonic src/dst columns in the export and the asm appears to be corrupted..
The exported asm (sans clipping corruption) doesn't look too far off Amiga syntaxes. I suspect if I spend an hour or two looking into it, and maybe write my own export plugin I can get something out of it.. but still. |
15 February 2024, 21:07 | #22 |
Registered User
Join Date: Jul 2009
Location: Lala Land
Posts: 608
|
Here's an example:
Code:
ram:00000930 0ab900008... eori.l #0x8000,(currentDoubleBufferOffsetMay... |
28 February 2024, 08:28 | #23 |
Registered User
Join Date: Jul 2009
Location: Lala Land
Posts: 608
|
Ghidra 11.0.1.
How to make a function from a pointer assigned to a table. In Pool of Radiance an affects table is populated with function handlers by affect type as index (I exported my executable with symbols already defined from Resource hence the label names being Resource-created): Code:
002308e6 43 fa f7 14 lea (-0x8ec,PC)=>lbC010FFC,A1 002308ea 23 c9 00 move.l A1,(DAT_00287b26).l 28 7b 26 Code:
/* WARNING: Removing unreachable block (ram,0x0023003e) */ void UndefinedFunction_0022fffc(void) ... Code:
lbC010FFC XREF[1]: SetupAffectTables:002308e6(*) 0022fffc 4e 55 ff fc link.w A5,-0x4 00230000 bf f9 00 cmpa.l (hSPLower).l,SP 28 9d 28 The way I have found to define the standard affect handler function signature is to paste in: Code:
void Affect00E46E (character_s * char_p, effect_s * effect_p, int param_3) Hope this helps someone! Last edited by copse; 29 February 2024 at 22:22. |
29 February 2024, 22:20 | #24 |
Registered User
Join Date: Jul 2009
Location: Lala Land
Posts: 608
|
Ghidra 11.0.1.
Here's another minor quirk that doesn't happen too often related to decompilation, local variable types and reuse of stack-based local variables. Code:
byte BuildNearTargets(character_s *char_p,byte max_range) { ... character_s *local_14; ... local_14 = (character_s *)PlayerMapPosX_Thunk4(char_p); local_10 = PlayerMapPosY_Thunk4(char_p); ... if (DAT_0028783a != 0) { for (i = 1; bVar2 = result_count, i <= bVar1; i = i + 1) { local_14 = (&g_character_array)[*(byte *)((int)&g_map_to_background_tile + (uint)i * 3 + 2)]; Related issue: https://github.com/NationalSecurityA...ra/issues/2573 Not a big deal in the scheme of things, but useful to understand. Hope this helps someone! |
01 March 2024, 10:32 | #25 |
Global Moderator
Join Date: Jan 2004
Location: Oxford
Posts: 14,657
|
For Ambermoon I believe they wrote an exporter plugin?
But I think you're right exporting wasn't fun and Pyrdacor said numerous times he wanted to leave Ghidra environment following a successfull disassembly and re-assembly and continue working only on the exported files as soon as possible. |
13 March 2024, 06:50 | #26 |
Registered User
Join Date: Jul 2009
Location: Lala Land
Posts: 608
|
Ghidra 11.0.1
There's another likely m68k bug in ghidra decompilation, where the first variable of a struct is an array or pointer it will decompile references to later variables in the struct (even outside the fixed array bounds) as relative to that first variable. For example: Code:
struct character_s { char name[14]; ... ushort x; ... } Code:
void f(character_s *char_p) { ... ... (ushort)*(char_p->name + 30) ... ... } |
24 May 2024, 05:37 | #27 |
Registered User
Join Date: Jul 2009
Location: Lala Land
Posts: 608
|
The previous post is because I had not completely named and datatyped that part of the structure. That will decompile correctly for the most part, if you work out what part of the struct it is touching and what uses it and with what types.
Where it fails in my special case is where the code I am decompiling does indexing with 1-based indexing. It'll glom onto the not actually existing 0 indexed location. I don't think there's much that can be done about this and it's not that common. |
24 May 2024, 05:40 | #28 |
Registered User
Join Date: Jul 2009
Location: Lala Land
Posts: 608
|
I was using the wrong thing for exporting decompiled source code.
Go to File -> Export Program, then select Format C/C++. It will output a C file in my case. This provides the pure C source code and none of the disassembly. |
02 June 2024, 08:43 | #29 |
Registered User
Join Date: Jul 2009
Location: Lala Land
Posts: 608
|
I just loaded up an OS-friendly executable that was written with some C variant. It uses A4 as a base register. I can't for the life of me work out if Ghidra can bind it to the data structure it points it to so that I can type the accesses. This means that in every function I have to type the register access in the decompiler output.
This is one place Resource shines once you know where the menu option is. |
02 June 2024, 22:38 | #30 | |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,316
|
Quote:
|
|
01 August 2024, 11:15 | #31 |
Registered User
Join Date: Jan 2024
Location: Zagreb / Croatia
Posts: 19
|
Just for reference, I built a Ghidra->IRA export tool that I will release (as 0BSD open source) if there's enough interest. Let me know in this thread if it's worth your and my time..
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help disassembling Wicked | moohorse | Coders. Asm / Hardware | 33 | 04 June 2023 22:57 |
Ghidra disassembler / decompiler supports 68000 | mark_k | Coders. Asm / Hardware | 21 | 20 March 2019 12:09 |
Disassembling an A600 | Revival9001 | support.Hardware | 2 | 31 January 2017 07:01 |
Disassembling resource | copse | Coders. General | 1 | 02 April 2012 03:36 |
Disassembling and reassembling | absence | Coders. General | 7 | 22 September 2009 15:30 |
|
|