Help me with ASM

Started by
11 comments, last by sasho648 11 years, 10 months ago
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+3A?j
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+1D?j
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.
Advertisement
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.)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


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

[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!
[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.

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.
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?

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
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.

This topic is closed to new replies.

Advertisement