针对基于图的相似代码检测方法复杂度高、对代码多样化识别能力有限等问题,提出基于结构特征聚类的方法。首先将代码表示为控制依赖树,在此基础上执行代码标准化,消除代码表达方式的多样化,以便识别语法表示不同,而语义相似的代码;然后采用特征向量描述程序的结构信息,将复杂的图的相似度求解问题转换为简单的相似向量的聚类问题,快速提取可能相似的候选代码。实验结果表明,方法与Gabel等人提出的方法相比,可以识别更多的代码多样化。
The traditional graph based similar code detection approaches usually have high complexity, and are limited in recognizing code variations. In this paper, we propose a similar code retrieval approach based on the clustering of structural features. Source codes are represented as control dependence trees, and code normalization is performed to eliminate code variations so as to recognize the syntactically different but semantically similar codes. Then, vectors are computed to describe the structural information of source code, and the difficult graph similarity problem is reduced to a simpler vector clustering problem. Candidate similar codes are quickly extracted. Test results show that our method can recognize more code variations than that of the method proposed by Gabel et al.