Code matching analysis method and device, electronic equipment and storage medium
By acquiring the source code package and calculating hash information to build an index, the matching status of the files to be analyzed can be quickly filtered, solving the problem of low efficiency in source code matching detection for self-developed software and achieving efficient code matching analysis.
Patent Information
- Application Number
- CN202210337362.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-31
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2042-03-31
AI Technical Summary
Existing technologies for source code matching and detection of self-developed software have low efficiency, cannot quickly and accurately process a large amount of source code data information of open source components, and have low matching calculation efficiency.
By obtaining the source code package, parsing the source code files, calculating hash information, and building a directory index, inputting the package to be analyzed and calculating hash information, finding matching directories, filtering consecutively arranged index information, and determining the matching status.
It enables fast and accurate matching analysis of large amounts of code, improving detection coverage and matching efficiency, and accurately identifying the matching status of self-developed software and open-source components.
Smart Images

Figure CN114756586B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of code analysis technology, and in particular to a code matching analysis method, apparatus, electronic device and storage medium. Background Technology
[0002] Currently, independently developed information technology products have become an important development trend in my country's information technology industry. To accelerate the security process of independently developed software, it is necessary not only to reduce reliance on non-self-developed software but also to conduct code testing and analysis to reduce security risks. Therefore, source code matching testing (such as self-development rate testing) of independently developed software is required. This analysis can reveal the source code matching status of independently developed software with other open-source components, facilitating software development and maintenance.
[0003] However, currently available software for source code matching and detection (such as detection of self-developed rate) of independently developed software is inefficient. It cannot quickly and accurately process and analyze the data information of a large number of open source component source codes efficiently, and the matching calculation efficiency is also low. Summary of the Invention
[0004] The purpose of this application is to provide a code matching analysis method, apparatus, electronic device, and storage medium to address the shortcomings of some of the aforementioned technical problems. This method can quickly and accurately perform matching analysis on a large number of codes, thereby improving detection coverage and matching efficiency.
[0005] To achieve the above objectives, this application provides a code matching analysis method, which includes:
[0006] Obtain the source code package, which includes several source code files;
[0007] The source code package is parsed to obtain the corresponding source code file. Each source code file includes several lines of code. The corresponding hash information is calculated based on each line of code. A corresponding directory is established based on the hash information. The corresponding directory contains corresponding index information. The index information records the component information corresponding to the line of code and the line number information of the line of code.
[0008] Input the package to be analyzed, and calculate the hash information corresponding to each line of code in each file to be analyzed in the package;
[0009] Based on the hash information corresponding to each line of code in each file to be analyzed, find the matching directory and read the index information in the matching directory;
[0010] Based on the component information and row number information corresponding to the index information in each of the paired directories, filter the index information that corresponds to the component information and the row number information is arranged continuously;
[0011] determining matching condition information corresponding to the file to be analyzed according to the screened index information.
[0012] Optionally, the "screening the index information corresponding to the component information and the line number information in the paired directories according to the component information and the line number information" comprises:
[0013] According to the index information corresponding to the same component information and the line number information arranged continuously, the number of lines arranged continuously corresponding to each component information is obtained.
[0014] Optionally, the "obtaining the number of lines arranged continuously corresponding to each component information" comprises:
[0015] According to the index information screened, the number of line number information arranged continuously under the same component information is determined respectively to determine the number of lines.
[0016] Optionally, the matching condition information comprises matching success and matching failure.
[0017] The "determining matching condition information corresponding to the file to be analyzed according to the screened index information" comprises:
[0018] Comparing the number of lines arranged continuously corresponding to each component information with a preset judgment value respectively.
[0019] If at least one of the number of lines is greater than the preset judgment value, the matching condition information corresponding to the file to be analyzed is matching success.
[0020] Optionally, the method further comprises:
[0021] The matching condition information comprises matching success and matching failure.
[0022] Determining the number of files to be analyzed in the analysis package that match successfully.
[0023] Determining the matching degree information of the analysis package according to the number of files to be analyzed that match successfully.
[0024] Optionally, the matching degree information comprises self-development rate.
[0025] According to the number of files to be analyzed that match successfully and the total number of files to be analyzed in the analysis package, the corresponding self-development rate is calculated.
[0026] Optionally, the "obtaining the source code package" comprises:
[0027] Collecting open source component information, the open source component information including code repository address information;
[0028] Downloading related source code according to the code repository address information;
[0029] Obtaining the source code package according to the downloaded source code.
[0030] To achieve the above object, the application further provides a code matching analysis device, comprising:
[0031] An acquisition module is configured to acquire a source code package, the source code package including a plurality of source code files;
[0032] An analysis module is configured to analyze the source code package to obtain corresponding source code files, each source code file including a plurality of lines of code, corresponding hash information being calculated according to each line of code, a corresponding directory being established according to the hash information, corresponding index information being established in the corresponding directory, the index information recording component information corresponding to the line of code and line number information where the line of code is located;
[0033] An input module is configured to input a package to be analyzed and calculate hash information corresponding to each line of code of each file to be analyzed in the package to be analyzed;
[0034] A pairing module is configured to find paired directories according to the hash information corresponding to each line of code of each file to be analyzed and read the index information in the paired directories;
[0035] A screening module is configured to screen index information corresponding to the component information and the line number information according to the index information in each paired directory;
[0036] A calculation module is configured to determine matching condition information corresponding to the file to be analyzed according to the screened index information.
[0037] To achieve the above object, the application further provides an electronic device, comprising:
[0038] A processor;
[0039] A memory having executable instructions of the processor stored therein;
[0040] The processor is configured to execute the executable instructions to perform the code matching analysis method as described above.
[0041] To achieve the above object, the application further provides a computer readable storage medium, which stores a computer program, and the computer program comprises the code matching analysis method as described above when executed by a processor.
[0042] The application further provides a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. A processor of an electronic device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the electronic device executes the code matching analysis method as described above.
[0043] The application obtains and parses a source code package to obtain a plurality of source code files, then calculates corresponding hash information according to each line of code in the source code files respectively, and establishes corresponding directories according to the hash information respectively, and each directory has corresponding index information established therein, wherein the index information records component information corresponding to the line of code and line number information where the line of code is located. In use, only the to-be-analyzed package needs to be input, and the hash information corresponding to each line of code in each to-be-analyzed file is calculated, the paired directories are searched according to the hash information corresponding to each line of code of each to-be-analyzed file, the index information corresponding to the component information and continuously arranged line number information is screened in combination with the index information in the paired directories, and finally the matching status information corresponding to the to-be-analyzed file is determined according to the screened index information. According to the application, the hash information corresponding to each line of code is obtained, and when the to-be-analyzed file is paired and analyzed, only the hash information corresponding to the code in the to-be-analyzed file needs to be matched with the directory, and the index information recorded in the component information and the line number information are combined to quickly screen the index information corresponding to the component information and continuously arranged line number information, so as to determine the matching status of the to-be-analyzed file. Therefore, the code matching analysis can be quickly and accurately performed on a large number of codes, and the detection coverage and matching efficiency are improved. BRIEF DESCRIPTION OF DRAWINGS
[0044] Figure 1 A flowchart of the code matching analysis method of the embodiment of the application is shown.
[0045] Figure 2 A schematic block diagram of the code matching analysis device of the embodiment of the application is shown.
[0046] Figure 3 A schematic block diagram of the electronic device of the embodiment of the application is shown. DETAILED DESCRIPTION
[0047] To explain the technical content, structural features, implementation principles and achieved objects and effects of the application in detail, the following will be described in detail in combination with the embodiments and the accompanying drawings.
[0048] Please refer to Figure 1The embodiment of the application discloses a code matching analysis method, which comprises the following steps:
[0049] 101, obtain a source code package, the source code package comprising a plurality of source code files.
[0050] Specifically, the plurality of source code files in the source code package respectively record data information of different open source components, such as component names, codes and the like.
[0051] In some embodiments, the above-mentioned "obtaining a source code package" comprises the following steps:
[0052] collecting open source component information, the open source component information comprising code repository address information;
[0053] downloading relevant source codes according to the code repository address information;
[0054] obtaining a source code package according to the downloaded source codes.
[0055] By collecting open source component information and downloading relevant source codes according to corresponding code repository address information, and collecting and packaging the downloaded source codes to obtain a source code package, a large amount of source codes corresponding to open source components can be quickly obtained, the number of matchable components is increased, the coverage is improved, and more comprehensive code matching analysis can be carried out subsequently.
[0056] Specifically, the open source component information can be obtained from some databases recording relevant data of open source components, such as maven, npm, pypi and the like remote databases. The open source component information usually comprises component names, versions and code repository address information, and the code repository address information refers to the code repository address where the source codes corresponding to the components are located, such as the position of the source codes in the corresponding source code hosting platform url. In use, the collected open source component information is stored in a component library, then relevant source codes are downloaded from the corresponding source code hosting platform according to the code repository address information in the open source component information of the component library and are updated to the component library (the source codes corresponding to the open source component itself can be downloaded, or the source codes of other components associated with the open source component can be downloaded, and the like), and finally the downloaded source codes are stored and integrated to obtain a source code package. Of course, when the version of the open source component is updated, the updated source codes can be downloaded from the corresponding code repository address. In addition, the data of the component library can be traversed to find open source components without downloaded source codes, and the corresponding source codes can be downloaded from the source code hosting platform to improve the number and efficiency of source code collection.
[0057] 102, parse the source code package to obtain corresponding source code files, each source code file comprising a plurality of lines of codes, corresponding hash information being calculated according to each line of code, a corresponding directory being established according to the hash information, and corresponding index information being established in the corresponding directory, the index information recording component information corresponding to the line of code and line number information where the line of code is located.
[0058] Generally, each source code file has corresponding code, and is often composed of multiple lines of code. Since the specific composition of each line of code is usually diverse, different hash information can be calculated for each line of code (the specific form of the hash information is not limited here, which can be 4-bit hash or 16-bit hash, etc. as long as each line of code is calculated in the same way and the specific form of the calculated hash information is consistent, such as the calculated hash information is 16-bit hash), of course, if the code content is the same, the calculated hash information is also the same, for example, a source code file is composed of 10 lines of code, and the corresponding hash information is calculated for each line of code, if the code content of the 8th line and the 10th line is the same, the hash information corresponding to the 8th line and the 10th line is the same. Then, the corresponding directory is established according to each hash information, for example, when the hash information is 16-bit hash, a directory is established with 4-bit hash, to establish a four-level directory (of course, the directory can also be divided according to other specific forms, which is not limited here), and finally the corresponding index information is established in this four-level directory, which is used to record the component information corresponding to the line of code and the line number information of the line of code, for example, this four-level directory is obtained according to the hash information calculated for the 3rd line of code, and the four-level directory records the component information to which the 3rd line of code belongs and the line number information (3rd line) of the line of code. It should be noted that the above specific values are only for example and are not limited here. In addition, the specific calculation principle and process of the hash is a routine means for those skilled in the art, which is not described here.
[0059] 103, input the package to be analyzed, and calculate the hash information corresponding to each line of code of each file to be analyzed in the package to be analyzed.
[0060] Generally, the specific form of the hash information calculated according to each line of code of the file to be analyzed is the same as that of the hash information calculated according to each line of code of the source code file, such as 16-bit hash, which is convenient for subsequent matching. Of course, the specific calculation method is also a routine means, which is not described here, as long as the corresponding hash information can be calculated according to each line of code in each file to be analyzed.
[0061] 104, find the paired directory according to the hash information corresponding to each line of code of each file to be analyzed, and read the index information in the paired directory.
[0062] Specifically, according to the hash information corresponding to each line of code of each file to be analyzed, the directory corresponding to the hash information is searched respectively. Since each directory is established according to the hash information corresponding to each line of code of the source code file, in the searching process, only the hash information needs to be compared with the directory to find the directory matched with the hash information corresponding to each line of code in the file to be analyzed. If the directory matched with the hash information is found, it indicates that the source code package contains the code corresponding to the hash information. Of course, when the code analysis is matched, not only the matching of single line of code is considered, but also the matching of multiple lines of code is needed to be judged comprehensively, which can not only avoid the matching between some standard codes (industry common codes), but also improve the accuracy. Therefore, when the directory matched with each hash information is found, the index information in the matched directory is read to further analyze and improve the reliability of the matching.
[0063] 105. According to the component information and line number information corresponding to the index information in the matched directory, the index information with the component information corresponding and the line number information continuously arranged is screened.
[0064] Generally, in the process of code matching, not only the matching between single line of code, but also the matching between multiple lines of code continuously arranged is needed to improve the reliability of code matching. Here, it is needed to compare whether the multiple lines of code continuously arranged are from the same component and whether the multiple lines of code continuously arranged are all successfully matched, and of course the specific number of lines of code continuously arranged can be set by itself, such as 20 lines, which is not limited here. Of course, in the present application, all the index information with the component information corresponding and the line number information continuously arranged can be screened first, and then whether the specific number of lines is judged in the subsequent analysis.
[0065] The following is an example, assuming that the file A1 to be analyzed has 10 lines of code, respectively denoted as B1-B10, the hash information is calculated according to each line of code, and the paired directory is searched according to the hash information corresponding to each line of code, and the index information in the paired directory is read. Assuming that codes B1-B8 are paired to directories C1-C8, the index information D1-D8 of directories C1-C8 is read, and the index information corresponding to the component information and the line number information is filtered according to the component information and the line number information, assuming that index information D1, D2, and D3 all correspond to component E1, and D1, D2, and D3 correspond to 3 lines of code arranged continuously in component E1 (such as 1-3 lines of code in component E1), therefore, index information D1, D2, and D3 meet the condition of component information corresponding and line number information arranged continuously, assuming that index information D4-D8 all correspond to component E2, and D4-D8 correspond to 5 lines of code arranged continuously in component E2 (such as 2-6 lines of code in component E2), therefore, index information D4-D8 meet the condition of component information corresponding and line number information arranged continuously. It should be noted that the above specific forms are only for example and understanding, and are not limited herein.
[0066] In some embodiments, the above-mentioned "filtering index information corresponding to component information and line number information according to component information and line number information corresponding to index information in paired directories" includes:
[0067] According to the index information corresponding to the line number information arranged continuously under the same component information, the number of lines arranged continuously corresponding to each component information is obtained.
[0068] By obtaining the number of lines arranged continuously corresponding to each component information, the number of code lines paired with each component information can be quickly and accurately obtained, which is convenient for subsequent analysis.
[0069] Further, the above-mentioned "obtaining the number of lines arranged continuously corresponding to each component information" includes:
[0070] According to the filtered index information, the number of line number information arranged continuously under the same component information is determined to determine the number of lines.
[0071] By determining the number of line number information arranged continuously under the same component information to determine the number of lines, the number of code lines paired with each component information can be accurately and quickly obtained, which is convenient for subsequent analysis.
[0072] Continuing to refer to the above example, since the index information D1, D2, D3 satisfies the condition that the component information corresponds (all correspond to component E1) and the line number information is arranged continuously (the codes of 3 continuous lines corresponding to component E1 are arranged), and the index information D4-D8 satisfies the condition that the component information corresponds (all correspond to component E2) and the line number information is arranged continuously (the codes of 5 continuous lines corresponding to component E2 are arranged), according to the number of continuously arranged line number information under the same component information in the screened index information, the number of lines is determined, so there are 3 lines of codes in the file A1 to be analyzed that are paired with component E1, and 5 lines of codes that are paired with component E2.
[0073] 106. Determining the matching condition information corresponding to the file to be analyzed according to the screened index information.
[0074] Specifically, the matching condition information refers to the matching degree of the codes of each file to be analyzed and the codes in the source code package. The specific form of the matching condition information can be a specific numerical value, such as a matching rate of 80%, or a specific level, such as a high matching degree (which can also be represented by characters such as ABC to represent the level), which is not limited herein.
[0075] In some embodiments, the matching condition information includes matching success and matching failure.
[0076] The above "determining the matching condition information corresponding to the file to be analyzed according to the screened index information" includes:
[0077] Comparing the number of continuously arranged line numbers corresponding to each component information with a preset determination value, respectively;
[0078] If at least one line number is greater than the preset determination value, the matching condition information corresponding to the file to be analyzed is matching success.
[0079] By comparing the number of continuously arranged line numbers corresponding to each component information with a preset determination value, respectively, the matching condition information corresponding to the file to be analyzed is determined. If the number of continuously arranged line numbers corresponding to any component information is greater than the preset determination value, it means that there is a certain number of codes (the number is greater than the preset determination value) in the file to be analyzed that are paired with the codes of the corresponding component information, that is, the similarity of the codes of the file to be analyzed and the codes of the corresponding component information is high.
[0080] Continuing to refer to the above example, since there are 3 lines of code in the file A1 to be analyzed that are paired with the component E1 and 5 lines of code that are paired with the component E2, and the preset determination value is set to 4 lines, since there are 5 lines of code in the file A1 to be analyzed that are paired with the component E2, it is indicated that the file A1 to be analyzed and the corresponding matching status information are matched successfully (and matched successfully with the component E2). Of course, if the number of line numbers of the file to be analyzed and the plurality of components respectively paired is greater than the preset determination value, it is also indicated that the file to be analyzed and the corresponding matching status information are matched successfully, such as assuming that the file A2 to be analyzed is respectively paired with the components E3, E4 and E5, wherein A2 has 100 lines of code, the number of line numbers respectively paired with the components E3, E4 and E5 is 40, 40 and 20, and the preset determination value is set to 35 lines, it is indicated that the file to be analyzed and the corresponding matching status information are matched successfully (and matched successfully with the components E3 and E4), as long as the number of continuously arranged line numbers corresponding to any component information is greater than the preset determination value, the matching status information corresponding to the file to be analyzed can be determined as matched successfully. Of course, if the number of continuously arranged line numbers corresponding to each component information is less than the preset determination value, the matching status information corresponding to the file to be analyzed can be determined as matched unsuccessfully. It should be noted that the above specific forms are only for example and for understanding, and are not limited herein.
[0081] In some embodiments, the above method further comprises:
[0082] The matching status information comprises matching success and matching failure;
[0083] Determining the number of files to be analyzed matched successfully in the package to be analyzed;
[0084] Determining the matching degree information of the package to be analyzed according to the number of files to be analyzed matched successfully.
[0085] Since there are a plurality of files to be analyzed in the package to be analyzed, the matching status information of each file to be analyzed is analyzed respectively to determine the number of files to be analyzed matched successfully, and then the matching degree information of the entire package to be analyzed can be analyzed, which is convenient for the developer to clearly understand the overall situation of the package to be analyzed.
[0086] Specifically, the specific form of the matching degree information of the package to be analyzed can be a specific numerical value, such as a matching rate of 80%, etc., and can also be a specific level, such as a higher matching degree (which can also be represented by ABC characters to represent the level), and is not limited herein.
[0087] The following is an example, assuming that the package to be analyzed has 10 files to be analyzed, each of which is analyzed by the code matching analysis described above to obtain the matching status information corresponding to each file to be analyzed, and the number of successfully matched files to be analyzed in the package to be analyzed is determined. Assuming that 6 files to be analyzed have matching status information that is successfully matched, the matching degree information of the package to be analyzed is determined according to the number of successfully matched files to be analyzed, that is, the matching degree of the package to be analyzed is large, and 6 of the 10 files to be analyzed are successfully matched. It should be noted that the specific forms and the like described above are only for illustration and understanding, and are not limited herein.
[0088] Further, the matching degree information includes a self-development rate.
[0089] The self-development rate is calculated according to the number of successfully matched files to be analyzed and the total number of files to be analyzed in the package to be analyzed.
[0090] The self-development rate is calculated according to the number of successfully matched files to be analyzed and the total number of files to be analyzed in the package to be analyzed, which facilitates the developer to clearly understand the matching status of the package to be analyzed.
[0091] Specifically, the self-development rate refers to the degree of independent research and development, such as the degree of independent research and development of the code in the file to be analyzed, that is, the proportion of the number of codes in the file to be analyzed that are not successfully matched with the source code package.
[0092] The above example is continued to illustrate, assuming that 6 of the 10 files to be analyzed in the package to be analyzed have matching status information that is successfully matched. Since the matching status information of the file to be analyzed is successfully matched, it reflects that the code in the corresponding file to be analyzed has a high matching degree with the code in the source code package, and therefore can be regarded as non-self-developed code (having a high matching degree with existing code). If the matching status information of the file to be analyzed is a failure, it reflects that the code in the corresponding file to be analyzed has a low matching degree with the code in the source code package, and therefore can be regarded as self-developed code (having a low matching degree with existing code). Therefore, 6 of the 10 files to be analyzed in the package to be analyzed have non-self-developed code, and 4 of the files to be analyzed have self-developed code, so the self-development rate can be calculated according to the number of successfully matched files to be analyzed and the total number of files to be analyzed in the package to be analyzed. Specifically, the ratio of the number of self-developed files to the total number of files in the package to be analyzed, such as the self-development rate of the above package to be analyzed, which is 40% (4 / 10).
[0093] Of course, in some embodiments, all data can be displayed for the developer to refer to, and the self-development rate of the package to be analyzed can be viewed from the perspective of the package to be analyzed or the file to be analyzed, and the matching status information of each file to be analyzed in the package to be analyzed can be viewed, such as the relevant information of the successfully matched code, and the like, which is not limited herein.
[0094] The application obtains and analyzes a source code package to obtain a plurality of source code files, then calculates corresponding hash information according to each line of code in the source code files respectively, and establishes corresponding directories according to the hash information respectively, and corresponding index information is established in each directory, wherein the index information records component information corresponding to the line of code and line number information where the line of code is located. In use, only the package to be analyzed needs to be input, and the hash information corresponding to each line of code in each file to be analyzed is calculated, the paired directories are found according to the hash information corresponding to each line of code of each file to be analyzed, the index information corresponding to the component information and continuously arranged line number information is screened in combination with the index information in the paired directories, and finally the matching condition information corresponding to the file to be analyzed is determined according to the screened index information. According to the application, the hash information corresponding to each line of code is obtained, and when the file to be analyzed is paired and analyzed, only the hash information corresponding to the code in the file to be analyzed needs to be matched with the directory, and the index information recorded in the component information and the line number information are combined to quickly screen the index information corresponding to the component information and continuously arranged line number information, so as to determine the matching condition of the file to be analyzed, thereby being capable of quickly and accurately matching and analyzing a large number of codes, and improving the detection coverage and matching efficiency.
[0095] Please refer to Figure 2 The embodiment of the application further discloses a code matching analysis device, which comprises:
[0096] The acquisition module 10 is used for acquiring a source code package, and the source code package comprises a plurality of source code files;
[0097] The analysis module 11 is used for analyzing the source code package to obtain corresponding source code files, each source code file comprises a plurality of lines of code, corresponding hash information is calculated according to each line of code respectively, corresponding directories are established according to the hash information, and corresponding index information is established in the corresponding directories, wherein the index information records component information corresponding to the line of code and line number information where the line of code is located;
[0098] The input module 12 is used for inputting a package to be analyzed, and calculating hash information corresponding to each line of code of each file to be analyzed in the package to be analyzed;
[0099] The pairing module 13 is used for finding paired directories according to the hash information corresponding to each line of code of each file to be analyzed, and reading index information in the paired directories;
[0100] The screening module 14 is used for screening index information corresponding to the component information and continuously arranged line number information according to the index information in each paired directory;
[0101] The calculation module 15 is used to determine the matching status information of the file to be analyzed based on the filtered index information.
[0102] For a detailed description of the code matching analysis device, please refer to the code matching analysis method described above, which will not be repeated here.
[0103] Please see Figure 3 This application also discloses an electronic device comprising:
[0104] Processor 21;
[0105] Memory 20, which stores executable instructions of processor 21;
[0106] The processor 21 is configured to execute the above-described code matching and analysis method by executing executable instructions.
[0107] This application also discloses a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the above-described code matching and analysis method.
[0108] This application also discloses a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. The processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the aforementioned code matching analysis method.
[0109] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by hardware related to computer program instructions. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0110] The above-disclosed examples are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall fall within the scope of this application.
Claims
1. A code matching and analysis method, characterized in that, include: Obtain the source code package, which includes several source code files; The source code package is parsed to obtain the corresponding source code file. Each source code file includes several lines of code. The corresponding hash information is calculated based on each line of code. A corresponding directory is established based on the hash information. The corresponding directory contains corresponding index information. The index information records the component information corresponding to the line of code and the line number information of the line of code. The component information is open source component information, including component name, version and code repository address. Input the package to be analyzed, and calculate the hash information corresponding to each line of code in each file to be analyzed in the package; Based on the hash information corresponding to each line of code in each file to be analyzed, the matching directory is found, and the index information in the matching directory is read. The hash information calculated based on each line of code in the file to be analyzed is in the same specific form as the hash information calculated based on each line of code in the source code file. Based on the component information and row number information corresponding to the index information in each of the paired directories, filter the index information that corresponds to the component information and the row number information is arranged continuously; The matching status information corresponding to the file to be analyzed is determined based on the filtered index information; The phrase "filtering the index information corresponding to the component information and the row number information in each paired directory, where the row number information is consecutively arranged" includes: Based on the index information corresponding to the row number information under the same component information and with consecutive row numbers, obtain the number of consecutive row numbers corresponding to each component information. The phrase "obtaining the number of consecutive row numbers corresponding to each of the component information" includes: Based on the filtered index information, the number of consecutively arranged row numbers under the same component information is determined to determine the number of row numbers.
2. The code matching analysis method as described in claim 1, characterized in that, The matching status information includes successful matching and failed matching. The phrase "determining the matching status information corresponding to the file to be analyzed based on the filtered index information" includes: The number of consecutively arranged row numbers corresponding to each component information is compared with a preset judgment value; If the number of at least one of the line numbers is greater than the preset judgment value, then the matching status information corresponding to the file to be analyzed is a successful match.
3. The code matching analysis method as described in claim 1, characterized in that, Also includes: The matching status information includes successful matching and failed matching. Determine the number of files in the package to be analyzed that successfully match; The matching degree information of the package to be analyzed is determined based on the number of files that are successfully matched.
4. The code matching analysis method as described in claim 3, characterized in that, The matching degree information includes the self-developed rate; The self-developed rate is calculated based on the number of successfully matched files to be analyzed and the total number of files to be analyzed in the package to be analyzed.
5. The code matching analysis method as described in claim 1, characterized in that, The "obtaining source code package" includes: Collect information on open-source components, including code repository address information; Download the relevant source code based on the code repository address information; The source code package is obtained based on the downloaded source code.
6. A code matching and analysis device, characterized in that, include: An acquisition module is used to acquire a source code package, which includes several source code files. The parsing module is used to parse the source code package to obtain the corresponding source code file. Each source code file includes several lines of code. The corresponding hash information is calculated based on each line of code. A corresponding directory is established based on the hash information. The corresponding directory contains corresponding index information. The index information records the component information corresponding to the line of code and the line number information of the line of code. The component information is open source component information, including component name, version and code repository address. The input module is used to input the package to be analyzed and to calculate the hash information corresponding to each line of code in each file to be analyzed in the package. The pairing module is used to find the paired directory based on the hash information corresponding to each line of code in each file to be analyzed, and to read the index information in the paired directory. The hash information calculated based on each line of code in the file to be analyzed is in the same specific form as the hash information calculated based on each line of code in the source code file. A filtering module is used to filter index information that corresponds to the component information and the row number information is arranged continuously, based on the component information and the row number information corresponding to the index information in each paired directory. A calculation module, which is used to determine the matching status information corresponding to the file to be analyzed based on the filtered index information; The phrase "filtering the index information corresponding to the component information and the row number information in each paired directory, where the row number information is consecutively arranged" includes: Based on the index information corresponding to the row number information under the same component information and with consecutive row numbers, obtain the number of consecutive row numbers corresponding to each component information. The phrase "obtaining the number of consecutive row numbers corresponding to each of the component information" includes: Based on the filtered index information, the number of consecutively arranged row numbers under the same component information is determined to determine the number of row numbers.
7. An electronic device, characterized in that, include: processor; A memory in which executable instructions of the processor are stored; The processor is configured to execute the code matching analysis method according to any one of claims 1-5 by executing the executable instructions.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the code matching analysis method as described in any one of claims 1-5.
Citation Information
Patent Citations
Program source code similarity detection method suitable for large-scale samples
CN111290784A
Analysis of a legacy source code application
US20090164984A1