[Win32utils-devel] Fwd: win32/process problem

Heesob Park phasis at gmail.com
Sat Dec 8 20:18:39 EST 2007


Hi,

2007/12/9, Daniel Berger <djberg96 at gmail.com>:
>
> Whoops, forgot to include the line that fails:
>
> if va_list.length == 0
>
> So, for some reason va_list isn't set.
>
> Dan


Did you modified my code?
I did'nt use va_list.length. but I had omitted initializing va_list .
Here is the corrent code:

      def get_description(rec, event_source, lkey)
         str     = rec[rec[36,4].unpack('L')[0] .. -1]
         num     = rec[26,2].unpack('S')[0] # NumStrings
         hkey    = [0].pack('L')
         key     = BASE_KEY + "#{@source}\\#{event_source}"
         buf     = 0.chr * 8192
         va_list = va_list0 = (num == 0) ? [] : str.unpack('Z*' * num)

         if RegOpenKeyEx(lkey, key, 0, KEY_READ, hkey) == 0
            value = 'ParameterMessageFile'
            file  = 0.chr * MAX_SIZE
            hkey  = hkey.unpack('L')[0]
            size  = [file.length].pack('L')

     if RegQueryValueEx(hkey, value, 0, 0, file, size) == 0
         file = file.nstrip
        exe  = 0.chr * MAX_SIZE
        ExpandEnvironmentStrings(file, exe, exe.size)
        exe = exe.nstrip
        va_list = va_list0.map{|v|
          va = v
          v.scan(/%%(\d+)/).uniq.each {|x|
            exe.split(';').each{ |file|
                     hmodule  = LoadLibraryEx(file, 0,
DONT_RESOLVE_DLL_REFERENCES)
                     if hmodule != 0
                       FormatMessage(
                          FORMAT_MESSAGE_FROM_HMODULE |
                          FORMAT_MESSAGE_ARGUMENT_ARRAY,
                          hmodule,
                          x.first.to_i,
                          0,
                          buf,
                          buf.size,
                          v
                       )
                       FreeLibrary(hmodule)
                       break if buf.nstrip != ""
                     end
                   }
                   va = va.gsub("%%#{x.first}",buf.nstrip)
          }
          va
        }
            end

            value = 'EventMessageFile'
            file  = 0.chr * MAX_SIZE
            size  = [file.length].pack('L')

            if RegQueryValueEx(hkey, value, 0, 0, file, size) == 0
               file = file.nstrip
               exe  = 0.chr * MAX_SIZE

               ExpandEnvironmentStrings(file, exe, exe.size)
               exe = exe.nstrip

        # Try to retrieve message *without* expanding the inserts yet
               exe.split(';').each{ |file|
                  hmodule  = LoadLibraryEx(file, 0,
DONT_RESOLVE_DLL_REFERENCES)
                  event_id = rec[20,4].unpack('L')[0]
                  if hmodule != 0
                     FormatMessage(
                        FORMAT_MESSAGE_FROM_HMODULE |
                        FORMAT_MESSAGE_IGNORE_INSERTS,
                        hmodule,
                        event_id,
                        0,
                        buf,
                        buf.size,
                        nil
                     )

                     FreeLibrary(hmodule)
                     break if buf.nstrip != "" # All messages read
                  end
               }



               # Determine higest %n insert number
               max_insert = [num,buf.nstrip.scan
(/%(\d+)/).map{|x|x[0].to_i}.max].compact.max
               # Insert dummy strings for not provided by caller */
               ((num+1)..(max_insert)).each {|x|va_list.push("%#{x}")}

          if num == 0
             va_list_ptr = 0.chr * 4
          else
             va_list_ptr = va_list.map{ |x|
                [x + 0.chr].pack('P').unpack('L')[0]
             }.pack('L*')
          end

               exe.split(';').each{ |file|
                  hmodule  = LoadLibraryEx(file, 0,
DONT_RESOLVE_DLL_REFERENCES)
                  event_id = rec[20,4].unpack('L')[0]
                  if hmodule != 0
                     FormatMessage(
                        FORMAT_MESSAGE_FROM_HMODULE |
                        FORMAT_MESSAGE_ARGUMENT_ARRAY,
                        hmodule,
                        event_id,
                        0,
                        buf,
                        buf.size,
                        va_list_ptr
                     )

                     FreeLibrary(hmodule)
                     break if buf.nstrip != "" # All messages read
                  end
               }
            end

            RegCloseKey(hkey)
         end
         [va_list0, buf.strip]
      end

Regards,

Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071209/dd959694/attachment-0001.html 


More information about the win32utils-devel mailing list