コード例 #1
0
 private void ProcessRecord(XmlnsPropertyRecord record, AssemblyDefinition containingAssembly)
 {
     if (FixXmlNamespace(record.XmlNamespace, out string fixedNamespace))
     {
         record.XmlNamespace = fixedNamespace;
     }
 }
コード例 #2
0
        private void ProcessRecord(XmlnsPropertyRecord record, AssemblyDefinition containingAssembly)
        {
            if (record == null)
            {
                return;
            }
            string       xmlNamespace  = record.XmlNamespace;
            const string AssemblyDef   = "assembly=";
            int          assemblyStart = xmlNamespace.IndexOf(AssemblyDef, StringComparison.Ordinal);

            if (assemblyStart == -1)
            {
                return;
            }

            // Make sure it is one of the merged assemblies
            string xmlAssembly = xmlNamespace.Substring(assemblyStart + AssemblyDef.Length);

            if (_mainAssembly.Name.Name != xmlAssembly && _otherAssemblies.All(x => x.Name.Name != xmlAssembly))
            {
                return;
            }

            string xmlNsWithoutAssembly = xmlNamespace.Substring(0, assemblyStart);

            record.XmlNamespace = string.Format("{0}{1}{2}", xmlNsWithoutAssembly, AssemblyDef, _mainAssembly.Name.Name);
        }
コード例 #3
0
        public void UpdateReference(Identifier old, Identifier @new)
        {
            string prefix = rec.Value.Substring(0, rec.Value.IndexOf(':'));

            if (old.scope != @new.scope)
            {
                string xmlNamespace = "clr-namespace:" + @new.scope;
                if (@new.scope == null || !string.IsNullOrEmpty(assembly))
                {
                    xmlNamespace += ";assembly=" + assembly;
                }

                for (int i = 0; i < doc.Count; i++)
                {
                    XmlnsPropertyRecord xmlns = doc[i] as XmlnsPropertyRecord;
                    if (xmlns != null)
                    {
                        if (xmlns.XmlNamespace == xmlNamespace)
                        {
                            prefix = xmlns.Prefix;
                            break;
                        }
                        else if (xmlns.Prefix == prefix)
                        {
                            XmlnsPropertyRecord r = new XmlnsPropertyRecord();
                            r.AssemblyIds  = xmlns.AssemblyIds;
                            r.Prefix       = prefix = ObfuscationHelper.Instance.GetNewName(xmlns.Prefix, NameMode.Letters);
                            r.XmlNamespace = xmlNamespace;
                            doc.Insert(i, r);
                            break;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(prefix))
            {
                rec.Value = prefix + ":" + @new.name;
            }
            else
            {
                rec.Value = @new.name;
            }
        }
コード例 #4
0
ファイル: BamlDisassembler.cs プロジェクト: haise0/dnSurgeon
        void DisassembleRecord(BamlContext ctx, XmlnsPropertyRecord record)
        {
            WriteText("Prefix=");
            WriteString(record.Prefix);

            WriteText(", XmlNamespace=");
            WriteString(record.XmlNamespace);

            WriteText(", AssemblyIds={");
            for (int i = 0; i < record.AssemblyIds.Length; i++)
            {
                if (i != 0)
                {
                    WriteText(", ");
                }
                WriteAssemblyId(ctx, record.AssemblyIds[i]);
            }
            WriteText("}");
        }
コード例 #5
0
ファイル: WPFRemapper.cs プロジェクト: dmirmilshteyn/RefRemap
        private void ProcessRecord(XmlnsPropertyRecord record)
        {
            string xmlNamespace  = record.XmlNamespace;
            int    assemblyStart = xmlNamespace.IndexOf(XmlnsAssemblyDefinition, StringComparison.Ordinal);

            if (assemblyStart == -1)
            {
                return;
            }

            // Make sure it is one of the merged assemblies
            string xmlAssembly = xmlNamespace.Substring(assemblyStart + XmlnsAssemblyDefinition.Length);

            if (!SourceAssemblies.Contains(xmlAssembly))
            {
                return;
            }

            string xmlNsWithoutAssembly = xmlNamespace.Substring(0, assemblyStart);

            record.XmlNamespace = $"{xmlNsWithoutAssembly}{XmlnsAssemblyDefinition}{TargetModule.Assembly.Name}";
        }
コード例 #6
0
ファイル: RenameReferences.cs プロジェクト: n017/Confuser
        public void UpdateReference(Identifier old, Identifier @new)
        {
            string prefix = rec.Value.Substring(0, rec.Value.IndexOf(':'));
            if (old.scope != @new.scope)
            {
                string xmlNamespace = "clr-namespace:" + @new.scope;
                if (@new.scope == null || !string.IsNullOrEmpty(assembly))
                    xmlNamespace += ";assembly=" + assembly;

                for (int i = 0; i < doc.Count; i++)
                {
                    XmlnsPropertyRecord xmlns = doc[i] as XmlnsPropertyRecord;
                    if (xmlns != null)
                    {
                        if (xmlns.XmlNamespace == xmlNamespace)
                        {
                            prefix = xmlns.Prefix;
                            break;
                        }
                        else if (xmlns.Prefix == prefix)
                        {
                            XmlnsPropertyRecord r = new XmlnsPropertyRecord();
                            r.AssemblyIds = xmlns.AssemblyIds;
                            r.Prefix = prefix = ObfuscationHelper.Instance.GetNewName(xmlns.Prefix, NameMode.Letters);
                            r.XmlNamespace = xmlNamespace;
                            doc.Insert(i, r);
                            break;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(prefix))
                rec.Value = prefix + ":" + @new.name;
            else
                rec.Value = @new.name;
        }
コード例 #7
0
        private void WalkBaml(ResourcePart part)
        {
            Dictionary <string, string> namespaces = new Dictionary <string, string>();

            foreach (BamlRecord record in part.Baml)
            {
                if (record.Type == BamlRecordType.TypeInfo)
                {
                    TypeInfoRecord typeInfo = (TypeInfoRecord)record;

                    TypeDefinition type;
                    if (typesMap.TryGetValue(typeInfo.TypeFullName, out type))
                    {
                        AddUsedType(type);
                    }

                    continue;
                }

                if (record.Type == BamlRecordType.XmlnsProperty)
                {
                    XmlnsPropertyRecord ns            = (XmlnsPropertyRecord)record;
                    const string        CLR_NAMESPACE = "clr-namespace:";
                    if (ns.XmlNamespace.StartsWith(CLR_NAMESPACE))
                    {
                        namespaces.Add(ns.Prefix, ns.XmlNamespace.Substring(CLR_NAMESPACE.Length));
                    }

                    continue;
                }

                if (record.Type == BamlRecordType.Text)
                {
                    TextRecord textRecord = (TextRecord)record;

                    int index = textRecord.Value.IndexOf(':');
                    if (index == -1)
                    {
                        continue; // not ns reference
                    }
                    string name;
                    if (!namespaces.TryGetValue(textRecord.Value.Substring(0, index), out name))
                    {
                        continue;
                    }

                    name += "." + textRecord.Value.Substring(index + 1);

                    TypeDefinition type;

                    // type as string?
                    if (typesMap.TryGetValue(name, out type))
                    {
                        AddUsedType(type);
                        continue;
                    }

                    index = name.LastIndexOf(".", StringComparison.InvariantCulture);

                    // member?
                    if (typesMap.TryGetValue(name.Substring(0, index), out type))
                    {
                        AddUsedType(type);
                    }

                    continue;
                }

                if (record.Type == BamlRecordType.PropertyWithConverter)
                {
                    PropertyWithConverterRecord propertyInfo = (PropertyWithConverterRecord)record;

                    string resourceName = propertyInfo.Value;

                    if (resourceName.StartsWith(wpfPathPrefix))
                    {
                        resourceName = resourceName.Substring(wpfPathPrefix.Length, resourceName.Length - wpfPathPrefix.Length);
                    }

                    if (resourceName.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase))
                    {
                        resourceName = resourceName.Substring(0, resourceName.Length - 4) + "baml";
                    }

                    resourceName = resourceName.ToLower();

                    ResourcePart resourcePart;
                    if (!wpfRootParts.TryGetValue(resourceName, out resourcePart))
                    {
                        continue;
                    }

                    if (resourcePart.Baml != null)
                    {
                        AddUsedBaml(resourcePart);
                    }
                    else
                    {
                        Log($"WPF resource used: {resourceName}");
                        usedWpfResources.Add(resourceName);
                    }
                }
            }
        }