• Create Account

## Help me with ASM

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

12 replies to this topic

### #1 ProDevGURU   Members

78
Like
0Likes
Like

Posted 11 June 2012 - 11:52 AM

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
mov     bl, [ebp+0]
sub     ecx, esi
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.

### #2ApochPiQ  Moderators

21386
Like
5Likes
Like

Posted 11 June 2012 - 01:19 PM

POPULAR

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

### #3frob  Moderators

41235
Like
0Likes
Like

Posted 11 June 2012 - 01:22 PM

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.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.

### #4MajinMLF  Members

129
Like
1Likes
Like

Posted 11 June 2012 - 01:51 PM

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

### #5SimonForsman  Members

7584
Like
0Likes
Like

Posted 11 June 2012 - 01:56 PM

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.

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)
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!

### #6Narf the Mouse  Members

318
Like
0Likes
Like

Posted 11 June 2012 - 08:38 PM

...If this is password cracking, I suggest banning.

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

Edited by Narf the Mouse, 11 June 2012 - 08:44 PM.

### #7Nypyren  Members

10966
Like
0Likes
Like

Posted 11 June 2012 - 08:43 PM

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.

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, 11 June 2012 - 08:44 PM.

### #8 ProDevGURU   Members

78
Like
0Likes
Like

Posted 12 June 2012 - 11:05 AM

Thanks for the posts . This by the way isn't an "

reverse engineering/cracking/keygen attempt"

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

"

repne scasb" call do?

Edited by sasho648, 12 June 2012 - 11:06 AM.

### #9nife87  Members

520
Like
1Likes
Like

Posted 12 June 2012 - 11:52 AM

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.

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

### #10 ProDevGURU   Members

78
Like
0Likes
Like

Posted 12 June 2012 - 12:03 PM

Many thanks for the info (it's shame that I thought this call is a loop ).

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

Edited by sasho648, 13 June 2012 - 07:01 AM.

### #11 ProDevGURU   Members

78
Like
0Likes
Like

Posted 13 June 2012 - 08:56 AM

### #12Olof Hedman  Members

5698
Like
0Likes
Like

Posted 13 June 2012 - 09:28 AM

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.

### #13 ProDevGURU   Members

78
Like
0Likes
Like

Posted 13 June 2012 - 10:54 AM

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


Edited by sasho648, 13 June 2012 - 12:14 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.