Beispiel #1
0
        string GetCreatedBy(ModuleDef mod)
        {
            var asm = mod.Assembly;

            if (asm == null)
            {
                return(null);
            }
            var ca = asm.CustomAttributes.Find("System.Reflection.AssemblyCompanyAttribute");

            if (ca == null)
            {
                return(null);
            }
            if (ca.ConstructorArguments.Count != 1)
            {
                return(null);
            }
            var arg = ca.ConstructorArguments[0];
            var s   = arg.Value as UTF8String;

            if (UTF8String.IsNull(s))
            {
                return(null);
            }
            return(s);
        }
Beispiel #2
0
 public static UTF8String GetUTF8String(UTF8String utf8String, string s)
 {
     if (!UTF8String.IsNull(utf8String))
     {
         return(utf8String);
     }
     return(s);
 }
Beispiel #3
0
        public static void Write(this DataWriter writer, IWriterError helper, UTF8String s)
        {
            if (UTF8String.IsNull(s))
            {
                helper.Error("UTF8String is null");
                s = UTF8String.Empty;
            }

            writer.WriteCompressedUInt32(helper, (uint)s.DataLength);
            writer.WriteBytes(s.Data);
        }
Beispiel #4
0
        public static void SplitNameAndNamespace(UTF8String utf8Name, string fullName, out UTF8String ns, out UTF8String name)
        {
            if (fullName == null)
            {
                fullName = string.Empty;
            }

            if (!UTF8String.IsNull(utf8Name))
            {
                if (fullName == utf8Name.String)
                {
                    ns   = UTF8String.Empty;
                    name = utf8Name;
                    return;
                }

                if (fullName.EndsWith("." + utf8Name.String))
                {
                    ns   = fullName.Substring(0, fullName.Length - utf8Name.String.Length - 1);
                    name = utf8Name;
                    return;
                }
            }

            int i = fullName.LastIndexOf('.');

            if (i < 0)
            {
                ns   = UTF8String.Empty;
                name = fullName;
            }
            else
            {
                ns   = fullName.Substring(0, i);
                name = fullName.Substring(i + 1);
            }
        }
Beispiel #5
0
        static Info?GetInfo(TypeDef td)
        {
            if (td == null)
            {
                return(null);
            }
            if (td.IsWindowsRuntime)
            {
                return(null);
            }

            UTF8String scope = null, identifier = null;
            var        tia = td.CustomAttributes.Find("System.Runtime.InteropServices.TypeIdentifierAttribute");

            if (tia != null)
            {
                if (tia.ConstructorArguments.Count >= 2)
                {
                    if (tia.ConstructorArguments[0].Type.GetElementType() != ElementType.String)
                    {
                        return(null);
                    }
                    if (tia.ConstructorArguments[1].Type.GetElementType() != ElementType.String)
                    {
                        return(null);
                    }
                    scope      = tia.ConstructorArguments[0].Value as UTF8String ?? tia.ConstructorArguments[0].Value as string;
                    identifier = tia.ConstructorArguments[1].Value as UTF8String ?? tia.ConstructorArguments[1].Value as string;
                }
            }
            else
            {
                var mod = td.Module;
                var asm = mod == null ? null : mod.Assembly;
                if (asm == null)
                {
                    return(null);
                }
                bool isTypeLib = asm.CustomAttributes.IsDefined("System.Runtime.InteropServices.ImportedFromTypeLibAttribute") ||
                                 asm.CustomAttributes.IsDefined("System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute");
                if (!isTypeLib)
                {
                    return(null);
                }
            }

            if (UTF8String.IsNull(identifier))
            {
                CustomAttribute gca;
                if (td.IsInterface && td.IsImport)
                {
                    gca = td.CustomAttributes.Find("System.Runtime.InteropServices.GuidAttribute");
                }
                else
                {
                    var mod = td.Module;
                    var asm = mod == null ? null : mod.Assembly;
                    if (asm == null)
                    {
                        return(null);
                    }
                    gca = asm.CustomAttributes.Find("System.Runtime.InteropServices.GuidAttribute");
                }
                if (gca == null)
                {
                    return(null);
                }
                if (gca.ConstructorArguments.Count < 1)
                {
                    return(null);
                }
                if (gca.ConstructorArguments[0].Type.GetElementType() != ElementType.String)
                {
                    return(null);
                }
                scope = gca.ConstructorArguments[0].Value as UTF8String ?? gca.ConstructorArguments[0].Value as string;
                var ns   = td.Namespace;
                var name = td.Name;
                if (UTF8String.IsNullOrEmpty(ns))
                {
                    identifier = name;
                }
                else if (UTF8String.IsNullOrEmpty(name))
                {
                    identifier = new UTF8String(Concat(ns.Data, (byte)'.', empty));
                }
                else
                {
                    identifier = new UTF8String(Concat(ns.Data, (byte)'.', name.Data));
                }
            }
            return(new Info(scope, identifier));
        }