CN101714075B - Function calling method and device - Google Patents

Function calling method and device Download PDF

Info

Publication number
CN101714075B
CN101714075B CN 200910189035 CN200910189035A CN101714075B CN 101714075 B CN101714075 B CN 101714075B CN 200910189035 CN200910189035 CN 200910189035 CN 200910189035 A CN200910189035 A CN 200910189035A CN 101714075 B CN101714075 B CN 101714075B
Authority
CN
China
Prior art keywords
function
address
dynamic link
link library
internal memory
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.)
Expired - Fee Related
Application number
CN 200910189035
Other languages
Chinese (zh)
Other versions
CN101714075A (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.)
Wondershare Technology Co ltd
Original Assignee
Shenzhen Wondershare Software 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 Shenzhen Wondershare Software Co Ltd filed Critical Shenzhen Wondershare Software Co Ltd
Priority to CN 200910189035 priority Critical patent/CN101714075B/en
Publication of CN101714075A publication Critical patent/CN101714075A/en
Application granted granted Critical
Publication of CN101714075B publication Critical patent/CN101714075B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention relates to a function calling technology and provides function calling method and device for overcoming the defect that a nonderivation function in a dynamic link library (DLL) can not be called by the prior art. The function calling method is used for calling a nonderivation function in the DLL and comprises the following steps of: loading the DLL in an internal memory and confirming a base address of the DLL in the internal memory; fixing a real address of the nonderivation function in the cache on the basis of a relative address and the base address of the nonderivation function in the DLL and calling the nonderivation function according to the real address. The invention also provides the function calling device. The function calling method and device can fix the real address of the nonderivation function in the internal memory by fixing a virtual address of the nonderivation function in the DLL and the base address of the loaded DLL in the internal memory and can realize the calling of the nonderivation function on the basis of the real address. The technical scheme has simple operation and is easy for realization.

Description

Function calling method and device
Technical field
The present invention relates to the function call technology, more particularly, relate to a kind of function calling method and device.
Background technology
Dynamic link library is the concept development from C language function library and Pascal library unit, is the executable file as the Sharing Function storehouse.Dynamic link provides a kind of method, makes process can call the function that does not belong to its executable code.The executable code of function is positioned among the DLL (Dynamic LinkLibrary, dynamic link library), this DLL comprise one or more by compiling, link and with the function of the process separate storage of using them.DLL also helps shared data and resource.A plurality of application programs are the content of single DLL copy in the access memory simultaneously.Can be interpreted as a function library to dynamic link library, this function library has comprised global data, the function that compiled and resource.Dynamic link library can not direct operation as common executable file, but is used for for other exe file (executable file) or dll file the Sharing Function storehouse being provided.DLL is loaded in the predetermined base address through after compiling, if conflict with other DLL, file just is mapped on the virtual address identical in the process.Different with static library is that it can not directly be linked in the executable file, but when program run, just loads.The dynamic link library of a plurality of application programs in can shared drive so just saved the spending of internal memory greatly, and can have been reduced the size of executable file effectively.
Dynamic link library generally comprises .lib (derivative function) .h .DLL file.Dynamic link library has following two kinds of method of application:
A. implicit expression link, static library is similar with using, and is divided into for three steps: quote .lib, comprise header file, use derivative function;
B. dynamic load directly uses LoadLibrary to load required dynamic base, specifies required derivative function then.
Said method can only call the function of deriving among the DLL.If have some functions to realize our desired function among the DLL, but can't derive separately, then we can't use these functions separately.
Therefore, need a kind of technical scheme, can realize calling non-derivative function among the DLL.
Summary of the invention
The technical matters that the present invention will solve is, can't call the defective of the non-derivative function among the DLL to prior art, and a kind of function calling method and device are provided.
The technical solution adopted for the present invention to solve the technical problems is:
Construct a kind of function calling method, be used for calling the non-derivative function of dynamic link library, comprising:
Load step is included in and loads said dynamic link library and the definite base address of this dynamic link library in internal memory in the internal memory;
Invocation step comprises based on relative address and the said base address of said non-derivative function in said dynamic link library and confirms the true address of non-derivative function in internal memory, and calls this non-derivative function according to this true address.
In function calling method provided by the invention; Saidly confirm that based on the relative address and the said base address of said non-derivative function in said dynamic link library the true address of non-derivative function in internal memory further comprises, confirms said true address according to formula:
True address=relative address+base address
The present invention also provides a kind of function call device, is used for calling the non-derivative function of dynamic link library, comprising:
Load-on module is used for loading said dynamic link library and confirming the base address of this dynamic link library in internal memory at internal memory;
Calling module is used for confirming the true address of non-derivative function in internal memory based on said non-derivative function in the relative address and the said base address of said dynamic link library, and calls this non-derivative function according to this true address.
In function call device provided by the invention; When confirming the true address of non-derivative function in internal memory based on relative address and the said base address of said non-derivative function in said dynamic link library, said calling module is confirmed said true address according to formula:
True address=relative address+base address
The present invention also provides a kind of function calling method, is used for calling the non-member function of deriving in the class of dynamic link library, comprising:
Load step is included in and loads said dynamic link library and the definite base address of this dynamic link library in internal memory in the internal memory;
Invocation step comprises based on relative address and the said base address of said member function in said dynamic link library and confirms the true address of member function in internal memory, and calls this member function according to this true address.
In function calling method provided by the invention; Saidly confirm that based on the relative address and the said base address of said member function in said dynamic link library the true address of non-derivative function in internal memory further comprises, confirms said true address according to formula:
True address=relative address+base address
The present invention also provides a kind of function call device, is used for calling the non-member function of deriving in the class of dynamic link library, comprising:
Load-on module is used for loading said dynamic link library and confirming the base address of this dynamic link library in internal memory at internal memory;
Calling module is used for confirming the true address of member function in internal memory based on said member function in the relative address and the said base address of said dynamic link library, and calls this member function according to this true address.
In function call device provided by the invention; When confirming the true address of member function in internal memory based on relative address and the said base address of said member function in said dynamic link library, said calling module is used for confirming said true address according to formula:
True address=relative address+base address
The technical scheme of embodiment of the present invention; Have following beneficial effect: function calling method provided by the invention can be confirmed the true address of non-derivative function in internal memory through confirming virtual address and dynamic link library loading back the base address in internal memory of non-derivative function in dynamic link library with device, and realizes calling of non-derivative function based on this true address.Technical scheme provided by the invention is simple to operate, is easy to realize.
Description of drawings
To combine accompanying drawing and embodiment that the present invention is described further below, in the accompanying drawing:
Fig. 1 is the process flow diagram according to the function calling method of the present invention's one preferred embodiment;
Fig. 2 is the logical organization synoptic diagram according to the function call device of the present invention's one preferred embodiment;
Fig. 3 is the process flow diagram according to the function calling method of the present invention's one preferred embodiment;
Fig. 4 is the logical organization synoptic diagram according to the function call device of the present invention's one preferred embodiment.
Embodiment
In order to make the object of the invention, technical scheme and advantage clearer,, the present invention is further elaborated below in conjunction with accompanying drawing and embodiment.Should be appreciated that specific embodiment described herein only in order to explanation the present invention, and be not used in qualification the present invention.
Function calling method provided by the invention can be confirmed the true address of non-derivative function in internal memory through confirming virtual address and dynamic link library loading back the base address in internal memory of non-derivative function in dynamic link library with device, and realizes calling of non-derivative function based on this true address.Technical scheme provided by the invention is simple to operate, is easy to realize.Just combine accompanying drawing and specific embodiment to describe technical scheme of the present invention in detail below.
Fig. 1 is the process flow diagram according to the function calling method 100 of the present invention's one preferred embodiment.Function calling method provided by the invention is used for calling the non-derivative function of dynamic link library.As shown in Figure 1, method 100 starts from step 102.
Subsequently, at next step 104, in internal memory, load said dynamic link library and confirm the base address of this dynamic link library in internal memory.
In concrete implementation procedure, before execution in step 104, at first need to the non-derivative function that will call carry out function declaration, and define the function pointer of a same type.
In concrete implementation procedure, the base address that execution in step 104 is obtained is and loads the handle that returns behind the dynamic link library.
Subsequently, at next step 106, confirm the true address of non-derivative function in internal memory based on the relative address and the said base address of said non-derivative function in said dynamic link library.
In concrete implementation procedure, can use existing multiple instrument to obtain the relative address of non-derivative function in dynamic link library, such as but not limited to IDA Pro Advanced.
In concrete implementation procedure, can calculate true address according to formula:
True address=relative address+base address
Subsequently, at next step 108, call this non-derivative function according to this true address.
In concrete implementation procedure,, just can call this non-derivative function through giving the function pointer of definition in the step 104 with this true address assignment.
At last, method 100 ends at step 110.
In concrete implementation procedure, method 100 can be realized by following code:
#include″stdafx.h″
#include<windows.h>
#define FUNTION_OFFSET 0x10001630-0x10000000//0x10001630-0x10000000 is the relative address of non-derivative function in dynamic link library
typedef?void(_cdecl*funtion)(void);
int?main(int?argc,char*argv[])
{
HMODULE?mod;
Mod=LoadLibraryA (" D: "); //mydll.dll is a dynamic link library
Funtion pMy_funtion=(funtion) ((_ int64) mod+FUNTION_OFFSET); // (_ int64) mod+FUNTION_OFFSET is true address
PMy_funtion (); // call the non-derivative function my_funtion among the mydll.dll
return?0;
}
The present invention also provides a kind of function call device, just combines Fig. 2 described below.
Fig. 2 is the logical organization synoptic diagram according to the function call device 200 of the present invention's one preferred embodiment.Function call device provided by the invention is used for calling the non-derivative function of dynamic link library.As shown in Figure 2, function call device 200 provided by the invention comprises load-on module 202 and calling module 204.
Load-on module 202 is used for loading said dynamic link library and confirming the base address of this dynamic link library in internal memory at internal memory.
In concrete implementation procedure, before loading dynamic link library, at first need to the non-derivative function that will call carry out function declaration, and define the function pointer of a same type.
In concrete implementation procedure, the base address that load-on module 202 is obtained is and loads the handle that returns behind the dynamic link library.
Calling module 204 is used for confirming the true address of non-derivative function in internal memory based on said non-derivative function in the relative address and the said base address of said dynamic link library, and calls this non-derivative function according to this true address.
In concrete implementation procedure, can use existing multiple instrument to obtain the relative address of non-derivative function in dynamic link library, such as but not limited to IDA Pro Advanced.
In concrete implementation procedure, when confirming the true address of non-derivative function in internal memory based on relative address and the said base address of said non-derivative function in said dynamic link library, calling module 204 is confirmed said true address according to formula:
True address=relative address+base address
In concrete implementation procedure, through giving the function pointer of definition mentioned above with this true address assignment, calling module 204 just can call this non-derivative function.
It is a kind of to non-call method of deriving member function in the class in the dynamic link library that the present invention also provides, and just combines Fig. 3 described below.
Fig. 3 is the process flow diagram according to the function calling method 300 of the present invention's one preferred embodiment.Function calling method provided by the invention is used for calling the non-member function of deriving in the class of dynamic link library.As shown in Figure 3, method 300 starts from step 302.
Subsequently, at next step 304, in internal memory, load said dynamic link library and confirm the base address of this dynamic link library in internal memory.
In concrete implementation procedure, before execution in step 304, at first need find out the type of non-all member variables of deriving type and the order of definition; State a class then, the order of its member variable is identical with non-derivation class with type, is function pointer of each member function definition again.
In concrete implementation procedure, the base address that execution in step 304 is obtained is and loads the handle that returns behind the dynamic link library.
Subsequently, at next step 306, confirm the true address of member function in internal memory based on the relative address and the said base address of member function in dynamic link library.
In concrete implementation procedure, can use existing multiple instrument to obtain the relative address of member function in dynamic link library, such as but not limited to IDA Pro Advanced.
In concrete implementation procedure, can calculate true address according to formula:
True address=relative address+base address
Subsequently, at next step 308, call this member function according to this true address.
In concrete implementation procedure,, just can call this member function through with the function pointer of this true address assignment to the preceding text definition.
At last, method 300 ends at step 310.
In concrete implementation procedure, method 300 can be realized by following code:
#include″stdafx.h″
#include<windows.h>
#define?FUNTION_OFFSET?0x10001470-0x10000000//0x10001470-
0x10000000 is the relative address of member function in dynamic link library
typedef?void(_cdecl*funtion)(void);
typedef?void(_cdecl*mem_funtion)(void*it);
_int64?g_Imagebase=0;
class?my_class
{
public:
int?m_val;
my_class()
{
pfuntion=(funtion)(g_Imagebase+FUNTION_OFFSET);
}
funtion?pfuntion;
void?my_funtion(void)
{
pfuntion();
}
};
int?main(int?argc,char*argv[])
{
g_Imagebase=
(_int64)LoadLibrary?A(″D:\\test\\mydll\\Debug\\mydll.dll″);
my_class*myclass=new?my_class;
myclass->my_funtion();
printf(″%d″,myclass->m_val);
return?0;
}
The present invention also provides a kind of non-device of deriving member function in the class in the dynamic link library that calls, and just combines Fig. 4 described below.
Fig. 4 is the logical organization synoptic diagram according to the function call device 400 of the present invention's one preferred embodiment.Function call device provided by the invention is used for calling the non-member function of deriving in the class of dynamic link library.As shown in Figure 4, function call device 400 comprises load-on module 402 and calling module 404.
Load-on module 402 is used for loading said dynamic link library and confirming the base address of this dynamic link library in internal memory at internal memory;
In concrete implementation procedure, before loading dynamic link library, at first need find out the type of non-all member variables of deriving type and the order of definition; State a class then, the order of its member variable is identical with non-derivation class with type, is function pointer of each member function definition again.
In concrete implementation procedure, the base address that load-on module 402 is obtained is and loads the handle that returns behind the dynamic link library.
Calling module 404 is used for confirming the true address of member function in internal memory based on said member function in the relative address and the said base address of said dynamic link library, and calls this member function according to this true address.
In concrete implementation procedure, can use existing multiple instrument to obtain the relative address of member function in dynamic link library, such as but not limited to IDA Pro Advanced.
In concrete implementation procedure, can calculate true address according to formula:
True address=relative address+base address
In concrete implementation procedure, through the function pointer that this true address assignment is defined to preceding text, calling module 404 just can call this member function.
The above is merely preferred embodiment of the present invention, not in order to restriction the present invention, all any modifications of within spirit of the present invention and principle, being done, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.

Claims (4)

1. function calling method is used for calling the non-derivative function of dynamic link library, it is characterized in that, comprising:
Load step comprises function pointer identical with said non-derivative function type of definition and in internal memory, loads said dynamic link library and the definite base address of this dynamic link library in internal memory;
Invocation step; Comprise based on relative address and the said base address of said non-derivative function in said dynamic link library and confirm the true address of non-derivative function in internal memory, said true address assignment is given said function pointer and called this non-derivative function according to this true address;
Saidly confirm that based on the relative address and the said base address of said non-derivative function in said dynamic link library the true address of non-derivative function in internal memory further comprises, confirms said true address according to formula:
True address=relative address+base address.
2. function call device is used for calling the non-derivative function of dynamic link library, it is characterized in that, comprising:
Load-on module is used for defining a function pointer identical with said non-derivative function type and loads said dynamic link library and the definite base address of this dynamic link library in internal memory at internal memory;
Calling module; Be used for confirming the true address of non-derivative function in internal memory in the relative address and the said base address of said dynamic link library, said true address assignment is given said function pointer and called this non-derivative function according to this true address based on said non-derivative function;
When confirming the true address of non-derivative function in internal memory based on relative address and the said base address of said non-derivative function in said dynamic link library, said calling module is confirmed said true address according to formula:
True address=relative address+base address.
3. a function calling method is used for calling the non-member function of deriving in the class of dynamic link library, it is characterized in that, comprising:
Load step comprises the type of all member variables of at first finding out said non-derivation class and the order of definition; State a class then, the order of its member variable is identical with said non-derivation class with type, is that each said member function defines a function pointer and in internal memory, loads said dynamic link library and the definite base address of this dynamic link library in internal memory again;
Invocation step; Comprise based on relative address and the said base address of said member function in said dynamic link library and confirm the true address of member function in internal memory, said true address assignment is given corresponding said function pointer and called this member function according to this true address;
Saidly confirm that based on the relative address and the said base address of said member function in said dynamic link library the true address of member function in internal memory further comprises, confirms said true address according to formula:
True address=relative address+base address.
4. a function call device is used for calling the non-member function of deriving in the class of dynamic link library, it is characterized in that, comprising:
Load-on module is used for being respectively said non-each said member function of deriving class and defines the function pointer identical with type with its order and load said dynamic link library and the definite base address of this dynamic link library in internal memory at internal memory;
Calling module; Be used for confirming the true address of member function in internal memory in the relative address and the said base address of said dynamic link library, said true address assignment is given corresponding said function pointer and called this member function according to this true address based on said member function;
When confirming the true address of member function in internal memory based on relative address and the said base address of said member function in said dynamic link library, said calling module is used for confirming said true address according to formula:
True address=relative address+base address.
CN 200910189035 2009-12-17 2009-12-17 Function calling method and device Expired - Fee Related CN101714075B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200910189035 CN101714075B (en) 2009-12-17 2009-12-17 Function calling method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200910189035 CN101714075B (en) 2009-12-17 2009-12-17 Function calling method and device

Publications (2)

Publication Number Publication Date
CN101714075A CN101714075A (en) 2010-05-26
CN101714075B true CN101714075B (en) 2012-12-19

Family

ID=42417744

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200910189035 Expired - Fee Related CN101714075B (en) 2009-12-17 2009-12-17 Function calling method and device

Country Status (1)

Country Link
CN (1) CN101714075B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103823663A (en) * 2012-11-19 2014-05-28 腾讯科技(深圳)有限公司 Method and device of calling member variables
CN106095416A (en) * 2016-06-01 2016-11-09 腾讯科技(深圳)有限公司 A kind of in the application redirect processing method, device and intelligent terminal

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101908119B (en) * 2010-08-12 2012-10-03 浙江中控软件技术有限公司 Method and device for processing dynamic link library (DLL) file
CN105677435A (en) * 2015-12-30 2016-06-15 小米科技有限责任公司 Function invoking method, apparatus and terminal
CN106406857B (en) * 2016-08-30 2021-04-13 惠州学院 Memory multiplexing method and device for dynamic link library
CN106502745B (en) * 2016-10-26 2019-12-10 腾讯科技(深圳)有限公司 Function calling method and device

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101271402A (en) * 2007-03-20 2008-09-24 华为技术有限公司 Method and system for calling function

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101271402A (en) * 2007-03-20 2008-09-24 华为技术有限公司 Method and system for calling function

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103823663A (en) * 2012-11-19 2014-05-28 腾讯科技(深圳)有限公司 Method and device of calling member variables
CN103823663B (en) * 2012-11-19 2017-12-01 腾讯科技(深圳)有限公司 A kind of method and apparatus for calling member variable
CN106095416A (en) * 2016-06-01 2016-11-09 腾讯科技(深圳)有限公司 A kind of in the application redirect processing method, device and intelligent terminal
CN106095416B (en) * 2016-06-01 2020-10-09 腾讯科技(深圳)有限公司 Jump processing method and device in application program and intelligent terminal

Also Published As

Publication number Publication date
CN101714075A (en) 2010-05-26

Similar Documents

Publication Publication Date Title
CN110096338B (en) Intelligent contract execution method, device, equipment and medium
CN101714075B (en) Function calling method and device
US10367822B2 (en) Restrictive access control for modular reflection
US8645930B2 (en) System and method for obfuscation by common function and common function prototype
US8570333B2 (en) Method and system for enabling managed code-based application program to access graphics processing unit
CN106415495B (en) Programming system and language for application development
US9003402B1 (en) Method and system for injecting function calls into a virtual machine
KR20170094136A (en) System and method for execution of application code compiled according to two instruction set architectures
US20130198494A1 (en) Method for compiling a parallel thread execution program for general execution
US7917898B2 (en) Methods and apparatus to provide a modular native method invocation system
US8436862B2 (en) Method and system for enabling managed code-based application program to access graphics processing unit
EP2564316B1 (en) Resumable methods
CN103793255B (en) Starting method for configurable multi-main-mode multi-OS-inner-core real-time operating system structure
EP3350696A1 (en) Overriding a migrated method of an updated type
US11106623B1 (en) Virtualized multicore systems with extended instruction heterogeneity
US20140208300A1 (en) COMMUNICATION STACK FOR SOFTWARE-HARDWARE CO-EXECUTION ON HETEROGENEOUS COMPUTING SYSTEMS WITH PROCESSORS AND RECONFIGURABLE LOGIC (FPGAs)
US10229044B2 (en) Conditional stack frame allocation
WO2014055135A1 (en) Fast remote procedure call
US8516455B2 (en) Dynamic loading of kernel extensions
US9207956B2 (en) Class loading device for a java runtime environment, cluster system and method of executing a function
US20110209004A1 (en) Integrating templates into tests
US20210089282A1 (en) Memory ordering annotations for binary emulation
US8250589B2 (en) Method for simplifying interfaces having dynamic libraries
CN111176663A (en) Data processing method, device and equipment of application program and storage medium
US20120324430A1 (en) Aliasing buffers

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C56 Change in the name or address of the patentee

Owner name: SHENZHEN WONDERSHARE INFORMATION TECHNOLOGY CO., L

Free format text: FORMER NAME: SHENZHEN WONDERSHARE SOFTWARE CO., LTD.

CP03 Change of name, title or address

Address after: 518057 Guangdong city of Shenzhen province Nanshan District Gao Xin Road, room 9 building on the north side of block A901 No. 006 TCL Industry Research Institute building A A Building 8 floor

Patentee after: SHENZHEN WONDERSHARE INFORMATION TECHNOLOGY Co.,Ltd.

Address before: 518057 Guangdong province Shenzhen city Nanshan District high tech Park South Road Fucheng technology building on the third floor

Patentee before: WONDERSHARE SOFTWARE Co.,Ltd.

CP03 Change of name, title or address

Address after: 850000 Tibet autonomous region, Lhasa City, New District, west of the East Ring Road, 1-4 road to the north, south of 1-3 Road, Liu Dong building, east of the 8 unit 6, floor 2, No.

Patentee after: WONDERSHARE TECHNOLOGY CO.,LTD.

Address before: 518057 Guangdong city of Shenzhen province Nanshan District Gao Xin Road, room 9 building on the north side of block A901 No. 006 TCL Industry Research Institute building A A Building 8 floor

Patentee before: SHENZHEN WONDERSHARE INFORMATION TECHNOLOGY Co.,Ltd.

CP03 Change of name, title or address
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20121219

CF01 Termination of patent right due to non-payment of annual fee