Skip to content

Commit fb567c6

Browse files
committed
Added some samples output + document change Kernel32Error -> WinproxyError + fix sample/readme/doc related
1 parent 784e669 commit fb567c6

7 files changed

Lines changed: 86 additions & 36 deletions

File tree

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,31 @@ You can also make some operation on threads (suspend/resume/wait/get(or set) con
5050
32
5151
>>> windows.current_process.token.integrity
5252
SECURITY_MANDATORY_MEDIUM_RID(0x2000L)
53-
>>> calc = [p for p in windows.system.processes if p.name == "calc.exe"][0]
54-
>>> calc
55-
<WinProcess "calc.exe" pid 6960 at 0x37391f0>
56-
>>> calc.bitness
53+
>>> proc = [p for p in windows.system.processes if p.name == "notepad.exe"][0]
54+
>>> proc
55+
<WinProcess "notepad.exe" pid 16520 at 0x544e410>
56+
>>> proc.bitness
5757
64
58-
>>> calc.peb.modules[:3]
59-
[<RemoteLoadedModule64 "calc.exe" at 0x3671e90>, <RemoteLoadedModule64 "ntdll.dll" at 0x3671030>, <RemoteLoadedModule64 "kernel32.dll" at 0x3671080>]
60-
>>> k32 = calc.peb.modules[2]
58+
>>> proc.peb.modules[:3]
59+
[<RemoteLoadedModule64 "notepad.exe" at 0x3671e90>, <RemoteLoadedModule64 "ntdll.dll" at 0x3671030>, <RemoteLoadedModule64 "kernel32.dll" at 0x3671080>]
60+
>>> k32 = proc.peb.modules[2]
6161
>>> hex(k32.pe.exports["CreateFileW"])
6262
'0x7ffee6761550L'
63-
>>> calc.threads[0]
64-
<WinThread 3932 owner "calc.exe" at 0x3646350>
65-
>>> hex(calc.threads[0].context.Rip)
63+
>>> proc.threads[0]
64+
<WinThread 17688 owner "notepad.exe" at 0x53b47f0>
65+
>>> hex(proc.threads[0].context.Rip)
6666
'0x7ffee68b54b0L'
67-
>>> calc.execute_python("import os")
67+
>>> proc.execute_python("import os")
6868
True
69-
>>> calc.execute_python("exit(os.getpid() + 1)")
69+
>>> proc.execute_python("exit(os.getpid() + 1)")
7070
# execute_python raise if process died
7171
Traceback (most recent call last):
7272
...
73-
WindowsError: <WinProcess "calc.exe" pid 6960 (DEAD) at 0x37391f0> died during execution of python command
73+
WindowsError: <WinProcess "notepad.exe" pid 16520 (DEAD) at 0x579f610> died during execution of python command
7474
>>> calc
75-
<WinProcess "calc.exe" pid 6960 (DEAD) at 0x37391f0>
75+
<WinProcess "notepad.exe" pid 16520 (DEAD) at 0x579f610>
7676
>>> calc.exit_code
77-
6961L
77+
16521L
7878
```
7979

8080
### System information
@@ -126,7 +126,7 @@ but some have default values and the functions raise exception on call error (I
126126
# Help on function VirtualAlloc in module windows.winproxy:
127127
# VirtualAlloc(lpAddress=0, dwSize=NeededParameter, flAllocationType=MEM_COMMIT(0x1000L), flProtect=PAGE_EXECUTE_READWRITE(0x40L))
128128
# Errcheck:
129-
# raise Kernel32Error if result is 0
129+
# raise WinproxyError if result is 0
130130

131131
# Positional arguments
132132
>>> windows.winproxy.VirtualAlloc(0, 0x1000)
@@ -158,8 +158,8 @@ File "windows\winproxy.py", line 264, in VirtualAlloc
158158
File "windows\winproxy.py", line 133, in perform_call
159159
return self._cprototyped(*args)
160160
File "windows\winproxy.py", line 59, in kernel32_error_check
161-
raise Kernel32Error(func_name)
162-
windows.winproxy.Kernel32Error: VirtualAlloc: [Error 8] Not enough storage is available to process this command.
161+
raise WinproxyError(func_name)
162+
windows.winproxy.error.WinproxyError: VirtualAlloc: [Error 87] The parameter is incorrect.
163163
"""
164164
```
165165

@@ -212,10 +212,11 @@ To extract/play with even more information about the system, PythonForWindows is
212212
```python
213213
>>> import windows
214214
>>> windows.system.wmi.select
215-
<bound method WmiRequester.select of <windows.winobject.wmi.WmiRequester object at 0x036BA590>>
216-
>>> windows.system.wmi.select("Win32_Process", ["Name", "Handle"])[:4]
217-
[{'Handle': u'0', 'Name': u'System Idle Process'}, {'Handle': u'4', 'Name': u'System'}, {'Handle': u'412', 'Name': u'smss.exe'}, {'Handle': u'528', 'Name': u'csrss.exe'}]
218-
# Get WMI data for current process
215+
<bound method WmiNamespace.select of <WmiNamespace "root\cimv2">>
216+
>>> windows.system.wmi.select("Win32_Process")[:3]
217+
[<WmiObject instance of "Win32_Process">, <WmiObject instance of "Win32_Process">, <WmiObject instance of "Win32_Process">]# Get WMI data for current process
218+
>>> windows.system.wmi.select("Win32_Process")[42]["Name"]
219+
u'svchost.exe'
219220
>>> wmi_cp = [p for p in windows.system.wmi.select("Win32_Process") if int(p["Handle"]) == windows.current_process.pid][0]
220221
>>> wmi_cp["CommandLine"], wmi_cp["HandleCount"]
221222
(u'"C:\\Python27\\python.exe"', 227)
@@ -388,20 +389,20 @@ import windows
388389
import windows.debug
389390
import windows.test
390391
import windows.native_exec.simple_x86 as x86
392+
import windows.generated_def as gdef
391393

392-
from windows.test import pop_calc_32
393-
from windows.generated_def import EXCEPTION_ACCESS_VIOLATION
394+
from windows.test import pop_proc_32
394395

395396
class MyDebugger(windows.debug.Debugger):
396397
def on_exception(self, exception):
397398
code = exception.ExceptionRecord.ExceptionCode
398399
addr = exception.ExceptionRecord.ExceptionAddress
399400
print("Got exception {0} at 0x{1:x}".format(code, addr))
400-
if code == EXCEPTION_ACCESS_VIOLATION:
401+
if code == gdef.EXCEPTION_ACCESS_VIOLATION:
401402
print("Access Violation: kill target process")
402403
self.current_process.exit()
403404

404-
calc = windows.test.pop_calc_32(dwCreationFlags=DEBUG_PROCESS)
405+
calc = windows.test.pop_proc_32(dwCreationFlags=gdef.DEBUG_PROCESS)
405406
d = MyDebugger(calc)
406407
calc.execute(x86.assemble("int3; mov [0x42424242], EAX; ret"))
407408
d.loop()

docs/source/sample.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ Ouput::
431431
\xc6\x12x\x1am\xc8\x01t\xac\xa6\xf3#\x02\xd4J \x8eZ\xbb\x10W\xe1 0;\x06\t*\x86H\x86\xf7\r\x01\x07\x010\x14\x06\x08*
432432
\x86H\x86\xf7\r\x03\x07\x04\x08\x14F\x04\xad\xed9\xed<\x80\x18\x80]6\xccTV\xbc\xb8*\x84QY!~\xb3\n\x1aV\xd4\rf\xd1n:')
433433

434-
(cmd λ) python crypto\encryption_demo.py decrypt decrypt --password BADPASS message.crypt mykey.pfx
434+
(cmd λ) python crypto\encryption_demo.py decrypt --password BADPASS message.crypt mykey.pfx
435435
Traceback (most recent call last):
436436
File "..\samples\encryption_demo.py", line 103, in <module>
437437
res.func(**res.__dict__)
@@ -444,8 +444,8 @@ Ouput::
444444
File "c:\users\hakril\documents\work\pythonforwindows\windows\winproxy.py", line 148, in perform_call
445445
return self._cprototyped(*args)
446446
File "c:\users\hakril\documents\work\pythonforwindows\windows\winproxy.py", line 69, in kernel32_error_check
447-
raise Kernel32Error(func_name)
448-
windows.winproxy.Kernel32Error: PFXImportCertStore: [Error 86] The specified network password is not correct.
447+
raise WinproxyError(func_name)
448+
windows.winproxy.error.WinproxyError: PFXImportCertStore: [Error 86] The specified network password is not correct.
449449

450450
(cmd λ) python crypto\encryption_demo.py decrypt --password MYPASSWORD message.crypt mykey.pfx
451451
Result = <my secret message>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(cmd) python security\query_sacl.py
2+
This sample should be run as admin to demonstration SACL access
3+
4+
[NO-PRIV] Querying <C:\windows\notepad.exe> SecurityDescriptor without SACL
5+
sacl = <Acl count=0>
6+
7+
[NO-PRIV] Querying <C:\windows\notepad.exe> SecurityDescriptor with SACL
8+
None: [Error 1314] A required privilege is not held by the client.
9+
10+
Enabling <SeSecurityPrivilege>
11+
[ERROR] <Token TokenId=0xd6db5cc Type=TokenPrimary(0x1L)> has no privilege <SeSecurityPrivilege>
12+
13+
14+
(cmd-admin) python security\query_sacl.py
15+
16+
[NO-PRIV] Querying <C:\windows\notepad.exe> SecurityDescriptor without SACL
17+
sacl = <Acl count=0>
18+
19+
[NO-PRIV] Querying <C:\windows\notepad.exe> SecurityDescriptor with SACL
20+
None: [Error 1314] A required privilege is not held by the client.
21+
22+
Enabling <SeSecurityPrivilege>
23+
24+
[PRIV] Querying <C:\windows\notepad.exe> SecurityDescriptor with SACL
25+
sacl = <Acl count=1>
26+
[<SystemAuditACE mask=852246>]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(cmd) python security\security_descriptor.py
2+
Security descriptor is: <SecurityDescriptor object at 0x03E151C0>
3+
Owner: S-1-5-32-544
4+
- lookup: (u'BUILTIN', u'Administrateurs')
5+
Group: S-1-5-7
6+
- lookup: (u'AUTORITE NT', u'ANONYMOUS LOGON')
7+
Dacl: <Acl count=2>
8+
9+
ACE [0]: <AccessAllowedACE mask=269353023>
10+
- Header-AceType: ACCESS_ALLOWED_ACE_TYPE(0x0L)
11+
- Header-AceFlags: 1
12+
- Header-flags: [OBJECT_INHERIT_ACE(0x1L)]
13+
- Mask: 269353023
14+
- mask: [1L, 2L, 4L, 8L, 16L, 32L, READ_CONTROL(0x20000L), WRITE_DAC(0x40000L), WRITE_OWNER(0x80000L), GENERIC_ALL(0x10000000L)]
15+
- Sid: S-1-0-0
16+
17+
ACE [1]: <AccessDeniedACE mask=269353023>
18+
- Header-AceType: ACCESS_DENIED_ACE_TYPE(0x1L)
19+
- Header-AceFlags: 10
20+
- Header-flags: [CONTAINER_INHERIT_ACE(0x2L), INHERIT_ONLY_ACE(0x8L)]
21+
- Mask: 269353023
22+
- mask: [1L, 2L, 4L, 8L, 16L, 32L, READ_CONTROL(0x20000L), WRITE_DAC(0x40000L), WRITE_OWNER(0x80000L), GENERIC_ALL(0x10000000L)]
23+
- Sid: S-1-0-0

docs/source/winproxy.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Calling it
7070
File "windows\winproxy.py", line 133, in perform_call
7171
return self._cprototyped(*args)
7272
File "windows\winproxy.py", line 59, in kernel32_error_check
73-
raise Kernel32Error(func_name)
74-
windows.winproxy.Kernel32Error: VirtualAlloc: [Error 8] Not enough storage is available to process this command.
73+
raise WinproxyError(func_name)
74+
windows.winproxy.error.WinproxyError: None: [Error 8] Not enough storage is available to process this command.
7575
"""
7676
7777
@@ -92,12 +92,12 @@ Helper functions
9292
'0x77340520'
9393

9494

95-
Kernel32Error
95+
WinproxyError
9696
"""""""""""""
9797

98-
All errors raised by winproxy functions are instance of :class:`Kernel32Error` (or subclasses)
98+
All errors raised by winproxy functions are instance of :class:`WinproxyError` (or subclasses)
9999

100-
.. autoclass:: Kernel32Error
100+
.. autoclass:: WinproxyError
101101
:show-inheritance:
102102

103103
.. attribute:: api_name

tests/test_wmi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_wmiobject_getitem(wmi_cls):
151151

152152
props = wmi_obj.get_properties()
153153
assert isinstance(props, list)
154-
assert len(props) > wmi_obj["__PROPERTY_COUNT"]
154+
assert len(props) == wmi_obj["__PROPERTY_COUNT"]
155155
# Check that other dict-like methods exists
156156
assert wmi_obj.keys()
157157
assert wmi_obj.values()

windows/utils/improved_buffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def buffer(obj, eltclass=None):
118118
return BUFFER(eltclass, dlen)(*obj)
119119

120120
def resized_array(array, newnbelt):
121-
btype = buffer_type(array._type_, newnbelt)
121+
btype = BUFFER(array._type_, newnbelt)
122122
new_array = btype.from_address(ctypes.addressof(array))
123123
new_array._base_array_ = array # Keep a ref to prevent some gc
124124
return new_array

0 commit comments

Comments
 (0)