gpt4 book ai didi

C++ 写();反向写入给定的字节值

转载 作者:太空宇宙 更新时间:2023-11-04 12:46:41 25 4
gpt4 key购买 nike

<分区>

目前正在编写一个打开文件的程序,移动到给定的偏移量,然后更改偏移量处的字节。

这是代码:

void write(int offset, int modifiedBytes) {

fstream Binary("path/to/file");

if(!Binary) {
cout << "File not found!";
}

Binary.seekg(offset); //Go to given position from the given binary file
Binary.write((char *)&modifiedBytes,4); //put modified bytes into the given position from above
}

然后我有一个单独的函数,可以根据需要向其中添加乘法:

void doInjection() {
write(0xfe,0x7047); //write 7047 to 0xfe
}

虽然它确实会写入给定文件,但它会反向写入 7047 (4770)。

我也尝试过使用 put(); 而不是 write,但这只允许我使用 2 个字节,但它没有反向写入.

任何人都知道为什么它会反向写入我的给定值?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com