寻求“混淆器”开源的源代码,要对exe文件进行处理的那种,谢谢

解决方案 »

  1.   

    严重错误的理解。好的混淆器都是直接在编译后的MSIL和PE上面做手脚。你说的那种效率也太低了吧。
      

  2.   

    SharpAssembly
    http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=d5728198-c4d6-4851-96af-1630d59dfe27
    这个是开源的,但是不清楚有没有实现整个的混淆功能,可以到网络上搜索一下,好多Java的混淆器都有开源,只是.NET阵营铜味比较溶,因此开源的比较少(本人估计的)
      

  3.   

    JDK都开源了,算是SUN开了个好头。看看MS吧,就那点.NET框架代码还掖着藏着。
      

  4.   

    SimpleObfuscatorhttp://www.softpedia.com/get/Programming/Other-Programming-Files/SimpleObfuscator.shtml源代码混淆,不过人家已经混淆了,Reflector出来的话自己整理也能得到源代码
      

  5.   

    直接修改CLI,非常简单
    可以做到在Reflector里面看不到方法的具体实现,至于改名字就太小儿科了点
      

  6.   

    to: vwxyzh 愿闻其详谢谢
      

  7.   

    去看Cecil开源工程(See cil的谐音),学习一下,就知道怎么直接玩转了.net的程序集了
    能把程序集改成什么样,就看你脑袋里面能蹦出什么样的想法了
      

  8.   

    SharpAssembly 
    http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=d5728198-c4d6-4851-96af-1630d59dfe27 
    这个是开源的,但是不清楚有没有实现整个的混淆功能,可以到网络上搜索一下,好多Java的混淆器都有开源,只是.NET阵营铜味比较溶,因此开源的比较少(本人估计的) 严重同意。
      

  9.   

    http://www.cnblogs.com/chiname/articles/89477.html
    不知道这个能帮到你吗
      

  10.   

    随便写了个,不过暂时不开源,测试还没完成,Demo而已,不要当真:
    http://download.csdn.net/source/355613
      

  11.   

    vwxyzh 开源吧,大家可以共同研究促进,成立一个队伍也行
      

  12.   

    该说的都说了,先看Cecil,看明白了就简单了
    先贴出混淆的核心代码部分,代码比较乱,而且现在还有Bug,处理某些程序的时候有问题,涉及反射的更是一定出问题,效率也没有考虑过,总之,还在调整中
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;
    using Mono.Cecil;
    using Mono.Cecil.Cil;namespace ReflectorNightmare
    {
        internal sealed class ConfusionNameRebuilder
            : IMemberRebuilder //自定义的接口
        {        #region Fields
            private const MethodAttributes _skipAttribute = MethodAttributes.PInvokeImpl |
                MethodAttributes.UnmanagedExport | MethodAttributes.RTSpecialName;
            private IEnumerator<string> _name = GetName().GetEnumerator();
            #endregion        #region Ctors        public ConfusionNameRebuilder() { }        #endregion        #region Members        private void Exec(TypeDefinition type)
            {
                if (type != null && Match(type))
                    ExecCore(type);
            }        private void Exec(MethodDefinition method)
            {
                if (method != null)
                {
                    if (!IsMethodPublic(method))
                        foreach (ParameterDefinition p in method.Parameters)
                            ExecCore(p);
                    if (Match(method))
                        ExecCore(method);
                }
            }        private void Exec(PropertyDefinition property)
            {
                if (property != null && Match(property))
                    ExecCore(property);
            }        private void Exec(EventDefinition eventDef)
            {
                if (eventDef != null && Match(eventDef))
                    ExecCore(eventDef);
            }        private void Exec(FieldDefinition fieldDef)
            {
                if (fieldDef != null && Match(fieldDef))
                    ExecCore(fieldDef);
            }        private void ExecCore(TypeDefinition type)
            {
                type.Name = GetRandomName(type.Name);
                type.Namespace = string.Empty;
            }        private void ExecCore(MethodDefinition method)
            {
                method.Name = GetRandomName(method.Name);
            }        private void ExecCore(FieldDefinition fieldDef)
            {
                fieldDef.Name = GetRandomName(fieldDef.Name);
            }        private void ExecCore(PropertyDefinition propertyDef)
            {
                propertyDef.Name = GetRandomName(propertyDef.Name);
            }        private void ExecCore(EventDefinition eventDef)
            {
                eventDef.Name = GetRandomName(eventDef.Name);
            }        private void ExecCore(ParameterDefinition paramDef)
            {
                paramDef.Name = GetRandomName(paramDef.Name);
            }        private string GetRandomName(string name)
            {
                _name.MoveNext();
                return _name.Current;
                //return name + ":)"; // for test
            }        private static IEnumerable<string> GetName()
            {
                char[] c = new char[] { '\u0100' };
                while (true)
                {
                    while (c[0]++ < '\ufffd')
                        yield return new string(c);
                    int offset = 1;
                    while (offset < c.Length && c[offset] == '\ufffd')
                        offset++;
                    if (offset == c.Length)
                    {
                        c = new char[offset + 1];
                        c[offset] = '\u0100';
                    }
                    else
                        c[offset]++;
                    while (--offset >= 0)
                        c[offset] = '\u0100';
                    yield return new string(c);
                }
            }        private MethodNameInfo mni = new MethodNameInfo();        private bool Match(MethodDefinition method)
            {
                if (method.IsConstructor)
                    return false;
                if ((method.Attributes & MethodAttributes.RTSpecialName) == MethodAttributes.RTSpecialName)
                    return false;
                TypeDefinition type = method.DeclaringType as TypeDefinition;
                if (type.IsInterface)
                    return false;
                if (Cil.IsDelegate(type))
                    return false;
                bool sp = (method.Attributes & MethodAttributes.PInvokeImpl) == MethodAttributes.PInvokeImpl;
                sp |= (method.Attributes & MethodAttributes.UnmanagedExport) == MethodAttributes.UnmanagedExport;
                sp |= type.GenericParameters.Count > 0;
                sp |= method.GenericParameters.Count > 0;
                if ((method.Attributes & MethodAttributes.Private) == MethodAttributes.Private)
                    return !sp;
                if (sp)
                    mni.AddSkipMethod(method);
                if (method.IsVirtual)
                    return !mni.Add(method) && sp;
                if (sp)
                    return false;
                if ((method.Attributes & MethodAttributes.Public) == MethodAttributes.Public)
                    return !IsTypePublic(type);
                if ((method.Attributes & MethodAttributes.Family) == MethodAttributes.Family)
                    return !IsTypePublic(type);
                return true;
            }        private bool Match(FieldDefinition field)
            {
                // Generic Type's field
                TypeDefinition type = field.DeclaringType as TypeDefinition;
                if (type.GenericParameters.Count > 0)
                    return false;
                // Enum's field
                if ((field.Attributes & FieldAttributes.RTSpecialName) == FieldAttributes.RTSpecialName)
                    return false;
                return !((field.Attributes & FieldAttributes.Public) == FieldAttributes.Public &&
                    (field.Attributes & FieldAttributes.Family) == FieldAttributes.Family &&
                    IsTypePublic(field.DeclaringType as TypeDefinition));
            }        private bool Match(TypeDefinition type)
            {
                return type.GenericParameters.Count == 0 && !IsTypePublic(type);
            }        private bool Match(PropertyDefinition propertyDef)
            {
                TypeDefinition type = propertyDef.DeclaringType as TypeDefinition;
                if (type.IsInterface)
                    return !IsTypePublic(type);
                bool getMatch = propertyDef.GetMethod == null || !IsMethodPublic(propertyDef.GetMethod);
                bool setMatch = propertyDef.SetMethod == null || !IsMethodPublic(propertyDef.SetMethod);
                return getMatch && setMatch;
            }        private bool Match(EventDefinition eventDef)
            {
                TypeDefinition type = eventDef.DeclaringType as TypeDefinition;
                if (type.IsInterface)
                    return !IsTypePublic(type);
                bool addMatch = eventDef.AddMethod == null || !IsMethodPublic(eventDef.AddMethod);
                bool invokeMatch = eventDef.InvokeMethod == null || !IsMethodPublic(eventDef.InvokeMethod);
                bool removeMatch = eventDef.RemoveMethod == null || !IsMethodPublic(eventDef.RemoveMethod);
                return addMatch && invokeMatch && removeMatch;
            }        private bool IsTypePublic(TypeDefinition type)
            {
                TypeAttributes visibility = type.Attributes & TypeAttributes.VisibilityMask;
                if (visibility == TypeAttributes.Public)
                    return true;
                if (visibility == TypeAttributes.NestedPublic || visibility == TypeAttributes.NestedFamily)
                    return IsTypePublic(type.DeclaringType as TypeDefinition);
                return false;
            }        private bool IsMethodPublic(MethodDefinition method)
            {
                if ((method.Attributes & MethodAttributes.Public) == MethodAttributes.Public &&
                    (method.Attributes & MethodAttributes.Family) == MethodAttributes.Family)
                    return IsTypePublic(method.DeclaringType as TypeDefinition);
                return false;
            }
    内容过长继续贴
      

  13.   

    续:
            private void BatchRename(MethodReference[] items)
            {
                foreach (MethodDefinition method in items)
                {
                    if ((method.Attributes & MethodAttributes.Public) == MethodAttributes.Public &&
                        IsTypePublic(method.DeclaringType as TypeDefinition))
                        return;
                    if ((method.Attributes & MethodAttributes.Family) == MethodAttributes.Family &&
                        IsTypePublic(method.DeclaringType as TypeDefinition))
                        return;
                }
                string name = GetRandomName(items[0].Name);
                foreach (MethodReference item in items)
                {
                    item.Name = name;
                    foreach (ParameterDefinition pd in item.Parameters)
                        pd.Name = GetRandomName(pd.Name);
                }
            }        #endregion        #region IMemberRebuilder Members        public void Rebuild(MemberReference member)
            {
                Exec(member as TypeDefinition);
                Exec(member as MethodDefinition);
                Exec(member as PropertyDefinition);
                Exec(member as EventDefinition);
                Exec(member as FieldDefinition);
            }        public void Complete()
            {
                foreach (MethodReference[] items in mni.GetList())
                    BatchRename(items);
            }        public int Priority
            {
                get { return 0; }
            }        public bool IsDeal(RebuilderType type)
            {
                return true;
            }        #endregion    }
    }
      

  14.   

    另一个核心类
    using System;
    using System.Collections.Generic;
    using Mono.Cecil;namespace ReflectorNightmare
    {
        internal class MethodNameInfo
        {        private List<List<MethodReference>> _methodGroup = new List<List<MethodReference>>();
            private List<MethodReference> _skipMethods = new List<MethodReference>();        internal MethodNameInfo() { }        internal bool Add(MethodDefinition method)
            {
                if (method == null)
                    return false;
                if (method.IsConstructor)
                    return false;
                if (method.IsStatic)
                    return false;
                if (method.IsRuntimeSpecialName)
                    return false;
                if (!method.IsVirtual)
                    return false;
                if ((method.Attributes & MethodAttributes.Private) == MethodAttributes.Private)
                    return false;
                TypeDefinition type = method.DeclaringType as TypeDefinition;
                if (Cil.IsDelegate(type))
                    return false;
                bool result = LookupInterface(method, type);
                if (method.IsNewSlot)
                    return result;
                LookupBaseType(method, type);
                return true;
            }        private bool LookupInterface(MethodDefinition method, TypeDefinition type)
            {
                bool result = false;
                foreach (TypeReference tr in type.Interfaces)
                {
                    TypeDefinition td = tr as TypeDefinition;
                    if (td == null)
                    {
                        AddSkipMethod(method);
                        result= true;
                        continue;
                    }
                    foreach (MethodReference interfaceMethod in td.Methods)
                        if (IsMethodMatch(method, interfaceMethod))
                        {
                            AddCore(interfaceMethod, method);
                            result = true;
                            break;
                        }
                }
                return result;
            }        private bool IsMethodMatch(MethodReference x, MethodReference y)
            {
                if (x.Name != y.Name)
                    return false;
                if (x.ReturnType.ReturnType.MetadataToken != y.ReturnType.ReturnType.MetadataToken)
                    return false;
                if (x.Parameters.Count != y.Parameters.Count)
                    return false;
                for (int i = 0; i < x.Parameters.Count; i++)
                    if (x.Parameters[i].ParameterType.MetadataToken != y.Parameters[i].ParameterType.MetadataToken)
                        return false;
                return true;
            }        private void LookupBaseType(MethodDefinition method, TypeDefinition type)
            {
                TypeDefinition current = type.BaseType as TypeDefinition;
                while (current != null)
                {
                    foreach (MethodReference baseMethod in current.Methods)
                        if (IsMethodMatch(method, baseMethod))
                        {
                            AddCore(baseMethod, method);
                            return;
                        }
                    current = current.BaseType as TypeDefinition;
                }
                AddSkipMethod(method);
                return;
            }        private void AddCore(MethodReference mr, MethodDefinition md)
            {
                List<MethodReference> list;
                foreach (List<MethodReference> item in _methodGroup)
                    if (item.Contains(mr))
                    {
                        item.Add(md);
                        return;
                    }
                    else if (item.Contains(md))
                    {
                        item.Add(mr);
                        return;
                    }
                list = new List<MethodReference>();
                list.Add(mr);
                list.Add(md);
                _methodGroup.Add(list);
            }        internal void AddSkipMethod(MethodReference mr)
            {
                if (!_skipMethods.Contains(mr))
                    _skipMethods.Add(mr);
            }        internal List<MethodReference[]> GetList()
            {
                Merge();
                List<MethodReference[]> result = new List<MethodReference[]>(_methodGroup.Count);
                foreach (List<MethodReference> item in _methodGroup)
                    if (CanChangeName(item))
                        result.Add(item.ToArray());
                return result;
            }        private void Merge()
            {
                while (MergeCore()) ;
            }        private bool MergeCore()
            {
                bool result = false;
                for (int i = 0; i < _methodGroup.Count; i++)
                {
                    List<MethodReference> list = _methodGroup[i];
                    for (int j = i + 1; j < _methodGroup.Count; j++)
                    {
                        List<MethodReference> temp = _methodGroup[j];
                        for (int k = 0; k < temp.Count; k++)
                            if (list.Contains(temp[k]))
                            {
                                list.AddRange(temp);
                                _methodGroup.RemoveAt(j);
                                j--;
                                result = true;
                                break;
                            }
                    }
                }
                return result;
            }        private bool CanChangeName(List<MethodReference> list)
            {
                foreach (MethodReference mr in list)
                    if (_skipMethods.Contains(mr))
                        return false;
                return true;
            }
        }}基本上核心就这么点了
      

  15.   

    vwxyzh   能给我整个工程文件吗?谢谢!
      

  16.   

    有必要吗?
    我写的是控制台程序,之前的代码就是解析命令行,加载插件(只要有想象力,写个什么样的插件都有可能),加载命令行中指定的程序,然后就是一个个成员执行Rebuild方法,所有成员执行完毕再调Complete方法
    以及几个看名字就知道的Utility(例如:Cil.IsDelegate(type)这个还需要解释?)Cecil工程+核心代码+外壳部分(控制台/Windows/Asp.net的都可以) 就基本成形了
    lz难道连个外壳都想拿现成的?
      

  17.   

    To: LZ-_-!!!代码已经很完整了...To: vwxyzh混淆器应该直接操作(*.il)文件比较灵活, 结合现成的Ildasm与Ilasm处理可以省很多功夫...同时在处理大程序集时比这种反射方式的性能高得多...纯属个人见解...^o^
      

  18.   

    刚刚查了一下, VS2005->Dotfuscator Community Edition 貌似是使用了我所说的方式...自行分析Msil(这步比较麻烦)-_-!!!
      

  19.   

    Ildasm可以被SuppressIldasmAttribute特性屏蔽
    另外,分析ILAsm似乎比分析IL还难
      

  20.   

    ^o^ SuppressIldasmAttribute 屏蔽特性可以轻意跳过, 只需要对 Ildasm 做少许修改...
      

  21.   

    另外, 我们没有必要对 Ilasm 进行分析的, 只要对IL明文反操作, 最后再用 Ilasm 重编即可...
      

  22.   

    不过, 我深信处理IL明文难度相当大(其实就是分析String), 暂未实践(^o^)...
      

  23.   

    To: shinaterry
    没写清楚我说的ILAsm,不是指ILAsm.exe,而是指IL汇编
      

  24.   

    To: vwxyzh不好意思, 是我理解错误...
      

  25.   

    To:   vwxyzh 主要原因是没有玩过Cecil,找了老半天没有找到Cecil
      

  26.   

    .NET阵营铜味比较溶
    ----------------------------------------------------
    晕了~
      

  27.   

    http://www.mono-project.com/Cecil下载地址在这里
      

  28.   

    http://groups.google.com/group/mono-cecil/web/projects-using-cecil关注,SharpObfuscator 
    http://www.codeplex.com/SharpObfuscator/SourceControl/ListDownloadableCommits.aspx混淆如下,可是无法对字符串进行加密
    private void M16(object sender, EventArgs e)
    {
        string[] match = new string[1];
        this.F57.M10(base.Handle);
        match[0] = this.F59.SelectedItem.ToString();
        this.F57.M11(match, true);
        this.F57.M10(base.Handle);
        this.M18();
    }
      

  29.   

    SharpObfuscator   确实不错。如何增加字符串加密的IL代码?如何从exe、dll中提取出字符串代码?
      

  30.   

    SharpObfuscator       针对我的带签名的,多DLL的混淆,混淆之后没有办法运行
      

  31.   

    SharpObfuscator不错,学习一下怎么混淆泛型类和泛型方法
    不过,混淆效果有点差,内部的接口方法不混淆,内部的虚方法不混淆,字段不混淆,属性混淆还没完成To: cellblue
    带签名的还混淆啊,混淆出来能跑的话,就可以去骂MS的签名是骗人的了(除非不用强名的引用)
      

  32.   

    我使用XENOCODE可以混淆,而且还能组成同一个exe文件,或者多文件也可以
      

  33.   

    To:vwxyzh 我看你也是这方面的专家,请问如何对里面的字符串进行加密?
      

  34.   

    郁闷! 字符串加密, 无非是在混淆时利用加密算法对ldstr指令标记的字符串进行加密...而在此指令后动态织入解密算法的相关指令, 所谓保护强度实际上是建立在算法基础上...
      

  35.   

    shinaterry 提议提议还有什么实现方法,或许我可以在我的程序中预先加入加密算法