Skip to content

Commit

Permalink
Merge pull request #38 from jonatanSh/feature/issue_37_fix
Browse files Browse the repository at this point in the history
Feature/issue 37 fix
  • Loading branch information
jonatanSh authored Jul 30, 2023
2 parents a301490 + c6f3136 commit dc2c18d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion shelf/shelf/__version__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAJOR = 3
MINOR = 0
MINOR_MINOR = 5
MINOR_MINOR = 6
VERSION_FOR_PACK = MAJOR * 100 + MINOR * 10 + MINOR_MINOR
FULL = "{}.{}.{}".format(MAJOR, MINOR, MINOR_MINOR)
2 changes: 1 addition & 1 deletion shelf/shelf/arm/x32.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, elffile, shellcode_data, args, **kwargs):
ptr_fmt="I",
sections_to_relocate={
'.data.rel.ro': {'align_by': 'sh_addralign'},
'.got.plt': {'align_by': 'sh_entsize', 'relocate_all': True},
'.got.plt': {'align_by': 'sh_entsize'},

},
support_dynamic=True,
Expand Down
19 changes: 3 additions & 16 deletions shelf/shelf/lib/shellcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ def correct_symbols(self, shellcode_data):
for section, attributes in self.sections_to_relocate.items():
self.section_build_relocations_table(
section_name=section,
relocate_all=attributes.get("relocate_all", False),
shellcode_data=shellcode_data
)
return shellcode_data
Expand All @@ -326,9 +325,8 @@ def add_symbol_relocation_to_relocation_table(self, virtual_offset, offset, symb
self.patched_symbols_mapping[symbol_name] = [virtual_offset, offset]
self.add_to_relocation_table(virtual_offset, offset)

def section_build_relocations_table(self, section_name, relocate_all, shellcode_data):
def section_build_relocations_table(self, section_name, shellcode_data):
data_section = self.elffile.get_section_by_name(section_name)
original_symbol_addresses = self.get_original_symbols_addresses()
if data_section:
data_section_header = data_section.header
index = 0
Expand All @@ -339,9 +337,6 @@ def section_build_relocations_table(self, section_name, relocate_all, shellcode_
data_section_value = \
struct.unpack("{}{}".format(self.endian, self.ptr_fmt),
shellcode_data[data_section_start:data_section_end])[0]
if data_section_value not in original_symbol_addresses and not relocate_all:
self.logger.info("[R_SKIPPED]{}".format(hex(data_section_value)))
continue
sym_offset = data_section_value - self.loading_virtual_address
if sym_offset < 0:
continue
Expand Down Expand Up @@ -486,16 +481,6 @@ def linker_base_address(self):

return self._linker_base

def get_original_symbols_addresses(self):
symtab = self.elffile.get_section_by_name(".symtab")
addresses = []
for sym in symtab.iter_symbols():
address = sym.entry.st_value
if address >= self.loading_virtual_address:
addresses.append(address)

return addresses

@property
def symbols(self):
symtab = self.elffile.get_section_by_name(".symtab")
Expand Down Expand Up @@ -538,6 +523,8 @@ def find_symbols(self, symbol_name=None,
def get_symbol_name_from_address(self, address):

symtab = self.elffile.get_section_by_name(".symtab")
if not symtab:
return None
for sym in symtab.iter_symbols():
sym_address = sym.entry.st_value
if sym_address == address:
Expand Down
2 changes: 1 addition & 1 deletion shelf/shelf/mips/mips.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, elffile, shellcode_data, args, **kwargs):
shellcode_table_magic=ShellcodeMagics.arch32.value,
ptr_fmt="I",
sections_to_relocate={
'.got': {'align_by': 'sh_entsize', 'relocate_all': True},
'.got': {'align_by': 'sh_entsize'},
'.data.rel.ro': {'align_by': 'sh_addralign'},

},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_runner/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def forbidden_features(*maps):
'test_framework_tests': {
"test_file_fmt": "../outputs/{}_test_framework_tests.out.shellcode",
"supported_arches": all_arches,
"success": [""],
"success": ["SHELF:my_test_error_function"],
"features": [],
'check_rc': False
},
Expand Down

0 comments on commit dc2c18d

Please sign in to comment.