8 int main(int argc
, char **argv
){
9 unsigned char *buffer
= malloc(64 * 1024);
11 unsigned int size_vmlinux
= 0, real_size_vmlinux
= 0;
12 const unsigned char *magic_str
= "ACME_PART_MAGIC";
17 printf("%s in out\n", argv
[0]);
21 printf("Generating image\n");
23 FILE *vmlinux
= fopen(argv
[1], "r");
24 FILE *vmlinux_out
= fopen(argv
[2], "w");
25 if((!vmlinux
) || (!vmlinux_out
)){
26 printf("Error opening a file\n");
31 size_vmlinux
= s
.st_size
;
32 real_size_vmlinux
= (size_vmlinux
& 0xffff0000) + 0x10000;
34 printf("vmlinux = 0x%.08X / 0x%.08X\n", size_vmlinux
, real_size_vmlinux
);
36 unsigned int t
= fread(buffer
, 1, 64 * 1024, vmlinux
);
37 for(loop
= 0; loop
< (64 * 1024) - sizeof(magic_str
); loop
++){
38 if(buffer
[loop
] == magic_str
[0]){
39 if((magic
= strstr(&buffer
[loop
], magic_str
))){
40 printf("Magic at 0x%.08X %p %p\n", magic
- buffer
, magic
, buffer
);
41 printf("Found Magic %X%X%X%X\n",
42 buffer
[loop
+ strlen(magic_str
)],
43 buffer
[loop
+ strlen(magic_str
) + 2],
44 buffer
[loop
+ strlen(magic_str
) + 1],
45 buffer
[loop
+ strlen(magic_str
) + 3]);
47 buffer
[loop
+ strlen(magic_str
)] = real_size_vmlinux
>> 24;
48 buffer
[loop
+ strlen(magic_str
) + 2] = (real_size_vmlinux
>> 16) & 0xff;
49 buffer
[loop
+ strlen(magic_str
) + 1] = (real_size_vmlinux
>> 8) & 0xff;
50 buffer
[loop
+ strlen(magic_str
) + 3] = (real_size_vmlinux
) & 0xff;
52 printf("Replaced with %.02X%.02X%.02X%.02X\n",
53 buffer
[loop
+ strlen(magic_str
)],
54 buffer
[loop
+ strlen(magic_str
) + 2],
55 buffer
[loop
+ strlen(magic_str
) + 1],
56 buffer
[loop
+ strlen(magic_str
) + 3]);
62 fwrite(buffer
, 1, 64 * 1024, vmlinux_out
);
63 real_size_vmlinux
-= 64 * 1024;
65 real_size_vmlinux
-= 64 * 1024;
66 memset(buffer
, 0, 64 * 1024);
67 fread(buffer
, 1, 64 * 1024, vmlinux
);
68 fwrite(buffer
, 1, 64 * 1024, vmlinux_out
);
69 } while (real_size_vmlinux
);
This page took 0.05039 seconds and 5 git commands to generate.