111,111
社区成员




new Thread(Test) { IsBackground = true }.Start();
//=================
private void Test() {
int i = 0;
IServerVul iv = ServerVulPluginLoader.PluginLoader.GetPluginFromFile(Application.StartupPath + "/testplugin.dll");
//Console.WriteLine(iv.CheckVul("http://fuck.acunetix.com", 0, 5000));
while (true) {//一直循环让他报错(事实上 第一次访问就会出错 以前是看概率)
try {
Console.WriteLine(iv.CheckVul("http://fuck.acunetix.com", 0, 5000));
//用一个不纯在的域名去访问 让它出异常
} catch { }//这里也捕捉不了任何异常
this.BeginInvoke(new MethodInvoker(() => this.Text = (i++).ToString()));
Thread.Sleep(1);
}
}
public static xxxx(xx...){
HttpWebRequest...
try{
...
} catch (WebException ex){
//这里就是刚才上面截图部分
}
}
public string CheckVul(string strIp, int nPort, int nTimeout) {
try {
WebHelper.Test();//直接调用上面截图中的函数
} catch { }//捕捉不了
return "TRUE";
}
public class PluginLoader
{
public static IServerVul GetPluginFromFile(string strFile) {
IServerVul iPlugin = null;
string strSuffix = Regex.Match(strFile, @"\.\w+$", RegexOptions.IgnoreCase).Value.Trim().ToLower();
switch (strSuffix) {
case ".dll": iPlugin = PluginLoader.GetInterfaceFromDotNet(strFile); break;
case ".py": iPlugin = PluginLoader.GetInterfaceFromPython(strFile); break;
default: throw new ArgumentException("Can not load plugin from type[" + strSuffix + "] filename:" + strFile);
}
return iPlugin;
}
public static IServerVul GetInterfaceFromDotNet(string strFileName) {
try {
Assembly asm = Assembly.LoadFile(strFileName);
foreach (var t in asm.GetTypes()) {
if (t.GetInterface("IServerVul") != null) {
return (IServerVul)Activator.CreateInstance(t);
}
}
} catch (ReflectionTypeLoadException ex) {
throw new ReflectionTypeLoadException(ex.Types, ex.LoaderExceptions, ex.Message + "\r\n" + strFileName);
}
return null;
}
public static IServerVul GetInterfaceFromPython(string strFileName) {
return new PyServerVulPlugin(strFileName);
}
}
public static void Test()
{
IPlugin i = GetInterfaceFromDotNet(System.IO.Path.Combine(Environment.CurrentDirectory, @"plugin.dll"));
try
{
i.Foo("test");
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
public string Foo(string str)
{
try { StaticMethod.Test(); }
catch { }
return "test";
}
public string Foo(string str)
{
try { StaticMethod.Test(); }
catch { Console.WriteLine("ooo"); }
return "test";
}
public string Foo(string str)
{
try { StaticMethod.Test(); }
catch(Exception ex) { Console.WriteLine(ex); }
return "test";
}
调用的地方
string str = i.Foo("test");
Console.WriteLine(str);
最后都输出了test
在vs里还是会弹出未捕获异常的框
证明运行时这个异常确实被Plugin里的trycatch捕获了,只不过调试时vs认为没有处理,仅此而已,并不影响最终的程序