Changeset 2501 for neercs


Ignore:
Timestamp:
Jul 1, 2008, 1:26:12 AM (12 years ago)
Author:
Sam Hocevar
Message:
  • Preparing the amd64 port of grab.c by first making the current i386-specific code compile.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/grab.c

    r2498 r2501  
    3939#include "neercs.h"
    4040
     41#if defined __x86_64__
     42#   define RAX rax
     43#   define RBX rbx
     44#   define RCX rcx
     45#   define RDX rdx
     46#   define RSP rsp
     47#   define RIP rip
     48#else
     49#   define RAX eax
     50#   define RBX ebx
     51#   define RCX ecx
     52#   define RDX edx
     53#   define RSP esp
     54#   define RIP eip
     55#endif
     56
    4157#if defined USE_GRAB
    4258static int memcpy_from_target(pid_t pid, void* dest, void* src, size_t n)
     
    8399    }
    84100
    85     regs->esp = oregs.esp-4;
    86 
    87     oinst = ptrace(PTRACE_PEEKTEXT, pid, regs->esp, 0);
     101    regs->RSP = oregs.RSP - 4;
     102
     103    oinst = ptrace(PTRACE_PEEKTEXT, pid, regs->RSP, 0);
    88104    if (errno) {
    89105        fprintf(stderr, "PTRACE_PEEKTEXT failed\n");
     
    91107    }
    92108
    93     if (ptrace(PTRACE_POKETEXT, pid, regs->esp, 0x80cd) < 0) { /* int 0x80 */
     109    if (ptrace(PTRACE_POKETEXT, pid, regs->RSP, 0x80cd) < 0) { /* int 0x80 */
    94110        fprintf(stderr, "PTRACE_POKETEXT failed\n");
    95111        return errno;
    96112    }
    97113
    98     regs->eip = regs->esp;
     114    regs->RIP = regs->RSP;
    99115    if(ptrace(PTRACE_SETREGS, pid, NULL, regs) < 0)
    100116    {
     
    119135    }
    120136
    121     if(ptrace(PTRACE_POKETEXT, pid, oregs.esp-4 , oinst) < 0)
     137    if(ptrace(PTRACE_POKETEXT, pid, oregs.RSP-4 , oinst) < 0)
    122138    {
    123139        fprintf(stderr, "PTRACE_POKETEXT failed\n");
     
    137153    }
    138154
    139     regs.eax = SYS_close;
    140     regs.ebx = fd;
     155    regs.RAX = SYS_close;
     156    regs.RBX = fd;
    141157
    142158    return do_syscall(pid, &regs);
     
    152168    }
    153169
    154     regs.eax = SYS_dup2;
    155     regs.ebx = oldfd;
    156     regs.ecx = newfd;
     170    regs.RAX = SYS_dup2;
     171    regs.RBX = oldfd;
     172    regs.RCX = newfd;
    157173
    158174    return do_syscall(pid, &regs);
     
    181197    memcpy_into_target(pid, target_page, path, strlen(path)+4);
    182198
    183     regs.eax = SYS_open;
    184     regs.ebx = (long)target_page;
    185     regs.ecx = O_RDWR;
    186     regs.edx = 0755;
     199    regs.RAX = SYS_open;
     200    regs.RBX = (long)target_page;
     201    regs.RCX = O_RDWR;
     202    regs.RDX = 0755;
    187203
    188204    if((ret = do_syscall(pid, &regs)) != 0)
     
    194210    memcpy_into_target(pid, target_page, backup_page, size);
    195211
    196     *fd  = regs.eax;
     212    *fd  = regs.RAX;
    197213
    198214    return 0;
     
    211227    debug("Running setsid on process %d (sid=%d)", pid, getsid(pid));
    212228
    213     regs.eax = SYS_setpgid;
    214     regs.ebx = 0;
    215     regs.ecx = getsid(pid);
     229    regs.RAX = SYS_setpgid;
     230    regs.RBX = 0;
     231    regs.RCX = getsid(pid);
    216232
    217233    if((ret = do_syscall(pid, &regs)) != 0)
     
    220236    }
    221237
    222     if (regs.eax != 0) {
     238    if (regs.RAX != 0) {
    223239        fprintf(stderr, "setpgid failed\n");
    224         return -regs.eax;
    225     }
    226 
    227     regs.eax = SYS_setsid;
     240        return -regs.RAX;
     241    }
     242
     243    regs.RAX = SYS_setsid;
    228244
    229245    if((ret = do_syscall(pid, &regs)) != 0)
     
    234250    debug("pid %d has now sid %d", pid, getsid(pid));
    235251
    236     if (regs.eax == -1) {
     252    if (regs.RAX == -1) {
    237253        fprintf(stderr, "getsid failed\n");
    238         return -regs.eax;
     254        return -regs.RAX;
    239255    }
    240256
Note: See TracChangeset for help on using the changeset viewer.