blob: 413f845117fce39002bad878c21ecc1b17627d11 [file] [log] [blame]
Holger Hans Peter Freyther65d67dc2009-12-23 12:52:30 +01001/* Routines for parsing an ipacces SDP firmware file */
2
3/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <fcntl.h>
25#include <unistd.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30
Holger Hans Peter Freythere0d2ff42009-12-23 13:03:12 +010031/* more magic, the second "int" in the header */
32static char more_magic[] = { 0x10, 0x02, 0x00, 0x0 };
33
Holger Hans Peter Freyther65d67dc2009-12-23 12:52:30 +010034
35static void analyze_file(int fd)
36{
37 char buf[4096];
38 int rc;
39
40 rc = read(fd, buf, 4);
41 if (rc <= 0) {
42 fprintf(stderr, "Not enough space for the header.\n");
43 return;
44 }
45
46 if (strcmp(buf, " SDP") != 0) {
47 fprintf(stderr, "Wrong magic number at the beginning of the file.\n");
48 return;
49 }
50
Holger Hans Peter Freythere0d2ff42009-12-23 13:03:12 +010051 rc = read(fd, buf, 4);
52 if (rc <= 0) {
53 fprintf(stderr, "Not enough space for the more_magic.\n");
54 return;
55 }
56
57 if (strncmp(buf, more_magic, 4) != 0) {
58 fprintf(stderr, "The more magic is not right.\n");
59 return;
60 }
61
Holger Hans Peter Freyther65d67dc2009-12-23 12:52:30 +010062 printf("Printing header information:\n");
63}
64
65int main(int argc, char** argv)
66{
67 int i, fd;
68
69 for (i = 1; i < argc; ++i) {
70 printf("Opening possible firmware '%s'\n", argv[i]);
71 fd = open(argv[i], O_RDONLY);
72 if (!fd) {
73 perror("nada");
74 continue;
75 }
76
77 analyze_file(fd);
78 }
79
80 return EXIT_SUCCESS;
81}