Skip to content

DKorablin/ApkReader

Repository files navigation

Apk reader

Auto build Nuget

Android package file reader assembly. Can read apk files, android xml files (AndroidManifes.xml, *.xml), Dalvik executable format (dex), android resource files (arsc).

Usage:

using(ApkFile apk = new ApkFile(apkFilePath))
{
    if(apk.IsValid)
    {
        If(apk.AndroidManifest!=null)
        {//AndroidManifest.xml
            Console.WriteLine("Package: {0}", apk.AndroidManifest.Package);
            Console.WriteLine("Application name: {0} ({1})", apk.AndroidManifest.Application.Label, apk.AndroidManifest.VersionName);
            //...
        }

        if(apk.Resources!=null)
        {//resources.arsc
            //...
        }

        foreach(String filePathInApk in apk.GetFiles())
            switch(Path.GetExtension(filePathInApk).ToLowerInvariant()){
            case ".dex":
                using(Stream stream=apk.GetFileStream(filePathInApk, true)){
                    if(stream!=null)
                        using(DexFile dex=new DexFile(new StreamLoader(stream)))
                        {//Davlik executables
                            //...
                        }
                }
            break;
            }
    }
}

Supported structures:

  • ApkFile.cs
    • XmlFile — AndroidManifest.xml
    • Resources — resources.arsc
    • AndroidManifest — Stronly typled android manifest file
  • ApkSignature.cs (https://source.android.com/docs/security/features/apksigning)
    • APK signature block reading
    • Signature scheme V2 issuer certificate extracted (Need to test)
  • ArscFile.cs (resources.arsc)
    • Header — Resource file header
    • ResourceMap — Resource table (id,value(s))
  • MfFile.cs (https://docs.oracle.com/javase/tutorial/deployment/jar/signing.html)
    • JAR files integrinty validation
  • AxmlFile.cs (https://developer.android.com/guide/topics/manifest/manifest-intro)
    • Strongly typed manifest sections mapped to resources.arsc file where needed
  • DexFile.cs (https://source.android.com/devices/tech/dalvik/dex-format)
    • map_list — This is a list of the entire contents of a file, in order.
    • STRING_ID_ITEM — String identifiers list.
    • STRING_DATA_ITEM — String identifiers list.
    • CODE_ITEM — Source bytecode payload
    • TYPE_ID_ITEM — Type identifiers list.
    • TYPE_LIST — Referenced from Class definitions list and method prototype identifiers list.
    • PROTO_ID_ITEM — Method prototype identifiers list
    • FIELD_ID_ITEM — Field identifiers list
    • METHOD_ID_ITEM — Method identifiers list
    • CLASS_DATA_ITEM — Class structure list
    • encoded_field — Static and instance fields from the class_data_item
    • encoded_method — Class method definition list
    • CLASS_DEF_ITEM — Class definitions list
    • try_item — in the code exceptions are caught and how to handle them
    • encoded_catch_handler_list — Catch handler lists
    • encoded_type_addr_pair — One for each caught type, in the order that the types should be tested