News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Saving the icon of an executable

Started by Vortex, October 24, 2024, 06:27:19 AM

Previous topic - Next topic

Vortex

Saving the icon of an executable with OLE function and COM.

.code

start:

    invoke      LoadLibrary,ADDR file1
    test        eax,eax
    jnz         @f
    invoke      StdOut,ADDR errmsg
    invoke      ExitProcess,0
@@:
    mov         hLib,eax
    invoke      LoadIcon,eax,100
    mov         hIcon,eax

    mov         pd.cbSizeofstruct,SIZEOF PICTDESC   ; initialize the PICTDESC structure
    mov         pd.picType,PICTYPE_ICON
    push        hIcon
    pop         pd.icon.hicon
    invoke      OleCreatePictureIndirect,ADDR pd,ADDR IID_IPicture,TRUE,ADDR pBitmap
                                                    ; create the OLE image
    invoke      CreateStreamOnHGlobal,NULL,TRUE,ADDR pStream
                                                    ; create the destination stream to save the icon

    coinvoke    pBitmap,IPicture,SaveAsFile,pStream,TRUE,<OFFSET pcbSize>
    invoke      GetHGlobalFromStream,pStream,ADDR hGlobal
    invoke      GlobalLock,hGlobal                  ; get the address pointing the icon in memory
    invoke      WriteFileToDisc,ADDR IconName,eax,pcbSize
                                                    ; write the icon to disc
    coinvoke    pBitmap,IPicture,Release
    coinvoke    pStream,IStream,Release
    invoke      FreeLibrary,hLib
    invoke      ExitProcess,0