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

Source Code for Module winappdbg.win32.shell32

  1  # Copyright (c) 2009-2010, 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  Wrapper for shell32.dll in ctypes. 
 30  """ 
 31   
 32  __revision__ = "$Id: shell32.py 618 2010-02-11 02:15:09Z qvasimodo $" 
 33   
 34  from defines import * 
 35  from kernel32 import LocalFree 
 36   
 37  #--- shell32.dll -------------------------------------------------------------- 
 38   
 39  # LPWSTR *CommandLineToArgvW( 
 40  #     LPCWSTR lpCmdLine, 
 41  #     int *pNumArgs 
 42  # ); 
43 -def CommandLineToArgvW(lpCmdLine):
44 _CommandLineToArgvW = windll.shell32.CommandLineToArgvW 45 _CommandLineToArgvW.argtypes = [LPVOID, POINTER(ctypes.c_int)] 46 _CommandLineToArgvW.restype = LPVOID 47 48 if not lpCmdLine: 49 lpCmdLine = None 50 argc = ctypes.c_int(0) 51 vptr = ctypes.windll.shell32.CommandLineToArgvW(lpCmdLine, ctypes.byref(argc)) 52 if vptr == NULL: 53 raise ctypes.WinError() 54 argv = vptr 55 try: 56 argc = argc.value 57 if argc <= 0: 58 raise ctypes.WinError() 59 argv = ctypes.cast(argv, ctypes.POINTER(LPWSTR * argc) ) 60 argv = [ argv.contents[i] for i in xrange(0, argc) ] 61 finally: 62 if vptr is not None: 63 LocalFree(vptr) 64 return argv
65 66 CommandLineToArgvA = MakeANSIVersion(CommandLineToArgvW) 67 CommandLineToArgv = CommandLineToArgvA 68 69 # HINSTANCE ShellExecute( 70 # HWND hwnd, 71 # LPCTSTR lpOperation, 72 # LPCTSTR lpFile, 73 # LPCTSTR lpParameters, 74 # LPCTSTR lpDirectory, 75 # INT nShowCmd 76 # );
77 -def ShellExecuteA(hwnd = None, lpOperation = None, lpFile = None, lpParameters = None, lpDirectory = None, nShowCmd = None):
78 _ShellExecuteA = windll.shell32.ShellExecuteA 79 _ShellExecuteA.argtypes = [HWND, LPSTR, LPSTR, LPSTR, LPSTR, INT] 80 _ShellExecuteA.restype = HINSTANCE 81 82 if not nShowCmd: 83 nShowCmd = 0 84 success = _ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd) 85 success = ctypes.cast(success, c_int) 86 success = success.value 87 if not success > 32: # weird! isn't it? 88 raise ctypes.WinError(success)
89
90 -def ShellExecuteW(hwnd = None, lpOperation = None, lpFile = None, lpParameters = None, lpDirectory = None, nShowCmd = None):
91 _ShellExecuteW = windll.shell32.ShellExecuteW 92 _ShellExecuteW.argtypes = [HWND, LPWSTR, LPWSTR, LPWSTR, LPWSTR, INT] 93 _ShellExecuteW.restype = HINSTANCE 94 95 if not nShowCmd: 96 nShowCmd = 0 97 success = _ShellExecuteW(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd) 98 success = ctypes.cast(success, c_int) 99 success = success.value 100 if not success > 32: # weird! isn't it? 101 raise ctypes.WinError(success)
102 103 ShellExecute = GuessStringType(ShellExecuteA, ShellExecuteW) 104