我尝试获取 dmg 文件的标题。我看到了这个对我有很大帮助的链接 。所以我制作了一个 c++ 程序来获取所有这些东西。
这里是 :
struct Header
{
int img;
char tag[4];
short size;
short version;
int format;
int flag;
int num_block;
int offset;
int length;
int offset_comment;
int length_comment;
int offset_creator;
int length_creator;
char space[16];
};
void read_header(const char *path)
{
Header head;
FILE *file = fopen(path, "rb");
fread(&head, 1, sizeof(Header), file);
printf(" size short = %d\n", sizeof( short ));
printf(" size int = %d\n", sizeof( int ));
printf(" size struct = %d\n", sizeof( Header ));
printf("img %d\n", head.img);
printf("tag %s\n", head.tag);
printf("size %d\n", head.size);
printf("version %d\n", head.version);
printf("format %d\n", head.format);
printf("flag %d\n", head.flag);
printf("num_block %d\n", head.num_block);
printf("offset %d\n", head.offset);
printf("length %d\n", head.length);
printf("offset_comment %d\n", head.offset_comment);
printf("length_comment %d\n", head.length_comment);
printf("offset_creator %d\n", head.offset_creator);
printf("length_creator %d\n", head.length_creator);
}
我明白了:
size short = 2
size int = 4
size struct = 64
img 152133
tag
size 0
version 0
format 0
flag 0
num_block 0
offset 0
length 0
offset_comment 0
length_comment 0
offset_creator 0
length_creator 0
我不知道为什么我的所有值都是 null 除了第一个。我的 dmg 文件很好,我可以打开它。有人知道为什么我得到空值吗?