示例#1
0
        private static void LoadDependency(AssemblyName assn, AssemblyObject assObj)
        {
            if (Assembly.GetExecutingAssembly().GetName().Name == assn.Name ||
                Array.ConvertAll(Assembly.GetExecutingAssembly().GetReferencedAssemblies(), (v) => v.Name).Contains(assn.Name))
            {
                return;
            }

            // returned path to assembly should be absolute
            string depPath = assObj.Resolver.ResolveAssemblyToPath(assn);

            if (depPath == null)
            {
                return;
            }
            Assembly ass = assObj.Context.LoadFromAssemblyPath(depPath);

            Log.Core.Info($"[assembly loader] loaded assembly dependency '{Path.GetRelativePath(Environment.CurrentDirectory, depPath)}'");
            {
                var assnArr = ass.GetReferencedAssemblies();
                for (int i = 0; i < assnArr.Length; i++)
                {
                    LoadDependency(assnArr[i], assObj);
                }
            }
        }
示例#2
0
        public static Assembly Load(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }

            path = PathUtils.GetRelativePath(Environment.CurrentDirectory, path);

            AssemblyLoadContext        alc = new AssemblyLoadContext(null, true);
            AssemblyDependencyResolver dr  = new AssemblyDependencyResolver(path);
            Assembly rootAss = alc.LoadFromAssemblyPath(Path.GetFullPath(path));

            Log.Core.Info($"[assembly loader] loaded assembly '{path}'");

            AssemblyObject assemblyObject = new AssemblyObject(alc, dr, rootAss, path);

            _assemblies.Add(path, assemblyObject);

            var assnArr = rootAss.GetReferencedAssemblies();

            for (int i = 0; i < assnArr.Length; i++)
            {
                LoadDependency(assnArr[i], assemblyObject);
            }

            return(rootAss);
        }
示例#3
0
        public ExportedTypeObject(FileStream fs, PEReader pe, MetadataReader mr, ExportedType exportedType, ResolveAssemblyDelegate resolveAssembly) :
            base(fs, pe, mr, resolveAssembly)
        {
            _exportedType = exportedType;

            AssemblyForwardedTo = _resolveAssembly(ToAssemblyName(AssemblyHelpers.GetAssemblyReferenceForExportedType(_metaReader, exportedType)));
        }
示例#4
0
        public TestAssembly(string thisPath, string version, string configuration, string framework)
        {
            Version  = version;
            Location = Path.GetFullPath(Path.Combine(thisPath, "..", "..", "..", "..", "Functions.Dll", "bin", version, configuration, framework, "FunctionsDll.dll"));

            AssemblyObject = Assembly.LoadFile(Location);
            FunctionsType  = AssemblyObject.GetType("Functions.FunctionsDll");
            TestFunction   = FunctionsType.GetMethod("TestFunction");
        }
示例#5
0
        public ReferencedTypeObject(FileStream fs, PEReader pe, MetadataReader mr, TypeReference typeRef, ResolveAssemblyDelegate resolveAssembly) :
            base(fs, pe, mr, resolveAssembly)
        {
            _typeRef = typeRef;

            Name             = AssemblyHelpers.GetTypeName(_metaReader, _typeRef);
            DeclaredAssembly = null;

            // We are not able to resolve ModuleReferences yet.
            if (resolveAssembly != null && _typeRef.ResolutionScope.Kind != HandleKind.ModuleReference)
            {
                var assemblyRef = ToAssemblyName(AssemblyHelpers.GetAssemblyReferenceForReferencedType(_metaReader, _typeRef));
                DeclaredAssembly = resolveAssembly(assemblyRef);
            }
        }
示例#6
0
        private void ButtonLoadDepartment_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Environment.CurrentDirectory;
            openFileDialog1.Filter           = "Assembly files (*.exe;*.dll)|*.exe;*.dll|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;
            //openFileDialog1.RestoreDirectory = true;
#if asdfasdf
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Assembly department     = osalot.LoadAssembly(openFileDialog1.FileName);
                    Type[]   assembly_types = null;
                    try
                    {
                        assembly_types = a.GetTypes();
                    }
                    catch
                    {
                        return;
                    }
                    foreach (Type current_type in assembly_types)
                    {
                        Type[] interfaces;
                        interfaces = current_type.FindInterfaces(MyInterfaceFilter, "SellableItemType");
                        if (interfaces.Length > 0)
                        {
                            object o = Activator.CreateInstance(t);
                            tracker.objects.Add(ao = new AssemblyObject(t, o));
                            SellableItemType department = o as SellableItemType;
                        }
                    }
                }
                catch (Exception e2)
                {
                    Console.WriteLine(e2.Message);
                }
            }
#endif
        }
示例#7
0
        static bool InvokePreload(AssemblyTracker tracker, Type[] assembly_types, EventHandler handler)
        {
            int previous_assemblies = tracker.objects.Count;
            int previous            = core_common.persistant_plugins.Count;

            foreach (Type t in assembly_types)
            {
                Type[] interfaces;
                interfaces = t.FindInterfaces(MyInterfaceFilter, "IReflectorPlugin");
                if (interfaces.Length > 0)
                {
                    AssemblyObject ao;
                    object         o = Activator.CreateInstance(t);
                    tracker.objects.Add(ao = new AssemblyObject(t, o));
                    try
                    {
                        IReflectorPlugin plugin = o as IReflectorPlugin;
                        if (plugin != null)
                        {
                            plugin.Preload();
                            ao.plugin = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.log("Invoke preload threw exception... " + t.ToString() + ":" + ex.Message);
                    }

                    IReflectorPersistance persis = o as IReflectorPersistance;
                    if (persis != null)                      // it's a plugin, and has properties
                    {
                        object[] tags = t.GetCustomAttributes(true);
                        String   name = null;
                        foreach (object tag in tags)
                        {
                            PluginAttribute attr = tag as PluginAttribute;
                            if (attr != null)
                            {
                                name = attr.Name;
                            }
                        }
                        if (name == null)
                        {
                            name = o.ToString();
                        }
                        core_common.persistant_plugins.Add(o);
                        TypeMenuItem tmi = new TypeMenuItem(o, name);
                        InsertMenuItem(core_common.other_drop.DropDown, tmi);
                        tmi.Click += handler;
                    }

                    IReflectorPluginModule module_acceptor = o as IReflectorPluginModule;
                    if (module_acceptor != null)                      // it's a plugin, and has properties
                    {
                        core_common.plugin_module_acceptors.Add(module_acceptor);
                    }
                }
            }
            if (core_common.persistant_plugins.Count > previous ||
                tracker.objects.Count > previous_assemblies)
            {
                return(true);
            }
            return(false);
        }