Exemplo n.º 1
0
        public Dex(Stream dexStream)
        {
            if (!dexStream.CanSeek)
            {
                throw new ArgumentException("Must be able to seek the DEX stream");
            }

            DexStream   = dexStream;
            DexHeader   = DexHeader.Parse(dexStream);
            SectionsMap = ReadSectionsMap();
        }
Exemplo n.º 2
0
        internal static DexHeader Parse(Stream dexStream)
        {
            dexStream.Seek(0, SeekOrigin.Begin);
            var reader = new BinaryReader(dexStream);

            // Check for the DEX signature in the first bytes of the file
            var fileMagic = Encoding.UTF8.GetString(reader.ReadBytes(4));

            if (fileMagic.Equals("dey\n"))
            {
                throw new ArgumentException("Optimized DEX files are not supported");
            }
            else if (!fileMagic.Equals("dex\n"))
            {
                throw new ArgumentException(string.Format("Invalid DEX file - wrong signature. Found {0}", fileMagic));
            }


            DexHeader header = new DexHeader();

            header.ApiVersion             = Encoding.UTF8.GetString(reader.ReadBytes(4));
            header.Checksum               = reader.ReadUInt32();
            header.Signature              = reader.ReadBytes(20);
            header.FileSize               = reader.ReadUInt32();
            header.HeaderSize             = reader.ReadUInt32();
            header.IsLittleEndian         = reader.ReadUInt32() == 0x12345678;
            header.LinkSize               = reader.ReadUInt32();
            header.LinkOffset             = reader.ReadUInt32();
            header.MapOffset              = reader.ReadUInt32();
            header.StringIdsCount         = reader.ReadUInt32();
            header.StringIdsOffset        = reader.ReadUInt32();
            header.TypeIdsCount           = reader.ReadUInt32();
            header.TypeIdsOffset          = reader.ReadUInt32();
            header.PrototypeIdsCount      = reader.ReadUInt32();
            header.PrototypeIdsOffset     = reader.ReadUInt32();
            header.FieldIdsCount          = reader.ReadUInt32();
            header.FieldIdsOffset         = reader.ReadUInt32();
            header.MethodIdsCount         = reader.ReadUInt32();
            header.MethodIdsOffset        = reader.ReadUInt32();
            header.ClassDefinitionsCount  = reader.ReadUInt32();
            header.ClassDefinitionsOffset = reader.ReadUInt32();
            header.DataSize               = reader.ReadUInt32();
            header.DataOffset             = reader.ReadUInt32();

            return(header);
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     DexStream.Dispose(); //.Close();
     SectionsMap.Clear();
     DexHeader = null;
 }