diff --git a/C/scripts/build.sh b/C/scripts/build.sh index 3cbcb64..32406ee 100755 --- a/C/scripts/build.sh +++ b/C/scripts/build.sh @@ -2,6 +2,6 @@ #C printf "Running program...\n\n\n" if gcc $(find . -type f -name "*.c") ${CUSTOM_PARAMS} -o ${PROJECT_NAME}; then - ./${PROJECT_NAME} "$@" + sudo ./${PROJECT_NAME} "$@" fi printf "\n\n" diff --git a/main.c b/main.c index 6c0ebc4..f56c003 100644 --- a/main.c +++ b/main.c @@ -1,17 +1,21 @@ #include -#include +#include +#include +#include +#include +#include -unsigned long strToLong(char*str) { +unsigned long long strToLong(char*str) { int counter=0; char c; unsigned long val=0; int base=10; while ((c=str[counter++])!='\0') { - if (counter==1&&c=='0') { + if (c=='0'&&val==0&&base==10) { base=8; continue; } else - if (counter==2&&c=='x') { + if (c=='x'&&val==0&&base==8) { base=16; continue; } @@ -29,8 +33,8 @@ unsigned long strToLong(char*str) { } int main(int argc,char**argv) { - unsigned int pid; - unsigned long addr; + long unsigned int pid; + unsigned long long addr; unsigned long val; unsigned int interval=1000; if (argc<4) { @@ -43,9 +47,33 @@ int main(int argc,char**argv) { if (argc>=5) { interval=strToLong(argv[4]); } - printf("\nPID: %lu",pid); - printf("\nAddress: %lu",addr); - printf("\nValue: %lu",val); - printf("\nInterval: %lu",interval); + printf("\nPID: %lu",pid); + printf("\nAddress: 0x%08llx",addr); + printf("\nValue: %lu",val); + printf("\nInterval: %d",interval); + + char*proc_mem = malloc(50); + sprintf(proc_mem,"/proc/%ld/mem",pid); + int fd_proc_mem=open(proc_mem,O_RDWR); + if (fd_proc_mem==-1) { + printf("Could not open %s\n",proc_mem); + exit(1); + } + char*buf=malloc(sizeof(unsigned int)); + lseek(fd_proc_mem,addr,SEEK_SET); + read(fd_proc_mem,buf,sizeof(unsigned int)); + while (1) { + sprintf(buf,"%d",(int)val++); + lseek(fd_proc_mem,addr,SEEK_SET); + if (write(fd_proc_mem,buf,sizeof(unsigned int))==-1) { + printf("Error while writing\n"); + exit(1); + } + printf("\nWrite %d",(int)val-1); + sleep(2); + } + + free(buf); + free(proc_mem); } } \ No newline at end of file diff --git a/memovr b/memovr index be4871c..26c82ae 100755 Binary files a/memovr and b/memovr differ diff --git a/sig b/sig index 06a67d8..9278450 100755 --- a/sig +++ b/sig @@ -1,4 +1,4 @@ -export AUTO_UPDATE=true +export AUTO_UPDATE=false source utils/define.sh diff --git a/testProgram b/testProgram new file mode 100755 index 0000000..41ff809 Binary files /dev/null and b/testProgram differ diff --git a/testProgram. b/testProgram. new file mode 100644 index 0000000..dc60a1e --- /dev/null +++ b/testProgram. @@ -0,0 +1,20 @@ + +#include +#include +#include + +int main() { + + char foo[] = "This is some text from proc-1"; + + printf("Now execute\n"); + printf(" sudo ./testProgram2 %d %lx %lu\n", getpid(), (long unsigned int) foo, strlen(foo)+1); + + printf("Press any key\n"); +while (1) { + getchar(); + + printf("foo has changed to: %s\n", foo); +} + +} diff --git a/testProgram2 b/testProgram2 new file mode 100755 index 0000000..5e3f4ae Binary files /dev/null and b/testProgram2 differ diff --git a/testProgram2. b/testProgram2. new file mode 100644 index 0000000..9923e47 --- /dev/null +++ b/testProgram2. @@ -0,0 +1,49 @@ +#include +#include +// #include +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + + if (argc != 4) { + printf("proc-2 pid addr length\n"); + exit(1); + } + + int pid = strtol (argv[1], NULL, 10); + unsigned long addr = strtoul(argv[2], NULL, 16); + int len = strtol (argv[3], NULL, 10); + + char* proc_mem = malloc(50); + sprintf(proc_mem, "/proc/%d/mem", pid); + + printf("opening %s, address is %ld\n", proc_mem, addr); + int fd_proc_mem = open(proc_mem, O_RDWR); + if (fd_proc_mem == -1) { + printf("Could not open %s\n", proc_mem); + exit(1); + } + + char* buf = malloc(len); + + lseek(fd_proc_mem, addr, SEEK_SET); + read (fd_proc_mem, buf , len ); + + printf("String at %ld in process %d is:\n", addr, pid); + printf(" %s\n", buf); + + printf("\nNow, this string is modified\n"); + strncpy(buf, "Hello from proc-2", len); + + lseek(fd_proc_mem, addr, SEEK_SET); + if (write (fd_proc_mem, buf , len ) == -1) { + printf("Error while writing\n"); + exit(1); + } + + free(buf); + free(proc_mem); +}