public RenamedClass SearchForNewName(EntityName target)
        {
            if (name.NameNew != null)
            {
                if (target.Compare(NameNew))
                {
                    return(this);
                }
                if (target.Compare(NameNewFull))
                {
                    return(this);
                }
            }

            foreach (RenamedBase item in items)
            {
                if (item.EntityType != EntityType.Class)
                {
                    continue;
                }

                RenamedClass c = (RenamedClass)item;
                c = c.SearchForNewName(target);
                if (c != null)
                {
                    return(c);
                }
            }

            return(null);
        }
        private void BuildSubclass(RenamedClass c, PineappleTreeNode ownerNode)
        {
            PineappleTreeNode classNode = CreateNode(c.NameOld);

            ownerNode.Nodes.Add(classNode);
            BuildClassContent(c, classNode);
        }
        public static string BuildHintForClass(RenamedClass c)
        {
            if (c.SkipReason != null)
            {
                return(string.Format("Name:\r\n{0}\r\nSkip reason:\r\n{1}", c.NameOldFull, c.SkipReason));
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("Old name: ");
            sb.AppendLine(c.NameOldFull);
            sb.Append("New name: ");
            sb.AppendLine(CheckIfUnicode(c.NameNewFull));
            sb.Append("Name transform: ");
            sb.AppendLine(c.TransformName);
            if (c.OwnerClass != null)
            {
                sb.Append("Owner class: ");
                sb.AppendLine(CheckIfUnicode(c.OwnerClass.TransformNameFull));
            }
            else
            {
                sb.Append("Namespace transform: ");
                sb.AppendLine(CheckIfUnicode(c.TransformNamespace));
            }
            sb.Append("Subitems: ");
            sb.AppendLine(c.Items.Count.ToString());
            return(sb.ToString());
        }
Beispiel #4
0
        private void BuildClass(RenamedClass c)
        {
            PineappleTreeNode classNode = CreateNode(c.NameOld);
            PineappleTreeNode owner     = GetRootNodeForClass(c);

            owner.Nodes.Add(classNode);
            BuildClassContent(c, classNode);
        }
Beispiel #5
0
        public RenamedBase SearchForOldName(EntityName target)
        {
            foreach (RenamedClass renamedClass in classes)
            {
                RenamedClass c = renamedClass.SearchForOldName(target);
                if (c != null)
                {
                    return(c);
                }
            }

            return(null);
        }
            public string GetToolTip()
            {
                RenamedItem item = renamed as RenamedItem;

                if (item != null)
                {
                    return(TreeBuilder.BuildHintForItem(item));
                }
                RenamedClass @class = renamed as RenamedClass;

                if (@class != null)
                {
                    return(TreeBuilder.BuildHintForClass(@class));
                }

                return(entity.NameFull);
            }
Beispiel #7
0
        public RenamedItem(NanoXmlElement el, RenamedClass owner)
        {
            try
            {
                this.owner = owner;
                entityType = (EntityType)Enum.Parse(typeof(EntityType), el.Name.Substring(7));
                string str = el.GetAttribute("oldName");

                int i;
                if ((i = str.IndexOf(' ')) != -1)
                {
                    string s = str.Substring(0, i);
                    int    k = s.IndexOf('/');
                    if (k != -1)
                    {
                        resultType = new RenamedParam(s.Substring(0, k) + "." + s.Substring(k + 1));
                    }
                    else
                    {
                        resultType = new RenamedParam(s);
                    }
                    str = str.Substring(i + 1);
                }

                if ((i = str.IndexOf("::")) != -1)
                {
                    str = str.Substring(i + 2);
                }

                if ((i = str.IndexOf('(')) != -1)
                {
                    methodParams = new List <RenamedParam>();
                    foreach (string s in EntityName.ParseList(str, i + 1, ')'))
                    {
                        int k = s.IndexOf('/');
                        if (k != -1)
                        {
                            methodParams.Add(new RenamedParam(s.Substring(0, k) + "." + s.Substring(k + 1)));
                        }
                        else
                        {
                            methodParams.Add(new RenamedParam(s));
                        }
                    }

                    str = str.Substring(0, i);

                    i = str.IndexOf('[');
                    if (i != -1 && str[i + 2] == ']')
                    {
                        str = str.Substring(0, i);
                    }
                }

                string strNew = el.GetAttribute("newName");
                if (strNew != "dropped")
                {
                    name = new Renamed(str, strNew);
                }
                else
                {
                    name = new Renamed(str);
                }
            }
            catch (Exception e)
            {
                throw new ObfuscarParserException("Failed to process item element", e, el.Path);
            }
        }
Beispiel #8
0
        private void LoadFile()
        {
            loadTime = 0;
            LoadTimer       timer = new LoadTimer("XML Parsing");
            NanoXmlDocument xml   = NanoXmlDocument.LoadFromFile(filename);

            loadTime += timer.Stop();
            timer     = new LoadTimer("Items Processing");

            NanoXmlElement doc   = xml.DocumentElement;
            NanoXmlElement types = (NanoXmlElement)doc["renamedTypes"];

            modules.Clear();
            namespaces.Clear();
            namespacesObfuscated.Clear();
            classes.Clear();
            classesCache.Clear();
            haveSystemEntities = false;
            methodsCount       = classesCount = subclassesCount = skippedCount = 0;
            lastModified       = File.GetLastWriteTime(filename);

            List <RenamedClass> subclasses = new List <RenamedClass>();

            if (types != null)
            {
                foreach (NanoXmlElement element in types.ChildElements)
                {
                    if (string.Compare(element.Name, "renamedClass", StringComparison.Ordinal) == 0)
                    {
                        RenamedClass c = new RenamedClass(element, this);
                        classesCount++;
                        if (c.OwnerClassName == null)
                        {
                            classes.Add(c);
                            if (c.Name.NameOld != null && c.Name.NameOld.Namespace != null)
                            {
                                haveSystemEntities |= c.Name.NameOld.Namespace.StartsWith("System.");
                            }
                        }
                        else
                        {
                            subclasses.Add(c);
                        }

                        methodsCount += c.MethodsCount;

                        if (c.ModuleNew != null)
                        {
                            modules.Add(c.ModuleNew);
                        }
                        if (c.Name.NameOld != null)
                        {
                            classesCache[c.NameOld]     = c;
                            classesCache[c.NameOldFull] = c;

                            if (!string.IsNullOrEmpty(c.Name.NameOld.Namespace))
                            {
                                namespaces.Add(c.Name.NameOld.Namespace);
                            }
                        }
                        if (c.Name.NameNew != null)
                        {
                            classesCache[c.NameNew]     = c;
                            classesCache[c.NameNewFull] = c;

                            if (!string.IsNullOrEmpty(c.Name.NameNew.Namespace))
                            {
                                namespacesObfuscated.Add(c.Name.NameNew.Namespace);
                            }
                        }
                    }
                }
            }

            types = (NanoXmlElement)doc["skippedTypes"];
            if (types != null)
            {
                foreach (NanoXmlElement element in types.ChildElements)
                {
                    if (string.Compare(element.Name, "skippedClass", StringComparison.Ordinal) == 0)
                    {
                        skippedCount++;
                        classesCount++;
                        RenamedClass c = new RenamedClass(element, this);
                        if (c.OwnerClassName == null)
                        {
                            classes.Add(c);
                        }
                        else
                        {
                            subclasses.Add(c);
                        }

                        classesCache[c.NameOld]     = c;
                        classesCache[c.NameOldFull] = c;
                    }
                }
            }

            loadTime += timer.Stop();
            timer     = new LoadTimer("Subclasses Processing");

            foreach (RenamedClass subclass in subclasses)
            {
                RenamedClass c;
                if (classesCache.TryGetValue(subclass.OwnerClassName, out c))
                {
                    c.Items.Add(subclass);
                    subclass.OwnerClass = c;
                    subclassesCount++;
                    continue;
                }

                Debug.WriteLine("Failed to find root class: " + subclass.OwnerClassName);
                classes.Add(subclass);
            }

            loadTime += timer.Stop();
            timer     = new LoadTimer("Values Updating");

            foreach (RenamedClass c in classes)
            {
                c.UpdateNewNames(this);
            }

            loadTime += timer.Stop();
            Debug.WriteLine("Total Elapsed: {0} ms", loadTime);
        }
        private PineappleTreeNode GetRootNodeForClass(RenamedClass c)
        {
            if (c.Name.NameOld.Namespace == null)
            {
                return(GetNoNsNodeByModule(c.Name.NameNew.Module));
            }

            foreach (NamingValue value in naming)
            {
                if (groupModules && !Equals(value.module, c.ModuleNew))
                {
                    continue;
                }

                if (!groupNamespaces && !Equals(value.newNs, c.Name.NameNew.Namespace))
                {
                    continue;
                }

                if (!Equals(value.oldNs, c.Name.NameOld.Namespace))
                {
                    continue;
                }

                return(value.node);
            }

            PineappleTreeNode node = CreateNode(c.Name.NameOld.Namespace);

            node.ImageIndex = mainForm.ICON_NAMESPACE;
            string subItemText = null;

            if (c.Name.NameNew == null)
            {
                node.HighlightColorIndex = (int)Highlights.NoNewName;
                subItemText = "n/a";
            }
            else if (c.Name.NameNew.CompareNamespace(c.Name.NameOld))
            {
                node.HighlightColorIndex = (int)Highlights.NotRenamed;
            }
            else
            {
                subItemText = c.Name.NameNew.Namespace;
            }

            if (subItemText != null)
            {
                if (Configs.Instance.UseColumns)
                {
                    node.Subitems.Add(new PineappleTreeSubitem(subItemText));
                }
                else
                {
                    node.Text += "\n" + subItemText;
                }
            }

            if (groupModules)
            {
                GetModuleData(c.Name.NameNew.Module).moduleNode.Nodes.Add(node);
            }
            else
            {
                tree.Nodes.Add(node);
            }

            naming.Add(new NamingValue(c.Name.NameNew.Module, c.Name.NameOld.Namespace, c.Name.NameNew.Namespace, node));

            return(node);
        }
        private void BuildClassContent(RenamedClass c, PineappleTreeNode classNode)
        {
            classNode.ImageIndex = mainForm.ICON_CLASS;
            classNode.Tag        = c;

            classNode.ToolTipText = BuildHintForClass(c);
            mapping.MapRenamed(c, classNode);

            string subItemText = null;

            if (c.NameNew != null)
            {
                if (c.Name.NameNew.Equals(c.Name.NameOld))
                {
                    classNode.HighlightColorIndex = (int)Highlights.NotRenamed;
                }
                else
                {
                    subItemText = CheckIfUnicode(showModules ? c.NameNewFull : c.NameNew);
                }
            }
            else
            {
                subItemText = "n/a";
                classNode.HighlightColorIndex = (int)Highlights.NoNewName;
            }

            if (subItemText != null)
            {
                if (Configs.Instance.UseColumns)
                {
                    classNode.Subitems.Add(new PineappleTreeSubitem(subItemText));
                }
                else
                {
                    classNode.Text += "\n" + subItemText;
                }
            }

            foreach (RenamedBase renamedItem in c.Items)
            {
                if (renamedItem.EntityType == EntityType.Class)
                {
                    BuildSubclass((RenamedClass)renamedItem, classNode);
                    continue;
                }

                RenamedItem item = (RenamedItem)renamedItem;

                if (item.SkipReason != null && !showSkippedMembers)
                {
                    continue;
                }

                PineappleTreeNode node = new PineappleTreeNode(item.NameOld);
                classNode.Nodes.Add(node);
                node.ImageIndex = GetIconForEntity(item.EntityType, mainForm);
                node.Tag        = item;

                mapping.MapRenamed(item, node);

                node.ToolTipText = BuildHintForItem(item);
                subItemText      = null;

                if (item.NameNew == null)
                {
                    node.HighlightColorIndex = (int)Highlights.NoNewName;
                    subItemText = "n/a";
                }
                else
                {
                    if (item.NameNew.Equals(item.NameOld))
                    {
                        node.HighlightColorIndex = (int)Highlights.NotRenamed;
                    }
                    else
                    {
                        subItemText = CheckIfUnicode(item.NameNew);
                    }
                }

                if (subItemText != null)
                {
                    if (Configs.Instance.UseColumns)
                    {
                        node.Subitems.Add(new PineappleTreeSubitem(subItemText));
                    }
                    else
                    {
                        node.Text += "\n" + subItemText;
                    }
                }
            }
        }
Beispiel #11
0
        private void LoadFile()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            NanoXmlDocument xml = NanoXmlDocument.LoadFromFile(filename);

            timingXML = sw.ElapsedMilliseconds;
            Debug.WriteLine("XML Loading: " + timingXML + " ms");
            sw.Reset();
            sw.Start();

            NanoXmlElement doc   = xml.DocumentElement;
            NanoXmlElement types = (NanoXmlElement)doc["renamedTypes"];

            modules.Clear();
            namespaces.Clear();
            namespacesObfuscated.Clear();
            classes.Clear();
            haveSystemEntities = false;
            methodsCount       = classesCount = subclassesCount = skippedCount = 0;
            lastModified       = File.GetLastWriteTime(filename);

            List <RenamedClass> subclasses = new List <RenamedClass>();

            if (types != null)
            {
                foreach (NanoXmlElement element in types.ChildElements)
                {
                    if (string.Compare(element.Name, "renamedClass", StringComparison.Ordinal) == 0)
                    {
                        RenamedClass c = new RenamedClass(element, this);
                        classesCount++;
                        if (c.OwnerClassName == null)
                        {
                            classes.Add(c);
                            if (c.Name.NameOld != null && c.Name.NameOld.Namespace != null)
                            {
                                haveSystemEntities |= c.Name.NameOld.Namespace.StartsWith("System.");
                            }
                        }
                        else
                        {
                            subclasses.Add(c);
                        }

                        methodsCount += c.MethodsCount;
                        if (c.ModuleNew != null && !modules.Contains(c.ModuleNew))
                        {
                            modules.Add(c.ModuleNew);
                        }
                        if (c.Name.NameOld != null && !string.IsNullOrEmpty(c.Name.NameOld.Namespace) && !namespaces.Contains(c.Name.NameOld.Namespace))
                        {
                            namespaces.Add(c.Name.NameOld.Namespace);
                        }
                        if (c.Name.NameNew != null && !string.IsNullOrEmpty(c.Name.NameNew.Namespace) && !namespacesObfuscated.Contains(c.Name.NameNew.Namespace))
                        {
                            namespacesObfuscated.Add(c.Name.NameNew.Namespace);
                        }
                    }
                }
            }

            types = (NanoXmlElement)doc["skippedTypes"];
            if (types != null)
            {
                foreach (NanoXmlElement element in types.ChildElements)
                {
                    if (string.Compare(element.Name, "skippedClass", StringComparison.Ordinal) == 0)
                    {
                        skippedCount++;
                        classesCount++;
                        RenamedClass c = new RenamedClass(element, this);
                        if (c.OwnerClassName == null)
                        {
                            classes.Add(c);
                        }
                        else
                        {
                            subclasses.Add(c);
                        }
                    }
                }
            }


            timingParsing = sw.ElapsedMilliseconds;
            Debug.WriteLine("Parsing: " + timingParsing + " ms");
            sw.Reset();
            sw.Start();

            foreach (RenamedClass subclass in subclasses)
            {
                RenamedClass c = (RenamedClass)SearchForOldName(subclass.OwnerClassName);
                if (c == null)
                {
                    c = (RenamedClass)SearchForNewName(subclass.OwnerClassName);
                }

                if (c != null)
                {
                    c.Items.Add(subclass);
                    subclass.OwnerClass = c;
                    subclassesCount++;
                    continue;
                }

                Debug.WriteLine("Failed to find root class: " + subclass.OwnerClassName);
                classes.Add(subclass);
            }

            timingSubclasses = sw.ElapsedMilliseconds;
            Debug.WriteLine("Subclasses processing: " + timingSubclasses + " ms");
            sw.Reset();
            sw.Start();

            foreach (RenamedClass c in classes)
            {
                c.UpdateNewNames(this);
            }

            timingUpdateNewNames = sw.ElapsedMilliseconds;
            Debug.WriteLine("Values updating: " + timingUpdateNewNames + " ms");
            Debug.WriteLine("Total elapsed: " + TimingTotal + " ms");
            sw.Stop();
        }