mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-3216 Fixed CParser creation of Enums from define's with upper and
lower case u,l,ul when value surrounded by parentheses
This commit is contained in:
parent
cc6abb596d
commit
b10d01a2cb
4 changed files with 46 additions and 4 deletions
|
@ -77,6 +77,15 @@ public class AddressEvaluatorTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertEquals(addr("0x1"), AddressEvaluator.evaluate(p, "(((0x1 | 0x2) & 0x2) >= 0x1)"));
|
assertEquals(addr("0x1"), AddressEvaluator.evaluate(p, "(((0x1 | 0x2) & 0x2) >= 0x1)"));
|
||||||
assertEquals(addr("0x0"), AddressEvaluator.evaluate(p, "(((0x1 | 0x2) & 0x2) <= 0x1)"));
|
assertEquals(addr("0x0"), AddressEvaluator.evaluate(p, "(((0x1 | 0x2) & 0x2) <= 0x1)"));
|
||||||
|
|
||||||
|
assertEquals(addr("0x4"), AddressEvaluator.evaluate(p, "(4ul)"));
|
||||||
|
assertEquals(addr("0x4"), AddressEvaluator.evaluate(p, "(4UL)"));
|
||||||
|
assertEquals(addr("0x4"), AddressEvaluator.evaluate(p, "( 4l )"));
|
||||||
|
assertEquals(addr("0x4"), AddressEvaluator.evaluate(p, "(4L)"));
|
||||||
|
assertEquals(addr("0x4"), AddressEvaluator.evaluate(p, "(4u )"));
|
||||||
|
assertEquals(addr("0x4"), AddressEvaluator.evaluate(p, "( 4U)"));
|
||||||
|
|
||||||
|
assertEquals(null, AddressEvaluator.evaluate(p, "( 4P)"));
|
||||||
|
|
||||||
Symbol s = p.getSymbolTable().createLabel(addr("0x100"), "entry", SourceType.IMPORTED);
|
Symbol s = p.getSymbolTable().createLabel(addr("0x100"), "entry", SourceType.IMPORTED);
|
||||||
Address a = s.getAddress();
|
Address a = s.getAddress();
|
||||||
a = a.add(10);
|
a = a.add(10);
|
||||||
|
|
|
@ -158,6 +158,30 @@ public class PreProcessorTest extends AbstractGenericTest {
|
||||||
defname = "DefVal10";
|
defname = "DefVal10";
|
||||||
checkDefine(dtMgr, path, value, defname);
|
checkDefine(dtMgr, path, value, defname);
|
||||||
|
|
||||||
|
value = 1;
|
||||||
|
defname = "DefVal_1L";
|
||||||
|
checkDefine(dtMgr, path, value, defname);
|
||||||
|
|
||||||
|
value = 2;
|
||||||
|
defname = "DefVal_2l";
|
||||||
|
checkDefine(dtMgr, path, value, defname);
|
||||||
|
|
||||||
|
value = 3;
|
||||||
|
defname = "DefVal_3U";
|
||||||
|
checkDefine(dtMgr, path, value, defname);
|
||||||
|
|
||||||
|
value = 4;
|
||||||
|
defname = "DefVal_4u";
|
||||||
|
checkDefine(dtMgr, path, value, defname);
|
||||||
|
|
||||||
|
value = 5;
|
||||||
|
defname = "DefVal_5UL";
|
||||||
|
checkDefine(dtMgr, path, value, defname);
|
||||||
|
|
||||||
|
value = 6;
|
||||||
|
defname = "DefVal_6ul";
|
||||||
|
checkDefine(dtMgr, path, value, defname);
|
||||||
|
|
||||||
value = 0;
|
value = 0;
|
||||||
defname = "TOO_MANY_FISH";
|
defname = "TOO_MANY_FISH";
|
||||||
checkDefine(dtMgr, path, value, defname);
|
checkDefine(dtMgr, path, value, defname);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#undef a
|
#undef a
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* definition coming from -D, should evaluate to true */
|
/* definition coming from -D, should evaluate to true */
|
||||||
#if FROM_ARG_VALUE
|
#if FROM_ARG_VALUE
|
||||||
#define DID_ARG_VALUE 1
|
#define DID_ARG_VALUE 1
|
||||||
|
@ -218,6 +219,13 @@ int TEST_FAILED;
|
||||||
|
|
||||||
#define DefVal10 ((0x7fff) * 900L / 1000)
|
#define DefVal10 ((0x7fff) * 900L / 1000)
|
||||||
|
|
||||||
|
#define DefVal_1L (1L)
|
||||||
|
#define DefVal_2l (2l)
|
||||||
|
#define DefVal_3U (3U )
|
||||||
|
#define DefVal_4u ( 4u)
|
||||||
|
#define DefVal_5UL ( 5UL )
|
||||||
|
#define DefVal_6ul (6ul)
|
||||||
|
|
||||||
#define BIGNUM 64 * 16 + 16
|
#define BIGNUM 64 * 16 + 16
|
||||||
|
|
||||||
#define ImOctal 01234567
|
#define ImOctal 01234567
|
||||||
|
|
|
@ -257,7 +257,7 @@ public class AddressEvaluator {
|
||||||
if (globalSymbols.size() == 1) {
|
if (globalSymbols.size() == 1) {
|
||||||
return globalSymbols.get(0).getAddress();
|
return globalSymbols.get(0).getAddress();
|
||||||
}
|
}
|
||||||
return null;
|
return getValueObject(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object getValueObject(String strValue) {
|
private static Object getValueObject(String strValue) {
|
||||||
|
@ -268,10 +268,11 @@ public class AddressEvaluator {
|
||||||
start = 2;
|
start = 2;
|
||||||
radix = 16;
|
radix = 16;
|
||||||
}
|
}
|
||||||
if (strValue.endsWith("UL")) {
|
strValue = strValue.toLowerCase();
|
||||||
|
if (strValue.endsWith("ul")) {
|
||||||
strValue = strValue.substring(start, strValue.length() - 2);
|
strValue = strValue.substring(start, strValue.length() - 2);
|
||||||
}
|
}
|
||||||
else if (strValue.endsWith("L") || strValue.endsWith("l") || strValue.endsWith("U")) {
|
else if (strValue.endsWith("l") || strValue.endsWith("u")) {
|
||||||
strValue = strValue.substring(start, strValue.length() - 1);
|
strValue = strValue.substring(start, strValue.length() - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue