AmyrAhmady / DeAMX

DeAMX - .amx files decompiler for SA:MP originally made by trc_ in 2008
34 stars 7 forks source link

Errors in decompiling #4

Open Chaprnks opened 5 years ago

Chaprnks commented 5 years ago

ebH6S4V

This is the only result in decompiled .pwn: l7PJg24

AmyrAhmady commented 5 years ago

@Chaprnks its probably because that compiled script is using one of anti deamx methods.

Chaprnks commented 5 years ago

Is there any way to work around or bypass these anti deamx methods? like maybe check if a chunk looks like one, then skip those lines?

AmyrAhmady commented 5 years ago

@Chaprnks sorry for late answer, I didnt get any email from github for your reply 🙏 It's not like there's an actual line in compiled scripts to skip it I've been thinking about it a week ago and I might come up with an Anti-Anti-DeAMX (weird name tho 😄 ). I'd update this if I manage to make it work.

Chaprnks commented 5 years ago

Any luck?

AmyrAhmady commented 5 years ago

@Chaprnks its kinda funny that you commented here today, and I didn't know about it. I updated deamx just now, came here to tell you and saw your comment :P well then, go ahead, try it now

Quixomatic commented 4 years ago

@AmyrAhmady getting an error thrown on this amx file.

lua53: deamx_util.lua:148: bad argument #2 to 'seek' (not an integer in proper range)
stack traceback:
        [C]: in method 'seek'
        deamx_util.lua:148: in function 'readString'
        deamx_util.lua:8: in function 'readPrefixTable'
        deamx_util.lua:43: in function 'loadAMX'
        deamx.lua:431: in main chunk
        [C]: in ?

Any thoughts on why this might happen?

AmyrAhmady commented 4 years ago

@Quixomatic can I have your amx file for debugging and testing till I find what's wrong?

Quixomatic commented 4 years ago

amx file

@AmyrAhmady , yeah, I went ahead and uploaded to google drive: battle_man.amx

Quixomatic commented 4 years ago

@AmyrAhmady any luck? I noticed the offset value being fed to the seek function seemed really high when trying to debug.

Quixomatic commented 4 years ago

@Chaprnks why did you close this issue?

Chaprnks commented 4 years ago

Sorry, did it on accident.

AmyrAhmady commented 4 years ago

Thanks for the accident actually, I totally forgot about this issue. I just downloaded that .amx file and I kept looking for the issue for the past hour, I really don't know why this happens, sounds like a really weird issue. It would be awesome if you could reproduce this bug by writing a pawn script and compile it into a .amx file, so we know what happened in the pawn side as well and look for the answer in a better way with source code in our hand

Quixomatic commented 4 years ago

I will try to recreate the scenario and provide the source code.

Jack-Rickwood commented 4 years ago

@AmyrAhmady I am also having this exact same issue. Im not sure if you knew, but battle_man.amx is actually from pokemon sword and shield, and so is the file i am trying to decompile, so i guess its an issue with all pokemon sword and shield scripts. Edit: How would i even go about reverse engineering an amx file?

Jack-Rickwood commented 4 years ago

Okay i have tried about 20 other sword and shield amx files, and all of the ones above roughly 4kb give this error, and the ones below 4kb give a different error.

Jack-Rickwood commented 4 years ago

In case its helpful, i have uploaded 678 scripts from the game here: https://drive.google.com/file/d/1EsDS6vD6sCF9dm0z_d_lZR5a8D4wZrHJ/view?usp=sharing.

AmyrAhmady commented 4 years ago

Ah.. I see now, wish you could tell me this sooner, this DeAMX aka AMX decompiler only works with compiled pawn 3.2 samp scripts (San Andreas Multiplayer) I don't think we can make it work for another game or newer pawn/AMX VM versions without changing the whole code

Jack-Rickwood commented 4 years ago

I see, fair enough. If I was interested in manually reverse engineering one of these files on my own, how hard would that be and how would I go about it? Are there any disassemblers that might work on this file? @AmyrAhmady

AmyrAhmady commented 4 years ago

The thing is, AMX changed a lot since v3.2 (obviously) so you should start reading new documentations available in pawn repository at here https://github.com/compuphase/pawn/tree/master/doc they can be useful Also you can check AMX implementation here https://github.com/compuphase/pawn/tree/master/amx which helps A LOT for reversing your compiled scripts that basically AMX bytecodes

There are a few reliable and useful sources you can check and look into doing the RE by yourself or make use of those tools https://forums.alliedmods.net/showthread.php?t=294847

I know that Lysis is open source, both old one and the new one which is written in Java you can find them here https://github.com/peace-maker/lysis-java

Jack-Rickwood commented 4 years ago

Alright, thanks a bunch!

Edit: This is very helpful in case anyone is trying to do the same as me: https://github.com/YashasSamaga/AMX-Assembly-Docs/blob/master/DOCUMENT.md

Edit 2: It looks like pokemon swsh is NOT using pawn version 4, as when I look at the commit history, the current_file_version variable was bumped from 10 to 11 in the 4.0 commit, yet the in the swsh amx file header, the file version value is '0A' (10).

AmyrAhmady commented 4 years ago

Pawn 10 doesn't even exist tho, latest is 4, pretty sure you're doing something wrong, I'll look into it too when I get home

Jack-Rickwood commented 4 years ago

@AmyrAhmady Oh no I'm completely aware of that. It's actually using pawn 3.x, but that's just represented by a 10 in the file header. When I downloaded a san andreas mp script, it had an 8 in its header, meaning it uses an earlier version of pawn 3.x.