-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest1.c
131 lines (108 loc) · 2.99 KB
/
test1.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <libgen.h>
#include <biutils.h>
void extract_ramdisk(struct bootimage* bi)
{
int ret = bootimage_extract_ramdisk_archive(bi,NULL);
if ( ret == -1 ){
printf("bootimage_extract_ramdisk failed err=%d\n",errno);
}
}
void extract_ramdisk_directory(struct bootimage* bi)
{
int ret = bootimage_extract_ramdisk(bi,NULL);
if ( ret == -1 ){
printf("bootimage_extract_ramdisk failed err=%d\n",errno);
}
}
void extract_kernel(struct bootimage* bi)
{
int ret = bootimage_extract_kernel(bi,NULL);
if ( ret == -1 ){
printf("bootimage_extract_kernel failed err=%d\n",errno);
}
}
void extract_header_block(struct bootimage* bi)
{
int ret = bootimage_extract_header_block(bi,NULL);
if ( ret == -1 ){
printf("bootimage_extract_header_block failed err=%d\n",errno);
}
}
void list_archive(const char *name)
{
struct bootimage* bi = NULL;
printf("bi %p\n",bi);
bi = bootimage_initialize();
int ret = bootimage_file_read(bi,name);
if ( ret == -1 ){
printf("bootimage_file_read failed err=%d\n",errno);
}else{
extract_ramdisk(bi);
extract_kernel(bi);
extract_header_block(bi);
extract_ramdisk_directory(bi);
}
bootimage_free(&bi);
printf("bi %p\n",bi);
//int ret = bootimage_read_filename_(bi,name);
//int ret = bootimage_extract_ramdisk_entry_from_file(bi,name,"init.rc");
//ret = bootimage_read_kernel(bi);
/*printf("bi %p ret=%d errno=%d\n",bi,ret,errno);
bootimage_read_free(&bi);
printf("bi %p\n",bi);
*/
return ;
}
int print_tests(struct bootimage* bi )
{
printf("Running bootimage_print_header\n");
bootimage_print_header(bi);
printf("Running bootimage_print_kernel\n");
bootimage_print_kernel(bi);
printf("Running bootimage_print_kernel_version\n");
bootimage_print_kernel_version(bi);
return 0 ;
}
int extract_tests(struct bootimage* bi )
{
printf("Running bootimage_extract_uncompressed_kernel\n");
bootimage_extract_uncompressed_kernel(bi,NULL);
bootimage_extract_ramdisk(bi,NULL);
return 0 ;
}
int main(int argc ,char** argv)
{
//int ret = bootimage_file_print_header(argv[1]) ;
//if ( ret == -1 ){
// printf("bootimage_file_read failed err=%d\n",errno);
//}
char cwd[1024] = "out/out.rc";
//if (getcwd(cwd, sizeof(cwd)) != NULL)
// fprintf(stdout, "Current working dir: %s\n", cwd);
//else
// perror("getcwd() error");
char* dname = dirname(cwd);
printf("dirname=%s\n", dname);
struct bootimage* bi = NULL;
//printf("bi %p\n",bi);
bi = bootimage_initialize();
int ret = bootimage_file_read(bi,argv[1]);
//bootimage_extract_ramdisk_entry(bi,"init.rc","out.rc");
//bootimage_extract_ramdisk_entry(bi,"init.rc","out/out.rc");
printf("dirname=%s\n", dname);
bootimage_extract_ramdisk(bi,NULL);
//bootimage_extract_uncompressed_kernel(bi,NULL);
//bootimage_extract_kernel(bi,NULL);
//extract_tests(bi);
//print_tests(bi) ;
//printf("bi %p\n",bi);
//bootimage_extract_ramdisk(bi,NULL);
bootimage_free(&bi);
/*list_archive(argv[1]);*/
return 0 ;
}