├── test.xml ├── AxmlModify.c ├── AxmlParser.c ├── AxmlParser.h ├── README.md ├── options.h ├── makefile ├── AxmlModify.h ├── main.c └── options.c /test.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanchouchou/ManifestAmbiguity/HEAD/test.xml -------------------------------------------------------------------------------- /AxmlModify.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanchouchou/ManifestAmbiguity/HEAD/AxmlModify.c -------------------------------------------------------------------------------- /AxmlParser.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanchouchou/ManifestAmbiguity/HEAD/AxmlParser.c -------------------------------------------------------------------------------- /AxmlParser.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanchouchou/ManifestAmbiguity/HEAD/AxmlParser.h -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ManifestAmbiguity 2 | ================= 3 | 4 | Parser and Modify AndroidManifest.xml to prevent APK from re-packege 5 | 6 | 1 make, then get an executable file manifestAmbiguity. 7 | 8 | 9 | 2 ./manifestAmbiguity, then you will get complete information of this project. 10 | -------------------------------------------------------------------------------- /options.h: -------------------------------------------------------------------------------- 1 | #ifndef __OPTIONS_H__ 2 | #define __OPTIONS_H__ 3 | 4 | #define MA_VERSION 1 5 | struct options_t{ 6 | int parserXml; 7 | int modifyXml; 8 | int help; 9 | int version; 10 | char target_file[128]; 11 | char output_file[128]; 12 | }; 13 | 14 | 15 | struct options_t* handle_arguments(int argc, char* argv[]); 16 | void usage(); 17 | void show_help(); 18 | void show_version(); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | SOURCE=$(wildcard *.c *.cpp) 2 | OBJS=$(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(SOURCE))) 3 | CC=gcc 4 | XX=g++ 5 | CFLAGS=-Wall -O -g 6 | TARGET=manifestAmbiguity 7 | 8 | all: $(TARGET) 9 | 10 | %.o:%.c 11 | $(CC) $(CFLAGS) -c $< -o $@ 12 | 13 | %.o:%.cpp 14 | $(XX) $(CFLAGS) -c $< -o $@ 15 | 16 | $(TARGET): $(OBJS) 17 | $(CC) $(CFLAGS) $(OBJS) -o $(TARGET) 18 | 19 | 20 | clean: 21 | rm -rf *.o manifestAmbiguity 22 | -------------------------------------------------------------------------------- /AxmlModify.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: AxmlModify.h 3 | > Author: wanchouchou 4 | > Blog: Blog: http://www.cnblogs.com/wanyuanchun/ 5 | > Created Time: 11/08/2014 6 | ************************************************************************/ 7 | 8 | #ifndef AXMLMODIFY_H 9 | #define AXMLMODIFY_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | typedef struct{ 17 | char *data; 18 | uint32_t cur; 19 | }FileAssit_t; 20 | 21 | #ifdef __cplusplus 22 | #if __cplusplus 23 | extern "C"{ 24 | #endif // __cplusplus 25 | #endif // __cplusplus 26 | 27 | //axml modify functions 28 | void modifyStringChunk(FileAssit_t *in, FileAssit_t *out, size_t *externSize); 29 | void modifyAppTagChunk(FileAssit_t *in, FileAssit_t *out, size_t *externSize); 30 | int axmlModify(char* inbuf, size_t insize, char *out_filename); 31 | 32 | #ifdef __cplusplus 33 | #if __cplusplus 34 | } 35 | #endif // __cplusplus 36 | #endif // __cplusplus 37 | 38 | #endif // AXMLMODIFY_H 39 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > Project Name: ManifestAmbiguity 3 | > Author: wanchouchou 4 | > Blog: Blog: http://www.cnblogs.com/wanyuanchun/ 5 | > Created Time: 11/08/2014 6 | ************************************************************************/ 7 | #include "AxmlParser.h" 8 | #include "AxmlModify.h" 9 | #include "options.h" 10 | 11 | #ifdef _WIN32 /* windows */ 12 | #pragma warning(disable:4996) 13 | #endif 14 | 15 | /*Global vars. Used for AxmlModify*/ 16 | uint32_t g_styleDataOff = 0x0; 17 | uint32_t g_appTag_nameOff = 0x0; 18 | uint32_t g_curStringCount = 0x0; 19 | uint32_t g_appURIindex = 0x0; 20 | uint32_t g_res_ChunkSizeOffset = 0x0; 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | struct options_t *g_opts; 25 | FILE *fp; 26 | char *inbuf; 27 | size_t insize; 28 | char *outbuf; 29 | size_t outsize; 30 | int ret; 31 | const char *target_filename; 32 | /* 处理命令行 */ 33 | g_opts = handle_arguments(argc, argv); 34 | if (!g_opts) { 35 | /* 失败 */ 36 | usage(); 37 | return -1; 38 | } 39 | 40 | /* 处理命令行 */ 41 | if (g_opts->help) { 42 | show_help(); 43 | return 0; 44 | } 45 | if (g_opts->version) { 46 | show_version(); 47 | return 0; 48 | } 49 | 50 | target_filename = g_opts->target_file; 51 | fp = fopen(target_filename, "rb"); 52 | if(fp == NULL) 53 | { 54 | fprintf(stderr, "Error: open input file failed.\n"); 55 | return -1; 56 | } 57 | 58 | fseek(fp, 0, SEEK_END); 59 | insize = ftell(fp); 60 | fseek(fp, 0, SEEK_SET); 61 | 62 | inbuf = (char *)malloc(insize * sizeof(char)); 63 | if(inbuf == NULL) 64 | { 65 | fprintf(stderr, "Error: init file buffer.\n"); 66 | fclose(fp); 67 | return -1; 68 | } 69 | 70 | ret = fread(inbuf, 1, insize, fp); 71 | if(ret != insize) 72 | { 73 | fprintf(stderr, "Error: read file.\n"); 74 | free(inbuf); 75 | fclose(fp); 76 | return -1; 77 | } 78 | //无论是读取还是修改xml都需要先分析目标xml 79 | ret = AxmlToXml(&outbuf, &outsize, inbuf, insize); 80 | if(ret < 0){ 81 | fprintf(stderr, "Error: parse file.\n"); 82 | return -1; 83 | } 84 | if(g_opts->parserXml){ 85 | printf("%s", outbuf); 86 | return 0; 87 | } 88 | if(g_opts->modifyXml){ 89 | ret = axmlModify(inbuf, insize, g_opts->output_file); 90 | if(ret < 0){ 91 | fprintf(stderr, "Error: modify file.\n"); 92 | return -1; 93 | } 94 | } 95 | free(outbuf); 96 | free(inbuf); 97 | fclose(fp); 98 | 99 | return ret; 100 | } 101 | -------------------------------------------------------------------------------- /options.c: -------------------------------------------------------------------------------- 1 | /* 2 | AXML Ambiguity 3 | author: wanchouchou 4 | Blog: http://www.cnblogs.com/wanyuanchun/ 5 | */ 6 | 7 | #include "options.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | void usage() { 15 | show_help(); 16 | printf("Parser an AXML:\n"); 17 | printf(" ./manifestAmbiguity -p filename;\n"); 18 | printf(" Or ./manifestAmbiguity --parser=filename\n"); 19 | printf("Modify an AXML:\n"); 20 | printf(" ./manifestAmbiguity -m target_filename -o output_filename;\n"); 21 | printf(" Or ./manifestAmbiguity --modify=target_filename --out=output_filename\n"); 22 | } 23 | 24 | void show_version() { 25 | printf("+++++++++++++++++++++++++\n"); 26 | printf("+ Learning And Sharing +\n"); 27 | printf("+ Version: %d +\n", MA_VERSION); 28 | printf("+ From Wanchouchou ^-^! +\n"); 29 | printf("+++++++++++++++++++++++++\n"); 30 | } 31 | 32 | void show_help() { 33 | printf("\t----------------------------------------\n"); 34 | printf("\t|==== Android Manifest Ambiguity ==== |\n"); 35 | printf("\t----------------------------------------\n"); 36 | printf("manifestAmbiguity [options] file\n"); 37 | printf("-p, --parser=target_file parser axml and print it\n"); 38 | printf("-m, --modify=target_file modify axml. Up to now, we just provide a single function that inserting an useless attrbution in axml\n"); 39 | printf("-o, --out=output_file the file to store modified axml. If not defined , the default outfile is out.xml\n"); 40 | printf("-h, --help show help\n"); 41 | printf("-v, --version show version\n"); 42 | show_version(); 43 | } 44 | 45 | struct options_t* handle_arguments(int argc, char* argv[]) { 46 | static struct options_t opts; //必须static 不然就会在函数返回的时候被销毁~ 47 | memset(&opts, 0, sizeof(opts)); 48 | 49 | int opt; 50 | int longidx; 51 | if (argc == 1) { 52 | return NULL; 53 | } 54 | 55 | const char* short_opts = "hp:m:o:v"; 56 | struct option long_opts[] = { 57 | {"help", 0, NULL, 'h'}, 58 | {"parser", 1, NULL, 'p'}, 59 | {"modify", 1, NULL, 'm'}, 60 | {"out", 1, NULL, 'o'}, 61 | {"version", 0, NULL, 'v'}, 62 | {0, 0, 0, 0} 63 | }; 64 | 65 | while ((opt = getopt_long(argc, argv, short_opts, long_opts, &longidx)) != -1) { 66 | switch (opt) { 67 | case 'h': 68 | opts.help = 1; 69 | break; 70 | case 'p': 71 | opts.parserXml = 1; 72 | strncpy(opts.target_file, optarg, 128); 73 | break; 74 | case 'm': 75 | opts.modifyXml = 1; 76 | strncpy(opts.target_file, optarg, 128); 77 | break; 78 | case 'o': 79 | strncpy(opts.output_file, optarg, 128); 80 | break; 81 | case 'v': 82 | opts.version = 1; 83 | break; 84 | case '?': 85 | //unknow options; 86 | return NULL; 87 | break; 88 | default : 89 | return NULL; 90 | break; 91 | }/* end switch */ 92 | }/* end while */ 93 | 94 | return &opts; 95 | } 96 | 97 | 98 | 99 | --------------------------------------------------------------------------------