summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAndrew Lamoureux <andrew@vector35.com>2021-09-13 17:47:44 -0400
committerAndrew Lamoureux <andrew@vector35.com>2021-09-13 17:47:44 -0400
commit24d7fb807512c32f6e36af71fc6c5c7f5e3c2711 (patch)
tree13170e8aac5fba81f3285d79e8833a74d4c96cfa /python
parentbf2d0be05c7fa0558997fe34c66149787c0bea86 (diff)
Update typelib_create, typelib_dump examples to new API
Diffstat (limited to 'python')
-rwxr-xr-xpython/examples/typelib_create.py5
-rwxr-xr-xpython/examples/typelib_dump.py10
2 files changed, 8 insertions, 7 deletions
diff --git a/python/examples/typelib_create.py b/python/examples/typelib_create.py
index 61941822..303fa350 100755
--- a/python/examples/typelib_create.py
+++ b/python/examples/typelib_create.py
@@ -39,7 +39,7 @@ typelib.add_named_type('MyTypedefType', Type.int(4))
# example of typedef to typedef
# typedef MyTypedefType MySuperSpecialType;
def create_named_type_reference(type_name:str, to_what:NamedTypeReferenceClass):
- return NamedTypeReferenceType(named_type_class=to_what, name=type_name)
+ return NamedTypeReferenceType.create(named_type_class=to_what, guid=None, name=type_name)
typelib.add_named_type('MySuperSpecialType',
create_named_type_reference('MySpecialType', NamedTypeReferenceClass.TypedefNamedTypeClass))
@@ -80,7 +80,7 @@ with StructureBuilder.builder(typelib, 'Rectangle2') as struct_type:
'center')
# example: EnumerationTypeClass
-enum_type = EnumerationBuilder.create(arch)
+enum_type = EnumerationBuilder.create([], None, arch=arch)
enum_type.append('RED', 0)
enum_type.append('ORANGE', 1)
enum_type.append('YELLOW', 2)
@@ -117,5 +117,6 @@ typelib.add_named_object('_MySuperComputation', ftype)
# finalize
typelib.finalize()
+print('writing test.bntl')
typelib.write_to_file('test.bntl')
diff --git a/python/examples/typelib_dump.py b/python/examples/typelib_dump.py
index 90f6700d..4beff0db 100755
--- a/python/examples/typelib_dump.py
+++ b/python/examples/typelib_dump.py
@@ -22,7 +22,7 @@ def obj2str(t, depth=0):
indent = ' '*depth
result = ''
- if type(t) == binaryninja.types.Structure:
+ if type(t) == binaryninja.types.StructureType:
result = '%sStructure\n' % (indent)
for m in t.members:
result += obj2str(m, depth+1)
@@ -32,9 +32,9 @@ def obj2str(t, depth=0):
elif type(t) == binaryninja.types.FunctionParameter:
result = '%sFunctionParameter "%s"\n' % (indent, t.name)
result += type2str(t.type, depth+1)
- elif type(t) == binaryninja.types.NamedTypeReference:
+ elif type(t) == binaryninja.types.NamedTypeReferenceType:
result = '%sNamedTypeReference %s\n' % (indent, repr(t))
- elif type(t) == binaryninja.types.Enumeration:
+ elif type(t) == binaryninja.types.EnumerationType:
result = '%sEnumeration\n' % indent
for m in t.members:
result += obj2str(m, depth+1)
@@ -49,7 +49,7 @@ def type2str(t:binaryninja.types.Type, depth=0):
indent = ' '*depth
result = 'unimplemented'
- assert type(t) == binaryninja.types.Type
+ assert isinstance(t, binaryninja.types.Type)
tc = t.type_class
if tc == TypeClass.VoidTypeClass:
@@ -68,7 +68,7 @@ def type2str(t:binaryninja.types.Type, depth=0):
result += obj2str(t.enumeration, depth+1)
elif tc == TypeClass.PointerTypeClass:
result = '%sType class=Pointer\n' % indent
- result += type2str(t.element_type, depth+1)
+ result += type2str(t.target, depth+1)
elif tc == TypeClass.ArrayTypeClass:
result = '%sType class=Array\n' % indent
elif tc == TypeClass.FunctionTypeClass: