RandomDataNodeCreator的叶节点可以为ConstDataNode或者ConstFromFieldRvaDataNode
parent
f1b3bd3329
commit
3fded4273c
|
@ -15,7 +15,7 @@ namespace Obfuz.Virtualization
|
|||
{
|
||||
this.function = function;
|
||||
this.inputs = inputs;
|
||||
Type = function.ReturnType;
|
||||
Type = result.type;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,8 @@ namespace Obfuz.Virtualization
|
|||
_rvaDataAllocator = new RvaDataAllocator(_random);
|
||||
}
|
||||
|
||||
public void ObfuscateInt(MethodDef method, int value, List<Instruction> obfuscatedInstructions)
|
||||
private void CompileNode(IDataNode node, MethodDef method, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
IDataNode node = _nodeCreator.CreateRandom(DataNodeType.Int32, value);
|
||||
var ctx = new CompileContext
|
||||
{
|
||||
method = method,
|
||||
|
@ -30,21 +29,33 @@ namespace Obfuz.Virtualization
|
|||
rvaDataAllocator = _rvaDataAllocator,
|
||||
};
|
||||
node.Compile(ctx);
|
||||
}
|
||||
|
||||
public void ObfuscateInt(MethodDef method, int value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
IDataNode node = _nodeCreator.CreateRandom(DataNodeType.Int32, value);
|
||||
CompileNode(node, method, obfuscatedInstructions);
|
||||
//obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_I4, value));
|
||||
}
|
||||
|
||||
public void ObfuscateLong(MethodDef method, long value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
//IDataNode node = _nodeCreator.CreateRandom(DataNodeType.Int64, value);
|
||||
//CompileNode(node, method, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_I8, value));
|
||||
}
|
||||
|
||||
public void ObfuscateFloat(MethodDef method, float value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
//IDataNode node = _nodeCreator.CreateRandom(DataNodeType.Float32, value);
|
||||
//CompileNode(node, method, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_R4, value));
|
||||
}
|
||||
|
||||
public void ObfuscateDouble(MethodDef method, double value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
//IDataNode node = _nodeCreator.CreateRandom(DataNodeType.Float64, value);
|
||||
//CompileNode(node, method, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_R8, value));
|
||||
}
|
||||
|
||||
|
@ -56,6 +67,8 @@ namespace Obfuz.Virtualization
|
|||
|
||||
public void ObfuscateString(MethodDef method, string value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
//IDataNode node = _nodeCreator.CreateRandom(DataNodeType.String, value);
|
||||
//CompileNode(node, method, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldstr, value));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
using dnlib.DotNet.Emit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz.Virtualization.Functions
|
||||
{
|
||||
public class ConstDataCreator : NodeCreatorBase
|
||||
{
|
||||
public override IDataNode CreateExpr(DataNodeType type, object value, CreateExpressionOptions options)
|
||||
{
|
||||
return new ConstDataNode { Type = type, Value = value };
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using dnlib.DotNet.Emit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz.Virtualization.Functions
|
||||
{
|
||||
public class ConstFromFieldRvaDataCreator : NodeCreatorBase
|
||||
{
|
||||
public override IDataNode CreateExpr(DataNodeType type, object value, CreateExpressionOptions options)
|
||||
{
|
||||
return new ConstFromFieldRvaDataNode { Type = type, Value = value };
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@ namespace Obfuz.Virtualization
|
|||
|
||||
public abstract class FunctionBase : IFunction
|
||||
{
|
||||
public abstract DataNodeType ReturnType { get; }
|
||||
|
||||
public abstract void CreateArguments(DataNodeType type, object value, CreateExpressionOptions options, List<ConstValue> args);
|
||||
|
||||
|
@ -23,7 +22,7 @@ namespace Obfuz.Virtualization
|
|||
CompileSelf(ctx, ctx.output);
|
||||
}
|
||||
|
||||
public ConstExpression CreateExpr(DataNodeType type, object value, CreateExpressionOptions options)
|
||||
public IDataNode CreateExpr(DataNodeType type, object value, CreateExpressionOptions options)
|
||||
{
|
||||
var args = new List<ConstValue>();
|
||||
CreateArguments(type, value, options, args);
|
||||
|
|
|
@ -9,9 +9,8 @@ using static UnityEngine.Networking.UnityWebRequest;
|
|||
|
||||
namespace Obfuz.Virtualization.Functions
|
||||
{
|
||||
public class Int32FunctionAdd : Int32FunctionBase
|
||||
public class Int32FunctionAdd : FunctionBase
|
||||
{
|
||||
public override DataNodeType ReturnType => DataNodeType.Int32;
|
||||
|
||||
public override void CreateArguments(DataNodeType type, object v, CreateExpressionOptions options, List<ConstValue> args)
|
||||
{
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz.Virtualization.Functions
|
||||
{
|
||||
public abstract class Int32FunctionBase : FunctionBase
|
||||
{
|
||||
public override DataNodeType ReturnType => DataNodeType.Int32;
|
||||
}
|
||||
}
|
|
@ -9,9 +9,8 @@ using static UnityEngine.Networking.UnityWebRequest;
|
|||
|
||||
namespace Obfuz.Virtualization.Functions
|
||||
{
|
||||
public class Int32FunctionXor : Int32FunctionBase
|
||||
public class Int32FunctionXor : FunctionBase
|
||||
{
|
||||
public override DataNodeType ReturnType => DataNodeType.Int32;
|
||||
|
||||
public override void CreateArguments(DataNodeType type, object v, CreateExpressionOptions options, List<ConstValue> args)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.Virtualization
|
||||
{
|
||||
public abstract class NodeCreatorBase : IFunction
|
||||
{
|
||||
void IFunction.Compile(CompileContext ctx, List<IDataNode> inputs, ConstValue result)
|
||||
{
|
||||
throw new System.NotSupportedException("This function is not supported in this context.");
|
||||
}
|
||||
|
||||
public abstract IDataNode CreateExpr(DataNodeType type, object value, CreateExpressionOptions options);
|
||||
}
|
||||
}
|
|
@ -4,9 +4,8 @@ namespace Obfuz.Virtualization
|
|||
{
|
||||
public interface IFunction
|
||||
{
|
||||
DataNodeType ReturnType { get; }
|
||||
|
||||
ConstExpression CreateExpr(DataNodeType type, object value, CreateExpressionOptions options);
|
||||
IDataNode CreateExpr(DataNodeType type, object value, CreateExpressionOptions options);
|
||||
|
||||
void Compile(CompileContext ctx, List<IDataNode> inputs, ConstValue result);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ namespace Obfuz.Virtualization
|
|||
{
|
||||
new Int32FunctionAdd(),
|
||||
new Int32FunctionXor(),
|
||||
//new ConstFromFieldRvaDataCreator(),
|
||||
//new ConstDataCreator(),
|
||||
};
|
||||
_functions.Add(DataNodeType.Int32, int32Funcs);
|
||||
}
|
||||
|
@ -28,10 +30,12 @@ namespace Obfuz.Virtualization
|
|||
{
|
||||
throw new System.Exception($"No functions available for type {type}");
|
||||
}
|
||||
if (options.depth >= 2)
|
||||
if (options.depth >= 4)
|
||||
{
|
||||
//return new ConstDataNode() { Type = type, Value = value };
|
||||
return new ConstFromFieldRvaDataNode() { Type = type, Value = value };
|
||||
return _random.NextInt(100) < 50 ?
|
||||
new ConstFromFieldRvaDataNode() { Type = type, Value = value } :
|
||||
new ConstDataNode() { Type = type, Value = value };
|
||||
}
|
||||
var func = funcs[options.random.NextInt(funcs.Count)];
|
||||
++options.depth;
|
||||
|
|
Loading…
Reference in New Issue