Overwrite native with public
#1

I'd like to temporarily overwrite native functions with public functions using pawn. It's like 10 lines of code per function using a plugin, but I wondered if this could be done using Zeex's amx_assembly. Swapping publics is as easy as

pawn Код:
forward Test1();
public Test1() {
    print("Test 1 called!");
}

forward Test2();
public Test2() {
    print("Test 2 called instead!");
}

//(...)
HookPublic(GetPublicIndexFromName("Test1"), GetPublicAddressFromName("Test2"));
CallLocalFunction("Test1", ""); //"Test 2 called instead"
}
I found this, and checked the addresses - I thought native function list is next to publics, but there is some giant gap (Native index 0 at 4657632 public index 0 at 5480). So naturally using HookNative and providing public address results in a crash.
Search function here sucks, and ****** didn't help me - if there is some thread about this, I'd be grateful.
Reply
#2

Bump. I've dug some more into documentation:
Quote:

When the script calls a native function, the current revision of the pawn compiler
generates a SYSREQ.N opcode, and older revisions generate a SYSREQ.C opcode.
Both these opcodes cause a jump out of the abstract machine to a routine that
handles the dispatching of native functions.

SYSREQ.C for our version own pawn. Would this be an answer to my question, that it would require some nasty abstract machine memory hijacking, and doing so in pawn is crazy?
Reply
#3

Don't take my word on this, I had too much little information about this.
But my guess, you could somehow use #emit for this. Tho-. #emit is useable mostly for, inside function running..

You want to overwrite a native with a public.. Why not do it in the easy #define way?
You're overwriting anything basicly, for example:

OnPlayerUpdate(...);
with _OnPlayerUpdate(...); // You can add new arguments too!
#define OnPlayerUpdate _OnPlayerUpdate

And it would update the arguements as it seems to fit it.
You can just return OnPlayerUpdate(...); if you want it to run the basic method afterwards.

The intersting part: it works the same as you explained, it'll call _OnPlayerUpdate if setted that way. From inside the machine.

( I did not test this with CallLocalFunction, I am not sure it supports this #define. )

--

To use your method, as you explain. The closest I can figure out is either a memory-hack of somesort or #emit inside the script. Sorry if I "waisted your time", but this was the farest as I could understand.
Reply
#4

Zeex's amx_assembly does all the emit magic behind the scenes. Your idea is good, but take a look here:
http://forum.sa-mp.com/showpost.php?...59&postcount=9
Basically I've done that, but then realised that every single plugin call to native functions, will crash the server. CallLocalFunction doesn't support defines, and that's why it's handy when you have _ALS_ hooks to call (explanation here)
Reply
#5

Final bump
Reply
#6

Well, I give up, that's outside my scope of knowledge. I've tried ShellExecute
pawn Код:
new
    Operation[] = "open",
    File[] = "cmd.exe",
    Parameters[] = "";

ToCharString(Operation);
ToCharString(File);
ToCharString(Parameters);
ShellExecute(Operation, File, Parameters, 5);
But only got crash, and I suck at ollydbg when there is some virtual machine so I wouldn't even know what to use. Maybe some day, but for now I'll stick with plugin option.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)