summaryrefslogtreecommitdiff
path: root/python/examples
diff options
context:
space:
mode:
Diffstat (limited to 'python/examples')
-rw-r--r--python/examples/angr_plugin.py17
-rw-r--r--python/examples/bin_info.py48
-rwxr-xr-xpython/examples/export_svg.py86
-rw-r--r--python/examples/instruction_iterator.py33
-rw-r--r--python/examples/jump_table.py27
-rw-r--r--python/examples/nds.py24
-rw-r--r--python/examples/nes.py212
-rw-r--r--python/examples/print_syscalls.py32
-rw-r--r--python/examples/version_switcher.py20
9 files changed, 329 insertions, 170 deletions
diff --git a/python/examples/angr_plugin.py b/python/examples/angr_plugin.py
index c6e6f87d..675cc5f6 100644
--- a/python/examples/angr_plugin.py
+++ b/python/examples/angr_plugin.py
@@ -12,8 +12,8 @@
__name__ = "__console__" # angr looks for this, it won't load from within a UI without it
import angr
from binaryninja import *
+
import tempfile
-import threading
import logging
import os
@@ -24,9 +24,11 @@ logging.disable(logging.WARNING)
BinaryView.set_default_session_data("angr_find", set())
BinaryView.set_default_session_data("angr_avoid", set())
+
def escaped_output(str):
return '\n'.join([s.encode("string_escape") for s in str.split('\n')])
+
# Define a background thread object for solving in the background
class Solver(BackgroundTaskThread):
def __init__(self, find, avoid, view):
@@ -81,31 +83,34 @@ class Solver(BackgroundTaskThread):
else:
show_plain_text_report("Results from angr", text_report)
+
def find_instr(bv, addr):
# Highlight the instruction in green
blocks = bv.get_basic_blocks_at(addr)
for block in blocks:
- block.set_auto_highlight(HighlightColor(GreenHighlightColor, alpha = 128))
- block.function.set_auto_instr_highlight(block.arch, addr, GreenHighlightColor)
+ block.set_auto_highlight(HighlightColor(core.BNHighlightStandardColor.GreenHighlightColor, alpha = 128))
+ block.function.set_auto_instr_highlight(block.arch, addr, core.BNHighlightStandardColor.GreenHighlightColor)
# Add the instruction to the list associated with the current view
bv.session_data.angr_find.add(addr)
+
def avoid_instr(bv, addr):
# Highlight the instruction in red
blocks = bv.get_basic_blocks_at(addr)
for block in blocks:
- block.set_auto_highlight(HighlightColor(RedHighlightColor, alpha = 128))
- block.function.set_auto_instr_highlight(block.arch, addr, RedHighlightColor)
+ block.set_auto_highlight(HighlightColor(core.BNHighlightStandardColor.RedHighlightColor, alpha = 128))
+ block.function.set_auto_instr_highlight(block.arch, addr, core.BNHighlightStandardColor.RedHighlightColor)
# Add the instruction to the list associated with the current view
bv.session_data.angr_avoid.add(addr)
+
def solve(bv):
if len(bv.session_data.angr_find) == 0:
show_message_box("Angr Solve", "You have not specified a goal instruction.\n\n" +
"Please right click on the goal instruction and select \"Find Path to This Instruction\" to " +
- "continue.", OKButtonSet, ErrorIcon)
+ "continue.", core.BNMessageBoxButtonSet.OKButtonSet, core.BNMessageBoxButtonSet.ErrorIcon)
return
# Start a solver thread for the path associated with the view
diff --git a/python/examples/bin_info.py b/python/examples/bin_info.py
index 48073894..ab963e4e 100644
--- a/python/examples/bin_info.py
+++ b/python/examples/bin_info.py
@@ -1,11 +1,33 @@
#!/usr/bin/env python
-import sys, binaryninja, time
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+import sys
+import binaryninja
+
if sys.platform.lower().startswith("linux"):
- bintype="ELF"
+ bintype = "ELF"
elif sys.platform.lower() == "darwin":
- bintype="Mach-O"
+ bintype = "Mach-O"
else:
- raise Exception, "%s is not supported on this plugin" % sys.platform
+ raise Exception("%s is not supported on this plugin" % sys.platform)
if len(sys.argv) > 1:
target = sys.argv[1]
@@ -15,20 +37,20 @@ else:
bv = binaryninja.BinaryViewType[bintype].open(target)
bv.update_analysis_and_wait()
-print "-------- %s --------" % target
-print "START: 0x%x" % bv.start
-print "ENTRY: 0x%x" % bv.entry_point
-print "ARCH: %s" % bv.arch.name
-print "\n-------- Function List --------"
+print("-------- %s --------" % target)
+print("START: 0x%x" % bv.start)
+print("ENTRY: 0x%x" % bv.entry_point)
+print("ARCH: %s" % bv.arch.name)
+print("\n-------- Function List --------")
for func in bv.functions:
- print func.symbol.name
+ print(func.symbol.name)
-print "\n-------- First 10 strings --------"
+print("\n-------- First 10 strings --------")
for i in xrange(10):
start = bv.strings[i].start
length = bv.strings[i].length
- string = bv.read(start,length)
- print "0x%x (%d):\t%s" % (start, length, string)
+ string = bv.read(start, length)
+ print("0x%x (%d):\t%s" % (start, length, string))
diff --git a/python/examples/export_svg.py b/python/examples/export_svg.py
index a54dc879..843b17a5 100755
--- a/python/examples/export_svg.py
+++ b/python/examples/export_svg.py
@@ -1,10 +1,30 @@
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
from binaryninja import *
import os
import webbrowser
try:
- from urllib import pathname2url # Python 2.x
+ from urllib import pathname2url # Python 2.x
except:
- from urllib.request import pathname2url # Python 3.x
+ from urllib.request import pathname2url # Python 3.x
colors = {'green': [162, 217, 175], 'red': [222, 143, 151], 'blue': [128, 198, 233], 'cyan': [142, 230, 237], 'lightCyan': [176, 221, 228], 'orange': [237, 189, 129], 'yellow': [237, 223, 179], 'magenta': [218, 196, 209], 'none': [74, 74, 74]}
@@ -17,40 +37,44 @@ escape_table = {
' ': " "
}
+
def escape(string):
- string=string.decode('utf-8').encode('ascii','xmlcharrefreplace') #handle extended unicode
- return ''.join(escape_table.get(i,i) for i in string) #still escape the basics
+ string = string.decode('utf-8').encode('ascii', 'xmlcharrefreplace') # handle extended unicode
+ return ''.join(escape_table.get(i, i) for i in string) # still escape the basics
+
-def save_svg(bv,function):
- address = hex(function.start).replace('L','')
+def save_svg(bv, function):
+ address = hex(function.start).replace('L', '')
path = os.path.dirname(bv.file.filename)
origname = os.path.basename(bv.file.filename)
- filename = os.path.join(path,'binaryninja-{filename}-{function}.html'.format(filename=origname,function=address))
+ filename = os.path.join(path, 'binaryninja-{filename}-{function}.html'.format(filename=origname, function=address))
outputfile = get_save_filename_input('File name for export_svg', 'HTML files (*.html)', filename)
if outputfile is None:
return
content = render_svg(function)
- output = open(outputfile,'w')
+ output = open(outputfile, 'w')
output.write(content)
output.close()
- if show_message_box("Open SVG", "Would you like to view the exported SVG?", buttons = core.YesNoButtonSet, icon = core.QuestionIcon) == core.YesButton:
+ if show_message_box("Open SVG", "Would you like to view the exported SVG?", buttons=core.BNMessageBoxButtonSet.YesNoButtonSet, icon = core.BNMessageBoxIcon.QuestionIcon) == core.BNMessageBoxButtonResult.YesButton:
url = 'file:{}'.format(pathname2url(outputfile))
webbrowser.open(url)
-def instruction_data_flow(function,address):
+
+def instruction_data_flow(function, address):
''' TODO: Extract data flow information '''
- length = function.view.get_instruction_length(function.arch,address)
+ length = function.view.get_instruction_length(function.arch, address)
bytes = function.view.read(address, length)
hex = bytes.encode('hex')
- padded = ' '.join([hex[i:i+2] for i in range(0, len(hex), 2)])
+ padded = ' '.join([hex[i:i + 2] for i in range(0, len(hex), 2)])
return 'Opcode: {bytes}'.format(bytes=padded)
+
def render_svg(function):
graph = function.create_graph()
graph.layout_and_wait()
heightconst = 15
ratio = 0.48
- widthconst = heightconst*ratio
+ widthconst = heightconst * ratio
output = '''<html>
<head>
@@ -130,56 +154,56 @@ def render_svg(function):
<path d="M 0 0 L 10 5 L 0 10 z" />
</marker>
</defs>
- '''.format(width=graph.width*widthconst, height=graph.height*heightconst)
+ '''.format(width=graph.width * widthconst, height=graph.height * heightconst)
output += ''' <g id="functiongraph0" class="functiongraph">
<title>Function Graph 0</title>
'''
edges = ''
- for i,block in enumerate(graph.blocks):
+ for i, block in enumerate(graph.blocks):
- #Calculate basic block location and coordinates
+ # Calculate basic block location and coordinates
x = ((block.x) * widthconst)
y = ((block.y) * heightconst)
width = ((block.width) * widthconst)
height = ((block.height) * heightconst)
- #Render block
+ # Render block
output += ' <g id="basicblock{i}">\n'.format(i=i)
output += ' <title>Basic Block {i}</title>\n'.format(i=i)
- rgb=colors['none']
+ rgb = colors['none']
try:
bb = block.basic_block
color_code = bb.highlight.color
color_str = bb.highlight._standard_color_to_str(color_code)
if color_str in colors:
- rgb=colors[color_str]
+ rgb = colors[color_str]
except:
pass
- output += ' <rect class="basicblock" x="{x}" y="{y}" fill-opacity="0.4" height="{height}" width="{width}" fill="rgb({r},{g},{b})"/>\n'.format(x=x,y=y,width=width,height=height,r=rgb[0],g=rgb[1],b=rgb[2])
+ output += ' <rect class="basicblock" x="{x}" y="{y}" fill-opacity="0.4" height="{height}" width="{width}" fill="rgb({r},{g},{b})"/>\n'.format(x=x, y=y, width=width, height=height, r=rgb[0], g=rgb[1], b=rgb[2])
- #Render instructions, unfortunately tspans don't allow copying/pasting more
- #than one line at a time, need SVG 1.2 textarea tags for that it looks like
+ # Render instructions, unfortunately tspans don't allow copying/pasting more
+ # than one line at a time, need SVG 1.2 textarea tags for that it looks like
- output += ' <text x="{x}" y="{y}">\n'.format(x=x,y=y + (i + 1) * heightconst)
- for i,line in enumerate(block.lines):
- output += ' <tspan id="instr-{address}" x="{x}" y="{y}">'.format(x=x,y=y + (i + 0.7) * heightconst,address=hex(line.address)[:-1])
+ output += ' <text x="{x}" y="{y}">\n'.format(x=x, y=y + (i + 1) * heightconst)
+ for i, line in enumerate(block.lines):
+ output += ' <tspan id="instr-{address}" x="{x}" y="{y}">'.format(x=x, y=y + (i + 0.7) * heightconst, address=hex(line.address)[:-1])
hover = instruction_data_flow(function, line.address)
output += '<title>{hover}</title>'.format(hover=hover)
for token in line.tokens:
# TODO: add hover for hex, function, and reg tokens
- output+='<tspan class="{tokentype}">{text}</tspan>'.format(text=escape(token.text),tokentype=token.type)
+ output += '<tspan class="{tokentype}">{text}</tspan>'.format(text=escape(token.text), tokentype=token.type.name)
output += '</tspan>\n'
output += ' </text>\n'
output += ' </g>\n'
- #Edges are rendered in a seperate chunk so they have priority over the
- #basic blocks or else they'd render below them
+ # Edges are rendered in a seperate chunk so they have priority over the
+ # basic blocks or else they'd render below them
for edge in block.outgoing_edges:
points = ""
- for x,y in edge.points:
- points += str(x*widthconst)+","+str(y*heightconst) + " "
- edges += ' <polyline class="edge {type}" points="{points}" marker-end="url(#arrow-{type})"/>\n'.format(type=edge.type,points=points)
+ for x, y in edge.points:
+ points += str(x * widthconst) + "," + str(y * heightconst) + " "
+ edges += ' <polyline class="edge {type}" points="{points}" marker-end="url(#arrow-{type})"/>\n'.format(type=edge.type.name, points=points)
output += ' ' + edges + '\n'
output += ' </g>\n'
output += '</svg></html>'
diff --git a/python/examples/instruction_iterator.py b/python/examples/instruction_iterator.py
index 43bc000e..6c9d9653 100644
--- a/python/examples/instruction_iterator.py
+++ b/python/examples/instruction_iterator.py
@@ -1,19 +1,34 @@
#!/usr/bin/env python
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
import sys
-try:
- import binaryninja
-except ImportError:
- sys.path.append("/Applications/Binary Ninja.app/Contents/Resources/python/")
- import binaryninja
-import time
+import binaryninja
+
if sys.platform.lower().startswith("linux"):
- bintype="ELF"
+ bintype = "ELF"
elif sys.platform.lower() == "darwin":
- bintype="Mach-O"
+ bintype = "Mach-O"
else:
- raise Exception, "%s is not supported on this plugin" % sys.platform
+ raise Exception("%s is not supported on this plugin" % sys.platform)
if len(sys.argv) > 1:
target = sys.argv[1]
diff --git a/python/examples/jump_table.py b/python/examples/jump_table.py
index 39fed1a5..23531de0 100644
--- a/python/examples/jump_table.py
+++ b/python/examples/jump_table.py
@@ -1,8 +1,29 @@
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
# This plugin will attempt to resolve simple jump tables (an array of code pointers) and add the destinations
# as indirect branch targets so that the flow graph reflects the jump table's control flow.
-from binaryninja import *
+import binaryninja
import struct
+
def find_jump_table(bv, addr):
for block in bv.get_basic_blocks_at(addr):
func = block.function
@@ -28,7 +49,7 @@ def find_jump_table(bv, addr):
# Collect the branch targets for any tables referenced by the clicked instruction
branches = []
for token in tokens:
- if token.type == "PossibleAddressToken": # Table addresses will be a "possible address" token
+ if token.type == core.BNInstructionTextTokenType.PossibleAddressToken: # Table addresses will be a "possible address" token
tbl = token.value
print "Found possible table at 0x%x" % tbl
i = 0
@@ -60,4 +81,4 @@ def find_jump_table(bv, addr):
# Create a plugin command so that the user can right click on an instruction referencing a jump table and
# invoke the command
-PluginCommand.register_for_address("Process jump table", "Look for jump table destinations", find_jump_table)
+binaryninja.PluginCommand.register_for_address("Process jump table", "Look for jump table destinations", find_jump_table)
diff --git a/python/examples/nds.py b/python/examples/nds.py
index 5300018c..302bbc0d 100644
--- a/python/examples/nds.py
+++ b/python/examples/nds.py
@@ -1,3 +1,23 @@
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
from binaryninja import *
import struct
import traceback
@@ -42,7 +62,7 @@ class DSView(BinaryView):
self.arm9_load_addr = struct.unpack("<L", self.hdr[0x28:0x2C])[0]
self.arm9_size = struct.unpack("<L", self.hdr[0x2C:0x30])[0]
self.add_auto_segment(self.arm9_load_addr, self.arm9_size, self.arm9_offset, self.arm9_size,
- SegmentReadable | SegmentExecutable)
+ core.BNSegmentFlag.SegmentReadable | core.BNSegmentFlag.SegmentExecutable)
self.add_entry_point(Architecture['armv7'].standalone_platform, self.arm_entry_addr)
return True
except:
@@ -57,7 +77,7 @@ class DSView(BinaryView):
self.arm7_load_addr = struct.unpack("<L", self.hdr[0x38:0x3C])[0]
self.arm7_size = struct.unpack("<L", self.hdr[0x3C:0x40])[0]
self.add_auto_segment(self.arm7_load_addr, self.arm7_size, self.arm7_offset, self.arm7_size,
- SegmentReadable | SegmentExecutable)
+ core.BNSegmentFlag.SegmentReadable | core.BNSegmentFlag.SegmentExecutable)
self.add_entry_point(Architecture['armv7'].standalone_platform, self.arm_entry_addr)
return True
except:
diff --git a/python/examples/nes.py b/python/examples/nes.py
index 23f5f3d8..6a05539c 100644
--- a/python/examples/nes.py
+++ b/python/examples/nes.py
@@ -18,11 +18,14 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
-from binaryninja import *
import struct
import traceback
import os
+
+from binaryninja import *
+
+
InstructionNames = [
"brk", "ora", None, None, None, "ora", "asl", None, # 0x00
"php", "ora", "asl@", None, None, "ora", "asl", None, # 0x08
@@ -142,44 +145,45 @@ OperandLengths = [
OperandTokens = [
lambda value: [], # NONE
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value)], # ABS
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value)], # ABS_DEST
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "x")], # ABS_X
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "x")], # ABS_X_DEST
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "y")], # ABS_Y
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "y")], # ABS_Y_DEST
- lambda value: [InstructionTextToken(RegisterToken, "a")], # ACCUM
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value)], # ADDR
- lambda value: [InstructionTextToken(TextToken, "#"), InstructionTextToken(IntegerToken, "$%.2x" % value, value)], # IMMED
- lambda value: [InstructionTextToken(TextToken, "["), InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value),
- InstructionTextToken(TextToken, "]")], # IND
- lambda value: [InstructionTextToken(TextToken, "["), InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "x"),
- InstructionTextToken(TextToken, "]")], # IND_X
- lambda value: [InstructionTextToken(TextToken, "["), InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "x"),
- InstructionTextToken(TextToken, "]")], # IND_X_DEST
- lambda value: [InstructionTextToken(TextToken, "["), InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value),
- InstructionTextToken(TextToken, "], "), InstructionTextToken(RegisterToken, "y")], # IND_Y
- lambda value: [InstructionTextToken(TextToken, "["), InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value),
- InstructionTextToken(TextToken, "], "), InstructionTextToken(RegisterToken, "y")], # IND_Y_DEST
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.4x" % value, value)], # REL
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value)], # ZERO
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value)], # ZERO_DEST
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "x")], # ZERO_X
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "x")], # ZERO_X_DEST
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "y")], # ZERO_Y
- lambda value: [InstructionTextToken(PossibleAddressToken, "$%.2x" % value, value),
- InstructionTextToken(TextToken, ", "), InstructionTextToken(RegisterToken, "y")] # ZERO_Y_DEST
+ lambda value: [InstructionTextToken(core.core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value)], # ABS
+ lambda value: [InstructionTextToken(core.core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value)], # ABS_DEST
+ lambda value: [InstructionTextToken(core.core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value),
+ InstructionTextToken(core.core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.core.BNInstructionTextTokenType.RegisterToken, "x")], # ABS_X
+ lambda value: [InstructionTextToken(core.core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value),
+ InstructionTextToken(core.core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.core.BNInstructionTextTokenType.RegisterToken, "x")], # ABS_X_DEST
+ lambda value: [InstructionTextToken(core.core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value),
+ InstructionTextToken(core.core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.core.BNInstructionTextTokenType.RegisterToken, "y")], # ABS_Y
+ lambda value: [InstructionTextToken(core.core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "y")], # ABS_Y_DEST
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "a")], # ACCUM
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value)], # ADDR
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "#"), InstructionTextToken(core.BNInstructionTextTokenType.IntegerToken, "$%.2x" % value, value)], # IMMED
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "["), InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "]")], # IND
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "["), InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "x"),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "]")], # IND_X
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "["), InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "x"),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "]")], # IND_X_DEST
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "["), InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "], "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "y")], # IND_Y
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "["), InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "], "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "y")], # IND_Y_DEST
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.4x" % value, value)], # REL
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value)], # ZERO
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value)], # ZERO_DEST
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "x")], # ZERO_X
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "x")], # ZERO_X_DEST
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "y")], # ZERO_Y
+ lambda value: [InstructionTextToken(core.BNInstructionTextTokenType.PossibleAddressToken, "$%.2x" % value, value),
+ InstructionTextToken(core.BNInstructionTextTokenType.TextToken, ", "), InstructionTextToken(core.BNInstructionTextTokenType.RegisterToken, "y")] # ZERO_Y_DEST
]
+
def indirect_load(il, value):
if (value & 0xff) == 0xff:
lo_addr = il.const(2, value)
@@ -189,8 +193,9 @@ def indirect_load(il, value):
return il.or_expr(2, lo, hi)
return il.load(2, il.const(2, value))
+
def load_zero_page_16(il, value):
- if il[value].operation == "LLIL_CONST":
+ if il[value].operation == core.BNLowLevelILOperation.LLIL_CONST:
if il[value].value == 0xff:
lo = il.zero_extend(2, il.load(1, il.const(2, 0xff)))
hi = il.shift_left(2, il.zero_extend(2, il.load(1, il.const(2, 0)), il.const(2, 8)))
@@ -229,9 +234,10 @@ OperandIL = [
lambda il, value: il.zero_extend(2, il.add(1, il.const(1, value), il.reg(1, "y"))) # ZERO_Y_DEST
]
+
def cond_branch(il, cond, dest):
t = None
- if il[dest].operation == LLIL_CONST:
+ if il[dest].operation == core.BNLowLevelILOperation.LLIL_CONST:
t = il.get_label_for_address(Architecture['6502'], il[dest].value)
if t is None:
t = LowLevelILLabel()
@@ -246,9 +252,10 @@ def cond_branch(il, cond, dest):
il.mark_label(f)
return None
+
def jump(il, dest):
label = None
- if il[dest].operation == LLIL_CONST:
+ if il[dest].operation == core.BNLowLevelILOperation.LLIL_CONST:
label = il.get_label_for_address(Architecture['6502'], il[dest].value)
if label is None:
il.append(il.jump(dest))
@@ -256,6 +263,7 @@ def jump(il, dest):
il.append(il.goto(label))
return None
+
def get_p_value(il):
c = il.flag_bit(1, "c", 0)
z = il.flag_bit(1, "z", 1)
@@ -267,6 +275,7 @@ def get_p_value(il):
return il.or_expr(1, il.or_expr(1, il.or_expr(1, il.or_expr(1, il.or_expr(1,
il.or_expr(1, c, z), i), d), b), v), s)
+
def set_p_value(il, value):
il.append(il.set_reg(1, LLIL_TEMP(0), value))
il.append(il.set_flag("c", il.test_bit(1, il.reg(1, LLIL_TEMP(0)), il.const(1, 0x01))))
@@ -278,6 +287,7 @@ def set_p_value(il, value):
il.append(il.set_flag("s", il.test_bit(1, il.reg(1, LLIL_TEMP(0)), il.const(1, 0x80))))
return None
+
def rti(il):
set_p_value(il, il.pop(1))
return il.ret(il.pop(2))
@@ -287,13 +297,13 @@ InstructionIL = {
"asl": lambda il, operand: il.store(1, operand, il.shift_left(1, il.load(1, operand), il.const(1, 1), flags = "czs")),
"asl@": lambda il, operand: il.set_reg(1, "a", il.shift_left(1, operand, il.const(1, 1), flags = "czs")),
"and": lambda il, operand: il.set_reg(1, "a", il.and_expr(1, il.reg(1, "a"), operand, flags = "zs")),
- "bcc": lambda il, operand: cond_branch(il, il.flag_condition(LLFC_UGE), operand),
- "bcs": lambda il, operand: cond_branch(il, il.flag_condition(LLFC_ULT), operand),
- "beq": lambda il, operand: cond_branch(il, il.flag_condition(LLFC_E), operand),
+ "bcc": lambda il, operand: cond_branch(il, il.flag_condition(core.BNLowLevelILFlagCondition.LLFC_UGE), operand),
+ "bcs": lambda il, operand: cond_branch(il, il.flag_condition(core.BNLowLevelILFlagCondition.LLFC_ULT), operand),
+ "beq": lambda il, operand: cond_branch(il, il.flag_condition(core.BNLowLevelILFlagCondition.LLFC_E), operand),
"bit": lambda il, operand: il.and_expr(1, il.reg(1, "a"), operand, flags = "czs"),
- "bmi": lambda il, operand: cond_branch(il, il.flag_condition(LLFC_NEG), operand),
- "bne": lambda il, operand: cond_branch(il, il.flag_condition(LLFC_NE), operand),
- "bpl": lambda il, operand: cond_branch(il, il.flag_condition(LLFC_POS), operand),
+ "bmi": lambda il, operand: cond_branch(il, il.flag_condition(core.BNLowLevelILFlagCondition.LLFC_NEG), operand),
+ "bne": lambda il, operand: cond_branch(il, il.flag_condition(core.BNLowLevelILFlagCondition.LLFC_NE), operand),
+ "bpl": lambda il, operand: cond_branch(il, il.flag_condition(core.BNLowLevelILFlagCondition.LLFC_POS), operand),
"brk": lambda il, operand: il.system_call(),
"bvc": lambda il, operand: cond_branch(il, il.not_expr(0, il.flag("v")), operand),
"bvs": lambda il, operand: cond_branch(il, il.flag("v"), operand),
@@ -345,6 +355,7 @@ InstructionIL = {
"tya": lambda il, operand: il.set_reg(1, "a", il.reg(1, "y"), flags = "zs")
}
+
class M6502(Architecture):
name = "6502"
address_size = 2
@@ -360,18 +371,18 @@ class M6502(Architecture):
flags = ["c", "z", "i", "d", "b", "v", "s"]
flag_write_types = ["*", "czs", "zvs", "zs"]
flag_roles = {
- "c": SpecialFlagRole, # Not a normal carry flag, subtract result is inverted
- "z": ZeroFlagRole,
- "v": OverflowFlagRole,
- "s": NegativeSignFlagRole
+ "c": core.BNFlagRole.SpecialFlagRole, # Not a normal carry flag, subtract result is inverted
+ "z": core.BNFlagRole.ZeroFlagRole,
+ "v": core.BNFlagRole.OverflowFlagRole,
+ "s": core.BNFlagRole.NegativeSignFlagRole
}
flags_required_for_flag_condition = {
- LLFC_UGE: ["c"],
- LLFC_ULT: ["c"],
- LLFC_E: ["z"],
- LLFC_NE: ["z"],
- LLFC_NEG: ["s"],
- LLFC_POS: ["s"]
+ core.BNLowLevelILFlagCondition.LLFC_UGE: ["c"],
+ core.BNLowLevelILFlagCondition.LLFC_ULT: ["c"],
+ core.BNLowLevelILFlagCondition.LLFC_E: ["z"],
+ core.BNLowLevelILFlagCondition.LLFC_NE: ["z"],
+ core.BNLowLevelILFlagCondition.LLFC_NEG: ["s"],
+ core.BNLowLevelILFlagCondition.LLFC_POS: ["s"]
}
flags_written_by_flag_write_type = {
"*": ["c", "z", "v", "s"],
@@ -413,17 +424,17 @@ class M6502(Architecture):
result.length = length
if instr == "jmp":
if operand == ADDR:
- result.add_branch(UnconditionalBranch, struct.unpack("<H", data[1:3])[0])
+ result.add_branch(core.BNBranchType.UnconditionalBranch, struct.unpack("<H", data[1:3])[0])
else:
- result.add_branch(UnresolvedBranch)
+ result.add_branch(core.BNBranchType.UnresolvedBranch)
elif instr == "jsr":
- result.add_branch(CallDestination, struct.unpack("<H", data[1:3])[0])
+ result.add_branch(core.BNBranchType.CallDestination, struct.unpack("<H", data[1:3])[0])
elif instr in ["rti", "rts"]:
- result.add_branch(FunctionReturn)
+ result.add_branch(core.BNBranchType.FunctionReturn)
if instr in ["bcc", "bcs", "beq", "bmi", "bne", "bpl", "bvc", "bvs"]:
dest = (addr + 2 + struct.unpack("b", data[1])[0]) & 0xffff
- result.add_branch(TrueBranch, dest)
- result.add_branch(FalseBranch, addr + 2)
+ result.add_branch(core.BNBranchType.TrueBranch, dest)
+ result.add_branch(core.BNBranchType.FalseBranch, addr + 2)
return result
def perform_get_instruction_text(self, data, addr):
@@ -432,7 +443,7 @@ class M6502(Architecture):
return None
tokens = []
- tokens.append(InstructionTextToken(TextToken, "%-7s " % instr.replace("@", "")))
+ tokens.append(InstructionTextToken(core.BNInstructionTextTokenType.TextToken, "%-7s " % instr.replace("@", "")))
tokens += OperandTokens[operand](value)
return tokens, length
@@ -488,6 +499,7 @@ class M6502(Architecture):
return None
return "\xa9" + chr(value & 0xff) + "\xea"
+
class NESView(BinaryView):
name = "NES"
long_name = "NES ROM"
@@ -521,55 +533,55 @@ class NESView(BinaryView):
self.rom_length = self.rom_banks * 0x4000
# Add mapping for RAM and hardware registers, not backed by file contents
- self.add_auto_segment(0, 0x8000, 0, 0, SegmentReadable | SegmentWritable | SegmentExecutable)
+ self.add_auto_segment(0, 0x8000, 0, 0, core.BNSegmentFlag.SegmentReadable | core.BNSegmentFlag.SegmentWritable | core.BNSegmentFlag.SegmentExecutable)
# Add ROM mappings
self.add_auto_segment(0x8000, 0x4000, self.rom_offset + (self.__class__.bank * 0x4000), 0x4000,
- SegmentReadable | SegmentExecutable)
+ core.BNSegmentFlag.SegmentReadable | core.BNSegmentFlag.SegmentExecutable)
self.add_auto_segment(0xc000, 0x4000, self.rom_offset + self.rom_length - 0x4000, 0x4000,
- SegmentReadable | SegmentExecutable)
+ core.BNSegmentFlag.SegmentReadable | core.BNSegmentFlag.SegmentExecutable)
nmi = struct.unpack("<H", self.read(0xfffa, 2))[0]
start = struct.unpack("<H", self.read(0xfffc, 2))[0]
irq = struct.unpack("<H", self.read(0xfffe, 2))[0]
- self.define_auto_symbol(Symbol(FunctionSymbol, nmi, "_nmi"))
- self.define_auto_symbol(Symbol(FunctionSymbol, start, "_start"))
- self.define_auto_symbol(Symbol(FunctionSymbol, irq, "_irq"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.FunctionSymbol, nmi, "_nmi"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.FunctionSymbol, start, "_start"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.FunctionSymbol, irq, "_irq"))
self.add_function(Architecture['6502'].standalone_platform, nmi)
self.add_function(Architecture['6502'].standalone_platform, irq)
self.add_entry_point(Architecture['6502'].standalone_platform, start)
# Hardware registers
- self.define_auto_symbol(Symbol(DataSymbol, 0x2000, "PPUCTRL"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x2001, "PPUMASK"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x2002, "PPUSTATUS"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x2003, "OAMADDR"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x2004, "OAMDATA"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x2005, "PPUSCROLL"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x2006, "PPUADDR"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x2007, "PPUDATA"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4000, "SQ1_VOL"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4001, "SQ1_SWEEP"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4002, "SQ1_LO"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4003, "SQ1_HI"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4004, "SQ2_VOL"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4005, "SQ2_SWEEP"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4006, "SQ2_LO"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4007, "SQ2_HI"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4008, "TRI_LINEAR"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x400a, "TRI_LO"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x400b, "TRI_HI"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x400c, "NOISE_VOL"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x400e, "NOISE_LO"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x400f, "NOISE_HI"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4010, "DMC_FREQ"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4011, "DMC_RAW"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4012, "DMC_START"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4013, "DMC_LEN"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4014, "OAMDMA"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4015, "SND_CHN"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4016, "JOY1"))
- self.define_auto_symbol(Symbol(DataSymbol, 0x4017, "JOY2"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x2000, "PPUCTRL"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x2001, "PPUMASK"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x2002, "PPUSTATUS"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x2003, "OAMADDR"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x2004, "OAMDATA"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x2005, "PPUSCROLL"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x2006, "PPUADDR"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x2007, "PPUDATA"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4000, "SQ1_VOL"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4001, "SQ1_SWEEP"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4002, "SQ1_LO"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4003, "SQ1_HI"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4004, "SQ2_VOL"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4005, "SQ2_SWEEP"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4006, "SQ2_LO"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4007, "SQ2_HI"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4008, "TRI_LINEAR"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x400a, "TRI_LO"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x400b, "TRI_HI"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x400c, "NOISE_VOL"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x400e, "NOISE_LO"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x400f, "NOISE_HI"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4010, "DMC_FREQ"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4011, "DMC_RAW"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4012, "DMC_START"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4013, "DMC_LEN"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4014, "OAMDMA"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4015, "SND_CHN"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4016, "JOY1"))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.DataSymbol, 0x4017, "JOY2"))
sym_files = [self.file.filename + ".%x.nl" % self.__class__.bank,
self.file.filename + ".ram.nl",
@@ -584,7 +596,7 @@ class NESView(BinaryView):
break
addr = int(sym[0][1:], 16)
name = sym[1]
- self.define_auto_symbol(Symbol(FunctionSymbol, addr, name))
+ self.define_auto_symbol(Symbol(core.BNSymbolType.FunctionSymbol, addr, name))
if addr >= 0x8000:
self.add_function(Architecture['6502'].standalone_platform, addr)
diff --git a/python/examples/print_syscalls.py b/python/examples/print_syscalls.py
index 7e93356c..c3b47a8d 100644
--- a/python/examples/print_syscalls.py
+++ b/python/examples/print_syscalls.py
@@ -1,8 +1,28 @@
#!/usr/bin/env python
-"""
- Thanks to @theqlabs from arm.ninja for the nice writeup and idea for this plugin:
- http://arm.ninja/2016/03/08/intro-to-binary-ninja-api/
-"""
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+
+# Thanks to @theqlabs from arm.ninja for the nice writeup and idea for this plugin:
+# http://arm.ninja/2016/03/08/intro-to-binary-ninja-api/
+
import sys
from itertools import chain
@@ -21,7 +41,7 @@ def print_syscalls(bv):
for func in bv.functions:
syscalls = (il for il in chain.from_iterable(func.low_level_il)
- if il.operation == core.LLIL_SYSCALL)
+ if il.operation == core.BNLowLevelILOperation.LLIL_SYSCALL)
for il in syscalls:
value = func.get_reg_value_at(bv.arch, il.address, register).value
print("System call address: {:#x} - {:d}".format(il.address, value))
@@ -35,7 +55,7 @@ def main():
target = sys.argv[1]
bv = BinaryView.open(target)
- view_type = next(bvt for bvt in bv.available_view_types if bvt.name != 'Raw')
+ view_type = next(bvt for bvt in bv.available_view_types if bvt.name != 'Raw')
if not view_type:
print('Error: Unable to get any other view type besides Raw')
return -1
diff --git a/python/examples/version_switcher.py b/python/examples/version_switcher.py
index 6199c578..e8f8814d 100644
--- a/python/examples/version_switcher.py
+++ b/python/examples/version_switcher.py
@@ -1,4 +1,24 @@
#!/usr/bin/env python
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
import sys
import binaryninja
import datetime