Commit 19e1aa2f authored by Andrea Gussoni's avatar Andrea Gussoni
Browse files

Add IDA scripts for normalizing the JSON

parent 0d49b587
if [ $# -eq 0 ]; then
echo "No arguments supplied"
exit 1
if [ ! -d $normalized_dir ]; then
mkdir $normalized_dir;
cd $workdir/ida-json
for filename in *
echo "Normalizing input: $filename"
$basepath/scripting/ida-extraction-scripts/ $filename $normalized_dir/$filename
#!/usr/bin/env python3
import argparse
import json
from rangeset import RangeSet
empty = (RangeSet(0,0)).difference(RangeSet(-1,1))
def compute_coverage(function):
# Compute the coverage of the function starting from the info contained in
# the basic blocks
coverage = empty
for x in function["basic_blocks"]:
coverage = coverage | RangeSet(int(x["start"], 16), int(x["end"], 16))
# Write each interval to the coverage field
coverage_list = []
for interval in coverage:
coverage_list.append({'start': hex(interval[0]), 'end': hex(interval[1])})
function["coverage"] = coverage_list
def main():
parser = argparse.ArgumentParser(description='My nice tool.')
parser.add_argument('ida', metavar='IDAFILE', help='IDA created file')
parser.add_argument('normalized', metavar='OUTPUT', help='File in output')
args = parser.parse_args()
# Json output preparation
normalized = []
with open(args.ida, "r") as input_file, open(args.normalized, "w") as output_file:
# Load the original json
data = json.load(input_file)
# Iterate over all the functions
for function in data:
# Create the new function element with the basic infos
new_function = {'entry_point': "bb." + function['name'],
'entry_point_address': function['startAddr'],
'instruction_number' : function['instruction_number'],
'basic_blocks': []}
# Add the basic blocks
for basic_block in function['basicBlocks']:
new_function['basic_blocks'].append({'start': basic_block['startAddr'],
'end': basic_block['endAddr']})
# Calculate the coverage using the info contained in the basic
# blocks, since the end address produced by IDA does not take into
# account gaps
# Append the newly created function to the output json
# Write the json on the output file
json.dump(normalized, output_file, indent=2)
if __name__ == "__main__":
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