CN113760379A - Method and device for adding parameters in published program - Google Patents

Method and device for adding parameters in published program Download PDF

Info

Publication number
CN113760379A
CN113760379A CN202010428067.0A CN202010428067A CN113760379A CN 113760379 A CN113760379 A CN 113760379A CN 202010428067 A CN202010428067 A CN 202010428067A CN 113760379 A CN113760379 A CN 113760379A
Authority
CN
China
Prior art keywords
target
parameter
address
memory space
modified
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.)
Granted
Application number
CN202010428067.0A
Other languages
Chinese (zh)
Other versions
CN113760379B (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.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network 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 Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN202010428067.0A priority Critical patent/CN113760379B/en
Publication of CN113760379A publication Critical patent/CN113760379A/en
Application granted granted Critical
Publication of CN113760379B publication Critical patent/CN113760379B/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/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44557Code layout in executable memory

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to the technical field of computers, in particular to a method and a device for adding parameters in a published program, wherein the method comprises the following steps: acquiring target parameter information from the associated service program; acquiring a first address of a target function to which a target parameter belongs in a memory; reading the assembly code of the parameter to be modified from the memory according to the first address, and copying the assembly code to a code memory space; copying the parameters to be modified to a data memory space, and adding target parameters in the parameters to be modified in the data memory space; and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space. The server receives data sent by the server at any time, the target parameter information can be sent to the published client in time, the target parameter can be quickly added at a specific position of the client program according to the target parameter information, the version of the client does not need to be published, and the publishing process of the whole parameter adding function is greatly saved.

Description

Method and device for adding parameters in published program
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for adding parameters in a published program.
Background
At present, software programs developed in windows systems sometimes encounter some special urgent needs, and a parameter, which may be some data or some field, needs to be added to the released programs. For example, we want to classify the on-demand programs on the live platform, and the on-demand programs have two types, one is on-demand, and the other is a newly developed new function: the server cannot distinguish the short video functions of the pages because the two types of the short video functions belong to the on-demand programs. There is therefore a need to add a field at the client to inform the server of the short video function of whether the page is on demand or found.
For adding a parameter, the conventional scheme is to reopen a program, reissue a new program after adding the parameter, and the whole program needs to perform a series of processes such as function development, function test, integration test, function acceptance, version signature packaging and publishing, and the server also needs to apply for a large amount of bandwidth to perform version update. Therefore, the technical problem that the modification process is complicated when the program is changed slightly exists in the prior art.
Disclosure of Invention
The invention aims to provide a method and a device for adding parameters in a published program, so as to solve the problem that the modification process is complicated when the program is slightly changed in the prior art.
The embodiment of the invention provides the following scheme:
according to a first aspect of the present invention, an embodiment of the present invention provides a method for adding parameters in a published program, including:
acquiring target parameter information from the associated service program;
extracting target parameters and the data types of the target parameters from the target parameter information, and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information;
acquiring the data size of the target parameter according to the data type, and allocating a data memory space with a corresponding size to the target parameter according to the data size;
distributing a code memory space corresponding to the data memory space, and setting the attribute of the code memory space as Page _ EXECUTE _ READWRITE;
reading an assembly code of a parameter to be modified from the memory according to the first address, and copying the assembly code to the code memory space;
copying the parameters to be modified to the data memory space, and adding the target parameters to the parameters to be modified in the data memory space;
and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space.
Preferably, the copying the parameter to be modified to the data memory space, and adding the target parameter to the parameter to be modified in the data memory space includes:
extracting a second address of the parameter to be modified in the target function and a third address of the parameter to be modified in the parameter to be modified from the target parameter information;
acquiring a parameter to be modified according to the second address, and copying the parameter to be modified to the data memory space;
and positioning the third address in the parameter to be modified in the data memory space, and adding the target function at the third address.
Preferably, the obtaining a first address of an objective function to which the objective parameter belongs in a memory according to the objective parameter information includes:
extracting a module name of a target module, a relative offset address of a target function and a code length from the target parameter information, wherein the target module comprises the target function;
obtaining the initial address of the target module in the memory according to the module name;
and obtaining the first address of the target function in the memory according to the starting address, the relative offset address and the code length.
Preferably, the acquiring target parameter information from the associated service program includes:
inquiring whether a parameter modification request is sent to an associated service program when starting, and if the service program returns a confirmation message, acquiring target parameter information;
or,
and receiving a parameter modification request sent by the service program in the running process, and extracting target parameter information from the parameter modification request.
Preferably, before extracting the target parameter information from the parameter modification request, the method includes:
traversing all the working threads through a system API function CreateToolhelp32Snapshot, and calling a system API function SuspendThread to suspend the working threads;
correspondingly, after the step of modifying the assembly code in the memory into a jump instruction jumping to the code memory space, the method includes:
calling the system API function resumerthread restores the worker thread.
Preferably, after traversing all the working threads through the system API function CreateToolhelp32Snapshot and calling the system API function SuspendThread to suspend the working threads, the method includes:
judging whether a thread which is executing the target function exists in the working threads or not;
if not, executing the step of extracting the target parameter information from the parameter modification request;
and if so, recovering the working thread, setting a timer, and returning to the step of judging whether the thread executing the target function exists in the working thread after the timer is overtime.
According to a second aspect of the present invention, there is provided an apparatus for adding parameters to a published program, comprising:
the information acquisition module is used for acquiring target parameter information from the associated service program;
the positioning module is used for extracting target parameters and data types of the target parameters from the target parameter information and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information;
the first allocation module is used for obtaining the data size of the target parameter according to the data type and allocating a data memory space with a corresponding size to the target parameter according to the data size;
the second allocating module is configured to allocate a code memory space corresponding to the data memory space, and set an attribute of the code memory space to PAGE _ EXECUTE _ READWRITE;
the copying module is used for reading the assembly code of the parameter to be modified from the memory according to the first address and copying the assembly code to the code memory space;
a parameter adding module, configured to copy the parameter to be modified to the data memory space, and add the target parameter to the parameter to be modified in the data memory space;
and the jump module is used for modifying the assembly code in the memory into a jump instruction for jumping to the code memory space.
Preferably, the parameter adding module is specifically configured to extract, from the target parameter information, a second address of the parameter to be modified in the target function and a third address of the target parameter in the parameter to be modified; acquiring a parameter to be modified according to the second address, and copying the parameter to be modified to the data memory space; and positioning the third address in the parameter to be modified in the data memory space, and adding the target function at the third address.
According to a third aspect of the present invention, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the method steps of any of the first aspects of the present invention.
According to a fourth aspect of the present invention, there is provided a client comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method steps according to any one of the first aspect of the present invention when executing the program.
Compared with the prior art, the invention has the following advantages and beneficial effects:
the invention obtains the target parameter information from the associated service program; extracting target parameters and the data types of the target parameters from the target parameter information, and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information; acquiring the data size of the target parameter according to the data type, and allocating a data memory space with a corresponding size to the target parameter according to the data size; distributing a code memory space corresponding to the data memory space, and setting the attribute of the code memory space as Page _ EXECUTE _ READWRITE; reading an assembly code of a parameter to be modified from the memory according to the first address, and copying the assembly code to the code memory space; copying the parameters to be modified to the data memory space, and adding the target parameters to the parameters to be modified in the data memory space; and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space. Compared with the prior art that fields or data are added based on a client version updating mode, the method and the system can quickly add the target parameters at the specific position of the client program according to the target parameter information without releasing the client version, greatly save the release flow of the whole parameter adding function, and solve the technical problem that the modification process of the program is complicated when the program is slightly changed.
Drawings
In order to more clearly illustrate the embodiments of the present specification or the technical solutions in the prior art, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present specification, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a flowchart illustrating a method for adding parameters to a published program according to an embodiment of the invention;
FIG. 2 is a schematic diagram of an apparatus for adding parameters to a published program according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a computer-readable storage medium according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a client according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described clearly and completely with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, rather than all embodiments, and all other embodiments obtained by those skilled in the art based on the embodiments of the present invention belong to the scope of protection of the embodiments of the present invention.
First embodiment
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for adding parameters to a published program according to an embodiment of the present invention.
In this embodiment, the method for adding parameters in a published program is applied to a client, and the method includes:
step S10: and acquiring target parameter information from the associated service program.
The purpose of this step is: and acquiring target parameter information sent by the server at any time through the service program.
The execution main body of the embodiment is a client, the client program of the client is a published program, and the service program is a group of programs which are compiled for providing a service means for a user to maintain and use a computer. In order to assist the client to receive data at any time, a windows service program associated with the client is created through a system API, the service program is issued with the client program and is resident in the system, the service program is started when the windows is started, even if the user does not open the client program, the service program is started, and a network connection is created, so that the service program can receive the data of the server at any time. For example, if there is a function to add a parameter to a program that has already been released, the service program may receive data from the server and perform the parameter addition as soon as the client program is opened, so that the parameter addition can be performed before the client starts up.
Before the service program receives data from the server program, a network protocol between the service program and the server program is also designed: the server program issues a function protocol for increasing the parameters, and a plurality of the function protocols can be issued simultaneously, and each function protocol can increase the parameters. The protocol is as follows:
Struct ProtoData{
id is a globally unique number used for differentiation between statistics and subsequent functions.
Module name of ModuleName client.
The Address client needs the relative offset Address of the module where the added function resides.
CodeLen increases the code length of the function code of the function in the memory.
The data Type of the added parameter of Type only supports data of simple data Type, such as character string and integer.
Value added parameter data.
Len increased parameter data length.
No increases the data at the several parameters.
Position of the parameter whose Position increases. The several position increasing parameters are indicated.
The size of the original number of parameters of the function for which Num is increased. }
The parameters in the protocol are advanced to the general functions, so that any function of any module of a client program, any parameter of the function and any position of the any parameter can be modified, the conditions as many as possible can be greatly met, and the protocol has high universality. Based on the protocol, the service program can receive data of the server at any time and send the received data to the client as target parameter information. Accordingly, the target parameter information includes: the method comprises the following steps of obtaining a module name of a target module, a relative offset address and code length of a target function, a target parameter, a parameter type and data length of the target parameter, a second address of the parameter to be modified in the target function, a third parameter position of the target parameter in the parameter to be modified and a data size of the parameter to be modified.
In a possible implementation manner, when the service program receives a parameter modification request that the server needs to add parameters, the running state of the client includes two cases, one is that the client program is not started at this time, and the other is that the client program is executing. According to the two cases, different data receiving methods are adopted, and the step S10 includes: inquiring whether a parameter modification request is sent to an associated service program when starting, and if the service program returns a confirmation message, acquiring target parameter information; or receiving a parameter modification request sent by the service program in the running process, and extracting target parameter information from the parameter modification request. After the client program is started, firstly forbidding loading and execution of other functions, then accessing the associated service program, inquiring whether a parameter modification request is sent to the service program, if the service program returns a confirmation message, suspending the starting process of the client program, acquiring target parameter information, and executing the subsequent function of adding parameters; and if the service program returns a negative confirmation message, starting normal program execution, and loading and executing other functions of the client.
In a possible implementation, before extracting the target parameter information from the parameter modification request, the method includes: traversing all the working threads through a system API function CreateToolhelp32Snapshot, and calling a system API function SuspendThread to suspend the working threads; correspondingly, after the step of modifying the assembly code in the memory into a jump instruction jumping to the code memory space, the method includes: calling the system API function resumerthread restores the worker thread. In the execution process of the client program, if a certain parameter of a certain function is directly modified, and a certain working thread of the function may be executing, the program may be crashed, so that all working threads need to be suspended before the parameter is modified, and all working threads are recovered after the modification is completed, thereby ensuring the stability of the client program.
Further, after traversing all the working threads through the system API function CreateToolhelp32Snapshot and calling the system API function SuspendThread to suspend the working threads, the method includes: judging whether a thread which is executing the target function exists in the working threads or not; if not, executing the step of extracting the target parameter information from the parameter modification request; and if so, recovering the working thread, setting a timer, and returning to the step of judging whether the thread executing the target function exists in the working thread after the timer is overtime.
When the thread which is executing the target function does not exist in the working threads, the parameters are modified so as to prevent the client program from crashing. When judging that the thread which is executing the target function exists in the working threads, the working threads are recovered, a timer, such as a timer of 10 seconds, is set while the threads are recovered, so that the working threads are continuously executed within the timing period of the timer, after the timer is overtime, the judging step is returned, so that whether the thread which is executing the target function exists in the working threads of the client is judged, and if the thread does not exist, the working threads are executed completely, and the subsequent parameter modifying step can be executed. And setting the execution times of the judging step, for example, 5 times, and if the thread which is executing the target function still exists in the working threads after the judging step is executed for 5 times, not restoring the working threads, but restarting the client, thereby avoiding unnecessary resource consumption. When the working thread is suspended, the current call stack of each working thread needs to be acquired, so that the memory address executed by the current working thread is acquired, the memory address of each working thread is stored, the use is convenient when the working thread is suspended next time, and the thread control efficiency is improved.
In a specific implementation, whether the CurrentAddress currently executed by each working thread is in the start address and the tail address of the target function is judged, if yes, the working thread is indicated to be executing the target function, and otherwise, the working thread is indicated not to be executing the target function currently.
Step S20: and extracting target parameters and the data types of the target parameters from the target parameter information, and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information.
The purpose of this step is: and positioning the actual position of the target function so as to accurately find the target parameter in the target function.
The target function belongs to the client program, the target parameter is a parameter that needs to be added to the target function, and in order to add the target parameter to the target function, a first address of the target function in a memory must be determined first.
In a possible implementation manner, the obtaining, according to the target parameter information, a first address of an objective function to which the target parameter belongs in a memory includes: extracting a module name of a target module, a relative offset address of a target function and a code length from the target parameter information, wherein the target module comprises the target function; obtaining the initial address of the target module in the memory according to the module name; and obtaining the first address of the target function in the memory according to the starting address, the relative offset address and the code length. The address loaded to the memory at the start of each module is changed, so that a real module address needs to be obtained based on actual operation. The specific acquisition function address is as follows:
HModule getmodulehandle (modulename); and filling the module name of the target module so as to obtain the initial address of the target module in the memory. The starting address of the target function in the memory can be determined through the starting address of the target module in the memory and the relative offset address of the target function relative to the target module, so that the tail address of the target function in the memory is determined according to the starting address of the target function in the memory and the code length of the target function, and the starting address and the tail address of the target function in the memory are the first address. start _ Address equals hmodule + Address.
end_address=start_address+codelen。
Step S30: and acquiring the data size of the target parameter according to the data type, and allocating a data memory space with a corresponding size to the target parameter according to the data size.
The purpose of this step is: and allocating a data memory space with a reasonable size for the target parameters, thereby avoiding resource waste.
The data types include at least: int type, string type and bone type, wherein int type is integer, string type is character string, bone type includes True and False. For example, when the data type of the target parameter is int type, a segment of data memory space is allocated: int data ═ new int [ Num +1 ]; where Num denotes the size of the parameter to be modified and "1" in the above code denotes an increased size.
Step S40: allocating a code memory space corresponding to the data memory space, and setting the attribute of the code memory space as Page _ EXECUTE _ READWRITE
The purpose of this step is: and providing a code memory space for the target parameter, wherein the code memory space can execute assembly codes.
In order to store a target parameter and run a code corresponding to the target parameter, a code memory space is allocated to the target parameter, and when the code in the code memory space is executed, data in the data memory space is called. Since the client program is already released, the client program is composed of assembly code, and therefore, the function of adding parameters must be completed based on the assembly code. And distributing a code memory space for the target parameter through a system function VirtualAlloc, and setting the attribute of the code memory space to PAGE _ EXECUTE _ READWRITE, wherein the attribute indicates that the target memory can EXECUTE assembly codes.
The code memory space code is as follows:
BYTE pbyme ═ virtual alloc (NULL, nSize, MEM _ COMMIT, PAGE _ EXECUTE _ READWRITE), where pbyme is the starting address of the code memory space.
Step S50: and reading the assembly code of the parameter to be modified from the memory according to the first address, and copying the assembly code to the code memory space.
The purpose of this step is: and under the condition of increasing the parameters, adaptively modifying the memory address of the assembly code of the parameters to be modified.
And in order to add the target parameter to the assembly code, locating the target function in the memory according to the first address, and further locating the assembly code in the target function, so that the assembly code can be read and copied to pbyMem in the code memory space.
For windows system, the assembly code is x86 assembly code, then when the compiler compiles the program, the initial assembly code of the function is the allocation and register value storage and assignment for the stack, and the parameter of the function is in the current allocated function stack space. The specific assembly code is as follows:
push ebp first pushes the ebp register onto the stack.
mov ebp, esp then assigns the esp register to the ebp register.
sub esp, xx this stage subtracts one xx value from esp to indicate that the current function allocates a stack size of xx memory spaces for use internally by this function.
An Extended Base Pointer (EBP) register (mov eax, dword ptr [ EBP +8 ]) is a 32-bit base pointer register, in which a pointer is stored, the pointer indicates a parameter base address when storing or reading a parameter, and the EBP is generally used to obtain a function parameter, a local variable, and the like according to an address corresponding to the pointer. The [ ebp + x ] is the address pointed by the pointer after the stack bottom moves up by x bits, and the parameter address is generally determined according to a formula [ ebp +4+ No 4] specified by a computer in the assembly engine, so that the parameter can be found quickly and intelligently. Then [ ebp +8] at this time stores the value of the first parameter of the function, and [ ebp +12] stores the value … … of the second parameter, thereby determining that the parameter to be modified is the specific number of parameters. And calculating the position of the parameter to be modified in the target function through a formula [ ebp +4+ No x 4] and a No field in the target parameter information. For example, when No is equal to 1, the calculation result is [ ebp +8], which represents that the parameter to be modified is the first parameter in the objective function; when No is equal to 2, the calculation result is [ ebp +12], and the parameter to be modified is represented as a second parameter in the objective function.
Step S60: copying the parameters to be modified to the data memory space, and adding the target parameters to the parameters to be modified in the data memory space.
The purpose of this step is: target parameters are directly added to the parameters to be modified, a program does not need to be re-developed, and complexity of parameter addition is reduced.
Since the code memory space can execute the assembly code, after the assembly code is copied to the code memory space, the parameter to be modified needs to be copied to the data memory space, and the target parameter is added to the parameter to be modified in the data memory space, so that the parameter is added to the function of the issued client program.
In a possible implementation, the step S70 includes: extracting a second address of the parameter to be modified in the target function and a third address of the parameter to be modified in the parameter to be modified from the target parameter information; acquiring a parameter to be modified according to the second address, and copying the parameter to be modified to the data memory space; and positioning the third address in the parameter to be modified in the data memory space, and adding the target function at the third address.
The memory stores the client program, the client program comprises the target module, the target module comprises the target function, the target function comprises the parameter to be modified, and the parameter to be modified comprises a plurality of positions, so that the accuracy of parameter increase can be improved by gradually positioning a first address of the target function in the memory and a second address of the parameter to be modified in the target function, and finally determining a third address of the target parameter in the parameter to be modified, so that the target parameter is added to the third address.
In a possible implementation manner, the second address of the parameter to be modified in the target function and the third address of the parameter to be modified in the parameter to be modified are extracted from the target parameter information
Step S70: and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space.
The purpose of this step is: maintaining a normal execution order of the objective function.
The target function in the memory comprises a plurality of parameters, the parameters have a given execution sequence, in order to ensure that the target function is normally executed after the parameters are added, the assembly code in the memory is modified into a jump instruction which jumps to the code memory space, and the modified code is as follows:
BYTE byPadCode[]={
0xe9, xx, xx, xx wherein xx is offset data, the value of which is calculated by the equation: (int) ((byPadCode +1) ═ int) pbyme- (start _ address +3+ 5); }. The jump instruction starts to be executed after the two instructions push ebp and mov ebp, esp of the assembly code. "3" in the above equation indicates the memory size of the two instructions, and "5" in the above equation indicates the memory size of the jump instruction itself. And in the process of executing the target function according to a given execution sequence, when the jump instruction is executed, jumping to the code memory space to execute the assembly code and the target parameter, and returning to the next parameter in the target function after the execution is finished to continue the execution.
The technical scheme provided in the embodiment of the application at least has the following technical effects or advantages:
the embodiment acquires target parameter information from the associated service program through the client; extracting target parameters and the data types of the target parameters from the target parameter information, and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information; acquiring the data size of the target parameter according to the data type, and allocating a data memory space with a corresponding size to the target parameter according to the data size; distributing a code memory space corresponding to the data memory space, and setting the attribute of the code memory space as Page _ EXECUTE _ READWRITE; reading an assembly code of a parameter to be modified from the memory according to the first address, and copying the assembly code to the code memory space; copying the parameters to be modified to the data memory space, and adding the target parameters to the parameters to be modified in the data memory space; and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space. Compared with the prior art that fields or data are added based on a client version updating mode, the method and the system can quickly add the target parameters at the specific position of the client program according to the target parameter information without releasing the client version, greatly save the release flow of the whole parameter adding function, and solve the technical problem that the modification process of the program is complicated when the program is slightly changed.
Second embodiment
Based on the same inventive concept, as shown in fig. 2, an embodiment of the present invention further provides an apparatus for adding parameters in a published program, including:
an information obtaining module 10, configured to obtain target parameter information from an associated service program;
a positioning module 20, configured to extract a target parameter and a data type of the target parameter from the target parameter information, and obtain, according to the target parameter information, a first address of a target function to which the target parameter belongs in an internal memory;
the first allocation module 30 is configured to obtain the data size of the target parameter according to the data type, and allocate a data memory space of a corresponding size to the target parameter according to the data size;
a second allocating module 40, configured to allocate a code memory space corresponding to the data memory space, and set an attribute of the code memory space to PAGE _ EXECUTE _ READWRITE;
the copying module 50 is configured to read an assembly code of a parameter to be modified from the memory according to the first address, and copy the assembly code to the code memory space;
a parameter adding module 60, configured to copy the parameter to be modified to the data memory space, and add the target parameter to the parameter to be modified in the data memory space;
and a jump module 70, configured to modify the assembly code in the memory into a jump instruction to jump to the code memory space.
In a possible implementation manner, the parameter adding module 60 is specifically configured to extract, from the target parameter information, a second address of the parameter to be modified in the target function and a third address of the target parameter in the parameter to be modified; acquiring a parameter to be modified according to the second address, and copying the parameter to be modified to the data memory space; and positioning the third address in the parameter to be modified in the data memory space, and adding the target function at the third address.
In a possible implementation, the locating module 20 is specifically configured to extract, from the target parameter information, a module name of a target module, a relative offset address of a target function, and a code length, where the target module includes the target function; obtaining the initial address of the target module in the memory according to the module name; and obtaining the first address of the target function in the memory according to the starting address, the relative offset address and the code length.
In a possible implementation manner, the information obtaining module 10 is specifically configured to query, when starting, a related service program whether a parameter modification request is sent, and if the service program returns a confirmation message, obtain target parameter information; or receiving a parameter modification request sent by the service program in the running process, and extracting target parameter information from the parameter modification request.
In a possible embodiment, the apparatus further comprises:
the thread control module is used for traversing all the working threads through a system API function CreateToolhelp32Snapshot and calling a system API function SuspendThread to suspend the working threads;
the thread control module is also used for calling a system API function ResumeThread to recover the working thread.
In a possible implementation manner, the thread control module is further configured to determine whether a thread that is executing the target function exists in the working threads; if not, executing the step of extracting the target parameter information from the parameter modification request; and if so, recovering the working thread, setting a timer, and returning to the step of judging whether the thread executing the target function exists in the working thread after the timer is overtime.
Compared with the prior art, the embodiment of the invention has the following advantages and beneficial effects:
the embodiment acquires target parameter information from the associated service program; extracting target parameters and the data types of the target parameters from the target parameter information, and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information; acquiring the data size of the target parameter according to the data type, and allocating a data memory space with a corresponding size to the target parameter according to the data size; distributing a code memory space corresponding to the data memory space, and setting the attribute of the code memory space as Page _ EXECUTE _ READWRITE; reading an assembly code of a parameter to be modified from the memory according to the first address, and copying the assembly code to the code memory space; copying the parameters to be modified to the data memory space, and adding the target parameters to the parameters to be modified in the data memory space; and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space. The method and the system have the advantages that the data sent by the server at any time are received through the associated service program, so that the target parameter information can be sent to the published client in time, and compared with the prior art in which fields or data are added based on a client version updating mode, the method and the system can quickly add the target parameters at the specific position of the client program according to the target parameter information without publishing the client version, greatly save the publishing process of the whole parameter adding function, and solve the technical problem that the modifying process of the program is complicated when the program is slightly modified.
Third embodiment
Based on the same inventive concept, as shown in fig. 3, an embodiment of the present invention further provides a computer-readable storage medium 300, on which a computer program 311 is stored, and when the program 311 is executed by a processor, the following steps are implemented:
acquiring target parameter information from the associated service program; extracting target parameters and the data types of the target parameters from the target parameter information, and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information; acquiring the data size of the target parameter according to the data type, and allocating a data memory space with a corresponding size to the target parameter according to the data size; distributing a code memory space corresponding to the data memory space, and setting the attribute of the code memory space as Page _ EXECUTE _ READWRITE; reading an assembly code of a parameter to be modified from the memory according to the first address, and copying the assembly code to the code memory space; copying the parameters to be modified to the data memory space, and adding the target parameters to the parameters to be modified in the data memory space; and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space.
In a specific implementation, the computer program 311 may implement the method steps of any one of the first implementation embodiments described above when executed by a processor.
Fourth embodiment
Based on the same inventive concept, as shown in fig. 4, an embodiment of the present invention further provides a client 400, which includes a memory 410, a processor 420, and a computer program 411 stored in the memory 410 and running on the processor 420, where the processor 420 executes the computer program 411 to implement the following steps:
acquiring target parameter information from the associated service program; extracting target parameters and the data types of the target parameters from the target parameter information, and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information; acquiring the data size of the target parameter according to the data type, and allocating a data memory space with a corresponding size to the target parameter according to the data size; distributing a code memory space corresponding to the data memory space, and setting the attribute of the code memory space as Page _ EXECUTE _ READWRITE; reading an assembly code of a parameter to be modified from the memory according to the first address, and copying the assembly code to the code memory space; copying the parameters to be modified to the data memory space, and adding the target parameters to the parameters to be modified in the data memory space; and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space.
In a specific implementation, the method steps of any one of the above-described first implementation embodiments may be implemented when the processor 420 executes the computer program 411.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (modules, systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.

Claims (10)

1. A method for adding parameters in a published program, which is applied to a client, is characterized in that the method comprises the following steps:
acquiring target parameter information from the associated service program;
extracting target parameters and the data types of the target parameters from the target parameter information, and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information;
acquiring the data size of the target parameter according to the data type, and allocating a data memory space with a corresponding size to the target parameter according to the data size;
distributing a code memory space corresponding to the data memory space, and setting the attribute of the code memory space as Page _ EXECUTE _ READWRITE;
reading an assembly code of a parameter to be modified from the memory according to the first address, and copying the assembly code to the code memory space;
copying the parameters to be modified to the data memory space, and adding the target parameters to the parameters to be modified in the data memory space;
and modifying the assembly code in the memory into a jump instruction which jumps to the code memory space.
2. The method according to claim 1, wherein the copying the parameter to be modified to the dataram space and adding the target parameter to the parameter to be modified in the dataram space comprises:
extracting a second address of the parameter to be modified in the target function and a third address of the parameter to be modified in the parameter to be modified from the target parameter information;
acquiring a parameter to be modified according to the second address, and copying the parameter to be modified to the data memory space;
and positioning the third address in the parameter to be modified in the data memory space, and adding the target function at the third address.
3. The method according to claim 1, wherein the obtaining a first address of an objective function to which the objective parameter belongs in a memory according to the objective parameter information comprises:
extracting a module name of a target module, a relative offset address of a target function and a code length from the target parameter information, wherein the target module comprises the target function;
obtaining the initial address of the target module in the memory according to the module name;
and obtaining the first address of the target function in the memory according to the starting address, the relative offset address and the code length.
4. The method of claim 1, wherein obtaining target parameter information from an associated service comprises:
inquiring whether a parameter modification request is sent to an associated service program when starting, and if the service program returns a confirmation message, acquiring target parameter information;
or,
and receiving a parameter modification request sent by the service program in the running process, and extracting target parameter information from the parameter modification request.
5. The method of claim 4, wherein before extracting the target parameter information from the parameter modification request, the method comprises:
traversing all the working threads through a system API function CreateToolhelp32Snapshot, and calling a system API function SuspendThread to suspend the working threads;
correspondingly, after the step of modifying the assembly code in the memory into a jump instruction jumping to the code memory space, the method includes:
calling the system API function resumerthread restores the worker thread.
6. The method of claim 5, wherein after traversing all the working threads through the system API function CreateToolhelp32Snapshot and invoking the system API function SuspendThread to pause the working threads, the method comprises:
judging whether a thread which is executing the target function exists in the working threads or not;
if not, executing the step of extracting the target parameter information from the parameter modification request;
and if so, recovering the working thread, setting a timer, and returning to the step of judging whether the thread executing the target function exists in the working thread after the timer is overtime.
7. An apparatus for adding parameters to a published program, comprising:
the information acquisition module is used for acquiring target parameter information from the associated service program;
the positioning module is used for extracting target parameters and data types of the target parameters from the target parameter information and acquiring a first address of a target function to which the target parameters belong in a memory according to the target parameter information;
the first allocation module is used for obtaining the data size of the target parameter according to the data type and allocating a data memory space with a corresponding size to the target parameter according to the data size;
the second allocating module is configured to allocate a code memory space corresponding to the data memory space, and set an attribute of the code memory space to PAGE _ EXECUTE _ READWRITE;
the copying module is used for reading the assembly code of the parameter to be modified from the memory according to the first address and copying the assembly code to the code memory space;
a parameter adding module, configured to copy the parameter to be modified to the data memory space, and add the target parameter to the parameter to be modified in the data memory space;
and the jump module is used for modifying the assembly code in the memory into a jump instruction for jumping to the code memory space.
8. The apparatus according to claim 7, wherein the parameter adding module is specifically configured to extract, from the target parameter information, a second address of the parameter to be modified in the target function and a third address of the target parameter in the parameter to be modified; acquiring a parameter to be modified according to the second address, and copying the parameter to be modified to the data memory space; and positioning the third address in the parameter to be modified in the data memory space, and adding the target function at the third address.
9. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method steps of any one of claims 1 to 6.
10. A client comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method steps of any of claims 1-6 when executing the program.
CN202010428067.0A 2020-05-20 2020-05-20 Method and device for adding parameters in published program Active CN113760379B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010428067.0A CN113760379B (en) 2020-05-20 2020-05-20 Method and device for adding parameters in published program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010428067.0A CN113760379B (en) 2020-05-20 2020-05-20 Method and device for adding parameters in published program

Publications (2)

Publication Number Publication Date
CN113760379A true CN113760379A (en) 2021-12-07
CN113760379B CN113760379B (en) 2024-08-02

Family

ID=78782235

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010428067.0A Active CN113760379B (en) 2020-05-20 2020-05-20 Method and device for adding parameters in published program

Country Status (1)

Country Link
CN (1) CN113760379B (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060168431A1 (en) * 1998-10-14 2006-07-27 Peter Warnes Method and apparatus for jump delay slot control in a pipelined processor
CN103049302A (en) * 2012-12-28 2013-04-17 中国科学院声学研究所 Method for generating optimized strcpy standard library function assembly codes by program
CN103793209A (en) * 2012-10-26 2014-05-14 珠海市君天电子科技有限公司 Method and system for modifying Android program execution flow
US9164754B1 (en) * 2013-12-18 2015-10-20 Amazon Technologies, Inc. Runtime patching of native-code programs
CN105739961A (en) * 2014-12-12 2016-07-06 中兴通讯股份有限公司 Starting method and device of embedded system
US20170329621A1 (en) * 2011-02-08 2017-11-16 Pegasystems Inc. Code injection and code interception in an operating system with multiple subsystem environments
CN109284104A (en) * 2018-09-28 2019-01-29 北京航空航天大学青岛研究院 Method based on webpage assembler language control page jump
CN110673899A (en) * 2018-07-03 2020-01-10 武汉斗鱼网络科技有限公司 Program processing method and related equipment

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060168431A1 (en) * 1998-10-14 2006-07-27 Peter Warnes Method and apparatus for jump delay slot control in a pipelined processor
US20170329621A1 (en) * 2011-02-08 2017-11-16 Pegasystems Inc. Code injection and code interception in an operating system with multiple subsystem environments
CN103793209A (en) * 2012-10-26 2014-05-14 珠海市君天电子科技有限公司 Method and system for modifying Android program execution flow
CN103049302A (en) * 2012-12-28 2013-04-17 中国科学院声学研究所 Method for generating optimized strcpy standard library function assembly codes by program
US9164754B1 (en) * 2013-12-18 2015-10-20 Amazon Technologies, Inc. Runtime patching of native-code programs
CN105739961A (en) * 2014-12-12 2016-07-06 中兴通讯股份有限公司 Starting method and device of embedded system
CN110673899A (en) * 2018-07-03 2020-01-10 武汉斗鱼网络科技有限公司 Program processing method and related equipment
CN109284104A (en) * 2018-09-28 2019-01-29 北京航空航天大学青岛研究院 Method based on webpage assembler language control page jump

Also Published As

Publication number Publication date
CN113760379B (en) 2024-08-02

Similar Documents

Publication Publication Date Title
US11620215B2 (en) Multi-threaded pause-less replicating garbage collection
CN112015491B (en) Method, device and computer storage medium for realizing function jump
CN110377580B (en) Data migration method, device and equipment
CN110247984B (en) Service processing method, device and storage medium
EP3198452B1 (en) On-demand loading of dynamic scripting language code for reduced memory usage
US20200310963A1 (en) Real-time replicating garbage collection
CN112219196B (en) Method and apparatus for representing active frames for non-suspended garbage collection
US9734620B2 (en) Apparatus and method for graphics state management
CN110347407A (en) A kind of method, apparatus, computer equipment and medium obtaining EMS memory occupation amount
CN112487092B (en) Intelligent contract calling method and device based on blockchain
CN113190282A (en) Android operating environment construction method and device
CN106776018B (en) Parallel processing method and equipment for master node and slave node of distributed system
CN109558121B (en) Interface driver development method, device, equipment and storage medium
CN111045698A (en) Redundant picture deleting method and device, electronic equipment and storage medium
WO2024119930A1 (en) Scheduling method and apparatus, and computer device and storage medium
CN113760379B (en) Method and device for adding parameters in published program
CN112631994A (en) Data migration method and system
CN109343953B (en) Memory management method and device and electronic equipment
CN115033337A (en) Virtual machine memory migration method, device, equipment and storage medium
CN114625572B (en) Reverse debugging memory backup method, electronic device and medium
WO2023138453A1 (en) Container loading method and apparatus
CN111352703B (en) Data processing method and device, electronic equipment and storage medium
CN107632934B (en) Function copying method and device in C-sharp
CN118051319A (en) Resource allocation method, device, equipment, computer storage medium and vehicle
CN117742725A (en) Code compiling method, electronic equipment and computer readable 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