Date: Wed, 28 Aug 2002 03:29:17 +0200 From: Pawel Jakub Dawidek <nick@garage.freebsd.pl> To: freebsd-hackers@freebsd.org Subject: Replacing kernel functions. Message-ID: <20020828012917.GH22722@garage.freebsd.pl>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hello hackers...
I've wrote two functions to replace kernel functions.
/*
* sysfun - address of kernel function
* myfun - address of our function
* buf - 5 bytes length buffer to keep old first 5 kernel function bytes
*/
static u_int
funchange(void *sysfun, void *myfun, void *buf)
{
static u_char *chgcode = "\xe9....";
u_long *addr;
/*
* Dots will be replaced by address of our function, so we go:
* jmp <myfun>
*/
if (sysfun == NULL || myfun == NULL || buf == NULL)
return (EFAULT);
/* Keep first 5 bytes of kernel function in giveen buffer */
memcpy(buf, sysfun, 5);
/* Count address for 'jmp' and put it to 'chgcode' */
addr = (u_long *)((u_char *)chgcode + 1);
*addr = (u_long)myfun - (u_long)sysfun - 10;
/* ok! let's replace it */
memcpy(sysfun, chgcode, 5);
return (0);
}
static u_int
funbackchange(void *sysfun, void *buf)
{
if (sysfun == NULL || buf == NULL)
return (EFAULT);
memcpy(sysfun, buf, 5);
return (0);
}
How to use:
int
ourfun(...)
{
[...]
}
[...]
char buf[5];
[...]
funchange(kernfun, ourfun, buf);
[...]
funbackchange(kernfun, buf);
[...]
Ok... And now what I want from You.
This works of course only on i386 arch and I need version of those functions
for the rest of archs supported by FreeBSD.
So if You know how to port them, fell free to send me Your version:)
Thanks!
--
Pawel Jakub Dawidek
UNIX Systems Administrator
http://garage.freebsd.pl
Am I Evil? Yes, I Am.
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (FreeBSD)
iQCVAwUBPWwnbT/PhmMH/Mf1AQFhLQQAiZSEchxpZIwnveOTRTSCggdA4SSqgbmw
5aupjbncIcqfqN4tgehQqggvB+dg4CpIaDYYFk9Hepe0KFHnBbKNUkxWPRiS1V6D
FflzL1ROalGh0P41wyKoY2cRH3QYiOtapoFWoghZ/lOlkjOHrzJdFJlAIO891+Sg
d8LnEWJRhqw=
=lrIl
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020828012917.GH22722>
