EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Processor detection

Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.
#11301
Posted: 10/09/2009 11:45:55
by Kent Briggs (Standard support level)
Joined: 02/25/2007
Posts: 3

Is there a convenient way in a 32-bit Delphi app to detect which of the three drivers needs to be installed? GetSystemInfo() has a wProcessorArchitecture parameter that will do it for 64-bit apps but it always returns the 32-bit constant for 32-bit apps running on a 64-bit version of Windows. So I go to plan B and use this function:

Code
function IsWow64: Boolean;
type
  TIsWow64Process = function(Handle: Windows.THandle; var Res: Windows.BOOL): Windows.BOOL; stdcall;
var
  IsWow64Result: Windows.BOOL;
  IsWow64Process: TIsWow64Process;
begin
  Result := False;
  IsWow64Process := Windows.GetProcAddress(Windows.GetModuleHandle('kernel32'), 'IsWow64Process');
  if Assigned(IsWow64Process) then
    if IsWow64Process(Windows.GetCurrentProcess, IsWow64Result) then Result := IsWow64Result;
end;


However, that doesn't distinguish between AMD64 and IA64. It would be helpful if RawDisk contained a built-in function that told me which driver I needed. If I try to install the 32-bit driver on a 64-bit system or vice-versa, the GetLastError() function just returns 0.

On a related note, is there any problem in renaming the drivers to elrawdsk32.sys, elrawdsk64.sys, and elrawdski64.sys so that can be saved in the same folder? It appears to work ok in my tests so far.
#11303
Posted: 10/09/2009 13:56:51
by Eugene Mayevski (EldoS Corp.)

This is the source code of the DLL which is used in installer to detect system platform:

Code
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
typedef BOOL (WINAPI *LPFN_GETNATIVESYSTEMINFO) (LPSYSTEM_INFO lpSystemInfo);

LPFN_ISWOW64PROCESS fnIsWow64Process;
LPFN_GETNATIVESYSTEMINFO fnGetNativeSystemInfo;

int GetPlatform()
{
   SYSTEM_INFO sysInfo;

   fnGetNativeSystemInfo = (LPFN_GETNATIVESYSTEMINFO) GetProcAddress(
        GetModuleHandle(TEXT("kernel32")),"GetNativeSystemInfo");
  
    if (NULL != fnGetNativeSystemInfo)
    {
        if (!fnGetNativeSystemInfo(&sysInfo))
        {
            return PROCESSOR_ARCHITECTURE_UNKNOWN;
        }
      switch (sysInfo.dwProcessorType)
      {
         case PROCESSOR_ARCHITECTURE_AMD64:
            return 1;
         case PROCESSOR_ARCHITECTURE_IA64:
            return 2;
         default:
            return 0;
      }
    }
   else
      return PROCESSOR_ARCHITECTURE_UNKNOWN;
}

BOOL IsWow64()
{
    BOOL bIsWow64 = FALSE;

    fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
  
    if (NULL != fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
        {
            // handle error
        }
    }
    return bIsWow64;
}

INSTDETECT64BIT_API int Detect64bitType(void)
{
   if (!IsWow64())
      return 0; // 32-bit process
   else
      return GetPlatform();
}


Sincerely yours
Eugene Mayevski
#11304
Posted: 10/09/2009 14:57:39
by Kent Briggs (Standard support level)
Joined: 02/25/2007
Posts: 3

Quote
Eugene Mayevski wrote:
This is the source code of the DLL which is used in installer to detect system platform:


I need to call GetNativeSystemInfo() instead of GetSystemInfo(). Thanks.

Reply

Statistics

Topic viewed 4867 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!