Exemple #1
0
        void VisitInstr(ILInstrList instrs, ILInstruction instr, ref int index, ILTransformer tr)
        {
            if (instr.Operand is ILBlockTarget)
            {
                var target = (ILBlockTarget)instr.Operand;
                if (target.Target == trampoline)
                {
                    target.Target = newTrampoline;
                }
            }
            else if (instr.IR == null)
            {
                return;
            }

            if (instr.IR.Annotation == SMCBlock.CounterInit && instr.OpCode == ILOpCode.PUSHI_DWORD)
            {
                var imm = (ILImmediate)instr.Operand;
                if ((int)imm.Value == 0x0f000001)
                {
                    newTrampoline.CounterOperand = imm;
                }
            }
            else if (instr.IR.Annotation == SMCBlock.EncryptionKey && instr.OpCode == ILOpCode.PUSHI_DWORD)
            {
                var imm = (ILImmediate)instr.Operand;
                if ((int)imm.Value == 0x0f000002)
                {
                    imm.Value = (int)newTrampoline.Key;
                }
            }
            else if (instr.IR.Annotation == SMCBlock.AddressPart1 && instr.OpCode == ILOpCode.PUSHI_DWORD &&
                     instr.Operand is ILBlockTarget)
            {
                var target = (ILBlockTarget)instr.Operand;

                var relBase = new ILInstruction(ILOpCode.PUSHR_QWORD, ILRegister.IP, instr);
                instr.OpCode  = ILOpCode.PUSHI_DWORD;
                instr.Operand = new SMCBlockRef(target, relBase, (uint)adrKey);

                instrs.Replace(index, new[] {
                    relBase,
                    instr,
                    new ILInstruction(ILOpCode.ADD_QWORD, null, instr)
                });
            }
            else if (instr.IR.Annotation == SMCBlock.AddressPart2 && instr.OpCode == ILOpCode.PUSHI_DWORD)
            {
                var imm = (ILImmediate)instr.Operand;
                if ((int)imm.Value == 0x0f000003)
                {
                    imm.Value = adrKey;
                }
            }
        }
Exemple #2
0
 void VisitInstr(ILInstrList instrs, ILInstruction instr, ref int index, ILTransformer tr)
 {
     if (instr.Operand is ILRegister)
     {
         var reg = ((ILRegister)instr.Operand).Register;
         if (reg.IsGPR())
         {
             methodInfo.UsedRegister.Add(reg);
         }
     }
 }
Exemple #3
0
 void VisitInstr(ILInstrList instrs, ILInstruction instr, ref int index, ILTransformer tr)
 {
     if (instr.OpCode == ILOpCode.__ENTRY)
     {
         instrs.RemoveAt(index);
         index--;
     }
     else if (instr.OpCode == ILOpCode.__EXIT)
     {
         instrs[index] = new ILInstruction(ILOpCode.RET, null, instr);
     }
 }
Exemple #4
0
        public void Transform(ILTransformer tr)
        {
            if (tr.Block.Targets.Contains(trampoline))
            {
                tr.Block.Targets[tr.Block.Targets.IndexOf(trampoline)] = newTrampoline;
            }

            if (tr.Block.Sources.Contains(trampoline))
            {
                tr.Block.Sources[tr.Block.Sources.IndexOf(trampoline)] = newTrampoline;
            }

            tr.Instructions.VisitInstrs(VisitInstr, tr);
        }
        void VisitInstr(ILInstrList instrs, ILInstruction instr, ref int index, ILTransformer tr)
        {
            if (instr.OpCode == ILOpCode.PUSHI_DWORD && instr.Operand is IHasOffset)
            {
                var relBase = new ILInstruction(ILOpCode.PUSHR_QWORD, ILRegister.IP, instr);
                instr.OpCode  = ILOpCode.PUSHI_DWORD;
                instr.Operand = new ILRelReference((IHasOffset)instr.Operand, relBase);

                instrs.Replace(index, new[] {
                    relBase,
                    instr,
                    new ILInstruction(ILOpCode.ADD_QWORD, null, instr)
                });
            }
        }
Exemple #6
0
        private void CompileHelpers(MethodDef method, ScopeBlock scope)
        {
            var methodCtx = new IRContext(method, method.Body);

            methodCtx.IsRuntime = true;
            var irTransformer = new IRTransformer(scope, methodCtx, rt);

            irTransformer.Transform();

            var ilTranslator  = new ILTranslator(rt);
            var ilTransformer = new ILTransformer(method, scope, rt);

            ilTranslator.Translate(scope);
            ilTransformer.Transform();

            var postTransformer = new ILPostTransformer(method, scope, rt);

            postTransformer.Transform();
        }
Exemple #7
0
        public void Initialize(ILTransformer tr)
        {
            this.trampoline = null;
            tr.RootScope.ProcessBasicBlocks <ILInstrList>(b =>
            {
                if (b.Content.Any(instr => instr.IR != null && instr.IR.Annotation == SMCBlock.AddressPart2))
                {
                    this.trampoline = (ILBlock)b;
                }
            });
            if (this.trampoline == null)
            {
                return;
            }

            CFG.ScopeBlock scope = tr.RootScope.SearchBlock(this.trampoline).Last();
            this.newTrampoline = new SMCBlock(this.trampoline.Id, this.trampoline.Content);
            scope.Content[scope.Content.IndexOf(this.trampoline)] = this.newTrampoline;

            this.adrKey            = tr.VM.Random.Next();
            this.newTrampoline.Key = (byte)tr.VM.Random.Next();
        }
Exemple #8
0
 public void Transform(ILTransformer tr)
 {
     tr.Instructions.VisitInstrs(VisitInstr, tr);
 }
Exemple #9
0
 public void Initialize(ILTransformer tr)
 {
 }
Exemple #10
0
 public void Transform(ILTransformer tr) => tr.Instructions.VisitInstrs(this.VisitInstr, tr);
Exemple #11
0
 public void Initialize(ILTransformer tr)
 {
     methodInfo           = tr.VM.Data.LookupInfo(tr.Method);
     methodInfo.RootScope = tr.RootScope;
     tr.VM.Data.SetInfo(tr.Method, methodInfo);
 }
Exemple #12
0
        protected virtual void TransformVMIL()
        {
            var transformer = new ILTransformer(Method, RootScope, Runtime);

            transformer.Transform();
        }