使用fread()读取二进制文件内容
我想使用 fread 读取二进制文件的一段。二进制内容为 0xf3 0xf 0x1e 0xfa...
但我从 fread() 0xfffffff3 0xf 读取并输出...我想知道为什么0xf3 变为 0xfffffff3 0xf 0x1e 0xfffffffa...
我的实现代码如下:
char movslq_inst[length];
/* Open the target_binary */
FILE * target_binary = fopen(target_path,"rb+");
/* Jump to target address */
if (fseek(target_binary, offset, SEEK_SET) != 0)
{
printf("Unable to seek file '%s' at offset '%i", target_path, offset);
exit(0);
}
/* Read the target bytes */
if (fread(movslq_inst, length, 1, target_binary) != 1)
{
printf("Unable to read file '%s'", target_path);
exit(0);
}
/* test examine */
printf("read content: \n");
for(int i = 0; i < length; i++)
{
printf("0x%x ",movslq_inst[i]);
}
printf("\n");
I want to use fread to read a segment of a binary file. The binary content is 0xf3 0xf 0x1e 0xfa...
But I read and output from fread() 0xfffffff3 0xf... I want to know why 0xf3 becomes 0xfffffff3 0xf 0x1e 0xfffffffa...
My implementation code is as follows:
char movslq_inst[length];
/* Open the target_binary */
FILE * target_binary = fopen(target_path,"rb+");
/* Jump to target address */
if (fseek(target_binary, offset, SEEK_SET) != 0)
{
printf("Unable to seek file '%s' at offset '%i", target_path, offset);
exit(0);
}
/* Read the target bytes */
if (fread(movslq_inst, length, 1, target_binary) != 1)
{
printf("Unable to read file '%s'", target_path);
exit(0);
}
/* test examine */
printf("read content: \n");
for(int i = 0; i < length; i++)
{
printf("0x%x ",movslq_inst[i]);
}
printf("\n");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了。它应该是
unsigned char movslq_inst[length];
而不是char movslq_inst[length];
。I worked it out. It should be
unsigned char movslq_inst[length];
instead ofchar movslq_inst[length];
.