源代码与二进制文件SCA检测原理
1、源代码与二进制的关系和特点
SCA(Software Composition Analysis)软件成分分析,通俗的理解就是通过分析软件包含的一些信息和特征来实现对该软件的识别、管理、追踪的技术。SCA具体的检测原理又是如何实现的,源代码和二进制文件的SCA检测又有哪些相同点和不同点,下面内容就来回答一下上述疑问。
对应编译类型的语言(C/C++/Go/Rust),都是遵循:源代码—>编译—>链接—>二进制文件的过程。影响二进制文件的因素包括不同的CPU架构(ARM、X86、PPC、MIPS…),不同的操作系统(Wndows、Linux、iOS、Android…),不同的编译优化选项(O0~O3),即使是同一套源代码,最终编译生成的二进制文件之间也是差别非常大的。注:上述影响因素不涉及java语言
从上面可知源代码和二进制文件之间存在巨大的差别,源代码是基于高阶语言来编写,是给人看的,人看了很方便理解其中语句的语义;而二进制是由流(指令流或字节流)来构成的,是给计算机“看”的,对人来说是非常不友好,不好理解。
源代码包含了变量符号类型、函数名称、类名称、代码逻辑结构等大量丰富的代码信息,相反为保留二进制文件的紧凑性,编译生成的二进制文件中会丢弃掉很多运行时用不到的信息,只保留程序正确运行必要的信息,比如被丢弃的信息有变量类型、变量名称等符号信息,可能被保留的有类名称、函数名称等信息,一定会保留的有常量字符串数据。另外为了保证程序的正确运行,还会有保留一个相应的配置信息,比如jar包中的manifest信息、POM信息、maven信息、资源文件等。基于这些特点源代码SCA和二进制SCA的检测原理也存在很大的不同。