CN107861807B - Optimization method and device for program call - Google Patents

Optimization method and device for program call Download PDF

Info

Publication number
CN107861807B
CN107861807B CN201711160655.5A CN201711160655A CN107861807B CN 107861807 B CN107861807 B CN 107861807B CN 201711160655 A CN201711160655 A CN 201711160655A CN 107861807 B CN107861807 B CN 107861807B
Authority
CN
China
Prior art keywords
function
optimized
optimization
jump
optimized function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201711160655.5A
Other languages
Chinese (zh)
Other versions
CN107861807A (en
Inventor
任太胜
易新
王浩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Qihoo Technology Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201711160655.5A priority Critical patent/CN107861807B/en
Publication of CN107861807A publication Critical patent/CN107861807A/en
Application granted granted Critical
Publication of CN107861807B publication Critical patent/CN107861807B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Abstract

The invention discloses a method and a device for optimizing program calling, relates to the technical field of application development, and mainly aims to solve the problem that in the existing version after 7.0 android, due to the fact that the JIT technology is used for performing dynamic optimization during function calling, namely, dex is dynamically translated to a local function during program running, aiming at the dynamic optimization, the next time function calling is performed on a function subjected to JIT optimization processing, the optimized function is called, and calling cannot be performed. The main technical scheme is as follows: when the optimized function operation is triggered and called, judging whether the optimized function executes the hooking operation or not; and if the optimized function executes the hooking operation, the optimized function is optimized by the optimized function through a jump template and a preset processing operation, wherein the jump template is used for optimizing the optimized function. The method is mainly used for optimizing the program call.

Description

Optimization method and device for program call
Technical Field
The invention relates to the technical field of application development, in particular to a method and a device for optimizing program calling.
Background
With the rapid development of the application development technology of the operating system, the virtualization technology is used for processing and developing the bottom layer of the operating system and becomes a mainstream means. The Android Runtime (ART) virtual machine is different from the traditional Dalvik virtual machine, and a pre-compiling technology is used for replacing a timely compiling technology in Dalvik, so that starting and execution of an application program are accelerated.
At present, an ART virtual machine used by an android system in an android 4.4 version adopts a just-in-time production mode JIT technology to carry out dynamic optimization of interpretation and execution of the ART virtual machine in a multi-open application process, the dynamic optimization is only limited to the condition that the process can normally run, in order to save time, the ART virtual machine is not dynamically optimized during installation, whether balance call is carried out during the operation of the called function or not is carried out to carry out dynamic optimization, i.e., dex is determined to be a local function, only limited to the case where the current process survives, but in the version after android 7.0, since the JIT technique is a dynamic optimization at function call time, namely, the dex is dynamically translated to the local function during the running of the program, aiming at the dynamic optimization, the function of the JIT optimization processing can not be ensured to be called next time, the optimized function is called, so that calling cannot be performed, and optimization of program calling becomes a problem to be solved urgently.
Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for optimizing a program call, and mainly aims to solve the problem that in the existing version after 7.0 android, because the JIT technology performs dynamic optimization during function call, that is, a dex is dynamically translated to a local function during program run, for the dynamic optimization, it cannot be guaranteed that an optimized function is called when a function subjected to JIT optimization processing is called next time, and thus the calling cannot be performed.
According to one aspect of the invention, a method for optimizing a program call is provided, which comprises the following steps:
when the optimized function operation is triggered and called, judging whether the optimized function executes the hooking operation or not;
and if the optimized function executes the hooking operation, the optimized function is optimized by the optimized function through a jump template and a preset processing operation, wherein the jump template is used for optimizing the optimized function.
Further, the method further comprises:
and if the optimized function does not execute the hooking operation, directly adopting a preset processing operation and the optimized function to process the optimized function.
Further, if the optimized function executes the hooking operation, the optimizing function performs optimization processing on the optimized function through a jump template and a preset processing operation, including:
when the optimized function hooks the optimized function through the Hook function, judging whether a skip identifier exists in the optimized function;
if the skip identifier exists, analyzing the parameter in the optimized function;
if the conversion format identifier of the parameter is smaller than a preset conversion condition, skipping to a replacement function for processing through a preset pointing instruction;
after the replacement function is executed, judging whether a first jump instruction is executed according to the service requirement of the optimization function, if the service requirement is determined to execute the optimization function, executing the first jump instruction, wherein the first jump instruction is used for jumping to the optimization function;
and enabling the optimization function to process the optimization function through preset processing operation.
Further, the method further comprises:
and if the conversion format identifier of the parameter is larger than a preset conversion condition, executing a second jump instruction, wherein the second jump instruction is used for jumping to the optimized function.
Further, when the optimized function hooks the optimized function through the Hook function, the determining whether a jump identifier exists in the optimized function includes:
and when the optimized function hooks the optimized function through the Hook function, judging whether a head byte in the optimized function is a jump mark JMP or not.
Further, after analyzing the parameter in the optimized function if the skip identifier exists, the method further includes:
and storing the analyzed parameters in local variables corresponding to a preset thread, converting elements in the local variables into corresponding data type pointers according to the parameters, and transmitting the data type pointers to a Java layer, wherein the parameters comprise conversion format information, parameter transmission sequence information and parameter type information. After the replacement function is executed, judging whether to execute a first jump instruction according to the service requirement of the optimization function, and if the service requirement is determined to execute the optimization function, executing the first jump instruction comprises the following steps:
and detecting whether the identifier of the optimization function needing to be executed exists in the optimization function service according to the data type pointer, and if the identifier of the optimization function needing to be executed exists, executing the first jump instruction.
After the jump to the replacement function for processing is performed through the preset pointing instruction, the method further includes:
further, resetting the conversion format identifier.
According to an aspect of the present invention, there is provided an apparatus for optimizing a program call, including:
the judging unit is used for judging whether the optimized function executes the hooking operation or not when the optimized function operation is triggered and called;
the first processing unit is configured to, if the optimized function executes the hooking operation, optimize the optimized function by the optimized function through a jump template in combination with a preset processing operation, where the jump template is used to optimize the optimized function.
Further, the apparatus further comprises:
and the second processing unit is used for directly adopting preset processing operation and the optimization function to process the optimized function if the optimized function does not execute hooking operation.
Further, the first processing unit includes:
the judging module is used for judging whether a jump identifier exists in the optimized function when the optimized function hooks the optimized function through a Hook function;
the analysis module is used for analyzing the parameters in the optimized function if the jump identifier exists;
the first processing module is used for skipping to a replacement function for processing through a preset pointing instruction if the conversion format identifier of the parameter is smaller than a preset conversion condition;
the first execution module is used for judging whether to execute a first jump instruction according to the service requirement of the optimization function after the replacement function is executed, and if the service requirement is determined to execute the optimization function, executing the first jump instruction, wherein the first jump instruction is used for jumping to the optimization function;
and the second processing module is used for enabling the optimization function to process the optimized function through preset processing operation.
Further, the first processing unit further includes:
and the second execution module is used for executing a second jump instruction if the conversion format identifier of the parameter is larger than a preset conversion condition, wherein the second jump instruction is used for jumping to the optimized function.
Further, the determining module is specifically configured to determine whether a head byte in the optimized function is a jump flag JMP when the optimized function hooks the optimized function through a Hook function.
Further, the first processing unit further includes:
and the storage module is used for storing the analyzed parameters in local variables corresponding to a preset thread, converting elements in the local variables into corresponding data type pointers according to the parameters and transmitting the data type pointers to the Java layer, wherein the parameters comprise conversion format information, parameter transmission sequence information and parameter type information.
Further, the first execution module is specifically configured to detect whether an identifier that the optimization function needs to be executed exists in the optimization function service according to the data type pointer, and if the identifier that the optimization function needs to be executed exists, execute the first jump instruction.
Further, the first processing unit further includes:
and the resetting module is used for resetting the conversion format identifier.
According to still another aspect of the present invention, a storage medium is provided, wherein at least one executable instruction is stored in the storage medium, and the executable instruction causes a processor to execute an operation corresponding to the optimization method called by the program.
According to still another aspect of the present invention, there is provided a terminal including: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the optimization method called by the program.
By the technical scheme, the technical scheme provided by the embodiment of the invention at least has the following advantages:
the invention provides an optimization method and device for program calling, which comprises the steps of firstly judging whether an optimization function executes a hooking operation or not when the operation of the optimization function is triggered to be called, if the optimization function executes the hooking operation, optimizing the optimization function by combining a jump template and a preset processing operation, wherein the jump template is used for optimizing the optimization function. Compared with the prior version after 7.0 android, the JIT technology is used for dynamically optimizing the function during calling, namely, the dex is dynamically translated to the local function during the program operation, and aiming at the dynamic optimization, the optimized function is called when the function subjected to the JIT optimization processing is called next function, so that the calling cannot be performed.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
FIG. 1 is a flowchart illustrating a method for optimizing a program call according to an embodiment of the present invention;
FIG. 2 is a diagram illustrating a JIT dynamic optimization process provided by an embodiment of the present invention;
FIG. 3 is a flow chart of another method for optimizing a program call according to an embodiment of the present invention;
FIG. 4 is a flow chart of a jump module provided by an embodiment of the invention;
FIG. 5 is a flowchart illustrating a process of operating a jump template in conjunction with a default process according to an embodiment of the present invention;
FIG. 6 is a block diagram of an apparatus for optimizing a procedure call according to an embodiment of the present invention;
FIG. 7 is a block diagram of an apparatus for optimizing a program call according to an embodiment of the present invention;
fig. 8 shows a schematic diagram of a terminal according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
The embodiment of the invention provides a method for optimizing program calling, which comprises the following steps of:
101. when the optimized function operation is triggered and called, whether the optimized function executes the hooking operation is judged.
The hooking operation is an Inline Hook operation, and the Inline Hook is performed on a machine code of a function, wherein the machine code is a binary code compiled by ART. In addition, the Hook function is a Hook function, which is a part of an operating system message processing mechanism, by setting a Hook, an application program can filter all messages and events at a system level, and access messages which cannot be accessed under normal conditions, the Hook is essentially a program used for processing system messages, and is hung in the system through system call, and the Inline Hook is different from the prior ordinary Hook by modifying the call address of the function, but directly modifies an instruction in the function body of the function, and realizes the purpose of hooking by using a jump instruction.
It should be noted that the optimization function is a cooperer optimization function in the JIT dynamic optimization process as shown in fig. 2, and then the optimized artMethod function is optimized.
102. And if the optimized function executes the hooking operation, the optimized function is optimized by combining a jump template with a preset processing operation.
The skip template is used for carrying out format optimization on the optimized function, if the optimized function executes hooking operation, the interpretation function to be called is a function which is not format optimized, the skip template is a space memory used for converting the format of the optimized function, and the preset processing operation is an operation for providing corresponding processing for the optimized function, such as the operation of assigning a code again. And performing format conversion by combining preset processing operation and taking the artMethod as an optimized function, so that the optimized function called by the local function is the function with the optimized format.
Compared with the prior version after 7.0 android, the optimization method for program calling has the advantages that the JIT technology is used for dynamically optimizing the function during calling, namely, the dex is dynamically translated to the local function during the program running, aiming at the dynamic optimization, the optimized function is called when the function subjected to the JIT optimization processing is called next time, so that the calling cannot be carried out.
An embodiment of the present invention provides another method for optimizing a program call, as shown in fig. 3, where the method includes:
201. when the optimized function operation is triggered and called, whether the optimized function executes the hooking operation is judged.
This step is the same as step 101 shown in fig. 1, and is not described herein again.
It should be noted that, when the ART virtual machine is running, the internal running is performed through the Class description of Class and the Class Method description of Method. Each Java function corresponds to a Method structure, the member variables of the Method structure comprise a class object pointer of a Method, an attribute of the Method, an index of the Method in a dex file, a machine code pointer of the Method, a pointer of a Method Native code and the like, and the Java function is called at a Native layer to obtain the Method structure of the optimized function.
202. And when the optimized function hooks the optimized function through the Hook function, judging whether a jump mark exists in the optimized function.
After the optimized function performs hooking operation, namely hooking the optimized function to be called, namely the interpretation function, for the optimized function through the Hook function of the Inline Hook operation, therefore, when the optimized function hooks the optimized function through the Hook function, the optimized function can be converted into optimization of calling the local function by the local function. Before the optimized function is hooked, a flag for judging whether to jump is configured in a head byte of the optimized function, that is, before the optimized function is run, whether a jump flag exists in the optimized function needs to be judged, generally, in order to optimize the optimized function to be optimized, jump flags are configured in the optimized functions so as to directly jump to a template for optimization operation. The optimization function may be a sample optimization function in a DEX format, and the optimization function may be an artMethod function in an ELF format, which is not specifically limited in the embodiment of the present invention.
For the embodiment of the present invention, step 202 may specifically be: and when the optimized function hooks the optimized function through the Hook function, judging whether a head byte in the optimized function is a jump mark JMP or not.
It should be noted that, in order to format convert an optimized function that needs format conversion before an instruction in the optimized function is executed, a JMP instruction for jumping needs to be configured in a header byte of the optimized function, and the configured JMP instruction may occupy 8 bytes in the optimized function. Therefore, in the current step, it is directly determined whether the first 8 bytes of the optimized function is a JMP instruction.
For the conversion between formats in the ART virtual machine, optimization during calling between the local function and the local function needs to be performed, and therefore, when the optimization function and the optimized function in the embodiment of the present invention are both local functions, the conversion between the formats can be performed.
For the embodiment of the present invention, step 203 after step 202, if there is a skip identifier, analyzes the parameter in the optimized function.
The parameters are parameters for determining whether to perform spatial conversion in the optimized function, the corresponding spatial conversion includes conversion from a Java layer to a Native layer between functions, or from a Java layer to a Native layer, and the specific parameters include parameters for embodying a function format, parameters for embodying whether to perform conversion between functions, and the like.
It should be noted that, generally, for parameter analysis, some conversion format identifiers that need to be converted may be preset specifically, and matching is performed according to the conversion format identifiers and preset conversion conditions, and if the conversion format identifiers are not consistent with the preset conversion conditions, it is indicated that conversion is needed. When the split application function in the ART virtual machine is called, whether the conversion format is needed or not is further determined for the function to be called. For example, when a program for obtaining an advertisement link address in a DEX format of a game avatar application calls a link address program in an ELF format located in the bottom layer of an ART virtual machine, a situation that the formats of an original function and a target function are inconsistent occurs.
For the embodiment of the present invention, step 203 is followed by: and storing the analyzed parameters in local variables corresponding to preset threads, converting elements in the local variables into corresponding data type pointers according to the parameters, and transmitting the corresponding data type pointers to a Java layer.
The parameters include conversion format information, parameter transmission sequence information, and parameter type information, the preset thread is a container capable of supporting global variable storage, the parameters include conversion format information, parameter transmission sequence information, parameter type information, and the like, the conversion format includes conversion from a Java layer to a Native layer, or between Java layers of Native layers, for example, an ELF format and a DEX file, and embodiments of the present invention are not particularly limited. The local variables are limited local variables used for storing parameters in the preset thread, and the ART virtual machine analyzes the parameters from a register and a stack according to the parameter transfer protocol requirement and then serves as a basis for format conversion because the problems of function parameter types, space conversion and the like are involved when the function is called by jumping from an assembly layer to a Java layer. Specifically, the parameters corresponding to the assembly may be sequentially stored in an array form in the local variables of the preset thread, and the elements corresponding to the local variables of the preset thread are converted into corresponding data type pointers according to the parameter transmission sequence and the parameter type and transmitted to the Java layer.
204a, if the conversion format identifier of the parameter is smaller than the preset conversion condition, skipping to a replacement function for processing through a preset pointing instruction.
For the embodiment of the present invention, generally, the conversion format identifier is set to be a specific F, if F is smaller than 0, the conversion is set to be required, and the function jumps to a replacement function through a preset pointer instruction to perform conversion processing, where the replacement function is a function capable of performing format conversion, that is, when the function jumps to the format conversion function, a conversion code in the replacement function is first run, then an ELF-format function of a target function is converted into a DEX-format function, and then it is determined whether to call back an original function, which is not specifically limited in the embodiment of the present invention. The preset pointing instruction is used for assigning an address of a first execution instruction in a replacement function of the machine instruction to an instruction in a PC register, so that a currently executed process is jumped to the replacement function, and the PC register stores an address of a next instruction to be executed and indicates the next instruction to be executed, namely jump is realized.
It should be noted that, when the optimized function is called, for the operation characteristics of the ART virtual machine, format conversion between different functions may be performed by jumping to a replacement function. In addition, because different format conversions exist when the functions are called through Hook operation, the preset pointing instruction can dynamically configure the address of the first pointing instruction of the replacement function to the PC register according to the optimized function and the optimized function, thereby realizing the dynamic conversion among different formats.
204b, if the conversion format identifier of the parameter is larger than the preset conversion condition, executing a second jump instruction.
As shown in fig. 4, when the format conversion flag F is greater than 0, the jump is directly made to the optimized function through a second jump instruction JMP, the second jump instruction is used to jump to the optimized function, and the first 8 bytes in the optimized function are dynamically configured in the second jump instruction, so that the optimized function without format conversion is directly executed. The steps 202 and 203 are the execution programs preset in the template, and since the LDR instruction and the step of jumping back to the optimization function when F is greater than 0 need to be changed according to the addresses of the optimization function and the replacement function, the LDR and callback optimization functions in the template are dynamically generated as shown in fig. 4.
For the embodiment of the present invention, in step 205 after step 204a, after the replacement function is executed, whether to execute a first jump instruction is determined according to the service requirement of the optimization function, and if the service requirement is determined to execute the optimization function, the first jump instruction is executed.
For an embodiment of the present invention, the first jump instruction is used to jump to the optimization function.
After the replacement function is executed, a target function after format conversion which needs to be executed by returning to the original function and a target function after format conversion which does not need to be executed by returning to the original function appear, the judgment of specifically returning to the execution of the optimization function is determined according to the service requirement of the system, the service requirement is the execution purpose of the calling function, the scene of service execution comprises the service execution scene, such as system authority and parameter filtering, generally, the function calling aiming at the system authority is set as a non-callback optimization function, the function calling aiming at the parameter filtering is set as a callback optimization function, and the logic of the service requirement is generally written into a function instruction, so the specific judgment basis can be determined according to the parameter in the analyzed and optimized function, and the embodiment of the invention is not particularly limited. The first jump instruction is a JMP jump instruction that can be a jump from the currently executing thread to the optimization function, as shown in fig. 4, after the replacement function is executed, if the service requirement of the optimization function is parameter filtering, the JMP is used to call back the optimization function.
For the embodiment of the present invention, step 205 may specifically be: and detecting whether the identifier of the optimization function needing to be executed exists in the optimization function service according to the data type pointer, and if the identifier of the optimization function needing to be executed exists, executing the first jump instruction.
Generally, since the service requirement to be executed by the optimization function can be embodied by the identifier in the function, whether the identifier corresponding to the service requirement exists in the optimization function is detected one by one through the data type pointer, so as to determine whether the optimization function needs to be called back.
Further, for the embodiment of the present invention, after step 205, the method further includes: and resetting the conversion format identifier.
In order to avoid forming a dead loop by jumping to the alternative function again through the jump template shown in fig. 4 after the callback optimization function is performed, it is necessary to reset F smaller than 0 to an arbitrary value larger than 0 after the callback optimization function is executed once, so as to make the current execution process jump to the content of the optimized function in the optimized function to execute the optimized function.
For the embodiment of the present invention, step 206 after step 205, the optimized function is processed by the optimized function through a preset processing operation.
It should be noted that, because the optimized function artMethod needs to perform a preset processing operation through the optimization function coipier, so as to perform operations such as reassigning codes and other parameters in the artMethod, as shown in fig. 5, after the optimization function coipier of Hook performs the jump template processing, the optimized function artMethod is optimized through the preset processing operation in combination with the preset processing operation, that is, after the optimization function coipier performs the Hook replacement function through the optimization function on the jump template, the optimized function artMethod is optimized through the preset processing operation.
For the embodiment of the present invention, the steps in parallel in step 202, if the optimized function does not execute the hooking operation, the optimized function is processed by directly adopting the preset processing operation and the optimized function.
As shown in fig. 2, dynamic optimization is performed by using the JIT technology, and if the optimized function and the optimized function are both format-optimized functions, which indicates that the optimized function is not Hook, the optimized function is directly called through a preset processing operation.
The invention provides another optimization method for program calling, the embodiment of the invention jumps to a jump template for parameter interpretation according to a JMP instruction in a head byte in a target function after an optimization function is subjected to hooking operation, carries out format conversion through an LDR calling replacement function when a conversion format identifier F is analyzed to be less than 0, then judges to carry out callback optimization function according to the service requirement of a parameter filtering class, resets the conversion format identifier, avoids the optimization calling failure when the DEX-format optimization function optimizes the ELF-format optimized function, thereby realizing that the optimization function calls the optimized function which is subjected to format optimization, and does not need to manually process the conversion format, ensuring the consistency of the format in the calling process and improving the optimization efficiency of program calling.
Further, as an implementation of the method shown in fig. 1, an embodiment of the present invention provides an apparatus for optimizing a program call, where as shown in fig. 6, the apparatus includes: a judging unit 31 and a first processing unit 32.
The judging unit 31 is used for judging whether the optimized function executes the hooking operation when the optimized function operation is triggered and called; the judging unit 31 is configured to execute a program module, which judges whether the optimized function executes a hooking operation when the optimized function operation is triggered and called, for the optimized device called by the program.
The first processing unit 32 is configured to, if the optimized function executes the hooking operation, optimize the optimized function through a jump template in combination with a preset processing operation, where the jump template is used to optimize the optimized function. The first processing unit 32 is a program module that is executed by an optimization device called by a program, and if the optimized function executes the hooking operation, the optimized function performs optimization processing on the optimized function by combining a jump template with a preset processing operation.
Compared with the prior version after 7.0 android, the optimization device for program calling has the advantages that the JIT technology is used for dynamically optimizing the function during calling, namely, the dex is dynamically translated to the local function during the program running, aiming at the dynamic optimization, the optimized function is called when the function subjected to the JIT optimization processing is called next time, so that the calling cannot be carried out.
Further, as an implementation of the method shown in fig. 3, an embodiment of the present invention provides another optimization apparatus for program invocation, as shown in fig. 7, the apparatus includes: a determination unit 41, a first processing unit 42, and a second processing unit 43.
A judging unit 41, configured to, when an optimized function operation is triggered to be called, judge whether the optimized function performs a hooking operation;
a first processing unit 42, configured to, if the optimized function executes the hooking operation, perform optimization processing on the optimized function through a jump template in combination with a preset processing operation, where the jump template is used to optimize the optimized function.
Further, the apparatus further comprises:
a second processing unit 43, configured to directly adopt a preset processing operation and the optimization function to process the optimized function if the optimized function does not execute a hooking operation.
Further, the first processing unit 42 includes:
a judging module 4201, configured to judge whether a skip identifier exists in the optimized function when the optimized function hooks the optimized function through a Hook function;
an analyzing module 4202, configured to analyze a parameter in the optimized function if there is a skip identifier;
a first processing module 4203, configured to jump to a replacement function for processing through a preset pointing instruction if the conversion format identifier of the parameter is smaller than a preset conversion condition;
a first executing module 4204, configured to, after the replacement function is executed, determine whether to execute a first jump instruction according to a service requirement of the optimization function, and if the service requirement is determined to execute the optimization function, execute the first jump instruction, where the first jump instruction is used to jump to the optimization function;
a second processing module 4205, configured to enable the optimization function to process the optimized function through a preset processing operation.
Further, the first processing unit 42 further includes:
a second executing module 4206, configured to execute a second jump instruction if the conversion format identifier of the parameter is greater than a preset conversion condition, where the second jump instruction is used to jump to the optimized function.
Further, the determining module 4201 is specifically configured to determine whether a head byte in the optimized function is a jump flag JMP when the optimized function hooks the optimized function through a Hook function.
Further, the first processing unit 42 further includes:
a storage module 4207, configured to store the analyzed parameters in a local variable corresponding to a preset thread, convert elements in the local variable into corresponding data type pointers according to the parameters, and transmit the data type pointers to a Java layer, where the parameters include conversion format information, parameter transmission sequence information, and parameter type information.
The first executing module 4204 is specifically configured to detect whether an identifier that requires execution of the optimization function exists in the optimization function service according to the data type pointer, and if the identifier that requires execution of the optimization function exists, execute the first jump instruction.
Further, the first processing unit 42 further includes:
a resetting module 4208, configured to reset the conversion format identifier.
The invention provides another optimization device for program calling, the embodiment of the invention jumps to a jump template for parameter interpretation according to a JMP instruction in a head byte in a target function after an optimization function is subjected to hooking operation, carries out format conversion through an LDR calling replacement function when a conversion format identifier F is analyzed to be less than 0, then judges to carry out callback optimization function according to the service requirement of a parameter filtering class, resets the conversion format identifier, avoids the optimization calling failure when the DEX-format optimization function optimizes the ELF-format optimized function, thereby realizing that the optimization function calls the optimized function which is subjected to format optimization, and does not need to manually process the conversion format, ensuring the consistency of the format in the calling process and improving the optimization efficiency of program calling.
According to an embodiment of the present invention, a storage medium is provided, where at least one executable instruction is stored, and the computer executable instruction can execute the data query method in any of the above method embodiments.
Fig. 8 is a schematic structural diagram of a terminal according to an embodiment of the present invention, and the specific embodiment of the present invention does not limit the specific implementation of the terminal.
As shown in fig. 8, the terminal may include: a processor (processor)502, a Communications Interface 504, a memory 506, and a communication bus 508.
Wherein: the processor 502, communication interface 504, and memory 506 communicate with one another via a communication bus 508.
A communication interface 504 for communicating with network elements of other devices, such as clients or other servers.
The processor 502 is configured to execute the program 510, and may specifically perform relevant steps in the above data query method embodiment.
In particular, program 510 may include program code that includes computer operating instructions.
The processor 502 may be a central processing unit CPU, or an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits configured to implement an embodiment of the present invention. The terminal comprises one or more processors, which can be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs.
And a memory 506 for storing a program 510. The memory 506 may comprise high-speed RAM memory, and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
The program 510 may specifically be used to cause the processor 502 to perform the following operations:
when the optimized function operation is triggered and called, judging whether the optimized function executes the hooking operation or not;
and if the optimized function executes the hooking operation, the optimized function is optimized by the optimized function through a jump template and a preset processing operation, wherein the jump template is used for optimizing the optimized function.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It will be appreciated by those skilled in the art that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components in the method and apparatus for optimization of program calls according to embodiments of the present invention. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.

Claims (14)

1. A method for optimizing a program call, comprising:
when the optimized function operation is triggered and called, judging whether the optimized function executes the hooking operation or not;
if the optimized function executes the hooking operation, the optimized function is optimized through a jump template and a preset processing operation, and the jump template is used for optimizing the optimized function;
if the optimized function does not execute the hooking operation, directly adopting a preset processing operation and the optimized function to process the optimized function;
if the optimized function executes the hooking operation, the optimizing function performs optimization processing on the optimized function through a jump template and a preset processing operation, and the optimization processing comprises the following steps:
when the optimized function hooks the optimized function through the Hook function, judging whether a skip identifier exists in the optimized function;
if the skip identifier exists, analyzing the parameter in the optimized function;
if the conversion format identifier of the parameter is smaller than a preset conversion condition, skipping to a replacement function for processing through a preset pointing instruction;
after the replacement function is executed, judging whether a first jump instruction is executed according to the service requirement of the optimization function, if the service requirement is determined to execute the optimization function, executing the first jump instruction, wherein the first jump instruction is used for jumping to the optimization function;
and enabling the optimization function to process the optimization function through preset processing operation.
2. The method of claim 1, further comprising:
and if the conversion format identifier of the parameter is larger than a preset conversion condition, executing a second jump instruction, wherein the second jump instruction is used for jumping to the optimized function.
3. The method of claim 2, wherein when the optimization function hooks the optimized function through a Hook function, determining whether a jump flag exists in the optimized function comprises:
and when the optimized function hooks the optimized function through the Hook function, judging whether a head byte in the optimized function is a jump mark JMP or not.
4. The method of claim 3, wherein after parsing parameters in the optimized function if the skip flag exists, the method further comprises:
and storing the analyzed parameters in local variables corresponding to a preset thread, converting elements in the local variables into corresponding data type pointers according to the parameters, and transmitting the data type pointers to a Java layer, wherein the parameters comprise conversion format information, parameter transmission sequence information and parameter type information.
5. The method of claim 4, wherein after the replacing function is executed, determining whether to execute a first jump instruction according to a service requirement of the optimizing function, and if the service requirement is determined to execute the optimizing function, executing the first jump instruction comprises:
and detecting whether the identifier of the optimization function needs to be executed exists in the service of the optimization function according to the data type pointer, and if the identifier of the optimization function needs to be executed exists, executing the first jump instruction.
6. The method according to any one of claims 1-5, wherein after jumping to the replacement function by the preset point instruction, the method further comprises:
and resetting the conversion format identifier.
7. An apparatus for optimizing a program call, comprising:
the judging unit is used for judging whether the optimized function executes the hooking operation or not when the optimized function operation is triggered and called;
the first processing unit is used for optimizing the optimized function by combining a jump template and a preset processing operation if the optimized function executes the hooking operation, wherein the jump template is used for optimizing the optimized function;
the second processing unit is used for directly adopting preset processing operation and the optimization function to process the optimized function if the optimized function does not execute hooking operation;
wherein the first processing unit comprises:
the judging module is used for judging whether a jump identifier exists in the optimized function when the optimized function hooks the optimized function through a Hook function;
the analysis module is used for analyzing the parameters in the optimized function if the jump identifier exists;
the first processing module is used for skipping to a replacement function for processing through a preset pointing instruction if the conversion format identifier of the parameter is smaller than a preset conversion condition;
the first execution module is used for judging whether to execute a first jump instruction according to the service requirement of the optimization function after the replacement function is executed, and if the service requirement is determined to execute the optimization function, executing the first jump instruction, wherein the first jump instruction is used for jumping to the optimization function;
and the second processing module is used for enabling the optimization function to process the optimized function through preset processing operation.
8. The apparatus of claim 7, wherein the first processing unit further comprises:
and the second execution module is used for executing a second jump instruction if the conversion format identifier of the parameter is larger than a preset conversion condition, wherein the second jump instruction is used for jumping to the optimized function.
9. The apparatus of claim 8,
the judging module is specifically configured to judge whether a head byte in the optimized function is a jump mark JMP when the optimized function hooks the optimized function through a Hook function.
10. The apparatus of claim 9, wherein the first processing unit further comprises:
and the storage module is used for storing the analyzed parameters in local variables corresponding to a preset thread, converting elements in the local variables into corresponding data type pointers according to the parameters and transmitting the data type pointers to the Java layer, wherein the parameters comprise conversion format information, parameter transmission sequence information and parameter type information.
11. The apparatus of claim 10,
the first execution module is specifically configured to detect whether an identifier that requires execution of the optimization function exists in a service of the optimization function according to the data type pointer, and if the identifier that requires execution of the optimization function exists, execute the first jump instruction.
12. The apparatus according to any of claims 7-11, wherein the first processing unit further comprises:
and the resetting module is used for resetting the conversion format identifier.
13. A storage medium having stored therein at least one executable instruction that causes a processor to perform operations corresponding to the optimization method of program invocation recited in any of claims 1-6.
14. A terminal, comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to execute the operation corresponding to the optimization method called by the program according to any one of claims 1-6.
CN201711160655.5A 2017-11-20 2017-11-20 Optimization method and device for program call Active CN107861807B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711160655.5A CN107861807B (en) 2017-11-20 2017-11-20 Optimization method and device for program call

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711160655.5A CN107861807B (en) 2017-11-20 2017-11-20 Optimization method and device for program call

Publications (2)

Publication Number Publication Date
CN107861807A CN107861807A (en) 2018-03-30
CN107861807B true CN107861807B (en) 2021-06-25

Family

ID=61702208

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711160655.5A Active CN107861807B (en) 2017-11-20 2017-11-20 Optimization method and device for program call

Country Status (1)

Country Link
CN (1) CN107861807B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111124484B (en) * 2018-10-31 2023-09-01 上海奥陶网络科技有限公司 Java program parameter optimization method
CN111352629A (en) * 2018-12-24 2020-06-30 北京奇虎科技有限公司 Optimization method and device for program call

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104598809A (en) * 2015-02-13 2015-05-06 北京奇虎科技有限公司 Program monitoring method and defending method thereof, as well as relevant device
US20150379263A1 (en) * 2014-06-27 2015-12-31 Harshawardhan Vipat Technologies for preventing hook-skipping attacks using processor virtualization features
US20170185791A1 (en) * 2015-12-24 2017-06-29 Intel Corporation Application program interface (API) monitoring bypass
CN107102944A (en) * 2017-04-07 2017-08-29 北京深思数盾科技股份有限公司 The analysis method and device of a kind of call function

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150379263A1 (en) * 2014-06-27 2015-12-31 Harshawardhan Vipat Technologies for preventing hook-skipping attacks using processor virtualization features
CN104598809A (en) * 2015-02-13 2015-05-06 北京奇虎科技有限公司 Program monitoring method and defending method thereof, as well as relevant device
US20170185791A1 (en) * 2015-12-24 2017-06-29 Intel Corporation Application program interface (API) monitoring bypass
CN107102944A (en) * 2017-04-07 2017-08-29 北京深思数盾科技股份有限公司 The analysis method and device of a kind of call function

Also Published As

Publication number Publication date
CN107861807A (en) 2018-03-30

Similar Documents

Publication Publication Date Title
CN108021357B (en) Optimization method and device for program call
US20110138382A1 (en) System and method for loading resources into a virtual machine
CN108319513B (en) Message transmission method and device in multi-partition operating system
US11016769B1 (en) Method and apparatus for processing information
CN106648755B (en) Method and device for dynamically loading dex in android art environment
CN111736913B (en) Class loading method and device
CN111258557B (en) Code processing method, device, electronic equipment and computer readable medium
CN107861807B (en) Optimization method and device for program call
CN110569250A (en) Management method and device for analysis library of Internet of things network element
CN111813635A (en) Monitoring method, system and device for intelligent contracts of block chains
CN107908391B (en) Optimization method and device for program call
CN112486570B (en) Glibc compatible method for CPUs of different types
CN110442392B (en) Packet isolation method and device, electronic equipment and storage medium
EP3872630B1 (en) Request processing method and apparatus, electronic device, and computer storage medium
CN108664293B (en) Application control method and device in android system
US20180181399A1 (en) Information processing device, information processing method, and storage medium
CN117056906B (en) Instruction access control method, system, storage medium and equipment
CN112395149B (en) Script behavior identification method and device, storage medium and computer equipment
CN109947407B (en) Data acquisition method and device
CN110874214B (en) Function calling method and device, electronic equipment and storage medium
CN108829502B (en) Method and device for realizing thread operation
CN114489859A (en) Script code execution method and device, storage medium and equipment
CN117311792A (en) Version number updating method, device, equipment and storage medium
CN115827140A (en) Visual large screen generation method, device, equipment and storage medium
CN117519712A (en) Application program running method, device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant