尝试使用dnlib写入字符串时出现System.OutOfMemoryException

我使用dnlib做我的第一个混淆器。当我想写我的字符串时,会抛出一个异常,并且我不知道如何解决该问题(我尝试用字节数组加载它,但是没有任何工作)。

我的代码就是这个:

private void defindTyoe(ModuleDefMD module)
{
    foreach(TypeDef type in module.Types)
    {
        foreach(MethodDef method in type.Methods)
        {
            if (method.Body == null) continue;
            for(int i = 0; i < method.Body.Instructions.Count; i++)
            {
                if(method.Body.Instructions[i].OpCode == OpCodes.Ldstr)
                {
                    String oldString = method.Body.Instructions[i].Operand.ToString(); //Original String.
                    String newString = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(oldString)); //Encrypted String by Base64
                    method.Body.Instructions[i].OpCode = OpCodes.Nop; //Change the Opcode for the Original Instruction
                    method.Body.Instructions.Insert(i + 1,new Instruction(OpCodes.Call,module.Import(typeof(System.Text.Encoding).GetMethod("get_UTF8",new Type[] { })))); //get Method (get_UTF8) from Type (System.Text.Encoding).
                    method.Body.Instructions.Insert(i + 2,new Instruction(OpCodes.Ldstr,newString)); //add the Encrypted String
                    method.Body.Instructions.Insert(i + 3,module.Import(typeof(System.Convert).GetMethod("FromBase64String",new Type[] { typeof(string) })))); //get Method (FromBase64String) from Type (System.Convert),and arguments for method we will get it using "new Type[] { typeof(string) }"
                    method.Body.Instructions.Insert(i + 4,new Instruction(OpCodes.Callvirt,module.Import(typeof(System.Text.Encoding).GetMethod("GetString",new Type[] { typeof(byte[]) }))));
                }
            }
        }
    }
}

错误消息是这样的: ScreenShot_ErrorMessage

tianli12345 回答:尝试使用dnlib写入字符串时出现System.OutOfMemoryException

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3120613.html

大家都在问