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
98b229be
Commit
98b229be
authored
Dec 03, 2020
by
Andrea Gussoni
Browse files
Add IDA scripts to strip debug info
parent
797ab5c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
scripting/ida-extraction-scripts/elf-replace-dynstr.py
0 → 100755
View file @
98b229be
#!/usr/bin/env python3
import
argparse
import
sys
from
elftools.elf.elffile
import
ELFFile
from
elftools.elf.dynamic
import
DynamicSegment
def
log_error
(
msg
):
sys
.
stderr
.
write
(
"[ERROR] {}
\n
"
.
format
(
msg
))
def
log
(
msg
):
sys
.
stderr
.
write
(
msg
+
"
\n
"
)
def
unique_or_none
(
list
):
if
not
list
:
return
None
assert
len
(
list
)
==
1
return
list
[
0
]
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
"Rewrite portions of .dynstr."
)
parser
.
add_argument
(
"elf_path"
,
metavar
=
"ELF"
,
help
=
"path to the ELF file."
)
args
=
parser
.
parse_args
()
with
open
(
args
.
elf_path
,
"rb+"
)
as
elf_file
:
elf
=
ELFFile
(
elf_file
)
# Blank dynstr section
dynamic
=
unique_or_none
([
segment
for
segment
in
elf
.
iter_segments
()
if
type
(
segment
)
is
DynamicSegment
])
if
dynamic
is
None
:
log
(
"Not a dynamic executable"
)
return
0
address
=
unique_or_none
([
tag
.
entry
.
d_val
for
tag
in
dynamic
.
iter_tags
()
if
tag
.
entry
.
d_tag
==
"DT_STRTAB"
])
offset
=
None
if
address
:
offset
=
unique_or_none
(
list
(
elf
.
address_offsets
(
address
)))
size
=
unique_or_none
([
tag
.
entry
.
d_val
for
tag
in
dynamic
.
iter_tags
()
if
tag
.
entry
.
d_tag
==
"DT_STRSZ"
])
if
offset
is
None
or
size
is
None
:
log
(
"DT_STRTAB not found"
)
return
0
elf_file
.
seek
(
offset
)
original
=
elf_file
.
read
(
size
)
new
=
"
\x00
"
*
size
new
=
new
.
encode
(
"ascii"
)
elf_file
.
seek
(
offset
)
elf_file
.
write
(
new
)
log
(
"patching dynstr with zeroes"
)
# Blank strtab section
strtab
=
unique_or_none
([
section
for
section
in
elf
.
iter_sections
()
if
section
.
name
==
".strtab"
])
offset
=
strtab
.
header
[
"sh_offset"
]
size
=
strtab
.
header
[
"sh_size"
]
elf_file
.
seek
(
offset
)
original
=
elf_file
.
read
(
size
)
new
=
"
\x00
"
*
size
new
=
new
.
encode
(
"ascii"
)
elf_file
.
seek
(
offset
)
elf_file
.
write
(
new
)
log
(
"patching strtab with zeroes"
)
return
0
if
__name__
==
"__main__"
:
sys
.
exit
(
main
())
scripting/ida-extraction-scripts/strip-all.sh
0 → 100755
View file @
98b229be
#!/bin/bash
# With this step, we remove some additional debug infos from binaries, that, if
# present, some decompilers take advantage to perform optimizations orthogonal
# to our evaluation purposes.
if
[
$#
-eq
0
]
;
then
echo
"No arguments supplied"
exit
1
fi
arch
=
$1
basepath
=
$(
pwd
)
workdir
=
$basepath
/workdir-
$arch
stripped_dir
=
$workdir
/stripped
if
[
!
-d
$stripped_dir
]
;
then
mkdir
$stripped_dir
;
fi
cd
$arch
# Use the `objcopy` tool to remove the `.dynstr` section from the ELF
for
filename
in
*
do
echo
"Removing the .dynstr section from the ELF"
if
[[
"
$arch
"
==
"x86-64"
*
]]
;
then
cp
$filename
$stripped_dir
/
$filename
.stripped
$basepath
/scripting/ida-extraction-scripts/elf-replace-dynstr.py
$stripped_dir
/
$filename
.stripped
else
echo
"Unsupported architecture"
exit
1
fi
done
;
# Use the `strip` tool to remove dbg info
for
filename
in
*
do
echo
"Stripping input:
$filename
"
if
[[
"
$arch
"
==
"x86-64"
*
]]
;
then
strip
--strip-debug
$stripped_dir
/
$filename
.stripped
elif
[[
"
$arch
"
==
"arm"
*
]]
;
then
armv7a-hardfloat-linux-uclibceabi-strip
--strip-debug
$stripped_dir
/
$filename
.stripped
elif
[[
"
$arch
"
==
"mips"
*
]]
;
then
mips-unknown-linux-musl-strip
--strip-debug
$stripped_dir
/
$filename
.stripped
else
echo
"Unsupported architecture"
exit
1
fi
done
;
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