Closed PerikiyoXD closed 3 months ago
You can try either creating the rest of EE memory as a non-overlay memory block, or use the savestate importer script (which should do that automatically).
I did create an extra memory block after the binary up to the full 32 MB of the size, that made it work.
We could try to automatically create an overlay if that'd make the same effect. I couldn't make it work using a overlay, might be skill issue.
BUT
I've pinpointed a bug in MIPS "J" instructions... https://scc.ustc.edu.cn/zlsc/lxwycj/200910/W020100308600769158777.pdf It seems that the .sinc definition has a bug and does not follow either R5900 or MIPS standard docs.
Ghidra:
IDA:
https://github.com/NationalSecurityAgency/ghidra/pull/4193 Seems that's in the process of being fixed? I hope
Can you give an example of a specific place in a specific game where this is a problem? It looks like a fix has been merged into ghidra's master branch (for the issue you linked), and I'd like to have a proper test case.
Also it's unclear to me what you're trying to show with the ghidra/ida comparsion above.
Can you give an example of a specific place in a specific game where this is a problem? It looks like a fix has been merged into ghidra's master branch (for the issue you linked), and I'd like to have a proper test case.
SLES-503.06, 0x002DD620
, j
instruction.
Would work for any j
or jal
Also it's unclear to me what you're trying to show with the ghidra/ida comparsion above.
Proving that the resolved addresses are between ida and ghidra differ, thus making the ghidra output erroneous.
ghidra doesn't properly substract the address on the j
/jal
, thus pointing to a x2-ish address.
seems to be an issue with the MIPS sleigh pcode. Might be PS2 specific but I've checked both ISA manuals:
EE Core Instruction Set Manual Version 6.0
and
MIPS32™ Architecture For Programmers Volume II: The MIPS32™ Instruction Set
and I suspect the pcode for both MIPS
and R5900
processor definitions (which is based from MIPS
) are wrong.
For example:
SLES-503.06, 0x002DD3E4
ghidra:
002dd3e4 60 db 16 0c jal FUN_005b6d80 undefined FUN_005b6d80()
ida
main:002DD3E4 B0 6D 0B 0C jal dword_5B6C8C-0x2DB5CC # hex(0x5B6C8C-0x2DB5CC) => '0x2db6c0'
# hex(0x5B6C8C-0x2DB5CC) => '0x2db6c0'
is the arithmetic logic I've manually calculated. It points to the proper address in ida, doesn't for ghidra.
SLES-503.06, 0x0012b0c0
in the main function show that rapidly:
I did create an extra memory block after the binary up to the full 32 MB of the size, that made it work.
We could try to automatically create an overlay if that'd make the same effect. I couldn't make it work using a overlay, might be skill issue.
BUT
I've pinpointed a bug in MIPS "J" instructions... https://scc.ustc.edu.cn/zlsc/lxwycj/200910/W020100308600769158777.pdf It seems that the .sinc definition has a bug and does not follow either R5900 or MIPS standard docs.
What about making it configurable? PSX-DESR has 64mb for EE RAM and Devkits have 128mb
I did create an extra memory block after the binary up to the full 32 MB of the size, that made it work. We could try to automatically create an overlay if that'd make the same effect. I couldn't make it work using a overlay, might be skill issue. BUT I've pinpointed a bug in MIPS "J" instructions... https://scc.ustc.edu.cn/zlsc/lxwycj/200910/W020100308600769158777.pdf It seems that the .sinc definition has a bug and does not follow either R5900 or MIPS standard docs.
What about making it configurable? PSX-DESR has 64mb for EE RAM and Devkits have 128mb
I'd probably add a configuration on the processor settings panel to decide RAM size.
SLES-503.06, 0x002DD620
,j
instruction.
I've checked it and can't reproduce it on the latest version of the extension, although I noticed the executable file has a relocation table.
Are you on the latest version? Earlier versions had a bug where it would incorrectly apply relocations, even for statically linked executable files.
In the dialog for importing a file there should be an option for disabling relocations if you want to test it without updating.
Did clone ghidra and self-built it. It still points to bad addresses.
Trying without relocs.
Sorry I meant the version of this extension, not ghidra.
I'm using latest ghidra. Doesn't make any difference so far.
I've just downloaded latest release of ghidra-emotionengine-reloaded.
Same behaviour, unchecked relocs in the import settings.
I'm going to try find a random MIPS .elf file to test if there's this issue in ghidra and check on ida too.
The machine code for that instruction is definitely different to what's shown in my ghidra and your IDA. What does the relocation table window in Ghidra say about that address?
Could you provide a screenshot of that main just like I did? Just as visual comparison for me.
The machine code for that instruction is definitely different to what's shown in my ghidra and your IDA. What does the relocation table window in Ghidra say about that address?
"0012b0c0","APPLIED","0x4","0x22e9","5c a2 0b 0c","njWaitVSync"
All relocations:
If relocations are disabled none of them should be being applied. Even if they're enabled they should be being discarded by this logic:
// Some versions of the Metrowerks compiler produced relocation tables
// in statically linked executables. We want to disable relocation in
// those cases.
if(elfRelocationContext.getElfHeader().isExecutable()) {
return RelocationResult.SKIPPED;
}
Here's what I see in Ghidra:
I think this is what you meant: https://github.com/chaoticgd/ghidra-emotionengine-reloaded/assets/3116368/3c91273a-bf1e-4ae9-a1a3-2412a8741eb0
I will try again
It didn't change the outcome. I will try rebuilding ghidra-emotionengine-reloaded myself... I guess
Seems that ghidra-emotionengine-reloaded won't compile against latest ghidra main branch:
PS C:\Users\pxd\Desktop\ghidraDevelopment\ghidra-emotionengine-reloaded> gradle build
> Task :compileJava
C:\Users\pxd\Desktop\ghidraDevelopment\ghidra-emotionengine-reloaded\src\main\java\ghidra\emotionengine\relocation\EmotionEngine_ElfRelocationHandler.java:56: error: relocate(ElfRelocationContext,ElfRelocation,Address) in EmotionEngine_ElfRelocationHandler cannot override relocate(ElfRelocationContext,ElfRelocation,Address) in AbstractElfRelocationHandler
public RelocationResult relocate(ElfRelocationContext elfRelocationContext, ElfRelocation relocation,
^
overridden method is final
Note: C:\Users\pxd\Desktop\ghidraDevelopment\ghidra-emotionengine-reloaded\src\main\java\ghidra\emotionengine\relocation\EmotionEngine_ElfRelocationHandler.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --info option to get more log output.
> Run with --scan to get full insights.
BUILD FAILED in 5s
1 actionable task: 1 executed
Backing to ghidra 11.0.1 to test this
It was a version mismatch. I was using ghidra 11.0 and now I used ghidra 11.0.1 and it's working properly.
Okay, good we figured that out. If you don't have any more questions you can close this.
I tried making an overlay for RAM as described here;
https://psi-rockin.github.io/ps2tek/#memorymap
but didn't help.