Skip to content

Commit 82f5140

Browse files
committed
simplify code
1 parent a225ecf commit 82f5140

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

pwnlib/elf/elf.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,14 +1164,11 @@ def libc_start_main_return(self):
11641164
to list all calls inside __libc_start_main, find the call to exit
11651165
after the call to main and select the previous call.
11661166
"""
1167-
if '__libc_start_main' not in self.functions:
1167+
func = self.functions.get('__libc_start_main')
1168+
exit_addr = self.symbols.get('exit')
1169+
if not (func and exit_addr):
11681170
return 0
11691171

1170-
if 'exit' not in self.symbols:
1171-
return 0
1172-
1173-
func = self.functions['__libc_start_main']
1174-
exit_addr = self.symbols['exit']
11751172
# `__libc_start_call_main` is usually smaller than `__libc_start_main`,
11761173
# (except for powerpc which uses a bigger `generic_start_main`), so
11771174
# we might disassemble a bit too much, but it's a good dynamic estimate.
@@ -1184,9 +1181,8 @@ def libc_start_main_return(self):
11841181
call_return_offset = 1
11851182
call_instructions = set([cs.CS_GRP_CALL])
11861183
if self.arch in ['arm', 'thumb']:
1187-
if b'armhf' in self.linker:
1188-
# FIXME: I have no idea why setting self.arch = 'armhf' does not work
1189-
eabi = 'hf'
1184+
# FIXME: I have no idea why setting self.arch = 'armhf' does not work
1185+
if b'armhf' in self.linker: eabi = 'hf'
11901186
if exit_addr & 1: exit_addr -= 1
11911187
elif self.arch == 'aarch64':
11921188
pass
@@ -1197,9 +1193,8 @@ def libc_start_main_return(self):
11971193
pass
11981194
elif self.arch in ['ppc', 'powerpc', 'powerpc64']:
11991195
callee_size *= 2
1200-
if exit_addr & 1 == 0:
1201-
# powepc often jumps to the local entry point after TOC setup
1202-
exit_addr += 8
1196+
# powepc often jumps to the local entry point after TOC setup
1197+
if exit_addr & 1 == 0: exit_addr += 8
12031198
pass
12041199
elif self.arch in ['em_s390', 's390']:
12051200
imm_index = 1

0 commit comments

Comments
 (0)