Created
May 26, 2020 21:16
-
-
Save gitlarryf/0b73a52e3b9b6d59c49922b0613985bb to your computer and use it in GitHub Desktop.
x86 Hash Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Hash(char *str) | |
{ | |
char *p = str; | |
__asm { | |
mov ecx, dword ptr [esp+4] | |
test ecx, 3 | |
je go | |
bloop: | |
mov al, byte ptr[ecx] | |
inc ecx | |
test al,al | |
je two | |
test ecx, 3 | |
jne bloop | |
add eax, 0 | |
go: | |
mov eax, dword ptr[ecx] | |
mov edx, 7EFEFEFFh | |
add edx, eax | |
xor eax,0FFFFFFFFh | |
xor eax, edx | |
add ecx, 4 | |
test eax, 81010100h | |
je go | |
mov eax, dword ptr[ecx-4] | |
test al, al | |
je three | |
test ah, ah | |
je four | |
test eax, 0FF0000h | |
je ad | |
test eax, 0FF000000h | |
je two | |
jmp go | |
two: | |
lea eax, [ecx-1] | |
mov ecx, dword ptr [p+4] | |
sub eax, ecx | |
ret | |
ad: | |
lea eax, [ecx-2] | |
mov ecx, dword ptr [p+4] | |
sub eax, ecx | |
ret | |
four: | |
lea eax, [ecx-3] | |
mov ecx, dword ptr [p+4] | |
sub eax, ecx | |
ret | |
three: | |
lea eax, [ecx-4] | |
mov ecx, dword ptr [p+4] | |
sub eax, ecx | |
ret | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment