FreeCalypso > hg > freecalypso-reveng
comparison miscprog/memwrite-grep.c @ 205:8bdc87c0fc03
memwrite-grep hack-utility written
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Thu, 10 Dec 2015 07:29:35 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
204:e9254e0234ab | 205:8bdc87c0fc03 |
---|---|
1 /* | |
2 * This utility performs a memmem() binary "grep", checking to see if a given | |
3 * binary file (firmware image) contains the $l1tm_mem_write implementation | |
4 * code found in our TCS211 objects and in that one C11x fw version for which | |
5 * we have the map file. | |
6 */ | |
7 | |
8 #define _GNU_SOURCE | |
9 #include <sys/types.h> | |
10 #include <sys/file.h> | |
11 #include <sys/stat.h> | |
12 #include <stdio.h> | |
13 #include <string.h> | |
14 #include <stdlib.h> | |
15 #include <unistd.h> | |
16 | |
17 u_char needle[50] = { | |
18 0x30, 0xb5, | |
19 0x45, 0x68, | |
20 0x42, 0x78, | |
21 0x04, 0x3a, | |
22 0x12, 0x06, | |
23 0x13, 0x0e, | |
24 0x00, 0x2b, | |
25 0x09, 0xd0, | |
26 0x00, 0x22, | |
27 0x14, 0x18, | |
28 0x24, 0x7a, | |
29 0x54, 0x55, | |
30 0x52, 0x1c, | |
31 0x12, 0x04, | |
32 0x12, 0x0c, | |
33 0x01, 0x3b, | |
34 0x00, 0x2b, | |
35 0xf6, 0xd1, | |
36 0x00, 0x20, | |
37 0x88, 0x80, | |
38 0x00, 0x06, | |
39 0x00, 0x0e, | |
40 0x48, 0x70, | |
41 0x88, 0x70, | |
42 0x30, 0xbd | |
43 }; | |
44 | |
45 u_char *haystack; | |
46 size_t haystack_size; | |
47 | |
48 read_file(filename) | |
49 char *filename; | |
50 { | |
51 int fd; | |
52 struct stat st; | |
53 | |
54 fd = open(filename, O_RDONLY); | |
55 if (fd < 0) { | |
56 perror(filename); | |
57 exit(1); | |
58 } | |
59 fstat(fd, &st); | |
60 if (!S_ISREG(st.st_mode)) { | |
61 fprintf(stderr, "error: %s is not a regular file\n", filename); | |
62 exit(1); | |
63 } | |
64 haystack_size = st.st_size; | |
65 haystack = malloc(haystack_size); | |
66 if (!haystack) { | |
67 fprintf(stderr, "unable to malloc buffer for %s\n", filename); | |
68 exit(1); | |
69 } | |
70 read(fd, haystack, haystack_size); | |
71 close(fd); | |
72 } | |
73 | |
74 main(argc, argv) | |
75 char **argv; | |
76 { | |
77 u_char *result; | |
78 | |
79 if (argc != 2) { | |
80 fprintf(stderr, "usage: %s firmware.bin\n", argv[0]); | |
81 exit(1); | |
82 } | |
83 read_file(argv[1]); | |
84 result = memmem(haystack, haystack_size, needle, sizeof needle); | |
85 if (result) | |
86 printf("Found the needle bytes at offset 0x%x\n", | |
87 result - haystack); | |
88 else | |
89 printf("Needle bytes not found in this image\n"); | |
90 exit(0); | |
91 } |