diff options
author | Matt Wrock <matt@mattwrock.com> | 2016-02-18 15:48:31 -0800 |
---|---|---|
committer | Matt Wrock <matt@mattwrock.com> | 2016-02-18 15:48:31 -0800 |
commit | 5ee5d196b52200701f67dc65a36d937d1388d067 (patch) | |
tree | fc4c42048385b25320db3591bfc552aa6e61dcea /lib/chef | |
parent | cab6243b977c501366721965c6ccd039f33646cf (diff) | |
download | chef-5ee5d196b52200701f67dc65a36d937d1388d067.tar.gz |
fallback to netmsg.dll error table if error message is not found in system errors
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/win32/api/error.rb | 35 | ||||
-rw-r--r-- | lib/chef/win32/error.rb | 14 |
2 files changed, 45 insertions, 4 deletions
diff --git a/lib/chef/win32/api/error.rb b/lib/chef/win32/api/error.rb index aa80f89743..dc83f9cb2b 100644 --- a/lib/chef/win32/api/error.rb +++ b/lib/chef/win32/api/error.rb @@ -874,6 +874,20 @@ class Chef SEM_NOGPFAULTERRORBOX = 0x0002 SEM_NOOPENFILEERRORBOX = 0x8000 + # Flags for LoadLibraryEx + + DONT_RESOLVE_DLL_REFERENCES = 0x00000001 + LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010 + LOAD_LIBRARY_AS_DATAFILE = 0x00000002 + LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040 + LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020 + LOAD_LIBRARY_SEARCH_APPLICATION_DIR = 0x00000200 + LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000 + LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100 + LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800 + LOAD_LIBRARY_SEARCH_USER_DIRS = 0x00000400 + LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008 + ############################################### # Win32 API Bindings ############################################### @@ -891,8 +905,8 @@ DWORD WINAPI FormatMessage( __in_opt va_list *Arguments ); =end - safe_attach_function :FormatMessageA, [:DWORD, :LPCVOID, :DWORD, :DWORD, :LPTSTR, :DWORD, :varargs], :DWORD - safe_attach_function :FormatMessageW, [:DWORD, :LPCVOID, :DWORD, :DWORD, :LPWSTR, :DWORD, :varargs], :DWORD + safe_attach_function :FormatMessageA, [:DWORD, :HANDLE, :DWORD, :DWORD, :LPTSTR, :DWORD, :varargs], :DWORD + safe_attach_function :FormatMessageW, [:DWORD, :HANDLE, :DWORD, :DWORD, :LPWSTR, :DWORD, :varargs], :DWORD =begin DWORD WINAPI GetLastError(void); @@ -916,6 +930,23 @@ UINT WINAPI SetErrorMode( =end safe_attach_function :SetErrorMode, [:UINT], :UINT +=begin +https://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx +HMODULE WINAPI LoadLibraryEx( + _In_ LPCTSTR lpFileName, + _Reserved_ HANDLE hFile, + _In_ DWORD dwFlags +); +=end + safe_attach_function :LoadLibraryExW, [:LPCTSTR, :HANDLE, :DWORD], :HANDLE + +=begin +https://msdn.microsoft.com/en-us/library/windows/desktop/ms683152(v=vs.85).aspx +BOOL WINAPI FreeLibrary( + _In_ HMODULE hModule +); +=end + safe_attach_function :FreeLibrary, [:HANDLE], :BOOL end end end diff --git a/lib/chef/win32/error.rb b/lib/chef/win32/error.rb index 8c3ff2f08f..83d4583f1d 100644 --- a/lib/chef/win32/error.rb +++ b/lib/chef/win32/error.rb @@ -29,11 +29,21 @@ class Chef def self.format_message(message_id = 0, args = {}) flags = args[:flags] || FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY - source = args[:source] + flags |= FORMAT_MESSAGE_ALLOCATE_BUFFER + source = args[:source] || 0 language_id = args[:language_id] || 0 varargs = args[:varargs] || [:int, 0] buffer = FFI::MemoryPointer.new :pointer - num_chars = FormatMessageW(flags | FORMAT_MESSAGE_ALLOCATE_BUFFER, source, message_id, language_id, buffer, 0, *varargs) + num_chars = FormatMessageW(flags, source, message_id, language_id, buffer, 0, *varargs) + if num_chars == 0 + source = LoadLibraryExW("netmsg.dll".to_wstring, 0, LOAD_LIBRARY_AS_DATAFILE) + begin + num_chars = FormatMessageW(flags | FORMAT_MESSAGE_FROM_HMODULE, source, message_id, language_id, buffer, 0, *varargs) + ensure + FreeLibrary(source) + end + end + if num_chars == 0 raise! end |