Software component analysis preprocessing method and system
By using filtering rules and hash algorithms to process source code packages and extract and divide sub-modules in software component analysis, the problem of source tracing of third-party components is solved and the traceability efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202410694262.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-13
AI Technical Summary
In software component analysis, it is difficult to accurately trace the source of third-party components, mainly because there is a lot of data in the open source library and the component code modified by Fork is not exactly the same as the source code, resulting in a large workload and long time-consuming comparison.
By obtaining predefined filtering rules, configure the rule engine to filter the source code package, extract the target file and divide it into sub-modules with the same number of lines of code, and use a hash algorithm to calculate the unique identification code of each sub-module for subsequent traceability. match.
It effectively reduces redundant files in the source code package, improves the file matching speed and accuracy in the code traceability process, and ensures accurate matching of core function files. Even if there are Fork modifications during the development process, the source can be accurately traced.
Smart Images

Figure CN118643500A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of preprocessing of software component analysis, and in particular to a preprocessing method and system for software component analysis. Background Art
[0002] SCA (Software Composition Analysis) is a method for detecting, analyzing and managing third-party components (such as open source libraries, frameworks, etc.) used in software projects. SCA tools can help developers detect and identify components used in application projects, and check whether these components contain currently known vulnerabilities or security issues, which helps to improve the security of applications and prevent potential vulnerability attacks.
[0003] In the SCA process, it is usually difficult to accurately trace the source of third-party components. On the one hand, there is a lot of data in the open source library, and the method of collecting all the data for comparison is labor-intensive and time-consuming. On the other hand, the component code in the open source library is usually forked and modified by other developers. The forked component code is not exactly the same as its source code, which makes it more difficult to match the source of third-party components with the code in the open source library.
[0004] Although the specific codes in the component have undergone different degrees of changes based on actual needs, the core code used to implement the most important functions of the component usually does not change, that is, what is generally changed are the auxiliary code files in the software. In theory, the source of the third-party component code can be traced based on the core code of the open source library component. Summary of the invention
[0005] The purpose of the present invention is to provide a preprocessing method and system for software component analysis that provides accurate and effective matching data for software component analysis, so that the corresponding source code source can be accurately found in the subsequent tracing process.
[0006] To achieve the above object, the present invention discloses a preprocessing method for software component analysis, which comprises:
[0007] Obtaining a predefined filtering rule, wherein the filtering rule is used to filter out auxiliary files in the software source code package according to a rule matching method;
[0008] Configuring a rule engine based on the filtering rules;
[0009] Screening the files in the source code package of the software to be processed based on the rule engine to extract the target file;
[0010] Dividing the target file into a plurality of submodules having the same number of code lines;
[0011] The unique identification code of each submodule is calculated and stored through a preset identification algorithm.
[0012] Specifically, the method for obtaining the predefined filtering rules includes:
[0013] Open source rules are collected from an Internet rule base at regular intervals through a script file, the open source rules including the filtering rules, and the open source rules are processed through a filtering rule screening method to extract the filtering rules.
[0014] Specifically, the filtering rule includes a first filtering rule, and the first filtering rule is used to filter the source code package in file units to obtain the target file.
[0015] Furthermore, the first filtering rule includes one or more of a path specification method, a regular rule matching method, and a file format filtering method.
[0016] Specifically, the filtering rule further includes a second filtering rule, and the second filtering rule is used to filter the file extracted by the first filtering rule in units of code lines to obtain the target file.
[0017] Furthermore, the second filtering rule includes removing empty code lines and tab lines.
[0018] Specifically, the unique identification code includes a hash code, and the identification algorithm includes a hash algorithm. All the sub-modules are processed by the hash algorithm to obtain a hash code corresponding to each of the sub-modules, and the hash code is used as the unique identification code of each of the sub-modules.
[0019] The invention also discloses a preprocessing system for software component analysis, and the preprocessing system works based on the preprocessing method mentioned above.
[0020] The present invention also discloses a preprocessing system for software component analysis, comprising:
[0021] one or more processors;
[0022] Memory;
[0023] and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs comprising instructions for executing the pre-processing method as described above.
[0024] The present invention also discloses a computer-readable storage medium, comprising a computer program, wherein the computer program can be executed by a processor to complete the preprocessing method as described above.
[0025] Compared with the prior art, the preprocessing method provided by the above technical solution of the present invention processes the source code package through a rule engine to obtain a target file, and then divides the target file into multiple sub-modules with the same number of code lines, and finally calculates the unique identification code of each sub-module. Then, in the code tracing process of the subsequent software component analysis, the code content of the third-party component is matched with the content of each sub-module, and then based on the unique identification code of each sub-module, the source source code package of the third-party component can be found. It can be seen that through the above preprocessing method, the redundant files in the source code package can be effectively reduced, thereby improving the file matching speed and accuracy in the subsequent code tracing process, and effectively improving the efficiency of software component analysis; in addition, since the generated target file is the core function file in the source code package, the target file is divided into multiple sub-modules, even if the source code is Forked during the development process, it will not affect the matching of the original core code, so that the source code package can be accurately traced. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 4 is a flow chart of the preprocessing method in an embodiment of the present invention.
[0027] Figure 2 4 is a processing flow chart of the preprocessing system in an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to explain the technical content, structural features, achieved objectives and effects of the present invention in detail, the following is a detailed description in conjunction with the implementation methods and the accompanying drawings.
[0029] This embodiment discloses a software component analysis (SCA) preprocessing method to provide accurate and effective matching data for component source matching during the SCA analysis process.
[0030] It should be noted that SCA is a method and behavior for identifying and classifying various software components to detect the origin and security of components. The SCA tool collects component information in the application and then generates a corresponding component analysis report. The component analysis report contains detailed information about the component, such as name, source file, dependency, etc. Among them, the SCA tool matches the specific content of the extracted component with the known component library or database to obtain the source information of the component. Therefore, in the SCA analysis, the source code package of the software to be processed needs to be processed to obtain the component code information of the software to be processed.
[0031] like Figure 1 , the preprocessing method specifically comprises the following steps:
[0032] S1: Obtain a predefined filtering rule, where the filtering rule is used to filter out auxiliary files in a software source code package according to a rule matching method.
[0033] S2: Configure the rule engine based on the filtering rules.
[0034] S3: Screen the files in the source code package of the software to be processed based on the rule engine to extract the target files.
[0035] S4: Divide the target file into multiple submodules with the same number of code lines.
[0036] S5: Calculate and store the unique identification code of each submodule through a preset identification algorithm.
[0037] In summary, the preprocessing method first obtains predefined filtering rules, which are used to filter and screen the files in the source code package of the software to be processed. Based on the configuration of the rule engine based on the filtering rules, the core code in the source code package can be directly filtered based on the rule engine to remove non-core files in the source code, that is, auxiliary files, so as to obtain the target file. The purpose of filtering and screening the source code package is to remove auxiliary files and code lines such as configuration and testing in the source code package, so as to avoid wasting time, human resources and storage space to parse and store redundant files, and then achieve faster traceability tracking in the subsequent source matching, which speeds up the search speed, and improves the traceability efficiency and accuracy. Based on the target file, even if the third-party component forks and modifies the source code during the development process, accurate traceability can be achieved.
[0038] Secondly, the preprocessing method divides the target file into multiple submodules with the same lines, and encodes and identifies each submodule through an identification algorithm. Dividing the file into multiple submodules can speed up the matching speed when matching the source of third-party components. It is not necessary to compare all the contents in the open source component files one by one, avoiding the increase of waiting time due to file occupancy, and can effectively improve the matching accuracy during the SCA analysis process.
[0039] Based on the calculated unique identification code, the source file information of the submodule can be quickly found and determined in the subsequent SCA analysis process.
[0040] In short, this preprocessing method retains the core files of the components in the source code package to the maximum extent by filtering, identifying and storing the source code package, thereby providing accurate and effective matching data for the subsequent tracing process, saving time, manpower and database storage space. Based on the target file data obtained by this technical solution, even when facing third-party components that have been forked and modified during the development process, the accurate source of the component can be found quickly and effectively, greatly improving the overall efficiency and accuracy of subsequent tracing.
[0041] Specifically, the method for obtaining the predefined filtering rules includes:
[0042] The open source rules are collected from the Internet rule base regularly through the script file, and the open source rules include filtering rules. The open source rules are processed through the filtering rule screening method to extract the filtering rules. Figure 2 In this embodiment, the open source rules come from an open source rule library on the Internet. The open source rule collection server collects the open source rules from the rule library through a script file, and then extracts the filtering rules from the open source rules through a filtering rule screening method and stores them in a database.
[0043] Furthermore, the script file includes a Python script file or a Golang script file. In this embodiment, the open source rule collection server crawls and collects the open source rules in the open source library through the script file.
[0044] More specifically, the above-mentioned filtering rule screening method includes a regular matching method, and the filtering rule screening method extracts the filtering rules in the open source rules based on a predefined keyword set. In this embodiment, a keyword set for extracting filtering rules is predefined, and the regular matching method extracts the open source rules containing any keyword in the keyword set as filtering rules.
[0045] On the other hand, the filtering rules include a first filtering rule, which is used to filter the source code package in units of files to obtain the target file. In this embodiment, the function of the first filtering rule is to filter out the auxiliary files in the source code package in units of files and only retain the core target file.
[0046] Furthermore, the first filtering rule also includes one or more of a path specification method, a regular rule matching method, and a file format filtering method. In the present embodiment, the path specification method is used to remove the local path prefixes and special characters of the files in the source code package of the software to be processed, and only retain the relative paths of these files, so as to extract the target file according to the file path. The regular rule matching method can extract the files containing any file path, file name or file content in the source code package in the above three sets as the target file based on the preset file path set, the preset file name set, and the preset file content set. The file format filtering method removes the files that do not conform to the preset file format, and extracts the files in the source code package whose suffix conforms to the preset file format as the target file. In the specific use process, one or more of the path specification method, the regular rule matching method, and the file format filtering method can be selected according to the actual situation to extract the target file.
[0047] On the other hand, the filtering rule also includes a second filtering rule, which is used to filter the files extracted by the first filtering rule in units of code lines to obtain the target file. The second filtering rule includes removing empty code lines and tab lines. In this embodiment, the purpose of removing these empty code lines and tab lines is to remove useless lines in the file and compress the memory of the extracted target file, which is conducive to saving storage space and achieving source matching faster during tracing.
[0048] On the other hand, in this embodiment, the code of the target file is divided into a submodule every 5 lines and stored in the database, and a submodule corresponds to a unique identification code. It should be noted that in different application scenarios, there is no strict limit on the number of lines of code stored in the submodule, and it can be modified according to the actual situation during the preprocessing process.
[0049] On the other hand, the unique identification code includes a hash code, and the identification algorithm includes a hash algorithm. All submodules are processed by the hash algorithm to obtain a hash code corresponding to each submodule, and the hash code is used as the unique identification code of each submodule. In this embodiment, the hash algorithm identifies and sorts the submodules, and the hash code corresponding to the generated submodule is used to identify the submodule. Based on the hash code, detailed information of the source file such as the location of each submodule stored in the database, the file of the source code package where each submodule is located, the content of the file, and the storage location of the file in the application program can be obtained.
[0050] On the other hand, in order to improve the overall preprocessing efficiency, the thread pool is also used in this embodiment to parse the files in the source code package. In this embodiment, the source code package files need to be parsed before preprocessing, and the specific content of each file in the source code package can be obtained during the parsing process. The thread pool can parse multiple files in the source code package at the same time to improve the file parsing efficiency. The parsed contents obtained by parsing each file can be merged to obtain a parsed content set, thereby removing the same data in the parsed content, avoiding repeated preprocessing operations on the same data, and speeding up the preprocessing rate from the source.
[0051] On the other hand, the obtained filtering rules are also encapsulated as a filtering interface. In this embodiment, the collected filtering rules can be used repeatedly. By encapsulating the filtering interface to process the source code package, there is no need to consider whether the relevant filtering rules of the source code packages used for filtering are consistent, which can ensure the uniformity of the filtering rules. In addition, the encapsulated interface is easy to use and can be used at any time, further simplifying the subsequent filtering and screening operation process of other source code packages.
[0052] It is worth mentioning that after the filtering rules are encapsulated into a filtering interface, query entries and exits related to the unique identification code and other data corresponding to each submodule and submodule are also created. At the same time, the database addition, deletion, query and modification related operations are encapsulated into a toolkit, and the toolkit and query entry and exit are compressed, obfuscated, encrypted, and shelled and crack-proof. Finally, the query entry and exit, toolkit and filtering rule interface are encapsulated together into a unified SDK device. By adding the SDK device to the private server warehouse, it can be used directly in the subsequent preprocessing of the source code package and the tracing of the third-party components.
[0053] In another preferred embodiment of the present invention, a preprocessing system for software component analysis is also disclosed, and the preprocessing system works based on the above preprocessing method.
[0054] The present invention also discloses a preprocessing system for software component analysis, which includes one or more processors, a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the program includes instructions for executing the preprocessing method as described above. The processor can adopt a general central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), or one or more integrated circuits for executing related programs to execute the preprocessing method of the method embodiment of the present application.
[0055] The present invention also discloses a computer-readable storage medium, which includes a computer program, and the computer program can be executed by a processor to complete the preprocessing method as described above. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium can be a read-only memory (ROM), or a random access memory (RAM), or a magnetic medium, such as a floppy disk, a hard disk, a tape, a magnetic disk, or an optical medium, such as a digital versatile disc (DVD), or a semiconductor medium, such as a solid state disk (SSD), etc.
[0056] The embodiment of the present application also discloses a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of an electronic device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the electronic device performs the above-mentioned preprocessing method.
[0057] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of rights of the present invention. Therefore, equivalent changes made according to the scope of the patent application of the present invention are still within the scope covered by the present invention.
Claims
1. A preprocessing method for software component analysis, characterized in that: include: Obtaining a predefined filtering rule, wherein the filtering rule is used to filter out auxiliary files in the software source code package according to a rule matching method; Configuring a rule engine based on the filtering rules; Screening the files in the source code package of the software to be processed based on the rule engine to extract the target file; Dividing the target file into a plurality of submodules having the same number of code lines; The unique identification code of each submodule is calculated and stored through a preset identification algorithm.
2. The preprocessing method for software component analysis according to claim 1, characterized in that: The method for obtaining the predefined filtering rules includes: Open source rules are collected from an Internet rule base at regular intervals through a script file, the open source rules including the filtering rules, and the open source rules are processed through a filtering rule screening method to extract the filtering rules.
3. The preprocessing method for software component analysis according to claim 1, characterized in that: The filtering rules include a first filtering rule, and the first filtering rule is used to filter the source code package in file units to obtain the target file.
4. The preprocessing method for software component analysis according to claim 3, characterized in that: The first filtering rule includes one or more of a path specification method, a regular rule matching method, and a file format filtering method.
5. The preprocessing method for software component analysis according to claim 3, characterized in that: The filtering rules also include a second filtering rule, which is used to filter the files extracted by the first filtering rules in units of code lines to obtain the target file.
6. The preprocessing method for software component analysis according to claim 5, characterized in that: The second filtering rule includes removing empty code lines and tab lines.
7. The preprocessing method for software component analysis according to claim 1, characterized in that: The unique identification code includes a hash code, and the identification algorithm includes a hash algorithm. All the sub-modules are processed by the hash algorithm to obtain a hash code corresponding to each of the sub-modules, and the hash code is used as the unique identification code of each of the sub-modules.
8. A preprocessing system for software component analysis, characterized in that: The pretreatment system works based on the pretreatment method according to any one of claims 1 to 7.
9. A preprocessing system for software component analysis, characterized in that: include: one or more processors; Memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs comprising instructions for executing the pre-processing method according to claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The invention comprises a computer program which can be executed by a processor to implement the preprocessing method according to any one of claims 1 to 7.
Citation Information
Cited By
SCA source code analysis method and device based on user-defined mapping
CN119690445A
