Code processing method and device, equipment and storage medium
By obtaining and decompiling the enhanced bytecode of the class during the Java application runtime, the problem of developers understanding the bytecode logic of Java runtime is solved, and the parsing and displaying of the bytecode of Java runtime is realized. , simplifies the debugging process.
Patent Information
- Application Number
- CN202410963540.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-18
- Publication Date
- 2024-12-13
AI Technical Summary
The existing technology cannot effectively help developers understand and debug enhanced Java bytecode, resulting in logical hiding and opacity becoming a pain point for developers to track and understand technical processes.
By using Java proxy features to obtain the enhanced bytecode content of the class dynamically generated class through the monitoring interface and detection interface, decompile into a displayable source code file, so as to enable the Developers read.
It realizes the parsing and display of dynamic bytecode in Java runtime, simplifies the process of developers understanding the enhanced logic and mechanism of runtime, and reduces the difficulty of debugging and tracking.
Smart Images

Figure CN119127200A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of big data technology, and in particular to a code processing method, device, equipment and storage medium. Background Art
[0002] Dynamic bytecode enhancement and runtime type generation technologies are already common technologies in the Java field. These enhancement technologies have greatly expanded the dynamic capabilities of the basic framework at runtime. However, these capabilities also bring many inconveniences to developers' debugging and tracing.
[0003] At present, R&D personnel can use various development tools to debug and track statically deployed Java compilers, but there is currently no solution that can effectively help developers understand the running logic of the enhanced bytecode. The hidden logic and opacity of this code often become a pain point for developers to track and understand the technical process.
[0004] Therefore, how to assist developers to understand the enhanced bytecode accurately and conveniently becomes a technical problem that needs to be solved urgently. Summary of the invention
[0005] The present application provides a code processing method, apparatus, device and storage medium to assist developers in accurately and conveniently understanding enhanced bytecode.
[0006] In a first aspect, the present application provides a code processing method, comprising:
[0007] During the running of the application, according to the pre-configured listening interface implementation class, the context objects of all class instances in the application are obtained;
[0008] According to the context object, bytecode information of a target class is obtained, where the target class is an enhanced dynamically generated class;
[0009] A displayable target file is generated according to the bytecode information of the target class.
[0010] In a possible design, obtaining bytecode information of the target class according to the context object includes:
[0011] According to the original class, a newly added class is determined in the context object, and the newly added class is used as the target class;
[0012] According to the target class, an instance of the detection interface at runtime is obtained to obtain bytecode information of the target class.
[0013] In a possible design, acquiring an instance of the detection interface at runtime according to the target class to obtain bytecode information of the target class includes:
[0014] The instance of the class file converter is executed by using the instance of the detection interface at runtime, and the target class is passed in to trigger a reconversion operation to obtain the bytecode information of the target class.
[0015] In a possible design, before obtaining the context objects of all class instances in the application according to the preconfigured listening interface implementation class, the method further includes:
[0016] Create the monitoring interface implementation class;
[0017] The monitoring interface implementation class is loaded into the configuration file of the application.
[0018] In a possible design, during the running process of the application, according to the pre-configured listening interface implementation class, the context objects of the instances of all classes in the application are obtained, including:
[0019] Use the listening interface implementation class in the configuration file as the interception point;
[0020] During the running process of the application, according to the interception point, the context objects of the instances of all classes in the application are obtained in the method of starting the completion event.
[0021] In a possible design, generating a displayable target file according to the bytecode information of the target class includes:
[0022] Decompiling the bytecode information of the target class to obtain a source code file corresponding to the bytecode information of the target class;
[0023] The target file is generated from the source code file and displayed using a preset display format.
[0024] In a second aspect, the present application provides a code processing device, comprising:
[0025] A first acquisition module is used to acquire context objects of instances of all classes in the application according to a pre-configured listening interface implementation class during the running process of the application;
[0026] A second acquisition module is used to acquire bytecode information of a target class according to the context object, wherein the target class is an enhanced dynamically generated class;
[0027] A generation module is used to generate a displayable target file according to the bytecode information of the target class.
[0028] In a possible design, the second acquisition module is specifically used to:
[0029] According to the original class, a newly added class is determined in the context object, and the newly added class is used as the target class;
[0030] According to the target class, an instance of the detection interface at runtime is obtained to obtain bytecode information of the target class.
[0031] In a possible design, the second acquisition module acquires an instance of the detection interface at runtime according to the target class to obtain bytecode information of the target class, specifically:
[0032] The instance of the class file converter is executed by using the instance of the detection interface at runtime, and the target class is passed in to trigger a reconversion operation to obtain the bytecode information of the target class.
[0033] In a possible design, before obtaining the context objects of instances of all classes in the application according to the preconfigured listening interface implementation class, the first obtaining module is further used to:
[0034] Create the monitoring interface implementation class;
[0035] The monitoring interface implementation class is loaded into the configuration file of the application.
[0036] In a possible design, the first acquisition module, during the running process of the application, acquires the context objects of the instances of all classes in the application according to the pre-configured listening interface implementation class, specifically for:
[0037] Use the listening interface implementation class in the configuration file as the interception point;
[0038] During the running process of the application, according to the interception point, the context objects of the instances of all classes in the application are obtained in the method of starting the completion event.
[0039] In a possible design, the generating module is specifically used for:
[0040] Decompiling the bytecode information of the target class to obtain a source code file corresponding to the bytecode information of the target class;
[0041] The target file is generated from the source code file and displayed using a preset display format.
[0042] In a third aspect, an embodiment of the present application provides an electronic device, including: at least one processor and a memory;
[0043] 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 code processing method described in the first aspect and various possible designs of the first aspect.
[0044] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium;
[0045] The computer-readable storage medium stores computer-executable instructions. When the processor executes the computer-executable instructions, the code processing method described in the first aspect and various possible designs of the first aspect is implemented.
[0046] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the code processing method described in the first aspect and various possible designs of the first aspect.
[0047] The code processing method, device, equipment and storage medium provided by the present application relate to the field of big data technology. In this solution, during the running process of the application, according to the pre-configured listening interface implementation class, the context object of all class instances in the application is obtained; according to the context object, the bytecode information of the target class is obtained, and the target class is an enhanced dynamically generated class; according to the bytecode information of the target class, a displayable target file is generated. In this technical solution, the proxy feature of Java can be used to obtain the bytecode content of the dynamically generated class enhanced during the runtime of the Java application, and save it, and then obtain a displayable Java source code program for developers to read, to assist in understanding the logic and mechanism of runtime enhancement. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0049] Figure 1 The process of the code processing method provided in the embodiment of the present application Figure 1 ;
[0050] Figure 2 The process of the code processing method provided in the embodiment of the present application Figure 2 ;
[0051] Figure 3 The process of the code processing method provided in the embodiment of the present application Figure 3 ;
[0052] Figure 4 The process of the code processing method provided in the embodiment of the present application Figure 4 ;
[0053] Figure 5 An example flowchart of a code processing method provided in an embodiment of the present application;
[0054] Figure 6 A schematic diagram of the structure of a code processing device provided in an embodiment of the present application;
[0055] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0056] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0057] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0058] In the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of information such as financial data or user data involved shall comply with the provisions of relevant laws and regulations and shall not violate public order and good morals.
[0059] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0060] Dynamic bytecode enhancement and runtime type generation technology are already common technologies in the Java field. Bytecode enhancement implementations based on basic components such as Asm (Java bytecode manipulation framework), Java code generation libraries (such as Code Generation Library, Cglib), Javassist (Java bytecode editor), etc. are also widely used in various Java basic frameworks. These enhancement technologies greatly expand the dynamic capabilities of the basic framework at runtime. However, they also bring many inconveniences to developers' debugging and tracing.
[0061] Currently, developers can use various development tools to debug and track statically deployed Java compilers, but there is currently no product that can effectively help developers understand the operating logic of the enhanced bytecode. The hidden logic and opacity of this code often become a pain point for developers to track and understand the technical process.
[0062] That is, the prior art cannot parse the dynamic bytecode of the Java runtime for analysis and understanding by developers.
[0063] In response to the above technical problems, the present application proposes the following technical concept: the characteristics of the Java agent (English: Agent) can be used to extract bytecode enhancement technology to modify, intercept or extract the bytecode content of the runtime class when the application is running. That is, when it is necessary to analyze or obtain the bytecode information of certain classes, a predefined listening interface class can be inserted. After the Java application is started, the context object of all class instances is first obtained, and then the bytecode of the newly added class in the context object can be obtained through the detection interface (English: Instrumentation) interface, including the structure, methods, fields and other information of the class. Once the bytecode of the runtime class is obtained, it can be decompiled into a readable format for further analysis, decompilation or other operations, which solves the technical problems existing in the prior art.
[0064] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0065] Figure 1 The process of the code processing method provided in the embodiment of the present application Figure 1 .like Figure 1 As shown, the code processing method includes:
[0066] It should be understood that for ease of understanding, the embodiment of the present application is illustrated by taking the Java application corresponding to the SpringBoot project as an example. The method involved in the embodiment of the present application can also be applied to any other non-Spring-boot Java application for runtime bytecode collection and analysis.
[0067] Step 11: During the running of the application, the context objects of all class instances in the application are obtained according to the pre-configured listening interface implementation class;
[0068] In this solution, the Spring-boot application is started. The application automatically loads all types according to the project configuration information, and relies on the underlying Cglib technology of Spring to enhance specific SpringBean types. The specific enhancement is to create a runtime inheritance type of the target type, generate runtime bytecode resources and load them into the Java virtual machine.
[0069] After the Spring application context ApplicationContext is loaded, the target runtime type can be generated at a specific stage.
[0070] In this example, you can choose to create a listening interface implementation class SpringApplicationRunListener to obtain the context objects of all class instances in the application, that is, read the context object of springboot.
[0071] Step 12: Obtain the bytecode information of the target class according to the context object;
[0072] Among them, the target class is the enhanced dynamically generated class;
[0073] In this step, after obtaining the context object as described above, it is necessary to obtain the bytecode information of the specific target class to be obtained through the context object.
[0074] That is, the above-mentioned context object records the details, names and original classes of all dynamically generated classes. Based on this, the enhanced dynamically generated class can be determined first, and then based on the enhanced dynamically generated class, the bytecode information corresponding to the enhanced dynamically generated class can be determined, including: class name and class bytecode array.
[0075] Step 13: Generate a displayable target file based on the bytecode information of the target class.
[0076] In this step, after obtaining the bytecode information of the target class, the bytecode information can be converted into a file that is easy for developers to understand and displayed, thereby assisting developers in understanding the logic and mechanism of runtime enhancement.
[0077] Under this implementation, one implementation is to convert the bytecode information of the target class into Java source code, and display it in a preset display form in a graphical interactive interface of the electronic device.
[0078] The code processing method provided in the embodiment of the present application obtains the context object of all class instances in the application according to the pre-configured listening interface implementation class during the running process of the application; obtains the bytecode information of the target class according to the context object, and the target class is the enhanced dynamically generated class; generates a displayable target file according to the bytecode information of the target class. In this technical solution, the proxy feature of Java can be used to obtain the bytecode content of the dynamically generated class enhanced during the runtime of the Java application, and save it, and then obtain a displayable Java source code program for developers to read and assist in understanding the logic and mechanism of runtime enhancement.
[0079] Based on the above embodiments, Figure 2 The process of the code processing method provided in the embodiment of the present application Figure 2 .like Figure 2 As shown, the implementation of the above step 12 may be:
[0080] Step 21: According to the original class, determine the newly added class in the context object, and use the newly added class as the target class;
[0081] In this step, it is pre-recorded that the original class may be UserConfiguration, and its object bean instance is read at this time. In this example, the newly added class can be determined, for example, as:
[0082] UserConfiguration$$EnhancerBySpringCGLIB$$e15389bd.
[0083] Step 22: According to the target class, obtain the instance of the detection interface at runtime and obtain the bytecode information of the target class.
[0084] In this step, the runtime bytecode array form of the target class can be obtained by obtaining the name and type information of the target class, that is, the bytecode information of the target class is obtained.
[0085] Optionally, in Java, the detection interface, ie, the Instrumentation interface, can also be translated as "tool interface" or "instrumentation".
[0086] The Instrumentation interface provides services for bytecode enhancement and instrumentation operations when the Java program is running. Through this interface, bytecode can be added to the method, and data can be obtained and provided to the tool for use. These changes are completely additive and will not change the state and behavior of the application.
[0087] Optionally, the implementation of step 22 may be: executing the class file converter instance using the instance of the detection interface runtime, and passing in the target class to trigger a reconversion operation to obtain the bytecode information of the target class.
[0088] Under this implementation, ByteBuddyAgenth can be used to obtain a runtime instance of the instrumentation type of the detection interface).
[0089] Use the addTransformer of the runtime instance to add the concrete implementation of the aforementioned class file transformer ClassFileTransformer. Here, canRetransform must be set to true.
[0090] Use Instrumentation to execute the retransformation class retransformClasses and pass in the aforementioned target class, namely: UserConfiguration$$EnhancerBySpringCGLIB$$e15389bd.
[0091] The internal implementation of Instrumentation blocks the current thread and triggers the retransformation operation of the target type in another thread, which calls the transform method of the ClassFileTransformer instance.
[0092] It should be understood that the embodiment of the present application only provides one acquisition method, and other methods can also be used to obtain the bytecode information of the target class.
[0093] The code processing method provided in the embodiment of the present application determines the newly added class in the context object according to the original class, and uses the newly added class as the target class; according to the target class, the instance of the detection interface at runtime is obtained to obtain the bytecode information of the target class. In this technical solution, after obtaining the instances of all classes, all classes can be filtered according to the original class to determine the enhanced dynamically generated class, and then the bytecode related to the enhanced dynamically generated class is extracted using the instance of the detection interface at runtime to conveniently obtain the extended bytecode.
[0094] Based on the above embodiments, Figure 3 The process of the code processing method provided in the embodiment of the present application Figure 3 .like Figure 3 As shown, the implementation before the above step 11 can be:
[0095] Step 31, create a monitoring interface implementation class;
[0096] In this step, create a new Java class and implement the listener interface implementation class interface. This interface contains various event callback methods when the application (such as the Java program corresponding to Spring Boot) is running, allowing custom logic to be added at different stages of the application life cycle, that is, to obtain a listener interface implementation class, such as SpringApplicationRunListener.
[0097] Step 32: Load the monitoring interface implementation class into the application's configuration file.
[0098] In this step, the listening interface implementation class is loaded into the configuration file of the application, so that when the application is running, the listening interface implementation class is run based on the configuration file.
[0099] That is, the Spring Boot application will automatically scan and load classes that implement the SpringApplicationRunListener interface when it starts. To ensure that the listener can be loaded and used correctly, you need to specify the fully qualified class name of the listener in the META-INF / spring.factories configuration file.
[0100] After that, you can implement various methods of the SpringApplicationRunListener interface in your custom listener class and add listening business logic as needed. The listener methods will be called at different stages of the application, such as when the application starts, when the environment is ready, when the context is loaded, etc.
[0101] In this implementation, the specific implementation type of the listener interface implementation class SpringApplicationRunListener is selected and loaded in the META-INF / spring.factories configuration file.
[0102] Optionally, based on this, when executing the application, the following implementation (implementation of the above step 11) is:
[0103] The first step is to use the listening interface implementation class in the configuration file as the interception point;
[0104] In this implementation, the configuration definition will prompt Spring-boot to automatically run the listening interface implementation class SpringApplicationRunListener to serve as an interception point and as the runtime bytecode collection entry.
[0105] The second step is to obtain the context objects of all class instances in the application in the method of the startup completion event according to the interception point during the running of the application.
[0106] In this implementation, during the running of the application, the startup completion event started of the listening interface implementation class SpringApplicationRunListener is implemented, and the context object of springboot is read in the event method.
[0107] The code processing method provided in the embodiment of the present application creates a listening interface implementation class and loads the listening interface implementation class into the configuration file of the application. In this technical solution, the listening interface implementation class can be selected and loaded in the configuration file to obtain the context objects of all class instances when the subsequent application is running.
[0108] Based on the above embodiments, Figure 4 The process of the code processing method provided in the embodiment of the present application Figure 4 .like Figure 4 As shown, the implementation of the above step 13 may be:
[0109] Step 41: Decompile the bytecode information of the target class to obtain a source code file corresponding to the bytecode information of the target class;
[0110] In this step, after obtaining the enhanced bytecode information of the dynamically generated class, in order to facilitate the understanding of the developer, the bytecode information can be decompiled into a source code file using a decompilation technology.
[0111] In this implementation, the decompilation technology can be jd-core, etc., which reads the bytecode information of the target class and saves it to the class file on the disk, and generates a decompiled Java file, that is, a source code file corresponding to the bytecode information.
[0112] The bytecode information of the target class includes: class name className, and class bytecode array classfileBuffer.
[0113] Step 42: Generate a target file from the source code file and display it using a preset display format.
[0114] In this step, a target file of the Java file may be generated and displayed using a specific display format.
[0115] The display format may be a markup language (HyperText Markup Language, html) of structured web page content, a desktop table (English: form), or other possible formats.
[0116] The above presentation can simplify the process of developers debugging and understanding runtime code, reducing the difficulty of understanding the technical process.
[0117] The code processing method provided in the embodiment of the present application decompiles the bytecode of the target class to obtain the source code file corresponding to the bytecode information of the target class, and generates and displays the target file from the source code file using a preset display format. The technical solution uses decompilation technology to obtain the Java source code program for developers to read and better assist in understanding the logic and mechanism of runtime enhancement.
[0118] Based on the above embodiments, Figure 5 This is a schematic diagram of an example flow of a code processing method provided in an embodiment of the present application. Figure 5 As shown, the code processing method involved in the embodiment of the present application is described from the aspects of application, bytecode analysis, Java-tool (English: tool) implementation, etc.:
[0119] app:
[0120] Step 1: Start, load, and build the runtime type;
[0121] Step 2: Send a build completion event;
[0122] Bytecode analysis:
[0123] Step 3: Initialize bytecode analysis;
[0124] Java-Tools:
[0125] Step 4: Initialize and return the detection interface instance implementation;
[0126] Bytecode analysis:
[0127] Step 5. Add class file converter interface implementation;
[0128] Java-Tools:
[0129] Step 6. Receive and add the converter;
[0130] Bytecode analysis:
[0131] Step 7: Get the receiving runtime instance according to the target type;
[0132] app:
[0133] Step 8: Read the runtime instance based on the type;
[0134] Bytecode analysis:
[0135] Step 9: Get the runtime specific type based on the runtime instance;
[0136] Step 10: Trigger re-conversion operations;
[0137] Java-Tools:
[0138] Step 11: Receive the request.
[0139] Step 12: Pull data and call back;
[0140] Bytecode analysis:
[0141] Step 13: Receive conversion callback;
[0142] Step 14: Read and save the class name and binary content to a specific target location;
[0143] Step 15: Parse and decompile the target binary file into Java text form;
[0144] Step 16. Display Java text;
[0145] Step 17. End.
[0146] The technical principle and technical effect of the code processing method provided in the embodiment of the present application are similar to those of the above embodiment and will not be repeated here.
[0147] Based on the above method embodiments, the following is an implementation of the device embodiments involved in the embodiments of the present application.
[0148] Figure 6 This is a schematic diagram of the structure of the code processing device provided in the embodiment of the present application. Figure 6 As shown, the code processing device comprises:
[0149] A first acquisition module 61 is used to acquire context objects of instances of all classes in the application according to a pre-configured listening interface implementation class during the running of the application;
[0150] A second acquisition module 62, configured to acquire bytecode information of a target class according to the context object, wherein the target class is an enhanced dynamically generated class;
[0151] The generating module 63 is used to generate a displayable target file according to the bytecode information of the target class.
[0152] In a possible design, the second acquisition module 62 is specifically configured to:
[0153] According to the original class, determining a newly added class in the context object, and using the newly added class as the target class;
[0154] According to the target class, an instance of the detection interface at runtime is obtained to obtain bytecode information of the target class.
[0155] In a possible design, the second acquisition module 62 acquires an instance of the detection interface at runtime according to the target class to obtain bytecode information of the target class, specifically:
[0156] The instance of the class file converter is executed by using the instance of the detection interface at runtime, and the target class is passed in to trigger a reconversion operation to obtain the bytecode information of the target class.
[0157] In a possible design, before obtaining the context objects of the instances of all classes in the application according to the preconfigured listening interface implementation class, the first obtaining module 61 is further used to:
[0158] Create the monitoring interface implementation class;
[0159] The monitoring interface implementation class is loaded into the configuration file of the application.
[0160] In a possible design, the first acquisition module 61, during the running process of the application, acquires the context objects of the instances of all classes in the application according to the pre-configured listening interface implementation class, specifically for:
[0161] Use the listening interface implementation class in the configuration file as the interception point;
[0162] During the running process of the application, according to the interception point, the context objects of the instances of all classes in the application are obtained in the method of starting the completion event.
[0163] In a possible design, the generating module 63 is specifically used for:
[0164] Decompiling the bytecode information of the target class to obtain a source code file corresponding to the bytecode information of the target class;
[0165] The target file is generated from the source code file and displayed using a preset display format.
[0166] The code processing device provided in the embodiment of the present application can be used to execute the technical solution of the code processing method in the above embodiment. Its implementation principle and technical effect are similar and will not be repeated here.
[0167] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software calling through processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software calling through processing elements, and some modules can be implemented in the form of hardware. For example, the first acquisition module 61 can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The function of the first acquisition module 61. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.
[0168] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 As shown, the electronic device may include:
[0169] A processor 71, a memory 72, and computer program instructions stored in the memory 72 and executable on the processor 71. When the processor 71 executes the computer program instructions, the code processing method provided in any of the foregoing embodiments is implemented.
[0170] Optionally, the above-mentioned components of the electronic device may be connected via a system bus.
[0171] The memory 72 may be a separate storage unit or a storage unit integrated in the processor 71. The number of the processor 71 may be one or more.
[0172] It should be understood that the processor 71 can be a central processing unit (CPU), or other general-purpose processors 71, digital signal processors 71 (DSP), application-specific integrated circuits (ASIC), etc. The general-purpose processor 71 can be a microprocessor 71 or the processor 71 can also be any conventional processor 71, etc. The steps of the method disclosed in the present application can be directly embodied as being executed by the hardware processor 71, or can be executed by a combination of hardware and software modules in the processor 71.
[0173] The system bus may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The memory 72 may include a random access memory 72 (RAM), and may also include a non-volatile memory 72 (NVM), such as at least one disk memory 72.
[0174] All or part of the steps of the above-mentioned method embodiments can be completed by hardware related to program instructions. The above-mentioned program can be stored in a readable memory 72. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the above-mentioned memory 72 (storage medium) includes: read-only memory 72 (ROM), RAM, flash memory 72, hard disk, solid state hard disk, magnetic tape, floppy disk, optical disk and any combination thereof.
[0175] An embodiment of the present application also provides a chip for executing instructions, which is used to execute the technical solution of the code processing method in the above embodiment.
[0176] The embodiment of the present application also provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the code processing method of the above embodiment.
[0177] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, the technical solution of the code processing method in the above embodiment can be implemented.
[0178] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0179] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.
[0180] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.
[0181] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.
[0182] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0183] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0184] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0185] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0186] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic control unit or a main control device.
[0187] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0188] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned 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 application.
Claims
1. A code processing method, characterized in that: include: During the running of the application, according to the pre-configured listening interface implementation class, the context objects of all class instances in the application are obtained; According to the context object, bytecode information of a target class is obtained, where the target class is an enhanced dynamically generated class; A displayable target file is generated according to the bytecode information of the target class.
2. The method according to claim 1, characterized in that The step of obtaining bytecode information of a target class according to the context object includes: According to the original class, determining a newly added class in the context object, and using the newly added class as the target class; According to the target class, an instance of the detection interface at runtime is obtained to obtain bytecode information of the target class.
3. The method according to claim 2, characterized in that The step of acquiring an instance of the detection interface at runtime according to the target class to obtain bytecode information of the target class includes: The instance of the class file converter is executed by using the instance of the detection interface at runtime, and the target class is passed in to trigger a reconversion operation to obtain the bytecode information of the target class.
4. The method according to any one of claims 1 to 3, characterized in that: Before obtaining the context objects of all class instances in the application according to the pre-configured listening interface implementation class, the method further includes: Create the monitoring interface implementation class; The monitoring interface implementation class is loaded into the configuration file of the application.
5. The method according to claim 4, characterized in that During the running process of the application, according to the pre-configured listening interface implementation class, the context objects of the instances of all classes in the application are obtained, including: Use the listening interface implementation class in the configuration file as the interception point; During the running process of the application, according to the interception point, the context objects of the instances of all classes in the application are obtained in the method of starting the completion event.
6. The method according to any one of claims 1 to 3, characterized in that: The step of generating a displayable target file according to the bytecode information of the target class includes: Decompiling the bytecode information of the target class to obtain a source code file corresponding to the bytecode information of the target class; The target file is generated from the source code file and displayed using a preset display format.
7. A code processing device, characterized in that: include: A first acquisition module is used to acquire context objects of instances of all classes in the application according to a pre-configured listening interface implementation class during the running process of the application; A second acquisition module is used to acquire bytecode information of a target class according to the context object, wherein the target class is an enhanced dynamically generated class; A generation module is used to generate a displayable target file according to the bytecode information of the target class.
8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.
