Jump to content
Tuts 4 You

[Help] Algo reversing and rewriting


bloodyshade

Recommended Posts

bloodyshade

Hi,

Basically, I'm having trouble while trying to rewrite this algo in python: http://codepad.org/TzClwG0f

The following is my python code so far: http://codepad.org/FoNjfrNf

The problem I'm facing right now is with the "imul edx, esi" part.

Actual output after each imul:

edx = 00440DE5; esi = 0000D1E7
edx = 153FD307; esi = 0044DBC9
edx = 21D9FD55; esi = 157B0901
edx = A060DCA8; esi = 34A2F56E
edx = 792A72E4; esi = 94C22C24
edx = 776312D0; esi = EDE861A8
edx = C9C94B03; esi = 9A8B79F1
edx = E974DC40; esi = 53423F50
edx = A48678AD; esi = BA36FD3D
edx = FE839AA6; esi = 1EB0B64B
edx = AA45EBF7; esi = E033912D
edx = 203A5ABC; esi = 4A7746AB

And this is my code's output:

edx = 0x440de5; esi = 0xd1e7
edx = 0x153fd307; esi = 0x44dbc9
edx = 0x21d9fd55; esi = 0x157b0901
edx = 0xa060dca8L; esi = 0x34a2f56e
edx = 0xc792a6084L; esi = 0x94c22bc4L
edx = 0x86775f38e0L; esi = 0xcede84df0L
edx = 0xb9cd28d8133L; esi = 0x8a9ab77b01L
edx = 0x4086abfd56e0L; esi = 0xb16483b0698L
edx = 0x76bb98fa5051L; esi = 0x4b90e3c66a21L
edx = 0xf27e11cce5ceL; esi = 0x3d2b7b3c6affL
edx = 0x94e044e005fa3L; esi = 0xcf556af0f2d1L
edx = 0xee447b810c9d8cL; esi = 0x9815124f1792fL

Any ideas on what might be happening? (my guess is that the value on edx is not exactly what it seems, but I'm really unsure)

I've read into the imul mnemonic but as you can see I probably didn't get the hang of it yet.

PS: I hope this is not against the rules as this is mostly an asm/programming problem. But in case it is, I'd be glad if an admin would please remove it or edit whatever requires so.

Thank you.

Link to comment

looks like python is handling the 'bitness' of the value.. going 64 bit when it overflows... as your first 5 steps are right, and it goes screwy after that...

Link to comment
bloodyshade

Hi guys, thanks for the replies.

I changed the code so that the operations would all be 32bits: http://codepad.org/O12asZk4

However the result is still wrong for some reason: http://codepad.org/oplsmODq

I'm really at a loss here, I have no idea what is wrong, from what I can see it should be ok now. I'm a beginner though and this is my first algo reversing, so I probably did something wrong there.

If you guys have any other ideas, please let me know :)

Thanks again.

Link to comment

Python doesn't have a fixed integer length, so you can't just change signs by switching the leftmost bit (ie. it doesnt have a leftmost bit)

You'll have to manually check (& (1<<31)) before every multiplication/division.

Also that's why your code for CDQ is probably wrong, as all numbers you're working with are positive to Python.

Link to comment
bloodyshade

Python doesn't have a fixed integer length, so you can't just change signs by switching the leftmost bit (ie. it doesnt have a leftmost bit)

You'll have to manually check (& (1<<31)) before every multiplication/division.

Also that's why your code for CDQ is probably wrong, as all numbers you're working with are positive to Python.

Hmm, I'm not sure I understand how to achieve that, but thanks for the explanation. This sure is giving me more trouble than I was expecting :)

I guess I'll just abandon the python code and write it in c++ instead, I believe I won't have that problem there.

Thank you.

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