I want to change the logic of an exe by changing the binary. One of the hex values in the exe is 75 which I have to change to 74 (JNE to JE in x86 assembly). I know it's the 1276th byte of the file, but how do I do this?
我想通过更改二进制来更改exe的逻辑。 exe中的一个十六进制值是75,我必须将其更改为74(x86汇编中的JNE到JE)。我知道这是文件的第1276个字节,但我该怎么做?
Here's what I have:
这就是我所拥有的:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fileH = fopen ("foo", "r+");
fseek(fileH, 1276, SEEK_SET);
fwrite("74", 1, 1, fileH);
fclose(fileH);
return 0;
}
Also for some reason I'm getting 'fileH' undeclared, even though I included stdio and have FILE in all uppercase. I wasn't able to find anyone else with this problem. Running this on ubuntu
也是出于某些原因我得到'fileH'未声明,即使我包含stdio并且全部都是FILE。我无法找到有这个问题的其他人。在ubuntu上运行它
2 个解决方案
#1
2
You must define a byte value to write to the file. And the 8086 opcode for JE
is 74
in hexadecimal, not decimal.
您必须定义一个字节值以写入该文件。 JE的8086操作码是十六进制的74,而不是十进制。
#include <stdio.h>
int main(void)
{
unsigned char byt = 0x74;
FILE *fileH = fopen ("foo.txt", "r+");
if (fileH == NULL)
return 1;
if (fseek(fileH, 3, SEEK_SET))
return 1;
if (fwrite(&byt, 1, 1, fileH) != 1)
return 1;
if (fclose(fileH))
return 1;
printf("File updated\n");
return 0;
}
As a demo using a small text file, content before:
作为使用小文本文件的演示,内容之前:
0123456789
and after:
之后:
012t456789
I have no idea why your compiler refuses fileH
except that sometimes a text editor can leave a rogue unseen character where there should not be one. The solution there, is to delete and retype the offending line.
我不知道为什么你的编译器拒绝fileH,除了有时文本编辑器可以留下一个流氓看不见的字符,其中不应该有一个。那里的解决方案是删除并重新键入违规行。
#2
0
int main()
{
FILE *fileH = fopen ("foo", "r+");
fseek(fileH, 1276, SEEK_SET);
putc(0x74,fileH);
}
and xxd -p foo to dump in hex your file
和xxd -p foo以十六进制形式转储文件
#1
2
You must define a byte value to write to the file. And the 8086 opcode for JE
is 74
in hexadecimal, not decimal.
您必须定义一个字节值以写入该文件。 JE的8086操作码是十六进制的74,而不是十进制。
#include <stdio.h>
int main(void)
{
unsigned char byt = 0x74;
FILE *fileH = fopen ("foo.txt", "r+");
if (fileH == NULL)
return 1;
if (fseek(fileH, 3, SEEK_SET))
return 1;
if (fwrite(&byt, 1, 1, fileH) != 1)
return 1;
if (fclose(fileH))
return 1;
printf("File updated\n");
return 0;
}
As a demo using a small text file, content before:
作为使用小文本文件的演示,内容之前:
0123456789
and after:
之后:
012t456789
I have no idea why your compiler refuses fileH
except that sometimes a text editor can leave a rogue unseen character where there should not be one. The solution there, is to delete and retype the offending line.
我不知道为什么你的编译器拒绝fileH,除了有时文本编辑器可以留下一个流氓看不见的字符,其中不应该有一个。那里的解决方案是删除并重新键入违规行。
#2
0
int main()
{
FILE *fileH = fopen ("foo", "r+");
fseek(fileH, 1276, SEEK_SET);
putc(0x74,fileH);
}
and xxd -p foo to dump in hex your file
和xxd -p foo以十六进制形式转储文件