本文为看雪论坛优秀文章
看雪论坛作者ID:一枝笔
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
namespace dessttrrr
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Users\admin1\Desktop\新建文件夹\newDll"; //调用dll路径
Assembly assem = Assembly.LoadFile(path);
Type[] tys;
try
{
tys = assem.GetTypes();
int i = 0;
string []mystr=new string[10000];
int j = 0;
foreach (Type ty in tys)//遍历查找类名
{
if (ty.Name == "Program")
{
for (; i < 10000; ++i)
{
ConstructorInfo magicConstructor = ty.GetConstructor(Type.EmptyTypes);
object magicClassObject = magicConstructor.Invoke(new object[] { });//获取一个类实例
object[] paramertors = new object[] { i }; //需要传入的参数
MethodInfo[] methods = ty.GetMethods();
MethodInfo mi = ty.GetMethod("getStr"); //获取方法
object aa = mi.Invoke(magicClassObject, paramertors);
int flag = String.Compare("", aa.ToString());
if (flag != 0)
{
int flag2 = aa.ToString()[0];//去除乱码
if (flag2 < 255)
{
mystr[j] = i.ToString() + ": " + aa.ToString() + "\n";
++j;
}
}
}
File.WriteAllLines("str.txt", mystr, Encoding.Default);
}
}
}
catch (ReflectionTypeLoadException ex)
{
// now look at ex.LoaderExceptions - this is an Exception[], so:
foreach (Exception inner in ex.LoaderExceptions)
{
// write details of"inner", in particular inner.Message
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PrivateImplementationDetails;
using System.Reflection;
using System.IO;
namespace getstr
{
class Program
{
static void Main(string[] args)
{
try
{
string[] mystr = new string[10000];
Type type = typeof(Class0);
object obj = Activator.CreateInstance(type);
ConstructorInfo magicConstructor = type.GetConstructor(Type.EmptyTypes);
// 获取所有方法。
MethodInfo[] methods = type.GetMethods();
object magicClassObject = magicConstructor.Invoke(new object[] { });
int i = 0;
foreach (MethodInfo method in methods)//遍历方法
{
MethodInfo mi = type.GetMethod(method.Name);
if (method.Name.Length < 3)//解密的方法名称长度都不大于,以此来过滤掉其他函数
{
object aa = mi.Invoke(magicClassObject, new object[] { });
mystr[i] = "_" + method.Name+"__: "+aa.ToString() + "\n";
++i;
}
}
File.WriteAllLines("newstr.txt", mystr, Encoding.Default);
}
catch (ReflectionTypeLoadException ex)
{
// now look at ex.LoaderExceptions - this is an Exception[], so:
foreach (Exception inner in ex.LoaderExceptions)
{
// write details of"inner", in particular inner.Message
}
}
}
}
}
看雪ID:一枝笔
https://bbs.pediy.com/user-home-875523.htm
# 往期推荐
4.协议分析实战
球分享
球点赞
球在看
点击“阅读原文”,了解更多!