[MPlayer-dev-eng] silly code

Arpi arpi at thot.banki.hu
Wed Jan 2 17:28:45 CET 2002


Hi,

> > i think i need some asm for teh above, to same/restore eax?
> perhaps the attched file might be usefull 

I think it expects caller to pass parameters in stack.
My problem: I cannot modify caller(s). I cannot modify called function.
But I can (in DLL loader) lie to the caller, and give it a fake address,
instead of teh real adderss of the routine it want to call.
So, in short, I can insert a wrapper function between caller and called
func. It works fine for C functions:

int fake_func(int a,int b){
	int ret;
	printf("foobar125 called: a=%d b=%d\n",a,b);
	ret=orig_func(a,b);
	printf("foobar125 returned: %d\n",ret);
	return ret;
}

orig func is a function pointer to the real function. the caller will call
fake_func, instead of orig_func (i lie at dll loader at funcname->address
mapping). It works fine.

But there are a few function which uses registers for parameters, instead of
stack like C does.
And I need ideas how to modify above wrapper to keep the value of
registers, and pass them to the called orig function, and the same for
returned values.

I think something like this:

void fake_func(){
	asm { ... save registers to memory ... }
	printf( ... );  // from memory
	restore regs, call orig func, save regs again
	printf  retrun values
	restore regs, ret
}

problem: it seems to gcc compiles extra code to modify EBP etc before the
asm {} block begins, so it will save already modified valiables.

maybe the whole fake_fucn should be written in pure asm, and it should call
another c function for printf job?


A'rpi / Astral & ESP-team

--
mailto:arpi at thot.banki.hu
http://esp-team.scene.hu



More information about the MPlayer-dev-eng mailing list