How to iterate vtable of COM coclass?
-
Hello, How to iterate (infact access) the vtable of COM coclass(that will implement the methods of its exposed interfaces).? Only I need to access vtable where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum" Regards Muhammad Usman Khalil
-
Hello, How to iterate (infact access) the vtable of COM coclass(that will implement the methods of its exposed interfaces).? Only I need to access vtable where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum" Regards Muhammad Usman Khalil
Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?
-
Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?
I need to call all the functions of COM Interface exposed methods at runtime. For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime. Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time. Any Suggestions?
-
I need to call all the functions of COM Interface exposed methods at runtime. For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime. Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time. Any Suggestions?
-
Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?
a coclass will always have pointers to virtual tables (of all interfaces it implements) as its instance data. In CreateObject() function, coclass is instantiated, type casted to the interface ptr which we demands through CoCreaInstance and returned. so the returned ptr will be pointing to the virtual table of that interface. This virtual table ptr is used later in function calls to locate the correct implemented functions. Pls correct me if iam wrong..
-
a coclass will always have pointers to virtual tables (of all interfaces it implements) as its instance data. In CreateObject() function, coclass is instantiated, type casted to the interface ptr which we demands through CoCreaInstance and returned. so the returned ptr will be pointing to the virtual table of that interface. This virtual table ptr is used later in function calls to locate the correct implemented functions. Pls correct me if iam wrong..
Can we then be able to take its size as well? I mean how many no of entries(addresses) that vtable would then have?
-
I need to call all the functions of COM Interface exposed methods at runtime. For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime. Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time. Any Suggestions?
Checkout the following articles... It may helpful for your needs.... Writing An Extensible COM Application[^] Pluggable Components using Component Categories Part I[^]
-
Can we then be able to take its size as well? I mean how many no of entries(addresses) that vtable would then have?
size of the returned interface ptr will be size of a pointer (4 bytes as any pointer). so in order to call the functions using that ptr, u need to have their declarations. Also for all com interfaces, first few entries in vtable will point to the implementation of functions from the base interfaces, such as QueryInterface, AddRef ... of IUnknown. So think whether ur plan is going to work our or not..
-
Hello, How to iterate (infact access) the vtable of COM coclass(that will implement the methods of its exposed interfaces).? Only I need to access vtable where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum" Regards Muhammad Usman Khalil
You're going about things the wrong way. Getting the v-table's address is no problem. Doing something useful with it will be. All it is an array of function pointers. The pointers have no type information associated with them. It sounds like you should look into type libraries (see the ITypeLib[^] interface) or automation[^].
Steve
-
You're going about things the wrong way. Getting the v-table's address is no problem. Doing something useful with it will be. All it is an array of function pointers. The pointers have no type information associated with them. It sounds like you should look into type libraries (see the ITypeLib[^] interface) or automation[^].
Steve
I have got the addresses of functions from vtable but in little wiered manner. like typedef void (*FN)(void) FN pFn=0 int* dwPtr= (int*)pSomeInterface; pFn=(FN)*((int*)*(&dwPtr[Count])+1);//will give the address of QueryInterface pFn=(FN)*((int*)*(&dwPtr[Count])+2);//will give the address of AddRef pFn=(FN)*((int*)*(&dwPtr[Count])+3);say release pFn=(FN)*((int*)*(&dwPtr[Count])+6);//and finally my method Sum but this is all hardcoded stuff and little wiered. I in a search of some generic usefull method to lookup their addresses and then I NEED their NAME as well so that which ever at runtime I give the name as function my app should traverse and call only that method
-
I have got the addresses of functions from vtable but in little wiered manner. like typedef void (*FN)(void) FN pFn=0 int* dwPtr= (int*)pSomeInterface; pFn=(FN)*((int*)*(&dwPtr[Count])+1);//will give the address of QueryInterface pFn=(FN)*((int*)*(&dwPtr[Count])+2);//will give the address of AddRef pFn=(FN)*((int*)*(&dwPtr[Count])+3);say release pFn=(FN)*((int*)*(&dwPtr[Count])+6);//and finally my method Sum but this is all hardcoded stuff and little wiered. I in a search of some generic usefull method to lookup their addresses and then I NEED their NAME as well so that which ever at runtime I give the name as function my app should traverse and call only that method
typedef void (*FN)(void)
using FN, how are you going to call those methods like QueryInterface, AddRef.. as they take various number of arguments? u may be able to call without errors, bt result will be unexpected. without having specific info about the functions in interface, u won't be able to proceed..
-
typedef void (*FN)(void)
using FN, how are you going to call those methods like QueryInterface, AddRef.. as they take various number of arguments? u may be able to call without errors, bt result will be unexpected. without having specific info about the functions in interface, u won't be able to proceed..
Yeah true.!! but _asm patch helped me out in this regard. _asm { push argument_1 push argument_2 call proc ;function address } Here suppose i have given all info (parameters or arguments) at run time for NOW(Which I have passed it on runtime console). For future(might be later) I will load every thing from TLB's. e.g (How to know that QueryInterface taking 3 params of different type? This is ITypeLibe which provides information from TLB of that Component which I can query from registry to load specific TLB and give me specific function signature and types). Hence I got all params and function names as well(Which I can decipher from signature working with RE's(regular expression)). But Now I need to call the function, which would have specific address(NOT KNOWN) arguments(parameters) which I have collected from TLB, and name as well. How that address corresponds to that function name to which I am going to call. For this I need to traverse vtable which is holding functional addresses, LASTLY need to correspond function address with NAME of that function. This is I dont know. How? More over one function with the same name may appear in vtable(Overloading case). In that case we need to distinguish function names w.r.t their addresses. How to tackle ?
-
I need to call all the functions of COM Interface exposed methods at runtime. For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime. Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time. Any Suggestions?
Even if you get the function pointers this way, how to get the function signature (arguments and types)? You may have to use type library to get more details about the interface functions and supported interfaces.
-
Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?
Here is a link to very extensive work & code concerning this, that is, dumping VTables and VPtrs... http://www.jose.it-berater.org/smfforum/index.php?board=362.0