能力值:
( LV3,RANK:20 )
|
-
-
2 楼
另外一个例子,谢谢。
/*****************************
*ptrace testing by lasvegas
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/ptrace.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/user.h>
#include <string.h>
void getdata(pid_t child, char* const addr, unsigned long getlen, char* const rbuf);
void setdata(pid_t child, void* const addr, unsigned long setlen, char* const sbuf);
int main(int argc, char** argv)
{
unsigned long lrmt =0x31;
char rmt[] ="\xEB\x1D\x5B\x48\xC7\xC0\x01\x00\x00\x00\x48\xC7\xC7\x01\x00\x00\x00\x48\x89\xDE\x48\xC7\xC2\x0D\x00\x00\x00\x0F\x05\xEB\x13\xE8\xDE\xFF\xFF\xFF\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x21\x0A";
char back[lrmt];
pid_t child =0;
struct user_regs_struct reg;
if(argc !=2)
{
printf("Usage: %s <target executable file>\n", argv[0]);
exit(1);
}
child =fork();
if(child ==0)
{
ptrace(PTRACE_TRACEME, 0, NULL, 0);
if(execlp(argv[1], argv[1], NULL) <0)
{
printf("Damn for executable execlp(%s,...)\n", argv[1]);
exit(2);
}
}
else
{
printf("Trace on %d...\n", child);
int status;
ptrace(PTRACE_ATTACH, child, NULL, NULL);
wait(&status);
if(WIFEXITED(status))
{
exit(0);
}
ptrace(PTRACE_GETREGS, child, NULL, ®);
getdata(child, (void*)reg.rip, lrmt, back);
setdata(child, (void*)reg.rip, lrmt, rmt);
ptrace(PTRACE_SETREGS, child, NULL, ®);
ptrace(PTRACE_CONT, child, NULL, NULL);
wait(NULL);
//restore
setdata(child, (void*)reg.rip, lrmt, back);
ptrace(PTRACE_SETREGS, child, NULL, ®);
//
ptrace(PTRACE_DETACH, child, NULL, NULL);
}
return 0;
}
/*
typedef union _mem_byte
{
long inst;
char insts[sizeof(long)];
}mem_byte;
*/
void getdata(pid_t child, char* const addr, unsigned long getlen, char* const rbuf)
{
int i =0, j =0;
char *laddr =NULL;
char *lbuf =NULL;
long mb;
laddr =addr;
lbuf =rbuf;
j =getlen/sizeof(long);
for(i =0; i <j; i++)
{
memset(&mb, 0, sizeof(long));
mb =ptrace(PTRACE_PEEKDATA, child, laddr, NULL);
memcpy(lbuf, &mb, sizeof(long));
lbuf +=sizeof(long);
laddr +=sizeof(long);
}
if(getlen %sizeof(long) !=0)
{
memset(&mb, 0, sizeof(long));
mb =ptrace(PTRACE_PEEKDATA, child, laddr, NULL);
memcpy(lbuf, &mb, getlen %sizeof(long));
}
return;
}
void setdata(pid_t child, void* const addr,unsigned long setlen, char* const sbuf)
{
int i =0, j=0;
char *laddr =NULL;
char *lbuf =NULL;
long mb;
laddr =addr;
lbuf =sbuf;
j =setlen/sizeof(long);
for(i =0; i <j; i++)
{
memset(&mb, 0, sizeof(long));
memcpy(&mb, lbuf, sizeof(long));
ptrace(PTRACE_POKETEXT, child, laddr, mb);
laddr +=sizeof(long);
lbuf +=sizeof(long);
}
if(setlen %sizeof(long) !=0)
{
memset(&mb, 0, sizeof(long));
memcpy(&mb, lbuf, setlen%sizeof(long));
ptrace(PTRACE_POKETEXT, child, laddr, mb);
}
return;
}
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
linux上的。。mark
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
我这两天也在做这个小移植的工作,其实这里主要的问题就是从4B-->8B的问题,还有就是寄存器的对应关系,想知道楼主是怎么对应的?
例如:
ECX<==>RSI
EDX<==>RDX
很久以前学过intel的汇编,现在忘了,请楼主指教
|