06.01.2010, 17:33
Also, Peter's PAWN Invoke stuff does leak lots of memory.
Originally Posted by Y_Leѕѕ
Getting the addresses is quite slow, as is figuring out the parameters as it requires looking into the EXE file and figuring out how bits work (I did used to be on the team, so do have a slight advantage in that I used to have source code access so know how certain parts are done, but they do change).
Getting the addresses of PAWN natives is easy - I've got code to do that for me. Getting the addresses you actually need is harder as the PAWN natives read in the parameters, convert them to a regular format then pass them to other functions. Also, the PAWN invoke plugin doesn't actually go through PAWN for most calls, it just needs the AMX to exist to load all the function addresses which can then be looked up dynamically. This stage can be improved somewhat to remove the AMX and speed up the lookups (either create a static list with my code or embed the code into the plugin and rebuild the list every time the server starts), which may be a compromise between the two current methods. |
static cell AMX_NATIVE_CALL Func(AMX*, cell*); int (*func)(AMX*, cell*); //Is how my wrapper stores them
Originally Posted by SMX
I've had a little look at those functions in SA-MP.
My assembly knowledge is less than basic but I could tell that what I was discussing is not possible because all stuff they do is right there in those functions, they do not just call any underlying functions, I feel a bit stupid about thinking that was possible now. So I really have no idea about how to bypass AMX when calling those natives. You say you have a way of doing it. I've had a look at some of your plugins namely YSF and that multithreaded one but I can't really figure out how you do it. I saw something about pointer to members, I can understand why as I've read SA-MP is programmed in C++ so it will most likely use classes. What I know about pointer to members is that if you want to call one you also need to provide a pointer to an instance of that object, so how do you know what classes SA-MP has and how do you get pointers to instances of them when it's running? Perhaps a little example to get me in the right direction? |
Originally Posted by SMX
I've had a little look at those functions in SA-MP.
My assembly knowledge is less than basic but I could tell that what I was discussing is not possible because all stuff they do is right there in those functions, they do not just call any underlying functions, I feel a bit stupid about thinking that was possible now. So I really have no idea about how to bypass AMX when calling those natives. You say you have a way of doing it. I've had a look at some of your plugins namely YSF and that multithreaded one but I can't really figure out how you do it. I saw something about pointer to members, I can understand why as I've read SA-MP is programmed in C++ so it will most likely use classes. What I know about pointer to members is that if you want to call one you also need to provide a pointer to an instance of that object, so how do you know what classes SA-MP has and how do you get pointers to instances of them when it's running? Perhaps a little example to get me in the right direction? |
Originally Posted by SMX
MaVe, with hook do you mean replace it's internal pointer to the function it calls at runtime so it calls your custom function instead?
If so how do you even replace that pointer? Doesn't that give trouble because you are writing memory where you're not supposed to? Forgive me but my knowledge about this kind of stuff is also really poor, love to learn about it though. |
Originally Posted by SMX
Yeah that's what I meant.
But how do you replace that address? |
int hkFunctionToHook(int arg1, int arg2)
{
logprintf("Received call to FunctionToHook! I block it, do nothing.");
return 1;
}
Call((DWORD)0x12345678, (DWORD)&hkFunctionToHook); // we redirect the function call to our function
typedef RETTYPE (*FunctionToHook_t)(int, int);
FunctionToHook_t pfnOriginalFunction = (FunctionToHook_t)0x11234567;
int hkFunctionToHook(int arg1, int arg2)
{
logprintf("Received call to FunctionToHook! I just append this log message.");
// Call the original function
return pfnOriginalFunction(arg1, arg2);
}
Originally Posted by iLinx
...
The downside of course that there will be alot of people from the forums who will be confused by the C++ code and may even just quit because of it ... |
Originally Posted by SMX
...
The AMX could then be provided as a plugin for people still using PAWN so nothing changes for them. |
Originally Posted by SMX
Then they might aswell already feel inferior as it is already possible to create gamemodes in C++, or what is your point?
|
Originally Posted by Littlejth
Quote:
|