aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2022-08-19 11:16:32 +0200
committerFlorian Weimer <fweimer@redhat.com>2022-08-23 19:33:38 +0200
commitbd13cb19f5e15e9e9a92a536e755fd93a97a67f6 (patch)
treeb1ab4c7e4bc89fe2c1e894702d5b335eb622808b /scripts
parentaf6b1cce9812273c7f597be6536d28eaec6fb89b (diff)
downloadglibc-bd13cb19f5e15e9e9a92a536e755fd93a97a67f6.zip
glibc-bd13cb19f5e15e9e9a92a536e755fd93a97a67f6.tar.gz
glibc-bd13cb19f5e15e9e9a92a536e755fd93a97a67f6.tar.bz2
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>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/glibcelf.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/glibcelf.py b/scripts/glibcelf.py
index de05091..5c8f46f 100644
--- a/scripts/glibcelf.py
+++ b/scripts/glibcelf.py
@@ -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()]