how to assign value to EIP with C language in ubuntu

Posted by user353573 on Stack Overflow See other posts from Stack Overflow or by user353573
Published on 2010-06-08T13:59:45Z Indexed on 2010/06/08 14:02 UTC
Read the original article Hit count: 239

Filed under:

where is wrong? how to assign value to eip to change the location of running in program?

Please help !!!!

error: cannot convert ‘mcontext_t*’ to ‘sigcontext*’ in assignment

struct ucontext {
    unsigned long     uc_flags;
    struct ucontext  *uc_link;
    stack_t       uc_stack;
    struct sigcontext uc_mcontext;
    sigset_t      uc_sigmask;   /* mask last for extensibility */
};

#include <stdio.h>
#include <signal.h>
#include <asm/ucontext.h>
void handler(int signum, siginfo_t *siginfo, void *uc0){
    struct ucontext *uc;
    struct sigcontext *sc;

    uc = (struct ucontext *)uc0;
    sc = &uc->uc_mcontext;

    sc->eip = target;
    //uc->uc_mcontext.gregs[REG_EIP]
}

int main (int argc, char** argv){
    struct sigaction act;
    act.sa_sigaction = handler;
    act.sa_flags = SA_SIGINFO;
    sigaction(SIGTRAP, &act, NULL);

    asm("movl $skipped, %0" : : "m" (target));

    asm("int3"); // cause SIGTRAP
    printf("to be skipped.\n");
    asm("skipped:");
    printf("Done.\n");
}

© Stack Overflow or respective owner

Related posts about c