private static void AddEdges(InstructionNode node, List <LabeledVertex> labeledVertexes)
        {
            LabeledVertex vertex = labeledVertexes[node.InstructionIndex];

            foreach (var dataFlowBackVertex in node.DataFlowBackRelated)
            {
                vertex.BackEdges.Add(new LabeledEdge()
                {
                    EdgeType          = EdgeType.DataFlow,
                    Index             = dataFlowBackVertex.ArgIndex,
                    SourceVertex      = labeledVertexes[dataFlowBackVertex.Argument.InstructionIndex],
                    DestinationVertex = vertex
                });
            }
            foreach (var branch in node.BranchProperties.Branches)
            {
                vertex.BackEdges.Add(new LabeledEdge()
                {
                    EdgeType          = EdgeType.ProgramFlowAffecting,
                    Index             = (int)branch.MergeNodeBranchIndex,
                    SourceVertex      = labeledVertexes[branch.OriginatingNode.InstructionIndex],
                    DestinationVertex = vertex
                });
            }
            foreach (var dataFlowBackVertex in node.DataFlowForwardRelated)
            {
                vertex.ForwardEdges.Add(new LabeledEdge()
                {
                    EdgeType          = EdgeType.DataFlow,
                    Index             = dataFlowBackVertex.ArgIndex,
                    SourceVertex      = vertex,
                    DestinationVertex = labeledVertexes[dataFlowBackVertex.Argument.InstructionIndex]
                });
            }
        }
Beispiel #2
0
        public static double GetSelfScore(LabeledVertex labeledVertex)
        {
            int    selfScore  = VertexScorePoints.ExactMatch;
            object lockObject = new object();

            //Parallel.ForEach(labeledVertex.BackEdges, (edge) =>
            foreach (var edge in labeledVertex.BackEdges)
            {
                int score = EdgeScorer.GetEdgeMatchScore(edge, edge, SharedSourceOrDest.Dest, null, IndexImportance.Important, false);
                lock (lockObject)
                {
                    selfScore += score;
                }
            }
            //Parallel.ForEach(labeledVertex.ForwardEdges, (edge) =>
            foreach (var edge in labeledVertex.ForwardEdges)
            {
                int score = EdgeScorer.GetEdgeMatchScore(edge, edge, SharedSourceOrDest.Source, null, IndexImportance.Important, false);
                lock (lockObject)
                {
                    selfScore += score;
                }
            }
            if (OutDataCodes.Contains(labeledVertex.Opcode))
            {
                selfScore *= ImportantCodeMultiplier;
            }
            return(selfScore);
        }
Beispiel #3
0
 public CompoundedLabeledVertex(LabeledVertex firstMostVertex)
 {
     FirstMostVertex = firstMostVertex;
     Opcode          = firstMostVertex.Opcode;
     Operand         = firstMostVertex.Operand;
     Index           = firstMostVertex.Index;
 }
        private static List <LabeledVertex> GetBackSingleUnitTree(LabeledVertex frontMostInSingleUnit)
        {
            List <LabeledVertex>  backTree    = new List <LabeledVertex>();
            Queue <LabeledVertex> backRelated = new Queue <LabeledVertex>();

            foreach (var backSingleUnit in frontMostInSingleUnit.BackEdges.Where(x => x.EdgeType == EdgeType.SingleUnit))
            {
                backRelated.Enqueue(backSingleUnit.SourceVertex);
            }
            while (backRelated.Count > 0)
            {
                var currNode = backRelated.Dequeue();
                backTree.Add(currNode);
                foreach (var backSingleUnit in currNode.BackEdges.Where(x => x.EdgeType == EdgeType.SingleUnit))
                {
                    backRelated.Enqueue(backSingleUnit.SourceVertex);
                }
            }
            return(backTree);
        }
Beispiel #5
0
        public static double GetScore(LabeledVertex sourceGraphVertex, LabeledVertex imageGraphVertex, NodePairings pairings)
        {
            double score = 0;

            if (sourceGraphVertex.Opcode == imageGraphVertex.Opcode)
            {
                score += VertexScorePoints.CodeMatch;
            }
            else
            {
                score += VertexScorePoints.CodeFamilyMatch;
            }
            if (sourceGraphVertex.Operand == imageGraphVertex.Operand)
            {
                score += VertexScorePoints.OperandMatch;
            }
            var backEdgeScore    = EdgeScorer.ScoreEdges(sourceGraphVertex.BackEdges, imageGraphVertex.BackEdges, pairings, SharedSourceOrDest.Dest);
            var forwardEdgeScore = EdgeScorer.ScoreEdges(sourceGraphVertex.ForwardEdges, imageGraphVertex.ForwardEdges, pairings, SharedSourceOrDest.Source);

            score += backEdgeScore + forwardEdgeScore;
            lock (pairings)
            {
                if (pairings.Pairings[imageGraphVertex].Count > 0)
                {
                    //score -= VertexScorePoints.SingleToMultipleVertexMatchPenalty;
                    score *= 0.9;
                }
            }
            if (OutDataCodes.Contains(sourceGraphVertex.Opcode))
            {
                score *= ImportantCodeMultiplier;
            }
            //if (sourceGraphVertex.IsInReturnBackTree)
            //{
            //    score *= ImportantCodeMultiplier;
            //}
            var scoreToDouble = score / GetSelfScore(sourceGraphVertex);

            return(score);
        }