Bytecode modification method, device, computer equipment and storage medium
Through the bytecode modification method, based on the candidate business logic set and the bytecode to be modified, the bytecode of the initial business logic class is dynamically replaced, which solves the problems of high invasiveness and low efficiency in traditional technology, and realizes efficient and flexible bytecode modification.
Patent Information
- Application Number
- CN202111591489.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-23
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2041-12-23
AI Technical Summary
In traditional technology, R&D personnel need to modify service codes through hard-coded or static section dimensions, resulting in high invasiveness, low efficiency and high risk, and the need for dynamic sections cannot be achieved.
Provide a bytecode modification method, by obtaining the candidate business logic class set and loading the bytecode to be modified, the target business needs are determined based on the dimension of the initial business needs, and the instantiation modification function replaces the bytecode of the initial business logic class with the bytecode of the target business logic class.
It realizes multi-dimensional modification at the business logic bytecode level, without a fixed entry point, reduces code intrusion and dependence, improves efficiency and flexibility, and simplifies maintenance.
Smart Images

Figure CN114416530B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of program modification, and in particular to a bytecode modification method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] In traditional technologies, developers have to modify the service code every time to meet the needs of testers and operation and maintenance personnel, and they basically use hard-coded or static aspect dimensions. Static aspect technology solutions have great limitations, because Spring AOP can only implement aspect functions by hard-coding entry points and logic through code, and the code is very invasive. Because Java code must be compiled into bytecode before it can run in the JVM, Spring AOP cannot change the relevant logic after compilation and cannot meet the needs of dynamic aspects. Such solutions have a great impact on the efficiency of R&D, testing, and operation and maintenance, and each modification to the service code means an increase in risk. Summary of the invention
[0003] Based on this, it is necessary to provide a bytecode modification method, apparatus, computer device, computer-readable storage medium and computer program product that can perform multi-dimensional modification in response to the above technical problems.
[0004] In a first aspect, the present application provides a bytecode modification method, the method comprising:
[0005] Acquire a candidate business logic class set, the candidate business logic class set comprising a modification function and at least one candidate business logic class, the candidate business logic class corresponding to a candidate business requirement;
[0006] Loading the bytecode to be modified, wherein the bytecode to be modified includes an initial business logic class, wherein the initial business logic class corresponds to an initial business requirement, and a dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified;
[0007] Determine a target business requirement in the candidate business requirements based on the dimensions in the initial business requirements, and determine a target business logic class in the candidate business logic class set based on the target business requirement;
[0008] The modification function is instantiated, and based on the instantiated modification function, the bytecode to be modified including the initial business logic class is replaced with the bytecode including the target business logic class.
[0009] In one embodiment, the modification function includes a path determination class and an attribute modification class of a business logic class, and obtaining a candidate business logic class set includes:
[0010] According to business requirements, generating the candidate business logic class based on the attribute modification class, the candidate business logic class including one or more of the attributes, functions and bytecode files for replacement;
[0011] The method further comprises:
[0012] Determine the path information of the initial business logic class based on the path determination class, and determine the data to be modified in the initial business logic class based on the path information, wherein the data to be modified includes one or more of the attributes, functions and bytecode files to be modified;
[0013] The candidate business logic class is used to replace the data to be modified in the initial business logic class.
[0014] In one embodiment, the candidate business logic class set includes a preset business logic class set, and obtaining the candidate business logic class set includes:
[0015] Before loading the bytecode to be modified, obtaining a preset business logic data packet;
[0016] Loading the preset business logic class set from the preset business logic data packet, the preset business logic class set including a preset business method class corresponding to a preset business method class bytecode;
[0017] The instantiation-based modification function replaces the to-be-modified bytecode including the initial business logic class with the bytecode including the target business logic class, including:
[0018] The instantiated modification function replaces the to-be-modified bytecode including the initial business logic class with the bytecode including the target business logic class.
[0019] In one embodiment, the generation of the preset service logic data packet includes:
[0020] Determine a proxy class file, wherein the proxy class file is used to modify the initial business logic class;
[0021] Acquire a virtual interface for testing, and generate a virtual interface class file based on the virtual interface;
[0022] The proxy class file and the virtual interface class file are combined, and the combined files are compiled to obtain the preset business logic data packet.
[0023] In one embodiment, the generation of the proxy class file includes:
[0024] Determine a list file of the proxy class file, wherein the list file is used to define the modification authority of the proxy class file;
[0025] Determine a modification class of a proxy class file, wherein the modification class includes a modification function of the proxy class file; wherein the instantiated modification function is used to replace the initial business logic class bytecode with the target business logic class bytecode;
[0026] The manifest file and the modified class are combined to generate the proxy class file.
[0027] In one embodiment, the method further comprises:
[0028] If the dimension of the initial business requirement is log missing, then adding the log in the proxy class program to the bytecode to be modified;
[0029] If the dimension of the initial business requirement is program testing, the virtual interface in the application proxy program is used to replace the third-party address in the program to be tested, and the program to be tested with the replaced interface is used as the bytecode to be modified.
[0030] In one embodiment, the dimension of the initial business requirement also includes a dimension of data to be modified, and the dimension of data to be modified includes metadata to be modified and a data type of the metadata to be modified. The method further includes:
[0031] Before loading the bytecode to be modified, obtaining the data dimension to be modified corresponding to the bytecode to be modified;
[0032] The determining, based on the initial business requirement, a target business requirement among the candidate business requirements includes:
[0033] Under the dimension of the data to be modified, the target business requirement is determined based on the initial business requirement, and the target business requirement includes a modification requirement of the metadata to be modified and / or a modification requirement of the data type.
[0034] In a second aspect, the present application also provides a bytecode modification device. The device comprises:
[0035] A candidate business logic acquisition module, used to acquire a candidate business logic class set, wherein the candidate business logic class set includes a modification function and at least one candidate business logic class, and the candidate business logic class corresponds to a candidate business requirement;
[0036] A bytecode to be modified loading module, used to load the bytecode to be modified, wherein the bytecode to be modified includes an initial business logic class, the initial business logic class corresponds to an initial business requirement, and the dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified;
[0037] A business requirement determination module, configured to determine a target business requirement among the candidate business requirements based on at least one dimension of the initial business requirement, and determine a target business logic class among the candidate business logic class set based on the target business requirement;
[0038] The bytecode modification module is used to instantiate the modification function and replace the bytecode to be modified including the initial business logic class with the bytecode including the target business logic class based on the instantiated modification function.
[0039] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0040] Acquire a candidate business logic class set, the candidate business logic class set comprising a modification function and at least one candidate business logic class, the candidate business logic class corresponding to a candidate business requirement;
[0041] Loading the bytecode to be modified, wherein the bytecode to be modified includes an initial business logic class, wherein the initial business logic class corresponds to an initial business requirement, and a dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified;
[0042] Determine a target business requirement in the candidate business requirements based on the dimensions in the initial business requirements, and determine a target business logic class in the candidate business logic class set based on the target business requirement;
[0043] The modification function is instantiated, and based on the instantiated modification function, the bytecode to be modified including the initial business logic class is replaced with the bytecode including the target business logic class.
[0044] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0045] Acquire a candidate business logic class set, the candidate business logic class set comprising a modification function and at least one candidate business logic class, the candidate business logic class corresponding to a candidate business requirement;
[0046] Loading the bytecode to be modified, wherein the bytecode to be modified includes an initial business logic class, wherein the initial business logic class corresponds to an initial business requirement, and a dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified;
[0047] Determine a target business requirement in the candidate business requirements based on the dimensions in the initial business requirements, and determine a target business logic class in the candidate business logic class set based on the target business requirement;
[0048] The modification function is instantiated, and based on the instantiated modification function, the bytecode to be modified including the initial business logic class is replaced with the bytecode including the target business logic class.
[0049] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0050] Acquire a candidate business logic class set, the candidate business logic class set comprising a modification function and at least one candidate business logic class, the candidate business logic class corresponding to a candidate business requirement;
[0051] Loading the bytecode to be modified, wherein the bytecode to be modified includes an initial business logic class, wherein the initial business logic class corresponds to an initial business requirement, and a dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified;
[0052] Determine a target business requirement in the candidate business requirements based on the dimensions in the initial business requirements, and determine a target business logic class in the candidate business logic class set based on the target business requirement;
[0053] The modification function is instantiated, and based on the instantiated modification function, the bytecode to be modified including the initial business logic class is replaced with the bytecode including the target business logic class.
[0054] The above-mentioned bytecode modification method, apparatus, computer equipment, storage medium and computer program product provide a new modification direction through a set of candidate business logic classes. The bytecode to be modified can be modified at the special level of the business logic class bytecode, without using a fixed entry point to modify the bytecode, so that the bytecode can be oriented to various programs, reducing the possibility of code intrusion; and the target business demand is selected based on the initial business demand dimension corresponding to the bytecode to be modified. This process provides a guarantee for the reuse of candidate business logic classes, allowing the program to respond to various scenarios more flexibly; in addition, based on the instantiated modification function, the initial business logic class bytecode is replaced with the target business logic class bytecode, so that the related logic of the modification dimension is decoupled from the service logic, reducing the dependency, not prone to problems, and more convenient maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1An application environment diagram of a bytecode modification method in an embodiment;
[0056] Figure 2 A schematic diagram of a flow chart of a bytecode modification method in one embodiment;
[0057] Figure 3 A schematic diagram of a process of replacing bytecodes in one embodiment;
[0058] Figure 4 A schematic diagram of a process of replacing bytecodes in one embodiment;
[0059] Figure 5 A schematic diagram of a process for obtaining a preset service logic data packet in one embodiment;
[0060] Figure 6 A schematic diagram of a process for generating a proxy class file in an embodiment;
[0061] Figure 7 A schematic diagram of a process flow of metadata dimensions of initial business requirements in one embodiment;
[0062] Figure 8 is a schematic diagram of a comparison process in different dimensions in one embodiment;
[0063] Fig. 9 A schematic diagram of a flow chart of generating an agent class program in one embodiment;
[0064] Fig.10 A schematic diagram of a replacement process in an embodiment;
[0065] Fig.11 A schematic diagram of a modified process in an embodiment;
[0066] Fig.12 A schematic diagram of the overall flow of a bytecode modification method in an embodiment;
[0067] Fig.13 A schematic diagram of a modification interface corresponding to metadata in an embodiment;
[0068] Fig.14 is a structural block diagram of a bytecode modification device in an embodiment;
[0069] Fig.15 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0070] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. In the following description, the meaning of "A and / or B" is "at least one of A and B".
[0071] The bytecode modification method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented with an independent server or a server cluster consisting of multiple servers. The solution provided in the embodiment of the present application can be implemented by the terminal 102; it can also be implemented by the terminal 102 and the server 104 in collaboration. For example, the terminal 102 can provide certain information to the server 104 so that the server 104 can perform related calculation processes. After the server 104 calculates, it will feed back the calculation results to the terminal 102, and then the terminal 102 will replace the bytecode file; for example, using a distributed algorithm, the terminal 102 and the server 104 are both used as nodes in the distributed algorithm, and resources are mutually assisted through multiple nodes to achieve the corresponding effect.
[0072] In one embodiment, Figure 2 As shown, a bytecode modification method is provided, which is applied to Figure 1 Taking the server 104 in the example as an example, the following steps are included:
[0073] Step 202: Obtain a candidate business logic class set, where the candidate business logic class set includes a modification function and at least one candidate business logic class, and the candidate business logic class corresponds to a candidate business requirement.
[0074] A modification function can be a function used to modify the business logic in some programs, or it can be other data structures or algorithms that have the function of modifying business logic. For the modification function itself, it can be a general business logic, and in special cases, the modification function will be used as a candidate business logic class. For example, if the bytecode to be modified is a set of encapsulated business logic classes, when another set of business logic classes is used to modify the bytecode to be modified, the candidate business logic class may include one or more modification functions.
[0075] A candidate business logic class is a business logic class used to modify the bytecode to be modified. A candidate business logic class is a special data type, which includes attributes and business logic functions for replacement, and the business logic function can be a related function for operating data or a related function for transmitting messages. After a candidate business logic class is instantiated, multiple data objects can be generated, each of which has the attributes and related functions of the candidate business logic class, and each data object can further add personalized data to achieve different functions. Among them, the difference between the candidate business logic class and the instantiated candidate business logic class is that the candidate business logic class is a data type, not data that can be stored in memory, while the instantiated candidate business logic class is data that can be stored in memory, not a data type; the difference between the candidate business logic class and the instantiated candidate business logic class is that the candidate business logic class can also be used as a base class to add some personalized related functions to generate a corresponding derived class, and then generate one or more data objects based on the derived class. Correspondingly, the data object generated based on the derived class includes both the attributes and functions of the base class and the personalized related functions in the derived class.
[0076] Step 204, load the bytecode to be modified, the bytecode to be modified includes an initial business logic class, the initial business logic class corresponds to an initial business requirement, and the dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified.
[0077] The bytecode to be modified can be a functional file for implementing a certain function or a file with missing logs. If the bytecode to be modified is a functional file, the initial business logic class is required to implement the relevant functions of the file, and the initial business logic class corresponds to at least one initial business requirement. The first dimension of the initial business requirement is the detection or modification of data and data types, and the second dimension of the initial business requirement is the repair requirement for missing logs and / or the testing requirement for the bytecode to be modified. The first dimension is combined with the second dimension to form the real dimension of the initial business requirement, and the bytecode file can be repaired and modified dynamically.
[0078] Correspondingly, if the bytecode to be modified is a file with missing logs, some functions of the file may not be implemented through the initial business logic class, and the initial business logic class corresponds to at least one initial business requirement. The first dimension of the initial business requirement is the modification of data and data types, and the second dimension of the initial business requirement is the need to repair missing logs. After the first dimension is combined with the second dimension, the bytecode file can be repaired dynamically. It can be understood that the bytecode to be modified after the log is repaired can also be used as the bytecode to be modified for testing; based on the same principle, the bytecode to be modified after the test can also be the bytecode to be modified for missing logs.
[0079] By loading the bytecode to be modified, the main program corresponding to the bytecode to be modified can be determined, and the binary or hexadecimal data corresponding to the business logic class of the main program can be read into the memory. These data are placed in the function area when the program is running, and then a class object of the bytecode to be modified is created in the memory to subpackage the data structure of the class in the function area, thereby obtaining the initial business logic class.
[0080] Step 206 , based on the dimensions in the initial business requirements, determine the target business requirements in the candidate business requirements, and based on the target business requirements, determine the target business logic class in the candidate business logic class set.
[0081] The dimensions of the initial business requirements include the repair requirement dimension of missing logs, the test requirement dimension of the bytecode to be modified, and the requirement dimension of combining repair and testing. The requirement dimension of combining repair and testing also includes at least two dimensions, namely, the requirement dimension of log repair first and the requirement dimension of program testing first.
[0082] There may be certain similarities between the dimensions to which the candidate business requirements and the initial business requirements belong. Both can be divided into a first dimension and a second dimension. The first dimension is used to determine the dimension of the specific data or specific data type to be modified, while the second dimension is used to determine whether the bytecode to be modified requires log repair or testing. There may also be certain differences between the dimensions to which the candidate business requirements and the initial business requirements belong. Most candidate business requirements only focus on one of the repair requirement dimension or the test requirement dimension. Therefore, according to the dimensions of the initial business requirements, multiple sub-requirements of the initial business requirements can be divided, and each sub-requirement can correspond to a candidate business requirement in the candidate business requirement set, and the multiple candidate business requirements corresponding to this dimension are the target business requirements corresponding to the initial business requirements, that is, any dimension of the initial business requirements can correspond to multiple target business requirements. It can be understood that if the dimension of the initial business requirement corresponds to multiple target business requirements, then each target business requirement can correspond to different functional requirements respectively. These functional requirements are used to realize the repair and replacement of data or data types within the dimension. Therefore, the target business requirement can have requirement identifiers corresponding to modification requirements such as "modification requirements for outpatient patient data", "modification requirements for outpatient patient data types", and "modification requirements for outpatient patient data and data types". The requirement identifier can be any data type such as string, integer, long integer, floating point, class, etc.
[0083] After obtaining the target business requirements, the target business logic class is determined based on the target business requirements, that is, the candidate business logic class corresponding to the target business requirements is used as the target business logic class, and the target business requirements and the target business logic class are in a one-to-one mapping relationship. Through this mapping relationship, the target business logic class can be accurately obtained. As a result, the matching process between requirements is refined, the possibility of matching errors is reduced, and it is easier to obtain the target business requirements.
[0084] Step 208: instantiate the modification function, and replace the bytecode to be modified including the initial business logic class with the bytecode including the target business logic class based on the instantiated modification function.
[0085] The process of modifying the function instantiation can be implemented based on the proxy class bytecode, or by reacting to certain events. For example, the proxy class program can be loaded first to instantiate the modification function, and then the bytecode to be modified can be loaded. Finally, the initial business logic class bytecode can be replaced with the target business logic class bytecode by instantiating the modification function. Another example is that when loading the bytecode to be modified, the corresponding modification function can be obtained synchronously, and after the virtual machine executes the bytecode to be modified, the modification function can be instantiated to obtain the modification function object, and the initial business logic class bytecode can be converted into the target business logic class bytecode using the modification function object.
[0086] In the above bytecode modification method, a set of candidate business logic classes is obtained, the set of candidate business logic classes includes a modification function and at least one candidate business logic class, and the candidate business logic class corresponds to a candidate business requirement; the bytecode to be modified is loaded, the bytecode to be modified includes an initial business logic class, the initial business logic class corresponds to an initial business requirement, and the dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified; based on the dimension in the initial business requirement, a target business requirement in the candidate business requirement is determined, and based on the target business requirement, a target business logic class in the set of candidate business logic classes is determined; the modification function is instantiated, and based on the instantiated modification function, the bytecode to be modified including the initial business logic class is replaced with the bytecode including the target business logic class. Therefore, the candidate business logic class set provides a new modification direction. The bytecode to be modified can be modified at the special level of the business logic class bytecode. There is no need to use a fixed entry point to modify the bytecode, so that the bytecode can be oriented to various programs, reducing the code intrusiveness; and the target business demand is selected based on the initial business demand dimension corresponding to the bytecode to be modified. This process provides a guarantee for the reuse of candidate business logic classes, allowing the program to respond to various scenarios more flexibly; in addition, based on the instantiated modification function, the bytecode to be modified including the initial business logic class is replaced with the bytecode including the target business logic class, so that the related logic of the modification dimension is decoupled from the service logic, reducing the dependency, not prone to problems, and more convenient maintenance.
[0087] In one embodiment, Figure 3 As shown, the modification function includes a path determination class and an attribute modification class of the business logic class, wherein the path determination class can be a specific class in the class library, or a class generated by the attribute modification class, or a class pool, which is used to determine the location of the target business logic class and / or the location of the initial business logic class; the path determination class can determine the specific location of various classes, and then directly create or modify the corresponding class to track and control the operated class. The attribute modification class can be a specific class in the library class, or a class obtained by the path determination class, which can be a class for loading, and can use any bytecode in the target business logic class to modify any bytecode in the initial business logic class. After loading the bytecode to be modified, the path determination class and the attribute modification class are obtained because the path determination class and the attribute modification class need to be based on the loaded bytecode to be modified in order to work.
[0088] The candidate business logic class collection includes:
[0089] Step 302: Generate candidate business logic classes based on the attribute modification class according to business requirements. The candidate business logic classes include one or more of the attributes, functions, and bytecode files to be replaced.
[0090] Correspondingly, the method further includes:
[0091] Step 304, determine the class based on the path, determine the path information of the initial business logic class, determine the data to be modified in the initial business logic class based on the path information, the data to be modified includes one or more of the properties, functions and bytecode files to be modified, wherein the candidate business logic class is used to replace the data to be modified in the initial business logic class.
[0092] In this embodiment, the candidate business logic class is generated by the attribute modification class. Therefore, the target business logic class selected based on the candidate business logic is loaded and run in the virtual machine as the program to be modified. The path determination class searches for the location of the data to be modified, thereby refining the granularity of the data to be modified, and the attributes, functions or the entire bytecode file in the specific bytecode file can be replaced.
[0093] In one embodiment, Figure 4 As shown, the candidate business logic class set includes a preset business logic class set, and obtaining the candidate business logic class set includes:
[0094] Step 402: before loading the bytecode to be modified, obtain a preset business logic data package.
[0095] The process of obtaining the preset business logic data package must precede the loading of the bytecode to be modified, because the preset business logic data package is equivalent to a custom interceptor, which replaces the bytecode to be modified that has not yet been loaded. Therefore, on the one hand, the stability of the execution of this method can be increased to avoid problems in the bytecode modification process. On the other hand, the preset business logic data package provides a guarantee for the reuse of candidate business logic classes, allowing the program to respond to various scenarios more flexibly.
[0096] Step 404: Load a preset business logic class set from the preset business logic data packet, wherein the preset business logic class set includes a preset business method class corresponding to a preset business method class bytecode.
[0097] The business method class is a class defined for a special function called a method. There is a correspondence between classes in the business method class. After the business method class is instantiated, the classes in the business method class generate data objects with dependencies according to the correspondence between classes. The data objects and the instantiated business method class are used to implement a specific application function. The preset business method class is a data type used to operate the business logic replacement process. After the preset business method class is instantiated, the corresponding business logic object can be obtained. The business logic object corresponds to the preset business method class bytecode.
[0098] Correspondingly, the initial business logic class bytecode is replaced with the target business logic class bytecode based on the instantiation modification function, including:
[0099] Step 406: Replace the bytecode to be modified including the initial business logic class with the bytecode including the target business logic class based on the instantiated modification function.
[0100] After the initial business logic bytecode is replaced, the bytecode to be modified is still in the loading state, and the overall loading can be completed by a single task execution subject, which can ensure the stability and reliability of the overall loading. In turn, the stability of execution is guaranteed. Before and after the bytecode to be modified is replaced, the same process or thread can be used for loading.
[0101] In this embodiment, through the pre-loaded preset business logic data package, the corresponding business logic class set can be called more conveniently, and the preset business method class can be directly applied to replace the business logic class, thereby realizing the overall replacement of the preset business method class bytecode, thereby increasing the stability of execution and the possibility of modifying the bytecode. At the same time, it provides a guarantee for the reuse of candidate business logic classes, allowing the program to respond to various scenarios more flexibly.
[0102] In one embodiment, Figure 5 As shown, the generation of the preset business logic data package includes:
[0103] Step 502, determining a proxy class file, where the proxy class file is used to modify the initial business logic class.
[0104] Proxy files, also called proxy functions, proxy programs or agent programs, are generally written by users through a virtual machine used to generate proxy files, and are used to implement file replacement functions. Proxy files and the bytecode to be modified belong to two different tasks and can be loaded separately through two processes.
[0105] Step 504: Acquire a virtual interface for testing, and generate a virtual interface class file based on the virtual interface.
[0106] The virtual interface class file is mainly a file that can be configured at will, and can also be considered as a class, which is used to define the relevant interfaces for virtual testing. The virtual interface class file can make the test process compatible with various application environments.
[0107] Step 506, combining the proxy class file and the virtual interface class file, and compiling the combined files to obtain a preset business logic data package.
[0108] In this embodiment, through the proxy class file, the programs corresponding to the preset business logic data package and the bytecode to be modified are loaded separately, the problems caused by loading the bytecode to be modified are avoided, the overall replacement of the preset business method class bytecode is realized, the execution stability is increased, the possibility of the bytecode to be modified is further reduced, and the possibility of code intrusion is further reduced, so that the bytecode can be better oriented to various programs; and the virtual interface class file is generated based on the virtual interface, so that the preset business logic data package will not cause problems in other files due to test problems, thereby ensuring the system stability during the bytecode modification process.
[0109] In one embodiment, Figure 6 As shown, the generation of the proxy class file includes:
[0110] Step 602, determining a list file of the proxy class file, where the list file is used to define the modification authority of the proxy class file.
[0111] The modification permissions of the proxy class files can facilitate the overall scheduling of multiple functions, realize the overall replacement of the preset business method class bytecode, increase the stability of execution, and reduce the possibility of problems when modifying the bytecode to be modified. As a result, the bytecode can be further oriented to various programs and the possibility of code intrusion can be reduced.
[0112] Step 604, determining a modification class of the proxy class file, the modification class including a modification function of the proxy class file, wherein the instantiated modification function is used to replace the initial business logic class bytecode with the target business logic class bytecode.
[0113] Step 606, combine the manifest file and the modified class to generate a proxy class file.
[0114] In this embodiment, the modification degree of the proxy class file is determined by the manifest file, and the modification functions are combined through the modification class, thereby decoupling the modification class and the manifest file. The execution permissions of the modification functions in the modification class are defined through the manifest file, further improving the reuse efficiency of the modification functions, reducing dependencies, being less likely to cause problems, and being easier to maintain.
[0115] In one embodiment, the method further comprises:
[0116] If the dimension of the initial business requirement is log missing, the log in the proxy class program is added to the bytecode to be modified.
[0117] If the dimension of the initial business requirement is program testing, the virtual interface in the application proxy program is used to replace the third-party address in the program to be tested, and the program to be tested with the replaced interface is used as the bytecode to be modified.
[0118] In this embodiment, based on the dimension of initial business needs, execution programs under two dimensions are defined, and logs are added to corresponding positions through the log missing dimension. Based on the program test dimension, the program to be tested with a replacement interface is more convenient for free scheduling. Therefore, there is no need to use a fixed entry point to modify the bytecode, so that the bytecode can be oriented to various programs, reducing the possibility of code intrusion.
[0119] In one embodiment, Figure 7 As shown, the dimension of the initial business demand also includes the dimension of the data to be modified, and the dimension of the data to be modified includes the metadata to be modified and the data type of the metadata to be modified. Metadata is a kind of data used to construct specific business data, business logic, data structure and other arbitrary data or data types, which is equivalent to a data template. One metadata often corresponds to multiple business data classes, business data entities or static data, and business data classes and business data entities can be modified in batches by modifying the metadata. Based on this, the method also includes:
[0120] Step 702: before loading the bytecode to be modified, obtain the data dimension to be modified corresponding to the bytecode to be modified.
[0121] The data dimension to be modified may have a certain correlation with the dimension of the initial business requirement, which is mainly the modification of factors such as data or data type. These data have their corresponding bytecode files. It is the modification dimension in the traditional sense, mainly referring to the specific modified data.
[0122] Based on the initial business requirements, determine the target business requirements among the candidate business requirements, including:
[0123] Step 704 , under the dimension of the data to be modified, determine the target business requirement based on the initial business requirement, where the target business requirement includes the modification requirement of the metadata to be modified and / or the modification requirement of the data type.
[0124] In this embodiment, the data dimensions to be modified that can be dynamically adjusted are determined based on the data dimensions to be modified, and under the data dimensions to be modified, metadata or the data type of metadata is selected for modification. In this way, various files generated by the metadata can be modified synchronously, with high modification efficiency, which provides a guarantee for the reuse of candidate business logic classes and enables the program to respond to various scenarios more flexibly.
[0125] Each of the above embodiments has its own focus. In order to better describe the overall technical solution, a relatively complete embodiment will be used to discuss the overall business process.
[0126] like Figure 8 As shown, it shows the environment for testing and the environment for log repair;
[0127] Among them, when in a test environment, it includes the following usage steps:
[0128] 1. Determine the functions of third-party programs for easy calling;
[0129] 2. Replace the address of the third-party program with the address of the virtual interface mock. The address of the virtual interface mock corresponds to the interface to be tested. The interface to be tested can be a new interface.
[0130] 3. Configure the initial business requirements, the dimensions of the initial business requirements, and the dimensions of the data to be repaired from the front-end interface, obtain the interface script of the virtual interface mock under this dimension, and finally execute the proxy program to implement test-related functions.
[0131] Therefore, in the test environment, if a third-party mock scenario is required, you only need to configure the cut-off point on the management platform, write the mock script, and restart the service. There is no need to communicate and rely on R&D personnel, and testers can realize the test requirements by themselves.
[0132] Among them, when in the environment of log repair, it includes the following steps:
[0133] The operation and maintenance personnel detect the problem of the bytecode to be modified through the operation and maintenance program. When handling the problem, they check the log. If the log is missing, they issue instructions to the corresponding program of the R&D personnel to generate the initial business requirements;
[0134] In this dimension, the R&D personnel configure the initial business requirements from the front-end interface, select the dimensions of the initial business requirements and the dimensions of the data to be modified through the proxy program, perform log repair through the proxy program, and return the process node to the operation and maintenance personnel after restarting the proxy program;
[0135] The operation and maintenance personnel continue to troubleshoot the problem until the troubleshooting is completed. Among them, the operation and maintenance personnel can add log scenarios. After receiving the requirements, the R&D personnel do not need to modify the code of the main service. They only need to write the code in the Agent and restart the service to realize the demand for dynamic addition of logs, which reduces the coupling of the code and the risk of service modification.
[0136] In an optional embodiment, if Fig. 9 As shown in the figure, the writing process of the proxy program is described, which includes the following steps:
[0137] 1. In the Agent project code, define a MANIFEST.MF manifest file, which must include the Premain-Class option; for example:
[0138] Manifest-Version:1.0
[0139] Can-Redefine-Classes:true
[0140] Can-Retransform-Classes:true
[0141] Premain-Class:com.kingdeehit.PreMainAgent
[0142] Among them, "Manifest-Version:1.0" indicates the code version corresponding to the program, which is used for legality verification; "Can-Redefine-Classes:true" means that the Java program code can be modified, and the class can be redefined; and "Can-Retransform-Classes:true" means that the Java program code can be modified, and the plug-in class can be defined; "Premain-Class" means the pre-loaded class.
[0143] 2. Create a class specified by Premain-Class, which contains a premain method and adds logging logic. The "premain method" indicates preloading.
[0144] 3. Package the premain class and the manifest file MANIFEST.MF into a jar package;
[0145] 4. Start the main service using the parameter -javaagent:jar package path;
[0146] 5. The JAVA virtual machine (JVM) loads the agent class program Agent code and executes the modified bytecode logic in the Agent;
[0147] In an optional embodiment, if Fig.10 As shown in the figure, taking the outpatient service as an example, when the R&D personnel finish writing the Agent code and start the program, they first use the Agent startup parameter java-javaagent:agent.jar to explain the Agent code execution of the agent class program, which includes:
[0148] 1. Before the main method main corresponding to the bytecode to be modified is executed, the premain method in the agent is executed;
[0149] 2. In the premain method, use the addTransformer function of the Instrumentation object instance to add the log of the "method in outpatient business" added in the agent to the JVM;
[0150] 3. The systemClassLoader of the JAVA virtual machine (JVM) obtains the bytecode "outpatient service class file" to be modified;
[0151] 4. Before loading the "outpatient service class file", the JAVA virtual machine (JVM) calls the transform method of the transformation function ClassFileTransformer to add the log of the outpatient service class interface;
[0152] 5. The modified outpatient service bytecode file is returned to the virtual machine (JVM) to dynamically add logs.
[0153] In an optional embodiment, if Fig.11 As shown, the specific steps of modifying through the path determination class and the attribute modification class are discussed. The attribute modification class is the class pool ClassPool, and the attribute modification class is the CtClass class used to determine the attribute, which includes:
[0154] 1. Construct the ClassPool class, which is the class pool of javassist. The ClassPool class can be used to track and control the classes being operated;
[0155] 2. Generate a class file from the script written by the management platform, copy it to the specified path, and insert it into the bytecode related to the initialization of ClassPool;
[0156] 3. Get the outpatient business class through CtClass, and replace the initial business logic class with the calling address of the third-party service through class methods such as cClass.getDeclaredMethod for deleting the business logic class and cMethod.insertAt for inserting the business logic class. Finally, compile and convert it into a Class bytecode object through the toClass method or directly write it into a class file.
[0157] In an alternative embodiment, Fig.12 As shown, the collaborative work of the above two implementation methods is described at the same time, which includes agent class program coding, data obtained through the management platform, loading data packets based on path information, starting the JAVA virtual machine, and the virtual machine running, to realize the five modules of dynamic debugging dimension.
[0158] 1. In the coding module, first write the agent program, then define the corresponding manifest file, and finally compile it into the modification bytecode file of the agent class. The modification bytecode file is part of the preset business logic data package; among them, the modification bytecode file is used to modify the data;
[0159] 2. The module that obtains data on the management platform needs to write a virtual interface script. The virtual interface script is a script that uses a virtual interface to replace a third-party address. A virtual interface class file is generated based on the virtual interface script, and the virtual interface script is combined with the modified class bytecode file to obtain a preset business logic data packet.
[0160] 3. Start the agent class program and the main program corresponding to the bytecode to be modified, wherein the path information for obtaining the preset business logic data packet of the agent class program is: java-javaagent:outpatient serviceAgent.jar-jaroutpatient service.jar.
[0161] 4. During the startup phase of the Java virtual machine JVM, the required dimension of adding logs can be implemented first. The legitimacy of the class file can be verified first, including information such as whether the JAVA version is compatible. After the legitimacy verification, the agent class program Agent is statically loaded based on the parent delegation mechanism. After loading the agent class program, the initial business logic class "outpatient business class" of the bytecode to be modified is obtained, and then based on the modification function in the agent class program Agent, the method class is modified to implement log addition.
[0162] 5. During the startup phase of the Java virtual machine JVM, you can also execute the test requirement dimension first. You can select the path determination class and attribute modification class in the Javassist class library for modification, and replace the third-party address URL with the interface address of the virtual script for testing, and then obtain the bytecode file with the target business logic class. The requirement dimension of adding logs that can be executed first belongs to the "outpatient business class".
[0163] 6. Finally, load the bytecode file with the target business logic class to implement dynamic sectioning, and adjust the modification dimension at will to modify the data to be modified. The data to be modified can be metadata or metadata type or specific data, and the interface for adjusting the modification dimension at will is as follows Fig.13 shown.
[0164] Comparing this specific solution with the original process of SpringAOP, it can be seen that this solution can implement AOP at the virtual machine level, and there is no need to hardcode all aspects in the code. This embodiment can provide two ways of dynamic aspects. One is to modify the compiled class bytecode file through the JavaAgent method and the instrumentation premain method when the JVM is statically loaded, so as to achieve the purpose of dynamic modification; this method can only modify the method body defined by the class, and cannot modify the method name and add new methods or attributes. This method can meet the needs of adding log logic to the outpatient business class. In addition, while starting the Agent, Javassist can also be used to read the outpatient business class, and dynamically modify the code that calls the third-party service, and change the URL address to the company's mock service address. Through this process, the tester's need to implement mock through configuration writing is realized. The effects of this embodiment are: first, it reduces the coupling of hard-coded program codes and the intrusiveness of codes, and can dynamically add aspects according to actual needs to cope with more complex actual scenarios; second, it reduces the dependency and communication costs in the research and development process and improves the efficiency of testing, operation and maintenance, and research and development; third, compared with other methods of implementing dynamic aspects, it has higher performance and flexibility; in addition, it adopts Javassist dynamic bytecode technology, which is easier to use and simpler than ASM, and there is no need to understand JVM instructions.
[0165] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0166] Based on the same inventive concept, the embodiment of the present application also provides a bytecode modification device for implementing the bytecode modification method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more bytecode modification device embodiments provided below can refer to the limitations of the bytecode modification method above, and will not be repeated here.
[0167] In one embodiment, Fig.14 As shown, a bytecode modification device is provided, comprising:
[0168] A candidate business logic acquisition module 1402 is used to acquire a candidate business logic class set, wherein the candidate business logic class set includes a modification function and at least one candidate business logic class, and the candidate business logic class corresponds to a candidate business requirement;
[0169] The bytecode to be modified loading module 1404 is used to load the bytecode to be modified, wherein the bytecode to be modified includes an initial business logic class, and the initial business logic class corresponds to an initial business requirement, and the dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified;
[0170] The business requirement determination module 1406 is used to determine a target business requirement in the candidate business requirements based on the dimensions in the initial business requirement, and determine a target business logic class in the candidate business logic class set based on the target business requirement;
[0171] The bytecode modification module 1408 is used to instantiate the modification function, and replace the bytecode to be modified including the initial business logic class with the bytecode including the target business logic class based on the instantiated modification function.
[0172] In one embodiment, the modification function includes a path determination class and an attribute modification class of a business logic class, and the candidate business logic acquisition module 1402 includes:
[0173] A business requirement determination unit, configured to generate the target business logic class based on the attribute modification class according to the candidate business requirement, wherein the candidate business logic class includes one or more of the attributes, functions and bytecode files for replacement;
[0174] Correspondingly, the device further includes a path determination module;
[0175] A path determination module is used to determine the path information of the initial business logic class based on the path determination class, and determine the data to be modified in the initial business logic class based on the path information, wherein the data to be modified includes one or more of the attributes, functions and bytecode files to be modified; wherein the candidate business logic class is used to replace the data to be modified in the initial business logic class.
[0176] In one embodiment, the candidate business logic class set includes a preset business logic class set, and the candidate business logic acquisition module 1402 includes:
[0177] A preset data packet acquisition unit, used to acquire a preset business logic data packet before loading the bytecode to be modified;
[0178] A preset method body acquisition unit, used to load the preset business logic class set from the preset business logic data packet, wherein the preset business logic class set includes a preset business method class corresponding to a preset business method class bytecode;
[0179] The bytecode modification module 1408 includes: a method body replacement unit, which is used to replace the bytecode to be modified including the initial business logic class with the bytecode including the target business logic class based on the instantiated modification function.
[0180] In one of the embodiments, the apparatus further comprises a data packet generation module, wherein the data packet generation module comprises:
[0181] A proxy class file determining unit, used to determine the proxy class file, wherein the proxy class file is used to modify the initial business logic class;
[0182] An interface class file determining unit, used for acquiring a virtual interface for testing, and generating a virtual interface class file based on the virtual interface;
[0183] The data packet generating unit is used to combine the proxy class file and the virtual interface class file, and compile the combined file to obtain the preset business logic data packet.
[0184] In one embodiment, the proxy class file determination unit includes:
[0185] A list determination subunit, used to determine a list file of a proxy class file, wherein the list file is used to define the modification authority of the proxy class file;
[0186] A modification class determination subunit is used to determine a modification class of a proxy class file, wherein the modification class includes a modification function of the proxy class file; wherein the instantiated modification function is used to replace the initial business logic class bytecode with the target business logic class bytecode;
[0187] The proxy class file generation subunit is used to combine the manifest file and the modification class to generate the proxy class file.
[0188] In one of the embodiments, the device further comprises a dimension determination module, wherein the dimension determination module comprises:
[0189] A log dimension unit, used for adding the log in the proxy class program to the bytecode to be modified if the dimension of the initial business requirement is log missing;
[0190] The test dimension unit is used to replace the third-party address in the program to be tested with the virtual interface in the application proxy program if the dimension of the initial business demand is program testing, and use the program to be tested with the replaced interface as the bytecode to be modified.
[0191] In one of the embodiments, the dimension of the initial business demand further includes a dimension of data to be modified, the dimension of data to be modified includes metadata to be modified and a data type of the metadata to be modified, and the device includes a data dimension determination module;
[0192] The data dimension determination module is used to obtain the data dimension to be modified corresponding to the bytecode to be modified before loading the bytecode to be modified;
[0193] The determining, based on the initial business requirement, a target business requirement among the candidate business requirements includes:
[0194] The business requirement determination module 1406 is used to determine the target business requirement based on the initial business requirement under the dimension of the data to be modified, and the target business requirement includes the modification requirement of the metadata to be modified and / or the modification requirement of the data type.
[0195] Each module in the above bytecode modification device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0196] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.15 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a bytecode modification method is implemented.
[0197] Those skilled in the art will understand that Fig.15 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0198] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0199] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0200] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0201] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0202] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0203] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A bytecode modification method, characterized in that: The method comprises: Acquire a set of candidate business logic classes, the set of candidate business logic classes including a modification function and at least one candidate business logic class, the candidate business logic class corresponding to a candidate business requirement; the modification function including a path determination class and an attribute modification class of the business logic class, the candidate business logic class is generated according to the candidate business requirement and the attribute modification class, and the candidate business logic class includes one or more of an attribute, a function and a bytecode file for replacement; Loading the bytecode to be modified, wherein the bytecode to be modified includes an initial business logic class, wherein the initial business logic class corresponds to an initial business requirement, and a dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified; Determine a target business requirement in the candidate business requirements based on the dimensions in the initial business requirements, and determine a target business logic class in the candidate business logic class set based on the target business requirement; Instantiating the modification function, and replacing the bytecode to be modified including the initial business logic class with the bytecode including the target business logic class based on the instantiated modification function; Based on the path determination class, path information of the initial business logic class is determined, and based on the path information, data to be modified in the initial business logic class is determined, wherein the data to be modified includes one or more of a property, a function, and a bytecode file to be modified; wherein the candidate business logic class is used to replace the data to be modified in the initial business logic class; Among them, the candidate business logic class set includes a preset business logic class set, and the obtaining of the candidate business logic class set includes: determining a proxy class file, wherein the proxy class file is used to modify the initial business logic class; obtaining a virtual interface for testing, and generating a virtual interface class file based on the virtual interface; combining the proxy class file with the virtual interface class file, and compiling the combined file to obtain a preset business logic data packet; before loading the bytecode to be modified, obtaining the preset business logic data packet; and loading the preset business logic class set from the preset business logic data packet, wherein the preset business logic class set includes a preset business method class corresponding to a preset business method class bytecode.
2. The method according to claim 1, characterized in that The generation of the proxy class file includes: Determine a list file of the proxy class file, wherein the list file is used to define the modification authority of the proxy class file; Determine a modification class of a proxy class file, wherein the modification class includes a modification function of the proxy class file; wherein the instantiated modification function is used to replace an initial business logic class bytecode with the target business logic class bytecode; The manifest file and the modified class are combined to generate the proxy class file.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: If the dimension of the initial business requirement is log missing, then adding the log in the proxy class program to the bytecode to be modified; If the dimension of the initial business requirement is program testing, the virtual interface in the application proxy program is used to replace the third-party address in the program to be tested, and the program to be tested with the replaced interface is used as the bytecode to be modified.
4. The method according to claim 1 or 2, characterized in that: The dimension of the initial business requirement also includes a dimension of data to be modified, and the dimension of the data to be modified includes metadata to be modified and a data type of the metadata to be modified. The method further includes: Before loading the bytecode to be modified, obtaining the data dimension to be modified corresponding to the bytecode to be modified; The determining, based on the initial business requirement, a target business requirement among the candidate business requirements includes: Under the dimension of the data to be modified, the target business requirement is determined based on the initial business requirement, and the target business requirement includes a modification requirement of the metadata to be modified and / or a modification requirement of the data type.
5. The method according to claim 1, characterized in that The first dimension of the initial business requirement is the detection or modification of data and data types, and the second dimension of the initial business requirement is at least one of the repair requirement of the missing log and the test requirement of the bytecode to be modified; the determining of the target business requirement among the candidate business requirements based on the dimensions in the initial business requirement includes: The first dimension and the second dimension are combined into a dimension of the initial business requirement.
6. The method according to claim 1, characterized in that The dimension of the initial business requirement corresponds to multiple target business requirements, each of which corresponds to a requirement identifier of a different functional requirement. The functional requirement is used to implement the repair and replacement of data or data types within the dimension.
7. The method according to claim 1, characterized in that The target business requirement and the target business logic class are in a one-to-one mapping relationship; the determining the target business logic class in the candidate business logic class set based on the target business requirement includes: The target business logic class is obtained by determining the mapping relationship.
8. A bytecode modification device, characterized in that: The device comprises: A candidate business logic acquisition module is used to acquire a set of candidate business logic classes, wherein the set of candidate business logic classes includes a modification function and at least one candidate business logic class, wherein the candidate business logic class corresponds to a candidate business requirement; the modification function includes a path determination class and an attribute modification class of the business logic class, wherein the candidate business logic class is generated based on the attribute modification class according to the candidate business requirement, and wherein the candidate business logic class includes one or more of attributes, functions, and bytecode files for replacement; A bytecode to be modified loading module, used to load the bytecode to be modified, wherein the bytecode to be modified includes an initial business logic class, the initial business logic class corresponds to an initial business requirement, and the dimension of the initial business requirement includes at least one of a repair requirement dimension of missing logs and a test requirement dimension of the bytecode to be modified; A business requirement determination module, configured to determine a target business requirement among the candidate business requirements based on at least one dimension of the initial business requirement, and determine a target business logic class among the candidate business logic class set based on the target business requirement; A bytecode modification module, used for instantiating the modification function, and replacing the bytecode to be modified including the initial business logic class with the bytecode including the target business logic class based on the instantiated modification function; A path determination module, used to determine the path information of the initial business logic class based on the path determination class, and determine the data to be modified in the initial business logic class based on the path information, wherein the data to be modified includes one or more of the attributes, functions and bytecode files to be modified; wherein the candidate business logic class is used to replace the data to be modified in the initial business logic class; Among them, the candidate business logic class set includes a preset business logic class set. When obtaining the candidate business logic class set, the candidate business logic acquisition module is specifically used to determine a proxy class file, and the proxy class file is used to modify the initial business logic class; obtain a virtual interface for testing, and generate a virtual interface class file based on the virtual interface; combine the proxy class file with the virtual interface class file, compile the combined file to obtain a preset business logic data packet; before loading the bytecode to be modified, obtain the preset business logic data packet; load the preset business logic class set from the preset business logic data packet, and the preset business logic class set includes a preset business method class corresponding to a preset business method class bytecode.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data processing method, device, equipment and system based on byte code
CN111782340A