0

我有这样的程序

#include <stdio.h>

int somma(x,y){
  return x+y;
}

int diff(x,y){
  return x-y;
}



int main(){
  int x=5;
  int y=4;
  printf("la somma e' %d", somma(x,y));
  printf("La differenza e' %d", diff(x,y));
}

我正在尝试修补它以用 diff 函数替换 somma 函数的调用。在 E8 79 FF FF FF 和 diff 函数有 op E8 70 FF FF FF 所以我试图做的是:用 diff 替换 somma 函数的 op。所以我的 somma op 变成了 E8 70 FF FF FF 但是当我尝试执行它时,我收到了一个分段错误。为什么?我的错误是什么?

编辑这是我工作的屏幕。 伊达亲

4

1 回答 1

1

You can't simply replace the offset with something else in some other place to replace what it calls. What you need to do is calculate the relative offset from the caller offset to the function offset: destination - source - 5. So, for example, if the location of the opcode where you call the somma is 0x348232, and the location of somma is 0x858232, so the relative offset would be 0x858232-0x348232-5 = 0x50FFFB, and you'd have to replace the original bytes with E8 FB FF 50 00

于 2011-12-27T01:30:24.493 回答