-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathoptions.c
98 lines (86 loc) · 2.73 KB
/
options.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
/*
AXML Ambiguity
author: wanchouchou
Blog: http://www.cnblogs.com/wanyuanchun/
*/
#include "options.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
void usage() {
show_help();
printf("Parser an AXML:\n");
printf(" ./manifestAmbiguity -p filename;\n");
printf(" Or ./manifestAmbiguity --parser=filename\n");
printf("Modify an AXML:\n");
printf(" ./manifestAmbiguity -m target_filename -o output_filename;\n");
printf(" Or ./manifestAmbiguity --modify=target_filename --out=output_filename\n");
}
void show_version() {
printf("+++++++++++++++++++++++++\n");
printf("+ Learning And Sharing +\n");
printf("+ Version: %d +\n", MA_VERSION);
printf("+ From Wanchouchou ^-^! +\n");
printf("+++++++++++++++++++++++++\n");
}
void show_help() {
printf("\t----------------------------------------\n");
printf("\t|==== Android Manifest Ambiguity ==== |\n");
printf("\t----------------------------------------\n");
printf("manifestAmbiguity [options] file\n");
printf("-p, --parser=target_file parser axml and print it\n");
printf("-m, --modify=target_file modify axml. Up to now, we just provide a single function that inserting an useless attrbution in axml\n");
printf("-o, --out=output_file the file to store modified axml. If not defined , the default outfile is out.xml\n");
printf("-h, --help show help\n");
printf("-v, --version show version\n");
show_version();
}
struct options_t* handle_arguments(int argc, char* argv[]) {
static struct options_t opts; //必须static 不然就会在函数返回的时候被销毁~
memset(&opts, 0, sizeof(opts));
int opt;
int longidx;
if (argc == 1) {
return NULL;
}
const char* short_opts = "hp:m:o:v";
struct option long_opts[] = {
{"help", 0, NULL, 'h'},
{"parser", 1, NULL, 'p'},
{"modify", 1, NULL, 'm'},
{"out", 1, NULL, 'o'},
{"version", 0, NULL, 'v'},
{0, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, short_opts, long_opts, &longidx)) != -1) {
switch (opt) {
case 'h':
opts.help = 1;
break;
case 'p':
opts.parserXml = 1;
strncpy(opts.target_file, optarg, 128);
break;
case 'm':
opts.modifyXml = 1;
strncpy(opts.target_file, optarg, 128);
break;
case 'o':
strncpy(opts.output_file, optarg, 128);
break;
case 'v':
opts.version = 1;
break;
case '?':
//unknow options;
return NULL;
break;
default :
return NULL;
break;
}/* end switch */
}/* end while */
return &opts;
}