Example #1
0
        static void ReadApk(String filePath)
        {
            using (ApkFile apk = new ApkFile(filePath))
            {
                Console.WriteLine("Package: {0}", apk.AndroidManifest.Package);
                Console.WriteLine("Application name: {0} ({1})", apk.AndroidManifest.Application.Label, apk.AndroidManifest.VersionName);

                if (apk.MfFile != null)
                {
                    UInt32 totalFiles   = 0;
                    UInt32 hashNotFound = 0;
                    UInt32 invalidHash  = 0;
                    foreach (String apkFilePath in apk.GetFiles())
                    {
                        totalFiles++;
                        String sHash = apk.MfFile[apkFilePath];
                        if (sHash == null)
                        {
                            //Console.WriteLine("Hash not found for file: {0}", apkFilePath);
                            hashNotFound++;
                        }
                        else if (!apk.MfFile.ValidateHash(apkFilePath, apk.GetFile(apkFilePath)))
                        {
                            //Console.WriteLine("InvalidHash: {0} ({1})", apkFilePath, sHash);
                            invalidHash++;
                        }
                    }

                    Console.WriteLine("Total files: {0:N0}", totalFiles);
                    if (hashNotFound > 0)
                    {
                        Console.WriteLine("Hash Not found: {0:N0}", hashNotFound);
                    }
                    if (invalidHash > 0)
                    {
                        Console.WriteLine("Invalid hash: {0:N0}", invalidHash);
                    }
                }

                TreeDto root = BuildTree(apk.GetHeaderFiles().ToArray(), '/');
                String  test = ConvertTreeToStringRec(root, 0);

                foreach (String xmlFile in apk.GetHeaderFiles())
                {
                    switch (Path.GetExtension(xmlFile).ToLowerInvariant())
                    {
                    case ".xml":
                        /*if(xmlFile.Equals("AndroidManifest.xml", StringComparison.OrdinalIgnoreCase))
                         *      continue;*/

                        Byte[] file = apk.GetFile(xmlFile);
                        //ManifestFile manifest = new ManifestFile(file);
                        //Console.WriteLine(manifest.Xml.ConvertToString());

                        AxmlFile axml = new AxmlFile(StreamLoader.FromMemory(file, xmlFile));
                        if (axml.Header.IsValid)
                        {
                            XmlNode xml = axml.RootNode;
                            Console.WriteLine("---" + xmlFile + ":");
                            Console.WriteLine(xml.ConvertToString());
                        }
                        else
                        {
                            Console.WriteLine("---" + xmlFile + ":");
                            Console.WriteLine(System.Text.Encoding.UTF8.GetString(file));
                        }
                        break;
                    }
                }

                ReadApkManifestRecursive(apk.AndroidManifest);
            }
        }