Example #1
0
        private static TreeDto BuildTree(String[] paths, Char pathSeparator)
        {
            if (paths == null)
            {
                return(null);
            }

            TreeDto rootNode = new TreeDto("0", "Dummy");
            TreeDto currentNode;

            foreach (String path in paths)
            {
                currentNode = rootNode;
                String[] pathSplit = path.Split(pathSeparator);
                foreach (String subPath in pathSplit)
                {
                    Type    zz        = GetFileTypeByExtension(subPath);
                    TreeDto foundNode = currentNode.GetNode(subPath);
                    currentNode = foundNode == null
                                                ? currentNode.AddNode(new TreeDto("0", subPath))
                                                : foundNode;
                }
            }

            return(rootNode);
        }
Example #2
0
        private static String ConvertTreeToStringRec(TreeDto root, Int32 tabsCount)
        {
            String        text   = new String(Enumerable.Repeat('\t', tabsCount).ToArray()) + root.Text + "\r\n";
            StringBuilder result = new StringBuilder(text);

            if (root.Nodes != null)
            {
                foreach (TreeDto dto in root.Nodes)
                {
                    result.Append(ConvertTreeToStringRec(dto, tabsCount + 1));
                }
            }

            return(result.ToString());
        }
Example #3
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);
            }
        }
Example #4
0
 public TreeDto AddNode(TreeDto node)
 {
     this._nodes.Add(node);
     return(node);
 }