Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright 2018 Nagravision SA
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand All @@ -26,6 +26,10 @@

import struct
import importlib
import sys

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3

class CortexView(BinaryView):
name = "CortexFirmware"
Expand Down Expand Up @@ -93,7 +97,7 @@ def init(self):

#SP_VALUE is a data pointer
self.define_auto_symbol_and_var_or_function(
Symbol(SymbolType.DataSymbol,
Symbol(SymbolType.DataSymbol,
mcu.ROM_OFF,
mcu.IRQ[0]),
Type.pointer(self.arch, Type.void(), const=True),
Expand All @@ -105,8 +109,8 @@ def init(self):
#All other vectory are function pointers
for i in range(1, len(mcu.IRQ)):
self.define_auto_symbol_and_var_or_function(
Symbol(SymbolType.DataSymbol,
mcu.ROM_OFF+(4*i),
Symbol(SymbolType.DataSymbol,
mcu.ROM_OFF+(4*i),
mcu.IRQ[i]),
Type.pointer(self.arch, Type.void(), const=True),
self.platform)
Expand All @@ -124,16 +128,24 @@ def init(self):
def is_valid_for_data(self, data):
#Read two DWORDS
ivt = data.read(0, 8)
if ord(ivt[3])>0x20:
#SP value should be in SRAM (max 0x20......)
return False
if ord(ivt[7])>0x08:
#Reset vector should be in flash (max 0x08......)
return False
if PY2:
if ord(ivt[3])>0x20:
#SP value should be in SRAM (max 0x20......)
return False
if ord(ivt[7])>0x08:
#Reset vector should be in flash (max 0x08......)
return False
else:
if ivt[3]>0x20:
#SP value should be in SRAM (max 0x20......)
return False
if ivt[7]>0x08:
#Reset vector should be in flash (max 0x08......)
return False
return True

def perform_get_entry_point(self):
return self.symbols['f_RESET_IRQ'].address


CortexView.register()
45 changes: 22 additions & 23 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
{
"plugin": {
"name": "Cortex-M firmware Plugin",
"type": ["binaryview"],
"api": "python2",
"description": "A plugin to load Cortex-based MCU firmwares.",
"longdescription": "This plugin loads MCU binary dumps and fills the interrupt vector tables to kickstart the reversing process.\n\nIt supports multiple MCUs, based on libopencm3 (https://github.com/libopencm3/libopencm3/). The *platforms/gen.sh* file is used to generate the platform files from an existing libopencm3 installation.",
"license": {
"name": "Apache 2.0",
"text": "Copyright 2018 Nagravision SA\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License."
},
"dependencies": {
"pip": [],
"apt": [],
"installers": [],
"other": []
},
"version": "1.0 alpha",
"author": "Nagravision SA",
"minimumBinaryNinjaVersion": {
"dev": "1.0.dev-576",
"release": "9999"
}
}
"pluginmetadataversion": 2,
"name": "Cortex-M firmware Plugin",
"type": ["binaryview"],
"api": ["python2", "python3"],
"description": "A plugin to load Cortex-based MCU firmwares.",
"longdescription": "This plugin loads MCU binary dumps and fills the interrupt vector tables to kickstart the reversing process.\n\nIt supports multiple MCUs, based on libopencm3 (https://github.com/libopencm3/libopencm3/). The *platforms/gen.sh* file is used to generate the platform files from an existing libopencm3 installation.",
"license": {
"name": "Apache 2.0",
"text": "Copyright 2018 Nagravision SA\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License."
},
"platforms" : ["Darwin", "Linux", "Windows"],
"installinstructions" : {
"Darwin" : "no special instructions, package manager is recommended",
"Linux" : "no special instructions, package manager is recommended",
"Windows" : "no special instructions, package manager is recommended"
},
"dependencies": {
},
"version": "1.0a",
"author": "Vector 35 Inc",
"author": "Nagravision SA",
"minimumbinaryninjaversion": 576
}