2010-06-08 49 views
0

哪裏出錯?如何爲eip分配值以更改在程序中運行的位置?如何在ubuntu中用C語言指定EIP的值

請幫忙!!!!

錯誤:無法轉換「mcontext_t *」到「sigcontext *」在分配

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"); 
} 
+0

首先,您需要移動'#includes'以使它們位於'struct ucontext'之前,否則'sigset_t' * et al *在使用之前不會被定義。 – 2010-06-08 14:06:16

+0

它編譯和運行在我的電腦上,沒有錯誤。 GCC 4.3 – zoli2k 2010-06-08 14:07:14

+0

gcc(Ubuntu 4.4.1-4ubuntu9)4.4.1運行錯誤 – user353573 2010-06-08 14:10:05

回答

1

僅供參考。檢查man setjmpman longjmp