Calling function pointers without definitions
I've had this huge bug on me for the longest time in C++/C in that you cannot call abstract function pointers without defining the arguments like so:
Now you should know that good practice is expecting your arguments to always be 4 bytes, since standard x86 architecture pushes 4 bytes at a time on to the stack. The return value should always be 4 bytes too since it is passed in a register that can only hold up to 4 bytes; So why can't C call a function without needing to define all the arguments? We know every argument is going to be 4 bytes!
Well we're going to break this good practice of 4 byte arguments so we can call abstract function pointers without needing to make a definition.
I thought about it: You can pass entire structures on the stack in C!
Entire arrays cannot be passed on the stack (they are converted to a 4 byte pointer), but we can pass structs
You don't need pos, but I use it when the user is deciding which arguments to pass without having to input the number of arguments or making a definition.
You can also replace int args[x] with char args[x*4]. I do this so I have access to each byte in the member. If you need to pass an entire integer, just cast it or use memcpy.
We can now define an abstract function type.
I think any experienced C programmer would know what to do from there.
The reason this works is because C puts the entire structure on the stack in order.
I hope this helps!
This trick goes great with my Importing library procedures without any IATs tutorial
Code:
int (*func)(int arg1,char* fedup,int keeptypingmyarguments);
Well we're going to break this good practice of 4 byte arguments so we can call abstract function pointers without needing to make a definition.
I thought about it: You can pass entire structures on the stack in C!
Entire arrays cannot be passed on the stack (they are converted to a 4 byte pointer), but we can pass structs
Code:
struct Passer {
int args[13]; //52 bytes of argument stack space
int pos; //Stack position (0 is 1st arg, 1 is 2nd arg, etc.) *Can be a char to save space
};
You can also replace int args[x] with char args[x*4]. I do this so I have access to each byte in the member. If you need to pass an entire integer, just cast it or use memcpy.
We can now define an abstract function type.
Code:
typedef int (*FUNC)(Passer pass); FUNC func = ptr_to_func;
Code:
#include <windows.h>
struct Passer {
int args[13];
int pos;
};
typedef int (*FUNC)(Passer pass);
FUNC func;
int main() {
Passer pass;
func = (FUNC)GetProcAddress(LoadLibrary("kernel32.dll"),"Beep");
pass.args[0] = 1500;
pass.args[1] = 500;
func(pass);
Sleep(100);
func({{1500,500}}); //You don't even need to declare a Passer variable, just note the two pairs of {}s
}
I hope this helps!

This trick goes great with my Importing library procedures without any IATs tutorial

