Sign in to follow this  
sasho648

Help me with ASM

Recommended Posts

sasho648    78
I just include some assembler code to my source - it works bur I want to translate it to c++ code. Here is the function with the ASM:


[CODE]
unsigned long _STRING_GetHashValue(char* Str) {
unsigned long Hash;
__asm {
push ebp
mov eax, Str
mov ebp, eax
push esi
push edi
mov edi, ebp
or ecx, 0FFFFFFFFh
xor eax, eax
repne scasb
not ecx
dec ecx
mov esi, ecx
mov eax, ecx
sar esi, 6
inc esi
test ecx, ecx
jle short loc_482B9D
push ebx

loc_482B80: ; CODE XREF: _STRING_GetHashValue+3Aj
mov edx, eax
mov edi, eax
shl edx, 5
sar edi, 2
xor ebx, ebx
add edx, edi
mov bl, [ebp+0]
sub ecx, esi
add edx, ebx
xor eax, edx
inc ebp
test ecx, ecx
jg short loc_482B80
pop ebx

loc_482B9D: ; CODE XREF: _STRING_GetHashValue+1Dj
pop edi
pop esi
pop ebp
mov Hash, eax
}
return Hash;
}[/CODE]

I will be very happy if you help me. I really need to translate this to c++ code and make the opposite function.

Share this post


Link to post
Share on other sites
frob    44973
[quote name='sasho648' timestamp='1339437120' post='4948227']
I really need to translate this to c++ code and make the opposite function.
[/quote]
The opposite function how?

A hash by definition is one way.

You can make hamburger out of a cow, but you can't make a cow out of hamburger.

Similarly with a hash, you can compute a hash from a message, but you can't compute the message from its hash.

Share this post


Link to post
Share on other sites
SimonForsman    7642
[quote name='frob' timestamp='1339442568' post='4948260']
[quote name='sasho648' timestamp='1339437120' post='4948227']
I really need to translate this to c++ code and make the opposite function.
[/quote]
The opposite function how?

A hash by definition is one way.

You can make hamburger out of a cow, but you can't make a cow out of hamburger.

Similarly with a hash, you can compute a hash from a message, but you can't compute the message from its hash.
[/quote]

You can make new animals though, turn those into hamburgers and see which of those hamburgers best match the original hamburger. (If the hamburger is identical to the original hamburger and the animal you made seems to be a cow then odds are fairly good that your cow is identical to the cow that made the original hamburger)

Share this post


Link to post
Share on other sites
Narf the Mouse    322
[s]...If this is password cracking, I suggest banning.[/s]

Post probably isn't necessary. Moderators can do their jobs without comments from the peanut gallery. Edited by Narf the Mouse

Share this post


Link to post
Share on other sites
Nypyren    12074
[quote name='MajinMLF' timestamp='1339444310' post='4948280']
This is a ida pro dump (CODE XREF: gives it away) - so why not use hexrays to give you pseudo c
[/quote]

IDA has a free version now, but it doesn't include the decompiler. [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]

To OP: That code is RIDICULOUSLY short and simple. Just do it by hand. It won't take any time at all. Edited by Nypyren

Share this post


Link to post
Share on other sites
sasho648    78
Thanks for the posts [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] . This by the way isn't an "[left][background=rgb(250, 251, 252)]reverse engineering/cracking/keygen attempt" [/background][/left][left][img]http://public.gamedev.net//public/style_emoticons/default/ph34r.png[/img][/left][left][background=rgb(250, 251, 252)] I just try to find the real names in a game file archive with hashes which I think is fully legally. Anyway can somebody tell me what the [/background][/left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]"[/background][/left][/size][/font][/color]repne scasb" call do? Edited by sasho648

Share this post


Link to post
Share on other sites
nife87    520
First hit on Google:
http://www.int80h.org/strlen/

[quote]
In assembly language finding the length of a C-style string is a snap. The x86 family of microprocessors come with with the scasb instruction which searches for the first occurence of a byte whose value is equal to that of the AL register. The address of the start of the string itself has to be in the EDI register. Technically, it is supposed to be in the extra segment, but we do not need to worry about that in the flat 32-bit memory mode anymore. When used along with the repne prefix, the scasb instruction goes up (or down, depending on the direction flag) the memory, looking for the match.
[/quote]

This is also good:
http://www.csc.depauw.edu/~bhoward/asmtut/asmtut7.html

Share this post


Link to post
Share on other sites
sasho648    78
Many thanks for the info (it's shame that I thought this call is a loop[img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img] ).

EDiT: AnY way I still wait if someone translate this to c. Edited by sasho648

Share this post


Link to post
Share on other sites
alh420    5995
I doubt you will find anyone to do your work for you here.

Also, it will not help you, you will not be able to extract the strings from the hashes.
unless you use it to do a brute force search as SimonForsman suggests, but thats not very practical for anything but very short strings.

Share this post


Link to post
Share on other sites
sasho648    78
Oh anyway the Ida pro do my work and i found the source. I improve it too. Here is it if somebody is curious:



[CODE]

signed int __cdecl STRING_GetHashValue(char* String)
{
signed int StrLen = strlen(String);
signed int Hash = StrLen;

for (int Indx(0); Indx<StrLen; ++Indx)
Hash ^= (Hash >> 2) + 32 * Hash + String[Indx];

return Hash;
}
[/CODE] Edited by sasho648

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this