forked from P4nda0s/AndroidNativeEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,12 @@ | ||
from collections import defaultdict | ||
|
||
from elftools.elf.elffile import SymbolTableSection | ||
|
||
|
||
class Module: | ||
|
||
""" | ||
:type filename str | ||
:type base_addr int | ||
:type size int | ||
:type dynsym SymbolTableSection | ||
""" | ||
def __init__(self, filename, address, size, dynsym): | ||
def __init__(self, filename, address, size, symbols_resolved): | ||
self.filename = filename | ||
self.base_addr = address | ||
self.size = size | ||
self.symbols = ModuleSymbols(dynsym) | ||
|
||
|
||
# Thanks to | ||
# https://github.com/eliben/pyelftools/blob/82299758cc0c0ca788de094ee2d83f6f490a8ef4/elftools/elf/sections.py#L143 | ||
class ModuleSymbols: | ||
|
||
def __init__(self, dynsym): | ||
self._symbols = list(dynsym.iter_symbols()) | ||
self._symbol_name_map = None | ||
|
||
def get_symbol_by_name(self, name): | ||
if self._symbol_name_map is None: | ||
self._symbol_name_map = defaultdict(list) | ||
for i, sym in enumerate(self.iter_symbols()): | ||
self._symbol_name_map[sym.name].append(i) | ||
|
||
symnums = self._symbol_name_map.get(name) | ||
|
||
return [self.get_symbol(i) for i in symnums] if symnums else None | ||
|
||
def num_symbols(self): | ||
return len(self._symbols) | ||
|
||
def get_symbol(self, n): | ||
return self._symbols[n] | ||
|
||
def iter_symbols(self): | ||
for i in range(self.num_symbols()): | ||
yield self.get_symbol(i) | ||
self.symbols = symbols_resolved |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class SymbolResolved: | ||
|
||
def __init__(self, address, symbol): | ||
self.address = address | ||
self.symbol = symbol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters