Skip to content

Commit

Permalink
Merge pull request #20 from zznop/19-struct-bug
Browse files Browse the repository at this point in the history
Fixed struct bug from missing types
  • Loading branch information
Brandon Miller authored Dec 27, 2019
2 parents 7c30da8 + 70703ac commit 8bd7324
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions binja/binja_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from collections import OrderedDict
from binaryninja import *

"""
Expand Down Expand Up @@ -76,7 +77,7 @@ def open_json_file(self, json_file):
"""

f = open(json_file, 'rb')
return json.load(f)
return json.load(f, object_pairs_hook=OrderedDict)

def import_functions(self, functions, sections):
"""
Expand Down Expand Up @@ -146,7 +147,12 @@ def import_structures(self, structs):
for struct_name, struct_info in structs.items():
struct = types.Structure()
for member_name, member_info in struct_info['members'].items():
typ, _ = self.bv.parse_type_string('{}'.format(member_info['type']))
try:
typ, _ = self.bv.parse_type_string('{}'.format(member_info['type']))
except SyntaxError:
print('Failed to apply type ({}) to member ({}) in structure ({})'.format(
member_info['type'], member_name, struct_name))
typ, _ = self.bv.parse_type_string('uint8_t [{}]'.format(member_info['size']))
struct.insert(int(member_info['offset']), typ, member_name)

self.bv.define_user_type(struct_name, Type.structure_type(struct))
Expand Down
3 changes: 2 additions & 1 deletion ida/ida_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ida_bytes
import idautils
import json
from collections import OrderedDict

"""
Exports analysis data from IDA to a bnida json file
Expand Down Expand Up @@ -209,7 +210,7 @@ def get_structs():
:return: Dict containing structure info
"""

structs = {}
structs = OrderedDict()
for idx, sid, name in idautils.Structs():
struct = ida_struct.get_struc(sid)
structs[name] = {}
Expand Down

0 comments on commit 8bd7324

Please sign in to comment.