forked from rupran/elfremove
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_tool.py
executable file
·53 lines (45 loc) · 1.91 KB
/
remove_tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3
# Copyright 2018-2029, Julian Geus <[email protected]>
# Copyright 2018-2020, Andreas Ziegler <[email protected]>
#
# This file is part of ELFRemove.
#
# ELFRemove is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ELFRemove is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ELFRemove. If not, see <https://www.gnu.org/licenses/>.
import sys
from elfremove.elfremove import ELFRemove
def proc(filename, functions):
elf_rem = ELFRemove(filename)
if elf_rem.dynsym is None:
print('dynsym table not found in File!')
sys.exit(1)
# collect the set of Symbols for given function names
elf_rem.collect_symbols_in_dynsym(names=functions)
if elf_rem.symtab is not None:
elf_rem.collect_symbols_in_symtab(names=elf_rem.get_dynsym_names())
print('Functions to remove from library dynsym:')
elf_rem.print_removed_functions()
if elf_rem.symtab is not None:
print('\nFunctions to remove from library symtab:')
elf_rem.print_removed_functions(from_symtab=True)
ans = input("Type 'yes' to delete theses functions: ")
if ans == 'yes':
elf_rem.remove_symbols_from_dynsym()
if elf_rem.symtab is not None:
# don't override functions again
elf_rem.remove_symbols_from_symtab(overwrite=False)
if __name__ == '__main__':
if len(sys.argv) < 3:
print('Usage: python3 remove_tool.py <library> <func1> ... <funcN>')
sys.exit(1)
proc(sys.argv[1], sys.argv[2:])