-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgsimg.c
66 lines (54 loc) · 1.41 KB
/
gsimg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (C) 2011 <fwhacking|gmail:com>
*
* This is free software, licensed under the GNU General Public License v2.
* See /LICENSE for more information.
*
*/
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "gsimg.h"
static void print_usage(const char *name)
{
printf("Usage: %s firmware\n", name);
}
int main(int argc, char **argv)
{
FILE *fd;
GS_HEADER *hdr;
unsigned char *fp;
long size;
if (argc != 2)
{
print_usage(argv[0]);
exit(1);
}
fd = fopen(argv[1], "rb");
if (fd == NULL)
{
printf("Could not read the firmware file '%s'\n", argv[1]);
print_usage(argv[0]);
exit(1);
}
size = fseek(fd, 0L, SEEK_END);
size = ftell(fd);
//~ printf("Firmware file size : %ld bytes\n\n", size);
fseek(fd, 0L, SEEK_SET);
fp = malloc(size);
fread(fp, size, 1, fd);
fclose(fd);
hdr = (GS_HEADER *) fp;
printf("HEADER\n");
printf("-------------------------------------\n");
printf("size\t\t%d\n", SWAP_BE32(hdr->size) * 2);
printf("checksum\t0x%04X\n", SWAP_BE16(hdr->checksum));
printf("version\t\t%d.%d.%d.%d\n", hdr->version1, hdr->version2, hdr->version3, hdr->version4);
printf("build date\t%d-%02d-%02d %02d:%02d\n", SWAP_BE16(hdr->build_year), hdr->build_month, hdr->build_day, hdr->build_hour, hdr->build_minute);
printf("name\t\t%s\n", hdr->name);
printf("-------------------------------------\n\n");
free(fp);
exit(0);
}