示例#1
0
 /// <summary>
 /// 动态调用DLL
 /// </summary>
 /// <param name="DllFileName">dll名称</param>
 /// <param name="NameSpace">命名空间</param>
 /// <param name="ClassName">类名</param>
 /// <param name="MethodName">方法名</param>
 /// <param name="ObjArrayParams">参数数组</param>
 /// <returns></returns>
 public static object DllInvoke(string DllFileName, string NameSpace, string ClassName, string MethodName, params object[] ObjArrayParams)
 {
     try
     {
         //载入程序集
         Assembly DllAssembly = Assembly.LoadFrom(DllFileName);
         Type[]   DllTypes    = DllAssembly.GetTypes();
         foreach (Type DllType in DllTypes)
         {
             //查找要调用的命名空间及类
             if (DllType.Namespace == NameSpace && DllType.Name == ClassName)
             {
                 //查找要调用的方法并进行调用
                 MethodInfo MyMethod = DllType.GetMethod(MethodName);
                 if (MyMethod != null)
                 {
                     object mObject = Activator.CreateInstance(DllType);
                     return(MyMethod.Invoke(mObject, ObjArrayParams));
                 }
             }
         }
     }
     catch (Exception)
     {
         //MessageBoxHelper.ShowError(mEx.Message);
     }
     return((object)0);
 }
示例#2
0
        /// <summary>
        /// 除外ファイルか判定
        /// </summary>
        /// <param name="iFullPath">フルパス</param>
        /// <returns>除外対象ファイルの場合True</returns>
        private bool IsIgnoreFile(string iFullPath)
        {
            string filename = Path.GetFileName(iFullPath).ToLower();
            string dirname  = Path.GetDirectoryName(iFullPath).ToLower();
            // DllTypeでチェック
            DllType dllType = DllTypeExt.GetDllType(iFullPath);

            if (dllType == DllType.Nothing)
            {
                return(true);
            }
            if (!settings.DllTypeInfoList[dllType].Enable)
            {
                return(true);
            }

            // IgnorePathでチェック
            foreach (var ignorePath in settings.IgnorePathList)
            {
                if (!ignorePath.Enable || ignorePath.Path.Length == 0)
                {
                    continue;
                }
                if (dirname.IndexOf(ignorePath.Path.ToLower()) >= 0)
                {
                    if ((dllType == DllType.EliteAPI && ignorePath.EliteAPI) ||
                        (dllType == DllType.EliteMMOAPI && ignorePath.EliteMMOAPI))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#3
0
        /// <summary>
        /// DLLを置換メインスレッド
        /// </summary>
        private void ExecuteReplaceThread()
        {
            try
            {
                this.IsRunningReplace = true;
                if (!IsReplaceOK())
                {
                    this.StatusMessage = Resources.MsgExecuteAfterDownload;
                    SystemSounds.Hand.Play();
                    return;
                }

                int count = 0;
                foreach (var target in this.DllList)
                {
                    if (!this.IsRunningReplace)
                    {
                        return;
                    }
                    if (!target.Enable)
                    {
                        continue;
                    }
                    //コピー元のファイルパス決定
                    DllType dllType = DllTypeExt.GetDllType(target.Path);
                    if (dllType == DllType.Nothing)
                    {
                        continue;
                    }
                    string sourcePath = GetSourcePath(dllType);
                    //ファイルコピー
                    if (target.Enable)
                    {
                        Console.WriteLine("処理中 {0} {1}", sourcePath, target.Path);
                        this.StatusMessage = string.Format(Resources.MsgReplace, target.Path);
                        if (!CopyDll(sourcePath, target.Path))
                        {
                            this.StatusMessage = string.Format(Resources.MsgErrorReplace, target.Path);
                            break;
                        }
                        count++;
                    }
                }
                this.StatusMessage = string.Format(Resources.MsgReplaced, count);
                SystemSounds.Asterisk.Play();
            }
            catch (Exception e)
            {
                this.StatusMessage = string.Format(Resources.MsgError, e.Message);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                SystemSounds.Hand.Play();
            }
            finally
            {
                this.IsRunningReplace = false;
            }
        }
        public static bool IsManagedAssembly(string file)
        {
            DllType dllType = InternalEditorUtility.DetectDotNetDll(file);

            if (dllType != DllType.Unknown)
            {
                return(dllType != DllType.Native);
            }
            return(false);
        }
示例#5
0
 /// <summary>
 /// DLLが保存されているパスを返す
 /// </summary>
 /// <param name="iDllFilename">保存パスに追加するファイル名</param>
 /// <returns>DLL保存パス</returns>
 private string GetSourcePath(DllType iDllType = DllType.Nothing)
 {
     if (iDllType == DllType.Nothing)
     {
         return(Path.Combine(".", Constants.PathSourceDll));
     }
     else
     {
         return(Path.Combine(".", Constants.PathSourceDll, iDllType.GetFileName()));
     }
 }
示例#6
0
        public static string GetFileName(this DllType iDllType)
        {
            Dictionary <DllType, string> filenames = new Dictionary <DllType, string>()
            {
                { DllType.EliteAPI, Constants.FilenameEliteAPI },
                { DllType.EliteMMOAPI, Constants.FilenameEliteMMOAPI },
                { DllType.Nothing, string.Empty },
            };

            return(filenames[iDllType]);
        }
示例#7
0
 /// <summary>
 /// DLLをインターネットよりダウンロード
 /// </summary>
 /// <param name="iDllType">DllType</param>
 /// <returns>成功した場合True</returns>
 private bool DownloadDll(DllType iDllType)
 {
     try
     {
         DllTypeInfo dll = settings.DllTypeInfoList[iDllType];
         if (!dll.Enable || dll.DownloadUrl.Length == 0 || dll.Filename.Length == 0)
         {
             return(false);
         }
         // DLL保存ディレクトリ作成
         string path = GetSourcePath();
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         // ダウンロード
         string downloadFilename = Path.Combine(GetSourcePath(), Constants.FilenameTemp);
         if (File.Exists(downloadFilename))
         {
             File.Delete(downloadFilename);
         }
         using (WebClient wc = new WebClient())
         {
             if (settings.Proxy.Enable)
             {
                 string proxy = string.Format("http://{0}:{1}", settings.Proxy.Server, settings.Proxy.Port);
                 wc.Proxy = new WebProxy(proxy);
             }
             wc.Encoding = Encoding.UTF8;
             wc.DownloadFile(dll.DownloadUrl, downloadFilename);
         }
         // ファイル移動
         string destFilename = Path.Combine(GetSourcePath(), dll.Filename);
         if (File.Exists(destFilename))
         {
             File.Delete(destFilename);
         }
         File.Move(downloadFilename, destFilename);
         // バージョン取得
         RefreshDllVersion();
         return(true);
     }
     catch (Exception e)
     {
         string msg = string.Format(Resources.MsgVersionUpFor, iDllType, e.Message);
         throw new Exception(msg, e);
     }
 }
示例#8
0
        /// <summary>
        /// DLL配布ページから、バージョンアップが必要か判定
        /// </summary>
        /// <param name="iDllType">DLL種別</param>
        /// <param name="oXPathData">判定用文字列</param>
        /// <returns>バージョンアップが必要な場合True</returns>
        private bool MasterVersionCheck(DllType iDllType, out string oXPathData)
        {
            try
            {
                oXPathData = string.Empty;
                DllTypeInfo dll = settings.DllTypeInfoList[iDllType];
                if (!dll.Enable || dll.XPath.Length == 0 || dll.CheckUrl.Length == 0)
                {
                    return(false);
                }

                using (WebClient wc = new WebClient())
                {
                    if (settings.Proxy.Enable)
                    {
                        string proxy = string.Format("http://{0}:{1}", settings.Proxy.Server, settings.Proxy.Port);
                        wc.Proxy = new WebProxy(proxy);
                    }
                    wc.Encoding = Encoding.UTF8;
                    string html = wc.DownloadString(dll.CheckUrl);

                    HtmlDocument htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(html);
                    HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes(dll.XPath);
                    if (nodes != null && nodes.Count == 1)
                    {
                        string val = nodes[0].InnerText.Replace("\r", "").Replace("\n", "").Trim();
                        if (dll.XPathData != val)
                        {
                            oXPathData = val;
                            return(true);
                        }
                    }
                    else
                    {
                        throw new Exception(Resources.MsgXPathNotExist);
                    }
                }
                return(false);
            }
            catch (Exception e)
            {
                string msg = string.Format(Resources.MsgCheckingFor, iDllType, e.Message);
                throw new Exception(msg, e);
            }
        }
示例#9
0
        /// <summary>
        /// 加载DLL的方法 不支持重载方法 速度慢
        /// </summary>
        /// <example>
        /// <code>
        /// Safe.DllInvoke("../bin/Pub.Class.dll".GetMapPath(), "Pub.Class", "Session2", "Set", new object[] { "test", "3" });
        /// Msg.Write(Safe.DllInvoke("../bin/Pub.Class.dll".GetMapPath(), "Pub.Class", "Session2", "Get", new object[] { "test" }));
        /// </code>
        /// </example>
        /// <param name="DllFileName">dll全路径</param>
        /// <param name="NameSpace">命名空间</param>
        /// <param name="ClassName">类名</param>
        /// <param name="MethodName">方法名</param>
        /// <param name="ObjArrayParams">参数</param>
        /// <returns>返回值</returns>
        public static object DllInvoke(string DllFileName, string NameSpace, string ClassName, string MethodName, object[] ObjArrayParams)
        {
            Assembly DllAssembly = Assembly.LoadFrom(DllFileName);

            Type[] DllTypes = DllAssembly.GetTypes();
            foreach (Type DllType in DllTypes)
            {
                if (DllType.Namespace == NameSpace && DllType.Name == ClassName)
                {
                    MethodInfo MyMethod = DllType.GetMethod(MethodName);
                    if (MyMethod.IsNotNull())
                    {
                        object mObject = Activator.CreateInstance(DllType);
                        return(MyMethod.Invoke(mObject, ObjArrayParams));
                    }
                }
            }
            return((object)0);
        }
示例#10
0
 private static bool IsValidIoTDll(DllType dllType, bool isUAP)
 {
     return(dllType == DllType.WindowsIoT || (isUAP && dllType == DllType.WindowsIoTUAP) || (!isUAP && dllType == DllType.WindowsIoTNonUAP));
 }
示例#11
0
文件: Dlls.cs 项目: rohme/DllUpdater
        /// <summary>
        /// DLL配布ページから、バージョンアップが必要か判定
        /// </summary>
        /// <param name="iDllType">DLL種別</param>
        /// <param name="oXPathData">判定用文字列</param>
        /// <returns>バージョンアップが必要な場合True</returns>
        private bool MasterVersionCheck(DllType iDllType, out string oXPathData)
        {
            try
            {
                oXPathData = string.Empty;
                DllTypeInfo dll = settings.DllTypeInfoList[iDllType];
                if (!dll.Enable || dll.XPath.Length == 0 || dll.CheckUrl.Length == 0) return false;

                using (WebClient wc = new WebClient())
                {
                    if (settings.Proxy.Enable)
                    {
                        string proxy = string.Format("http://{0}:{1}", settings.Proxy.Server, settings.Proxy.Port);
                        wc.Proxy = new WebProxy(proxy);
                    }
                    wc.Encoding = Encoding.UTF8;
                    string html = wc.DownloadString(dll.CheckUrl);

                    HtmlDocument htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(html);
                    HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes(dll.XPath);
                    if (nodes != null && nodes.Count == 1)
                    {
                        string val = nodes[0].InnerText.Replace("\r", "").Replace("\n", "").Trim();
                        if (dll.XPathData != val)
                        {
                            oXPathData = val;
                            return true;
                        }
                    }
                    else
                    {
                        throw new Exception(Resources.MsgXPathNotExist);
                    }
                }
                return false;
            }
            catch (Exception e)
            {
                string msg = string.Format(Resources.MsgCheckingFor, iDllType, e.Message);
                throw new Exception(msg, e);
            }
        }
示例#12
0
文件: Dlls.cs 项目: rohme/DllUpdater
 /// <summary>
 /// DLLが保存されているパスを返す
 /// </summary>
 /// <param name="iDllFilename">保存パスに追加するファイル名</param>
 /// <returns>DLL保存パス</returns>
 private string GetSourcePath(DllType iDllType = DllType.Nothing)
 {
     if (iDllType == DllType.Nothing)
         return Path.Combine(".", Constants.PathSourceDll);
     else
         return Path.Combine(".", Constants.PathSourceDll, iDllType.GetFileName());
 }
示例#13
0
文件: Dlls.cs 项目: rohme/DllUpdater
 /// <summary>
 /// DLLをインターネットよりダウンロード
 /// </summary>
 /// <param name="iDllType">DllType</param>
 /// <returns>成功した場合True</returns>
 private bool DownloadDll(DllType iDllType)
 {
     try
     {
         DllTypeInfo dll = settings.DllTypeInfoList[iDllType];
         if (!dll.Enable || dll.DownloadUrl.Length == 0 || dll.Filename.Length == 0) return false;
         // DLL保存ディレクトリ作成
         string path = GetSourcePath();
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         // ダウンロード
         string downloadFilename = Path.Combine(GetSourcePath(), Constants.FilenameTemp);
         if (File.Exists(downloadFilename)) File.Delete(downloadFilename);
         using (WebClient wc = new WebClient())
         {
             if (settings.Proxy.Enable)
             {
                 string proxy = string.Format("http://{0}:{1}", settings.Proxy.Server, settings.Proxy.Port);
                 wc.Proxy = new WebProxy(proxy);
             }
             wc.Encoding = Encoding.UTF8;
             wc.DownloadFile(dll.DownloadUrl, downloadFilename);
         }
         // ファイル移動
         string destFilename = Path.Combine(GetSourcePath(), dll.Filename);
         if (File.Exists(destFilename)) File.Delete(destFilename);
         File.Move(downloadFilename, destFilename);
         // バージョン取得
         RefreshDllVersion();
         return true;
     }
     catch (Exception e)
     {
         string msg = string.Format(Resources.MsgVersionUpFor, iDllType, e.Message);
         throw new Exception(msg, e);
     }
 }
示例#14
0
 private static bool IsValidIoTDll(DllType dllType, bool isUAP)
 {
     return (dllType == DllType.WindowsIoT || (isUAP && dllType == DllType.WindowsIoTUAP) || (!isUAP && dllType == DllType.WindowsIoTNonUAP));
 }
        /// <summary>
        /// the generic load routine for the system. The exported routines lead here
        /// </summary>
        /// <param name="TargetFormatClassCheck">specific null to skip this check. Called to see if the exported type is a match <seealso cref="TargetClassLoadName"/></param>
        /// <param name="TargetFormatClassString">if TargetFormatClassCheck is null checked class names are compaired against it</param>
        /// <param name="VerifyCallback">prevent unwanted assemblys from being used. <seealso cref="AssemblyCheck"/></param>
        /// <param name="VerifyAssemblyString">if Verifycallback is null, this is case sensisite compared with the FullName of the loaded assembly. No match means no go</param>
        /// <param name="DllLocation">load the dll from here</param>
        /// <param name="SubDomain">name of AppDomain created from the parent subdomain</param>
        /// <param name="MaxOverflow">load nore than MaxOverflow if > 0. Set negative to disable cap</param>
        /// <param name="Overflow">on exit contained additional loaded and instanced types</param>
        /// <returns></returns>
        private T LoadPlugin(TargetClassLoadName TargetFormatClassCheck,
                             string TargetFormatClassString,
                             AssemblyCheck VerifyCallback,
                             string VerifyAssemblyString,
                             string DllLocation,
                             string SubDomain,
                             int MaxOverflow,
                             out List <T> Overflow)
        {
            T Iterate = null;
            T ret     = null;

            Overflow = null;
            if (MaxOverflow < 0)
            {
                Overflow = new List <T>();
            }

            /*
             * redundant but get point accross
             * if (MaxOverflow == 0)
             * {
             *  Overflow = null;
             * }*/

            if (MaxOverflow >= 1)
            {
                Overflow = new List <T>(MaxOverflow);
            }

            Tool_DuplicateDomain(FormatContainer, SubDomain, out AppDomain Probe);

            AssemblyResolver_DynamicClassLoader tiny = new AssemblyResolver_DynamicClassLoader();

            Probe.AssemblyResolve += new ResolveEventHandler(tiny.Probe_AssemblyResolve);

            Assembly Dll = Probe.Load(DllLocation);

            if (VerifyCallback != null)
            {
                if (VerifyCallback(Dll) == false)
                {
                    throw new InvalidOperationException("Dll: " + Path.GetFileName(DllLocation) + " did not pass VerifyCheck");
                }
            }
            else
            {
                if (VerifyAssemblyString != null)
                {
                    if (Dll.FullName.Contains(VerifyAssemblyString) == false)
                    {
                        throw new InvalidOperationException("Dll: " + Path.GetFileName(DllLocation) + " did not pass VerifyCheck");
                    }
                }
            }


            foreach (Type DllType in  Dll.GetExportedTypes())
            {
                /*
                 * FUTURE ME: PAST ME WAS SLEEPY.
                 * This code is indended to check 3 scenerios for a match
                 *
                 *  #1
                 * TargetFormatClassCheck delegate is not null and returns true on call
                 *
                 * #2
                 *  TargetFormatClassCheck delegate is null, and the string is contained within the type's fullname if not zero
                 *
                 *  #3
                 *  both TargetClassCheck delegate is null and the string is null (this matches any)
                 *
                 *
                 *  Reason at the time is to consalodate the instance creation code on  match
                 *  YOUR THANK ME LATER FOR THIS COMMENT,
                 *  PAST ME
                 *
                 *      Follow Up:  Catch Generic Routines and things man or the .net runtime was not ment to instance in a Try Catch block
                 */
                /*if (((TargetFormatClassCheck != null) &&
                 * (TargetFormatClassCheck(DllType.FullName, DllType.GetTypeInfo()) == true))
                 ||
                 || ((TargetFormatClassString != null)) && ((TargetFormatClassString != null) && (DllType.FullName.Contains(TargetFormatClassString) == true))
                 ||
                 ||(TargetFormatClassString == null) && (TargetFormatClassCheck == null)) */

                if (TargetFormatClassCheck != null)
                {
                    if (TargetFormatClassCheck(DllType.FullName, DllType.GetTypeInfo()) == false)
                    {
                        continue;
                    }
                }
                if (TargetFormatClassString != null)
                {
                    if (DllType.FullName.Contains(TargetFormatClassString) == false)
                    {
                        continue;
                    }
                }


                {
                    // it's a match
                    Iterate = new T();
                    {
                        Iterate.Domain         = Probe;
                        Iterate.Handler        = Activator.CreateInstance(DllType);
                        Iterate.HandlerType    = DllType;
                        Iterate.LoadedAssembly = Dll;
                    };
                    if (ret == null)
                    {
                        ret = Iterate;
                        if (MaxOverflow == 0)
                        {
                            break;
                        }
                        else
                        {
                            if (MaxOverflow > 0)
                            {
                                MaxOverflow--;
                            }
                        }
                    }
                    else
                    {
                        Overflow.Add(Iterate);
                        MaxOverflow--;
                    }
                }
            }


            if (ret == null)
            {
                // no matches
                AppDomain.Unload(Probe);
                Overflow.Clear();
                Overflow = null;
            }
            return(ret);
        }
示例#16
0
        static bool IsManagedAssembly(string systemPath)
        {
            DllType dllType = InternalEditorUtility.DetectDotNetDll(systemPath);

            return(dllType != DllType.Unknown && dllType != DllType.Native);
        }