private TripleObject BuildFromTriple(Instruction fromInstruction, string fromInstanceOwnerKey, MethodDefinition parentMethod) { var tripleObj = new TripleObject(); tripleObj.Instruction = fromInstruction; var fromObjectType = InstructionKeyService.GetFromObjectType(fromInstruction); tripleObj.ObjectType = fromObjectType; if (fromObjectType == ObjectType.Argument) { int fromArgumentIndex = (int)DecompilerService.GetPosition(fromInstruction); tripleObj.ObjectKey = InstructionKeyService.GetObjectKey(fromInstruction, fromObjectType, parentMethod, fromArgumentIndex); } else { tripleObj.ObjectKey = InstructionKeyService.GetObjectKey(fromInstruction, fromObjectType, parentMethod); } tripleObj.InstructionKey = InstructionKeyService.GetInstructionKey(fromInstruction, parentMethod); tripleObj.OwnerTypeCategory = InstructionKeyService.GetTypeCategory(fromInstruction); tripleObj.OwnerTypeKey = InstructionKeyService.GetTypeKey(fromInstruction); tripleObj.InheritsFromConcreteClass = InstructionKeyService.GetConcreteInheritance(fromInstruction); tripleObj.InstanceOwnerKey = fromInstanceOwnerKey; return(tripleObj); }
private TripleObject BuildToTriple(Instruction toInstruction, string toInstanceOwnerKey, MethodDefinition parentMethod, int?toArgumentCounter = null) { var tripleObj = new TripleObject(); tripleObj.Instruction = toInstruction; var toObjectType = InstructionKeyService.GetToObjectType(toInstruction); tripleObj.ObjectType = toObjectType; tripleObj.InstanceOwnerKey = toInstanceOwnerKey; if (toObjectType == ObjectType.Argument) { var methodCallReference = (MethodReference)toInstruction.Operand; tripleObj.ObjectKey = InstructionKeyService.GetObjectKey(toInstruction, toObjectType, methodCallReference, toArgumentCounter.Value); } else { tripleObj.ObjectKey = InstructionKeyService.GetObjectKey(toInstruction, toObjectType, parentMethod); } tripleObj.InstructionKey = InstructionKeyService.GetInstructionKey(toInstruction, parentMethod); tripleObj.OwnerTypeCategory = InstructionKeyService.GetTypeCategory(toInstruction); tripleObj.OwnerTypeKey = InstructionKeyService.GetTypeKey(toInstruction); tripleObj.InheritsFromConcreteClass = InstructionKeyService.GetConcreteInheritance(toInstruction); return(tripleObj); }
public IList <AssignmentTree> PerformBacktrackingSearch(Instruction instruction, MethodDefinition methodOfInstruction, ISourceDetector nameSourceDetector, List <GoToInstancePattern> permittedToGoInstancePatterns, List <string> searchBaseConstructorPatterns) { _goToInstancePatterns = permittedToGoInstancePatterns; _searchBaseConstructorPatterns = searchBaseConstructorPatterns; var assignmentTrees = new List <AssignmentTree>(); CreateStartTraceSection(methodOfInstruction.FullName + " : " + instruction); var instructionKey = InstructionKeyService.GetInstructionKey(instruction, methodOfInstruction); var startingKeys = _tripleStore.GetToViaInstructionKey(instructionKey); foreach (var start in startingKeys) { Print(instructionKey, 0); var exploreTreeNode = new ExploreTreeNode() { FullSignature = start.ToString() }; var rootNode = new AssignmentTreeNode(start); var assignmentTree = new AssignmentTree(); assignmentTree.RootNode = rootNode; var counter = new BacktrackCounter(); _instructionKeyStack = new Stack <string>(); BacktrackingSearch(start, start, nameSourceDetector, counter, assignmentTree, rootNode, false, exploreTreeNode, 0); assignmentTrees.Add(assignmentTree); } return(assignmentTrees); }
public static ObjectInitializerScope BuildObjectInitializer(Instruction contructorInstruction, MethodDefinition parentMethod) { var objectInitializerScope = new ObjectInitializerScope(); objectInitializerScope.ParentMethod = parentMethod; objectInitializerScope.ConstructorInstruction = contructorInstruction; objectInitializerScope.ConstructorInstructionKey = InstructionKeyService.GetInstructionKey(contructorInstruction, parentMethod); objectInitializerScope.ConstructorOwnerKey = Guid.NewGuid().ToString(); var currentMemberScope = new MemberScope(); currentMemberScope.Parent = objectInitializerScope; objectInitializerScope.MemberScopes.Add(currentMemberScope); try { var instructionCursor = contructorInstruction.Next; while (instructionCursor != null && instructionCursor.Next != null) { if (instructionCursor.OpCode.Code == Mono.Cecil.Cil.Code.Nop && instructionCursor.Next.OpCode.Code == Mono.Cecil.Cil.Code.Dup) { currentMemberScope.Instructions.Add(instructionCursor); currentMemberScope = new MemberScope(); currentMemberScope.Parent = objectInitializerScope; objectInitializerScope.MemberScopes.Add(currentMemberScope); } else if (instructionCursor.OpCode.Code == Mono.Cecil.Cil.Code.Nop && instructionCursor.Next.OpCode.Code != Mono.Cecil.Cil.Code.Dup) { currentMemberScope.Instructions.Add(instructionCursor); break; } else if (IsNewObjectInitializerScope(instructionCursor)) { currentMemberScope.Instructions.Add(instructionCursor); currentMemberScope.NestedScope = BuildObjectInitializer(instructionCursor, parentMethod); var nestedScopeEndOffset = currentMemberScope.NestedScope.GetEndOffset(); instructionCursor = JumpToInstructionAfterOffset(parentMethod, nestedScopeEndOffset); if (instructionCursor == null) { break; } currentMemberScope.Instructions.Add(instructionCursor); } else { currentMemberScope.Instructions.Add(instructionCursor); } instructionCursor = instructionCursor.Next; } } catch (Exception ex) { } foreach (var memberScope in objectInitializerScope.MemberScopes) { ReorderInstructions(memberScope.Instructions); } return(objectInitializerScope); }