Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-4886 Corrected speculative param storage determination

ghidra1b203afe7007c
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/program/util/ConstantPropogationReferenceTest.java b/Ghidra/Features/Base/src/test/java/ghidra/program/util/ConstantPropogationReferenceTest.java
index e551d72f42..6015ab4681 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/program/util/ConstantPropogationReferenceTest.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/program/util/ConstantPropogationReferenceTest.java
@@ -24,19 +24,17 @@ import org.junit.Test;
import generic.test.AbstractGenericTest;
import ghidra.app.plugin.core.analysis.ConstantPropagationAnalyzer;
import ghidra.app.plugin.core.analysis.ConstantPropagationContextEvaluator;
-import ghidra.framework.store.LockException;
import ghidra.program.database.ProgramBuilder;
-import ghidra.program.model.address.*;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.address.AddressSet;
import ghidra.program.model.lang.Register;
import ghidra.program.model.lang.RegisterValue;
import ghidra.program.model.listing.*;
import ghidra.program.model.mem.MemoryBlock;
-import ghidra.program.model.mem.MemoryConflictException;
import ghidra.program.model.pcode.Varnode;
import ghidra.program.model.symbol.Reference;
import ghidra.program.model.symbol.ReferenceIterator;
import ghidra.program.util.SymbolicPropogator.Value;
-import ghidra.util.exception.CancelledException;
import ghidra.util.exception.NotFoundException;
import ghidra.util.task.TaskMonitor;
@@ -57,12 +55,12 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
public ConstantPropogationReferenceTest() {
super();
}
-
+
@Test
- public void testOperandRef_MIPS6432() throws Exception {
-
+ public void testOperandRef_MIPS6432() throws Exception {
+
builder = new ProgramBuilder("MIPS_6432", "MIPS:BE:64:64-32addr");
-
+
// lui v0, 0x80a8
// addiu v0, v0, -0xdf0
// sw v0, -0x46e8(gp)
@@ -75,7 +73,7 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
program = builder.getProgram();
program.startTransaction("Test");
-
+
Address codeStart = addr("0x80a7f214");
Listing listing = program.getListing();
assertNotNull("Bad instruction disassembly", listing.getInstructionAt(codeStart));
@@ -93,18 +91,19 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
assertOperandReferenceTo(1, instr, addr("0x8fffb918"));
}
-
+
@Test
public void testBadAddressOffsetTracking() throws Exception {
builder = new ProgramBuilder("thunk", ProgramBuilder._MIPS);
- builder.setBytes("0x1000", "3c 1c 00 14 27 9c b3 34 03 99 e0 21 27 bd ff e0" +
- "af bc 00 10 3c 07 12 34 24 e7 45 67 ac a7 00 10" +
- "3c 06 0a 0b 24 c6 0c 0d ae 06 00 10 8e 11 00 10" +
- "8c b1 00 10 8f b1 00 10 8e 51 00 10 ae 53 00 10" +
- "8e 51 00 10 36 92 00 00 8e 51 00 10 8e 92 00 10" +
- "3c 11 00 53 8e 51 00 10 03 e0 00 08 27 bd 00 20");
+ builder.setBytes("0x1000",
+ "3c 1c 00 14 27 9c b3 34 03 99 e0 21 27 bd ff e0" +
+ "af bc 00 10 3c 07 12 34 24 e7 45 67 ac a7 00 10" +
+ "3c 06 0a 0b 24 c6 0c 0d ae 06 00 10 8e 11 00 10" +
+ "8c b1 00 10 8f b1 00 10 8e 51 00 10 ae 53 00 10" +
+ "8e 51 00 10 36 92 00 00 8e 51 00 10 8e 92 00 10" +
+ "3c 11 00 53 8e 51 00 10 03 e0 00 08 27 bd 00 20");
//00001000 lui gp,0x14
//00001004 addiu gp,gp,-0x4ccc
@@ -123,29 +122,29 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
//00001038 lw s1,0x10(s2)
//0000103c sw s3,0x10(s2)
//00001040 lw s1,0x10(s2)
- //00001044 ori s2,s4,0x0
- //00001048 lw s1,0x10(s2)
+ //00001044 ori s2,s4,0x0
+ //00001048 lw s1,0x10(s2)
//0000104c lw s2,0x10(s4)
//00001050 lui s1=>DAT_00530000,0x53
//00001054 lw s1,0x10(s2)
//00001058 jr ra
//0000105c _addiu sp,sp,0x20
-
+
builder.disassemble("0x1000", 88, false);
-
+
builder.createFunction("0x1000");
-
+
analyzer = new ConstantPropagationAnalyzer();
-
+
program = builder.getProgram();
program.startTransaction("Test");
-
+
Address codeStart = addr("0x1000");
Listing listing = program.getListing();
assertNotNull("Bad instruction disassembly", listing.getInstructionAt(codeStart));
-
+
setRegister(addr("0x1000"), "gp", 0x11200000);
-
+
// follow all flows building up context
// use context to fill out addresses on certain instructions
ContextEvaluator eval = new ConstantPropagationContextEvaluator(TaskMonitor.DUMMY, true) {
@@ -165,116 +164,122 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
String loc = instr.getMinAddress().toString();
Varnode registerVarnode;
- switch(loc) {
- case "00001010":
- // gp should be 0x14 + t9 offset space
- registerVarnode = regValue(context,"gp");
- assertTrue("symbolic value", context.isSymbol(registerVarnode));
- assertEquals("(t9, 0x13b334, 4)", registerVarnode.toString());
- // S3 should be S3 at entry
- registerVarnode = regValue(context,"s3");
- assertTrue("register s3", context.isRegister(registerVarnode));
- assertEquals("s3", context.getRegister(registerVarnode).getName());
- break;
- case "0000102c":
- // s1 restored from space 0x10(s0) space
- registerVarnode = regValue(context,"s1");
- assertTrue("constant value", registerVarnode.isConstant());
- assertEquals("(const, 0xa0b0c0d, 4)", registerVarnode.toString());
- break;
- case "00001030":
- // s1 restored from space 0x10(a1) space
- registerVarnode = regValue(context,"s1");
- assertTrue("symbolic value", registerVarnode.isConstant());
- assertEquals("(const, 0x12344567, 4)", registerVarnode.toString());
- break;
- case "00001034":
- // s1 restored from space 0x10(sp) space
- registerVarnode = regValue(context,"s1");
- assertTrue("symbolic value", context.isSymbol(registerVarnode));
- assertEquals("(t9, 0x13b334, 4)", registerVarnode.toString());
- break;
- case "00001038":
- // s1 restored from space 0x10(s2) space
- registerVarnode = regValue(context,"s1");
- //assertTrue("Still s1", registerVarnode.isRegister());
- boolean isBad = false;
- try {
- context.getConstant(registerVarnode, null);
- } catch (NotFoundException e) {
- isBad = true;
- }
- assertTrue("Can get constant value", isBad);
- break;
- case "00001040":
- // s1 restored from space 0x10(s2) space - stored a3
- registerVarnode = regValue(context,"s1");
- assertTrue("register s3", registerVarnode.isRegister());
- assertEquals("s3", context.getRegister(registerVarnode).getName());
-
- Address lastSetLocation = context.getLastSetLocation(context.getRegisterVarnode(context.getRegister("s2")), null);
- assertEquals("s2 last set", null, lastSetLocation);
- break;
- case "00001048":
- // s1 restored from space 0x10(s2) after s2 has been set again
- // it should no longer be s3 that was stored in another s2 relative space
- registerVarnode = regValue(context,"s1");
- //assertTrue("Still s1", registerVarnode.isRegister());
- isBad = false;
- try {
- context.getConstant(registerVarnode, null);
- } catch (NotFoundException e) {
- isBad = true;
- }
- assertTrue("Can get constant value", isBad);
- break;
- case "0000104c":
- // s1 restored from space 0x10(s2) after s2 has been set again
- // it should no longer be s3 that was stored in another s2 relative space
- registerVarnode = regValue(context,"s2");
- //assertTrue("Still s2", registerVarnode.isRegister());
- isBad = false;
- try {
- context.getConstant(registerVarnode, null);
- } catch (NotFoundException e) {
- isBad = true;
- }
- assertTrue("Can get constant value", isBad);
- lastSetLocation = context.getLastSetLocation(context.getRegisterVarnode(context.getRegister("s2")), null);
- assertEquals("s2 last set", 0x104fL, lastSetLocation.getOffset());
- break;
- case "00001054":
- // s1 restored from space 0x10(s2) after s2 has been set again
- // it should no longer be s3 that was stored in another s2 relative space
- registerVarnode = regValue(context,"s1");
- //assertTrue("Still s1", registerVarnode.isRegister());
- //assertEquals(context.getRegister(registerVarnode).getName(),"s1");
- isBad = false;
- try {
- context.getConstant(registerVarnode, null);
- } catch (NotFoundException e) {
- isBad = true;
- }
- assertTrue("Can get constant value", isBad);
- break;
+ switch (loc) {
+ case "00001010":
+ // gp should be 0x14 + t9 offset space
+ registerVarnode = regValue(context, "gp");
+ assertTrue("symbolic value", context.isSymbol(registerVarnode));
+ assertEquals("(t9, 0x13b334, 4)", registerVarnode.toString());
+ // S3 should be S3 at entry
+ registerVarnode = regValue(context, "s3");
+ assertTrue("register s3", context.isRegister(registerVarnode));
+ assertEquals("s3", context.getRegister(registerVarnode).getName());
+ break;
+ case "0000102c":
+ // s1 restored from space 0x10(s0) space
+ registerVarnode = regValue(context, "s1");
+ assertTrue("constant value", registerVarnode.isConstant());
+ assertEquals("(const, 0xa0b0c0d, 4)", registerVarnode.toString());
+ break;
+ case "00001030":
+ // s1 restored from space 0x10(a1) space
+ registerVarnode = regValue(context, "s1");
+ assertTrue("symbolic value", registerVarnode.isConstant());
+ assertEquals("(const, 0x12344567, 4)", registerVarnode.toString());
+ break;
+ case "00001034":
+ // s1 restored from space 0x10(sp) space
+ registerVarnode = regValue(context, "s1");
+ assertTrue("symbolic value", context.isSymbol(registerVarnode));
+ assertEquals("(t9, 0x13b334, 4)", registerVarnode.toString());
+ break;
+ case "00001038":
+ // s1 restored from space 0x10(s2) space
+ registerVarnode = regValue(context, "s1");
+ //assertTrue("Still s1", registerVarnode.isRegister());
+ boolean isBad = false;
+ try {
+ context.getConstant(registerVarnode, null);
+ }
+ catch (NotFoundException e) {
+ isBad = true;
+ }
+ assertTrue("Can get constant value", isBad);
+ break;
+ case "00001040":
+ // s1 restored from space 0x10(s2) space - stored a3
+ registerVarnode = regValue(context, "s1");
+ assertTrue("register s3", registerVarnode.isRegister());
+ assertEquals("s3", context.getRegister(registerVarnode).getName());
+
+ Address lastSetLocation = context.getLastSetLocation(
+ context.getRegisterVarnode(context.getRegister("s2")), null);
+ assertEquals("s2 last set", null, lastSetLocation);
+ break;
+ case "00001048":
+ // s1 restored from space 0x10(s2) after s2 has been set again
+ // it should no longer be s3 that was stored in another s2 relative space
+ registerVarnode = regValue(context, "s1");
+ //assertTrue("Still s1", registerVarnode.isRegister());
+ isBad = false;
+ try {
+ context.getConstant(registerVarnode, null);
+ }
+ catch (NotFoundException e) {
+ isBad = true;
+ }
+ assertTrue("Can get constant value", isBad);
+ break;
+ case "0000104c":
+ // s1 restored from space 0x10(s2) after s2 has been set again
+ // it should no longer be s3 that was stored in another s2 relative space
+ registerVarnode = regValue(context, "s2");
+ //assertTrue("Still s2", registerVarnode.isRegister());
+ isBad = false;
+ try {
+ context.getConstant(registerVarnode, null);
+ }
+ catch (NotFoundException e) {
+ isBad = true;
+ }
+ assertTrue("Can get constant value", isBad);
+ lastSetLocation = context.getLastSetLocation(
+ context.getRegisterVarnode(context.getRegister("s2")), null);
+ assertEquals("s2 last set", 0x104fL, lastSetLocation.getOffset());
+ break;
+ case "00001054":
+ // s1 restored from space 0x10(s2) after s2 has been set again
+ // it should no longer be s3 that was stored in another s2 relative space
+ registerVarnode = regValue(context, "s1");
+ //assertTrue("Still s1", registerVarnode.isRegister());
+ //assertEquals(context.getRegister(registerVarnode).getName(),"s1");
+ isBad = false;
+ try {
+ context.getConstant(registerVarnode, null);
+ }
+ catch (NotFoundException e) {
+ isBad = true;
+ }
+ assertTrue("Can get constant value", isBad);
+ break;
}
return super.evaluateContext(context, instr);
}
};
-
+
setRegister(addr("0x1000"), "s1", 0);
SymbolicPropogator symEval = new SymbolicPropogator(program);
Function func = program.getFunctionManager().getFunctionAt(builder.addr(0x1000));
-
+
symEval.flowConstants(codeStart, func.getBody(), eval, true, TaskMonitor.DUMMY);
-
+
Value registerValue = symEval.getRegisterValue(addr("0x1010"), null);
}
-
+
@Test
- public void testCorrectOperandConstantParam_X86_64() throws Exception {
-
+ public void testCorrectOperandConstantParam_X86_64() throws Exception {
+
builder = new ProgramBuilder("thunk", ProgramBuilder._X64, "gcc", this);
// PUSH RBP
@@ -287,9 +292,8 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
builder.setBytes("0x00040000",
"55 48 89 e5 bf 00 01 04 00 b8 00 00 00 00 66 67 e8 2a 00 c9 c3");
-
- builder.setBytes("0x00040100",
- "53 54 52 49 4e 47 20 25 73 20 25 73 0a 00 00");
+
+ builder.setBytes("0x00040100", "53 54 52 49 4e 47 20 25 73 20 25 73 0a 00 00");
builder.disassemble("0x00040000", 21);
@@ -297,7 +301,7 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
program = builder.getProgram();
program.startTransaction("Test");
-
+
Address codeStart = addr("0x00040000");
Listing listing = program.getListing();
assertNotNull("Bad instruction disassembly", listing.getInstructionAt(codeStart));
@@ -309,10 +313,10 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
assertNoOperandReference(0, instr);
assertOperandReferenceTo(1, instr, addr("0x00040100"));
}
-
+
@Test
- public void testOverlayReferences_AARCH64() throws Exception {
-
+ public void testOverlayReferences_AARCH64() throws Exception {
+
builder = new ProgramBuilder("thunk", ProgramBuilder._AARCH64);
// Copy and use PasteCopiedListingsBytesScript
@@ -345,152 +349,152 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
// 0040e91c 00 00 00 00 ddw 0h
String ovBlockName = "textov";
-
- MemoryBlock textBlock = builder.createOverlayMemory(ovBlockName,"0x400000",0x10000);
+
+ MemoryBlock textBlock = builder.createOverlayMemory(ovBlockName, "0x400000", 0x10000);
builder.setBytes(textBlock.getStart().toString(),
"fd 7b bf a9 fd 03 00 91 60 00 00 d0 01 00 24 91 60 00 00 d0 00 40 24 91 e2 03 01 aa e1 15 80 52 05 00 00 94 21 00 80 d2 40 00 80 d2 02 00 00 94 c0 03 5f d6 c0 03 5f d6");
-
- builder.setBytes(ovBlockName+":"+"0x0040e900",
- "53 74 72 69 6e 67 50 61 72 61 6d 31 00 00 00 00 53 74 72 69 6e 67 50 61 72 61 6d 32 00 00 00 00");
- builder.disassemble(textBlock.getStart().toString(), 16*4);
+ builder.setBytes(ovBlockName + ":" + "0x0040e900",
+ "53 74 72 69 6e 67 50 61 72 61 6d 31 00 00 00 00 53 74 72 69 6e 67 50 61 72 61 6d 32 00 00 00 00");
+
+ builder.disassemble(textBlock.getStart().toString(), 16 * 4);
analyzer = new ConstantPropagationAnalyzer();
program = builder.getProgram();
program.startTransaction("Test");
- Address codeStart = addr(ovBlockName+":"+"0x00400000");
+ Address codeStart = addr(ovBlockName + ":" + "0x00400000");
Listing listing = program.getListing();
assertNotNull("Bad instruction disassembly", listing.getInstructionAt(codeStart));
- AddressSet addressSet = new AddressSet(codeStart, codeStart.add(16*4));
+ AddressSet addressSet = new AddressSet(codeStart, codeStart.add(16 * 4));
analyze(addressSet);
Instruction instr;
- instr = listing.getInstructionAt(addr(ovBlockName+":"+"0x00400000").add(20));
+ instr = listing.getInstructionAt(addr(ovBlockName + ":" + "0x00400000").add(20));
assertNoOperandReference(1, instr);
- assertOperandReferenceTo(0, instr, addr(ovBlockName+":"+"0x0040e910"));
-
- instr = listing.getInstructionAt(addr(ovBlockName+":"+"0x00400000").add(24));
+ assertOperandReferenceTo(0, instr, addr(ovBlockName + ":" + "0x0040e910"));
+
+ instr = listing.getInstructionAt(addr(ovBlockName + ":" + "0x00400000").add(24));
assertNoOperandReference(1, instr);
- assertOperandReferenceTo(0, instr, addr(ovBlockName+":"+"0x0040e900"));
+ assertOperandReferenceTo(0, instr, addr(ovBlockName + ":" + "0x0040e900"));
}
-
+
@Test
- public void testOverlayReferencesToBase_AARCH64() throws Exception {
-
+ public void testOverlayReferencesToBase_AARCH64() throws Exception {
+
builder = new ProgramBuilder("thunk", ProgramBuilder._AARCH64);
-
+
String ovBlockName = "textov";
-
+
// Same as above test
-
- MemoryBlock textBlock = builder.createOverlayMemory(ovBlockName,"0x400000",0x1000);
+
+ MemoryBlock textBlock = builder.createOverlayMemory(ovBlockName, "0x400000", 0x1000);
builder.setBytes(textBlock.getStart().toString(),
"fd 7b bf a9 fd 03 00 91 60 00 00 d0 01 00 24 91 60 00 00 d0 00 40 24 91 e2 03 01 aa e1 15 80 52 05 00 00 94 21 00 80 d2 40 00 80 d2 02 00 00 94 c0 03 5f d6 c0 03 5f d6");
-
+
builder.setBytes("0x0040e900",
- "53 74 72 69 6e 67 50 61 72 61 6d 31 00 00 00 00 53 74 72 69 6e 67 50 61 72 61 6d 32 00 00 00 00");
+ "53 74 72 69 6e 67 50 61 72 61 6d 31 00 00 00 00 53 74 72 69 6e 67 50 61 72 61 6d 32 00 00 00 00");
- builder.disassemble(textBlock.getStart().toString(), 16*4);
+ builder.disassemble(textBlock.getStart().toString(), 16 * 4);
analyzer = new ConstantPropagationAnalyzer();
program = builder.getProgram();
program.startTransaction("Test");
- Address codeStart = addr(ovBlockName+":"+"0x00400000");
+ Address codeStart = addr(ovBlockName + ":" + "0x00400000");
Listing listing = program.getListing();
assertNotNull("Bad instruction disassembly", listing.getInstructionAt(codeStart));
- AddressSet addressSet = new AddressSet(codeStart, codeStart.add(16*4));
+ AddressSet addressSet = new AddressSet(codeStart, codeStart.add(16 * 4));
analyze(addressSet);
Instruction instr;
- instr = listing.getInstructionAt(addr(ovBlockName+":"+"0x00400000").add(20));
+ instr = listing.getInstructionAt(addr(ovBlockName + ":" + "0x00400000").add(20));
assertNoOperandReference(1, instr);
assertOperandReferenceTo(0, instr, addr("0x0040e910"));
-
- instr = listing.getInstructionAt(addr(ovBlockName+":"+"0x00400000").add(24));
+
+ instr = listing.getInstructionAt(addr(ovBlockName + ":" + "0x00400000").add(24));
assertNoOperandReference(1, instr);
assertOperandReferenceTo(0, instr, addr("0x0040e900"));
- }
+ }
-
@Test
- public void testOverlayReferencesToSplit_AARCH64() throws Exception {
-
+ public void testOverlayReferencesToSplit_AARCH64() throws Exception {
+
builder = new ProgramBuilder("thunk", ProgramBuilder._AARCH64);
String ovBlockName = "textov";
-
+
// Same as above test
-
- MemoryBlock textBlock = builder.createOverlayMemory(ovBlockName,"0x400000",0x1000);
+
+ MemoryBlock textBlock = builder.createOverlayMemory(ovBlockName, "0x400000", 0x1000);
builder.setBytes(textBlock.getStart().toString(),
"fd 7b bf a9 fd 03 00 91 60 00 00 d0 01 00 24 91 60 00 00 d0 00 40 24 91 e2 03 01 aa e1 15 80 52 05 00 00 94 21 00 80 d2 40 00 80 d2 02 00 00 94 c0 03 5f d6 c0 03 5f d6");
-
-
+
builder.withTransaction(() -> {
try {
- MemoryBlock dataBlock = builder.getProgram().getMemory().createInitializedBlock(ovBlockName, textBlock.getStart().getAddressSpace().getAddressInThisSpaceOnly(0x0040e900), 0x100L, (byte) 0, TaskMonitor.DUMMY,
- false);
-
+ MemoryBlock dataBlock = builder.getProgram()
+ .getMemory()
+ .createInitializedBlock(ovBlockName,
+ textBlock.getStart()
+ .getAddressSpace()
+ .getAddressInThisSpaceOnly(0x0040e900),
+ 0x100L, (byte) 0, TaskMonitor.DUMMY, false);
+
builder.setBytes(dataBlock.getStart().toString(),
- "53 74 72 69 6e 67 50 61 72 61 6d 31 00 00 00 00 53 74 72 69 6e 67 50 61 72 61 6d 32 00 00 00 00");
+ "53 74 72 69 6e 67 50 61 72 61 6d 31 00 00 00 00 53 74 72 69 6e 67 50 61 72 61 6d 32 00 00 00 00");
}
catch (Exception e) {
e.printStackTrace();
}
});
-
- builder.disassemble(textBlock.getStart().toString(), 16*4);
+
+ builder.disassemble(textBlock.getStart().toString(), 16 * 4);
analyzer = new ConstantPropagationAnalyzer();
program = builder.getProgram();
program.startTransaction("Test");
- Address codeStart = addr(ovBlockName+":"+"0x00400000");
+ Address codeStart = addr(ovBlockName + ":" + "0x00400000");
Listing listing = program.getListing();
assertNotNull("Bad instruction disassembly", listing.getInstructionAt(codeStart));
- AddressSet addressSet = new AddressSet(codeStart, codeStart.add(16*4));
+ AddressSet addressSet = new AddressSet(codeStart, codeStart.add(16 * 4));
analyze(addressSet);
Instruction instr;
- instr = listing.getInstructionAt(addr(ovBlockName+":"+"0x00400000").add(20));
+ instr = listing.getInstructionAt(addr(ovBlockName + ":" + "0x00400000").add(20));
assertNoOperandReference(1, instr);
- assertOperandReferenceTo(0, instr, addr(ovBlockName+":"+"0x0040e910"));
-
- instr = listing.getInstructionAt(addr(ovBlockName+":"+"0x00400000").add(24));
+ assertOperandReferenceTo(0, instr, addr(ovBlockName + ":" + "0x0040e910"));
+
+ instr = listing.getInstructionAt(addr(ovBlockName + ":" + "0x00400000").add(24));
assertNoOperandReference(1, instr);
- assertOperandReferenceTo(0, instr, addr(ovBlockName+":"+"0x0040e900"));
- }
+ assertOperandReferenceTo(0, instr, addr(ovBlockName + ":" + "0x0040e900"));
+ }
-
-
@Test
- public void testPIC_Call_X86_64() throws Exception {
-
+ public void testPIC_Call_X86_64() throws Exception {
+
builder = new ProgramBuilder("PICCode", ProgramBuilder._X64, "gcc", this);
- // entry
- // 48 83 ec 28 SUB RSP,0x28
+ // entry
+ // 48 83 ec 28 SUB RSP,0x28
// e8 00 00 00 00 CALL LAB_140020119
// LAB_140020119
- // 8f c3 POP RBX
- // 48 8d 43 e0 LEA RAX,[RBX + -0x20]
+ // 8f c3 POP RBX
+ // 48 8d 43 e0 LEA RAX,[RBX + -0x20]
// ff d0 CALL RAX
- // 48 83 c4 28 ADD RSP,0x28
- // c3 RET
+ // 48 83 c4 28 ADD RSP,0x28
+ // c3 RET
builder.setBytes("0x140020110",
- "48 83 ec 28 e8 00 00 00 00 8f c3 48 8d 43 e0 ff d0 48 83 c4 28 c3");
-
- builder.setBytes("0x1400200f9",
- "15 02 2f 00 00 89 05 e8 b9 00 00 48 83 c4 38");
+ "48 83 ec 28 e8 00 00 00 00 8f c3 48 8d 43 e0 ff d0 48 83 c4 28 c3");
+
+ builder.setBytes("0x1400200f9", "15 02 2f 00 00 89 05 e8 b9 00 00 48 83 c4 38");
builder.disassemble("0x140020110", 21);
@@ -498,7 +502,7 @@ public class ConstantPropogationReferenceTest extends AbstractGenericTest {
program = builder.getProgram();
program.startTransaction("Test");
-
+
Address codeStart = addr("140020110");
Listing listing = program.getListing();
assertNotNull("Bad instruction disassembly", listing.getInstructionAt(codeStart));
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/PrototypeModel.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/PrototypeModel.java
index 804105b28f..787760c3f5 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/PrototypeModel.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/PrototypeModel.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -239,6 +239,10 @@ public class PrototypeModel {
* i.e. {@link AutoParameterType#RETURN_STORAGE_PTR}, this routine will not pass back
* the storage location of the pointer, but will typically pass
* back the location of the normal return register which holds a copy of the pointer.
+ * <br>
+ * Note: storage will not be assigned to the {@link DataType#DEFAULT default undefined} datatype
+ * or zero-length datatype.
+ *
* @param dataType first parameter dataType or null for an undefined type.
* @param program is the Program
* @return return location or {@link VariableStorage#UNASSIGNED_STORAGE} if
@@ -259,6 +263,16 @@ public class PrototypeModel {
* Get the preferred parameter location for a new parameter which will appended
* to the end of an existing set of params. If existing parameters use custom
* storage, this method should not be used.
+ * <br>
+ * Note: storage will not be assigned to the {@link DataType#DEFAULT default undefined} datatype,
+ * zero-length datatype, or any subsequent parameter following such a parameter.
+ * <br>
+ * Warning: The use of this method is discourage since it can produce inaccurate
+ * results. It is recommended that a complete function signature be used in
+ * conjunction with the {@link #getStorageLocations(Program, DataType[], boolean)}
+ * method. Parameter storage allocation may be affected by the return datatype
+ * used on a function (e.g., hidden return storage parameter).
+ *
* @param params existing set parameters to which the next parameter will
* be appended. (may be null)
* @param dataType dataType associated with next parameter location or null
@@ -266,7 +280,9 @@ public class PrototypeModel {
* @param program is the Program
* @return next parameter location or {@link VariableStorage#UNASSIGNED_STORAGE} if
* unable to determine suitable location
+ * @deprecated use of {@link #getStorageLocations(Program, DataType[], boolean)} is preferred.
*/
+ @Deprecated
public VariableStorage getNextArgLocation(Parameter[] params, DataType dataType,
Program program) {
return getArgLocation(params != null ? params.length : 0, params, dataType, program);
@@ -276,15 +292,31 @@ public class PrototypeModel {
* Get the preferred parameter location for a specified index,
* which will be added/inserted within the set of existing function params.
* If existing parameters use custom storage, this method should not be used.
+ * <br>
+ * Note: storage will not be assigned to the {@link DataType#DEFAULT default undefined} datatype,
+ * zero-length datatype, or any subsequent parameter following such a parameter.
+ * <br>
+ * Warning: The use of this method is discourage since it can produce inaccurate
+ * results. It is recommended that a complete function signature be used in
+ * conjunction with the {@link #getStorageLocations(Program, DataType[], boolean)}
+ * method. Parameter storage allocation may be affected by the return datatype
+ * used on a function (e.g., hidden return storage parameter).
+ *
* @param argIndex is the index
* @param params existing set parameters to which the parameter specified by
- * argIndex will be added/inserted be appended (may be null).
+ * argIndex will be added/inserted be appended. The preceeding parameters
+ * are required for an accurate storage determination to be made. Any preceeding
+ * parameters not specified will be assumed as a 1-byte integer type which could
+ * cause an erroneous storage result to be returned. A null params list will cause
+ * all preceeding params to be assumed in a similar fashion.
* @param dataType dataType associated with next parameter location or null
* for a default undefined type.
* @param program is the Program
* @return parameter location or {@link VariableStorage#UNASSIGNED_STORAGE} if
* unable to determine suitable location
+ * @deprecated use of {@link #getStorageLocations(Program, DataType[], boolean)} is preferred.
*/
+ @Deprecated
public VariableStorage getArgLocation(int argIndex, Parameter[] params, DataType dataType,
Program program) {
@@ -302,7 +334,7 @@ public class PrototypeModel {
arr[i + 1] = params[i].getDataType(); // Copy in current types if we have them
}
else {
- arr[i + 1] = DataType.DEFAULT; // Otherwise assume default (integer) type
+ arr[i + 1] = Undefined1DataType.dataType; // Otherwise assume 1-byte (integer) type
}
}
arr[argIndex + 1] = dataType;
@@ -353,6 +385,10 @@ public class PrototypeModel {
* input parameters, if needed. In this case, the dataTypes array should not include explicit entries for
* these parameters. If addAutoParams is false, the dataTypes array is assumed to already contain explicit
* entries for any of these parameters.
+ * <br>
+ * Note: storage will not be assigned to the {@link DataType#DEFAULT default undefined} datatype
+ * or zero-length datatypes or any subsequent parameter following such a parameter.
+ *
* @param program is the Program
* @param dataTypes return/parameter datatypes (first element is always the return datatype,
* i.e., minimum array length is 1)