Jump to content
Tuts 4 You

Help in Porting from ASM to Delphi


Recommended Posts

Hello, i need help in porting this code from asm to delphi ( i have tried inlining it but it does not produce the right result)

@Test_00452510: movsx eax,byte ptr [esi+$050e858] // =======> $050e858 is pointing to an address in memory
lea edx,[eax+esi+1]
imul edx,ebx
add ecx,edx
mov eax,$07ccbfadf
imul ecx
sub edx,ecx
sar edx,9
mov eax,edx
shr eax,$01f
add eax,edx
imul eax,eax,$03e7
inc esi
add ecx,eax
cmp esi,edi
jl @Test_00452510

the above code was ripped with code ripper plugin in olly.

Link to comment

Inline asm will work fine - after you fix some of your bugs. :)


1) initial EBX value is unknown;

2) initial ECX value is unknown;

3) initial ESI and EDI values are unknown;

4) and don't forget to save/restore all important registers. I prefer to wrap inline asm in pushad/popad, just to be sure.

5) result of your ripped ASM code is in ECX, Delphi by default will ignore that. Make sure you store it in some variable.


EDIT: added #5.

Edited by kao
  • Like 2
Link to comment

thanks Kao for your suggestions but I have spent the better part of today trying to fix the bug ridden asm code but no success that is why I decided to port it in Delphi. well I will keep on trying and keep you updated on my progress. thanks once again.

Link to comment

To port that code to Delphi, you still need to answer my first 3 points about initial register values. :) If you'd give me few test inputs and expected results, I could try to make the appropriate Delphi code.

  • Like 1
Link to comment

After some good night rest and a Cup of Coffee this morning, I have finally ported the code to work properly (still used inline asm).
the problem was the variable i set the result from the asm code was not set to zero on initialization so that caused it to have junk values in memory.

Thanks Kao for your help and suggestions, i really appreciate it.

Link to comment

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
  • Create New...