FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Disable windows x64 redirection
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Disable windows x64 redirection
Posted: Thu Jun 12, 2014 03:19 PM
I'm trying to convert this functions from Delphi to Fivewin, someone can help me?

Code (Delphi): Select all Collapse
<div class="delphi" id="{CB}" style="font-family: monospace;">
var OldWow64RedirectionValue: LongBool;

function DisableWowRedirection: Boolean;  //by gejun
type TWow64DisableWow64FsRedirection = function(var Wow64FsEnableRedirection: LongBool): LongBool;
  StdCall;
var hHandle: THandle;
  Wow64DisableWow64FsRedirection: TWow64DisableWow64FsRedirection;
begin Result := true;
  try hHandle := GetModuleHandle('kernel32.dll');
    @Wow64DisableWow64FsRedirection := GetProcAddress(hHandle, 'Wow64DisableWow64FsRedirection');
    if ((hHandle <> 0) and (@Wow64DisableWow64FsRedirection <> nil)) then Wow64DisableWow64FsRedirection(OldWow64RedirectionValue);
  except Result := False;
  end;
end;

function RevertWowRedirection: Boolean;
type TWow64RevertWow64FsRedirection = function(var Wow64RevertWow64FsRedirection: LongBool): LongBool;
  StdCall;
var hHandle: THandle;
  Wow64RevertWow64FsRedirection: TWow64RevertWow64FsRedirection;
begin Result := true;
  try hHandle := GetModuleHandle('kernel32.dll');
    @Wow64RevertWow64FsRedirection := GetProcAddress(hHandle, 'Wow64RevertWow64FsRedirection');
    if ((hHandle <> 0) and (@Wow64RevertWow64FsRedirection <> nil)) then Wow64RevertWow64FsRedirection(OldWow64RedirectionValue);
  except Result := False;
  end;
end;</div>
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Disable windows x64 redirection
Posted: Thu Jun 12, 2014 06:12 PM
Samir,

Here you have it (easier):

Code (fw): Select all Collapse
#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( WOW64DISABLEWOW64FSREDIRECTION )
{
   void * pOldValue = NULL;

   hb_retl( Wow64DisableWow64FsRedirection( &pOldValue ) ); 
}

#pragma ENDDUMP


What do you need it for ? I have been reviewing the MS docs but I don't see a direct use for it:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365743(v=vs.85).aspx
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Disable windows x64 redirection
Posted: Fri Jun 13, 2014 12:44 PM
Antonio I found a VB version and found what is the error

I've made ths:
Code (fw): Select all Collapse
****************************************************************************
Function Redirecionamento64(lHabilita)
****************************************************************************
*
* Desabilitar o redirecionamento do windows 64 bits
* Parametros:
* Retorno: Nenhum
*
* Autor: Samir
* 12/06/2014 - 11:19:31
*
****************************************************************************
Local Result := -999, nOldValue := Nil

Public hHandleKernel := LoadLibrary("Kernel32.dll")

   Default lHabilita := .T.

   If hHandleKernel != 0

      If lHabilita

         Result := WOW64_Revert( @nOldValue )

      Else

         Result := WOW64_Disable( nOldValue )

      End

      FreeLibrary(hHandleKernel)
      
   End

   Release hHandleKernel

Return Result

/*------------------------------------------------------------------------*/


DLL32 STATIC FUNCTION WOW64_Disable( @OldValue as PTR) ;
      AS BOOL PASCAL FROM "Wow64DisableWow64FsRedirection";
      LIB hHandleKernel

DLL32 STATIC FUNCTION WOW64_Revert( OldValue as PTR) ;
      AS BOOL PASCAL FROM "Wow64RevertWow64FsRedirection";
      LIB hHandleKernel


I need to use this do check if a driver exist in the C:\Windows\System32\Drivers

If you are on a x64 SO and use Directory("C:\Windows\System32\Drivers") the return is the content of C:\Windows\SysWOW64\Drivers
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Disable windows x64 redirection
Posted: Fri Jun 13, 2014 01:38 PM

Samir,

So is it working fine now ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Disable windows x64 redirection
Posted: Fri Jun 13, 2014 02:03 PM
Yes, thanks.

If you wanna check by yourself:

Code (fw): Select all Collapse
//-- Get the files of the directory without disable the redirection
aFiles := Directory("C:\Windows\System32\Drivers")

ApresentaMatriz(aFiles)

//-- Get the files of the directory after disable the redirection
Redirecionamento64(.F.)

aFiles := Directory("C:\Windows\System32\Drivers")

ApresentaMatriz(aFiles)

//-- Restore the redirection
Redirecionamento64(.T.)



****************************************************************************
Procedure ApresentaMatriz(aMatriz)
****************************************************************************

local cMsg := "", nLen := 0, nDimensao := 0, m := 0, d := 0

   //-- Obter o tamanho da matriz passada por parâmetro
   nLen := Len(aMatriz)

   //-- Verificar se foi passado uma matriz por parâmetro
   If ValType(aMatriz) == "A"

      //-- Verifica se a matriz está preenchida
      If Len(aMatriz) > 0

         //-- Verifica se existe uma submatriz
         if ValType(aMatriz[1]) == "A"
            //-- Obtem o tamanho da submatriz
            nDimensao := Len(aMatriz[1])
         else
            //-- Identifica que não tem uma submatriz
            nDimensao := 0
         end

      else

         MsgInfo("Matriz vazia")

         Return

      end

   else

      MsgInfo("Parâmetro informado não é uma matriz")

      Return

   end

   //-- Roda a matriz principal
   For m := 1 to nLen

      //-- Verifica se vai ignorar os zeros
      cMsg += StrZero(m,nZero)+" - {"

      //-- Verifica se existe uma submatriz na linha especificada
      if ValType(aMatriz[m]) == "A"
         //-- obtêm o tamanho da submatriz da linha
         nDimensao := Len(aMatriz[m])
      else
         //-- Identifica que não existe uma submatriz na linha
         nDimensao := 0
      end

      //-- Se existir uma submatriz
      if nDimensao != 0

         //-- Roda a submatriz
         For d := 1 to nDimensao

            //-- Concatena o resultado para a exibição / Texto
            cMsg += DadosVar(aMatriz[m,d])

            //-- Verifica se não é a ultima dimensão
            if d != nDimensao
               cMsg += ", "
            end

         end

      else

         //-- Concatena o resultado para a exibição / Texto
         cMsg += DadosVar(aMatriz[m])

      end

      If m != nLen

         //-- Se for para ignorar zeros adiciona quebra de linha
         cMsg += "}"+CRLF

      else

         //-- Adiciona a formatação
         cMsg += "}"

      end

   end

   MsgInfo(cMsg)

Return nil

/*------------------------------------------------------------------------*/

****************************************************************************
static function DadosVar(xVar)
****************************************************************************

Local CValor := ""

   if cTipo == "C"
      cValor := xVar
   elseif cTipo == "N"
      //cValor := Str(xVar,,,.T.)
      cValor := StrTrim(xVar)
   elseif cTipo == "D"
      cValor := DtoC(xVar)
   elseif cTipo == "A"
      ApresentaMatriz(xVar,,,,cTitulo)
      Return "Matriz"
   elseif cTipo == "O"
      cValor := "Objeto:" + xVar:ClassName()
   elseif cTipo == "U"
      cValor := "Nulo"
   elseif cTipo == "L"
      cValor := if(xVar,"True","False")
   else
      cValor := xVar
   end

Return cValor

/*------------------------------------------------------------------------*/

****************************************************************************
Function Redirecionamento64(lHabilita)
****************************************************************************
*
* Desabilitar o redirecionamento do windows 64 bits
* Parametros:
* Retorno: Nenhum
*
* Autor: Samir
* 12/06/2014 - 11:19:31
*
****************************************************************************
Local Result := -999, nOldValue := Nil

Public hHandleKernel := LoadLibrary("Kernel32.dll")

   Default lHabilita := .T.

   If hHandleKernel != 0

      If lHabilita

         Result := WOW64_Revert( @nOldValue )

      Else

         Result := WOW64_Disable( nOldValue )

      End

      FreeLibrary(hHandleKernel)

   End

   Release hHandleKernel

Return Result

/*------------------------------------------------------------------------*/


DLL32 STATIC FUNCTION WOW64_Disable( @OldValue as PTR) ;
      AS BOOL PASCAL FROM "Wow64DisableWow64FsRedirection";
      LIB hHandleKernel

DLL32 STATIC FUNCTION WOW64_Revert( OldValue as PTR) ;
      AS BOOL PASCAL FROM "Wow64RevertWow64FsRedirection";
      LIB hHandleKernel
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Disable windows x64 redirection
Posted: Fri Jun 13, 2014 02:14 PM

Samir,

thanks for the example :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion