From 8265da2ec066c726c695424a4173ddd71d00735e Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 30 Apr 2020 03:22:37 -0400 Subject: [PATCH 1/2] remove some trailing whitespace and add py3 compatibility --- __init__.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/__init__.py b/__init__.py index 88e20f6..0ed310a 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,5 @@ # 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 @@ -7,9 +7,9 @@ # 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 @@ -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" @@ -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), @@ -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) @@ -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() From aa605e11fa45bf5c94e27db4d917ced52ad75c58 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Wed, 1 Jul 2020 10:25:45 -0400 Subject: [PATCH 2/2] update plugin.json to new format for inclusion in the plugin manager --- plugin.json | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/plugin.json b/plugin.json index 48ce958..1e8ece2 100644 --- a/plugin.json +++ b/plugin.json @@ -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 }