-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
66 lines (57 loc) · 1.52 KB
/
main.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
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "android.h"
#define VERSION "v1.0.0"
#define READ_HEADER \
if (!fread(&header, sizeof(header), 1, fp)) { \
STDERR("Unable to read the file.\n"); \
code = EXIT_FAILURE; \
break; \
}
int main(int argc, const char* argv[]) {
unsigned short code = EXIT_SUCCESS;
if (argc < 3) {
fprintf(stderr, FORE_BLUE "Android Things/" FORE_RED "BootInfo " STYLE_RESET VERSION "\n");
fprintf(stderr, "An utility for parsing the header section of Android boot images.\n\n");
fprintf(stderr, FORE_CYAN "Usage:\n" STYLE_RESET);
fprintf(stderr, " %s <boot.img> <boot header version>\n", argv[0]);
return EXIT_FAILURE;
}
FILE *fp;
if ((fp = fopen(argv[1], "r")) == NULL) {
STDERR("Unable to open %s: %s.\n", argv[1], strerror(errno));
return errno;
}
printf(FORE_BLUE "%s" STYLE_RESET ":\n", argv[1]);
switch (atoi(argv[2])) {
case 0: {
boot_img_hdr_v0 header;
READ_HEADER;
print_v0(header);
break;
}
case 1: {
boot_img_hdr_v1 header;
READ_HEADER;
print_v0(header.v0_base);
print_v1(header);
break;
}
case 2:{
boot_img_hdr_v2 header;
READ_HEADER;
print_v0(header.v1_base.v0_base);
print_v1(header.v1_base);
print_v2(header);
break;
}
default:
STDERR("Invalid boot header version: 0 <= header_version <= 2.\n");
code = EXIT_FAILURE;
}
fclose(fp);
return code;
}