您的位置:首页 > 编程语言 > C#

C# dll反混淆,反编译

2015-09-29 13:35 519 查看
C#的源代码通过编译,会变成中间语言,dll程序集。如果我们想看源代码,需要反编译。有些代码经过了混淆,就需要反混淆。

我们先通过反编译软件Reflector,把dll中的代码反编译下。这里只要打开reflector,然后引入这个dll就行。

经过混淆的代码,如下

public static BaseSqlGenerator GetSqlGenerator(ModelConfigOptions cfgOptions, string[] properties)
{
BaseSqlGenerator generator = null;
if ((cfgOptions & ModelConfigOptions.CreateSqlByXmlCfg) == ModelConfigOptions.None)
{
Label_005A:
if (_AutoSqlCreate == null)
{
_AutoSqlCreate = new AutoMappingSqlGenerator();
if (4 == 0)
{
if (0 == 0)
{
}
goto Label_002B;
}
if (3 != 0)
{
goto Label_0061;
}
if (2 != 0)
{
goto Label_005A;
}
}
else
{
goto Label_0061;
}
}
if (_XmlSqlConfigObject == null)
{
_XmlSqlConfigObject = new XmlConfigSqlGenerator();
}
generator = _XmlSqlConfigObject;
if (2 == 0)
{
return generator;
}
goto Label_004B;
Label_002B:
if (_AutoSqlCreate == null)
{
_AutoSqlCreate = new AutoMappingSqlGenerator();
}
Label_0032:
return _AutoSqlCreate;
Label_004B:
if (properties == null)
{
return generator;
}
if (8 == 0)
{
goto Label_0032;
}
if (((3 == 0) && (0 == 0)) && ((0 == 0) && (-1 != 0)))
{
if (0 == 0)
{
return generator;
}
goto Label_0032;
}
if (properties.Length <= 0)
{
return generator;
}
goto Label_002B;
Label_0061:
generator = _AutoSqlCreate;
goto Label_004B;
}

让人实在是费解。一般,通过反混淆,可以得到清楚的代码。我们通过de4dot工具反混淆下,
反混淆步骤如下:

通过cmd命令: F:\我的文件\安装文件\de4dot-2.0.3\de4dot-2.0.3>de4dot.exe
C:\Users\hq01ub721\Des

ktop\MB.ORM.dll

就会在同一级目录下生成一个叫...clean的程序集。然后再通过reflector工具打开着个dll。

下面是对dll反混淆后的代码

public static BaseSqlGenerator GetSqlGenerator(ModelConfigOptions cfgOptions, string[] properties)
{
BaseSqlGenerator generator = null;
if ((cfgOptions & ModelConfigOptions.CreateSqlByXmlCfg) != ModelConfigOptions.None)
{
if (_XmlSqlConfigObject == null)
{
_XmlSqlConfigObject = new XmlConfigSqlGenerator();
}
generator = _XmlSqlConfigObject;
}
else
{
if (_AutoSqlCreate == null)
{
_AutoSqlCreate = new AutoMappingSqlGenerator();
}
generator = _AutoSqlCreate;
}
if ((properties == null) || (properties.Length <= 0))
{
return generator;
}
if (_AutoSqlCreate == null)
{
_AutoSqlCreate = new AutoMappingSqlGenerator();
}
return _AutoSqlCreate;
}



这样就清楚多了。这代码会跟源码有点点区别,因为编译过程中,编译器帮你优化了一些语句,但是逻辑是不会改变的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# 源代码