CN101714075A - Function calling method and device - Google Patents

Function calling method and device Download PDF

Info

Publication number
CN101714075A
CN101714075A CN200910189035A CN200910189035A CN101714075A CN 101714075 A CN101714075 A CN 101714075A CN 200910189035 A CN200910189035 A CN 200910189035A CN 200910189035 A CN200910189035 A CN 200910189035A CN 101714075 A CN101714075 A CN 101714075A
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.)
Granted
Application number
CN200910189035A
Other languages
Chinese (zh)
Other versions
CN101714075B (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 providing the Sharing Function storehouse for other exe file (executable file) or dll file.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 just loads when program run.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 using method:
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 problem to be solved in the present invention is, can't call the defective of the non-derivative function among the DLL at 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 described 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 described base address of described non-derivative function in described dynamic link library and determines 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, describedly determine that based on the relative address and the described base address of described non-derivative function in described dynamic link library the true address of non-derivative function in internal memory further comprises, determine described true address according to following 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 described dynamic link library and determining the base address of this dynamic link library in internal memory at internal memory;
Calling module is used for determining the true address of non-derivative function in internal memory based on described non-derivative function in the relative address and the described base address of described dynamic link library, and calls this non-derivative function according to this true address.
In function call device provided by the invention, based on relative address and the described base address when determining non-derivative function true address in internal memory of described non-derivative function in described dynamic link library, described calling module is determined described true address according to following formula:
True address=relative address+base address
The present invention also provides a kind of function calling method, is used for calling the member function in the non-derivation class of dynamic link library, comprising:
Load step is included in and loads described 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 described base address of described member function in described dynamic link library and determines 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, describedly determine that based on the relative address and the described base address of described member function in described dynamic link library the true address of non-derivative function in internal memory further comprises, determine described true address according to following formula:
True address=relative address+base address
The present invention also provides a kind of function call device, is used for calling the member function in the non-derivation class of dynamic link library, comprising:
Load-on module is used for loading described dynamic link library and determining the base address of this dynamic link library in internal memory at internal memory;
Calling module is used for determining the true address of member function in internal memory based on described member function in the relative address and the described base address of described dynamic link library, and calls this member function according to this true address.
In function call device provided by the invention, based on relative address and the described base address when determining member function true address in internal memory of described member function in described dynamic link library, described calling module is used for determining described true address according to following formula:
True address=relative address+base address
Implement technical scheme of the present invention, have following beneficial effect: function calling method provided by the invention and device can be determined the true address of non-derivative function in internal memory by determining virtual address and dynamic link library loading back the base address in internal memory of non-derivative function in dynamic link library, and realize 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
The invention will be further described below in conjunction with drawings and Examples, in the accompanying drawing:
Fig. 1 is the process flow diagram according to the function calling method of a preferred embodiment of the present invention;
Fig. 2 is the logical organization synoptic diagram according to the function call device of a preferred embodiment of the present invention;
Fig. 3 is the process flow diagram according to the function calling method of a preferred embodiment of the present invention;
Fig. 4 is the logical organization synoptic diagram according to the function call device of a preferred embodiment of the present invention.
Embodiment
In order to make purpose of the present invention, technical scheme and advantage clearer,, the present invention is further elaborated below in conjunction with drawings and Examples.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 and device can be determined the true address of non-derivative function in internal memory by determining virtual address and dynamic link library loading back the base address in internal memory of non-derivative function in dynamic link library, and realize calling of non-derivative function based on this true address.Technical scheme provided by the invention is simple to operate, is easy to realize.Below just describe technical scheme of the present invention in detail with specific embodiment in conjunction with the accompanying drawings.
Fig. 1 is the process flow diagram according to the function calling method 100 of a preferred embodiment of the present invention.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 described dynamic link library and determine the base address of this dynamic link library in internal memory.
In the specific implementation process, before execution in step 104, at first need the non-derivative function that will call is carried out function declaration, and define the function pointer of a same type.
In the specific implementation process, 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, determine the true address of non-derivative function in internal memory based on the relative address and the described base address of described non-derivative function in described dynamic link library.
In the specific implementation process, 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 the specific implementation process, can calculate true address according to following formula:
True address=relative address+base address
Subsequently, at next step 108, call this non-derivative function according to this true address.
In the specific implementation process,, just can call this non-derivative function by giving the function pointer of definition in the step 104 with this true address assignment.
At last, method 100 ends at step 110.
In the specific implementation process, 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: test mydll Debug mydll.dll "); //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, below just described in conjunction with Fig. 2.
Fig. 2 is the logical organization synoptic diagram according to the function call device 200 of a preferred embodiment of the present invention.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 described dynamic link library and determining the base address of this dynamic link library in internal memory at internal memory.
In the specific implementation process, before loading dynamic link library, at first need the non-derivative function that will call is carried out function declaration, and define the function pointer of a same type.
In the specific implementation process, 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 determining the true address of non-derivative function in internal memory based on described non-derivative function in the relative address and the described base address of described dynamic link library, and calls this non-derivative function according to this true address.
In the specific implementation process, 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 the specific implementation process, based on relative address and the described base address when determining non-derivative function true address in internal memory of described non-derivative function in described dynamic link library, calling module 204 is determined described true address according to following formula:
True address=relative address+base address
In the specific implementation process, by giving the function pointer of definition mentioned above with this true address assignment, calling module 204 just can call this non-derivative function.
The present invention also provides a kind of call method to member function in the non-derivation class in the dynamic link library, below just described in conjunction with Fig. 3.
Fig. 3 is the process flow diagram according to the function calling method 300 of a preferred embodiment of the present invention.Function calling method provided by the invention is used for calling the member function in the non-derivation 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 described dynamic link library and determine the base address of this dynamic link library in internal memory.
In the specific implementation process, before execution in step 304, at first need to find out the type of all member variables of non-derivation class 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 the specific implementation process, 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, determine the true address of member function in internal memory based on the relative address and the described base address of member function in dynamic link library.
In the specific implementation process, 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 the specific implementation process, can calculate true address according to following formula:
True address=relative address+base address
Subsequently, at next step 308, call this member function according to this true address.
In the specific implementation process,, just can call this member function by giving function pointer defined above with this true address assignment.
At last, method 300 ends at step 310.
In the specific implementation process, 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 device of member function in the non-derivation class that calls in the dynamic link library, below just described in conjunction with Fig. 4.
Fig. 4 is the logical organization synoptic diagram according to the function call device 400 of a preferred embodiment of the present invention.Function call device provided by the invention is used for calling the member function in the non-derivation 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 described dynamic link library and determining the base address of this dynamic link library in internal memory at internal memory;
In the specific implementation process, before loading dynamic link library, at first need to find out the type of all member variables of non-derivation class 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 the specific implementation process, 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 determining the true address of member function in internal memory based on described member function in the relative address and the described base address of described dynamic link library, and calls this member function according to this true address.
In the specific implementation process, 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 the specific implementation process, can calculate true address according to following formula:
True address=relative address+base address
In the specific implementation process, by giving function pointer defined above with this true address assignment, calling module 404 just can call this member function.
The above only is preferred embodiment of the present invention, not in order to restriction the present invention, all any modifications of being done within the spirit and principles in the present invention, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.

Claims (8)

1. function calling method is used for calling the non-derivative function of dynamic link library, it is characterized in that, comprising:
Load step is included in and loads described 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 described base address of described non-derivative function in described dynamic link library and determines the true address of non-derivative function in internal memory, and calls this non-derivative function according to this true address.
2. function calling method according to claim 1, it is characterized in that, describedly determine that based on the relative address and the described base address of described non-derivative function in described dynamic link library the true address of non-derivative function in internal memory further comprises, determine described true address according to following formula:
True address=relative address+base address
3. 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 loading described dynamic link library and determining the base address of this dynamic link library in internal memory at internal memory;
Calling module is used for determining the true address of non-derivative function in internal memory based on described non-derivative function in the relative address and the described base address of described dynamic link library, and calls this non-derivative function according to this true address.
4. function call device according to claim 4, it is characterized in that, based on relative address and the described base address when determining non-derivative function true address in internal memory of described non-derivative function in described dynamic link library, described calling module is determined described true address according to following formula:
True address=relative address+base address
5. a function calling method is used for calling the member function in the non-derivation class of dynamic link library, it is characterized in that, comprising:
Load step is included in and loads described 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 described base address of described member function in described dynamic link library and determines the true address of member function in internal memory, and calls this member function according to this true address.
6. function calling method according to claim 5, it is characterized in that, describedly determine that based on the relative address and the described base address of described member function in described dynamic link library the true address of non-derivative function in internal memory further comprises, determine described true address according to following formula:
True address=relative address+base address
7. a function call device is used for calling the member function in the non-derivation class of dynamic link library, it is characterized in that, comprising:
Load-on module is used for loading described dynamic link library and determining the base address of this dynamic link library in internal memory at internal memory;
Calling module is used for determining the true address of member function in internal memory based on described member function in the relative address and the described base address of described dynamic link library, and calls this member function according to this true address.
8. function call device according to claim 7, it is characterized in that, based on relative address and the described base address when determining member function true address in internal memory of described member function in described dynamic link library, described calling module is used for determining described true address according to following 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 true CN101714075A (en) 2010-05-26
CN101714075B 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 (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101908119A (en) * 2010-08-12 2010-12-08 浙江中控软件技术有限公司 Method and device for processing dynamic link library (DLL) file
CN105677435A (en) * 2015-12-30 2016-06-15 小米科技有限责任公司 Function invoking method, apparatus and terminal
CN106406857A (en) * 2016-08-30 2017-02-15 惠州学院 Memory reusing method and device for dynamic link library
CN106502745A (en) * 2016-10-26 2017-03-15 腾讯科技(深圳)有限公司 A kind of function calling method and device

Families Citing this family (2)

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

Family Cites Families (1)

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

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101908119A (en) * 2010-08-12 2010-12-08 浙江中控软件技术有限公司 Method and device for processing dynamic link library (DLL) file
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
CN106406857A (en) * 2016-08-30 2017-02-15 惠州学院 Memory reusing method and device for dynamic link library
CN106406857B (en) * 2016-08-30 2021-04-13 惠州学院 Memory multiplexing method and device for dynamic link library
CN106502745A (en) * 2016-10-26 2017-03-15 腾讯科技(深圳)有限公司 A kind of function calling method and device

Also Published As

Publication number Publication date
CN101714075B (en) 2012-12-19

Similar Documents

Publication Publication Date Title
CN110096338B (en) Intelligent contract execution method, device, equipment and medium
CN109976761B (en) Software development kit generation method and device and terminal equipment
US8570333B2 (en) Method and system for enabling managed code-based application program to access graphics processing unit
US8458681B1 (en) Method and system for optimizing the object code of a program
US10776233B2 (en) Programmable test instrument
CN101714075B (en) Function calling method and device
US10180850B1 (en) Emulating applications that use hardware acceleration
US11900113B2 (en) Data flow processing method and related device
US8429632B1 (en) Method and system for debugging merged functions within a program
US8436862B2 (en) Method and system for enabling managed code-based application program to access graphics processing unit
US10691580B1 (en) Diagnosing applications that use hardware acceleration through emulation
US8549506B2 (en) Resumable methods
US20110302563A1 (en) Program structure recovery using multiple languages
US20090178028A1 (en) Method and system for invoking just-in-time debugger
Ennals et al. Task partitioning for multi-core network processors
WO2020123184A1 (en) Improving emulation and tracing performance using compiler-generated emulation optimization metadata
US8397217B2 (en) Integrating templates into tests
US8516455B2 (en) Dynamic loading of kernel extensions
CN102722438A (en) Kernel debugging method and equipment
CN102854801A (en) High data volume FPGA (Field Programmable Gate Array) simulating testing method based on time sharing multiplex
CN116992804A (en) Chip verification method and computing device
US8990515B2 (en) Aliasing buffers
CN116243923A (en) Applet processing method and device and electronic equipment
CN112631955B (en) Data processing method, device, electronic equipment and medium
US8261234B1 (en) System, method, and computer program product for compiling code adapted to execute utilizing a first processor, for executing the code utilizing a second processor

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