fix 32-bit crc32c binaries segfaulting, fix smoldd's --hash16 handling

This commit is contained in:
PoroCYon 2020-08-24 20:15:51 +02:00
parent 14bc2a53c3
commit 00b07fe5fc
2 changed files with 14 additions and 3 deletions

View File

@ -107,7 +107,7 @@ _smol_start:
; source in eax, result in eax ; source in eax, result in eax
%ifdef USE_CRC32C_HASH %ifdef USE_CRC32C_HASH
xor ecx, ecx xor eax, eax
%else %else
%ifndef USE_HASH16 %ifndef USE_HASH16
push ebx push ebx
@ -125,6 +125,7 @@ _smol_start:
lodsb lodsb
or al, al or al, al
xchg eax, ecx xchg eax, ecx
;jcxz .breakhash
jz short .breakhash jz short .breakhash
%ifdef USE_CRC32C_HASH %ifdef USE_CRC32C_HASH
@ -144,8 +145,10 @@ _smol_start:
jmp short .nexthashiter jmp short .nexthashiter
.breakhash: .breakhash:
%ifndef USE_CRC32C_HASH
%ifndef USE_HASH16 %ifndef USE_HASH16
pop ebx pop ebx
%endif
%endif %endif
pop ecx pop ecx
;%ifndef USE_HASH16 ;%ifndef USE_HASH16

View File

@ -114,18 +114,26 @@ def get_hashtbl(elf, blob, args):
tbl = [] tbl = []
while True: while True:
hashsz = 2 if elf.is32bit and args.hash16 else 4
#eprintf("sym from 0x%08x" % htoff) #eprintf("sym from 0x%08x" % htoff)
if len(blob)-htoff < 4: #eprintf("sym end at 0x%08x, blob end at 0x%08x" % (htoff+hashsz, len(blob)))
if htoff+hashsz > len(blob):
#eprintf("htoff = 0x%08x, len=%08x" % (htoff, len(blob))) #eprintf("htoff = 0x%08x, len=%08x" % (htoff, len(blob)))
if len(blob) <= htoff and len(tbl) > 0: if len(blob) <= htoff and len(tbl) > 0:
break break
#if elf.is32bit: #if elf.is32bit:
if struct.unpack('<B', blob[htoff:htoff+1])[0] == 0: if struct.unpack('<B', blob[htoff:htoff+1])[0] == 0:
break break
else:
assert False, "AAAAA rest is %s" % repr(blob[htoff:])
#else: #else:
# if struct.unpack('<H', blob[htoff:htoff+2])[0] == 0: # if struct.unpack('<H', blob[htoff:htoff+2])[0] == 0:
# break # break
val = struct.unpack('<I', blob[htoff:htoff+4])[0] # else:
# assert False, "AAAAA rest is %s" % repr(blob[htoff:])
val = struct.unpack(('<I' if hashsz == 4 else '<H'),
blob[htoff:htoff+hashsz])[0]
if (val & 0xFFFF) == 0: break if (val & 0xFFFF) == 0: break
tbl.append(val) tbl.append(val)
#eprintf("sym %08x" % val) #eprintf("sym %08x" % val)