コード例 #1
0
ファイル: DexParser.cs プロジェクト: steskalja/AstoriaUWP
        public void parse()
        {
            // read magic
            string magic = Encoding.UTF8.GetString(Buffers.readBytes(buffer, 8)); //new string(Buffers.readBytes(buffer, 8));

            if (!magic.StartsWith("dex\n"))
            {
                return;
            }
            int version = int.Parse(magic.Substring(4, 7));

            // now the version is 035
            if (version < 35)
            {
                // version 009 was used for the M3 releases of the Android platform (November–December 2007),
                // and version 013 was used for the M5 releases of the Android platform (February–March 2008)
                throw new Exception("Dex file version: " + version + " is not supported");
            }

            // read header
            DexHeader header = readDexHeader();

            header.setVersion(version);

            // read string pool
            long[] stringOffsets = readStringPool(header.getStringIdsOff(), header.getStringIdsSize());

            // read types
            int[] typeIds = readTypes(header.getTypeIdsOff(), header.getTypeIdsSize());

            // read classes
            DexClassStruct[] dexClassStructs = readClass(header.getClassDefsOff(),
                                                         header.getClassDefsSize());

            StringPool stringpool = readStrings(stringOffsets);

            string[] types = new string[typeIds.Length];
            for (int i = 0; i < typeIds.Length; i++)
            {
                types[i] = stringpool.get(typeIds[i]);
            }

            dexClasses = new DexClass[dexClassStructs.Length];
            for (int i = 0; i < dexClasses.Length; i++)
            {
                dexClasses[i] = new DexClass();
            }
            for (int i = 0; i < dexClassStructs.Length; i++)
            {
                DexClassStruct dexClassStruct = dexClassStructs[i];
                DexClass       dexClass       = dexClasses[i];
                dexClass.setClassType(types[dexClassStruct.getClassIdx()]);
                if (dexClassStruct.getSuperclassIdx() != NO_INDEX)
                {
                    dexClass.setSuperClass(types[dexClassStruct.getSuperclassIdx()]);
                }
                dexClass.setAccessFlags(dexClassStruct.getAccessFlags());
            }
        }
コード例 #2
0
ファイル: DexParser.cs プロジェクト: steskalja/AstoriaUWP
        /**
         * read class info.
         */
        private DexClassStruct[] readClass(long classDefsOff, int classDefsSize)
        {
            buffer.position((int)classDefsOff);

            DexClassStruct[] dexClassStructs = new DexClassStruct[classDefsSize];
            for (int i = 0; i < classDefsSize; i++)
            {
                DexClassStruct dexClassStruct = new DexClassStruct();
                dexClassStruct.setClassIdx(buffer.getInt());

                dexClassStruct.setAccessFlags(buffer.getInt());
                dexClassStruct.setSuperclassIdx(buffer.getInt());

                dexClassStruct.setInterfacesOff(Buffers.readUInt(buffer));
                dexClassStruct.setSourceFileIdx(buffer.getInt());
                dexClassStruct.setAnnotationsOff(Buffers.readUInt(buffer));
                dexClassStruct.setClassDataOff(Buffers.readUInt(buffer));
                dexClassStruct.setStaticValuesOff(Buffers.readUInt(buffer));
                dexClassStructs[i] = dexClassStruct;
            }

            return(dexClassStructs);
        }