CN113590091A - Data processing method and device, electronic equipment and storage medium - Google Patents

Data processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113590091A
CN113590091A CN202110745564.8A CN202110745564A CN113590091A CN 113590091 A CN113590091 A CN 113590091A CN 202110745564 A CN202110745564 A CN 202110745564A CN 113590091 A CN113590091 A CN 113590091A
Authority
CN
China
Prior art keywords
function
address
base class
subclass
class
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.)
Pending
Application number
CN202110745564.8A
Other languages
Chinese (zh)
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.)
Wuba Co Ltd
Original Assignee
Wuba 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 Wuba Co Ltd filed Critical Wuba Co Ltd
Priority to CN202110745564.8A priority Critical patent/CN113590091A/en
Publication of CN113590091A publication Critical patent/CN113590091A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces

Landscapes

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

Abstract

The invention provides a data processing method, a data processing device, electronic equipment and a storage medium. Acquiring a rewrite function table of a subclass in an executable file of an application program, wherein the subclass inherits a base class in the executable file, and the rewrite function table comprises a function address of an original function needing to be replaced in the base class, a class name of the base class and a function address of a target function for replacing the original function. And determining a virtual function table of the base class inherited by the subclass, wherein the virtual function table comprises function addresses of functions in the base class. And searching the function address of the original function in the virtual function table of the base class. And replacing the function address of the original function in the virtual function table of the base class by using the function address of the target function. Therefore, the function address of the target function is prevented from being used for replacing the function address which is not replaced in the virtual function table, the situation of replacement error is avoided, the situation that the wrong function is called when the application program calls the function after the situation occurs is avoided, and the running error of the application program can be avoided.

Description

Data processing method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a data processing method and apparatus, an electronic device, and a storage medium.
Background
An application includes a plurality of functions, and sometimes, for practical needs, it may be necessary to replace a certain function in the application with another function. In this case, the function address of the certain function in the virtual function table of the application program may be modified to the function address of the other function, so that when the application program calls the function based on the virtual function table, the function address of the other function may be obtained and called to the other function according to the function address of the other function.
The function address of the function in the virtual function table is not indexed by the function name of the function, but is indexed by the position sequence of the function address of the function in the virtual function table. For example, the virtual function table may be understood as an array, the array includes function addresses of a plurality of functions, the function addresses of the functions have respective position orders in the array, and the function addresses of the functions in the virtual function table may be indexed according to the position orders. The order of the positions of the function addresses of the functions in the virtual function table is adapted to the order of the occurrence of the function names of the functions in the application program.
In one example, it is assumed that the function address of the original function with the position order of N in the virtual function table is replaced by default with the function address of the target function. However, sometimes an application may be updated, for example, a new function is inserted into the application, and if the function name of the new function appears in the application in a sequence before the original function, the sequence of the function name of the original function appearing in the application is changed to N +1, so that the position sequence of the function address of the original function in the virtual function table is changed to N + 1.
In this way, the function name of the function whose appearance order is N in the application program becomes the function name of another function, and the function address whose position order is N in the virtual function table becomes the function address of the other function.
After the updated application program runs, the function address of the target function is still used to replace the function address with the position sequence of N in the virtual function table by default, that is, the function address of the other function is replaced, and the function address of the original function with the position sequence of N +1 is not replaced, that is, a replacement error condition occurs.
Therefore, function addresses of other functions cannot be obtained in the virtual function table subsequently when the other functions need to be called, and further the other functions cannot be called.
Disclosure of Invention
The application discloses a data processing method, a data processing device, electronic equipment and a storage medium.
In a first aspect, the present application shows a data processing method, comprising:
creating a subclass for inheriting a base class in a development environment of an application, wherein the base class is a class developed in the development environment;
setting a class name of the base class, a function name of an original function needing to be replaced in the base class and a function address of a target function for replacing the original function in the subclass;
in the process of generating an executable file of the application program according to the source code of the application program developed in the development environment, acquiring a function address of the primitive function according to the function name of the primitive function;
generating a rewrite function table for the subclass in the executable file, the rewrite function table including a function address of the primitive function, a class name of the base class, and a function address of the target function.
In a second aspect, the present application shows a data processing method, comprising:
acquiring a rewrite function table of a subclass in an executable file of an application program, wherein the subclass inherits a base class in the executable file, and the rewrite function table comprises a function address of a primary function to be replaced in the base class, a class name of the base class and a function address of a target function for replacing the primary function; wherein the rewrite function table is generated from a class name of the base class, a function name of the primitive function, and a function address of the target function set in the subclass in a development environment of the application program; the function address of the original function is obtained according to the function name of the original function; the subclass is used to inherit the base class;
acquiring a virtual function table of the base class according to the class name of the base class, wherein the virtual function table comprises function addresses of functions in the base class;
searching a function address of the original function in the virtual function table;
and replacing the function address of the original function in the virtual function table by using the function address of the target function.
In an optional implementation manner, the obtaining a table of rewrite functions of subclasses in an executable file of an application includes:
acquiring the memory address of the subclass in the executable file;
acquiring the offset of the rewriting function table of the subclass in the memory address;
and acquiring the rewriting function table according to the offset.
In an optional implementation manner, the obtaining an offset of the rewrite function table of the child class in the memory address includes:
obtaining the value of a specific flag bit in the subclass;
determining the structure of the subclass according to the value of the specific zone bit;
and determining the offset according to the structural body of the subclass.
In a third aspect, the present application shows a data processing apparatus comprising:
the system comprises a creating module, a determining module and a judging module, wherein the creating module is used for creating a subclass used for inheriting a base class in a development environment of an application program, and the base class is a class developed in the development environment;
a setting module, configured to set, in the subclass, a class name of the base class, a function name of an original function that needs to be replaced in the base class, and a function address of a target function that is used to replace the original function;
the first acquisition module is used for acquiring a function address of the primitive function according to a function name of the primitive function in the process of generating an executable file of the application program according to a source code of the application program developed in the development environment;
a generating module, configured to generate a rewrite function table of the subclass in the executable file, where the rewrite function table includes a function address of the primitive function, a class name of the base class, and a function address of the target function.
In a fourth aspect, the present application shows a data processing apparatus comprising:
a second obtaining module, configured to obtain a rewrite function table of a subclass in an executable file of an application program, where the subclass inherits a base class in the executable file, and the rewrite function table includes a function address of an original function to be replaced in the base class, a class name of the base class, and a function address of a target function used to replace the original function; wherein the rewrite function table is generated from a class name of the base class, a function name of the primitive function, and a function address of the target function set in the subclass in a development environment of the application program; the function address of the original function is obtained according to the function name of the original function; the subclass is used to inherit the base class;
a third obtaining module, configured to obtain a virtual function table of the base class according to the class name of the base class, where the virtual function table includes a function address of a function in the base class;
the searching module is used for searching the function address of the original function in the virtual function table;
a replacing module, configured to replace the function address of the primitive function in the virtual function table with the function address of the target function.
In an optional implementation manner, the second obtaining module includes:
a first obtaining unit, configured to obtain a memory address of the subclass in the executable file;
a second obtaining unit, configured to obtain an offset of the rewrite function table of the subclass in the memory address;
and the third acquisition unit is used for acquiring the rewriting function table according to the offset.
In an optional implementation manner, the second obtaining unit includes:
an obtaining subunit, configured to obtain a value of a specific flag bit in the subclass;
a first determining subunit, configured to determine a structure of the subclass according to a value of the specific flag bit;
and a second determining subunit, configured to determine the offset according to the structure of the subclass.
In a fifth aspect, the present application illustrates an electronic device comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to perform the data processing method of the first aspect.
In a sixth aspect, the present application shows a non-transitory computer readable storage medium having instructions which, when executed by a processor of an electronic device, enable the electronic device to perform the data processing method of the first aspect.
In a seventh aspect, the present application shows a computer program product, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the data processing method according to the first aspect.
In an eighth aspect, the present application illustrates an electronic device comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to perform the data processing method according to the second aspect.
In a ninth aspect, the present application shows a non-transitory computer readable storage medium having instructions which, when executed by a processor of an electronic device, enable the electronic device to perform the data processing method of the second aspect.
In a tenth aspect, the present application shows a computer program product, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the data processing method according to the second aspect.
The technical scheme provided by the application can comprise the following beneficial effects:
in the present application, in the process of developing an application, a subclass for inheriting a base class is created in a development environment of the application, the base class being a class developed in the development environment. The class name of the base class, the function name of the primitive function to be replaced in the base class, and the function address of the target function for replacing the primitive function are set in the subclass. In the process of generating an executable file of an application program according to source codes of the application program developed in a development environment, a function address of a primitive function is obtained according to a function name of the primitive function. And generating a rewriting function table of the subclass in the executable file, wherein the rewriting function table of the subclass comprises a function address of the original function, a class name of the base class and a function address of the target function.
By the method and the device, the rewriting function table of the subclass in the executable file of the application program can be obtained later when the hook primitive function is supported, the virtual function table of the base class inherited by the subclass is determined, and the virtual function table comprises the function address of the function in the base class. And searching the function address of the original function in the virtual function table of the base class. And replacing the function address of the original function in the virtual function table of the base class by using the function address of the target function.
By the method, the function address of the target function can be bound with the function address of the original function to be replaced, when the function address of the original function in the virtual function table in the base class needs to be replaced by the function address of the target function, the function address of the original function can be searched in the virtual function table without the occurrence sequence of the function name of the original function in the base class, but the function address of the original function can be directly searched in the virtual function table according to the function address of the original function, so that the function address searched in the virtual function table of the base class is certainly the function address of the original function, the function address of the target function can be used for replacing the function address of the original function by the function address of the target function in the virtual function table, and the function address which is not to be replaced in the virtual function table by the function address of the target function is avoided to be used for replacing the function address which is not to be replaced in the virtual function table, therefore, the situation of replacement errors is avoided, the situation that the wrong function is called when the application program calls the function later is avoided, and the running errors of the application program can be avoided.
Drawings
Fig. 1 is a flow chart illustrating steps of a data processing method according to the present application.
Fig. 2 is a flow chart illustrating steps of a data processing method according to the present application.
Fig. 3 is a block diagram of a data processing apparatus according to the present application.
Fig. 4 is a block diagram of a data processing apparatus according to the present application.
Fig. 5 is a block diagram of an electronic device shown in the present application.
Fig. 6 is a block diagram of an electronic device shown in the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a flowchart illustrating steps of a data processing method according to the present application is shown, and the method is applied to an electronic device, and specifically may include the following steps:
in step S101, a subclass for inheriting a base class, which is a class developed in the development environment, is created in the development environment of the application.
A developer may launch a development environment in an electronic device and develop source code for an application in the development environment.
In one embodiment, a portion of source code for an application has been developed in a development environment, the developed source code including at least a base class, which may include at least one function therein.
In the present application, there may be a case where it is necessary to call another function instead of calling a function in the base class when the base class is called later, and thus, it is necessary to hook the function in the base class, for example, replace the function with the another function, and it is necessary not to modify the code of the base class.
In this case, in the development phase, the developer can input, in the development environment of the application, a creation request for creating, in the development environment of the application, a subclass for inheriting a base class that is one of developed classes in the development environment. The electronic device can receive the creation request and then create a subclass for the inheritance base class in the development environment of the application according to the creation request.
In step S102, the class name of the base class, the function name of the primitive function that needs to be replaced in the base class, and the function address of the target function for replacing the primitive function are set in the subclass.
In the application, since a function in the base class is not called but another function is called when the base class is called after the base class is called, after a developer controls the electronic device to create a subclass for inheriting the base class in a development environment of an application program, a class name of the base class, a function name of an original function to be replaced in the base class, and a function address of a target function for replacing the original function can be set in the subclass in the development environment.
The electronic device receives a class name of the base class, a function name of the primitive function, and a function address of the target function set in the subclass.
The primitive function may be one of the functions included in the base class, or the like, and of course, the primitive function may also be two or more of the functions included in the base class.
In step S103, in the process of generating an executable file of an application program from source code of the application program that has been developed in the development environment, a function address of the primitive function is acquired from a function name of the primitive function.
The source code of the application program developed in the development environment includes at least a base class and a subclass of an inheritance base class, and also includes a class name of the base class, a function name of a primitive function, a function address of a target function, and the like set in the subclass.
In the application, after a developer writes source codes of an application program in a development environment, the developer may input a compilation request for compiling the source codes of the application program developed in the development environment into an electronic device, and the electronic device may receive the compilation request and compile the source codes of the application program developed in the development environment according to the compilation request to obtain an executable file of the application program.
Among them, the subclass in the development environment has a first character string or the like for indicating an inheritance relationship between the subclass and the base class, and also has a second character string or the like for indicating a function address for replacing a primitive function corresponding to a function name of a primitive function in the base class with a function address of a target function.
Therefore, in the process that the electronic device compiles the source code of the application program developed in the development environment, for the subclass, the electronic device can recognize a first character string, a second character string and the like in the subclass, and further can determine that the subclass and the base class have an inheritance relationship according to the first character string, and can determine that the function address of the target function needs to be used to replace the function address of the original function in the base class according to the second character string.
In the case that the above two conditions are satisfied, in the process of compiling the code in the development environment, for the subclass, a rewriting function table of the subclass is generated, for example, the function address of the original function may be looked up in the virtual function table according to the function name of the original function, for example, the order in which the original function appears in all functions in the base class may be determined according to the function name of the original function, and then the function address in the order may be looked up in the virtual function table of the base class and used as the function address of the original function, and then step S104 is executed.
In step S104, a rewrite function table of the subclass is generated in the executable file, the rewrite function table including a function address of the original function, a class name of the base class, and a function address of the target function.
In this way, the executable file has the rewriting function table of the subclass, so that when the function in the base class needs to be called later, when the function is called based on the storage address of the function in the virtual function table of the base class, the original function is not called according to the function address of the original function, but the target function is called according to the function address of the target function. Thereby realizing the purpose of using the hook primitive function of the target function.
The specific calling method can be referred to the embodiment shown in fig. 2, and is not described in detail here.
In the present application, in the process of developing an application, a subclass for inheriting a base class is created in a development environment of the application, the base class being a class developed in the development environment. The class name of the base class, the function name of the primitive function to be replaced in the base class, and the function address of the target function for replacing the primitive function are set in the subclass. In the process of generating an executable file of an application program according to source codes of the application program developed in a development environment, a function address of a primitive function is obtained according to a function name of the primitive function. And generating a rewriting function table of the subclass in the executable file, wherein the rewriting function table of the subclass comprises a function address of the original function, a class name of the base class and a function address of the target function.
By the method and the device, the rewriting function table of the subclass in the executable file of the application program can be obtained later when the hook primitive function is supported, the virtual function table of the base class inherited by the subclass is determined, and the virtual function table comprises the function address of the function in the base class. And searching the function address of the original function in the virtual function table of the base class. And replacing the function address of the original function in the virtual function table of the base class by using the function address of the target function.
By the method, the function address of the target function can be bound with the function address of the original function to be replaced, when the function address of the original function in the virtual function table in the base class needs to be replaced by the function address of the target function, the function address of the original function can be searched in the virtual function table without the occurrence sequence of the function name of the original function in the base class, but the function address of the original function can be directly searched in the virtual function table according to the function address of the original function, so that the function address searched in the virtual function table of the base class is certainly the function address of the original function, the function address of the target function can be used for replacing the function address of the original function by the function address of the target function in the virtual function table, and the function address which is not to be replaced in the virtual function table by the function address of the target function is avoided to be used for replacing the function address which is not to be replaced in the virtual function table, therefore, the situation of replacement errors is avoided, the situation that the wrong function is called when the application program calls the function later is avoided, and the running errors of the application program can be avoided.
Referring to fig. 2, a flowchart illustrating steps of a data processing method according to the present application is shown, and the method is applied to an electronic device, and specifically may include the following steps:
in step S201, a rewrite function table of a subclass in an executable file of an application program is obtained, where the subclass inherits a base class in the executable file, and the rewrite function table includes a function address of an original function to be replaced in the base class, a class name of the base class, and a function address of a target function for replacing the original function.
The rewriting function table is generated according to a class name of a base class set in a subclass in a development environment of the application program, a function name of a primitive function and a function address of a target function; the function address of the original function is obtained according to the function name of the original function; subclasses are used to inherit the base class.
In this application, after the executable file is run in the electronic device, the electronic device may initialize each class of the executable file, and when initializing the subclasses, may obtain the rewritten function table in the subclasses, and the specific obtaining manner may be as follows.
Wherein, this step can be realized through the following process, including:
2011. and acquiring the memory address of the subclass in the executable file.
In this application, the electronic device runs the executable file by loading the executable file in the memory of the electronic device, so that the executable file has a memory address in the memory of the electronic device.
In this step, the memory address of the subclass in the executable file may be obtained in a class. Of course, the memory address of the subclass in the executable file may also be obtained in other manners, and the specific obtaining manner is not limited in the present application.
2012. And acquiring the offset of the rewrite function table of the subclass in the memory address of the subclass.
This step can be realized by the following process, including:
11) and acquiring the value of the specific flag bit in the subclass.
In the present application, there are many contents in the subclasses, such as Flag, Parent, Name, access function, and rewrite function table override list. In different cases, the contents of the subclasses may be different, that is, the structures of the subclasses are different. What contents a subclass has can be distinguished by the value of the specific Flag, that is, the structure of the subclass can be distinguished by the value of the specific Flag. That is, different values of a particular flag bit correspond to different structures of a subclass.
12) And determining the structure of the subclass according to the value of the specific flag bit.
13) And determining the offset of the rewrite function table in the memory address according to the structure of the subclass.
In the present application, a subclass has a memory address in a memory, and an offset of a rewrite function table in the subclass in the memory address of the subclass can be understood as a distance from a start address of the rewrite function table in the memory to a head address of the memory address of the subclass.
After the structure of the subclass is determined, what contents are included in the subclass in order is determined, and the size of the space occupied by each content in the subclass is also determined.
After the structure of the subclass is determined, the position sequence of the rewrite function table in the subclass can be determined, and what contents are positioned before the rewrite function table in the subclass and the space size occupied by the contents can be determined, so that the offset of the rewrite function table in the structure of the subclass can be determined according to what contents are positioned before the rewrite function table in the subclass and the space size occupied by the contents, and can be used as the offset in the memory address.
2013. And acquiring the rewrite function table of the subclass according to the offset.
In the present application, the structure of the rewrite function table is set in advance and is fixed, for example, the order among the function address of the primitive function, the class name of the base class, and the function address of the target function in the rewrite function table is also set in advance and is fixed, and the size of the space (for example, bytes, etc.) occupied by each of the function address of the primitive function, the class name of the base class, and the function address of the target function in the rewrite function table is also set in advance and is fixed.
Based on this, the electronic device can analyze the function address of the primitive function, the class name of the base class, and the function address of the target function in the rewrite function table according to the rule set in advance.
For example, three adjacent contents of a specific space size are sequentially read from the offset, and the function address of the primitive function, the class name of the base class, and the function address of the target function are respectively analyzed in a specific order.
In step S202, a virtual function table of the base class inherited by the subclass is obtained according to the class name of the base class, and the virtual function table includes function addresses of functions in the base class.
In the application, a base class with an integrated subclass can be searched in an executable file according to a class name of the base class in the rewrite function table (a specific search mode may refer to a currently existing mode, which is not described in detail here), and then a virtual function table of the base class is searched in the base class.
In step S203, the function address of the original function is looked up in the virtual function table of the base class.
In this application, the virtual function table of the base class stores function addresses of each function in the base class, one of the function addresses is a function address of an original function, the function address of the original function can be searched in the virtual function table of the base class, and then step S204 is executed.
In step S204, the function address of the original function in the virtual function table of the base class is replaced with the function address of the target function.
In this way, the function address of the original function is not present in the virtual function table of the base class, but the function address of the target function is present, and the order of the positions of the function address of the original function in the virtual function table of the base class before replacement is the same as the order of the positions of the function address of the target function in the virtual function table of the base class after replacement.
Therefore, when a function in the base class needs to be called later, when the function is called based on the storage address of the function in the virtual function table of the base class, the original function is not called according to the function address of the original function, but the target function is called according to the function address of the target function, and the purpose of using the hook original function of the target function is achieved.
In the application, a rewrite function table of a subclass in an executable file of an application program is obtained, the subclass inherits a base class in the executable file, and the rewrite function table comprises a function address of an original function needing to be replaced in the base class, a class name of the base class and a function address of a target function for replacing the original function. And determining a virtual function table of the base class inherited by the subclass, wherein the virtual function table comprises function addresses of functions in the base class. And searching the function address of the original function in the virtual function table of the base class. And replacing the function address of the original function in the virtual function table of the base class by using the function address of the target function.
By the method, the function address of the target function can be bound with the function address of the original function to be replaced, when the function address of the original function in the virtual function table in the base class needs to be replaced by the function address of the target function, the function address of the original function can be searched in the virtual function table without the occurrence sequence of the function name of the original function in the base class, but the function address of the original function can be directly searched in the virtual function table according to the function address of the original function, so that the function address searched in the virtual function table of the base class is certainly the function address of the original function, the function address of the target function can be used for replacing the function address of the original function by the function address of the target function in the virtual function table, and the function address which is not to be replaced in the virtual function table by the function address of the target function is avoided to be used for replacing the function address which is not to be replaced in the virtual function table, therefore, the situation of replacement errors is avoided, the situation that the wrong function is called when the application program calls the function later is avoided, and the running errors of the application program can be avoided.
It is noted that, for simplicity of explanation, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will appreciate that the present application is not limited by the order of acts, as some steps may, in accordance with the present application, occur in other orders and concurrently. Further, those skilled in the art will also appreciate that the embodiments described in the specification are exemplary and that no action is necessarily required in this application.
Referring to fig. 3, a block diagram of a data processing apparatus according to the present application is shown, and the apparatus is applied to an electronic device, and specifically may include the following modules:
a creating module 11, configured to create, in a development environment of an application program, a subclass for inheriting a base class, where the base class is a class that has been developed in the development environment;
a setting module 12, configured to set, in the subclass, a class name of the base class, a function name of an original function that needs to be replaced in the base class, and a function address of a target function that is used to replace the original function;
a first obtaining module 13, configured to obtain, according to a function name of the primitive function, a function address of the primitive function in a process of generating an executable file of the application according to a source code of the application that has been developed in the development environment;
a generating module 14, configured to generate a rewrite function table of the subclass in the executable file, where the rewrite function table includes a function address of the primitive function, a class name of the base class, and a function address of the target function.
In the present application, in the process of developing an application, a subclass for inheriting a base class is created in a development environment of the application, the base class being a class developed in the development environment. The class name of the base class, the function name of the primitive function to be replaced in the base class, and the function address of the target function for replacing the primitive function are set in the subclass. In the process of generating an executable file of an application program according to source codes of the application program developed in a development environment, a function address of a primitive function is obtained according to a function name of the primitive function. And generating a rewriting function table of the subclass in the executable file, wherein the rewriting function table of the subclass comprises a function address of the original function, a class name of the base class and a function address of the target function.
By the method and the device, the rewriting function table of the subclass in the executable file of the application program can be obtained later when the hook primitive function is supported, the virtual function table of the base class inherited by the subclass is determined, and the virtual function table comprises the function address of the function in the base class. And searching the function address of the original function in the virtual function table of the base class. And replacing the function address of the original function in the virtual function table of the base class by using the function address of the target function.
By the method, the function address of the target function can be bound with the function address of the original function to be replaced, when the function address of the original function in the virtual function table in the base class needs to be replaced by the function address of the target function, the function address of the original function can be searched in the virtual function table without the occurrence sequence of the function name of the original function in the base class, but the function address of the original function can be directly searched in the virtual function table according to the function address of the original function, so that the function address searched in the virtual function table of the base class is certainly the function address of the original function, the function address of the target function can be used for replacing the function address of the original function by the function address of the target function in the virtual function table, and the function address which is not to be replaced in the virtual function table by the function address of the target function is avoided to be used for replacing the function address which is not to be replaced in the virtual function table, therefore, the situation of replacement errors is avoided, the situation that the wrong function is called when the application program calls the function later is avoided, and the running errors of the application program can be avoided.
Referring to fig. 4, a block diagram of a data processing apparatus according to the present application is shown, and the apparatus is applied to an electronic device, and specifically may include the following modules:
a second obtaining module 21, configured to obtain a rewrite function table of a subclass in an executable file of an application program, where the subclass inherits a base class in the executable file, and the rewrite function table includes a function address of a primitive function to be replaced in the base class, a class name of the base class, and a function address of a target function used to replace the primitive function; wherein the rewrite function table is generated from a class name of the base class, a function name of the primitive function, and a function address of the target function set in the subclass in a development environment of the application program; the function address of the original function is obtained according to the function name of the original function; the subclass is used to inherit the base class;
a third obtaining module 22, configured to obtain a virtual function table of the base class according to the class name of the base class, where the virtual function table includes a function address of a function in the base class;
a searching module 23, configured to search a function address of the primitive function in the virtual function table;
a replacing module 24, configured to replace the function address of the primitive function in the virtual function table with the function address of the target function.
In an optional implementation manner, the second obtaining module includes:
a first obtaining unit, configured to obtain a memory address of the subclass in the executable file;
a second obtaining unit, configured to obtain an offset of the rewrite function table of the subclass in the memory address;
and the third acquisition unit is used for acquiring the rewriting function table according to the offset.
In an optional implementation manner, the second obtaining unit includes:
an obtaining subunit, configured to obtain a value of a specific flag bit in the subclass;
a first determining subunit, configured to determine a structure of the subclass according to a value of the specific flag bit;
and a second determining subunit, configured to determine the offset according to the structure of the subclass.
In the application, a rewrite function table of a subclass in an executable file of an application program is obtained, the subclass inherits a base class in the executable file, and the rewrite function table comprises a function address of an original function needing to be replaced in the base class, a class name of the base class and a function address of a target function for replacing the original function. And determining a virtual function table of the base class inherited by the subclass, wherein the virtual function table comprises function addresses of functions in the base class. And searching the function address of the original function in the virtual function table of the base class. And replacing the function address of the original function in the virtual function table of the base class by using the function address of the target function.
By the method, the function address of the target function can be bound with the function address of the original function to be replaced, when the function address of the original function in the virtual function table in the base class needs to be replaced by the function address of the target function, the function address of the original function can be searched in the virtual function table without the occurrence sequence of the function name of the original function in the base class, but the function address of the original function can be directly searched in the virtual function table according to the function address of the original function, so that the function address searched in the virtual function table of the base class is certainly the function address of the original function, the function address of the target function can be used for replacing the function address of the original function by the function address of the target function in the virtual function table, and the function address which is not to be replaced in the virtual function table by the function address of the target function is avoided to be used for replacing the function address which is not to be replaced in the virtual function table, therefore, the situation of replacement errors is avoided, the situation that the wrong function is called when the application program calls the function later is avoided, and the running errors of the application program can be avoided.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
Optionally, an embodiment of the present invention further provides an electronic device, including: the processor, the memory, and the computer program stored in the memory and capable of running on the processor, when executed by the processor, implement the processes of the data processing method embodiments described above, and can achieve the same technical effects, and in order to avoid repetition, details are not described here.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when being executed by a processor, the computer program implements each process of the data processing method embodiment, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here. The computer-readable storage medium may be a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk.
Fig. 5 is a block diagram of an electronic device 800 shown in the present application. For example, the electronic device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, an exercise device, a personal digital assistant, and the like.
Referring to fig. 5, electronic device 800 may include one or more of the following components: a processing component 802, a memory 804, a power component 806, a multimedia component 808, an audio component 810, an input/output (I/O) interface 812, a sensor component 814, and a communication component 816.
The processing component 802 generally controls overall operation of the electronic device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 802 may include one or more processors 820 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operation at the device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phonebook data, messages, images, videos, and so forth. The memory 804 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
The power supply component 806 provides power to the various components of the electronic device 800. The power components 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 800.
The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and a user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front facing camera and/or a rear facing camera. The front-facing camera and/or the rear-facing camera may receive external multimedia data when the device 800 is in an operating mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 800 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 814 includes one or more sensors for providing various aspects of state assessment for the electronic device 800. For example, the sensor assembly 814 may detect an open/closed state of the device 800, the relative positioning of components, such as a display and keypad of the electronic device 800, the sensor assembly 814 may also detect a change in the position of the electronic device 800 or a component of the electronic device 800, the presence or absence of user contact with the electronic device 800, orientation or acceleration/deceleration of the electronic device 800, and a change in the temperature of the electronic device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 may access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G, or 5G), or a combination thereof. In an exemplary embodiment, the communication component 816 receives broadcast signals or broadcast operation information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 800 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a non-transitory computer-readable storage medium comprising instructions, such as the memory 804 comprising instructions, executable by the processor 820 of the electronic device 800 to perform the above-described method is also provided. For example, the non-transitory computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
Fig. 6 is a block diagram of an electronic device 1900 shown in the present application. For example, the electronic device 1900 may be provided as a server.
Referring to fig. 6, electronic device 1900 includes a processing component 1922 further including one or more processors and memory resources, represented by memory 1932, for storing instructions, e.g., applications, executable by processing component 1922. The application programs stored in memory 1932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 1922 is configured to execute instructions to perform the above-described method.
The electronic device 1900 may also include a power component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input/output (I/O) interface 1958. The electronic device 1900 may operate based on an operating system stored in memory 1932, such as Windows Server, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, or the like.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
While the present invention has been described with reference to the embodiments shown in the drawings, the present invention is not limited to the embodiments, which are illustrative and not restrictive, and it will be apparent to those skilled in the art that various changes and modifications can be made therein without departing from the spirit and scope of the invention as defined in the appended claims.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a U disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. A method of data processing, the method comprising:
creating a subclass for inheriting a base class in a development environment of an application, wherein the base class is a class developed in the development environment;
setting a class name of the base class, a function name of an original function needing to be replaced in the base class and a function address of a target function for replacing the original function in the subclass;
in the process of generating an executable file of the application program according to the source code of the application program developed in the development environment, acquiring a function address of the primitive function according to the function name of the primitive function;
generating a rewrite function table for the subclass in the executable file, the rewrite function table including a function address of the primitive function, a class name of the base class, and a function address of the target function.
2. A method of data processing, the method comprising:
acquiring a rewrite function table of a subclass in an executable file of an application program, wherein the subclass inherits a base class in the executable file, and the rewrite function table comprises a function address of a primary function to be replaced in the base class, a class name of the base class and a function address of a target function for replacing the primary function; wherein the rewrite function table is generated from a class name of the base class, a function name of the primitive function, and a function address of the target function set in the subclass in a development environment of the application program; the function address of the original function is obtained according to the function name of the original function; the subclass is used to inherit the base class;
acquiring a virtual function table of the base class according to the class name of the base class, wherein the virtual function table comprises function addresses of functions in the base class;
searching a function address of the original function in the virtual function table;
and replacing the function address of the original function in the virtual function table by using the function address of the target function.
3. The method of claim 2, wherein obtaining the rewrite function table for the subclasses in the application's executable file comprises:
acquiring the memory address of the subclass in the executable file;
acquiring the offset of the rewriting function table of the subclass in the memory address;
and acquiring the rewriting function table according to the offset.
4. The method of claim 3, wherein obtaining an offset of the rewrite function table for the child class in the memory address comprises:
obtaining the value of a specific flag bit in the subclass;
determining the structure of the subclass according to the value of the specific zone bit;
and determining the offset according to the structural body of the subclass.
5. A data processing apparatus, characterized in that the apparatus comprises:
the system comprises a creating module, a determining module and a judging module, wherein the creating module is used for creating a subclass used for inheriting a base class in a development environment of an application program, and the base class is a class developed in the development environment;
a setting module, configured to set, in the subclass, a class name of the base class, a function name of an original function that needs to be replaced in the base class, and a function address of a target function that is used to replace the original function;
the first acquisition module is used for acquiring a function address of the primitive function according to a function name of the primitive function in the process of generating an executable file of the application program according to a source code of the application program developed in the development environment;
a generating module, configured to generate a rewrite function table of the subclass in the executable file, where the rewrite function table includes a function address of the primitive function, a class name of the base class, and a function address of the target function.
6. A data processing apparatus, characterized in that the apparatus comprises:
a second obtaining module, configured to obtain a rewrite function table of a subclass in an executable file of an application program, where the subclass inherits a base class in the executable file, and the rewrite function table includes a function address of an original function to be replaced in the base class, a class name of the base class, and a function address of a target function used to replace the original function; wherein the rewrite function table is generated from a class name of the base class, a function name of the primitive function, and a function address of the target function set in the subclass in a development environment of the application program; the function address of the original function is obtained according to the function name of the original function; the subclass is used to inherit the base class;
a third obtaining module, configured to obtain a virtual function table of the base class according to the class name of the base class, where the virtual function table includes a function address of a function in the base class;
the searching module is used for searching the function address of the original function in the virtual function table;
a replacing module, configured to replace the function address of the primitive function in the virtual function table with the function address of the target function.
7. The apparatus of claim 6, wherein the second obtaining module comprises:
a first obtaining unit, configured to obtain a memory address of the subclass in the executable file;
a second obtaining unit, configured to obtain an offset of the rewrite function table of the subclass in the memory address;
and the third acquisition unit is used for acquiring the rewriting function table according to the offset.
8. The apparatus of claim 7, wherein the second obtaining unit comprises:
an obtaining subunit, configured to obtain a value of a specific flag bit in the subclass;
a first determining subunit, configured to determine a structure of the subclass according to a value of the specific flag bit;
and a second determining subunit, configured to determine the offset according to the structure of the subclass.
9. An electronic device, comprising: processor, memory and a computer program stored on the memory and executable on the processor, which computer program, when executed by the processor, carries out the steps of the data processing method according to any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program, when being executed by a processor, carries out the steps of the data processing method according to any one of claims 1 to 4.
CN202110745564.8A 2021-06-30 2021-06-30 Data processing method and device, electronic equipment and storage medium Pending CN113590091A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110745564.8A CN113590091A (en) 2021-06-30 2021-06-30 Data processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110745564.8A CN113590091A (en) 2021-06-30 2021-06-30 Data processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113590091A true CN113590091A (en) 2021-11-02

Family

ID=78245428

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110745564.8A Pending CN113590091A (en) 2021-06-30 2021-06-30 Data processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113590091A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115952017A (en) * 2023-03-09 2023-04-11 腾讯科技(深圳)有限公司 Memory processing method, device, equipment and medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115952017A (en) * 2023-03-09 2023-04-11 腾讯科技(深圳)有限公司 Memory processing method, device, equipment and medium

Similar Documents

Publication Publication Date Title
CN108008955B (en) Method and device for displaying user-defined control information
CN113590091A (en) Data processing method and device, electronic equipment and storage medium
CN106293683B (en) Project compiling method and device
CN108563487B (en) User interface updating method and device
CN108549570B (en) User interface updating method and device
CN110457084B (en) Loading method and device
CN108427568B (en) User interface updating method and device
CN109933357B (en) Application program upgrading method and device
CN113946346B (en) Data processing method and device, electronic equipment and storage medium
CN114489641B (en) Data processing method and device, electronic equipment and storage medium
CN114416218B (en) Data processing method and device, electronic equipment and storage medium
CN113934452B (en) Data processing method and device, electronic equipment and storage medium
CN114020505B (en) Data processing method and device, electronic equipment and storage medium
CN114020693B (en) Header file address acquisition method and device, electronic equipment and storage medium
CN113821212A (en) Information processing method and device, electronic equipment and storage medium
CN114020504B (en) Data processing method and device, electronic equipment and storage medium
CN111596949B (en) Method and device for developing application program
CN116126320B (en) Data processing method and device, electronic equipment and storage medium
CN114020694B (en) Header file address acquisition method and device, electronic equipment and storage medium
CN114416084B (en) Data processing method and device, electronic equipment and storage medium
CN112612516B (en) Code processing method and device
CN114115862A (en) Data processing method and device, electronic equipment and storage medium
CN114115863A (en) Data processing method and device, electronic equipment and storage medium
CN114416085A (en) Data processing method and device, electronic equipment and storage medium
CN116400925A (en) Data processing method and 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