Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help me with ASM

Started by sasho648 Jun 11, 2012 at 5:52 PM 11 replies 2.7k views
Original Post
sasho648
sasho648
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:



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;
}


I will be very happy if you help me. I really need to translate this to c++ code and make the opposite function.
ApochPiQ
ApochPiQ
This is an implementation of a relatively trivial hash function. It doesn't look like a particularly good one, but I doubt you can just "make the opposite function" by virtue of the nature of hashes.

Also, this smells like a reverse engineering/cracking/keygen attempt, in which case, may I say: shame upon you. (Unless I'm wrong, of course.)
frob
frob

I really need to translate this to c++ code and make the opposite function.

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.
MajinMLF
MajinMLF
This is a ida pro dump (CODE XREF: gives it away) - so why not use hexrays to give you pseudo c
SimonForsman
SimonForsman

[quote name='sasho648' timestamp='1339437120' post='4948227']
I really need to translate this to c++ code and make the opposite function.

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)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Narf the Mouse
Narf the Mouse
[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.
Nypyren
Nypyren

This is a ida pro dump (CODE XREF: gives it away) - so why not use hexrays to give you pseudo c


IDA has a free version now, but it doesn't include the decompiler. sad.png

To OP: That code is RIDICULOUSLY short and simple. Just do it by hand. It won't take any time at all.
sasho648
sasho648
Thanks for the posts smile.png . This by the way isn't an "

[background=rgb(250, 251, 252)]reverse engineering/cracking/keygen attempt" [/background]

ph34r.png

[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]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]"[/background]

[/font]repne scasb" call do?

nife87
nife87
First hit on Google:
http://www.int80h.org/strlen/


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
sasho648
sasho648
Many thanks for the info (it's shame that I thought this call is a looplaugh.png ).

EDiT: AnY way I still wait if someone translate this to c.
sasho648
sasho648
Can somebody translate this please??sad.png
alh420
alh420
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.
sasho648
sasho648
Oh anyway the Ida pro do my work and i found the source. I improve it too. Here is it if somebody is curious:





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;
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.