Skip to content

Commit 4d63a20

Browse files
authored
Merge pull request #4 from pdreiter/end-to-end-testing
End to end testing
2 parents 9f206c3 + 0fc7b0e commit 4d63a20

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

genprog_decomp_ida.py

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
IDA_DEFAULT_PATH=os.environ['HOME']+"/seclab_ida/ida/idat"
1313
if os.environ['IDA_BASE_DIR']:
14-
IDA_PATH=os.environ['IDA_BASE_DIR']+"/idat"
14+
IDA_PATH=os.environ['IDA_BASE_DIR']+"/idat"
1515
else:
16-
IDA_PATH=IDA_DEFAULT_PATH
16+
IDA_PATH=IDA_DEFAULT_PATH
1717

1818
# path to defs.h
1919
DEFS_PATH=os.path.dirname(os.path.realpath(__file__))+"/refs/defs.h"
@@ -649,9 +649,24 @@ def get_data_declarations(self, lines):
649649
header = header[3:] # handle commented out cases
650650

651651
dataType, dataName = self.getTypeAndLabel(header)
652-
defLine = "%s *(p%s);\n" %(dataType, dataName)
653-
dataName = dataName.split("[")[0] # handle arrays
654-
defLine += "#define %s (*p%s)\n" % (dataName, dataName)
652+
array_size=len(re.findall("\[\d*\]",dataName))
653+
print("Array Size:", array_size)
654+
defLine=""
655+
if array_size>=2:
656+
print("// --- WARNING! Two-dimensional array objects are not yet supported")
657+
defLine += "%s *(p%s);\n" %(dataType, dataName)
658+
dataName = dataName.split("[")[0] # handle arrays
659+
defLine += "#define %s (*p%s)\n" % (dataName, dataName)
660+
print(" // --- END OF WARNING!\n")
661+
elif array_size==1 and "*" not in dataType:
662+
dataName = dataName.split("[")[0] # handle arrays
663+
defLine = "%s *(p%s);\n" %(dataType, dataName)
664+
defLine += "#define %s (p%s)\n" % (dataName, dataName)
665+
else:
666+
defLine = "%s *(p%s);\n" %(dataType, dataName)
667+
dataName = dataName.split("[")[0] # handle arrays
668+
defLine += "#define %s (*p%s)\n" % (dataName, dataName)
669+
655670
if line.startswith("//"):
656671
defLine += "//"
657672
print(" ---->", defLine)
@@ -859,7 +874,7 @@ def generate_wrapper(self, target, funcs, stubMap, dataMap):
859874
wrapperStub += " my%s,\n" % self.get_stub_name(s)
860875
print(s)
861876
print(" - STUBNAME: ", self.get_stub_name(s))
862-
877+
863878
# note from pdr: looks like when data declarations are included, the
864879
# function prototype and funcstubs order of symbol definitions
865880
# are not consistent
@@ -869,7 +884,17 @@ def generate_wrapper(self, target, funcs, stubMap, dataMap):
869884
dataDef = d.split(";")[0]
870885
dataDef = dataDef.split("=")[0].strip()
871886
dataType, dataName = self.getTypeAndLabel(dataDef)
872-
wrapperStub += "\tvoid* my%s,\n" % dataName
887+
array_size=len(re.findall("\[\d*\]",dataName))
888+
if array_size>=2:
889+
print("SORRY: two-dimensional array objects just aren't working right now")
890+
print(" ==> "+dataType+" "+dataName)
891+
wrapperStub += "// --- WARNING! Two-dimensional array objects are not yet supported"
892+
wrapperStub += "\tvoid* my%s,\n" % dataName
893+
elif array_size==1 and "*" not in dataType:
894+
dataNamex = dataName.split("[")[0] # handle arrays
895+
wrapperStub += "\tvoid* my%s,\n" % dataNamex
896+
else:
897+
wrapperStub += "\tvoid* my%s,\n" % dataName
873898
print(" - DATA DECL: ", dataName)
874899

875900
for argTuple in args:
@@ -898,8 +923,16 @@ def generate_wrapper(self, target, funcs, stubMap, dataMap):
898923
dataDef = dataDef[3:] # handle commented out cases
899924
dataDef = dataDef.split("=")[0].strip()
900925
dataType, dataName = self.getTypeAndLabel(dataDef)
901-
wrapperStub += "\tp%s = (%s*) my%s;\n" % (dataName, dataType, dataName)
902-
926+
array_size=len(re.findall("\[\d*\]",dataName))
927+
if array_size>=2:
928+
print("// --- WARNING! Two-dimensional array objects are not yet supported\n")
929+
wrapperStub += "\tp%s = (%s*) my%s;\n" % (dataName, dataType, dataName)
930+
print(" // --- END OF WARNING!\n")
931+
elif array_size==1 and "*" not in dataType:
932+
dataNamex = dataName.split("[")[0] # handle arrays
933+
wrapperStub += "\tp%s = (%s*) my%s;\n" % (dataNamex, dataType, dataNamex)
934+
else:
935+
wrapperStub += "\tp%s = (%s*) my%s;\n" % (dataName, dataType, dataName)
903936

904937
for s in stubMap.keys():
905938
name = self.get_stub_name(s)
@@ -1101,7 +1134,10 @@ def run(self):
11011134

11021135

11031136
def main():
1104-
1137+
if not os.path.isfile(IDA_PATH):
1138+
print("ERROR: Environmental variable IDA_BASE_PATH is not set or '"+IDA_DEFAULT_PATH+"' does not exist")
1139+
import sys
1140+
sys.exit(-1)
11051141
parser = argparse.ArgumentParser(description='')
11061142
parser.add_argument('target_list',
11071143
help='path to the list of target binaries + paths')

refs/defs.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
#define LODWORD(x) (*((unsigned int*)&(x)))
55
#define HIWORD(x) (*((unsigned short*)&(x)+1))
66
#define LOWORD(x) (*((unsigned short*)&(x)))
7-
#define COERCE_UNSIGNED_INT64(x) (*((unsigned long*)(&x)))
7+
#define COERCE_UNSIGNED_INT64(x) (*((unsigned long*)(&x)))
8+
#define HIBYTE(x) (*((unsigned char*)&(x)+1))
9+
10+
11+
// from IDADOC support: _OWORD is an unknown type; the only known info is its size: 16 bytes
12+
#define _OWORD (unsigned long long)
13+

0 commit comments

Comments
 (0)