cosmetic: fucking linter :(

This commit is contained in:
Clement Rouault
2015-09-23 14:32:27 +02:00
parent 663de130b5
commit f5b0c0294f
23 changed files with 654 additions and 453 deletions
+3 -1
View File
@@ -1 +1,3 @@
from mytest import WindowsTestCase
from mytest import WindowsTestCase
__all__ = ["WindowsTestCase"]
+11 -10
View File
@@ -3,7 +3,6 @@ import struct
import time
import os
import textwrap
import ctypes
from contextlib import contextmanager
sys.path.append(".")
@@ -12,7 +11,6 @@ import windows
import windows.native_exec.simple_x86 as x86
import windows.native_exec.simple_x64 as x64
is_process_32_bits = windows.current_process.bitness == 32
is_process_64_bits = windows.current_process.bitness == 64
@@ -26,7 +24,6 @@ process_32bit_only = unittest.skipIf(not is_process_32_bits, "Test for 32bits pr
process_64bit_only = unittest.skipIf(not is_process_64_bits, "Test for 64bits process only")
if is_windows_32_bits:
def pop_calc_32():
return windows.utils.create_process(r"C:\Windows\system32\calc.exe", True)
@@ -45,6 +42,7 @@ else:
def pop_calc_64():
return windows.utils.create_process(r"C:\Windows\system32\calc.exe", True)
@contextmanager
def Calc64():
try:
@@ -53,6 +51,7 @@ def Calc64():
finally:
calc.exit()
@contextmanager
def Calc32():
try:
@@ -61,6 +60,7 @@ def Calc32():
finally:
calc.exit()
class WindowsTestCase(unittest.TestCase):
def setUp(self):
@@ -97,7 +97,6 @@ class WindowsTestCase(unittest.TestCase):
k32_base = windows.winproxy.LoadLibraryA("kernel32.dll")
self.assertEqual(windows.winproxy.GetProcAddress(k32_base, "GetCurrentProcessId"), get_current_proc_id)
# Native execution
def test_execute_to_32(self):
with Calc32() as calc:
@@ -161,7 +160,7 @@ class WindowsTestCase(unittest.TestCase):
if is_process_64_bits:
raise NotImplementedError("Python execution 64->32")
data = calc.virtual_alloc(0x1000)
remote_python_code ="""
remote_python_code = """
import ctypes
import windows
# windows.utils.create_console() # remove comment for debug
@@ -182,7 +181,7 @@ class WindowsTestCase(unittest.TestCase):
k32 = mods[0]
get_current_proc_id = k32.pe.exports['GetCurrentProcessId']
data = calc.virtual_alloc(0x1000)
remote_python_code ="""
remote_python_code = """
import ctypes
import windows
# windows.utils.create_console() # remove comment for debug
@@ -200,13 +199,14 @@ class WindowsTestCase(unittest.TestCase):
RegOpenKeyExA = [n for n in pythondll_mod.pe.imports['advapi32.dll'] if n.name == "RegOpenKeyExA"][0]
hook_value = []
@windows.hooks.RegOpenKeyExACallback
def open_reg_hook(hKey, lpSubKey, ulOptions, samDesired, phkResult, real_function):
hook_value.append((hKey, lpSubKey.value))
phkResult[0] = 12345678
return 0
x = RegOpenKeyExA.set_hook(open_reg_hook)
RegOpenKeyExA.set_hook(open_reg_hook)
import _winreg
open_args = (0x12345678, "MY_KEY_VALUE")
k = _winreg.OpenKey(*open_args)
@@ -221,14 +221,15 @@ class WindowsTestCase(unittest.TestCase):
def open_reg_hook_fail(hKey, lpSubKey, ulOptions, samDesired, phkResult, real_function):
return 0x11223344
x = RegOpenKeyExA.set_hook(open_reg_hook_fail)
RegOpenKeyExA.set_hook(open_reg_hook_fail)
import _winreg
open_args = (0x12345678, "MY_KEY_VALUE")
with self.assertRaises(WindowsError) as ar:
k = _winreg.OpenKey(*open_args)
_winreg.OpenKey(*open_args)
self.assertEqual(ar.exception.winerror, 0x11223344)
if __name__ == '__main__':
alltests = unittest.TestSuite()
alltests.addTest(unittest.makeSuite(WindowsTestCase))
unittest.TextTestRunner(verbosity=2).run(alltests)
unittest.TextTestRunner(verbosity=2).run(alltests)