Function call analysis method and device based on ASM bytecode and medium

Through the function call analysis method based on ASM bytecode, the problem of parsing function call relationships without running Java programs is solved, efficient and detailed function call path analysis and result output are achieved, and the capabilities of code review, dependency analysis and security vulnerability detection are improved.

CN120631471APending Publication Date: 2025-09-12SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510744063.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-05
Publication Date
2025-09-12

AI Technical Summary

Technical Problem

Existing technologies cannot parse bytecodes and accurately deduce the calling relationships between functions without running the Java program.

Method used

By introducing the function call analysis method based on ASM bytecode, the InvokeMethodCollector, InvokeMethodMatcher, InvokeMethodAnalyser and InvokeMethodResultOutput classes are used to collect, match and analyze the function call information of Java programs, and the analysis process is executed through the InvokeMethodAnalyserUtils tool class.

Benefits of technology

It can accurately deduce the calling relationship between Java functions without running the program, improve the efficiency and security of code analysis, and support multi-dimensional function call analysis and detailed result output.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120631471A_ABST
    Figure CN120631471A_ABST
Patent Text Reader

Abstract

The invention discloses a function call analysis method and device based on ASM byte codes and a medium, belongs to the technical field of computer software code development, and aims to solve the technical problem of how to analyze Java byte codes and accurately deduce a call relation between functions on the premise of not running a program.The technical scheme includes that a Jav a program analysis configuration file is newly added; function method calling information is collected; regular matching of function method calling information is carried out, wherein an InvokeMetal Matcher class is newly added to define a function matching expression; the method comprises the following steps of: analyzing function method substitute information: calling a newly added InvokeMedia Analyser class analysis function, and calling the newly added InvokeMedia Analyser class analysis function; a function method is output to call an information analysis result; an InvokeMetal ResultOutput class output function call result is newly added to a specified file; and a Java program code analysis process is executed, specifically, the InvokeMedia AnalyserUtils tool class is newly added to load the corresponding configuration file, and the Java program code analysis process is executed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer software code development, and in particular to a function call analysis method, device and medium based on ASM bytecode. Background Art

[0002] ASM is a Java bytecode manipulation and analysis framework that can modify or generate Java class files directly in binary form. The ASM bytecode manipulation framework is a core tool in the Java ecosystem for dynamically generating, modifying, and analyzing bytecode. Its efficiency and flexibility make it irreplaceable in scenarios such as AOP, dynamic proxying, and performance optimization.

[0003] Function call static analysis is an important tool for understanding program logic, detecting potential defects (such as uncalled code), and optimizing code interfaces. Currently, source code-based static analysis can only perform code style checks and cannot analyze all function call code blocks in Java programs.

[0004] Therefore, how to parse Java bytecode without running the program and accurately deduce the calling relationship between functions is a technical problem that needs to be solved urgently. Summary of the Invention

[0005] The technical task of the present invention is to provide a function call analysis method, device and medium based on ASM bytecode to solve the problem of how to parse Java bytecode without running the program and accurately deduce the calling relationship between functions.

[0006] The technical task of the present invention is achieved in the following manner: a function call analysis method based on ASM bytecode, the method is as follows:

[0007] New Java program analysis profile: introduced function call analysis method component library;

[0008] Collect function method call information: Add the InvokeMethodCollector class to analyze method metadata in a specified Java program code base;

[0009] Function method call information regular matching: Added the InvokeMethodMatcher class to define function matching expressions;

[0010] Analyze function method substitution information: Add the InvokeMethodAnalyser class to analyze function calls;

[0011] Output function method call information analysis results: Add the InvokeMethodResultOutput class to output function call results to a specified file;

[0012] Execute Java program code analysis process: Add the InvokeMethodAnalyserUtils tool class to load the corresponding configuration file and execute the Java program code analysis process.

[0013] As a preferred option, the newly added Java program analysis configuration file is as follows:

[0014] Added invoke_method.properties template configuration file, which is used to define the configuration file for Java program analysis, using key-value pair format, i.e. key=value;

[0015] Defining inputPath <string>Parameter, inputPath <string>The parameter is used to define the class path for reading the compiled Java program code, and read the Class file through this path to perform function call analysis;

[0016] Define methodPattern[Array <string>] parameter, methodPattern[Array<Strin g> ] parameter is used to perform regular matching on the function methods in the Class under the analyzePath path;

[0017] Define analyzeFields[Array <string>] parameter, analyzeFields[Array<Strin g> ] parameter is used to analyze the specific information of the function method;

[0018] Define statFields[Array <string>] parameter, statFields[Array <string>] parameter is used to perform multi-dimensional aggregation analysis on the specific information of the function method;

[0019] Define outputPath <string>Parameter, outputPath <string>The parameter is used to define the output address of the Java program function call analysis results;

[0020] Defining outputFileType <string>Parameter, outputFileType <string>The parameter is used to define the output file format of the function call analysis results; the output file formats include CSV, Excel, and TXT.

[0021] As a preference, the function method call information is collected as follows:

[0022] In the src / main / com / asm / analyser / core directory, a new InvokeMethodCollect or class is added to collect function and method call information of the compiled Class based on the inputPath of the Java program code;

[0023] Define the loadClass method to load all Class classes from the input Path path of the invoke_method.properties configuration file;

[0024] Define the collectMethod method to collect function call methods for all loaded Class classes, and use ASM's ClassVisitor to read function method meta information and function call information.

[0025] As a preference, the function method call information regular matching is as follows:

[0026] In the src / main / com / asm / analyser / core directory, a new InvokeMethodMatcher class is added to perform regular expression matching on the function call information analyzed by InvokeMethodCollector, thereby filtering out the function methods that need to be analyzed.

[0027] Define the methodPattern method to read the regular expression from the parameter methodPattern in the invoke_method.properties configuration file;

[0028] Define the methodMatch method to perform regular matching on the function call information collected by InvokeMethodCollector and use Pattern to compile the regular expression.

[0029] As a preference, the analysis function method substitution information is specifically as follows:

[0030] In the src / main / com / asm / analyser / core directory, a new InvokeMethodAnalyser class is added to analyze the function call information filtered by InvokeMethodMatcher and output the corresponding analysis results;

[0031] Define the analyzeMethod method, which is used to read the function call information (MethodInfo) filtered by InvokeMethodMatcher according to the analyzeFields field in the invoke_method.properties configuration file;

[0032] Define the statMethod method to aggregate and count the function call information filtered by InvokeMethodMatcher according to the statFields field in the invoke_method.properties configuration file.

[0033] As a preference, the output function method call information analysis results are as follows:

[0034] In the src / main / com / asm / analyser / core directory, add the InvokeMethodResultOutput class to output the function call information analysis results of InvokeMethodAnalyser to the specified file;

[0035] Define the outputResult method to output the function call analysis results of InvokeMethodAnalyser to the specified file according to the outputPath of the invoke_method.properties configuration file;

[0036] Define the outputFileType method, which is used to define the file format in which the function call analysis results are output to the file according to the outputFileType configuration file of invoke_method.properties.

[0037] Preferably, the Java program code analysis process is performed as follows:

[0038] In the src / main / com / asm / analyser directory, add the InvokeMethodAnalyserUtil s tool class to load the corresponding configuration file and execute the Java program code analysis process;

[0039] Define the loadProperties method to load the specified properties file, refer to the invoke_method.properties template configuration file;

[0040] Define the execAnalyse method to execute the analysis process of Java program code; the analysis process of Java program code includes configuration file loading, function call method collection, function call method screening, function call method analysis and function call method analysis result output.

[0041] Better yet, a new InvokeMethodAnalyserUtils tool class is added to load the corresponding configuration file and execute the Java program code analysis process as follows:

[0042] When using the InvokeMethodAnalyserUtils tool class to analyze function calls, use Maven to import the InvokeMethodAnalyserUtils tool class dependency package;

[0043] When using it, first compile the analyzed Java program code and output the Class class;

[0044] Define the configuration file according to the invoke_method.properties template, specify the configuration file in InvokeMethodAnalyserUtils, and execute execAnalyse to perform function call analysis on the Java program code.

[0045] An electronic device comprising: a memory and at least one processor;

[0046] wherein the memory stores computer-executable instructions;

[0047] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the above-mentioned function call analysis method based on ASM bytecode

[0048] A computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the above-mentioned function call analysis method based on ASM bytecode is implemented.

[0049] The ASM bytecode-based function call analysis method, device, and medium of the present invention have the following advantages:

[0050] (1) The present invention is used to parse Java bytecode without running the program, accurately deriving the calling relationships between functions, and can be applied to code review, dependency analysis, security vulnerability detection, and compilation optimization.

[0051] (2) The function call static analysis method based on ASM bytecode of the present invention can quickly analyze the calling code block of a specified function method in a Java program code library, including the function call class, code submission author, code update time, number of code call lines, etc.

[0052] (3) The present invention deeply analyzes Java program bytecode instructions and class structure to analyze function call paths, including the calling code blocks of function methods, function call classes, code submission authors, code update time, and the number of code call lines. Compared with static analysis of source code, this improves the efficiency of code analysis and the security of code programming. At the same time, when using the present invention, developers only need to define the Java program code library path and function path.

[0053] (4) The present invention implements function call analysis of Java program code through the nvokeMethodAnalyserUtils tool class. In addition to function call classes and call code blocks, developers can also configure regular expressions, perform multi-function call analysis, configure code submission authors, code update time, etc. according to their own needs, providing detailed code analysis capabilities;

[0054] (5) The present invention also provides more detailed function call analysis functions, while also improving the code analysis efficiency of developers and the security of code programming. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] The present invention will be further described below with reference to the accompanying drawings.

[0056] Attachment Figure 1 This is a flowchart of the function call analysis method based on ASM bytecode. DETAILED DESCRIPTION

[0057] The following is a detailed description of the ASM bytecode-based function call analysis method, device, and medium of the present invention with reference to the accompanying drawings and specific embodiments.

[0058] Example 1:

[0059] As attached Figure 1 As shown, this embodiment provides a function call analysis method based on ASM bytecode, and the method is specifically as follows:

[0060] S1. Added Java program analysis profile: introduced function call analysis method component library;

[0061] S2. Collect function method call information: Add the InvokeMethodCollector class to analyze the method metadata in the specified Java program code library;

[0062] S3. Function method call information regular matching: Added the InvokeMethodMatcher class to define function matching expressions;

[0063] S4. Analyze function method substitution information: Add the InvokeMethodAnalyser class to analyze function calls;

[0064] S5. Output function method call information analysis results: Add the InvokeMethodResultOutput class to output function call results to the specified file;

[0065] S6. Execute Java program code analysis process: Add the InvokeMethodAnalyserUtils tool class to load the corresponding configuration file and execute the Java program code analysis process.

[0066] The newly added Java program analysis configuration file in step S1 of this embodiment is specifically as follows:

[0067] S101. Added invoke_method.properties template configuration file, which is used to define the configuration file for Java program analysis. It uses the key-value pair format, i.e. key=value;

[0068] S102. Define inputPath <string>Parameter, inputPath <string>The parameter is used to define the class path for reading Java program code compilation, and read the Class file through this path for function call analysis;

[0069] S103、Define methodPattern[Array <string>] parameter, methodPattern[Array <string>] parameter is used to perform regular matching on the function methods in the Class under the analyzePath path;

[0070] S104、Define analyzeFields[Array <string>] parameter, analyzeFields[Array <string>] parameter is used to analyze the specific information of the function method;

[0071] S105、Define statFields[Array <string>] parameter, statFields[Array <string>] parameter is used to perform multi-dimensional aggregation analysis on the specific information of the function method;

[0072] S106. Define outputPath <string>Parameter, outputPath <string>The parameter is used to define the output address of the Java program function call analysis results;

[0073] S107. Define outputFileType <string>Parameter, outputFileType <string>The parameter is used to define the output file format of the function call analysis results; the output file formats include CSV, Excel, and TXT.

[0074] The collection function method call information in step S2 of this embodiment is specifically as follows:

[0075] S201. In the src / main / com / asm / analyser / core directory, add the InvokeMethodCollector class to collect function method call information of the Java program code compiled class according to the inputPath;

[0076] S202. Define the loadClass method to load all Class classes from the inputPath path of the invoke_method.properties configuration file;

[0077] S203. Define the collectMethod method to collect function call methods of all loaded Class classes, and use ASM's ClassVisitor to read function method meta information and function call information.

[0078] The regular matching of function method call information in step S3 of this embodiment is as follows:

[0079] S301. Add the InvokeMethodMatcher class in the src / main / com / asm / analyser / core directory to perform regular expression matching on the function call information analyzed by the InvokeMethodCollector, thereby selecting the function methods that need to be analyzed.

[0080] S302, define the methodPattern method, which is used to read the regular expression from the parameter methodPattern in the invoke_method.properties configuration file;

[0081] S303. Define the methodMatch method to perform regular matching on the function call information collected by InvokeMethodCollector and use Pattern to compile the regular expression.

[0082] The specific information of the analysis function method substitution in step S4 of this embodiment is as follows:

[0083] S401. Add the InvokeMethodAnalyser class in the src / main / com / asm / analyser / core directory to analyze the function call information filtered by the InvokeMethodMatcher class and output the corresponding analysis results.

[0084] S402. Define the analyzeMethod method, which is used to read the function call information (MethodInfo) filtered by the InvokeMethodMatcher according to the analyzeFields field of the invoke_method.properties configuration file;

[0085] S403 , define a statMethod method for performing aggregate statistics on the function call information filtered by InvokeMethodMatcher according to the statFields field of the invoke_method.properties configuration file.

[0086] The analysis results of the output function method call information in step S5 of this embodiment are as follows:

[0087] S501. In the src / main / com / asm / analyser / core directory, add the InvokeMethodResultOutput class to output the function call information analysis results of the InvokeMethodAnalyser to a specified file.

[0088] S502, define the outputResult method, which is used to output the function call analysis result of InvokeMethodAnalyser to a specified file according to the outputPath configuration file of invoke_method.properties;

[0089] S503 , define the outputFileType method, which is used to define the file format in which the function call analysis result is output to a file according to the invoke_method.properties configuration file outputFileType.

[0090] The specific process of executing Java program code analysis in step S6 of this embodiment is as follows:

[0091] S601. In the src / main / com / asm / analyser directory, add the InvokeMethodAnalyserUtils tool class to load the corresponding configuration file and execute the Java program code analysis process;

[0092] S602. Define the loadProperties method to load the specified properties file, refer to the invoke_method.properties template configuration file;

[0093] S603. Define the execAnalyse method to execute the analysis process of the Java program code; wherein the analysis process of the Java program code includes configuration file loading, function call method collection, function call method screening, function call method analysis, and function call method analysis result output.

[0094] The newly added InvokeMethodAnalyserUtils tool class in step S601 of this embodiment is used to load the corresponding configuration file and execute the Java program code analysis process as follows:

[0095] S60101. When using the InvokeMethodAnalyserUtils tool class to analyze function calls, use Maven to import the InvokeMethodAnalyserUtils tool class dependency package.

[0096] S60102. When in use, compile and analyze the Java program code and output the Class class;

[0097] S60103. Define the configuration file according to the invoke_method.properties template, specify the configuration file in InvokeMethodAnalyserUtils, and execute execAnalyse to perform function call analysis on the Java program code.

[0098] Example 2:

[0099] This embodiment also provides an electronic device, including: a memory and at least one processor;

[0100] wherein the memory stores computer-executable instructions;

[0101] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the function call analysis method based on ASM bytecode according to any one of the present inventions.

[0102] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor may be a microprocessor or any conventional processor, etc.

[0103] The memory can be used to store computer programs and / or modules. The processor implements various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created based on the use of the terminal, etc. In addition, the memory can also include high-speed random access memory and non-volatile memory, such as a hard disk, internal memory, a plug-in hard disk, a smart card (SMC), a secure digital (SD) card, a flash memory card, at least one disk storage period, a flash memory device, or other volatile solid-state memory devices.

[0104] Example 3:

[0105] This embodiment further provides a computer-readable storage medium storing a plurality of instructions, which are loaded by a processor to cause the processor to execute the ASM bytecode-based function call analysis method according to any embodiment of the present invention. Specifically, a system or device equipped with a storage medium can be provided, wherein the storage medium stores software program code that implements the functions of any of the above-described embodiments, and a computer (or CPU or MPU) of the system or device can read and execute the program code stored in the storage medium.

[0106] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute part of the present invention.

[0107] Examples of storage media for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code can be downloaded from a server computer via a communication network.

[0108] In addition, it should be clear that the functions of any of the above embodiments can be achieved not only by executing the program code read by the computer, but also by enabling the operating system operating on the computer to complete part or all of the actual operations based on the instructions of the program code.

[0109] In addition, it can be understood that the program code read from the storage medium is written into the memory provided in the expansion board inserted into the computer or into the memory provided in the expansion unit connected to the computer, and then based on the instructions of the program code, the CPU installed on the expansion board or expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above embodiments.

[0110] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.< / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / string>

Claims

1. A function call analysis method based on ASM bytecode, characterized in that: The method is as follows: New Java program analysis profile: introduced function call analysis method component library; Collect function method call information: Add the InvokeMethodCollector class to analyze method metadata in a specified Java program code base; Function method call information regular matching: Added the InvokeMethodMatcher class to define function matching expressions; Analyze function method substitution information: Add the InvokeMethodAnalyser class to analyze function calls; Output function method call information analysis results: Add the InvokeMethodResultOutput class to output function call results to a specified file; Execute Java program code analysis process: Add the InvokeMethodAnalyserUtils tool class to load the corresponding configuration file and execute the Java program code analysis process.

2. The function call analysis method based on ASM bytecode according to claim 1, characterized in that: The newly added Java program analysis configuration file is as follows: Added invoke_method.properties template configuration file, which is used to define the configuration file for Java program analysis, using key-value pair format, i.e. key=value; Defining inputPath <string>Parameter, inputPath <string> The parameter is used to define the class path for reading the compiled Java program code, and read the Class file through this path to perform function call analysis;< / string> < / string> Define methodPattern[Array <string> ] parameter, methodPattern[Array<Strin g> ] parameter is used to perform regular matching on the function methods in the Class under the analyzePath path;< / string> Define analyzeFields[Array <string> ] parameter, analyzeFields[Array<Strin g> ] parameter is used to analyze the specific information of the function method;< / string> Define statFields[Array <string>] parameter, statFields[Array <string> ] parameter is used to perform multi-dimensional aggregation analysis on the specific information of the function method;< / string> < / string> Define outputPath <string>Parameter, outputPath <string> The parameter is used to define the output address of the Java program function call analysis results;< / string> < / string> Defining outputFileType <string>Parameter, outputFileType <string> The parameter is used to define the output file format of the function call analysis results; the output file formats include CSV, Excel, and TXT.< / string> < / string> 3. The function call analysis method based on ASM bytecode according to claim 1, characterized in that: The collection function method call information is as follows: In the src / main / com / asm / analyser / core directory, a new InvokeMethodCollect or class is added to collect function and method call information of the compiled Class based on the inputPath of the Java program code; Define the loadClass method to load all Class classes from the input Path path of the invoke_method.properties configuration file; Define the collectMethod method to collect function call methods for all loaded Class classes, and use ASM's ClassVisitor to read function method meta information and function call information.

4. The function call analysis method based on ASM bytecode according to claim 1, characterized in that: The regular matching of function method call information is as follows: In the src / main / com / asm / analyser / core directory, a new InvokeMethodMatcher class is added to perform regular expression matching on the function call information analyzed by InvokeMethodCollector, thereby filtering out the function methods that need to be analyzed. Define the methodPattern method to read the regular expression from the parameter methodPattern in the invoke_method.properties configuration file; Define the methodMatch method to perform regular matching on the function call information collected by InvokeMethodCollector and use Pattern to compile the regular expression.

5. The function call analysis method based on ASM bytecode according to claim 1, characterized in that: The specific information of the analysis function method substitution is as follows: In the src / main / com / asm / analyser / core directory, a new InvokeMethodAnalyser class is added to analyze the function call information filtered by InvokeMethodMatcher and output the corresponding analysis results; Define the analyzeMethod method, which is used to read the function call information (MethodInfo) filtered by InvokeMethodMatcher according to the analyzeFields field in the invoke_method.properties configuration file; Define the statMethod method to aggregate and count the function call information filtered by InvokeMethodMatcher based on the st atFields field in the invoke_method.properties configuration file.

6. The function call analysis method based on ASM bytecode according to claim 1, characterized in that: The analysis results of the output function method call information are as follows: In the src / main / com / asm / analyser / core directory, add the InvokeMethodResultOutput class to output the function call information analysis results of InvokeMethodAnalyser to the specified file; Define the outputResult method to output the function call analysis results of InvokeMethodAnalyser to the specified file according to the outputPath of the invoke_method.properties configuration file; Define the outputFileType method, which is used to define the file format in which the function call analysis results are output to the file according to the outputFileType configuration file of invoke_method.properties.

7. The function call analysis method based on ASM bytecode according to any one of claims 1 to 6, characterized in that: The specific process of executing Java program code analysis is as follows: In the src / main / com / asm / analyser directory, add the InvokeMethodAnalyserUtil s tool class to load the corresponding configuration file and execute the Java program code analysis process; Define the loadProperties method to load the specified properties file, refer to the invoke_method.properties template configuration file; Define the execAnalyse method to execute the analysis process of Java program code; the analysis process of Java program code includes configuration file loading, function call method collection, function call method screening, function call method analysis and function call method analysis result output.

8. The function call analysis method based on ASM bytecode according to claim 7, characterized in that: Added the InvokeMethodAnalyserUtils tool class to load the corresponding configuration file and execute the Java program code analysis process as follows: When using the InvokeMethodAnalyserUtils tool class to analyze function calls, use Maven to import the InvokeMethodAnalyserUtils tool class dependency package; When using it, first compile the analyzed Java program code and output the Class class; Define the configuration file according to the invoke_method.properties template, specify the configuration file in InvokeMethodAnalyserUtils, and execute execAnalyse to perform function call analysis on the Java program code.

9. An electronic device, characterized in that: include: memory and at least one processor; wherein the memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the function call analysis method based on ASM bytecode according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the function call analysis method based on ASM bytecode as described in any one of claims 1 to 8 is implemented.