flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved]WIC+D2D1+LayeredWindow+headache

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
Hi
Please read the end of conversation to see my current issue


Last edited by Overclick on 19 Aug 2021, 16:09; edited 3 times in total
Post 25 Jul 2021, 00:01
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
Seems it is IWICImagingFactory::CreateBitmapFromMemory method, just don't understand what exactly the stride means?..

Also I don't need to use Res for storing image files. I can preload them to data section directly.
Code:
.data
 Img1      file '1.png'
           sImg1 = $-Img1
 Img2      file '2.png'
           sImg2 = $-Img2
 Img3      file '3.png'
           sImg3 = $-Img3
    
Post 26 Jul 2021, 01:07
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18183
Location: In your JS exploiting you and your system
revolution
You can load any data into any place you want within the exe.

The only reason to use the resource section is to allow other programs to read and/or write and/or update data from/into the exe file without having to recompile from source.
Post 26 Jul 2021, 01:46
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
Res is easy to manage, that why we use it for many options it's provide: manifest, dialog items, etc.
Many converter examples works by external image files, not ID of that preloaded files. I had few options to use:
1) WIC with temporary files
2) WIC with external resourses
3) ID based conversion technique like GDI+,OLE,etc
4) ... or do as I said to keep it working by WIC.
Post 26 Jul 2021, 08:12
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1626
Furs
Overclick wrote:
Seems it is IWICImagingFactory::CreateBitmapFromMemory method, just don't understand what exactly the stride means?..
Stride is a horizontal line of the bitmap, in memory.

For 24-bit RGB, it's ROUND_TO_DWORD(width * 3) bytes (it always rounds up to a DWORD, i.e. 4 bytes). So it can have padding if width isn't divisible by 4.
Post 26 Jul 2021, 12:10
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
Thanks for your help but if it always rounds up to DWORD why they made it editable? And isn't it Width * 4 then?
Post 27 Jul 2021, 09:24
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1626
Furs
Overclick wrote:
Thanks for your help but if it always rounds up to DWORD why they made it editable? And isn't it Width * 4 then?
24-bit RGB only stores 3 bytes per pixel (no alpha).

For example consider width == 7, 24 bpp, a stride would be:
Code:
ROUND_TO_DWORD(7*3) = 24  (from 21, so 3 extra bytes of padding at the end)    
Meanwhile a 32 bpp with alpha (4 bytes per pixel) would be:
Code:
7*4 = 28    
Post 27 Jul 2021, 12:31
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
What I'm doing wrong?
Code:
.idata
        import  D2d1,\
                        D2D1CreateFactory,'D2D1CreateFactory'
        import  ole32,\ 
                        CoInitializeEx,'CoInitializeEx',\ 
                        CoUninitialize,'CoUninitialize',\ 
                        CoCreateInstance,'CoCreateInstance',\
                        CoGetClassObject,'CoGetClassObject',\
                        CoTaskMemFree,'CoTaskMemFree'
.data
        interface               IWICImagingFactory,\
                        QueryInterface,\
                    AddRef,\
                    Release,\
                    CreateDecoderFromFilename,\
                    CreateDecoderFromStream,\
                    CreateDecoderFromFileHandle,\
                    CreateComponentInfo,\
                    CreateDecoder,\
                    CreateEncoder,\
                    CreatePalette,\
                    CreateFormatConverter,\
                    CreateBitmapScaler,\
                    CreateBitmapClipper,\
                    CreateBitmapFlipRotator,\
                    CreateStream,\
                    CreateColorContext,\
                    CreateColorTransformer,\
                    CreateBitmap,\
                    CreateBitmapFromSource,\
                    CreateBitmapFromSourceRect,\
                    CreateBitmapFromMemory,\
                    CreateBitmapFromHBITMAP,\
                    CreateBitmapFromHICON,\
                    CreateComponentEnumerator,\
                    CreateFastMetadataEncoderFromDecoder,\
                    CreateFastMetadataEncoderFromFrameDecode,\
                    CreateQueryWriter,\
                    CreateQueryWriterFromReader
                    
        interface               ID2D1Factory,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        ReloadSystemMetrics,\
                                        GetDesktopDpi,\
                                        CreateRectangleGeometry,\
                                        CreateRoundedRectangleGeometry,\
                                        CreateEllipseGeometry,\
                                        CreateGeometryGroup,\
                                        CreateTransformedGeometry,\
                                        CreatePathGeometry,\
                                        CreateStrokeStyle,\
                                        CreateDrawingStateBlock,\
                                        CreateWicBitmapRenderTarget,\
                                        CreateHwndRenderTarget,\
                                        CreateDxgiSurfaceRenderTarget,\
                                        CreateDCRenderTarget
                                        
        interface               ID2D1RenderTarget,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetFactory,\
                                        CreateBitmap,\
                                        CreateBitmapFromWicBitmap,\
                                        CreateSharedBitmap,\
                                        CreateBitmapBrush,\
                                        CreateSolidColorBrush,\
                                        CreateGradientStopCollection,\
                                        CreateLinearGradientBrush,\
                                        CreateRadialGradientBrush,\
                                        CreateCompatibleRenderTarget,\
                                        CreateLayer,\
                                        CreateMesh,\
                                        DrawLine,\
                                        DrawRectangle,\
                                        FillRectangle,\
                                        DrawRoundedRectangle,\
                                        FillRoundedRectangle,\
                                        DrawEllipse,\
                                        FillEllipse,\
                                        DrawGeometry,\
                                        FillGeometry,\
                                        FillMesh,\
                                        FillOpacityMask,\
                                        DrawBitmap,\
                                        DrawText,\
                                        DrawTextLayout,\
                                        DrawGlyphRun,\
                                        SetTransform,\
                                        GetTransform,\
                                        SetAntialiasMode,\
                                        GetAntialiasMode,\
                                        SetTextAntialiasMode,\
                                        GetTextAntialiasMode,\
                                        SetTextRenderingParams,\
                                        GetTextRenderingParams,\
                                        SetTags,\
                                        GetTags,\
                                        PushLayer,\
                                        PopLayer,\
                                        Flush,\
                                        SaveDrawingState,\
                                        RestoreDrawingState,\
                                        PushAxisAlignedClip,\
                                        PopAxisAlignedClip,\
                                        Clear,\
                                        BeginDraw,\
                                        EndDraw,\
                                        GetPixelFormat,\
                                        SetDpi,\
                                        GetDpi,\
                                        GetSize,\
                                        GetPixelSize,\
                                        GetMaximumBitmapSize,\
                                        IsSupported
        
        interface               ID2D1Bitmap,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetFactory,\
                                        GetSize,\
                                        GetPixelSize,\
                                        GetPixelFormat,\
                                        GetDpi,\
                                        CopyFromBitmap,\
                                        CopyFromRenderTarget,\
                                        CopyFromMemory
        
        
        interface               IWICBitmapDecoder,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        QueryCapability,\
                                        Initialize,\
                                        GetContainerFormat,\
                                        GetDecoderInfo,\
                                        CopyPalette,\
                                        GetMetadataQueryReader,\
                                        GetPreview,\
                                        GetColorContexts,\
                                        GetThumbnail,\
                                        GetFrameCount,\
                                        GetFrame
        
        interface               IWICBitmap,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels,\
                                        Lock,\
                                        SetPalette,\
                                        SetResolution
        
        
        
        
        
        
        
        
        
        pIWICFactory    IWICImagingFactory
        pD2DFactory             ID2D1Factory
        pDecoder                IWICBitmapDecoder
        pIWICBitmap             IWICBitmap
        pD2D1Bitmap             ID2D1Bitmap
        pRenderTarget   ID2D1RenderTarget
        
CLSID_WICImagingFactory                 GUID cacaf262-9370-4615-a13b-9f5539da4c0a
IID_IWICImagingFactory                  GUID ec5ec8a9-c395-4314-9c77-54d7a935ff70
IID_ID2D1Factory                        GUID 06152247-6f50-465a-9245-118bfd3b6007
GUID_WICPixelFormat32bppPBGRA           GUID 6fddc324-4e03-4bfe-b185-3d77768dc910
        
        CLSCTX_INPROC_SERVER = 1
        COINIT_APARTMENTTHREADED = 0x2
        COINIT_DISABLE_OLE1DDE = 0x4
        D2D1_FACTORY_TYPE_SINGLE_THREADED = 0
        
.code
        invoke  CoInitializeEx,0,\
                        COINIT_APARTMENTTHREADED or COINIT_DISABLE_OLE1DDE
        invoke  CoCreateInstance,CLSID_WICImagingFactory,0,\
                        CLSCTX_INPROC_SERVER,IID_IWICImagingFactory,pIWICFactory
        invoke  D2D1CreateFactory,D2D1_FACTORY_TYPE_SINGLE_THREADED,\
                        IID_ID2D1Factory,0,pD2DFactory    ;rax 0 but last error "no procedure found
        cominvk pIWICFactory,CreateBitmapFromMemory,640,480,\
                        GUID_WICPixelFormat32bppPBGRA,640*4,640*480*4,\
                        image,pIWICBitmap       ;rax 0
        cominvk pRenderTarget,CreateBitmapFromWicBitmap,[pIWICBitmap],0,\
                        pD2D1Bitmap    ;it drops app
.data
        image       file 'Res\Tray.png'
        db 1228800 dup(0)    
Post 04 Aug 2021, 07:12
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18183
Location: In your JS exploiting you and your system
revolution
Your .code section just drops off to nothing. No ret, or jmp, or anything.
Post 04 Aug 2021, 07:17
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
Quote:

Your .code section just drops off to nothing. No ret, or jmp, or anything.

It is cutted to show required parts. Read the comments
Post 04 Aug 2021, 16:27
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
1) I have to check the pD2DFactory created correctly
2) Check syntax of pRenderTarget,CreateBitmapFromWicBitmap


Description:
Filesize: 29.92 KB
Viewed: 1132 Time(s)

Capture.PNG


Post 04 Aug 2021, 16:31
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1080
Roman
Cool error info!
How you do this? How get registers values?
Post 05 Aug 2021, 10:28
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
Quote:

How you do this?

Macro. I want to rebuild it to dlgbox with memory mapping, float converter and more registers.
Quote:

How get registers values?

Save them to stack and load values from there.
Post 06 Aug 2021, 04:46
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
1) At debugger seems ok. I lost in deep jumps of function where it sets error code 127
2) In deep jumps it trying to read from zero address taken from data section. I'm not sure what it is. Seems it's one of the I-pointers prepared incorrectly.
Post 06 Aug 2021, 07:01
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
Code:
macro cominvk object,proc,[arg]
 { common
    assert defined object#.com.object ; must be a COM object
    macro call dummy
    \{ mov rax,[rcx]                     ;that is the place where read from zero
       call [rax+object#.#proc] \}
    fastcall ,[object],arg
    purge call }
    

Is that mean my ID2D1RenderTarget Interface wrongly implemented or I have to initialize it somehow?


Description:
Filesize: 11.74 KB
Viewed: 1067 Time(s)

Capture.PNG


Post 06 Aug 2021, 09:38
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3293
Location: vpcmipstrm
bitRAKE
When that is zero, it lacks a pointer to an interface. Although it may be defined correctly, you'll need to back up to where the interface pointer is populated. Typically, the address of that location is passed into another function.

_________________
¯\(°_o)/¯ unlicense.org
Post 06 Aug 2021, 10:56
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
I trying to do that by
Code:
cominvk pD2DFactory,CreateWicBitmapRenderTarget,pIWICBitmap,0,\
                        pRenderTarget
    

It drops too. Maybe I need to pass all of arguments instead of Null. I'll try it later.
But I never seen that on c/c++ examples
Post 06 Aug 2021, 11:13
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3293
Location: vpcmipstrm
bitRAKE
Sure love to see the assembly for that. Difficult to grok the types on these abstractions. For example, that last one should be a pointer to a pointer. If I saw an ADDR in there I'd be more comfortable.

_________________
¯\(°_o)/¯ unlicense.org
Post 06 Aug 2021, 15:19
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
I added BitmapProperties arg to CreateWicBitmapRenderTarget and now it doesn't drop but 0x80070057
Code:
struct  D2D1_PIXEL_FORMAT
                format          dw 0
                alphaMode       dw 0
        ends
        struct  D2D1_BITMAP_PROPERTIES
                pixelFormat     D2D1_PIXEL_FORMAT
                dpiX            dd 96.0f
                dpiY            dd 96.0f
        ends
        BitmapProperties        D2D1_BITMAP_PROPERTIES    
Post 07 Aug 2021, 07:29
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 391
Location: Ukraine
Overclick
OMG IWICBitmapSource is an Interface too Mad
Post 07 Aug 2021, 08:20
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.