Commit 0be1fd16 authored by Andrea Gussoni's avatar Andrea Gussoni
Browse files

Add IDA python scripts

parent 98b229be
import idaapi
import idc
import os
import sys
import json
import jsonpickle
class Function:
def __init__(self, name, startAddr, endAddr, instruction_number):
self.name = name
self.startAddr = startAddr
self.endAddr = endAddr
self.basicBlocks = []
self.arguments = []
self.instruction_number = instruction_number
def addBB(self, BB):
self.basicBlocks.append(BB)
def addArg(self, arg):
self.arguments.append(arg)
class BasicBlock:
def __init__(self, startAddr, endAddr):
self.startAddr = startAddr
self.endAddr = endAddr
class Argument:
def __init__(self, location=None):
self.location = location
functions = []
start = SegStart(BeginEA())
for function_start in Functions(SegStart(start), SegEnd(start)):
# Count the number of instructions
instruction_counter = 0
for i in FuncItems(function_start):
instruction_counter += 1
f = idaapi.FlowChart(idaapi.get_func(function_start))
curFunc = Function(GetFunctionName(function_start), "0x%08x"%f[0].startEA, "0x%08x"%FindFuncEnd(function_start), instruction_counter)
visited = set()
visited.add(f[0].startEA)
wl = [f[0]]
while len(wl) > 0:
bb = wl.pop()
start = "0x%08x"%bb.startEA
end = "0x%08x"%bb.endEA
block = BasicBlock(start, end)
curFunc.basicBlocks.append(block)
for successor in bb.succs():
if successor.startEA not in visited:
visited.add(successor.startEA)
wl.append(successor)
functions.append(curFunc)
with open(idc.ARGV[1], "w") as output:
json.dump(json.loads(jsonpickle.encode(functions, unpicklable=False)), output, indent=4)
idc.Exit(0)
import idaapi
import idc
import os
import sys
outputfile = idc.ARGV[1]
# Load the right plugin
is_ida64 = GetIdbPath().endswith(".i64") # hackhackhack - check if we're ida64 or ida32
print(is_ida64)
if is_ida64:
idaapi.load_plugin('hexx64')
else:
idaapi.load_plugin('hexarm')
idaapi.decompile_many(outputfile, None, 0)
idc.Exit(0)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment