Ejemplo n.º 1
0
        private string GetAssemblyIdentity(string fileName)
        {
            IntPtr num1    = (IntPtr)0;
            IntPtr num2    = (IntPtr)0;
            IntPtr hGlobal = (IntPtr)0;
            IntPtr num3    = (IntPtr)0;

            try
            {
                num1 = Win32ManifestGenerator.LoadLibrary(fileName);
                if (num1 == (IntPtr)0)
                {
                    throw new ApplicationException(string.Format("Failed to load library on referenced unmanaged dll '{0}'", (object)fileName));
                }
                IntPtr resource = Win32ManifestGenerator.FindResource(num1, 1, 24);
                if (resource == (IntPtr)0)
                {
                    throw new ApplicationException(string.Format("Win32 manifest does not exist referenced unmanaged dll '{0}'", (object)fileName));
                }
                hGlobal = Win32ManifestGenerator.LoadResource(num1, resource);
                if (hGlobal == (IntPtr)0)
                {
                    throw new ApplicationException(string.Format("Win32 manifest failed to load for referenced unmanaged dll '{0}'", (object)fileName));
                }
                IntPtr ptr = Win32ManifestGenerator.LockResource(hGlobal);
                if (Win32ManifestGenerator.SizeofResource(num1, resource) == 0)
                {
                    throw new ApplicationException(string.Format("Win32 manifest of referenced unmanaged dll '{0}' is empty", (object)fileName));
                }
                string stringAnsi = Marshal.PtrToStringAnsi(ptr);
                int    startIndex = stringAnsi.IndexOf("<assemblyIdentity", 0);
                int    num4       = stringAnsi.IndexOf("/>", startIndex);
                return(stringAnsi.Substring(startIndex, num4 + 2 - startIndex));
            }
            finally
            {
                if (hGlobal != (IntPtr)0)
                {
                    Win32ManifestGenerator.FreeResource(hGlobal);
                }
                if (num1 != (IntPtr)0)
                {
                    Win32ManifestGenerator.FreeLibrary(num1);
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string manifest       = string.Empty;
            string assembly       = string.Empty;
            bool   willBeManifest = false;
            bool   willBeAssembly = false;

            for (int i = 0; i < args.Length; ++i)
            {
                var arg = args[i];
                if (arg == "-manifest")
                {
                    willBeManifest = true;
                }
                else if (arg == "-assembly")
                {
                    willBeAssembly = true;
                }
                else if (willBeManifest)
                {
                    manifest = arg;
                }
                else if (willBeAssembly)
                {
                    assembly = arg;
                }
            }
            if (string.IsNullOrEmpty(assembly) || string.IsNullOrEmpty(manifest))
            {
                Console.WriteLine("usage: genman32_45 -assembly assembly_full_path -manifest output_manifest");
                Environment.Exit(-1);
            }
            Win32ManifestGenerator generator = new Win32ManifestGenerator();

            generator.GenerateWin32ManifestFile(manifest, assembly, false, "", ".");
            Environment.Exit(0);
        }