public abstract void Generate(ExpressionGenerator gen, int level, Random rand);
protected Expression Gen(ExpressionGenerator gen, int level, Random rand) { return(gen.Generate(this, level, rand)); }
protected Expression Gen(ExpressionGenerator gen, int level, Random rand) { return gen.Generate(this, level, rand); }
public abstract void Generate(ExpressionGenerator gen, int level, Random rand);
public override void Process(ConfusionParameter parameter) { Database.AddEntry("Const", "Type", parameter.GlobalParameters["type"] ?? "normal"); if (parameter.GlobalParameters["type"] != "dynamic" && parameter.GlobalParameters["type"] != "native") { ProcessSafe(parameter); return; } _Context txt = cc.txts[mod]; txt.isNative = parameter.GlobalParameters["type"] == "native"; txt.isDyn = parameter.GlobalParameters["type"] == "dynamic"; TypeDefinition modType = mod.GetType("<Module>"); FieldDefinition constTbl = new FieldDefinition( ObfuscationHelper.GetRandomName(), FieldAttributes.Static | FieldAttributes.CompilerControlled, mod.Import(typeof(Dictionary<uint, object>))); modType.Fields.Add(constTbl); AddHelper(constTbl, HelperAttribute.NoInjection); Database.AddEntry("Const", "ConstTbl", constTbl.FullName); FieldDefinition constBuffer = new FieldDefinition( ObfuscationHelper.GetRandomName(), FieldAttributes.Static | FieldAttributes.CompilerControlled, mod.Import(typeof(byte[]))); modType.Fields.Add(constBuffer); AddHelper(constBuffer, HelperAttribute.NoInjection); Database.AddEntry("Const", "ConstBuffer", constBuffer.FullName); if (txt.isNative) { txt.nativeDecr = new MethodDefinition( ObfuscationHelper.GetRandomName(), MethodAttributes.Abstract | MethodAttributes.CompilerControlled | MethodAttributes.ReuseSlot | MethodAttributes.Static, mod.TypeSystem.Int32); txt.nativeDecr.ImplAttributes = MethodImplAttributes.Native; txt.nativeDecr.Parameters.Add(new ParameterDefinition(mod.TypeSystem.Int32)); modType.Methods.Add(txt.nativeDecr); Database.AddEntry("Const", "NativeDecr", txt.nativeDecr.FullName); } var expGen = new ExpressionGenerator(Random.Next()); int seed = expGen.Seed; if (txt.isNative) { do { txt.exp = new ExpressionGenerator(Random.Next()).Generate(6); txt.invExp = ExpressionInverser.InverseExpression(txt.exp); } while ((txt.visitor = new x86Visitor(txt.invExp, null)).RegisterOverflowed); } else { txt.exp = expGen.Generate(10); txt.invExp = ExpressionInverser.InverseExpression(txt.exp); } Database.AddEntry("Const", "Exp", txt.exp); Database.AddEntry("Const", "InvExp", txt.invExp); txt.consters = CreateConsters(txt, Confuser.Random, "Initialize", constTbl, constBuffer); }
int ComputeRandNum(IList<Instruction> insts) { ExpressionGenerator gen = new ExpressionGenerator(Random.Next()); Expression exp = gen.Generate(2); int r = Random.Next(-10, 10); int i = ExpressionEvaluator.Evaluate(exp, r); foreach (var inst in new CecilVisitor(exp, new Instruction[] { Instruction.Create(OpCodes.Ldc_I4, r) }).GetInstructions()) insts.Add(inst); return i; }
public override void Initialize(ModuleDefinition mod) { if (mod.Architecture != TargetArchitecture.I386) Log("Junk code is not supported on target architecture, it won't be generated."); generator = new ExpressionGenerator(Random.Next()); }