summaryrefslogtreecommitdiff
path: root/python/examples/kaitai/view.py
diff options
context:
space:
mode:
authorAndrew Lamoureux <andrew@vector35.com>2019-03-21 17:49:02 -0400
committerAndrew Lamoureux <andrew@vector35.com>2019-03-21 17:49:02 -0400
commita6355074d451e9ba9b85f17bfcd7c273ec18ecfa (patch)
treeb5dae98e70afcb7a3c986851fb11d8a90391d018 /python/examples/kaitai/view.py
parenta79cc606a332377f5923f085dee953871ef72a05 (diff)
kaitai: statusbar widget menu to select any format
also: stop assuming file size on startup, return priority 1 (not 0)
Diffstat (limited to 'python/examples/kaitai/view.py')
-rw-r--r--python/examples/kaitai/view.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/python/examples/kaitai/view.py b/python/examples/kaitai/view.py
index c37711d8..ee1ef6c0 100644
--- a/python/examples/kaitai/view.py
+++ b/python/examples/kaitai/view.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
# python stuff
import io
import os
@@ -6,14 +8,16 @@ import types
import traceback
# binja stuff
-import binaryninjaui
-from binaryninja.settings import Settings
from binaryninja import log
-from binaryninja import _binaryninjacore as core
-from binaryninjaui import View, ViewType, ViewFrame, UIContext, HexEditor
from binaryninja import binaryview
-from PySide2.QtWidgets import QScrollArea, QWidget, QVBoxLayout, QGroupBox, QTreeWidget, QTreeWidgetItem, QLineEdit, QHeaderView
+from binaryninja.settings import Settings
+from binaryninja import _binaryninjacore as core
+from binaryninjaui import View, ViewType, ViewFrame, UIContext, HexEditor, getMonospaceFont
+
from PySide2.QtCore import Qt
+from PySide2.QtWidgets import QScrollArea, QWidget, QVBoxLayout, QGroupBox, QTreeWidget, QTreeWidgetItem, QLineEdit, QHeaderView
+
+from . import menu
if sys.version_info[0] == 2:
import kshelpers
@@ -68,15 +72,19 @@ class KaitaiView(QScrollArea, View):
self.kaitaiParse()
# parse the file using Kaitai, construct the TreeWidget
- def kaitaiParse(self):
- parsed = None
+ def kaitaiParse(self, formatName=None):
+ #print('kaitaiParse() with len(bv)=%d and bv.file.filename=%s' % (len(self.binaryView), self.binaryView.file.filename))
+
+ if len(self.binaryView) == 0:
+ return
kaitaiIO = kshelpers.KaitaiBinaryViewIO(self.binaryView)
if not kaitaiIO:
print('ERROR: initializing kaitai binary view')
- parsed = kshelpers.parseIo(kaitaiIO)
+ parsed = kshelpers.parseIo(kaitaiIO, formatName)
if not parsed:
print('ERROR: parsing the binary view')
+ return
tree = kshelpers.buildQtree(parsed)
if not tree:
@@ -240,6 +248,9 @@ class KaitaiView(QScrollArea, View):
# set hex group title to reflect current selection
#self.hexGroup.setTitle('Hex View @ [0x%X, 0x%X)' % (start, end))
+ def getStatusBarWidget(self):
+ return menu.KaitaiStatusBarWidget(self)
+
class KaitaiViewType(ViewType):
def __init__(self):
super(KaitaiViewType, self).__init__("Kaitai", "Kaitai")
@@ -252,22 +263,19 @@ class KaitaiViewType(ViewType):
# executable means the view is mapped like an OS loader would load an executable (eg: view=ELF)
# !executable means executable image is not mapped (eg: view=Raw) (or something like .png is loaded)
if binaryView.executable:
- return 0
+ return 1
if binaryView.start != 0:
- return 0
-
- if os.path.getsize(binaryView.file.filename) != len(binaryView):
- return 0
+ return 1
dataSample = binaryView.read(0, 16)
if len(dataSample) != 16:
- return 0
+ return 1
# if we don't recognize it, return 0
ksModuleName = kshelpers.idData(dataSample, len(binaryView))
if not ksModuleName:
- return 0
+ return 1
# for executables, yield triage (25)
if ksModuleName in ['elf', 'microsoft_pe', 'mach_o']: