Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure, as generally described and illustrated in the figures herein, could be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making creative efforts, shall fall within the protection scope of the disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The term "and/or" herein merely describes an associative relationship, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
According to research, in the existing code development technology, a code developer can generally use codes developed by other code development teams and adjust and improve the codes on the basis of the codes, so that the codes meeting the corresponding requirements are obtained. However, when the code used by the code developer is unstable or has corresponding defects, the misuse of the code may cause the system to crash. Therefore, a technical solution capable of hiding the defective or unstable code is needed to avoid the system crash caused by the misuse of the code.
Based on the above research, the present disclosure provides a code processing method, apparatus, computer device, and storage medium. According to the above description, the code to be processed may be obtained first, and the code to be processed may be compiled according to the target compiling mode to obtain the code compiling result. Thereafter, a code modification identifier may be identified in the code compilation result, and target modification data in the code compilation result that matches the code modification identifier may be determined. Therefore, the position of the target modification data can be better determined in the code compiling result through the code modification identifier, and the accuracy of the determined target modification data is further improved. Then, a target modification mode corresponding to the target modification data may be determined based on the target compilation mode, and the access right of the target modification data is modified according to the target modification mode, so as to obtain a modified code compilation result. Therefore, the code execution stability of the modified code compiling result can be ensured in the execution process, so that unstable codes or system crash caused by defective codes in the execution process can be avoided, and the code operation accuracy is improved. Meanwhile, the reuse rate of the codes to be processed can be improved, so that the development efficiency of the codes is improved.
To facilitate understanding of the present embodiment, a code processing method disclosed in the embodiments of the present disclosure is first described in detail, and an execution subject of the code processing method provided in the embodiments of the present disclosure is generally a computer device with certain computing power.
Referring to fig. 1, a flowchart of a code processing method provided by the embodiment of the present disclosure is shown, where the method includes steps S101 to S107, where:
s101: and acquiring a code to be processed, and compiling the code to be processed according to a target compiling mode to obtain a code compiling result.
Here, the target compiling mode may be the first compiling mode or the second compiling mode. The first compiling mode may be used to indicate a compiling mode corresponding to a compiling stage of an SDK (Software Development Kit), or may be understood as a compiling mode for compiling to-be-processed code corresponding to the SDK Kit. Wherein the second compilation mode may be used to indicate a compilation mode corresponding to a compilation phase of the host.
For example, the first compiling mode may be understood as a compiling mode corresponding to a development kit when running compiling; the second compiling mode can be understood as a compiling mode corresponding to an APP (Application program) running and compiling.
In the embodiment of the present disclosure, the to-be-processed code may be a code in Java language, or may also be a code in Python language, and the present disclosure does not limit the type of the to-be-processed code, so as to meet the actual requirement.
In the embodiment of the present disclosure, after the to-be-processed code is obtained, the target compiling mode may be determined first, and the to-be-processed code is compiled according to the determined target compiling mode, so as to obtain a code compiling result. The code compiling result may be a byte code file.
S103: and identifying a code modification identifier in the code compiling result, and determining target modification data matched with the code modification identifier in the code compiling result.
In the embodiment of the present disclosure, the code modification identifier may be understood as an identifier for indicating a modified part of the code, for example, the code modification identifier may be @ Hide, or the code modification identifier may also be @ concept, and the content of the code modification identifier is not particularly limited by the present disclosure, so as to be implemented.
In an embodiment of the present disclosure, the target modification data is used to indicate code data to be modified, for example, the target modification data may be at least one of: class to be modified, method to be modified, field to be modified. The present disclosure does not specifically limit the target modification data to meet the actual requirements.
In the embodiment of the disclosure, after the code compiling result is obtained, the code modification identifier may be identified in the code compiling result, and the target modification data matching with the code modification identifier in the code compiling result may be determined.
S105: determining a target modification mode of the target modification data based on the target compilation mode, wherein the target modification mode is used for indicating an access right for modifying the target modification data.
In the embodiment of the present disclosure, the target modification mode may be used to indicate an access right for modifying the target modification data, where the access right may be used to indicate visibility of the target modification data to other classes (or methods, or fields) contained in the code compilation result (or may also be understood as the code to be processed).
In the embodiment of the present disclosure, the access right may include at least the following: public (public), protected (protected), private (private), packet access rights (default).
In the embodiment of the present disclosure, a target modification mode corresponding to the target modification data may be determined based on the target compilation mode. For example, when the target compiling mode is the first compiling mode, the target modification mode corresponding to the target modification data may be determined as the first modification mode, and when the target compiling mode is the second compiling mode, the target modification mode corresponding to the target modification data may be determined as the second modification mode. The first modification mode can be used for indicating that the access right of the target modification data is modified to be a mode hidden from the outside, and the second modification mode can be used for indicating that the access right of the target modification data is modified to be a mode not hidden from the outside.
For example, the first modification mode corresponding to the target modification data may be: and modifying the access right of the target modification data to be private. For example, the access right of the target modification data can be modified from public to private.
For a second modification mode corresponding to the target modification data, the second modification mode may be: the access rights of the target modification data are modified to be common. For example, the access right of the target modification data can be modified from private to public.
S107: and modifying the access authority of the target modified data according to the target modification mode to obtain a modified code compiling result.
In the embodiment of the present disclosure, after the access right of the target modification data is modified according to the target modification mode, a modified code compiling result may be obtained.
For example, when the target modification mode is the first modification mode, the obtained modified code compilation result hides the target modification data, and at this time, in the process of executing the modified code compilation result, the code compilation result corresponding to the target modification data cannot be executed. For another example, when the target modification mode is the second modification mode, the obtained modified code compiling result does not hide the target modification data, and at this time, in the process of executing the modified code compiling result, the code compiling result corresponding to the target modification data may be executed.
According to the above description, the code to be processed may be obtained first, and the code to be processed may be compiled according to the target compiling mode to obtain the code compiling result. Thereafter, a code modification identifier may be identified in the code compilation result, and target modification data in the code compilation result that matches the code modification identifier may be determined. Therefore, the position of the target modification data can be better determined in the code compiling result through the code modification identifier, and the accuracy of the determined target modification data is further improved. Then, a target modification mode corresponding to the target modification data may be determined based on the target compiling mode, and the access right of the target modification data is modified according to the target modification mode, so as to obtain a modified code compiling result. Therefore, the compiling result of the modified code can ensure the stability of code execution in the executing process, so that unstable codes or system crash caused by defective codes in the executing process can be avoided, and the running accuracy of the codes is improved. Meanwhile, the reuse rate of the codes to be processed can be improved, so that the development efficiency of the codes is improved.
In an alternative embodiment, for S103: determining target modification data matched with the code modification identifier in the code compiling result, specifically comprising the following steps:
step S1031: determining byte codes matched with the code modification identifications in the code compiling result;
step S1032: determining the target modification data in the matched bytecode, wherein the target modification data includes at least one of: class to be modified, method to be modified, field to be modified.
In the embodiments of the present disclosure, the bytecode may be understood as a file containing a computer-executable program. The bytecode may be obtained by compiling code (i.e., source code) written by a developer. For example, the code compilation result may be understood as a bytecode.
In the disclosed embodiment, the bytecode matching the code modification identification can be determined in the code compilation result. For example, in the case that the code modification identifier is @ high (or @ common), the location of the code modification identifier @ high may be determined in the code compilation result, and the data subsequent to the location of the code modification identifier @ high may be determined as the bytecode matching the code modification identifier @ high.
Then, target modification data may be determined in the determined matching bytecode, where the target modification data may be at least one of: class to be modified, method to be modified, field to be modified.
In specific implementation, the bytecode corresponding to the first class (or method or field) after the position of the code modification identifier @ Hide may be determined as target modification data.
In the above embodiment, by determining the bytecode matched with the code modification identifier in the code compiling result and determining the target modification data in the matched bytecode, modification of the code to be processed caused by directly determining the code to be processed as the target modification data can be avoided, so that invariance and reusability of the code to be processed can be ensured, and time cost and labor cost for re-editing the code to be processed can be saved.
In an optional embodiment, on the basis of steps S1031 to S1032, with respect to S107: modifying the access authority of the target modified data according to the target modification mode to obtain a modified code compiling result, which specifically comprises the following processes:
and under the condition that the target modification mode is a first modification mode, modifying the original access right of the target modification data into a first access right, wherein the first access right is used for indicating that the target modification data is hidden outwards, and the target compiling mode corresponding to the first modification mode is a compiling mode corresponding to a compiling stage of the SDK.
In the embodiment of the present disclosure, after the target modification data is determined in the matched bytecode, the access right of the target modification data may be modified according to the target modification mode.
In a specific implementation, a target modification mode corresponding to the target compiling mode may be determined based on the target compiling mode, and then the access right of the target modification data may be modified according to the determined target modification mode.
For example, in a case where the target coding mode is the above-described first coding mode, it may be determined that a target modification mode corresponding to the target coding mode is the first modification mode. After that, the original access right of the target modification data can be modified into the first access right according to the first modification mode.
The original access right can be understood as the access right corresponding to the target modified data before modification.
The first access right is used for indicating that the target modification data is hidden from the outside, so that the original access right of the target data is data which is not hidden from the outside. At this time, it may be determined that the original access right may be any one of the following: public (public), protected (protected), package access rights (default).
In the above embodiment, the original access right of the target modification data may be modified to be hidden from outside when the target modification mode is the first modification mode, so that the access right of the target modification data may be modified to be hidden from outside in the compilation stage of the SDK, thereby avoiding an execution failure or an execution crash phenomenon caused by instability of the target modification data, and further ensuring accuracy and stability of execution.
In an alternative embodiment, as shown in fig. 2, the following are addressed: modifying the original access right of the target modification data into a first access right, and specifically comprising the following steps:
step S21: determining a permission identifier in the target modification data;
step S22: modifying the permission identifier to a first permission identifier, wherein the first permission identifier is an identifier corresponding to the first access permission.
In the embodiment of the present disclosure, the right identifier may be understood as an identifier of an access right, for example, in a case that the access right is public (public), a right identifier corresponding to the access right is public. As another example, in the case that the access right is protected (protected), the right identifier corresponding to the access right is protected. This is not further enumerated here.
In this embodiment of the present disclosure, the first permission identifier is an identifier corresponding to the first access permission, that is, the first permission identifier is a permission identifier corresponding to externally hidden target modification data, and at this time, the first permission identifier may be a private.
In the embodiment of the present disclosure, in the case that the original access right of the target modification data is modified to the first access right, the authority identifier in the target modification data may be determined by the original access right of the target modification data, and then the authority identifier is modified to the first authority identifier.
In a specific implementation, after the permission identifier is determined, a bytecode modification function is called to modify the permission identifier into the first permission identifier. Wherein the bytecode modification function may be a javasist function.
In the above embodiment, the permission identifier in the target modification data may be determined first, and then the permission identifier is modified into the first permission identifier, so that the target modification data can be hidden from the outside simply and quickly.
In an alternative embodiment, as shown in fig. 3, in the case that the target modification mode is the first modification mode, for S107: modifying the access right of the target modified data according to the target modification mode, which specifically comprises the following steps:
step S31: acquiring original access authority of the target modified data before modification;
step S32: and generating target identification information at the specified position of the target modification data based on the original access right, wherein the target identification information is used for indicating the original access right of the target modification data.
In the embodiment of the present disclosure, the specified position of the target data may be at the end of the target data, or may be at the beginning of the target data, and the specified position of the target data is not specifically limited by the present disclosure, so as to be implemented as the standard.
In embodiments of the present disclosure, the target identification information may be used to indicate the original access rights of the target modification data. For example, in the case where the original access rights of the target modification data are public (public), the target identification information may be: the modify is 1, or the target identification information may be: the modification is 0, and the content of the target identification information is not particularly limited in this disclosure, so as to meet the actual needs.
In the embodiment of the present disclosure, before modifying the target modification data according to the target modification mode, an original access right of the target modification data may be obtained first, and target identification information may be generated at a specified position of the target modification data based on the original access right.
In the above embodiment, in the case that the access right of the target modified data is modified according to the target modification mode, the original access right of the target modified data before modification is acquired, and the target identification information is generated based on the original access right, so that the original access right information of the target modified data can be retained. Meanwhile, the target identification information can also be used as identification information for finishing modifying the target modification data, so that the target modification data can be determined to be modified on the basis of the target identification information.
In an alternative embodiment, as shown in fig. 4, on the basis of step S31 to step S32, for S107: modifying the access right of the target modified data according to the target modification mode to obtain a modified code compiling result, and specifically comprising the following steps of:
step S41: under the condition that the target modification mode is a second modification mode, acquiring target identification information in the target modification data; the target compiling mode corresponding to the second modification mode is a compiling mode corresponding to a compiling stage of the host; (ii) a
Step S42: determining original access rights of the target modification data based on the target identification information;
step S43: determining a permission identifier corresponding to the original access permission to obtain a second permission identifier;
step S44: and modifying the authority identifier of the target modification data into a second authority identifier, wherein the second authority identifier is an identifier corresponding to the original access authority.
In the embodiment of the present disclosure, in a case that the target compiling mode is the second compiling mode, it may be determined that the target modification mode is the second modification mode based on the target compiling mode. In the case that the target modification mode is the second modification mode, the target identification information in the target modification data may be obtained first, and then the original access right of the target modification data may be determined based on the target identification information.
For example, when the target identification information is as described above: if the modify is 1, it may be determined that the original access right of the target data is public (public).
Thereafter, a rights identifier corresponding to the original access rights may be determined, resulting in a second rights identifier. The second permission identifier may be understood as an original access permission to restore the target modified data, for example, the second permission identifier may indicate a permission identifier that does not hide the target modified data from the outside.
For example, when the original access right is public (public), the second right identifier may be public.
The rights identifier of the target modification data may then be modified to a second rights identifier.
In specific implementation, a bytecode modification function may be called to modify the permission identifier of the target modification data to a second permission identifier. Wherein the bytecode modification function can be a javasist function.
In the above embodiment, when the target modification mode is the second modification mode, the target identification information in the target modification data may be obtained, and the original access right of the target modification data may be determined based on the target identification information. Then, after determining the second permission identifier corresponding to the original access permission, the permission identifier of the target modification data may be modified into the second permission identifier. Therefore, the compiling result of the modified code can be smoothly executed in the host execution stage, and the phenomenon that the code to be processed fails in the host stage is further avoided.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same inventive concept, a code processing apparatus corresponding to the code processing method is also provided in the embodiments of the present disclosure, and since the principle of solving the problem of the apparatus in the embodiments of the present disclosure is similar to the code processing method in the embodiments of the present disclosure, the implementation of the apparatus may refer to the implementation of the method, and the repeated parts are not described again.
Referring to fig. 5, a schematic diagram of a code processing apparatus provided in an embodiment of the present disclosure is shown, where the apparatus includes: an acquisition unit 51, a recognition unit 52, a determination unit 53, a modification unit 54; wherein, the first and the second end of the pipe are connected with each other,
the obtaining unit 51 is configured to obtain a code to be processed, and compile the code to be processed according to a target compilation mode to obtain a code compilation result;
a recognition unit 52, configured to recognize a code modification identifier in the code compilation result, and determine target modification data matching the code modification identifier in the code compilation result;
a determining unit 53, configured to determine a target modification mode of the target modification data based on the target compiling mode, where the target modification mode is used to indicate an access right to modify the target modification data;
and a modifying unit 54, configured to modify the access right of the target modified data according to the target modification mode, so as to obtain a modified code compiling result.
According to the above description, the code to be processed may be obtained first, and the code to be processed may be compiled according to the target compiling mode to obtain the code compiling result. Thereafter, a code modification identifier may be identified in the code compilation result, and target modification data in the code compilation result that matches the code modification identifier may be determined. Therefore, the position of the target modification data can be better determined in the code compiling result through the code modification identifier, and the accuracy of the determined target modification data is further improved. Then, a target modification mode corresponding to the target modification data may be determined based on the target compilation mode, and the access right of the target modification data is modified according to the target modification mode, so as to obtain a modified code compilation result. Therefore, the code execution stability of the modified code compiling result can be ensured in the execution process, so that unstable codes or system crash caused by defective codes in the execution process can be avoided, and the code operation accuracy is improved. Meanwhile, the reuse rate of the codes to be processed can be improved, so that the development efficiency of the codes is improved.
In a possible embodiment, the identification unit is further configured to: determining byte codes matched with the code modification identifications in the code compiling result; determining the target modification data in the matched bytecode, wherein the target modification data includes at least one of: class to be modified, method to be modified, field to be modified.
In a possible embodiment, the modifying unit is further configured to: and under the condition that the target modification mode is a first modification mode, modifying the original access right of the target modification data into a first access right, wherein the first access right is used for indicating that the target modification data is hidden outwards, and a target compiling mode corresponding to the first modification mode is a compiling mode corresponding to a compiling stage of the SDK.
In a possible embodiment, the modifying unit is further configured to: determining a permission identifier in the target modification data; modifying the permission identifier to a first permission identifier, wherein the first permission identifier is an identifier corresponding to the first access permission.
In a possible embodiment, the modifying unit is further configured to: under the condition that a target modification mode is a first modification mode, acquiring original access permission of the target modification data before modification; and generating target identification information at a specified position of the target modification data based on the original access right, wherein the target identification information is used for indicating the original access right of the target modification data.
In a possible implementation, the modifying unit is further configured to: under the condition that the target modification mode is a second modification mode, acquiring target identification information in the target modification data; the target compiling mode corresponding to the second modification mode is a compiling mode corresponding to a compiling stage of the host; determining original access rights of the target modification data based on the target identification information; determining a permission identifier corresponding to the original access permission to obtain a second permission identifier; and modifying the authority identifier of the target modification data into a second authority identifier, wherein the second authority identifier is an identifier corresponding to the original access authority.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
Corresponding to the code processing method in fig. 1, an embodiment of the present disclosure further provides a computer device 600, as shown in fig. 6, a schematic structural diagram of the computer device 600 provided in the embodiment of the present disclosure includes:
a processor 61, memory 62, and bus 63; the memory 62 is used for storing execution instructions and includes a memory 621 and an external memory 622; the memory 621 is also called an internal memory, and is used for temporarily storing the operation data in the processor 61 and the data exchanged with the external memory 622 such as a hard disk, the processor 61 exchanges data with the external memory 622 through the memory 621, and when the computer device 600 operates, the processor 61 communicates with the memory 62 through the bus 63, so that the processor 61 executes the following instructions:
acquiring a code to be processed, and compiling the code to be processed according to a target compiling mode to obtain a code compiling result;
identifying a code modification identifier in the code compiling result, and determining target modification data matched with the code modification identifier in the code compiling result;
determining a target modification mode of the target modification data based on the target compilation mode, wherein the target modification mode is used for indicating an access right for modifying the target modification data;
and modifying the access authority of the target modified data according to the target modification mode to obtain a modified code compiling result.
The embodiments of the present disclosure also provide a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to perform the steps of the code processing method described in the above method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
The embodiments of the present disclosure further provide a computer program product, where the computer program product carries a program code, and instructions included in the program code may be used to execute the steps of the code processing method in the foregoing method embodiments, which may be specifically referred to in the foregoing method embodiments and are not described herein again.
The computer program product may be implemented by hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK) or the like.
It can be clearly understood by those skilled in the art that, for convenience and simplicity of description, the specific working process of the system and the apparatus described above may refer to the corresponding process in the foregoing method embodiment, and details are not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, apparatus, and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in software functional units and sold or used as a stand-alone product, may be stored in a non-transitory computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, but not to limit the technical solutions, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: those skilled in the art can still make modifications or changes to the embodiments described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the technical scope of the disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.