-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_dex.c
92 lines (62 loc) · 2.47 KB
/
import_dex.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
#include "import_dex.h"
void isLittleEndian(uint32_t fp){
uint32_t endian;
lseek(fp, 40, SEEK_SET);
read(fp, &endian, sizeof(uint32_t));
if(endian == ENDIAN_CONSTANT){
littleEndian = TRUE;
printf("little endian\n");
}
else if(endian == REVERSE_ENDIAN_CONSTANT){
littleEndian = FALSE;
printf("big endian\n");
}
else{
printf("not type\n");
}
}
uint32_t getHeaderSize(uint32_t fp){ // default: LittleEndian, have to make processing BigEndian
uint32_t header_size;
lseek(fp, 36, SEEK_SET);
read(fp, &header_size, sizeof(uint32_t));
// printf("%d\t\t\t\t\t\t\t header size(int)\n", header_size);
return header_size;
}
void header_slice(uint32_t fp, uint32_t header_size){
lseek(fp, 0, SEEK_SET);
read(fp, pHeader, sizeof(uint8_t)*header_size);
// print_header();
}
void print_header(){
printf("\n<Header>\n");
uint8_t *tmp = "";
for(size_t i = 0; i < 8; i++){
printf("%02x", (*pHeader).magic[i]);
}
printf("\t\t\t\t\t magic\n");
printf("%08x %-52s checksum\n", (*pHeader).checksum, tmp);
for(size_t i = 0; i < 20; i++){
printf("%02x", (*pHeader).signature[i]);
}
printf("\t\t signature\n");
printf("%08x %-52s file_size\n", (*pHeader).file_size, tmp);
printf("%08x %-52s header_size\n", (*pHeader).header_size, tmp);
printf("%08x %-52s endian_tag\n", (*pHeader).endian_tag, tmp);
printf("%08x %-52s link_size\n", (*pHeader).link_size, tmp);
printf("%08x %-52s link_off\n", (*pHeader).link_off, tmp);
printf("%08x %-52s map_off\n", (*pHeader).map_off, tmp);
printf("%08x %-52s string_ids_size\n", (*pHeader).string_ids_size, tmp);
printf("%08x %-52s string_ids_off\n", (*pHeader).string_ids_off, tmp);
printf("%08x %-52s type_ids_size\n", (*pHeader).type_ids_size, tmp);
printf("%08x %-52s type_ids_off\n", (*pHeader).type_ids_off, tmp);
printf("%08x %-52s proto_ids_size\n", (*pHeader).proto_ids_size, tmp);
printf("%08x %-52s proto_ids_off\n", (*pHeader).proto_ids_off, tmp);
printf("%08x %-52s field_ids_size\n", (*pHeader).field_ids_size, tmp);
printf("%08x %-52s field_ids_off\n", (*pHeader).field_ids_off, tmp);
printf("%08x %-52s method_ids_size\n", (*pHeader).method_ids_size, tmp);
printf("%08x %-52s method_ids_off\n", (*pHeader).method_ids_off, tmp);
printf("%08x %-52s class_defs_size\n", (*pHeader).class_defs_size, tmp);
printf("%08x %-52s class_defs_off\n", (*pHeader).class_defs_off, tmp);
printf("%08x %-52s data_size\n", (*pHeader).data_size, tmp);
printf("%08x %-52s data_off\n", (*pHeader).data_off, tmp);
}