Skip to content

Commit b49a0e5

Browse files
committed
Additional end-to-end testing and bug resolution
1 parent dfb4380 commit b49a0e5

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

genprog_decomp_ida.py

Lines changed: 47 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,18 @@ 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+
wrapperStub += " // --- END OF WARNING!\n"
894+
elif array_size==1 and "*" not in dataType:
895+
dataNamex = dataName.split("[")[0] # handle arrays
896+
wrapperStub += "\tvoid* my%s,\n" % dataNamex
897+
else:
898+
wrapperStub += "\tvoid* my%s,\n" % dataName
873899
print(" - DATA DECL: ", dataName)
874900

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

904938
for s in stubMap.keys():
905939
name = self.get_stub_name(s)
@@ -1101,7 +1135,10 @@ def run(self):
11011135

11021136

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

0 commit comments

Comments
 (0)