Ejemplo n.º 1
0
        private static void ProcessAttribute_Application(PackageDataModel targetModel,
                                                         XmlAttributeCollection attributeCollection)
        {
            if (attributeCollection == null)
            {
                return;
            }

            foreach (XmlAttribute currentAttribute in attributeCollection)
            {
                Console.WriteLine("Node attribute: " + currentAttribute.Name + " " + currentAttribute.Value);
                switch (currentAttribute.Name)
                {
                case KEY_ATTRIBUTE_APPLICATION_ICON:
                    targetModel.AppIconResourceEntry = currentAttribute.Value.Trim('@');
                    break;

                case KEY_ATTRIBUTE_APPLICATION_LABEL:
                    targetModel.AppNameResourceEntry = currentAttribute.Value.Trim('@');
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private static void ProcessAttribute_Screens(PackageDataModel targetModel,
                                                     XmlAttributeCollection attributeCollection)
        {
            if (attributeCollection == null)
            {
                return;
            }

            foreach (XmlAttribute currentAttribute in attributeCollection)
            {
                if (currentAttribute.Value.Equals("true"))
                {
                    Console.WriteLine("Node attribute localname:  " + currentAttribute.LocalName);
                    if (currentAttribute.LocalName.EndsWith("Screens") ||
                        currentAttribute.LocalName.EndsWith("Density"))
                    {
                        targetModel.ScreenSize.Add(
                            currentAttribute.LocalName.Remove(currentAttribute.LocalName.Length - 7, 7));
                    }
                    else
                    {
                        targetModel.ScreenSize.Add(currentAttribute.LocalName);
                    }
                }
            }

            Console.WriteLine("Node ScreenSize: " + string.Concat(targetModel.ScreenSize));
        }
Ejemplo n.º 3
0
        public async Task Decode()
        {
            Debug.WriteLine("DefaultAABDecoder.Decode() decode start.");
            dataModel = new PackageDataModel();

            Debug.WriteLine("DefaultAABDecoder.Decode() start test java.");
            await Decode_JavaTest();

            if (DesktopJavaUtil.javaTested && DesktopJavaUtil.javaExist)
            {
                Debug.WriteLine("DefaultAABDecoder.Decode() Decode_Manifest start.");
                await Decode_Manifest();

                Debug.WriteLine("DefaultAABDecoder.Decode() Decode_AppName start.");
                await Decode_AppName();

                Debug.WriteLine("DefaultAABDecoder.Decode_AppIconEntry() Decode_AppIconEntry start.");
                await Decode_AppIconEntry();

                Debug.WriteLine("DefaultAABDecoder.Decode() Decode_Icon start.");
                await Decode_Icon();

                // statusReportEvent?.Invoke("WindowsAABDecoder.Decode() Decode_Signature start.");
                // await Decode_Signature();
            }
            Debug.WriteLine("DefaultAABDecoder.Decode() Decode_Hash start.");
            Decode_Hash();

            dataModel.Signature        = LocalizationCenter.currentDataModel.Msg_AABNotSupport;
            dataModel.RawDumpSignature = LocalizationCenter.currentDataModel.Msg_AABNotSupport;

            Debug.WriteLine("DefaultAABDecoder.Decode() decode finish.");
            decodeProgressCallbackEvent?.Invoke();
        }
Ejemplo n.º 4
0
        public static void ReadAPKSignature(PackageDataModel targetModel, string signResult)
        {
            StringBuilder finalResult = new StringBuilder();

            if (targetModel == null)
            {
                targetModel = new PackageDataModel();
            }

            string[] textLines = signResult.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string line in textLines)
            {
                if (line.Trim().Equals(SIGNATURE_HEAD))
                {
                    continue;
                }

                (string, string)splitResult = SplitKeyValue(line);

                if (splitResult.Item1.StartsWith("WARNING"))
                {
                    continue;
                }

                finalResult.AppendLine(line);
            }

            targetModel.Signature = finalResult.ToString();
        }
Ejemplo n.º 5
0
 public static void CalculateSHA1(Uri fileUri, PackageDataModel dataModel)
 {
     using (SHA1 sha = SHA1.Create())
     {
         using (FileStream stream = File.OpenRead(fileUri.OriginalString))
         {
             dataModel.SHA1Hash = System.BitConverter.ToString(sha.ComputeHash(stream)).Replace("-", "");
         }
     }
 }
Ejemplo n.º 6
0
        public async Task Decode()
        {
            //https://github.com/claunia/plist-cil
            //https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html
            Console.WriteLine("DefaultIPADecoder.Decode() decode start.");

            dataModel = new PackageDataModel();

            Console.WriteLine("DefaultIPADecoder.Decode() Extract info.plist start.");

            using (ZipArchive zipObject = ZipFile.Open(targetFilePath.OriginalString, ZipArchiveMode.Read, Encoding.UTF8))
            {
                IEnumerable <ZipArchiveEntry> listEntry = zipObject.Entries.Where(x => x.Name.Equals("Info.plist"));
                Console.WriteLine("DefaultIPADecoder.Decode() all plist entries: ");
                foreach (ZipArchiveEntry zae in listEntry)
                {
                    Console.WriteLine(zae.FullName);
                }
                Console.WriteLine("DefaultIPADecoder.Decode() all plist ends here");
                ZipArchiveEntry targetEntry = null;
                foreach (ZipArchiveEntry zae in listEntry)
                {
                    if (Path.GetDirectoryName(zae.FullName).Trim('/').EndsWith(".app"))
                    {
                        targetEntry = zae;
                        Console.WriteLine("DefaultIPADecoder.Decode() selected entry: " + zae.FullName);
                        break;
                    }
                }

                if (targetEntry != null)
                {
                    NSDictionary rootDoc = null;
                    using (Stream sourceStream = targetEntry.Open())
                        using (MemoryStream byteStream = new MemoryStream())
                        {
                            await sourceStream.CopyToAsync(byteStream);

                            rootDoc = (NSDictionary)PropertyListParser.Parse(byteStream.ToArray());
                            dataModel.RawDumpBadging = rootDoc.ToXmlPropertyList();
                            Console.WriteLine("DefaultIPADecoder.Decode() raw: \r\n" + dataModel.RawDumpBadging);
                        }

                    if (rootDoc != null)
                    {
                        //Core Method, read data
                        PListCilUtil.ReadNSData(dataModel, rootDoc);
                    }
                }
            }

            decodeProgressCallbackEvent?.Invoke();
        }
Ejemplo n.º 7
0
        private static void ProcessAttribute_Permission(PackageDataModel targetModel,
                                                        XmlAttributeCollection attributeCollection)
        {
            if (attributeCollection == null)
            {
                return;
            }

            foreach (XmlAttribute currentAttribute in attributeCollection)
            {
                if (currentAttribute.Name.Equals(KEY_ATTRIBUTE_NAME))
                {
                    Console.WriteLine("Node permission: " + currentAttribute.Value);
                    targetModel.Permissions.Add(currentAttribute.Value);
                }
            }
        }
Ejemplo n.º 8
0
        public static void ReadManifest(PackageDataModel targetModel, string manifestResult)
        {
            if (targetModel == null)
            {
                targetModel = new PackageDataModel();
            }

            try
            {
                XmlDocument targetDoc = new XmlDocument();
                targetDoc.LoadXml(manifestResult);

                ProcessNode(targetModel, targetDoc);
            }
            catch (Exception e)
            {
                Console.WriteLine("DesktopCMDAABUtil.ReadManifest() failed!");
            }
        }
Ejemplo n.º 9
0
        private static void ProcessAttribute_Feature(PackageDataModel targetModel,
                                                     XmlAttributeCollection attributeCollection)
        {
            if (attributeCollection == null)
            {
                return;
            }

            string featureName    = string.Empty;
            bool   featureRequire = false;

            foreach (XmlAttribute currentAttribute in attributeCollection)
            {
                if (currentAttribute.Name.Equals(KEY_ATTRIBUTE_NAME))
                {
                    featureName = currentAttribute.Value;
                }
                if (currentAttribute.Name.Equals(KEY_ATTRIBUTE_FEATURE_REQUIRED))
                {
                    bool.TryParse(currentAttribute.Value, out featureRequire);
                }
                if (currentAttribute.Name.Equals(KEY_ATTRIBUTE_OPENGLVERSION))
                {
                    targetModel.OpenGLVersion = StringConstant.FieldHead_OpenGL +
                                                OtherUtil.OpenGLVersionParse(currentAttribute.Value);
                    Console.WriteLine("Node OpenGL: " + targetModel.OpenGLVersion);
                    return;
                }
            }

            if (!string.IsNullOrEmpty(featureName))
            {
                Console.WriteLine("Node Feature: " + featureName + " " + featureRequire);
                if (featureRequire)
                {
                    targetModel.Feature_Require.Add(featureName);
                }
                else
                {
                    targetModel.Feature_NotRequire.Add(featureName);
                }
            }
        }
Ejemplo n.º 10
0
        //todo add ProcessResourceDump()

        public static void ReadAppName(PackageDataModel targetModel, string dumpResult)
        {
            if (string.IsNullOrWhiteSpace(dumpResult))
            {
                return;
            }

            string[] dumpResultLines = dumpResult.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            foreach (string line in dumpResultLines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                string trimedLine = line.Trim();
                if (trimedLine.StartsWith("Package"))
                {
                    continue;
                }
                if (trimedLine.StartsWith("0x"))
                {
                    continue;
                }

                string[] splitLine = trimedLine.Split('\"');
                if (splitLine.Length < 2)
                {
                    continue;
                }

                string targetValue = splitLine[1];
                // Debug.WriteLine("Feature Test targetValue=" + targetValue);
                //todo multiple language AppName?
                if (trimedLine.Contains("default"))
                {
                    targetModel.AppName = targetValue;
                    targetModel.AppNameLangDict.Add("default", targetValue);
                }
            }
        }
Ejemplo n.º 11
0
        private static void ProcessNode(PackageDataModel targetModel, XmlNode currentNode)
        {
            Console.WriteLine("Node name:  " + currentNode.Name);
            switch (currentNode.Name)
            {
            case KEY_MANIFEST:
            case KEY_SDK:
                ProcessAttribute_Default(targetModel, currentNode.Attributes);
                break;

            case KEY_SCREENSIZE:
                ProcessAttribute_Screens(targetModel, currentNode.Attributes);
                break;

            case KEY_FEATURE:
                ProcessAttribute_Feature(targetModel, currentNode.Attributes);
                break;

            case KEY_PERMISSION:
                ProcessAttribute_Permission(targetModel, currentNode.Attributes);
                break;

            case KEY_APPLICATION:
                ProcessAttribute_Application(targetModel, currentNode.Attributes);
                break;

            default:
                break;
            }

            if (currentNode.HasChildNodes)
            {
                XmlNodeList nodeList = currentNode.ChildNodes;
                foreach (XmlNode node in nodeList)
                {
                    ProcessNode(targetModel, node);
                }
            }
        }
Ejemplo n.º 12
0
        private static void ProcessAttribute_Default(PackageDataModel targetModel,
                                                     XmlAttributeCollection attributeCollection)
        {
            if (attributeCollection == null)
            {
                return;
            }

            foreach (XmlAttribute currentAttribute in attributeCollection)
            {
                Console.WriteLine("Node attribute: " + currentAttribute.Name + " " + currentAttribute.Value);
                switch (currentAttribute.Name)
                {
                case KEY_ATTRIBUTE_MANIFEST_PACKAGE:
                    targetModel.PackageName = currentAttribute.Value;
                    break;

                case KEY_ATTRIBUTE_MANIFEST_VERSIONNAME:
                    targetModel.VersionString = currentAttribute.Value;
                    break;

                case KEY_ATTRIBUTE_MANIFEST_VERSIONCODE:
                    targetModel.VersionCode = currentAttribute.Value;
                    break;

                case KEY_ATTRIBUTE_SDK_MIN:
                    targetModel.MinSDKCode = currentAttribute.Value;
                    break;

                case KEY_ATTRIBUTE_SDK_MAX:
                    targetModel.MaxSDKCode = currentAttribute.Value;
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 13
0
        public async Task Decode()
        {
            Debug.WriteLine("DefaultAPKDecoder.Decode() decode start.");
            dataModel = new PackageDataModel();

            Debug.WriteLine("DefaultAPKDecoder.Decode() Decode_Badging start.");
            await Decode_Badging();

            decodeProgressCallbackEvent?.Invoke();
            Debug.WriteLine("DefaultAPKDecoder.Decode() Decode_Icon start.");
            await Decode_Icon();

            decodeProgressCallbackEvent?.Invoke();
            Debug.WriteLine("DefaultAPKDecoder.Decode() Decode_Signature start.");
            await Decode_Signature();

            decodeProgressCallbackEvent?.Invoke();
            Debug.WriteLine("DefaultAPKDecoder.Decode() Decode_Hash start.");
            Decode_Hash();

            Debug.WriteLine("DefaultAPKDecoder.Decode() decode finish.");
            decodeProgressCallbackEvent?.Invoke();
        }
Ejemplo n.º 14
0
        public static void ReadAppIconEntry(PackageDataModel targetModel, string dumpResult)
        {
            if (string.IsNullOrWhiteSpace(dumpResult))
            {
                return;
            }

            string[] dumpResultLines = dumpResult.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in dumpResultLines.Reverse())
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                string trimedLine = line.Trim();
                if (trimedLine.StartsWith("Package"))
                {
                    continue;
                }
                if (trimedLine.StartsWith("0x"))
                {
                    continue;
                }

                string[] splitLine = trimedLine.Split(new[] { "[FILE]" }, StringSplitOptions.RemoveEmptyEntries);
                if (splitLine.Length < 2)
                {
                    continue;
                }

                string targetValue = splitLine[1];

                targetModel.MaxIconZipEntry = "base/" + targetValue.Trim();
                break;
            }
        }
Ejemplo n.º 15
0
 public DefaultAPKDecoder(ICmdPathProvider newPathProvider)
 {
     dataModel    = null;
     pathProvider = newPathProvider;
 }
Ejemplo n.º 16
0
        public static void ReadNSData(PackageDataModel targetModel, NSDictionary nsData)
        {
            targetModel.AppName       = nsData.ObjectForKey(KEY_APPNAME)?.ToString();
            targetModel.VersionString = nsData.ObjectForKey(KEY_VERSION_STRING)?.ToString();
            targetModel.VersionCode   = nsData.ObjectForKey(KEY_VERSION)?.ToString();
            targetModel.PackageName   = nsData.ObjectForKey(KEY_PACKAGENAME)?.ToString();

            //supports-screens <- UIDeviceFamily
            NSArray deviceFamilyArray = (NSArray)nsData.ObjectForKey(KEY_DEVICE_FAMILY);

            foreach (NSObject _obj in deviceFamilyArray)
            {
                int deviceFamilyValue = ((NSNumber)_obj).ToInt();
                switch (deviceFamilyValue)
                {
                case 1:
                    targetModel.ScreenSize.Add("iPhone");
                    break;

                case 2:
                    targetModel.ScreenSize.Add("iPad");
                    break;

                case 3:
                    targetModel.ScreenSize.Add("AppleTV");
                    break;

                case 4:
                    targetModel.ScreenSize.Add("AppleWatch");
                    break;
                }
            }

            //Device Capability
            //https://developer.apple.com/documentation/bundleresources/information_property_list/uirequireddevicecapabilities?language=objc
            // some ipa use dictionary for this
            List <string> capList = new List <string>();
            NSObject      capObj  = nsData.ObjectForKey(KEY_DEVICE_CAP);

            if (capObj is NSArray)
            {
                NSArray         deviceCapArray = (NSArray)capObj;
                List <NSObject> tempList       = new List <NSObject>(deviceCapArray);
                capList.AddRange(tempList.ConvertAll(x => x.ToString()));
            }
            else if (capObj is NSDictionary)
            {
                NSDictionary deviceCapDict = (NSDictionary)capObj;
                capList.AddRange(deviceCapDict.Keys);
            }

            foreach (string objStr in capList)
            {
                if (objStr.Contains("arm"))
                {
                    switch (objStr)
                    {
                    case "armv7":
                        targetModel.Architecture.Add("armv7");
                        break;

                    case "arm64":
                        targetModel.Architecture.Add("arm64");
                        break;
                    }
                }
                else if (objStr.Contains("opengl"))
                {
                    targetModel.OpenGLVersion += objStr;
                }
                else
                {
                    targetModel.Feature_Require.Add(objStr);
                }
            }


            //architecture

            //sdk
            targetModel.MinSDKCode = nsData.ObjectForKey(KEY_MINOS)?.ToString();
            targetModel.MaxSDKCode = nsData.ObjectForKey(KEY_TARGETOS)?.ToString();

            //dpi

            //permission
            foreach (string per in LIST_PERMISSION)
            {
                if (nsData.ContainsKey(per))
                {
                    targetModel.Permissions.Add(per);
                    targetModel.Permissions.Add("- " + nsData.ObjectForKey(per));
                }
            }

            //feature
        }
Ejemplo n.º 17
0
        public static void ReadBadging(PackageDataModel targetModel, string badgingResult)
        {
            if (targetModel == null)
            {
                targetModel = new PackageDataModel();
            }

            string[] textLines = badgingResult.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in textLines)
            {
                (string, string)splitResult = SplitKeyValue(line);
                string key   = splitResult.Item1.Trim();
                string value = splitResult.Item2.Trim('\'', ' ');

                //Console.WriteLine("key=" + key);
                //Console.WriteLine("value=" + value);

                if (key.StartsWith(KEY_APPICON))
                {
                    if (string.IsNullOrEmpty(targetModel.MaxIconZipEntry))
                    {
                        targetModel.MaxIconZipEntry = value;
                    }
                    else if (targetModel.MaxIconZipEntry.Count(x => x.Equals('x')) < value.Count(x => x.Equals('x')))
                    {
                        targetModel.MaxIconZipEntry = value;
                    }
                }
                if (key.StartsWith(KEY_APPLABEL))
                {
                    if (key.Equals(KEY_APPLABEL))
                    {
                        targetModel.AppNameLangDict.Add(StringConstant.LangCode_Key_Default, value);
                    }
                    else if (targetModel.AppNameLangDict.ContainsKey(StringConstant.LangCode_Key_Default) &&
                             !value.Equals(targetModel.AppNameLangDict[StringConstant.LangCode_Key_Default]))
                    {
                        targetModel.AppNameLangDict.Add(key.Substring(KEY_APPLABEL.Length + 1), value);
                    }
                }

                switch (key)
                {
                case KEY_PACKAGEGROUP:
                    Dictionary <string, string> packageDict = SplitSubDict(value);
                    targetModel.PackageName   = packageDict[SUBKEY_NAME];
                    targetModel.VersionCode   = packageDict[SUBKEY_VERSIONCODE];
                    targetModel.VersionString = packageDict[SUBKEY_VERSIONNAME];
                    break;

                case KEY_MINSDK:
                    targetModel.MinSDKCode = value;
                    break;

                case KEY_TARGETSDK:
                    targetModel.MaxSDKCode = value;
                    break;

                case KEY_APP:
                    Dictionary <string, string> labelDict = SplitSubDict(value);
                    targetModel.AppName = labelDict[SUBKEY_LABEL];
                    break;

                case KEY_SCREENSIZE:
                    targetModel.ScreenSize.AddRange(SplitSubArray(value));
                    break;

                case KEY_DENSITY:
                    targetModel.Densities.AddRange(SplitSubArray(value));
                    break;

                case KEY_DENSITY_ANY:
                    if (value.Equals(true.ToString().ToLower()))
                    {
                        targetModel.Densities.Add("any");
                    }
                    break;

                case KEY_PERMISSION:
                    Dictionary <string, string> permissionDict = SplitSubDict(value);
                    targetModel.Permissions.Add(permissionDict[SUBKEY_NAME]);
                    break;

                case KEY_FEATURE_REQUIRED:
                    Dictionary <string, string> featureDict = SplitSubDict(value);
                    targetModel.Feature_Require.Add(featureDict[SUBKEY_NAME]);
                    break;

                case KEY_FEATURE_NOTREQUIRED:
                    Dictionary <string, string> featureNRDict = SplitSubDict(value);
                    targetModel.Feature_NotRequire.Add(featureNRDict[SUBKEY_NAME]);
                    break;

                case KEY_GLES:
                    targetModel.OpenGLVersion = StringConstant.FieldHead_OpenGL + OtherUtil.OpenGLVersionParse(value);
                    break;

                case KEY_NATIVE_CODE:
                    targetModel.Architecture.AddRange(SplitSubArray(value));
                    break;

                default:
                    //Console.WriteLine("Key not processed, key=" + key);
                    break;
                }
            }
        }