Created
December 29, 2024 19:23
-
-
Save un4ckn0wl3z/333d1bcfbbcd5cd76aa5e8fd154a067b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/ptrace.h> | |
#include <unistd.h> | |
int main(void) | |
{ | |
printf("Ptrace\n"); | |
int pid; | |
printf("please input pid:"); | |
scanf("%d",&pid); | |
long address; | |
printf("please input address:"); | |
scanf("%lX",&address); | |
long ret= ptrace(PTRACE_ATTACH,pid,NULL,NULL); | |
printf("PTRACE_ATTACH:%d\n",ret); | |
if(ret!=0){ | |
printf("PTRACE_ATTACH ERROR\n"); | |
return 1; | |
} | |
sleep(1); | |
//write memory | |
int data; | |
printf("please input data you want:"); | |
scanf("%d",&data); | |
ptrace(PTRACE_POKEDATA,pid,address,data); | |
printf("PTRACE_POKEDATA:%d\n",ret); | |
sleep(1); | |
//read memory | |
printf("%lX:",address); | |
int num=40; | |
for (int i = 0; i < num; i++) { | |
ret= ptrace(PTRACE_PEEKDATA,pid,address,NULL); | |
printf("%d\t",ret); | |
address+=0x4; | |
if((i+1)%4==0){ | |
printf("\n"); | |
if(i!=(num-1)){ | |
printf("%lX:",address); | |
} | |
} | |
} | |
ret= ptrace(PTRACE_DETACH,pid,NULL,NULL); | |
printf("PTRACE_DETACH:%d\n",ret); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment