-
Antonio Linares
- Site Admin
- Posts: 42519
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 75 times
-
Contact:
Post
by Antonio Linares »
This is a virtual machine "dirty" hack
![Smile :-)](./images/smilies/icon_smile.gif)
but can result very useful under some circunstances. I place a copy here just in case someone want to test it:
test.prg
Code: Select all | Expand
#include "FiveWin.ch"
static pOld
function Main()
pOld := FunSwap( "TIME", "MYTIME" )
MsgInfo( Time() ) // We have replaced the original Time() function! :-)
return nil
function MyTime()
local uRet := ExecPtr( pOld ) // in case that we want to call the original function
return "now"
#pragma BEGINDUMP
#include <hbapi.h>
typedef void ( * PFUNC ) ( void );
HB_FUNC( FUNSWAP )
{
PHB_SYMB symFirst = hb_dynsymSymbol( hb_dynsymFindName( hb_parc( 1 ) ) );
PHB_SYMB symLast = hb_dynsymSymbol( hb_dynsymFindName( hb_parc( 2 ) ) );
PHB_FUNC pFirst = symFirst->value.pFunPtr;
symFirst->value.pFunPtr = symLast->value.pFunPtr;
hb_retnl( ( LONG ) pFirst );
}
HB_FUNC( EXECPTR )
{
PFUNC p = ( PFUNC ) hb_parnl( hb_pcount() );
p();
}
#pragma ENDDUMP
-
Antonio Linares
- Site Admin
- Posts: 42519
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 75 times
-
Contact:
Post
by Antonio Linares »
Another example:
test.prg
Code: Select all | Expand
#include "FiveWin.ch"
static pOld
function Main()
pOld := FunSwap( "DATE", "TOMORROW" )
MsgInfo( Date() ) // We have replaced the original Date() function! :-)
return nil
function Tomorrow()
local uRet := ExecPtr( pOld ) // in case that we want to call the original function
return uRet + 1
#pragma BEGINDUMP
#include <hbapi.h>
typedef void ( * PFUNC ) ( void );
HB_FUNC( FUNSWAP )
{
PHB_SYMB symFirst = hb_dynsymSymbol( hb_dynsymFindName( hb_parc( 1 ) ) );
PHB_SYMB symLast = hb_dynsymSymbol( hb_dynsymFindName( hb_parc( 2 ) ) );
PHB_FUNC pFirst = symFirst->value.pFunPtr;
symFirst->value.pFunPtr = symLast->value.pFunPtr;
hb_retnl( ( LONG ) pFirst );
}
HB_FUNC( EXECPTR )
{
PFUNC p = ( PFUNC ) hb_parnl( hb_pcount() );
p();
}
#pragma ENDDUMP
-
Antonio Linares
- Site Admin
- Posts: 42519
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 75 times
-
Contact:
Post
by Antonio Linares »
A useful way to create logs or do assertions (James!)
test.prg
Code: Select all | Expand
#include "FiveWin.ch"
static pOld
function Main()
pOld := FunSwap( "TEST", "LOGIT" )
MsgInfo( Test( "Hello", " world!" ) )
return nil
function Test( u1, u2 )
return u1 + u2
function LogIt( u1, u2 )
local uRet := ExecPtr( u1, u2, pOld ) // in case that we want to call the original function
MsgInfo( "Test() called with these parameters: " + u1 + ", " + u2 )
return uRet
#pragma BEGINDUMP
#include <hbapi.h>
typedef void ( * PFUNC ) ( void );
HB_FUNC( FUNSWAP )
{
PHB_SYMB symFirst = hb_dynsymSymbol( hb_dynsymFindName( hb_parc( 1 ) ) );
PHB_SYMB symLast = hb_dynsymSymbol( hb_dynsymFindName( hb_parc( 2 ) ) );
PHB_FUNC pFirst = symFirst->value.pFunPtr;
symFirst->value.pFunPtr = symLast->value.pFunPtr;
hb_retnl( ( LONG ) pFirst );
}
HB_FUNC( EXECPTR )
{
PFUNC p = ( PFUNC ) hb_parnl( hb_pcount() );
p();
}
#pragma ENDDUMP
-
James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
-
Contact:
Post
by James Bott »
Antonio,
This looks interesting. Thanks.
James