bloodyshade Posted April 29, 2011 Posted April 29, 2011 Hi,Basically, I'm having trouble while trying to rewrite this algo in python: http://codepad.org/TzClwG0fThe following is my python code so far: http://codepad.org/FoNjfrNfThe problem I'm facing right now is with the "imul edx, esi" part.Actual output after each imul:edx = 00440DE5; esi = 0000D1E7edx = 153FD307; esi = 0044DBC9edx = 21D9FD55; esi = 157B0901edx = A060DCA8; esi = 34A2F56Eedx = 792A72E4; esi = 94C22C24edx = 776312D0; esi = EDE861A8edx = C9C94B03; esi = 9A8B79F1edx = E974DC40; esi = 53423F50edx = A48678AD; esi = BA36FD3Dedx = FE839AA6; esi = 1EB0B64Bedx = AA45EBF7; esi = E033912Dedx = 203A5ABC; esi = 4A7746ABAnd this is my code's output:edx = 0x440de5; esi = 0xd1e7edx = 0x153fd307; esi = 0x44dbc9edx = 0x21d9fd55; esi = 0x157b0901edx = 0xa060dca8L; esi = 0x34a2f56eedx = 0xc792a6084L; esi = 0x94c22bc4Ledx = 0x86775f38e0L; esi = 0xcede84df0Ledx = 0xb9cd28d8133L; esi = 0x8a9ab77b01Ledx = 0x4086abfd56e0L; esi = 0xb16483b0698Ledx = 0x76bb98fa5051L; esi = 0x4b90e3c66a21Ledx = 0xf27e11cce5ceL; esi = 0x3d2b7b3c6affLedx = 0x94e044e005fa3L; esi = 0xcf556af0f2d1Ledx = 0xee447b810c9d8cL; esi = 0x9815124f1792fLAny 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.
evlncrn8 Posted April 29, 2011 Posted April 29, 2011 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...
Killboy Posted April 29, 2011 Posted April 29, 2011 Try performing modulo 2**32 after each operation (*, +, <<)
bloodyshade Posted April 29, 2011 Author Posted April 29, 2011 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.
Killboy Posted April 29, 2011 Posted April 29, 2011 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.
bloodyshade Posted April 29, 2011 Author Posted April 29, 2011 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now