More on WinRT

More on WinRT

Postby Antonio Linares » Sat Apr 16, 2016 8:07 am

Some WinRT tests

winrt2.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local pString, nLength

   RoInitialize( 1 )
   
   WindowsCreateString( AnsiToWide( "Hello" ), Len( AnsiToWide( "Hello" ) ), @pString )

   WindowsGetStringRawBuffer( pString, @nLength )
   
   MsgInfo( nLength )

   WindowsDeleteString( pString )
   
   RoUninitialize()

return nil

DLL FUNCTION RoInitialize( nType AS LONG ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoUninitialize() AS VOID PASCAL LIB "combase.dll"

DLL FUNCTION WindowsCreateString( cWideText AS LPSTR, nLength AS LONG, @pString AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"
   
DLL FUNCTION WindowsDeleteString( pString AS PTR ) AS LONG PASCAL LIB "combase.dll"  

DLL FUNCTION WindowsGetStringRawBuffer( pString AS PTR, @nLength AS LONG ) AS LPSTR PASCAL LIB "combase.dll"
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: More on WinRT

Postby Antonio Linares » Sat Apr 16, 2016 8:46 am

In progress, not ready yet

winrt2.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local pString, cIID, pFactory

   RoInitialize( 1 )

   pString = WinRTString( "Windows.UI.Notifications.ToastNotificationManager" )

   // "50AC103F-D235-4598-BBEF-98FE4D1A3AD4"

   cIID = Chr( 0x3F ) + Chr( 0x10 ) + Chr( 0xAC ) + Chr( 0x50 ) + ;
          Chr( 0x35 ) + Chr( 0xD2 ) + Chr( 0x98 ) + Chr( 0x45 ) + ;
          Chr( 0xBB ) + Chr( 0xEF ) + Chr( 0x98 ) + Chr( 0xFE ) + ;
          Chr( 0x4D ) + Chr( 0x1A ) + Chr( 0x3A ) + Chr( 0xD4 )

   MsgInfo( NumToHex( RoGetActivationFactory( pString, cIID, @pFactory ) ) )
   
   // MsgInfo( pFactory )
                                         
   WindowsDeleteString( pString )
   
   RoUninitialize()

return nil

function WinRTString( cText )

   local pString
   
   WindowsCreateString( AnsiToWide( cText ), Len( AnsiToWide( cText ) ), @pString )

return pString

DLL FUNCTION RoInitialize( nType AS LONG ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoUninitialize() AS VOID PASCAL LIB "combase.dll"

DLL FUNCTION WindowsCreateString( cWideText AS LPSTR, nLength AS LONG, @pString AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"
   
DLL FUNCTION WindowsDeleteString( pString AS PTR ) AS LONG PASCAL LIB "combase.dll"  

DLL FUNCTION WindowsGetStringRawBuffer( pString AS PTR, @nLength AS LONG ) AS LPSTR PASCAL LIB "combase.dll"

DLL FUNCTION RoGetActivationFactory( pString AS PTR, REFIID AS PTR, @pFactory AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: More on WinRT

Postby Antonio Linares » Sun Apr 17, 2016 4:35 am

This is working fine :-)

winrt2.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local pString, cIID, pFactory

   RoInitialize( 1 )

   pString = WinRTString( "Windows.UI.Notifications.ToastNotificationManager" )

   // "50AC103F-D235-4598-BBEF-98FE4D1A3AD4"

   cIID = Chr( 0x3F ) + Chr( 0x10 ) + Chr( 0xAC ) + Chr( 0x50 ) + ;
          Chr( 0x35 ) + Chr( 0xD2 ) + Chr( 0x98 ) + Chr( 0x45 ) + ;
          Chr( 0xBB ) + Chr( 0xEF ) + Chr( 0x98 ) + Chr( 0xFE ) + ;
          Chr( 0x4D ) + Chr( 0x1A ) + Chr( 0x3A ) + Chr( 0xD4 )

   MsgInfo( NumToHex( RoGetActivationFactory( pString, cIID, @pFactory ) ) )
   
   MsgInfo( pFactory )
                                         
   WindowsDeleteString( pString )
   
   RoUninitialize()

return nil

function WinRTString( cText )

   local pString
   
   WindowsCreateString( AnsiToWide( cText ), Len( cText ), @pString )

return pString

DLL FUNCTION RoInitialize( nType AS LONG ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoUninitialize() AS VOID PASCAL LIB "combase.dll"

DLL FUNCTION WindowsCreateString( cWideText AS LPSTR, nLength AS LONG, @pString AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"
   
DLL FUNCTION WindowsDeleteString( pString AS PTR ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION WindowsGetStringRawBuffer( pString AS PTR, @nLength AS LONG ) AS LPSTR PASCAL LIB "combase.dll"

DLL FUNCTION RoGetActivationFactory( pString AS PTR, REFIID AS LPSTR, @pFactory AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION WindowsCompareStringOrdinal( pString1 AS PTR, pString2 AS PTR, @nResult AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoActivateInstance( pString AS PTR, @pInstance AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: More on WinRT

Postby Antonio Linares » Sun Apr 17, 2016 9:49 pm

Inspecting a WinRT IInspectable :-)

We get three values. Searching for them in the registry we get:
{00000035-0000-0000-C000-000000000046} --> IActivationFactory
{50AC103F-D235-4598-BBEF-98FE4D1A3AD4} --> IToastNotificationManagerStatics
{7AB93C52-0E48-4750-BA9D-1A4113981847} --> IToastNotificationManagerStatics2

https://msdn.microsoft.com/en-us/library/windows/desktop/br205821(v=vs.85).aspx

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local pString, cIID, pFactory

   RoInitialize( 1 )

   pString = WinRTString( "Windows.UI.Notifications.ToastNotificationManager" )

   // "50AC103F-D235-4598-BBEF-98FE4D1A3AD4"

   cIID = Chr( 0x3F ) + Chr( 0x10 ) + Chr( 0xAC ) + Chr( 0x50 ) + ;
          Chr( 0x35 ) + Chr( 0xD2 ) + Chr( 0x98 ) + Chr( 0x45 ) + ;
          Chr( 0xBB ) + Chr( 0xEF ) + Chr( 0x98 ) + Chr( 0xFE ) + ;
          Chr( 0x4D ) + Chr( 0x1A ) + Chr( 0x3A ) + Chr( 0xD4 )

   RoGetActivationFactory( pString, cIID, @pFactory )
   WindowsDeleteString( pString );
   
   XBrowser( Inspectable_GetIids( pFactory ) )
   
   RoUninitialize()

return nil

function WinRTString( cText )

   local pString
   
   WindowsCreateString( AnsiToWide( cText ), Len( cText ), @pString )

return pString

DLL FUNCTION RoInitialize( nType AS LONG ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoUninitialize() AS VOID PASCAL LIB "combase.dll"

DLL FUNCTION WindowsCreateString( cWideText AS LPSTR, nLength AS LONG, @pString AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"
   
DLL FUNCTION WindowsDeleteString( pString AS PTR ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION WindowsGetStringRawBuffer( pString AS PTR, @nLength AS LONG ) AS LPSTR PASCAL LIB "combase.dll"

DLL FUNCTION RoGetActivationFactory( pString AS PTR, REFIID AS LPSTR, @pFactory AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoActivateInstance( pString AS PTR, @pInstance AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"

#pragma BEGINDUMP

#include <Windows.h>
#include <hbapi.h>

typedef HANDLE HSTRING;
typedef interface IInspectable IInspectable;   
   
typedef struct IInspectableVtbl
{
   BEGIN_INTERFACE
       
   HRESULT ( STDMETHODCALLTYPE * QueryInterface )(
       IInspectable * This,
       REFIID riid,
       void ** ppvObject );
       
   ULONG ( STDMETHODCALLTYPE * AddRef )(
       IInspectable * This );
       
   ULONG ( STDMETHODCALLTYPE * Release )(
       IInspectable * This);
       
   HRESULT ( STDMETHODCALLTYPE * GetIids )(
       IInspectable * This,
       ULONG * iidCount,
       IID ** iids );
       
   HRESULT ( STDMETHODCALLTYPE * GetRuntimeClassName )(
       IInspectable * This,
       HSTRING * className );
       
   HRESULT ( STDMETHODCALLTYPE * GetTrustLevel )(
       IInspectable * This,
       int * trustLevel );
       
   END_INTERFACE
} IInspectableVtbl;

interface IInspectable
{
   CONST_VTBL struct IInspectableVtbl * lpVtbl;
};

HB_FUNC( INSPECTABLE_GETIIDS )
{
   IInspectable * pInsp = ( IInspectable * ) hb_parnl( 1 );
   ULONG iidCount = 0;
   IID * iids = NULL;
   unsigned int i;
   char buffer[ 80 ];
   
   pInsp->lpVtbl->GetIids( pInsp, &iidCount, &iids );
   
   hb_reta( iidCount );
   
   for( i = 0; i < iidCount; i++ )
   {
      wsprintf( buffer,
                "{%08lX-%04hX-%04hX-%02hX%02hX-%02hX%02hX%02hX%02hX%02hX%02hX}",
                iids[ i ].Data1, iids[ i ].Data2, iids[ i ].Data3,
                iids[ i ].Data4[ 0 ], iids[ i ].Data4[ 1 ], iids[ i ].Data4[ 2 ],
                iids[ i ].Data4[ 3 ], iids[ i ].Data4[ 4 ], iids[ i ].Data4[ 5 ],
                iids[ i ].Data4[ 6 ], iids[ i ].Data4[ 7 ] );                
      hb_storvc( ( const char * ) buffer, -1, i + 1 );
   }  

   // We must clean iids memory
   // CoTaskMemFree( iids );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: More on WinRT

Postby Antonio Linares » Sun Apr 17, 2016 11:13 pm

The size of the "Unknown" :-)

Code: Select all  Expand view
HB_FUNC( SIZEOFUNKNOWN )
{
   IUnknown unknown;
   
   hb_retnl( sizeof( * unknown.lpVtbl ) );
}  


it seems as we are quite close to "hack" WinRT ;-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: More on WinRT

Postby Antonio Linares » Mon Apr 18, 2016 10:33 am

WinRT hacked! :-)

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local pString, cIID, pFactory, pXml

   RoInitialize( 1 )

   pString = WinRTString( "Windows.UI.Notifications.ToastNotificationManager" )

   // "50AC103F-D235-4598-BBEF-98FE4D1A3AD4"

   cIID = Chr( 0x3F ) + Chr( 0x10 ) + Chr( 0xAC ) + Chr( 0x50 ) + ;
          Chr( 0x35 ) + Chr( 0xD2 ) + Chr( 0x98 ) + Chr( 0x45 ) + ;
          Chr( 0xBB ) + Chr( 0xEF ) + Chr( 0x98 ) + Chr( 0xFE ) + ;
          Chr( 0x4D ) + Chr( 0x1A ) + Chr( 0x3A ) + Chr( 0xD4 )

   RoGetActivationFactory( pString, cIID, @pFactory )
   WindowsDeleteString( pString );

   MsgInfo( NumToHex( WinRTMethod( pFactory, 9, 3, @pXml ) ) ) // 9: Ninth method, 3: fourth template

   MsgInfo( pXml )

   RoUninitialize()

return nil

function WinRTString( cText )

   local pString
   
   WindowsCreateString( AnsiToWide( cText ), Len( cText ), @pString )

return pString

DLL FUNCTION RoInitialize( nType AS LONG ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoUninitialize() AS VOID PASCAL LIB "combase.dll"

DLL FUNCTION WindowsCreateString( cWideText AS LPSTR, nLength AS LONG, @pString AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"
   
DLL FUNCTION WindowsDeleteString( pString AS PTR ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoGetActivationFactory( pString AS PTR, REFIID AS LPSTR, @pFactory AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"

#pragma BEGINDUMP

#include <Windows.h>
#include <hbapi.h>

typedef void * ( __stdcall * PMETHOD0 )( void * );
typedef void * ( __stdcall * PMETHOD2 )( void *, void *, void * );

HB_FUNC( WINRTMETHOD ) // pInspectable, nMethod, params...
{
   IUnknown * unknown = ( IUnknown * ) hb_parnll( 1 );
   void * pMethod = ( ( void ** ) unknown->lpVtbl )[ hb_parnl( 2 ) - 1 ];
   IUnknown * pReturn;

   switch( hb_pcount() )
   {
      case 4:
         hb_retnll( ( HB_LONGLONG ) ( ( PMETHOD2 ) pMethod )( unknown, ( void * ) hb_parnll( 3 ), &pReturn ) );
   }

   if( HB_ISBYREF( 4 ) )
      hb_storvnll( ( HB_LONGLONG ) pReturn, 4 );
}  

#pragma ENDDUMP


See the types of the watched variables:
Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests