[Win32utils-devel] Debugging Segmentation Faults

Heesob Park phasis at gmail.com
Fri Jun 26 03:28:57 EDT 2009


Hi,

2009/6/26 Robert Clugston <waldo1979 at gmail.com>:
> All, I'm attempting to perform a remote registry query using win32-api. For
> some reason the last call to "RegQueryValueEx" is causing a segmentation
> fault. Any suggestions on how to resolve and/or debug this issue?
>
>>ruby win32.rb
> win32.rb:127: [BUG] Segmentation fault
> ruby 1.8.6 (2008-08-11) [i386-mswin32]
>
>
> This application has requested the Runtime to terminate it in an unusual
> way.
> Please contact the application's support team for more information.
>>Exit code: 3
>
> <!-- START CODE SNIPPET -->
> require "win32/api"
> require "windows/registry"
> include Win32
> require "dl"
>
> class Win32APIExample
>        def initialize
>            @aKEY_QUERY_VALUE = 0x1
>            @aKEY_SET_VALUE = 0x2
>            @aKEY_ALL_ACCESS = 0x3
>        end
>
>        def remotereg
>          machine = "\\\\myhost"
>
>          #http://support.microsoft.com/kb/315586
>
>          ############################
>          ## Connect to the remote registry service
>          #RegConnectRegistry
>          # http://msdn.microsoft.com/en-us/library/ms724840(VS.85).aspx
>          phkResult = 0.chr * 4
>          regConnectRegistry =
> API.new('RegConnectRegistry','PLP','L','advapi32')
>          returncode = regConnectRegistry.call(machine,
> Windows::Registry::HKEY_LOCAL_MACHINE, phkResult)
>
>          if returncode != Windows::Error::ERROR_SUCCESS
>            puts "AN ERROR OCCURRED"
>            return
>          end
>
>          phkResult = phkResult.unpack('L').first
>
>          ###########################
>          ## Open a handle to the specified Registry node
>          #RegOpenKeyEx
>          #http://msdn.microsoft.com/en-us/library/ms724897(VS.85).aspx
>          hKey = 0.chr * 4
>          regOpenKeyEx = API.new('RegOpenKeyEx','PSLLP','L','advapi32')
>          returncode =
> regOpenKeyEx.call(phkResult,"HARDWARE\\DESCRIPTION\\System",0, at aKEY_QUERY_VALUE,
> hKey)
>
>          if returncode != Windows::Error::ERROR_SUCCESS
>            puts "AN ERROR OCCURRED"
>            return
>          end
>
>          hKey = hKey.unpack('L').first
>
>
>          ###########################
>          ## GET the value of the specificed registry key
>          #RegQueryValueEx
>          #http://msdn.microsoft.com/en-us/library/ms724911(VS.85).aspx
>          lpData = 0.chr * 8192
>          lpcbData = [lpData.length].pack('L')
>
>          regQueryValueEx = API.new('   ','PSVLPP','L','advapi32')
>          returncode = regQueryValueEx.call(hKey, "SystemBIOSVersion", nil,
> Windows::Registry::REG_MULTI_SZ, lpData, lpcbData)
>
>        end
> end
>
> if __FILE__ == $0
>        b = Win32APIExample.new()
>        puts b.remotereg
> end
> <!-- END CODE SNIPPET -->

The 4th parameter is not an input but a ouput parameter.

The following line
         regQueryValueEx = API.new('   ','PSVLPP','L','advapi32')
         returncode = regQueryValueEx.call(hKey, "SystemBIOSVersion",
nil, Windows::Registry::REG_MULTI_SZ, lpData, lpcbData)
should be
         regQueryValueEx = API.new('RegQueryValueEx','PSPPPP','L','advapi32')
         returncode = regQueryValueEx.call(hKey, "SystemBIOSVersion",
nil, nil, lpData, lpcbData)
	 lpData[0,lpcbData.unpack('L').first].strip


Regards,

Park Heesob


More information about the win32utils-devel mailing list