summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2019-09-21 21:58:47 -0400
committerBrian Potchik <brian@vector35.com>2019-09-21 21:58:47 -0400
commit55cec0cdaf8df2fecb1e65c348aebf948b10e67e (patch)
tree498345c7e09aa583bed1e8cc479859e754d30230 /python
parent895972365e11346bf9cfcab1e73b882366f5b9bb (diff)
Add 'get_view_of_file_with_options' method to the BinaryViewType Python API.
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index aef72a6a..6d29b469 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -24,6 +24,7 @@ import traceback
import ctypes
import abc
import numbers
+import json
from collections import OrderedDict
@@ -663,7 +664,7 @@ class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
if isDatabase:
bv = view.get_view_of_type(available.name)
else:
- bv = cls[available.name].open(filename)
+ bv = available.open(filename)
break
else:
if isDatabase:
@@ -675,6 +676,34 @@ class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
bv.update_analysis_and_wait()
return bv
+ @classmethod
+ def get_view_of_file_with_options(cls, filename, update_analysis=True, options={}):
+ view = BinaryView.open(filename)
+ if view is None:
+ return None
+ bvt = None
+ for available in view.available_view_types:
+ if available.name != "Raw":
+ bvt = available
+ break
+
+ if bvt is None:
+ bvt = cls["Mapped"]
+
+ load_settings = bvt.get_load_settings_for_data(view)
+ load_settings.set_resource_id(bvt.name)
+ view.set_load_settings(bvt.name, load_settings)
+ for key, value in options.items():
+ if load_settings.contains(key):
+ load_settings.set_json(key, json.dumps(value), view)
+ else:
+ log.log_warn("Load Setting: {} not available!".format(key))
+
+ bv = bvt.create(view)
+
+ if bv is not None and update_analysis:
+ bv.update_analysis_and_wait()
+ return bv
def is_valid_for_data(self, data):
return core.BNIsBinaryViewTypeValidForData(self.handle, data.handle)