Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompiling a Method Implemented with extern keyword

when I decompiled a dll file with Reflector, I saw that the method I need is implemented as below. What does it mean? Is that possible to see the source code behind it?

[return: MarshalAs(UnmanagedType.BStr)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime), DispId(0x3a)]
public virtual extern string GetCOLDText([In] int PageNumber, [In] int Row, [In] int Column, [In, Optional, DefaultParameterValue(0x7fffffff)] int Length);

Regards.

like image 556
Feyyaz Avatar asked Jan 20 '11 08:01

Feyyaz


1 Answers

This is what you see when you use Reflector to look at a COM interop library that was created by tlbimp.exe. Or by adding a reference in the IDE to a COM server from the COM tab or Browse tab, same thing.

If you look at the outer class or interface that contains this method then you'll see the COM coclass or interface that contains this method. Important attributes on it are [ComImport] to indicate that it is implemented in another DLL and [Guid], the all important interface IID or coclass CLSID. COM classes and interfaces are uniquely identified by a guid, not a name. The CLSID guid is present in the registry, HKCR\CLSID\{guid} key.

COM servers like this are almost always implemented in an unmanaged language, C++ is most typical, but also Delphi or VB6. Decompiling C++ code after it is compiled is a fruitless exercise but you can get something out of Dumpbin.exe with the /disasm option. Assembly language programming skills and reams of free time are required. It is almost always expressly forbidden in the license agreement.

like image 95
Hans Passant Avatar answered Sep 23 '22 15:09

Hans Passant