Package winappdbg :: Package win32 :: Module shell32
[hide private]
[frames] | no frames]

Source Code for Module winappdbg.win32.shell32

  1  # Copyright (c) 2009, Mario Vilas 
  2  # All rights reserved. 
  3  # 
  4  # Redistribution and use in source and binary forms, with or without 
  5  # modification, are permitted provided that the following conditions are met: 
  6  # 
  7  #     * Redistributions of source code must retain the above copyright notice, 
  8  #       this list of conditions and the following disclaimer. 
  9  #     * Redistributions in binary form must reproduce the above copyright 
 10  #       notice,this list of conditions and the following disclaimer in the 
 11  #       documentation and/or other materials provided with the distribution. 
 12  #     * Neither the name of the copyright holder nor the names of its 
 13  #       contributors may be used to endorse or promote products derived from 
 14  #       this software without specific prior written permission. 
 15  # 
 16  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 17  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 18  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 19  # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 20  # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 21  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 22  # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 23  # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 24  # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 25  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 26  # POSSIBILITY OF SUCH DAMAGE. 
 27   
 28  """ 
 29  Debugging API wrappers in ctypes. 
 30   
 31  @see: U{http://apps.sourceforge.net/trac/winappdbg/wiki/Win32APIWrappers} 
 32  """ 
 33   
 34  __revision__ = "$Id: shell32.py 343 2009-08-03 22:58:22Z QvasiModo $" 
 35   
 36  from defines import * 
 37  from kernel32 import LocalFree 
 38   
 39  #--- shell32.dll -------------------------------------------------------------- 
 40   
 41  # LPWSTR *CommandLineToArgvW( 
 42  #     LPCWSTR lpCmdLine, 
 43  #     int *pNumArgs 
 44  # ); 
45 -def CommandLineToArgvW(lpCmdLine):
46 _CommandLineToArgvW = windll.shell32.CommandLineToArgvW 47 _CommandLineToArgvW.argtypes = [LPVOID, POINTER(ctypes.c_int)] 48 _CommandLineToArgvW.restype = LPVOID 49 50 if not lpCmdLine: 51 lpCmdLine = None 52 argc = ctypes.c_int(0) 53 vptr = ctypes.windll.shell32.CommandLineToArgvW(lpCmdLine, ctypes.byref(argc)) 54 if vptr == NULL: 55 raise ctypes.WinError() 56 argv = vptr 57 try: 58 argc = argc.value 59 if argc <= 0: 60 raise ctypes.WinError() 61 argv = ctypes.cast(argv, ctypes.POINTER(LPWSTR * argc) ) 62 argv = [ argv.contents[i] for i in xrange(0, argc) ] 63 finally: 64 if vptr is not None: 65 LocalFree(vptr) 66 return argv
67 68 CommandLineToArgvA = MakeANSIVersion(CommandLineToArgvW) 69 CommandLineToArgv = CommandLineToArgvA 70 71 # HINSTANCE ShellExecute( 72 # HWND hwnd, 73 # LPCTSTR lpOperation, 74 # LPCTSTR lpFile, 75 # LPCTSTR lpParameters, 76 # LPCTSTR lpDirectory, 77 # INT nShowCmd 78 # );
79 -def ShellExecuteA(hwnd = None, lpOperation = None, lpFile = None, lpParameters = None, lpDirectory = None, nShowCmd = None):
80 _ShellExecuteA = windll.shell32.ShellExecuteA 81 _ShellExecuteA.argtypes = [HWND, LPSTR, LPSTR, LPSTR, LPSTR, INT] 82 _ShellExecuteA.restype = HINSTANCE 83 84 if not nShowCmd: 85 nShowCmd = 0 86 success = _ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd) 87 success = ctypes.cast(success, c_int) 88 success = success.value 89 if not success > 32: # weird! isn't it? 90 raise ctypes.WinError(success)
91
92 -def ShellExecuteW(hwnd = None, lpOperation = None, lpFile = None, lpParameters = None, lpDirectory = None, nShowCmd = None):
93 _ShellExecuteW = windll.shell32.ShellExecuteW 94 _ShellExecuteW.argtypes = [HWND, LPWSTR, LPWSTR, LPWSTR, LPWSTR, INT] 95 _ShellExecuteW.restype = HINSTANCE 96 97 if not nShowCmd: 98 nShowCmd = 0 99 success = _ShellExecuteW(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd) 100 success = ctypes.cast(success, c_int) 101 success = success.value 102 if not success > 32: # weird! isn't it? 103 raise ctypes.WinError(success)
104 105 ShellExecute = GuessStringType(ShellExecuteA, ShellExecuteW) 106