Jump to content

  • Log In with Google      Sign In   
  • 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.

  • You cannot reply to this topic
12 replies to this topic

#1 sasho648   Members   -  Reputation: 137

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

Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 14295

Like
5Likes
Like

Posted 11 June 2012 - 01:19 PM

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

#3 frob   Moderators   -  Reputation: 18960

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 personal indie blog at bryanwagstaff.com.

#4 MajinMLF   Members   -  Reputation: 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

#5 SimonForsman   Crossbones+   -  Reputation: 5804

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!

#6 Narf the Mouse   Members   -  Reputation: 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.


#7 Nypyren   Crossbones+   -  Reputation: 3728

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

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 sasho648   Members   -  Reputation: 137

Like
0Likes
Like

Posted 12 June 2012 - 11:05 AM

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

reverse engineering/cracking/keygen attempt"

Posted Image

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.


#9 nife87   Members   -  Reputation: 516

Like
1Likes
Like

Posted 12 June 2012 - 11:52 AM

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.


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

#10 sasho648   Members   -  Reputation: 137

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 loopPosted Image ).

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

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


#11 sasho648   Members   -  Reputation: 137

Like
0Likes
Like

Posted 13 June 2012 - 08:56 AM

Can somebody translate this please??Posted Image

#12 Olof Hedman   Crossbones+   -  Reputation: 2662

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 sasho648   Members   -  Reputation: 137

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.



PARTNERS