Advertisement
Guest User

patch to make-static

a guest
Jun 30th, 2013
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.08 KB | None | 0 0
  1. diff -rupN make-static-0.01/Makefile make-static-0.02/Makefile
  2. --- make-static-0.01/Makefile   2004-11-18 16:48:02.000000000 +0100
  3. +++ make-static-0.02/Makefile   2013-06-30 15:51:56.243592997 +0200
  4. @@ -1,6 +1,6 @@
  5.  OBJECTS = make-static
  6.  
  7. -CFLAGS = -g -Wall -O3
  8. +CFLAGS = -g -W -Wall -Wextra -O3
  9.  
  10.  CHPAX = /sbin/chpax
  11.  DEPAX = test ! -x $(CHPAX) || $(CHPAX) -xperms
  12. diff -rupN make-static-0.01/imagewriter.c make-static-0.02/imagewriter.c
  13. --- make-static-0.01/imagewriter.c  2004-11-14 11:22:17.000000000 +0100
  14. +++ make-static-0.02/imagewriter.c  2013-06-30 15:49:35.089390936 +0200
  15. @@ -13,7 +13,7 @@
  16.  #include <dirent.h>
  17.  #include <fcntl.h>
  18.  #include <signal.h>
  19. -#include <linux/user.h>
  20. +#include <sys/user.h>
  21.  #include <linux/kdev_t.h>
  22.  #include <asm/ldt.h>
  23.  #include <elf.h>
  24. @@ -93,7 +93,7 @@ int write_proc_image_to_elf(struct proc_
  25.      eh.e_type = ET_EXEC;
  26.      eh.e_machine = EM_386;
  27.      eh.e_version = EV_CURRENT;
  28. -    eh.e_entry = p->user_data.regs.eip;
  29. +    eh.e_entry = p->user_data.regs.rip;
  30.      eh.e_phoff = sizeof(eh);
  31.      eh.e_shoff = 0;
  32.      eh.e_flags = 0x112;
  33. diff -rupN make-static-0.01/make-static.c make-static-0.02/make-static.c
  34. --- make-static-0.01/make-static.c  2004-11-18 16:45:27.000000000 +0100
  35. +++ make-static-0.02/make-static.c  2013-06-30 15:49:37.361426379 +0200
  36. @@ -7,7 +7,7 @@
  37.  
  38.  
  39.  #include <sys/types.h>
  40. -#include <linux/user.h>
  41. +#include <sys/user.h>
  42.  #include <sys/ptrace.h>
  43.  #include <fcntl.h>
  44.  #include <elf.h>
  45. diff -rupN make-static-0.01/process.c make-static-0.02/process.c
  46. --- make-static-0.01/process.c  2004-11-14 10:00:43.000000000 +0100
  47. +++ make-static-0.02/process.c  2013-06-30 15:54:02.013554965 +0200
  48. @@ -23,7 +23,7 @@
  49.  #include <dirent.h>
  50.  #include <fcntl.h>
  51.  #include <signal.h>
  52. -#include <linux/user.h>
  53. +#include <sys/user.h>
  54.  #include <linux/kdev_t.h>
  55.  #include <asm/ldt.h>
  56.  #include <asm/unistd.h>
  57. @@ -36,7 +36,7 @@ long scribble_zone = 0; /* somewhere to
  58.  
  59.  char* backup_page(pid_t target, void* addr) {
  60.      long* page = malloc(PAGE_SIZE);
  61. -    int i;
  62. +    size_t i;
  63.      long ret;
  64.      for(i = 0; i < PAGE_SIZE/sizeof(long); i++) {
  65.     ret = ptrace(PTRACE_PEEKTEXT, target, (void*)((long)addr+(i*sizeof(long))), 0);
  66. @@ -58,7 +58,7 @@ char* backup_page(pid_t target, void* ad
  67.  
  68.  int restore_page(pid_t target, void* addr, char* page) {
  69.      long *p = (long*)page;
  70. -    int i;
  71. +    size_t i;
  72.      assert(page);
  73.      for (i = 0; i < PAGE_SIZE/sizeof(long); i++) {
  74.     if (ptrace(PTRACE_POKETEXT, target, (void*)((long)addr+(i*sizeof(long))), p[i]) == -1) {
  75. @@ -74,7 +74,7 @@ int restore_page(pid_t target, void* add
  76.  int memcpy_into_target(pid_t pid, void* dest, const void* src, size_t n) {
  77.      /* just like memcpy, but copies it into the space of the target pid */
  78.      /* n must be a multiple of 4, or will otherwise be rounded down to be so */
  79. -    int i;
  80. +    size_t i;
  81.      long *d, *s;
  82.      d = (long*) dest;
  83.      s = (long*) src;
  84. @@ -90,7 +90,7 @@ int memcpy_into_target(pid_t pid, void*
  85.  int memcpy_from_target(pid_t pid, void* dest, const void* src, size_t n) {
  86.      /* just like memcpy, but copies it from the space of the target pid */
  87.      /* n must be a multiple of 4, or will otherwise be rounded down to be so */
  88. -    int i;
  89. +    size_t i;
  90.      long *d, *s;
  91.      d = (long*) dest;
  92.      s = (long*) src;
  93. @@ -143,7 +143,7 @@ int do_syscall(pid_t pid, struct user_re
  94.      }
  95.  
  96.      /* Set up registers for ptrace syscall */
  97. -    regs->eip = loc;
  98. +    regs->rip = loc;
  99.      if (ptrace(PTRACE_SETREGS, pid, NULL, regs) < 0) {
  100.     perror("ptrace setregs");
  101.     return 0;
  102. @@ -396,7 +396,7 @@ int get_one_vma(pid_t target_pid, char*
  103.  }
  104.  
  105.  int get_user_data(pid_t target_pid, struct user *user_data) {
  106. -    long pos;
  107. +    unsigned long pos;
  108.      int* user_data_ptr = (int*)user_data;
  109.  
  110.      /* We have a memory segment. We should retrieve its data */
  111. @@ -411,7 +411,7 @@ int get_user_data(pid_t target_pid, stru
  112.      return 1;
  113.  }
  114.  
  115. -int get_i387_data(pid_t target_pid, struct user_i387_struct* i387_data) {
  116. +int get_i387_data(pid_t target_pid, struct user_fpregs_struct* i387_data) {
  117.      /* We have a memory segment. We should retrieve its data */
  118.      fprintf(stderr, "[+] Retrieving FP registers... ");
  119.  
  120. @@ -432,20 +432,20 @@ off_t get_file_offset(pid_t pid, int fd,
  121.     return 0;
  122.      }
  123.  
  124. -    r.eax = __NR_lseek;
  125. -    r.ebx = fd;
  126. -    r.ecx = offset;
  127. -    r.edx = whence;
  128. +    r.rax = __NR_lseek;
  129. +    r.rbx = fd;
  130. +    r.rcx = offset;
  131. +    r.rdx = whence;
  132.  
  133.      if (!do_syscall(pid, &r)) return 0;
  134.  
  135.      /* Error checking! */
  136. -    if (r.eax < 0) {
  137. -   errno = -r.eax;
  138. +    if ((signed)r.rax < 0) {
  139. +   errno = -r.rax;
  140.     return (off_t)(-1);
  141.      }
  142.  
  143. -    return r.eax;
  144. +    return r.rax;
  145.  }
  146.  
  147.  int get_file_contents(char *filename, struct fd_entry_t *out_buf) {
  148. @@ -495,9 +495,9 @@ struct user_desc *get_tls_info(pid_t pid
  149.      return u;
  150.  }
  151.  
  152. -int is_in_syscall(pid_t pid, void* eip) {
  153. +int is_in_syscall(pid_t pid, void* rip) {
  154.      long inst;
  155. -    inst = ptrace(PTRACE_PEEKDATA, pid, eip-2, 0);
  156. +    inst = ptrace(PTRACE_PEEKDATA, pid, rip-2, 0);
  157.      if (errno) {
  158.     perror("ptrace(PEEKDATA)");
  159.     return 0;
  160. @@ -513,17 +513,17 @@ int get_signal_handler(pid_t pid, int si
  161.     return 0;
  162.      }
  163.  
  164. -    r.eax = __NR_rt_sigaction;
  165. -    r.ebx = sig;
  166. -    r.ecx = 0;
  167. -    r.edx = scribble_zone+0x100;
  168. -    r.esi = sizeof(ksa->sa_mask);
  169. +    r.rax = __NR_rt_sigaction;
  170. +    r.rbx = sig;
  171. +    r.rcx = 0;
  172. +    r.rdx = scribble_zone+0x100;
  173. +    r.rsi = sizeof(ksa->sa_mask);
  174.  
  175.      if (!do_syscall(pid, &r)) return 0;
  176.  
  177.      /* Error checking! */
  178. -    if (r.eax < 0) {
  179. -   errno = -r.eax;
  180. +    if ((signed)r.rax < 0) {
  181. +   errno = -r.rax;
  182.     perror("target rt_sigaction");
  183.     return 0;
  184.      }
  185. @@ -543,16 +543,16 @@ int get_termios(pid_t pid, int fd, struc
  186.     return 0;
  187.      }
  188.  
  189. -    r.eax = __NR_ioctl;
  190. -    r.ebx = fd;
  191. -    r.ecx = TCGETS;
  192. -    r.edx = scribble_zone+0x50;
  193. +    r.rax = __NR_ioctl;
  194. +    r.rbx = fd;
  195. +    r.rcx = TCGETS;
  196. +    r.rdx = scribble_zone+0x50;
  197.  
  198.      if (!do_syscall(pid, &r)) return 0;
  199.  
  200.      /* Error checking! */
  201. -    if (r.eax < 0) {
  202. -   errno = -r.eax;
  203. +    if ((signed)r.rax < 0) {
  204. +   errno = -r.rax;
  205.     perror("target ioctl");
  206.     return 0;
  207.      }
  208. @@ -570,19 +570,19 @@ int get_fcntl_data(pid_t pid, int fd, st
  209.     return 0;
  210.      }
  211.  
  212. -    r.eax = __NR_fcntl;
  213. -    r.ebx = fd;
  214. -    r.ecx = F_GETFD;
  215. +    r.rax = __NR_fcntl;
  216. +    r.rbx = fd;
  217. +    r.rcx = F_GETFD;
  218.  
  219.      if (!do_syscall(pid, &r)) return 0;
  220.  
  221.      /* Error checking! */
  222. -    if (r.eax < 0) {
  223. -   errno = -r.eax;
  224. +    if ((signed)r.rax < 0) {
  225. +   errno = -r.rax;
  226.     perror("target fcntl");
  227.     return 0;
  228.      }
  229. -    f->close_on_exec = r.eax;
  230. +    f->close_on_exec = r.rax;
  231.  
  232.      return 1;
  233.  }
  234. @@ -646,11 +646,11 @@ struct proc_image_t* get_proc_image(pid_
  235.     proc_image = NULL;
  236.     goto out_ptrace;
  237.      }
  238. -    fprintf(stderr, "EIP is 0x%lx\n", proc_image->user_data.regs.eip);
  239. -    if (is_in_syscall(target_pid, (void*)proc_image->user_data.regs.eip)) {
  240. +    fprintf(stderr, "rip is 0x%llx\n", proc_image->user_data.regs.rip);
  241. +    if (is_in_syscall(target_pid, (void*)proc_image->user_data.regs.rip)) {
  242.     fprintf(stderr, "[+] Process is probably in syscall. Noting this fact.\n");
  243. -   proc_image->user_data.regs.eip-=2;
  244. -   proc_image->user_data.regs.eax = proc_image->user_data.regs.orig_eax;
  245. +   proc_image->user_data.regs.rip-=2;
  246. +   proc_image->user_data.regs.rax = proc_image->user_data.regs.orig_rax;
  247.      }
  248.  
  249.      /* Get FP regs */
  250. diff -rupN make-static-0.01/process.h make-static-0.02/process.h
  251. --- make-static-0.01/process.h  2004-11-14 10:29:15.000000000 +0100
  252. +++ make-static-0.02/process.h  2013-06-30 15:50:56.734665097 +0200
  253. @@ -13,7 +13,7 @@
  254.  #include <sys/ptrace.h>
  255.  #include <sys/mman.h>
  256.  #include <signal.h>
  257. -#include <linux/user.h>
  258. +#include <sys/user.h>
  259.  #include <linux/kdev_t.h>
  260.  #include <linux/types.h>
  261.  #include <asm/ldt.h>
  262. @@ -71,7 +71,7 @@ struct fd_entry_t {
  263.  struct proc_image_t {
  264.      pid_t pid;
  265.      struct user user_data;
  266. -    struct user_i387_struct i387_data;
  267. +    struct user_fpregs_struct i387_data;
  268.      int num_maps;
  269.      struct map_entry_t *maps;
  270.      int num_tls;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement