From cfa01bd9bb99e5e7ded6db402951c081bdd21aa5 Mon Sep 17 00:00:00 2001 From: Amand Tihon Date: Mon, 3 Aug 2009 21:44:09 +0200 Subject: [PATCH] Correct stupid bug, use a simple hash function. --- Bold/linker.py | 2 +- data/bold_ibh-x86_64.asm | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) 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 -- 2.39.5