使用code2vec嵌入Java类:变量混淆的改进
Embedding Java Classes with code2vec: Improvements from Variable Obfuscation
摘要:
在软件工程的关键领域(如代码安全性)中,自动源代码分析可以从机器学习(ML)中受益。然而,许多标准ML方法需要数据的数字表示,并且不能直接应用于源代码。因此,为了启用ML,我们需要将源代码嵌入到数字特征向量中,同时尽可能保持代码的语义。code2vec是最近发布的一种嵌入方法,它使用方法名称预测的代理任务将Java方法映射到特征向量。然而,code2vec的实验表明,它学会了依赖变量名进行预测,这使得它很容易被错别字或对抗攻击所欺骗。此外,它只能嵌入单个Java方法,而不能嵌入整个方法集合,例如典型Java类中存在的方法,这使得难以在类级别执行预测(例如,用于识别恶意Java类)。这两个缺点都在本文提出的研究中得到解决。我们研究了在code2vec模型的训练过程中混淆变量名称的效果,以迫使它依赖于代码的结构而不是特定的名称,并考虑了一种通过聚合方法嵌入集来创建类级嵌入的简单方法。我们的研究结果,获得了一个具有挑战性的新的集合的源代码分类问题,表明混淆变量名称产生一个嵌入模型,既不受变量命名,更准确地反映代码语义。共享数据集、模型和代码,以便对源代码进行进一步的ML研究。
英文摘要:
Automatic source code analysis in key areas of software engineering, such as code security, can benefit from Machine Learning (ML). However, many standard ML approaches require a numeric representation of data and cannot be applied directly to source code. Thus, to enable ML, we need to embed source code into numeric feature vectors while maintaining the semantics of the code as much as possible. code2vec is a recently released embedding approach that uses the proxy task of method name prediction to map Java methods to feature vectors. However, experimentation with code2vec shows that it learns to rely on variable names for prediction, causing it to be easily fooled by typos or adversarial attacks. Moreover, it is only able to embed individual Java methods and cannot embed an entire collection of methods such as those present in a typical Java class, making it difficult to perform predictions at the class level (e.g., for the identification of malicious Java classes). Both shortcomings are addressed in the research presented in this paper. We investigate the effect of obfuscating variable names during the training of a code2vec model to force it to rely on the structure of the code rather than specific names and consider a simple approach to creating class-level embeddings by aggregating sets of method embeddings. Our results, obtained on a challenging new collection of source-code classification problems, indicate that obfuscating variable names produces an embedding model that is both impervious to variable naming and more accurately reflects code semantics. The datasets, models, and code are shared for further ML research on source code.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。