| 1 |
import idaapi |
| 2 |
if idaapi.IDA_SDK_VERSION <= 695: |
| 3 |
import idc |
| 4 |
import idaapi |
| 5 |
import binwalk |
| 6 |
if idaapi.IDA_SDK_VERSION >= 700: |
| 7 |
import ida_idc |
| 8 |
import ida_idaapi |
| 9 |
import binwalk |
| 10 |
|
| 11 |
from idaapi import * |
| 12 |
else: |
| 13 |
pass |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
try: |
| 18 |
class OpHandler(idaapi.action_handler_t): |
| 19 |
def __init__(self): |
| 20 |
idaapi.action_handler_t.__init__(self) |
| 21 |
|
| 22 |
def activate(self, ctx): |
| 23 |
arg = None |
| 24 |
a = binwalk_t() |
| 25 |
a.opcode_scan(arg) |
| 26 |
return 1 |
| 27 |
|
| 28 |
def update(self, ctx): |
| 29 |
return idaapi.AST_ENABLE_ALWAYS |
| 30 |
except AttributeError: |
| 31 |
pass |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
try: |
| 36 |
class SigHandler(idaapi.action_handler_t): |
| 37 |
def __init__(self): |
| 38 |
idaapi.action_handler_t.__init__(self) |
| 39 |
|
| 40 |
def activate(self, ctx): |
| 41 |
arg = None |
| 42 |
b = binwalk_t() |
| 43 |
b.signature_scan(arg) |
| 44 |
return 1 |
| 45 |
|
| 46 |
def update(self, ctx): |
| 47 |
return idaapi.AST_ENABLE_ALWAYS |
| 48 |
except AttributeError: |
| 49 |
pass |
| 50 |
|
| 51 |
class binwalk_t(idaapi.plugin_t): |
| 52 |
flags = 0 |
| 53 |
comment = "Scan the current IDB for file signatures" |
| 54 |
help = "" |
| 55 |
wanted_name = "Binwalk IDA Plugin" |
| 56 |
wanted_hotkey = "" |
| 57 |
|
| 58 |
def init(self): |
| 59 |
if idaapi.IDA_SDK_VERSION <= 695: |
| 60 |
self.menu_context_1 = idaapi.add_menu_item( |
| 61 |
"Search/", "binwalk opcodes", "", 0, self.opcode_scan, (None,)) |
| 62 |
self.menu_context_2 = idaapi.add_menu_item( |
| 63 |
"Search/", "binwalk signatures", "", 0, self.signature_scan, (None,)) |
| 64 |
|
| 65 |
if idaapi.IDA_SDK_VERSION >= 700: |
| 66 |
|
| 67 |
action_desc = idaapi.action_desc_t( |
| 68 |
'my:opaction', |
| 69 |
'Binwalk opcodes', |
| 70 |
OpHandler(), |
| 71 |
'', |
| 72 |
'Binwalk opcodes', |
| 73 |
) |
| 74 |
|
| 75 |
|
| 76 |
idaapi.register_action(action_desc) |
| 77 |
idaapi.attach_action_to_menu( |
| 78 |
'Search/', |
| 79 |
'my:opaction', |
| 80 |
idaapi.SETMENU_APP) |
| 81 |
|
| 82 |
|
| 83 |
action_desc = idaapi.action_desc_t( |
| 84 |
'my:sigaction', |
| 85 |
'Binwalk signatures', |
| 86 |
SigHandler(), |
| 87 |
'', |
| 88 |
'Binwalk signatures', |
| 89 |
) |
| 90 |
|
| 91 |
|
| 92 |
idaapi.register_action(action_desc) |
| 93 |
idaapi.attach_action_to_menu( |
| 94 |
'Search/', |
| 95 |
'my:sigaction', |
| 96 |
idaapi.SETMENU_APP) |
| 97 |
|
| 98 |
else: |
| 99 |
pass |
| 100 |
|
| 101 |
return idaapi.PLUGIN_KEEP |
| 102 |
|
| 103 |
def term(self): |
| 104 |
if idaapi.IDA_SDK_VERSION <= 695: |
| 105 |
idaapi.del_menu_item(self.menu_context_1) |
| 106 |
idaapi.del_menu_item(self.menu_context_2) |
| 107 |
if idaapi.IDA_SDK_VERSION >= 700: |
| 108 |
idaapi.detach_action_from_menu( |
| 109 |
'Search/', |
| 110 |
'my:opaction') |
| 111 |
idaapi.detach_action_from_menu( |
| 112 |
'Search/', |
| 113 |
'my:sigaction') |
| 114 |
else: |
| 115 |
pass |
| 116 |
|
| 117 |
return None |
| 118 |
|
| 119 |
def run(self, arg): |
| 120 |
return None |
| 121 |
|
| 122 |
def signature_scan(self, arg): |
| 123 |
binwalk.scan(idc.GetIdbPath(), signature=True) |
| 124 |
|
| 125 |
def opcode_scan(self, arg): |
| 126 |
binwalk.scan(idc.GetIdbPath(), opcode=True) |
| 127 |
|
| 128 |
|
| 129 |
def PLUGIN_ENTRY(): |
| 130 |
return binwalk_t() |