Software component analysis preprocessing method and system based on state machine
Through the state machine-based software component analysis preprocessing method, efficient parallel processing of open source libraries is realized, which solves the problems of long preprocessing time and high resource cost in the existing technology, and improves CPU utilization and process flexibility.
Patent Information
- Application Number
- CN202410729088.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-09-10
AI Technical Summary
When preprocessing open source libraries, the existing technology takes a long time and has low CPU performance utilization, high hardware resource costs, and the preprocessing process has low scalability and flexibility.
Using a state machine-based software component analysis preprocessing method, the state machine framework is configured to define processing states and jump conditions, and multiple state machine instances are generated for parallel processing of source code packages to achieve parallel processing and flexible expansion of the preprocessing process.
Significantly improves CPU utilization, shortens processing time, improves pre-processing speed and flexibility, and reduces hardware resource requirements and development costs.
Smart Images

Figure CN118626142A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to a software component analysis preprocessing method and system based on a state machine. Background Art
[0002] SCA (Software Composition Analysis) is a method for detecting, parsing 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] During the working process, 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 components in the application, such as name, component source, etc. Among them, the popular practice of obtaining the source of third-party components is that the SCA tool matches the specific content of the extracted third-party components with the known component database. When the third-party component matches the matching data in the component database, the accurate source of the third-party component can be determined. This approach requires us to pre-process the source code packages of known open source components, and then obtain the corresponding matching data to construct the component database to facilitate subsequent traceability work.
[0004] However, there are some urgent problems to be solved in the preprocessing work: First, the existing open source libraries contain a large number of open source components, the number of files within the components is large, and some files have large code lines. Processing the source code package on a single machine takes a long time and has low CPU performance utilization. If multiple machines are deployed, the hardware resource cost will increase, and the technical requirements for technicians will also increase. Secondly, during the preprocessing process, if the preprocessing steps are increased or reduced, the technicians are often required to adjust all the context logic, and the scalability and flexibility of the business processing flow of the preprocessing work are not high. Summary of the invention
[0005] The object of the present invention is to provide a software component analysis preprocessing method and system based on a state machine, which can process a number of source code packages in parallel and flexibly expand the preprocessing flow.
[0006] To achieve the above object, the present invention discloses a software component parsing preprocessing method based on a state machine, which comprises:
[0007] The state machine framework is configured based on the business process flow of the preprocessing work of the source code package in the software component analysis, and the configuration content includes: defining a number of processing states corresponding to each stage in the business process flow in the state machine framework, configuring corresponding processing logic for each of the processing states, and defining jump conditions for jumping between the processing states;
[0008] The processing logic corresponds to the business execution event at the corresponding stage in the business processing flow;
[0009] The jump condition is used to instruct the state machine to jump from the current processing state to another processing state according to the execution result of the processing logic;
[0010] A plurality of state machine instances corresponding to each of the source code packages to be processed are generated, and a plurality of the source code packages are processed in parallel by each of the state machine instances.
[0011] Furthermore, the processing state includes several normal business processing states executed in sequence, and the normal business processing state includes:
[0012] a preparation state, in which the processing logic is used to perform a process self-check starting with software component analysis;
[0013] a decompression state, in which the processing logic is used to decompress the source code package to obtain file information in the source code package;
[0014] A scanning state, in which the processing logic is used to extract the target file in the decompressed source code package according to a preset filtering rule;
[0015] A parsing state, in which the processing logic is used to calculate a unique identification code corresponding to each of the target files one by one through a preset identification algorithm;
[0016] a data processing state, in which the processing logic is used to compress and encrypt the target file and the unique identification code corresponding to the target file;
[0017] An end state, in which the processing logic is used to store the compressed and encrypted target file and the unique identification code corresponding to the target file into a database.
[0018] Furthermore, when the state machine instance is in the ready state and the processing logic corresponding to the ready state is correctly executed, a trigger event is generated to trigger the state machine instance to jump from the ready state to the decompression state;
[0019] When the state machine instance is in the decompression state and the processing logic corresponding to the preparation state is correctly executed, the trigger event is generated to trigger the state machine instance to jump from the decompression state to the scanning state;
[0020] When the state machine instance is in the scanning state and the processing logic corresponding to the scanning state is correctly executed, the trigger event is generated to trigger the state machine instance to jump from the scanning state to the parsing state;
[0021] When the state machine instance is in the parsing state and the processing logic corresponding to the parsing state is correctly executed, the trigger event is generated to trigger the state machine instance to jump from the parsing state to the data processing state;
[0022] When the state machine instance is in the data processing state and the processing logic corresponding to the data processing state is correctly executed, the trigger event is generated to trigger the state machine instance to jump from the data processing state to the end state;
[0023] When the state machine instance is in the end state and the processing logic corresponding to the end state is executed correctly, the trigger event is generated to trigger the state machine instance to jump from the end state to the preparation state.
[0024] Furthermore, the processing state also includes an abnormal state. When an exception occurs in the execution result of the processing logic of any of the processing states, the state machine instance jumps to the abnormal state and retries the processing logic that currently has an exception. When the number of retries reaches a preset threshold, if the execution result of the processing logic is still abnormal, the state machine instance jumps to the ready state.
[0025] The invention also discloses a software component analysis preprocessing system based on a state machine, and the system works based on the above-mentioned preprocessing method.
[0026] The present invention also discloses a software component analysis preprocessing system based on a state machine, comprising:
[0027] one or more processors;
[0028] Memory;
[0029] 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.
[0030] 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.
[0031] Compared with the prior art, the preprocessing method provided by the above technical solution of the present invention first configures the state machine framework based on the business processing flow of the preprocessing work. The state machine framework includes the processing state of each stage in the corresponding business processing flow, the business execution event to be executed in each processing state, and the jump condition indicating the state machine to jump between the processing states. Each time a source code package to be processed is received, a corresponding state machine instance will be generated to preprocess the source code package. In this process, multiple source code packages generate multiple state machine instances, and all state machine instances can be executed in parallel, thereby realizing the parallel processing of multiple source code packages, reducing the waiting time between the processing flows of each source code package, and significantly improving the CPU utilization rate. In addition, the preprocessing work based on the state machine enables the business processing flow to be flexibly changed according to the actual requirements of the operation. If the subsequent business processing flow needs to add or reduce steps, it is only necessary to increase or decrease the processing state and configure the corresponding processing logic and jump conditions. There is no need to adjust the entire preprocessing work logic according to the context, and the extensibility is strong and the flexibility is high. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 4 is a flow chart of the preprocessing method in an embodiment of the present invention.
[0033] Figure 2 This is an operation flow chart when an abnormality occurs in the processing logic in an embodiment of the present invention.
[0034] Figure 3 4 is an operation flow chart of the preprocessing system in an embodiment of the present invention. DETAILED DESCRIPTION
[0035] 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.
[0036] This embodiment discloses a state machine-based software component analysis preprocessing method and system that can process multiple source code packages in parallel and flexibly expand the preprocessing process, so as to provide accurate matching data for the subsequent third-party component tracing process. Figure 1 , the preprocessing method specifically comprises the following steps:
[0037] S1: The state machine framework is configured based on the business process flow of the preprocessing work of the source code package in the software component analysis. The configuration content includes: defining a number of processing states corresponding to each stage in the business process flow in the state machine framework, configuring corresponding processing logic for each processing state, and defining jump conditions for jumping between processing states. The processing logic corresponds to the business execution event at the corresponding stage in the business process flow, and the jump condition is used to instruct the state machine to jump from the current processing state to another processing state according to the execution result of the processing logic.
[0038] S2: Generate a plurality of state machine instances corresponding to each source code package to be processed, and process a plurality of source code packages in parallel through each state machine instance.
[0039] In summary, the preprocessing method first configures the state machine framework based on the business processing flow of the preprocessing work. The state machine framework includes the processing states of each stage in the corresponding business processing flow, the business execution events to be executed in each processing state, and the jump conditions that indicate the state machine to jump between processing states. Each time a source code package to be processed is received, a corresponding state machine instance will be generated to preprocess the source code package. This process realizes the concurrent processing of multiple source code packages. When the state machine instance is executed, it will automatically trigger the corresponding processing logic to process the source code package according to the preprocessing progress of the corresponding source code package and the processing state of the current state machine instance. Among them, the business processing flows of each source code package are independent of each other and executed concurrently. The processing of the next source code package does not need to wait for the end of the processing of the previous source code package, thereby shortening the waiting time between processes and significantly improving the overall CPU utilization.
[0040] Secondly, if the business process needs to be adjusted during the subsequent preprocessing process, it is only necessary to configure the corresponding processing state, processing logic and jump conditions in the state machine framework, without changing the entire preprocessing business process, so that the preprocessing work is scalable and flexible. In addition, the configuration and use of the state machine is not limited by the software and hardware environment, and the operation is simple and the use cost is low.
[0041] In summary, this software component parsing preprocessing method based on the state machine realizes the parallel processing of multiple source code packages through the state machine, improves the overall CPU utilization, and significantly improves the preprocessing speed. Based on the state machine, the preprocessing business processing flow is easily scalable, and the preprocessing workflow can be changed according to actual needs. It has strong flexibility and low development cost.
[0042] like Figure 3In this embodiment, the timer Timer periodically scans the database MogoDB for storing source code packages to detect whether there is a source code package to be processed in the database. When it detects a source code package to be processed, it will generate a corresponding state machine instance to process the source code package. The processing state of the generated initialized state machine instance is the ready state.
[0043] Specifically, in the state machine instance, each processing state has a corresponding processing logic. When the state machine instance is in any of the processing states, the processing logic corresponding to the processing state is automatically triggered to execute. The processing states specifically include:
[0044] Ready state. In the ready state, the state machine instance performs a process self-check starting with software component analysis. The state machine instance detects whether the current state is the ready state and whether an exception occurs in the process, and jumps to the processing state based on the detection results.
[0045] Decompression state: In the decompression state, the state machine instance will decompress the source code package. Decompression of the source code package can obtain detailed file information contained in the source code package, so as to extract the target files required in the source code package in the next step. In this embodiment, extracting this part of the core files is conducive to filtering out redundant files, and then providing more accurate matching data for the subsequent software component analysis process, thereby speeding up the traceability of third-party components.
[0046] Scanning state. In the scanning state, the state machine instance extracts the target file in the decompressed source code package according to the preset filtering rules. In this embodiment, the target file is the core file in the source code package, including the core file used to implement the component function. In the scanning state, the state machine instance filters redundant files according to the preset filtering rules, and then extracts this part of the core files as matching data in the tracing process of subsequent software component parsing. The filtering rules include a first filtering rule and a second filtering rule. The first filtering rule includes one or more of a path specification method based on files, a regular rule matching method, and a file format filtering method. The second filtering rule includes removing useless lines such as empty code lines and tab lines based on code lines.
[0047] Parsing state, in the parsing state, the state machine instance calculates a unique identification code corresponding to each target file one by one through a preset identification algorithm. In this embodiment, the unique identification code includes a hash code, and the identification algorithm includes a hash algorithm. Based on the hash code, detailed information such as the location of each target file stored in the database, the source code package it is in, and the storage location of the application can be accurately obtained in the subsequent tracing process.
[0048] Data processing state. In the data processing state, the state machine instance compresses and encrypts the target file and the unique identification code corresponding to the target file. The purpose of compression is to save the space occupied by the target file and the corresponding identification code data in the database, and the purpose of encryption is to prevent data leakage from causing information security problems.
[0049] End state: In the end state, the state machine instance stores the compressed and encrypted target file and the unique identification code corresponding to the target file into the database.
[0050] Furthermore, in this embodiment, the state machine instance generates a corresponding trigger event based on the execution result of the current processing logic and the jump condition, and the trigger event triggers the state machine instance to jump from the current processing state to the next normal business processing state. Specifically including:
[0051] When the state machine instance is in the ready state and the processing logic corresponding to the ready state is executed correctly, a trigger event corresponding to the jump condition being met in the ready state is generated, triggering the state machine instance to jump from the ready state to the decompression state;
[0052] When the state machine instance is in the decompression state and the processing logic corresponding to the preparation state is executed correctly, a trigger event corresponding to the jump condition being met in the decompression state is generated, triggering the state machine instance to jump from the decompression state to the scanning state;
[0053] When the state machine instance is in the scanning state and the processing logic corresponding to the scanning state is executed correctly, a trigger event corresponding to the jump condition being met in the scanning state is generated, triggering the state machine instance to jump from the scanning state to the parsing state;
[0054] When the state machine instance is in the parsing state and the processing logic corresponding to the parsing state is executed correctly, a trigger event corresponding to the jump condition being met in the parsing state is generated, triggering the state machine instance to jump from the parsing state to the data processing state;
[0055] When the state machine instance is in the data processing state and the processing logic corresponding to the data processing state is executed correctly, a trigger event corresponding to the jump condition being met in the data processing state is generated, triggering the state machine instance to jump from the data processing state to the end state;
[0056] When the state machine instance is in the end state and the processing logic corresponding to the end state is executed correctly, a trigger event corresponding to the jump condition in the end state is generated, triggering the state machine instance to jump from the end state to the ready state.
[0057] Furthermore, the processing state also includes an abnormal state. When an exception occurs in the execution result of the processing logic of any processing state, the state machine instance jumps to the abnormal state and retries the current processing logic where the exception occurs. When the number of retries reaches a preset threshold, if the execution result of the processing logic is still abnormal, the state machine instance jumps to the ready state.
[0058] like Figure 2 In this embodiment, the state machine instance executes the corresponding processing logic based on the current processing state. When an exception occurs in the processing logic, the state machine instance jumps to the abnormal state, and then retries the current abnormal processing logic for a preset number of times. At the same time, during each retry, it is determined whether the processing logic can be executed normally. If so, the retry is successful, a trigger event is generated, and the state machine instance jumps to the next normal business processing state. If not, it continues to retry. If the processing logic still has an exception after several retries, the retry fails, and the state machine instance jumps to the ready state, terminating the processing of the current source code package. It is worth mentioning that the default number of retries for the state machine instance is 5 times.
[0059] In another preferred embodiment of the present invention, a state machine-based file preprocessing system is also disclosed, and the system works based on the above preprocessing method.
[0060] The present invention also discloses a state machine-based file preprocessing system, 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.
[0061] 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.
[0062] 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.
[0063] 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 software component analysis preprocessing method based on a state machine, characterized in that: include: The state machine framework is configured based on the business process flow of the preprocessing work of the source code package in the software component analysis, and the configuration content includes: defining a number of processing states corresponding to each stage in the business process flow in the state machine framework, configuring corresponding processing logic for each of the processing states, and defining jump conditions for jumping between the processing states; The processing logic corresponds to the business execution event at the corresponding stage in the business processing flow; The jump condition is used to instruct the state machine to jump from the current processing state to another processing state according to the execution result of the processing logic; A plurality of state machine instances corresponding to each of the source code packages to be processed are generated, and a plurality of the source code packages are processed in parallel by each of the state machine instances.
2. The software component analysis preprocessing method based on a state machine according to claim 1 is characterized in that: The processing state includes several normal business processing states executed in sequence, and the normal business processing state includes: a preparation state, in which the processing logic is used to perform a process self-check starting with software component analysis; a decompression state, in which the processing logic is used to decompress the source code package to obtain file information in the source code package; A scanning state, in which the processing logic is used to extract the target file in the decompressed source code package according to a preset filtering rule; A parsing state, in which the processing logic is used to calculate a unique identification code corresponding to each of the target files one by one through a preset identification algorithm; a data processing state, in which the processing logic is used to compress and encrypt the target file and the unique identification code corresponding to the target file; An end state, in which the processing logic is used to store the compressed and encrypted target file and the unique identification code corresponding to the target file into a database.
3. The software component analysis preprocessing method based on state machine according to claim 2 is characterized in that: When the state machine instance is in the ready state and the processing logic corresponding to the ready state is correctly executed, a trigger event is generated to trigger the state machine instance to jump from the ready state to the decompression state; When the state machine instance is in the decompression state and the processing logic corresponding to the preparation state is correctly executed, the trigger event is generated to trigger the state machine instance to jump from the decompression state to the scanning state; When the state machine instance is in the scanning state and the processing logic corresponding to the scanning state is correctly executed, the trigger event is generated to trigger the state machine instance to jump from the scanning state to the parsing state; When the state machine instance is in the parsing state and the processing logic corresponding to the parsing state is correctly executed, the trigger event is generated to trigger the state machine instance to jump from the parsing state to the data processing state; When the state machine instance is in the data processing state and the processing logic corresponding to the data processing state is correctly executed, the trigger event is generated to trigger the state machine instance to jump from the data processing state to the end state; When the state machine instance is in the end state and the processing logic corresponding to the end state is executed correctly, the trigger event is generated to trigger the state machine instance to jump from the end state to the preparation state.
4. The software component analysis preprocessing method based on a state machine according to claim 2 is characterized in that: The processing state also includes an abnormal state. When an exception occurs in the execution result of the processing logic of any of the processing states, the state machine instance jumps to the abnormal state and retries the processing logic where the exception currently occurs. When the number of retries reaches a preset threshold, if the execution result of the processing logic is still abnormal, the state machine instance jumps to the ready state.
5. A software component analysis preprocessing system based on a state machine, characterized in that: The pretreatment system works based on the pretreatment method according to any one of claims 1 to 4.
6. A software component analysis preprocessing system based on a state machine, 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 4.
7. A computer-readable storage medium, characterized in that: The invention comprises a computer program, wherein the computer program can be executed by a processor to implement the preprocessing method according to any one of claims 1 to 4.
Citation Information
Cited By
SCA feature code updating method and device based on process splitting and storage medium
CN119690473A
SCA signature update method, device and storage medium based on process decomposition
CN119690473B
