public override void Visit(IInstructionContainer container) { for (int i = 0; i < container.Instructions.Count;) { Instruction current = container.Instructions[i] as Instruction; // hacky? // create FakeObjectCreationInstruction // this is a workaround because analysis-net splits // Bytecode.CreatObjectInstruction into multiple instructions // we need information from these three instructions to create again a // Bytecode.CreatObjectInstruction if (i + 2 < container.Instructions.Count && current is CreateObjectInstruction createObjectInstruction && container.Instructions[i + 1] is MethodCallInstruction callInstruction) { current = new FakeCreateObjectInstruction() { CreateObjectInstruction = createObjectInstruction, MethodCallInstruction = callInstruction, }; // do not process twice // the same instructions i += 2; }
public virtual void Visit(IInstructionContainer container) { foreach (var instruction in container.Instructions) { instruction.Accept(this); } }
public static ISet <IVariable> GetUsedVariables(this IInstructionContainer block) { var result = from i in block.Instructions from v in i.UsedVariables select v; //var result = block.Instructions.SelectMany(i => i.UsedVariables); return(new HashSet <IVariable>(result)); }
public override void Visit(IInstructionContainer container) { referencedSet = new HashSet <IReferenceable>(); fieldReferencedSet = new HashSet <IFieldReference>(); base.Visit(container); ReferencedSet = referencedSet; FieldReferencedSet = fieldReferencedSet; }
public static ISet <IVariable> GetDefinedVariables(this IInstructionContainer block) { var result = from i in block.Instructions let d = i as DefinitionInstruction where d != null && d.HasResult select d.Result; return(new HashSet <IVariable>(result)); //var result = new HashSet<IVariable>(); //foreach (var instruction in block.Instructions) //{ // var definition = instruction as DefinitionInstruction; // if (definition != null && definition.HasResult) // { // result.Add(definition.Result); // } //} //return result; }
// A basic block can end with a non-branch instruction or a conditional branch instruction. // In those cases there is an implict flow, it is not encoded in any instruction. // That forces us to translate the nodes in a very specific order or translate each instruction linearly. // The implicit flow expects a particular instruction after another one. // In order to avoid that situation we make the control flow explicit. // If a basic block terminates with a non branch instruction, // we generate a unconditional branch to the original fall through target. // If a basic block terminates with a conditional branch, we create an unconditional branch to the implicit target. private void TranslateImplicitFlow(IInstructionContainer container) { CFGNode n = container as CFGNode; var last = n.Instructions.Last(); if (Model.Extensions.CanFallThroughNextInstruction(last)) { UnconditionalBranchInstruction explicitBr; if (last is ConditionalBranchInstruction conditionalBranch) { var successor = n.Successors.Where(s => s.Instructions.First().Label != conditionalBranch.Target).Single(); explicitBr = new UnconditionalBranchInstruction(0, successor.Instructions.First().Label); } else { var successor = n.Successors.Single(); explicitBr = new UnconditionalBranchInstruction(0, successor.Instructions.First().Label); } explicitBr.Accept(this); } }
public override void Visit(IInstructionContainer container) { preState.Clear(); postState.Clear(); base.Visit(container); }
public static uint EndOffset(this IInstructionContainer block) { var instruction = block.Instructions.Last(); return(instruction.Offset); }
public static uint StartOffset(this IInstructionContainer block) { var instruction = block.Instructions.First(); return(instruction.Offset); }