Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrea Gussoni
artifacts-asiaccs20
Commits
19e1aa2f
Commit
19e1aa2f
authored
Dec 09, 2020
by
Andrea Gussoni
Browse files
Add IDA scripts for normalizing the JSON
parent
0d49b587
Changes
2
Hide whitespace changes
Inline
Side-by-side
scripting/ida-extraction-scripts/normalize-all.sh
0 → 100755
View file @
19e1aa2f
#!/bin/bash
if
[
$#
-eq
0
]
;
then
echo
"No arguments supplied"
exit
1
fi
arch
=
$1
basepath
=
$(
pwd
)
workdir
=
$basepath
/workdir-
$arch
normalized_dir
=
$workdir
/ida-json-normalized
if
[
!
-d
$normalized_dir
]
;
then
mkdir
$normalized_dir
;
fi
cd
$workdir
/ida-json
for
filename
in
*
do
echo
"Normalizing input:
$filename
"
$basepath
/scripting/ida-extraction-scripts/normalize.py
$filename
$normalized_dir
/
$filename
done
;
scripting/ida-extraction-scripts/normalize.py
0 → 100755
View file @
19e1aa2f
#!/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
compute_coverage
(
new_function
)
# Append the newly created function to the output json
normalized
.
append
(
new_function
)
# Write the json on the output file
json
.
dump
(
normalized
,
output_file
,
indent
=
2
)
if
__name__
==
"__main__"
:
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment