this app uses a struct like this:

typedef struct somename
{

int ( *Func1 ) ( char *szSomeString )
void ( *Func2 ) ( int someint )
} tempstruct;

Now I have a pointer to tempstruct and also a copy of it so I can do myptr->Func1 and myptr->Func2 but I want to reroute the ORIGINAL func address to the address of MY OWN function (I have injected a dll Into the process)

so when tempstruct.Func1 is called from inside the program it calls myFunc (which is int *myFunc (char *szSomeString)) and then myFunc calls the original Func1...

I can't quite get the forwarding to function, that meaning it crashes when I attempt :P
Posted on 2003-04-06 12:40:11 by SFP
Wrong programming language, from forum (moved from Main).
Posted on 2003-04-06 13:02:27 by bazik
no, I'm trying to use inline asm for the redirection, so it's not. I just wrote the C++ equivalent pseudo-code because I'm not fluent enough in asm to explain it well enough that way.
Posted on 2003-04-06 13:18:16 by SFP
Please anyone...
Posted on 2003-04-06 17:21:00 by SFP
If it is your asm thats is crashing, please post that.
Posted on 2003-04-06 22:15:32 by ThoughtCriminal
From what I see is that your struct stores 2 pointers which points to the address of 2 different functions. It makes no sense of what you are doing. Truly.



tempfunc struct
func1 dd ?
func2 dd ?
tempfunc ends

It is pointless having a pointer to the struct in that sense. Well I seemed to have noticed the word *injected*. What are you trying to do?
Posted on 2003-04-07 01:28:45 by roticv
It has been a few years since i last did C (so correct me if i am wrong), but i thought function pointers had to be typed void*, and you have an int* listed in your struct?

Anyway, you *really* need to learn pointers thoroughly before "graduating" from the C language, because they are used so extensively in asm.
Posted on 2003-04-07 05:53:08 by sluggy
Ok maybe I didn't explain it good enough....


The application has defined a struct as I showed, with different functions like I showed (the exact same format)...

Now the application does for instance: tempstruct.Func1("whatever") right, now I want to reroute the tempstruct.Func1 command to MY function.... So when the app does tempstruct.Func1("whatever") it calls MY func1, that's why I want to rewrite the calladdress of tempstruct...
Posted on 2003-04-07 07:44:03 by SFP
Now the application does for instance: tempstruct.Func1("whatever") right, now I want to reroute the tempstruct.Func1 command to MY function.... So when the app does tempstruct.Func1("whatever") it calls MY func1, that's why I want to rewrite the calladdress of tempstruct...



You want something like this:



somename blah;
...do some stuff with your struct called 'blah'........
blah.Func1 = [COLOR=red]&yourFunction[/color];
...and i can't remember how to call a function thru a pointer in C........
Posted on 2003-04-07 07:55:49 by sluggy
[size=9]#include <stdio.h>


typedef struct
{
void (*func)();
} TESTFUNC;

void print1(int);
void print2(void);
void print3(int, int);

int main(void)
{
TESTFUNC tf;

tf.func = print1;
(*tf.func)(1);

tf.func = print2;
(*tf.func)();

tf.func = print3;
(*tf.func)(1, 3);

puts("\n\nTesting ASM\n\n");

__asm
{
lea eax, print1
mov tf.func, eax

//Do Some Stuff

mov eax, tf.func
push 5
call eax
}

__asm
{
lea eax, print2
mov tf.func, eax

//Do Some Stuff

mov eax, tf.func
call eax
}

__asm
{
lea eax, print3
mov tf.func, eax

//Do Some Stuff

mov eax, tf.func
push 1500
push 12
call eax
}

return 0;
}

void print1(int n)
{
printf("I'm Function #%d\n", n);
}

void print2(void)
{
printf("I'm Function #2\n");
}

void print3(int x, int y)
{
printf("I'm Function #%d\n", x+y);
}[/size]
:grin:
Posted on 2003-04-07 14:42:16 by arkane