Skip to content

Commit

Permalink
Update bnida to support the latest Binary Ninja API 3.4.4271 @Diefunc…
Browse files Browse the repository at this point in the history
  • Loading branch information
Diefunction authored Jun 22, 2023
1 parent 27dd411 commit 33a318d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
36 changes: 16 additions & 20 deletions binja/binja_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import json
from binaryninja import SaveFileNameField, get_form_input, BackgroundTaskThread
from binaryninja import SaveFileNameField, get_form_input, BackgroundTaskThread, types
from collections import OrderedDict


Expand Down Expand Up @@ -110,27 +110,23 @@ def get_structures(self):
"""

structures = OrderedDict()
for type_token in self.bv.types:
typ = self.bv.get_type_by_name(type_token)
if typ.structure is None:
continue

struct_name = type_token.name[0]
members = {}
for member in typ.structure.members:
members[member.name] = {}
members[member.name]['offset'] = member.offset
members[member.name]['size'] = member.type.width
members[member.name]['type'] = ''
for token in member.type.tokens:
members[member.name]['type'] += str(token)

structures[struct_name] = {}
structures[struct_name]['size'] = typ.structure.width
structures[struct_name]['members'] = members

for type_name, vtype in self.bv.types:
if type(vtype) == types.StructureType:
struct_name = str(type_name)
members = {}
for member in vtype.members:
members[member.name] = {}
members[member.name]['offset'] = member.offset
members[member.name]['size'] = member.type.width
members[member.name]['type'] = ''
for token in member.type.tokens:
members[member.name]['type'] += str(token)
structures[struct_name] = {}
structures[struct_name]['size'] = vtype.width
structures[struct_name]['members'] = members
return structures


def run(self):
"""
Export analysis data to bnida JSON file
Expand Down
2 changes: 1 addition & 1 deletion binja/binja_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def import_structures(self, structs):
"""

for struct_name, struct_info in structs.items():
struct = types.Structure()
struct = types.StructureBuilder.create()
for member_name, member_info in struct_info['members'].items():
try:
typ, _ = self.bv.parse_type_string('{}'.format(
Expand Down

0 comments on commit 33a318d

Please sign in to comment.