From: Amand Tihon Date: Mon, 3 Aug 2009 19:44:09 +0000 (+0200) Subject: Correct stupid bug, use a simple hash function. X-Git-Tag: bold-0.1.0~6 X-Git-Url: https://git.alrj.org/?p=bold.git;a=commitdiff_plain;h=cfa01bd9bb99e5e7ded6db402951c081bdd21aa5 Correct stupid bug, use a simple hash function. --- diff --git a/Bold/linker.py b/Bold/linker.py index 8bc170a..8549066 100644 --- a/Bold/linker.py +++ b/Bold/linker.py @@ -26,7 +26,7 @@ def hash_name(name): """Caculate the hash of the function name.""" h = 0 for c in name: - h = (ord(c) - h + (h << 6) + (h << 16) & 0xffffffff) + h = ((h * 0x21) ^ ord(c)) & 0xffffffff return h class BoldLinker(object): diff --git a/data/bold_ibh-x86_64.asm b/data/bold_ibh-x86_64.asm index 5555551..42a25b4 100644 --- a/data/bold_ibh-x86_64.asm +++ b/data/bold_ibh-x86_64.asm @@ -36,8 +36,8 @@ _bold__ibh: mov rbx, [rbx + 24] ; skip the first two link_map entries mov rbx, [rbx + 24] - mov esi, [rel _bold__functions_hash] ; Implicitly zero-extended - mov edi, [rel _bold__functions_pointers] ; ditto + mov esi, _bold__functions_hash ; Implicitly zero-extended + mov edi, _bold__functions_pointers ; ditto mov ecx, _bold__functions_count ; Load all the symbols @@ -87,18 +87,13 @@ _bold__ibh: ; Compute the hash xor edx, edx + xor eax, eax .hash_loop: ; over each char - xor eax, eax + imul edx, edx, byte 0x21 + xor edx, eax lodsb test al, al - jz .hash_end - - sub eax, edx - shl edx, 6 - add eax, edx - shl edx, 10 - add edx, eax - jmp short .hash_loop + jnz short .hash_loop .hash_end: cmp edx, r15d ; Compare with stored hash