clean
[linux-2.4.21-pre4.git] / ver / modify.c
1 #include <stdio.h>
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include <fcntl.h> 
6
7 int main(int argc, char **argv)
8 {
9         int fd;
10         struct stat buf;
11         u_int32_t len, pos, sig;
12         unsigned long end_code=0x48945489;
13         
14         if (argc != 2)
15         {
16                 printf("Usage: modify <file>.\n");
17                 exit(0);
18         }
19         fd = open(argv[1], O_RDWR);
20         fstat(fd, &buf);
21         len = buf.st_size;
22         printf("Modifying the header...\n");
23         printf("Signature position is at %d from the start address.\n", len-4);
24         lseek(fd, 8, SEEK_SET);
25         len -= 4;
26         write(fd, &len, sizeof(u_int32_t));
27
28         printf("Checking the header...\n");
29         //Get the offset
30         lseek(fd, 8, SEEK_SET);
31         read(fd, &pos, sizeof(u_int32_t));
32
33         //Get the signature
34         lseek(fd, pos, SEEK_SET);
35         read(fd, &sig, sizeof(u_int32_t)); 
36         if (sig != end_code)
37                 printf("Bad target image!\n");
38         else
39                 printf("Correct target image!\n");
40         close(fd);
41         return 0;
42 }