Bytecode modification method and device, equipment and medium
By searching and inserting annotations of dependent object categories and dependent object categories in the bytecode, the problem of large source code modifications and failure of dependency injection in the existing dependency injection scheme is solved, and static dependency injection and code success run is achieved.
Patent Information
- Application Number
- CN202310815464.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-04
- Publication Date
- 2025-01-07
AI Technical Summary
The existing dependency injection schemes have problems in software development that the source code is modified in large amounts and a large amount of template code is written, and dependency injection may not be able to run successfully during the software stage after code compilation.
Search for the dependent object categories and dependent object categories in the bytecode to be measured through predetermined annotations, generate supplementary bytecode and insert them into the bytecode to be measured, realize static dependency injection, reduce the source code modification amount and ensure dependency injection successful operation.
It reduces the difficulty of code writing and maintenance, avoids the problem of failure of dependency injection, realizes successful injection during the compilation stage, and ensures successful dependency injection during the software runtime.
Smart Images

Figure CN119271204A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the technical field of code compilation, and in particular to a bytecode modification method, apparatus, device and medium. Background Art
[0002] In the process of software development, the dependencies between different object types in the software code are often complex. Complex dependencies can reduce the scalability of the software code, and make the maintenance and modification of the code more difficult. Existing dependency injection solutions can be used to decouple the dependencies between different object categories, thereby improving the scalability of the code and facilitating the maintenance and modification of the code. However, existing dependency injection solutions either require a large amount of modification to the source code, such as the need to write a large amount of template code, or there is a problem that the dependency injection code cannot actually succeed in the software stage after the code is compiled. Summary of the invention
[0003] The embodiments of the present disclosure describe a bytecode modification method, apparatus, device, and medium.
[0004] According to a first aspect, a bytecode modification method is provided, comprising:
[0005] According to the predetermined annotations, the bytecode to be tested is searched, and the dependent object category and the dependent object category for dependency injection are determined therefrom;
[0006] A supplementary bytecode is generated according to the dependent object category, and the supplementary bytecode is inserted into a portion of the bytecode to be tested corresponding to the dependent object category to obtain a target bytecode.
[0007] According to a second aspect, a bytecode modification device is provided, the device comprising:
[0008] A dependency determination unit is configured to search the bytecode to be tested according to a predetermined annotation, and determine therefrom a dependent object category and a dependent object category for dependency injection;
[0009] The modification unit is configured to generate a supplementary bytecode according to the dependent object category, and insert the supplementary bytecode into a portion of the bytecode to be tested corresponding to the dependent object category to obtain a target bytecode.
[0010] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method described in the first aspect.
[0011] According to a fourth aspect, an electronic device is provided, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in the first aspect is implemented.
[0012] According to the embodiments of the present disclosure, a bytecode modification method, device, equipment and medium are provided. The bytecode to be tested can be searched according to a predetermined annotation, and the dependent object category and the dependent object category used for dependency injection can be determined therefrom. Then, a supplementary bytecode is generated according to the dependent object category, and the supplementary bytecode is inserted into the part corresponding to the dependent object category in the bytecode to be tested to obtain the target bytecode. By using any one of the above methods, devices, storage media and electronic devices, static dependency injection of the code can be implemented in the compilation stage with only a small amount of source code modification, especially without writing a large amount of template code, and the code after dependency injection is guaranteed to run successfully in the software running stage. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 A schematic diagram showing a dependency injection solution;
[0014] Figure 2 A schematic diagram showing another dependency injection solution;
[0015] Figure 3 A schematic flow chart of a bytecode modification method according to an embodiment of the present disclosure is shown;
[0016] Figure 4 A schematic diagram showing a dependent object category in a bytecode according to an embodiment of the present disclosure is shown;
[0017] Figure 5 A schematic diagram showing dependent object categories in bytecode according to an embodiment of the present disclosure is shown;
[0018] Figure 6 A schematic diagram showing source code corresponding to dependency injection according to an embodiment of the present disclosure is shown;
[0019] Figure 7 A schematic diagram of a modified bytecode according to an embodiment of the present disclosure is shown;
[0020] Figure 8 A schematic block diagram of a bytecode modification device according to an embodiment of the present disclosure is shown;
[0021] Fig. 9 A schematic diagram of the structure of an electronic device suitable for implementing an embodiment of the present disclosure is shown;
[0022] Fig.10 A schematic diagram of the structure of a storage medium suitable for implementing the embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0023] The technical solution provided in this specification is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant inventions, rather than to limit the inventions. It should also be noted that, for ease of description, only the parts related to the relevant inventions are shown in the accompanying drawings. It should be noted that, in the absence of conflict, the embodiments of the present disclosure and the features in the embodiments can be combined with each other.
[0024] In the description of the implementations of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one / kind of implementation" or "the implementation" should be understood as "at least one / kind of implementation". The term "some implementations" should be understood as "at least some implementations". Other explicit and implicit definitions may also be included below.
[0025] In the process of software development, the dependencies between different object types in the software code are often complex. Complex dependencies can reduce the scalability of the software code, and the maintenance and modification of the code also become more difficult. The existing dependency injection scheme can be used to decouple the dependencies between different object types, thereby improving the scalability of the code and facilitating the maintenance and modification of the code. Specifically, the dependency injection (DI) scheme can decouple the dependencies between different dependent object categories (or consumer objects) and dependent object categories (or production objects). The dependent object category does not involve the construction of the dependent object category it depends on, and the dependent object category does not have the information on which dependent object category it depends on. The binding of the specific dependencies between them is completed through the dependency injection framework.
[0026] However, existing dependency injection solutions usually have the problem of large amount of modification to source code, such as writing a large amount of template code. Or there is a problem that the dependency injection code cannot actually succeed in the software stage after the code is compiled. For example, a dependency injection solution implements dependency injection through a predetermined code template. Figure 1 A schematic diagram of a dependency injection solution is shown, Figure 1As shown, this solution needs to implement dependency injection through the following code templates: for example, use the @Inje annotation to mark the dependent object category, for example, use the @Comp annotation to mark the specific interface that the dependent object category needs to implement, and the dependent object category (such as Activity) needs to explicitly call the framework function provided by the template, such as DaggerActivityComponent.builder().build(). inject (this) to implement the above specific interface. However, compared with the non-dependency injection case, the solution defines a specific interface and calls the feature framework function to implement the above specific interface. Not only does it require more additional code to be written in the source code, but its coding method is also quite different from the conventional coding method in the non-dependency injection case, making it more difficult to write and maintain the code. Another dependency injection solution is to dynamically inject dependencies during the software runtime. Figure 2 shows another schematic diagram of dependency injection. Figure 2 As shown, this solution can, for example, load the dependent object class and the dependent object class when the application is initialized, and search for the dependent object class required by the dependent object class during runtime through the dependency injection framework and inject it. However, since the dependent object class that the dependent object class depends on is searched during runtime, the code object of the dependent object class cannot be statically injected into the dependent object class during software compilation. This may result in a problem that after code compilation, for example, a specific dependent object class is not actually built during software runtime, and the dependent object class cannot be found, that is, the dependency injection during software runtime cannot actually succeed.
[0027] In order to solve the above technical problems, the embodiments of the present disclosure provide a method for modifying bytecodes. In some embodiments, the dependent object category and the dependent object category can be marked in the target source code by predetermined annotations in advance, and the annotations corresponding to the predetermined annotations can be searched in the bytecode to be tested obtained by compiling the target source code, and the dependent object category and the dependent object category used in the bytecode to be tested are determined according to the searched annotations. Then, a supplementary bytecode is generated according to the dependent object category, and the supplementary bytecode is inserted into the internal of the dependent object category in the bytecode to be tested to obtain the target bytecode. The advantages of this method are: on the one hand, compared with the solution of implementing dependency injection through code templates, for users, only a small amount of annotations need to be added to the source code to implement dependency injection, and there is no need to write more additional template codes, such as the dependent object category does not need to implement a specific interface, or call a specific framework function to implement the above specific interface. Therefore, the difficulty of code writing and maintenance is greatly reduced. On the other hand, compared with the solution of dynamic dependency injection at runtime, the target bytecode is obtained by modifying the bytecode to be tested obtained by compiling the source code, such as inserting the bytecode for constructing the dependent object category into the dependent object category in the bytecode to be tested. Furthermore, during the runtime, the object instance of the dependent object class can be directly constructed through the bytecode inserted in the dependent object class, that is, the problem of not being able to find the dependent object class will not occur during the runtime. The bytecode to be tested can also be modified during the compilation phase, so that if the code can be compiled, the dependency injection can actually succeed. This prevents the problem that the dependency injection cannot actually succeed during the software runtime after the code is compiled.
[0028] The detailed process of this method is further described below.
[0029] Figure 3 FIG. 1 is a flow chart showing a method for modifying a bytecode according to an embodiment of the present disclosure. Figure 3 As shown, the method comprises at least the following steps:
[0030] Step S301, searching the bytecode to be tested according to a predetermined annotation, and determining therefrom the dependent object category and the dependent object category for dependency injection;
[0031] Step S303, generating a supplementary bytecode according to the dependent object category, and inserting the supplementary bytecode into the part corresponding to the dependent object category in the bytecode to be tested to obtain a target bytecode.
[0032] First, in step S301, according to a predetermined annotation, the bytecode to be tested is searched, and the dependent object category and the dependent object category for dependency injection are determined therefrom. In different embodiments, the bytecode to be tested may be a bytecode obtained by compiling source code according to different software products or applications, or for different specific purposes. In different embodiments, the bytecode to be tested may also be a bytecode of different specific types, which may be obtained by compiling source code written in different programming languages by compilers (compilers) or interpreters (interpreters) corresponding to different coding languages, and this specification does not limit this. In one embodiment, the bytecode to be tested may be a Java bytecode, which may be obtained by compiling source code written in, for example, Java language or Kotlin language. In another embodiment, the bytecode to be tested may be a low-level virtual machine intermediate representation code LLVM IR (Low Level Virtual Machine Intermediate Representation), which may be obtained by compiling source code written in, for example, C++ language or Objective C language.
[0033] Annotation can be a special mark in different types of code (such as source code, or bytecode compiled from source code), which can be read when different types of code are compiled, loaded, and run, and corresponding processing is performed. Annotations can be used to embed supplementary information in the code without changing the original code and logic. In different embodiments, the specific method of searching for the bytecode to be tested may be different, and this specification does not limit this. Predetermined annotations can be used to identify the injected dependency relationship in the bytecode to be tested. Specifically, for example, they can be used to mark the dependent object category and the dependent object category in the dependency injection relationship. Here, the dependent object category and the dependent object category can refer to the category of program objects (or called class, class). Program objects are encapsulations of data structures and algorithms. Program objects belonging to the same class can share the properties and functions of the program class. In one embodiment, the predetermined annotations may include a first predetermined annotation and a second predetermined annotation, which are used to mark the dependent object category and the dependent object category in the bytecode to be tested, respectively. Thus, the dependent object category used for dependency injection can be determined from the multiple object categories included in the bytecode to be tested according to the first predetermined annotation; and the dependent object category used for dependency injection can be determined from the multiple object categories included in the bytecode to be tested according to the second predetermined annotation. In the above manner, the dependent object category and the dependent object category in the bytecode to be tested can be quickly determined by searching the predetermined annotation. For example, Figure 4 FIG. 1 is a schematic diagram showing a dependent object category in a bytecode according to an embodiment of the present disclosure. Figure 4As shown, you can use the annotation " @ Lcom / test / Provides ", quickly determine that the DataCenter class is the class of the dependent object category in the injected dependency relationship. Figure 4 FIG. 1 is a schematic diagram showing a dependent object category in a bytecode according to an embodiment of the present disclosure. Figure 5 As shown, you can follow the annotation " @ Lcom / Component ", quickly determine that the MainPagecomponent class is the class of the dependent object category in the injection dependency relationship. The dependent object category can be specifically injected with the attributes or member variables in the dependent object category. Therefore, in one embodiment, the predetermined annotation can also include a third predetermined annotation, and the third predetermined annotation is used to specify the attribute (Attribute) or member variable (Member Variables) pointed to by the dependency injection in the dependent object category. By searching the third predetermined annotation, the specific attribute or member variable of the dependency injection in the dependent object category can be quickly determined. Figure 5 As shown, for example, according to the annotation " @ Lcom / test / Inject ", quickly identify the dataCenter attribute as the specific attribute being injected.
[0034] As described above, in different embodiments, the bytecode to be tested may be a bytecode obtained by compiling source codes according to different software products or applications, or for different specific purposes. In one embodiment, the bytecode to be tested may be obtained, for example, by compiling a target source code. In order to obtain the bytecode to be tested including a predetermined annotation by compiling, in one embodiment, the target source code may include an annotation corresponding to the predetermined annotation. Figure 6A schematic diagram of the source code corresponding to the dependency injection according to the embodiment of the present disclosure is shown. In the example shown in Figure 6 (a), the dependent class (e.g., DataCenter) in the target source code is marked, for example, by the annotation @Provides, the dependent class (e.g., MainPagecomponent) is marked, for example, by the annotation @Component, and the dependency injection attribute in the dependent class (e.g., dataCenter) is marked, for example, by the annotation @Inject. It can be seen that these annotations in the target source code correspond to the predetermined annotations in the bytecode to be tested, respectively. Therefore, by compiling the target source code containing these annotations, the bytecode to be tested in which the predetermined annotations are marked can be obtained. In different embodiments, according to the programming statements of the target source code, the dependency injection attributes in the dependent class (e.g., dataCenter) can also be specified in other ways. For example, in one embodiment, the programming statements of the target source code support the attribute proxy feature, and the dependency injection attributes can also be specified through the attribute proxy. For example Figure 6 In the example shown in (b), the dependency injection property (e.g., dataCenter) in the dependent class can be specified by the property proxy expression "bydi". Figure 6 (a) and Figure 6 In the example of (b), for example, the use of the dependent object class and the dependent object class in the main{} function is consistent with the use under non-dependency injection. In other words, through this method, since the modification of bytecode can be achieved in an automatic way, the user only needs to make a small modification to the source code under non-dependency injection to achieve dependency injection, which improves the user's coding experience.
[0035] Then, in step S303, a supplementary bytecode is generated according to the dependent object class, and the supplementary bytecode is inserted into the part corresponding to the dependent object class in the bytecode to be tested to obtain a target bytecode. In this step, a corresponding bytecode (i.e., a supplementary bytecode) can be generated according to the dependent object class, and the bytecode can be inserted into the dependent object class in the bytecode to be tested to obtain a target bytecode. In one embodiment, specifically, the supplementary bytecode can be inserted into the constructor of the dependent object class, so that any object instance of the dependent object class executes the supplementary bytecode when it is constructed.
[0036] As mentioned above, in different embodiments, the bytecode to be tested may be a bytecode of different specific types. It is understood that in different embodiments, the supplementary bytecode generated according to the dependent object class may also be a bytecode of different specific types. In one embodiment, the supplementary bytecode may be used to perform the following operations: construct an object instance of the dependent object class, and assign the object instance to the attribute of the dependent object class. In different specific embodiments, the specific writing method of the supplementary bytecode may be different. Figure 7 FIG. 1 shows a schematic diagram of a modified bytecode according to an embodiment of the present disclosure. Figure 7 As shown, the supplementary bytecode can be, for example, an L1 bytecode block inserted into the constructor of the MainPageComponent class. In the above manner, the dependent object in the target bytecode obtained in the compilation phase includes the bytecode for constructing an object instance of the dependent object class, so that as long as the compilation is passed, the dependency injection can be successful, and the problem of not being able to find the dependent object class at runtime will not occur.
[0037] Figure 8 A schematic block diagram of a bytecode modification device according to an embodiment of the present disclosure is shown. The device is used to perform the following steps: Figure 3 The method shown, such as Figure 8 As shown, the device 800 includes:
[0038] The dependency determination unit 801 is configured to search the bytecode to be tested according to a predetermined annotation, and determine therefrom the dependent object category and the dependent object category for dependency injection;
[0039] The modifying unit 802 is configured to generate a supplementary bytecode according to the dependent object category, and insert the supplementary bytecode into a portion of the bytecode to be tested corresponding to the dependent object category to obtain a target bytecode.
[0040] The present disclosure also provides an electronic device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the following is achieved: Figure 3 The method shown.
[0041] You can also refer to the following Fig. 9 , which shows a structural schematic diagram of an electronic device 800 suitable for implementing an embodiment of the present application. Fig. 9 The electronic device 900 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0042] like Fig. 9As shown, the electronic device 900 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 901. The above-mentioned processing device 901 may be a general-purpose processor, a digital signal processor (Digital Signal Processing, DSP), a microprocessor or a microcontroller, and may further include an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 902 or the program loaded from the storage device 908 to the random access memory (RAM) 903. In RAM903, various programs and data required for the operation of the electronic device 900 are also stored. The processing device 901, ROM902 and RAM903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0043] Typically, the following devices may be connected to the I / O interface 905: an input device 906 including, for example, a touch screen, a touch pad, a keyboard, a mouse, etc.; an output device 907 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 908 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 909. The communication device 909 may allow the electronic device 900 to communicate with other devices wirelessly or by wire to exchange data. Fig. 9 The electronic device 900 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Fig. 9 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0044] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 909, or installed from the storage device 908, or installed from the ROM 902. When the computer program is executed by the processing device 901, the above-mentioned functions defined in the bytecode modification method provided in the embodiment of the present application are executed.
[0045] The present disclosure also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute the following steps provided in the present disclosure: Figure 1 The bytecode modification method shown in . Fig.10 A schematic diagram of a storage medium for implementing an embodiment of the present application. Fig.10 As shown, the storage medium 1000 may be a non-transitory computer-readable storage medium for storing non-transitory computer-executable instructions 1001. When the non-transitory computer-executable instructions 1001 are executed by the processor, the bytecode modification method provided in the embodiment of the present application may be implemented. For example, when the non-transitory computer-executable instructions 1001 are executed by the processor, one or more steps in the bytecode modification method provided in the embodiment of the present application may be executed. For example, the storage medium 1000 may be applied to the above-mentioned electronic device. For example, the storage medium 1000 may include a memory in the electronic device. For the description of the storage medium 1000, reference may be made to the description of the memory in the embodiment of the electronic device, and the repeated parts will not be repeated. The specific functions and technical effects of the storage medium 1000 may refer to the description of the bytecode modification method provided in the embodiment of the present application, and will not be repeated here.
[0046] It should be noted that the computer-readable medium described in the embodiments of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a memory card of a smart phone, a storage component of a tablet computer, a portable computer disk, a hard disk of a personal computer, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In an embodiment of the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, device or device. In an embodiment of the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0047] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the server, the electronic device implements the bytecode modification method provided in the embodiment of the present application.
[0048] Computer program code for performing the operations of the disclosed embodiments may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0049] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, which contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box may also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they may sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions. The units involved in the embodiments described in the present disclosure can be implemented by software or by hardware. Among them, the name of the unit does not constitute a limitation on the unit itself under certain circumstances. The functions described above in this article can be performed at least in part by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0050] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the storage medium and computing device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0051] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solution formed by the specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned public concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) to form a technical solution. In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Certain features described in the context of a single embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination.
[0052] The specific implementation methods described above further describe in detail the purpose, technical solutions and beneficial effects of the embodiments of the present invention. Although the subject matter has been described in a language specific to structural features and / or method logic actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims. It should be understood that the above is only a specific implementation method of the embodiments of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A bytecode modification method, comprising: According to the predetermined annotations, the bytecode to be tested is searched, and the dependent object category and the dependent object category for dependency injection are determined therefrom; A supplementary bytecode is generated according to the dependent object category, and the supplementary bytecode is inserted into a portion of the bytecode to be tested corresponding to the dependent object category to obtain a target bytecode.
2. The method according to claim 1, wherein: The predetermined annotation includes a first predetermined annotation and a second predetermined annotation, the first predetermined annotation is used to mark the dependent object category, and the second predetermined annotation is used to mark the dependent object category; The step of searching the bytecode to be tested according to the predetermined annotation and determining the dependent object category and the dependent object category for dependency injection includes: According to the first predetermined annotation, determining a dependent object class for dependency injection from a plurality of object classes included in the bytecode to be tested; According to the second predetermined annotation, a dependency object class used for dependency injection is determined from a plurality of object classes included in the bytecode to be tested.
3. The method according to claim 2, wherein: The predetermined annotation includes a third predetermined annotation, and the third predetermined annotation is used to mark the member variable pointed to by the dependency injection in the dependent object class.
4. The method according to claim 1, wherein: The supplementary bytecodes are used to perform the following operations: An object instance of the dependent object class is constructed, and the object instance is assigned to the attribute of the dependent object class.
5. The method according to claim 1, wherein: The bytecode to be tested is obtained by compiling a target source code, and the target source code includes an annotation corresponding to the predetermined annotation.
6. The method according to claim 5, wherein: In the portion of the target source code corresponding to the dependent object class, the properties of the dependency injection are specified through a property proxy.
7. The method according to claim 1, wherein: Inserting the supplementary bytecode into a portion of the bytecode to be tested corresponding to the dependent object class includes: inserting the supplementary bytecode into a constructor of the dependent object class.
8. The method according to claim 1, wherein: The bytecode to be tested is one of JAVA bytecode and low-level virtual machine intermediate representation code LLVM IR.
9. A bytecode modification device, comprising: A dependency determination unit is configured to search the bytecode to be tested according to a predetermined annotation, and determine therefrom a dependent object category and a dependent object category for dependency injection; The modification unit is configured to generate a supplementary bytecode according to the dependent object category, and insert the supplementary bytecode into a portion of the bytecode to be tested corresponding to the dependent object category to obtain a target bytecode.
10. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 8.
11. An electronic device comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 8 is implemented.