使用 IDA PRO 修补简单的 C 程序出现分段错误

发布于 2024-12-29 18:04:11 字数 422 浏览 1 评论 0原文

这是我的程序:

#include <stdio.h>

int main(){
  int var=5;
  if(var==5) printf("Accesso effettuato!");
  else printf("Access denied");

}

我更改了操作码...在十六进制编辑中,如下图所示,但是当我运行程序时,出现分段错误。

image1

image2

在此处输入图像描述

This is my program:

#include <stdio.h>

int main(){
  int var=5;
  if(var==5) printf("Accesso effettuato!");
  else printf("Access denied");

}

I change the op code... in the hex edit like in this image but when I run my program I get a segmentation fault.

image1

image2

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谜泪 2025-01-05 18:04:11

您会遇到分段错误,因为操作码 83 05 表示指令 ADD DWORD PTR [address],constant,其中 addressconstant 由接下来的五个字节 05 89 45 F4 75 确定。因此,在本例中,指令为 ADD DWORD PTR [F4458905],75。所以你引用了一个无效的内存地址。

You get a segmentation fault because the opcode 83 05 means the instruction ADD DWORD PTR [address],constant where the address and constant are determined by the next five bytes 05 89 45 F4 75. So in this case, the instruction is ADD DWORD PTR [F4458905],75. So you are referencing an invalid memory address.

很糊涂小朋友 2025-01-05 18:04:11

最初的指令是:

83 F9 05  cmp ecx, 5

看起来你正试图将其更改为持续的比较,例如:

83 05 05  cmp 5, 5     ; not what you think it is!

我怀疑这样的野兽是否存在,因为它的实用性充其量是值得怀疑的。比较两个常数似乎是对硅的浪费。

实际上将其更改为一条几乎肯定会取消引用无效地址的指令)。

作为选项一,您可以用设置零位的字节序列替换该三字节序列(因为检查下面的几条指令是 jnz 指令),并用足够的 nop< 填充它/code> 操作使其大小相同。

或者,查找cmp ecx, ecx 语句(再次使用适当的nop 填充),以便您可以确定所有 标志均已正确设置。根据 GNU 汇编器 as 的说法,这是:

39 c9      cmp  %ecx, %ecx
90         nop

The original instruction is:

83 F9 05  cmp ecx, 5

It looks like you're trying to change that into a constant comaparison, something like:

83 05 05  cmp 5, 5     ; not what you think it is!

I doubt that such a beast even exists, since its usefulness would be questionable at best. Comparing two constants would seem to be a waste of silicon.

What you're actually changing it to is an instruction that almost certainly dereferences an invalid address).

As option one, you can replace that three byte sequence with one that sets the zero bit (since the check a few instructions down is a jnz instruction), and pad it out with enough nop operations to make it the same size.

Alternatively, look for a cmp ecx, ecx statement (again with appropriate nop padding) so that you can be certain all flags are set correctly. This is, according to the GNU assembler as:

39 c9      cmp  %ecx, %ecx
90         nop
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文