GP-4711 Fix for import of 32-bit x86 Unix/Windows Rust binaries

This commit is contained in:
emteere
2025-10-28 17:22:13 +00:00
parent 25c2e8591e
commit 95ad48cdb3
12 changed files with 82 additions and 8 deletions

View File

@@ -28,6 +28,7 @@ import ghidra.framework.store.LockException;
import ghidra.program.database.SpecExtension;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.lang.Language;
import ghidra.program.model.lang.Processor;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.MemoryBlock;
@@ -97,9 +98,11 @@ public class RustUtilities {
public static int addExtensions(Program program, TaskMonitor monitor, String subPath)
throws IOException {
Processor processor = program.getLanguageCompilerSpecPair().getLanguage().getProcessor();
ResourceFile module = Application.getModuleDataSubDirectory(processor.toString(),
RustConstants.RUST_EXTENSIONS_PATH + subPath);
Language language = program.getLanguageCompilerSpecPair().getLanguage();
Processor processor = language.getProcessor();
int bitSize = language.getLanguageDescription().getSize();
String spath = RustConstants.RUST_EXTENSIONS_PATH + subPath+bitSize;
ResourceFile module = Application.getModuleDataSubDirectory(processor.toString(),spath);
int extensionCount = 0;

View File

@@ -1,11 +1,16 @@
##VERSION: 2.0
Module.manifest||GHIDRA||||END|
README.md||GHIDRA||||END|
data/extensions/rust/unix/cc.xml||GHIDRA||||END|
data/extensions/rust/unix/probe_fixup.xml||GHIDRA||||END|
data/extensions/rust/unix/try_fixup.xml||GHIDRA||||END|
data/extensions/rust/windows/probe_fixup.xml||GHIDRA||||END|
data/extensions/rust/windows/try_fixup.xml||GHIDRA||||END|
data/extensions/rust/unix32/cc.xml||GHIDRA||||END|
data/extensions/rust/unix32/probe_fixup.xml||GHIDRA||||END|
data/extensions/rust/unix32/try_fixup.xml||GHIDRA||||END|
data/extensions/rust/unix64/cc.xml||GHIDRA||||END|
data/extensions/rust/unix64/probe_fixup.xml||GHIDRA||||END|
data/extensions/rust/unix64/try_fixup.xml||GHIDRA||||END|
data/extensions/rust/windows32/probe_fixup.xml||GHIDRA||||END|
data/extensions/rust/windows32/try_fixup.xml||GHIDRA||||END|
data/extensions/rust/windows64/probe_fixup.xml||GHIDRA||||END|
data/extensions/rust/windows64/try_fixup.xml||GHIDRA||||END|
data/languages/adx.sinc||GHIDRA||||END|
data/languages/avx.sinc||GHIDRA||||END|
data/languages/avx2.sinc||GHIDRA||||END|

View File

@@ -0,0 +1,34 @@
<prototype name="__rustcall" extrapop="8" stackshift="8">
<input>
<pentry minsize="1" maxsize="500" align="4">
<addr offset="4" space="stack"/>
</pentry>
</input>
<output killedbycall="true">
<pentry minsize="4" maxsize="10" metatype="float" extension="float">
<register name="ST0"/>
</pentry>
<pentry minsize="1" maxsize="4">
<register name="EAX"/>
</pentry>
<pentry minsize="5" maxsize="8">
<addr space="join" piece1="EDX" piece2="EAX"/>
</pentry>
</output>
<unaffected>
<register name="ESP"/>
<register name="EBP"/>
<register name="ESI"/>
<register name="EDI"/>
<register name="EBX"/>
</unaffected>
<killedbycall>
<register name="ECX"/>
<register name="EDX"/>
<register name="ST0"/>
<register name="ST1"/>
</killedbycall>
<likelytrash>
<register name="EAX"/>
</likelytrash>
</prototype>

View File

@@ -0,0 +1,8 @@
<callfixup name="__rust_try">
<target name="__rust_try"/>
<pcode>
<body><![CDATA[
call [EDI];
]]></body>
</pcode>
</callfixup>

View File

@@ -0,0 +1,8 @@
<callfixup name="__rust_probestack">
<target name="__rust_probestack"/>
<pcode>
<body><![CDATA[
temp:1 = 0;
]]></body>
</pcode>
</callfixup>

View File

@@ -0,0 +1,8 @@
<callfixup name="__rust_try">
<target name="__rust_try"/>
<pcode>
<body><![CDATA[
call [EAX];
]]></body>
</pcode>
</callfixup>

View File

@@ -0,0 +1,8 @@
<callfixup name="__rust_probestack">
<target name="__rust_probestack"/>
<pcode>
<body><![CDATA[
temp:1 = 0;
]]></body>
</pcode>
</callfixup>