The MASM Forum

General => The Campus => Topic started by: GoneFishing on March 06, 2013, 01:29:08 AM

Title: Debugging Tools for Windows SDK API
Post by: GoneFishing on March 06, 2013, 01:29:08 AM
I'm trying to call DebugCreate function in MASM.
It's described in MSDN as follows:

                                 HRESULT DebugCreate(
                                                          _In_   REFIID InterfaceId,
                                                          _Out_  PVOID *Interface
                                                     );

IID of IDebugControl is defined in dbgeng.h :
   
/* 5182e668-105e-416e-ad92-24ef800424ba */
DEFINE_GUID(IID_IDebugControl, 0x5182e668, 0x105e, 0x416e,
                          0xad, 0x92, 0x24, 0xef, 0x80, 0x04, 0x24, 0xba);


I've never dealt with GUIDs . How do I define it in MASM?

Thanks 
Title: Re: Debugging Tools for Windows SDK API
Post by: dedndave on March 06, 2013, 01:47:20 AM
        .DATA
IID_IDebugControl GUID <5182E668h,105Eh,416Eh,<0ADh,92h,24h,0EFh,80h,4,24h,0BAh>>


it may be "more correct" to place it in the .CONST section
however, that creates another section
as long as your code is good, and doesn't overwrite the value, it's ok to place it in .DATA

you could place it in the .CODE section, i suppose   :P
Title: Re: Debugging Tools for Windows SDK API
Post by: GoneFishing on March 06, 2013, 04:17:52 AM
Now  it's S_OK!
THANKS!
Title: Re: Debugging Tools for Windows SDK API
Post by: TouEnMasm on March 14, 2013, 03:39:25 AM

Perhaps can you just translate dbgeng.h with this
http://masm32.com/board/index.php?topic=576.msg4665#msg4665 (http://masm32.com/board/index.php?topic=576.msg4665#msg4665)

All the header's of the Debugging Tools for Windows are easily translatable.
Title: Re: Debugging Tools for Windows SDK API
Post by: GoneFishing on April 03, 2013, 02:00:14 AM
Assembling the code I receive the following error:
QuoteAssembling: test.asm

***********
ASCII build
***********

test.asm(166) : error A2114: INVOKE argument type mismatch : argument : 2
IDebugClient(20): Macro Called From
  test.asm(166): Main Line Code
_
Assembly Error

test.asm(166)
IDebugClient CreateProcess, 0, offset debuggee, DEBUG_PROCESS

SDK API:
QuoteHRESULT
  IDebugClient::CreateProcess(
    IN ULONG64  Server,
    IN PSTR  CommandLine,
    IN ULONG  CreateFlags
    );

dbgeng.inc:
IDebugClient_CreateProcess TYPEDEF  PROTO :DWORD ,:QWORD ,:DWORD ,:DWORD
FIDebugClient_CreateProcess TYPEDEF PTR  IDebugClient_CreateProcess

... ... ...    ... ... ...   ... ... ...

STIDebugClient STRUCT
...
CreateProcess FIDebugClient_CreateProcess  ?
...
STIDebugClient ENDS

... ... ...    ... ... ...   ... ... ...

IDebugClient MACRO  Function:REQ, args:VARARG
; definition de la macro locale InvokeInterface
    LOCAL InvokeInterface, arg
    FOR arg, <args>     ;verifier que edx n'est pas dans la liste d'arguments args
        IFIDNI <&arg>, <edx> ;
            .ERR <edx is not allowed as a coinvoke parameter>
        ENDIF
    ENDM
    IFIDNI <&pInterface>, <edx>
        .ERR <edx is not allowed as a coinvoke parameter>
    ENDIF
;InvokeInterface = concatene ...CATSTR(concatene) MACRO instruction MASM32
;---------- on doit mettre ppv en premier argument -----------------------------------
    InvokeInterface CATSTR <invoke (STIDebugClient PTR[edx]).>,<&Function,ppvIDebugClient>
    IFNB <args>     ; add the list of parameter arguments if any
        InvokeInterface CATSTR InvokeInterface, <, >, <&args>
    ENDIF
;   forme les lignes de codes
    mov edx, ppvIDebugClient
    mov edx, [edx]
    InvokeInterface
ENDM




Just cannot figure out what's wrong :(

Dbgeng.h was converted to inc with the headinc tool (adviced by ToutEnMasm, many thanks to him!)


Title: Re: Debugging Tools for Windows SDK API
Post by: qWord on April 03, 2013, 02:10:39 AM
Seems like that you interchanged the types of the first and the second argument (declaration of IDebugClient_CreateProcess). Furthermore, INVOKE can't handle 64Bit constants: you might simply spilt the QWORD in two DWORDs. Alternatively you can use EDX::EAX or a variable to pass the argument.
Title: Re: Debugging Tools for Windows SDK API
Post by: japheth on April 03, 2013, 02:11:57 AM
Quote from: vertograd on April 03, 2013, 02:00:14 AM
Just cannot figure out what's wrong :(

Can't help directly, but I once also wrote a debugger based on the MS debug engine, and IDebugClient::CreateProcess() is also used there of course. It worked. By comparing my implementation with yours you may get an idea what's wrong.

www.japheth.de/Download/debxxf/CDBA.zip (http://www.japheth.de/Download/debxxf/CDBA.zip)
Title: Re: Debugging Tools for Windows SDK API
Post by: GoneFishing on April 03, 2013, 02:22:31 AM
Thank you, guys!
qWord:
          Hi, I'm very glad that your answer was the first :biggrin:
          I'll try changing QWORD to DWORD and will see the result

japheth:
          already downloading it
Title: Re: Debugging Tools for Windows SDK API
Post by: GoneFishing on April 04, 2013, 05:55:30 AM
Isn't it ironic, I was supplied with an excellent source code and yet I cannot even compile it :biggrin:

QuoteCDBA.ASM: 1023 lines, 2 passes, 829 ms, 0 warnings, 0 errors
CDBA.obj : error LNK2005: _start already defined in CDBA.obj
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugClient
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugControl
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugEventCallbacks
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugInputCallbacks
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugOutputCallbacks
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugSymbols
CDBA.exe : fatal error LNK1120: 6 unresolved externals
_
Link error

I want to compile it with debugging options
japheth, please help if you see it
Title: Re: Debugging Tools for Windows SDK API
Post by: japheth on April 04, 2013, 07:06:28 AM
Quote from: vertograd on April 04, 2013, 05:55:30 AM
QuoteCDBA.ASM: 1023 lines, 2 passes, 829 ms, 0 warnings, 0 errors
CDBA.obj : error LNK2005: _start already defined in CDBA_test.obj
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugClient
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugControl
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugEventCallbacks
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugInputCallbacks
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugOutputCallbacks
CDBA.obj : error LNK2001: unresolved external symbol _IID_IDebugSymbols
CDBA.exe : fatal error LNK1120: 6 unresolved externals
_
Link error

I want to compile it with debugging options
japheth, please help if you see it

It looks like the linker can't find a few IIDs. I did put these IIDs into uuid.lib supplied with WinInc, just for convenience.
Title: Re: Debugging Tools for Windows SDK API
Post by: GoneFishing on April 04, 2013, 11:33:47 PM
Japheth, thank you for  your help and providing the whole set of tools for coding !

I downloaded WinInc. After that I had to change only includelib path to lib\uuid.lib . Compiles and runs perfectly :t

But now I came upon another problem : assembling with -Zi argument  either in JWASM or ML ends up with LINK ERROR.
jwasm:
QuoteCDBA.ASM: 1023 lines, 2 passes, 703 ms, 0 warnings, 0 errors
CDBA.obj : error LNK2005: _start already defined in CDBA_test.obj
CDBA.exe : fatal error LNK1169: one or more multiply defined symbols found

ml(6.14):
QuoteAssembling: CDBA.asm
LINK : error LNK2001: unresolved external symbol _start
CDBA.exe : fatal error LNK1120: 1 unresolved externals

What am I to do to fix it?

Title: Re: Debugging Tools for Windows SDK API
Post by: japheth on April 05, 2013, 12:05:22 AM
Quote from: vertograd on April 04, 2013, 11:33:47 PM
What am I to do to fix it?

There seems to be a strange error in jwasm and masm - the entry symbol must be declared public if -Zi is set:


start proc c public

invoke main
invoke ExitProcess, eax

start endp


Note that the source contains a option proc:private, hence procedures are not automatically public here.
Title: Re: Debugging Tools for Windows SDK API
Post by: GoneFishing on April 06, 2013, 04:13:34 AM
Now I see ... and am going to read MASM basics and your source code with more attention :biggrin:
Thanks.