mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-26 13:21:07 +03:00
scripts/glibcelf.py: Add hashing support
ELF and GNU hashes can now be computed using the elf_hash and gnu_hash functions. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
@ -1158,5 +1158,24 @@ class Image:
|
||||
self._stringtab[sh_link] = strtab
|
||||
return strtab
|
||||
|
||||
def elf_hash(s):
|
||||
"""Computes the ELF hash of the string."""
|
||||
acc = 0
|
||||
for ch in s:
|
||||
if type(ch) is not int:
|
||||
ch = ord(ch)
|
||||
acc = ((acc << 4) + ch) & 0xffffffff
|
||||
top = acc & 0xf0000000
|
||||
acc = (acc ^ (top >> 24)) & ~top
|
||||
return acc
|
||||
|
||||
def gnu_hash(s):
|
||||
"""Computes the GNU hash of the string."""
|
||||
h = 5381
|
||||
for ch in s:
|
||||
if type(ch) is not int:
|
||||
ch = ord(ch)
|
||||
h = (h * 33 + ch) & 0xffffffff
|
||||
return h
|
||||
|
||||
__all__ = [name for name in dir() if name[0].isupper()]
|
||||
|
Reference in New Issue
Block a user