Ejemplo n.º 1
0
        public void LoadAssembly(String asm)
        {
            if (!File.Exists(asm))
            {
                throw new Exception(String.Format("Assembly file '{0}' does not exist! Load failed.", asm));
            }

            String extension = Path.GetExtension(asm).ToLower();

            if (extension == ".pe")
            {
                _emulatorNative.LoadPE(asm);
            }
            else if (extension == ".dat")
            {
                _emulatorNative.LoadDatabase(asm);
            }
            else if (extension == ".manifest" || extension == ".exe" || extension == ".dll")
            {
                String manifestPath = asm;

                if (extension == ".exe" || extension == ".dll")
                {
                    manifestPath += ".manifest";
                }

                if (!File.Exists(manifestPath))
                {
                    throw new Exception(String.Format("Manifest file '{0}' does not exist! Load failed.", manifestPath));
                }

                Manifest manifest = ManifestReader.ReadManifest(manifestPath, false);

                String manifestDirectoryPath = Path.GetDirectoryName(manifestPath);
                String exePePath             = FullPathToPe(manifestDirectoryPath, manifest.EntryPoint.TargetPath);

                foreach (AssemblyReference ar in manifest.AssemblyReferences)
                {
                    if (ar.AssemblyIdentity.Name == "Microsoft.Windows.CommonLanguageRuntime")
                    {
                        continue; // the manifest will always include the desktop CLR, which we will to ignore.
                    }
                    String pePath = FullPathToPe(manifestDirectoryPath, ar.TargetPath);
                    if (pePath == exePePath) // Skip this one for now to do last
                    {
                        continue;
                    }

                    LoadAssembly(pePath);
                }

                LoadAssembly(exePePath);
            }
            else
            {
                throw new Exception("Unrecognized assembly format: " + asm);
            }
        }