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.
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.