找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 5159|回复: 2

编译后的AndroidManifest.xml查看及修改源码

[复制链接]

307

主题

228

回帖

7343

积分

用户组: 真·技术宅

UID
2
精华
76
威望
291 点
宅币
5593 个
贡献
253 次
宅之契约
0 份
在线时间
948 小时
注册时间
2014-1-25
发表于 2016-3-29 17:51:27 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×


编译后的AndroidManifest.xml查看及修改源码

还在编写中,用于在无需其他文件的情况下,单独修改编译后的二进制AndroidManifest.xml文件,目前应该是全网首创吧


  1. #pragma once

  2. typedef unsigned char uint8_t;
  3. typedef unsigned short uint16_t;
  4. typedef unsigned long uint32_t;

  5. #include <vector>
  6. #include <stack>
  7. #include <string>
  8. using namespace std;

  9. enum {
  10.         RES_NULL_TYPE = 0x0000,
  11.         RES_STRING_POOL_TYPE = 0x0001,
  12.         RES_TABLE_TYPE = 0x0002,
  13.         RES_XML_TYPE = 0x0003,

  14.         // Chunk types in RES_XML_TYPE
  15.         RES_XML_FIRST_CHUNK_TYPE = 0x0100,
  16.         RES_XML_START_NAMESPACE_TYPE = 0x0100,
  17.         RES_XML_END_NAMESPACE_TYPE = 0x0101,
  18.         RES_XML_START_ELEMENT_TYPE = 0x0102,
  19.         RES_XML_END_ELEMENT_TYPE = 0x0103,
  20.         RES_XML_CDATA_TYPE = 0x0104,
  21.         RES_XML_LAST_CHUNK_TYPE = 0x017f,
  22.         // This contains a uint32_t array mapping strings in the string
  23.         // pool back to resource identifiers.  It is optional.
  24.         RES_XML_RESOURCE_MAP_TYPE = 0x0180,

  25.         // Chunk types in RES_TABLE_TYPE
  26.         RES_TABLE_PACKAGE_TYPE = 0x0200,
  27.         RES_TABLE_TYPE_TYPE = 0x0201,
  28.         RES_TABLE_TYPE_SPEC_TYPE = 0x0202
  29. };

  30. struct Res_value
  31. {
  32.         // Number of bytes in this structure.
  33.         uint16_t size;

  34.         // Always set to 0.
  35.         uint8_t res0;

  36.         // Type of the data value.
  37.         enum {
  38.                 // The 'data' is either 0 or 1, specifying this resource is either
  39.                 // undefined or empty, respectively.
  40.                 TYPE_NULL = 0x00,
  41.                 // The 'data' holds a ResTable_ref, a reference to another resource
  42.                 // table entry.
  43.                 TYPE_REFERENCE = 0x01,
  44.                 // The 'data' holds an attribute resource identifier.
  45.                 TYPE_ATTRIBUTE = 0x02,
  46.                 // The 'data' holds an index into the containing resource table's
  47.                 // global value string pool.
  48.                 TYPE_STRING = 0x03,
  49.                 // The 'data' holds a single-precision floating point number.
  50.                 TYPE_FLOAT = 0x04,
  51.                 // The 'data' holds a complex number encoding a dimension value,
  52.                 // such as "100in".
  53.                 TYPE_DIMENSION = 0x05,
  54.                 // The 'data' holds a complex number encoding a fraction of a
  55.                 // container.
  56.                 TYPE_FRACTION = 0x06,
  57.                 // The 'data' holds a dynamic ResTable_ref, which needs to be
  58.                 // resolved before it can be used like a TYPE_REFERENCE.
  59.                 TYPE_DYNAMIC_REFERENCE = 0x07,

  60.                 // Beginning of integer flavors...
  61.                 TYPE_FIRST_INT = 0x10,

  62.                 // The 'data' is a raw integer value of the form n..n.
  63.                 TYPE_INT_DEC = 0x10,
  64.                 // The 'data' is a raw integer value of the form 0xn..n.
  65.                 TYPE_INT_HEX = 0x11,
  66.                 // The 'data' is either 0 or 1, for input "false" or "true" respectively.
  67.                 TYPE_INT_BOOLEAN = 0x12,

  68.                 // Beginning of color integer flavors...
  69.                 TYPE_FIRST_COLOR_INT = 0x1c,

  70.                 // The 'data' is a raw integer value of the form #aarrggbb.
  71.                 TYPE_INT_COLOR_ARGB8 = 0x1c,
  72.                 // The 'data' is a raw integer value of the form #rrggbb.
  73.                 TYPE_INT_COLOR_RGB8 = 0x1d,
  74.                 // The 'data' is a raw integer value of the form #argb.
  75.                 TYPE_INT_COLOR_ARGB4 = 0x1e,
  76.                 // The 'data' is a raw integer value of the form #rgb.
  77.                 TYPE_INT_COLOR_RGB4 = 0x1f,

  78.                 // ...end of integer flavors.
  79.                 TYPE_LAST_COLOR_INT = 0x1f,

  80.                 // ...end of integer flavors.
  81.                 TYPE_LAST_INT = 0x1f
  82.         };
  83.         uint8_t dataType;

  84.         // Structure of complex data values (TYPE_UNIT and TYPE_FRACTION)
  85.         enum {
  86.                 // Where the unit type information is.  This gives us 16 possible
  87.                 // types, as defined below.
  88.                 COMPLEX_UNIT_SHIFT = 0,
  89.                 COMPLEX_UNIT_MASK = 0xf,

  90.                 // TYPE_DIMENSION: Value is raw pixels.
  91.                 COMPLEX_UNIT_PX = 0,
  92.                 // TYPE_DIMENSION: Value is Device Independent Pixels.
  93.                 COMPLEX_UNIT_DIP = 1,
  94.                 // TYPE_DIMENSION: Value is a Scaled device independent Pixels.
  95.                 COMPLEX_UNIT_SP = 2,
  96.                 // TYPE_DIMENSION: Value is in points.
  97.                 COMPLEX_UNIT_PT = 3,
  98.                 // TYPE_DIMENSION: Value is in inches.
  99.                 COMPLEX_UNIT_IN = 4,
  100.                 // TYPE_DIMENSION: Value is in millimeters.
  101.                 COMPLEX_UNIT_MM = 5,

  102.                 // TYPE_FRACTION: A basic fraction of the overall size.
  103.                 COMPLEX_UNIT_FRACTION = 0,
  104.                 // TYPE_FRACTION: A fraction of the parent size.
  105.                 COMPLEX_UNIT_FRACTION_PARENT = 1,

  106.                 // Where the radix information is, telling where the decimal place
  107.                 // appears in the mantissa.  This give us 4 possible fixed point
  108.                 // representations as defined below.
  109.                 COMPLEX_RADIX_SHIFT = 4,
  110.                 COMPLEX_RADIX_MASK = 0x3,

  111.                 // The mantissa is an integral number -- i.e., 0xnnnnnn.0
  112.                 COMPLEX_RADIX_23p0 = 0,
  113.                 // The mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn
  114.                 COMPLEX_RADIX_16p7 = 1,
  115.                 // The mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn
  116.                 COMPLEX_RADIX_8p15 = 2,
  117.                 // The mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn
  118.                 COMPLEX_RADIX_0p23 = 3,

  119.                 // Where the actual value is.  This gives us 23 bits of
  120.                 // precision.  The top bit is the sign.
  121.                 COMPLEX_MANTISSA_SHIFT = 8,
  122.                 COMPLEX_MANTISSA_MASK = 0xffffff
  123.         };

  124.         // Possible data values for TYPE_NULL.
  125.         enum {
  126.                 // The value is not defined.
  127.                 DATA_NULL_UNDEFINED = 0,
  128.                 // The value is explicitly defined as empty.
  129.                 DATA_NULL_EMPTY = 1
  130.         };

  131.         // The data for this item, as interpreted according to dataType.
  132.         typedef uint32_t data_type;
  133.         data_type data;

  134. };

  135. struct ResChunk_header
  136. {
  137.         // Type identifier for this chunk.  The meaning of this value depends
  138.         // on the containing chunk.
  139.         uint16_t type;

  140.         // Size of the chunk header (in bytes).  Adding this value to
  141.         // the address of the chunk allows you to find its associated data
  142.         // (if any).
  143.         uint16_t headerSize;

  144.         // Total size of this chunk (in bytes).  This is the chunkSize plus
  145.         // the size of any data associated with the chunk.  Adding this value
  146.         // to the chunk allows you to completely skip its contents (including
  147.         // any child chunks).  If this value is the same as chunkSize, there is
  148.         // no data associated with the chunk.
  149.         uint32_t size;
  150. };

  151. struct ResStringPool_header
  152. {
  153.         struct ResChunk_header header;

  154.         // Number of strings in this pool (number of uint32_t indices that follow
  155.         // in the data).
  156.         uint32_t stringCount;

  157.         // Number of style span arrays in the pool (number of uint32_t indices
  158.         // follow the string indices).
  159.         uint32_t styleCount;

  160.         // Flags.
  161.         enum {
  162.                 // If set, the string index is sorted by the string values (based
  163.                 // on strcmp16()).
  164.                 SORTED_FLAG = 1<<0,

  165.                 // String pool is encoded in UTF-8
  166.                 UTF8_FLAG = 1<<8
  167.         };
  168.         uint32_t flags;

  169.         // Index from header of the string data.
  170.         uint32_t stringsStart;

  171.         // Index from header of the style data.
  172.         uint32_t stylesStart;
  173. };

  174. /**
  175. * Reference to a string in a string pool.
  176. */
  177. struct ResStringPool_ref
  178. {
  179.     // Index into the string pool table (uint32_t-offset from the indices
  180.     // immediately after ResStringPool_header) at which to find the location
  181.     // of the string data in the pool.
  182.     uint32_t index;
  183. };

  184. /**
  185. * Extended XML tree node for namespace start/end nodes.
  186. * Appears header.headerSize bytes after a ResXMLTree_node.
  187. */
  188. struct ResXMLTree_namespaceExt
  189. {
  190.     // The prefix of the namespace.
  191.     struct ResStringPool_ref prefix;
  192.    
  193.     // The URI of the namespace.
  194.     struct ResStringPool_ref uri;
  195. };

  196. /**
  197. * Extended XML tree node for element start/end nodes.
  198. * Appears header.headerSize bytes after a ResXMLTree_node.
  199. */
  200. struct ResXMLTree_endElementExt
  201. {
  202.     // String of the full namespace of this element.
  203.     struct ResStringPool_ref ns;
  204.    
  205.     // String name of this node if it is an ELEMENT; the raw
  206.     // character data if this is a CDATA node.
  207.     struct ResStringPool_ref name;
  208. };

  209. /**
  210. * Extended XML tree node for element start/end nodes.
  211. * Appears header.headerSize bytes after a ResXMLTree_node.
  212. */
  213. struct ResXMLTree_endElementExt
  214. {
  215.     // String of the full namespace of this element.
  216.     struct ResStringPool_ref ns;
  217.    
  218.     // String name of this node if it is an ELEMENT; the raw
  219.     // character data if this is a CDATA node.
  220.     struct ResStringPool_ref name;
  221. };

  222. /**
  223. * Extended XML tree node for start tags -- includes attribute
  224. * information.
  225. * Appears header.headerSize bytes after a ResXMLTree_node.
  226. */
  227. struct ResXMLTree_attrExt
  228. {
  229.     // String of the full namespace of this element.
  230.     struct ResStringPool_ref ns;
  231.    
  232.     // String name of this node if it is an ELEMENT; the raw
  233.     // character data if this is a CDATA node.
  234.     struct ResStringPool_ref name;
  235.    
  236.     // Byte offset from the start of this structure where the attributes start.
  237.     uint16_t attributeStart;
  238.    
  239.     // Size of the ResXMLTree_attribute structures that follow.
  240.     uint16_t attributeSize;
  241.    
  242.     // Number of attributes associated with an ELEMENT.  These are
  243.     // available as an array of ResXMLTree_attribute structures
  244.     // immediately following this node.
  245.     uint16_t attributeCount;
  246.    
  247.     // Index (1-based) of the "id" attribute. 0 if none.
  248.     uint16_t idIndex;
  249.    
  250.     // Index (1-based) of the "class" attribute. 0 if none.
  251.     uint16_t classIndex;
  252.    
  253.     // Index (1-based) of the "style" attribute. 0 if none.
  254.     uint16_t styleIndex;
  255. };

  256. struct ResXMLTree_attribute
  257. {
  258.     // Namespace of this attribute.
  259.     struct ResStringPool_ref ns;
  260.    
  261.     // Name of this attribute.
  262.     struct ResStringPool_ref name;

  263.     // The original raw string value of this attribute.
  264.     struct ResStringPool_ref rawValue;
  265.    
  266.     // Processesd typed value of this attribute.
  267.     struct Res_value typedValue;
  268. };

  269. //RES_STRING_POOL_TYPE
  270. class ResStringPool
  271. {
  272. public:
  273.         struct ResStringPool_header header;
  274.         std::vector<int> stringOffsets;
  275.         std::vector<int> styleOffsets;
  276.         std::vector<unsigned char> stringData;
  277.         std::vector<unsigned char> styleData;
  278.         void setTo(unsigned char* nodeData)
  279.         {
  280.                 header = *(struct ResStringPool_header*)nodeData;
  281.                 int i=0;
  282.                 unsigned char* offset;
  283.                
  284.                 offset = nodeData + sizeof(struct ResStringPool_header);
  285.                 for(i=0;i<header.stringCount;i++)
  286.                 {
  287.                         stringOffsets.push_back(*(int*)offset);
  288.                         offset += 4;
  289.                 }
  290.                 for(i=0;i<header.styleCount;i++)
  291.                 {
  292.                         styleOffsets.push_back(*(int*)offset);
  293.                         offset += 4;
  294.                 }

  295.                 if(header.stringCount == 0 && header.styleCount != 0)
  296.                 {
  297.                         styleData.resize(header.header.size - header.stylesStart);
  298.                         styleData.assign(nodeData + header.stylesStart,nodeData + header.header.size);
  299.                 }
  300.                 else if(header.stringCount != 0 && header.styleCount == 0)
  301.                 {
  302.                         stringData.resize(header.header.size - header.stringsStart);
  303.                         stringData.assign(nodeData + header.stringsStart,nodeData + header.header.size);
  304.                 }
  305.                 else if(header.stringCount != 0 && header.styleCount != 0)
  306.                 {
  307.                         if(header.stringsStart < header.stylesStart)
  308.                         {//stringsStart < stylesStart < end
  309.                                 stringData.assign(header.stylesStart - header.stringsStart);
  310.                                 styleData.assign(header.header.size - header.stylesStart);
  311.                                 stringData.assign(nodeData + header.stringsStart, nodeData + header.stylesStart);
  312.                                 styleData.assign(nodeData + header.stylesStart, nodeData + header.header.size);
  313.                         }
  314.                         else
  315.                         {//stylesStart < stringsStart < end
  316.                                 stringData.assign(header.stringsStart - header.stylesStart);
  317.                                 styleData.assign(header.header.size - header.stringsStart);
  318.                                 styleData.assign(nodeData + header.stylesStart, nodeData + header.stringsStart);
  319.                                 stringData.assign(nodeData + header.stringsStart, nodeData + header.header.size);       
  320.                         }
  321.                 }
  322.         }

  323.         void serialize(unsigned char* nodeData, int& size)
  324.         {//调整参数使结构都是紧密排列的
  325.                 header.stringsStart = sizeof(struct ResStringPool_header) + stringOffsets.size()*4 + styleOffsets.size()*4;
  326.                 header.stylesStart = sizeof(struct ResStringPool_header) + stringOffsets.size()*4 + styleOffsets.size()*4 + stringData.size();
  327.                 int realsize = getSize();
  328.                 if(size < realsize)
  329.                         size=0;
  330.                 size = realsize;
  331.                 int offset = 0;
  332.                 memcpy(nodeData + offset, &header, sizeof(struct ResStringPool_header));
  333.                 offset += sizeof(struct ResStringPool_header);
  334.                 memcpy(nodeData + offset, &stringOffsets[0], stringOffsets.size()*4);
  335.                 offset += stringOffsets.size()*4;
  336.                 memcpy(nodeData + offset, &styleOffsets[0], styleOffsets.size()*4);
  337.                 offset += styleOffsets.size()*4;
  338.                 memcpy(nodeData + offset, &stringData[0],stringData.size());
  339.                 offset += stringData.size();
  340.                 memcpy(nodeData + offset, &styleData[0],styleData.size());
  341.                 offset += styleData.size();
  342.         }

  343.         int getSize()
  344.         {
  345.                 return sizeof(struct ResStringPool_header) + stringOffsets.size()*4 + styleOffsets.size()*4 + stringData.size() + styleData.size();
  346.         }

  347.         void print()
  348.         {
  349.                 wprintf(L"StringPool:");
  350.                 for(int i=0;i<header.stringCount;i++)
  351.                 {
  352.                         wprintf("%d:%s\n",(wchar_t*)(&stringData[0] + stringOffsets[i] + 2));
  353.                 }
  354.         }

  355.         wchar_t* getItem(int index)
  356.         {
  357.                 wchar_t* str = L"";
  358.                 if(index >= 0 && index < header.stringCount)
  359.                 {
  360.                         str= (wchar_t*)(&stringData[0] + stringOffsets[index] + 2);
  361.                 }
  362.                 return str;
  363.         }
  364. };

  365. class ResXmlResourceMap
  366. {
  367. public:
  368.         struct ResChunk_header header;
  369.         std::vector<int> mapType;
  370.         void setTo(unsigned char* nodeData)
  371.         {
  372.                 header = *(struct ResStringPool_header*)nodeData;
  373.                 for(int i=header.headerSize;i<header.size;i+=4)
  374.                 {
  375.                         mapType.push_back(*(int*)(nodeData + i));
  376.                 }
  377.         }
  378.         void serialize(unsigned char* nodeData, int& size)
  379.         {
  380.                 int realsize = getSize();
  381.                 if(size < realsize)
  382.                         size=0;
  383.                 size=realsize;
  384.                 int offset = 0;
  385.                 memcpy(nodeData + offset, &header, sizeof(ResChunk_header));
  386.                 offset += sizeof(ResChunk_header);
  387.                 memcpy(nodeData +offset, &mapType[0], mapType.size()*4);
  388.                 offset += mapType.size()*4;
  389.         }

  390.         int getSize()
  391.         {
  392.                 return sizeof(struct ResChunk_header) + mapType.size()*4;
  393.         }

  394.         void print()
  395.         {
  396.                 wprintf(L"ResourceMap:");
  397.                 for(int i=0;i<mapType.size();i++)
  398.                 {
  399.                         wprintf(L"%d:%08x\n",i,mapType[i]);
  400.                 }
  401.         }

  402.         int getItem(int index)
  403.         {
  404.                 int ret = 0;
  405.                 if(index >= 0 && index < mapType.size())
  406.                 {
  407.                         ret= mapType[index];
  408.                 }
  409.                 return ret;
  410.         }
  411. };


  412. class ResXmlTreeNode:public ResChunk_header
  413. {
  414. public:
  415.         int layer;//通过层号得到树形关系
  416.         struct ResXmlTreeNode* father;//知道是谁的孩子
  417.         std::wstring nodeName;
  418.         virtual void setTo(unsigned char* nodeData, ResXmlTreeNode* _father, int _layer){};
  419.         virtual void print(){};
  420.         virtual int getSize(){return sizeof(ResChunk_header)};
  421.         virtual void serialize(unsigned char* nodeData, int& size){};
  422. };

  423. //RES_XML_START_NAMESPACE_TYPE/RES_XML_END_NAMESPACE_TYPE
  424. class ResXmlNamespace:public ResXmlTreeNode
  425. {
  426. public:
  427.         ResXMLTree_namespaceExt ext;
  428.         std::vector<unsigned char> headerData;

  429.         ResXmlNamespace(unsigned char* nodeData, ResXmlTreeNode* _father, int _layer)
  430.         {
  431.                 setTo(nodeData,_father,_layer);
  432.         }

  433.         void setTo(unsigned char* nodeData, ResXmlTreeNode* _father, int _layer)
  434.         {
  435.                 this->father = _father;
  436.                 this->layer = _layer;
  437.                 this->type = ((ResChunk_header*)nodeData)->type;
  438.                 this->headerSize = ((ResChunk_header*)nodeData)->headerSize;
  439.                 this->size = ((ResChunk_header*)nodeData)->size;
  440.                 this->ext = *(ResXMLTree_namespaceExt*)(nodeData + this->headerSize);
  441.                 headerData.resize(headerSize - sizeof(ResChunk_header));
  442.                 headerData.assign(nodeData + sizeof(ResChunk_header), nodeData + this->headerSize);
  443.         }

  444.         virtual void serialize(unsigned char* nodeData, int& size)
  445.         {
  446.                 int realsize = getSize();
  447.                 if(size < realsize)
  448.                         return;
  449.                 size = realsize;
  450.                 ResChunk_header header = {this->type,this->headerSize,this->size};
  451.                 int offset = 0;
  452.                 memcpy(nodeData + offset, &header, sizeof(ResChunk_header));
  453.                 offset += sizeof(ResChunk_header);
  454.                 memcpy(nodeData + offset, &headerData[0], headerData.size());
  455.                 offset += headerData.size();
  456.                 memcpy(nodeData + offset, &ext, sizeof(ResXMLTree_namespaceExt));
  457.                 offset += sizeof(sizeof(ResXMLTree_namespaceExt));
  458.         }

  459.         virtual int getSize()
  460.         {
  461.                 return sizeof(ResChunk_header) + sizeof(ResXMLTree_namespaceExt) + headerData.size();
  462.         }

  463.         virtual void print(ResStringPool& stringPool)
  464.         {
  465.                 for(int i=0;i<layer+1;i++)
  466.                 {
  467.                         wprintf(L" ");
  468.                 }
  469.                 if(type == RES_XML_START_NAMESPACE_TYPE)
  470.                 {
  471.                         wprintf(L"Start Namespace %s %s\n", stringPool.getItem(ext.prefix.index), stringPool.getItem(ext.uri.index));
  472.                 }
  473.                 else if(type == RES_XML_END_NAMESPACE_TYPE)
  474.                 {
  475.                         wprintf(L"End Namespace %s %s\n", stringPool.getItem(ext.prefix.index), stringPool.getItem(ext.uri.index));
  476.                 }
  477.         }
  478. };

  479. class ResXmlStartElement:public ResXmlTreeNode
  480. {
  481.         ResXMLTree_attrExt ext;
  482.         std::vector<unsigned char> headerData;
  483.         std::vector<struct ResXMLTree_attribute> attribs;

  484.         ResXmlStartElement(unsigned char* nodeData, ResXmlTreeNode* _father, int _layer)
  485.         {
  486.                 setTo(nodeData,_father,_layer);
  487.         }

  488.         virtual void setTo(unsigned char* nodeData, ResXmlTreeNode* _father, int _layer)
  489.         {
  490.                 this->father = _father;
  491.                 this->layer = _layer;
  492.                 this->type = ((ResChunk_header*)nodeData)->type;
  493.                 this->headerSize = ((ResChunk_header*)nodeData)->headerSize;
  494.                 this->size = ((ResChunk_header*)nodeData)->size;
  495.                 this->ext = *(ResXMLTree_attrExt*)(nodeData + this->headerSize);
  496.                 headerData.resize(headerSize - sizeof(ResChunk_header));
  497.                 headerData.assign(nodeData + sizeof(ResChunk_header), nodeData + this->headerSize);
  498.                 attribs.resize(this->ext.attributeCount);
  499.                 attribs.assign(*(ResXMLTree_attribute*)(nodeData + this->headerSize + this->ext.attributeStart),
  500.                         *(ResXMLTree_attribute*)(nodeData + this->headerSize + this->ext.attributeStart + sizeof(struct ResXMLTree_attribute) * this->ext.attributeCount));
  501.         }

  502.         virtual void print(ResStringPool& stringPool)
  503.         {

  504.                 for(int i=0;i<attribs.size();i++)
  505.                 {
  506.                         for(int i=0;i<layer+1;i++)
  507.                         {
  508.                                 wprintf(L" ");
  509.                         }
  510.                         wprintf(L"A:%s %s %s %02x\n", stringPool.getItem(attribs[i].ns.index), stringPool.getItem(attribs[i].name.index),
  511.                                 stringPool.getItem(attribs[i].rawValue.index), attribs[i].typedValue.dataType);
  512.                 }
  513.         }

  514.         virtual int getSize()
  515.         {
  516.                 return sizeof(ResChunk_header) + headerData.size() + attribs.size() * sizeof(ResXMLTree_attribute);
  517.         }

  518.         virtual void serialize(unsigned char* nodeData, int& size)
  519.         {
  520.                 int realsize = getSize();
  521.                 if(size < realsize)
  522.                         return;
  523.                 size = realsize;
  524.                 ResChunk_header header = {this->type,this->headerSize,this->size};
  525.                 int offset = 0;
  526.                 memcpy(nodeData + offset, &header, sizeof(ResChunk_header));
  527.                 offset += sizeof(ResChunk_header);
  528.                 memcpy(nodeData + offset, &headerData[0], headerData.size());
  529.                 offset += headerData.size();
  530.                 memcpy(nodeData + offset, &attribs[0], sizeof(ResXMLTree_attribute) * attribs.size());
  531.                 offset += sizeof(ResXMLTree_attribute) * attribs.size();
  532.         }
  533. };

  534. class ResXmlEndElement:public ResXmlTreeNode
  535. {
  536. public:
  537.         ResXMLTree_endElementExt ext;
  538.         std::vector<unsigned char> headerData;

  539.         ResXmlEndElement(unsigned char* nodeData, ResXmlTreeNode* _father, int _layer)
  540.         {
  541.                 setTo(nodeData,_father,_layer);
  542.         }

  543.         void setTo(unsigned char* nodeData, ResXmlTreeNode* _father, int _layer)
  544.         {
  545.                 this->father = _father;
  546.                 this->layer = _layer;
  547.                 this->type = ((ResChunk_header*)nodeData)->type;
  548.                 this->headerSize = ((ResChunk_header*)nodeData)->headerSize;
  549.                 this->size = ((ResChunk_header*)nodeData)->size;
  550.                 this->ext = *(ResXMLTree_endElementExt*)(nodeData + this->headerSize);
  551.                 headerData.resize(headerSize - sizeof(ResChunk_header));
  552.                 headerData.assign(nodeData + sizeof(ResChunk_header), nodeData + this->headerSize);
  553.         }

  554.         virtual void serialize(unsigned char* nodeData, int& size)
  555.         {
  556.                 int realsize = getSize();
  557.                 if(size < realsize)
  558.                         return;
  559.                 size = realsize;
  560.                 ResChunk_header header = {this->type,this->headerSize,this->size};
  561.                 int offset = 0;
  562.                 memcpy(nodeData + offset, &header, sizeof(ResChunk_header));
  563.                 offset += sizeof(ResChunk_header);
  564.                 memcpy(nodeData + offset, &headerData[0], headerData.size());
  565.                 offset += headerData.size();
  566.                 memcpy(nodeData + offset, &ext, sizeof(ResXMLTree_endElementExt));
  567.                 offset += sizeof(sizeof(ResXMLTree_endElementExt));
  568.         }

  569.         virtual int getSize()
  570.         {
  571.                 return sizeof(ResChunk_header) + sizeof(ResXMLTree_endElementExt) + headerData.size();
  572.         }

  573.         virtual void print(ResStringPool& stringPool)
  574.         {
  575.                 for(int i=0;i<layer+1;i++)
  576.                 {
  577.                         wprintf(L" ");
  578.                 }
  579.                 if(type == RES_XML_START_NAMESPACE_TYPE)
  580.                 {
  581.                         wprintf(L"Start Namespace %s %s\n", stringPool.getItem(ext.name.index), stringPool.getItem(ext.ns.index));
  582.                 }
  583.                 else if(type == RES_XML_END_NAMESPACE_TYPE)
  584.                 {
  585.                         wprintf(L"End Namespace %s %s\n", stringPool.getItem(ext.name.index), stringPool.getItem(ext.ns.index));
  586.                 }
  587.         }
  588. };


  589. class ResXml
  590. {
  591.         ResChunk_header header;
  592.         class ResStringPool stringPool;
  593.         class ResXmlResourceMap resourceMap;
  594.         std::vector<std::auto_ptr<class ResXmlTreeNode>> elements;
  595.         std::stack<class ResXmlTreeNode*> topstack;

  596.         void setTo(unsigned char* nodeData)
  597.         {
  598.                 if(((ResChunk_header*)nodeData)->type == RES_XML_TYPE)//类型匹配
  599.                 {
  600.                         header = *(ResChunk_header*)nodeData;
  601.                         ResChunk_header* begin = (ResChunk_header*)(nodeData + header.headerSize);
  602.                         ResChunk_header* end = (ResChunk_header*)(nodeData + header.size);
  603.                         int depth = 0;
  604.                         while(begin < end)
  605.                         {
  606.                                 switch(begin->type)
  607.                                 {
  608.                                 case RES_STRING_POOL_TYPE:
  609.                                         {
  610.                                                 depth = 0;
  611.                                                 stringPool.setTo((unsigned char*)begin);
  612.                                         }
  613.                                         break;

  614.                                 case RES_XML_RESOURCE_MAP_TYPE:
  615.                                         {
  616.                                                 depth = 0;
  617.                                                 resourceMap.setTo((unsigned char*)begin);
  618.                                         }
  619.                                         break;

  620.                                 case RES_XML_START_NAMESPACE_TYPE:
  621.                                         {
  622.                                                 depth = 0;
  623.                                                 ResXmlTreeNode* node = new ResXmlNamespace((unsigned char*)begin, NULL, depth);
  624.                                                 elements.push_back(node);
  625.                                                 topstack.push(node);
  626.                                         }
  627.                                         break;

  628.                                 case RES_XML_END_NAMESPACE_TYPE:
  629.                                         {
  630.                                                 depth = 0;
  631.                                                 topstack.pop();
  632.                                                 ResXmlTreeNode* node = new ResXmlNamespace((unsigned char*)begin, NULL, depth);
  633.                                                 elements.push_back(node);
  634.                                         }
  635.                                         break;

  636.                                 case RES_XML_START_ELEMENT_TYPE:
  637.                                         {
  638.                                                 depth++;
  639.                                                 ResXmlTreeNode* node = new ResXmlNamespace((unsigned char*)begin, topstack.top(), depth);
  640.                                                 elements.push_back(node);
  641.                                                 topstack.push(node);
  642.                                         }
  643.                                         break;

  644.                                 case RES_XML_END_ELEMENT_TYPE:
  645.                                         {
  646.                                                 depth--;
  647.                                                 topstack.pop();
  648.                                                 ResXmlTreeNode* node = new ResXmlNamespace((unsigned char*)begin, topstack.top(), depth);
  649.                                                 elements.push_back(node);       
  650.                                         }
  651.                                         break;
  652.                                 default:
  653.                                         //unknown
  654.                                         break;
  655.                                 }
  656.                                 begin = (ResChunk_header*)((unsigned char*)begin + begin->size);
  657.                         }
  658.                 }       
  659.         }

  660.         void serialize(unsigned char* nodeData, int& size)
  661.         {
  662.                 int realsize = getSize();
  663.                 if(size < realsize)
  664.                         return;
  665.                 size = realsize;
  666.                 int offset = 0;
  667.                 int left = 0;
  668.                 memcpy(nodeData + offset, &header, sizeof(ResChunk_header));
  669.                 offset += sizeof(ResChunk_header);
  670.                 //写入字符串池
  671.                 left = size - offset;
  672.                 stringPool.serialize(nodeData + offset, left);
  673.                 offset += stringPool.getSize();
  674.                 //写入资源映射
  675.                 left = size - offset;
  676.                 resourceMap.serialize(nodeData + offset, left);
  677.                 offset += resourceMap.getSize();
  678.                 //写入XML树
  679.                 for(int i=0;i<elements.size();i++)
  680.                 {
  681.                         left = size - offset;
  682.                         elements[i]->serialize(nodeData + offset, left);
  683.                         offset += elements[i]->getSize();
  684.                 }
  685.         }

  686.         virtual int getSize()
  687.         {
  688.                 int size = sizeof(ResChunk_header) + stringPool.getSize() + resourceMap.getSize();
  689.                 for(int i=0;i<elements.size();i++)
  690.                 {
  691.                         size += elements[i]->getSize();
  692.                 }
  693.                 return size;
  694.         }

  695.         void print()
  696.         {
  697.                 wprintf(L"totalsize=%d\n",header.size);
  698.                 stringPool.print();
  699.                 resourceMap.print();
  700.                 for(int i=0;i<elements.size();i++)
  701.                 {
  702.                         size += elements[i]->print();
  703.                 }
  704.         }
  705. };

复制代码
回复

使用道具 举报

1111

主题

1651

回帖

7万

积分

用户组: 管理员

一只技术宅

UID
1
精华
244
威望
743 点
宅币
24241 个
贡献
46222 次
宅之契约
0 份
在线时间
2297 小时
注册时间
2014-1-26
发表于 2016-4-3 22:09:49 | 显示全部楼层
你这东西应该是能够直接修改一个已经编译了的AndroidManifest.xml的文件吧?
一开始看标题我还不明白是个啥。
确实是个不错的东西。建议再写一份C的。
回复 赞! 靠!

使用道具 举报

0

主题

41

回帖

45

积分

用户组: 初·技术宅

UID
3351
精华
0
威望
2 点
宅币
0 个
贡献
0 次
宅之契约
0 份
在线时间
0 小时
注册时间
2018-1-14
发表于 2018-1-14 14:48:35 | 显示全部楼层
可以可以!!
回复

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-4-24 10:49 , Processed in 0.046886 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表