From 4069c0892ab0473f1de21f626143c9674fb0936e Mon Sep 17 00:00:00 2001 From: Clement Rouault Date: Fri, 8 Jul 2016 13:58:05 +0200 Subject: [PATCH] Add com sample + update readme/todo --- README.md | 34 +++++++++++++++++++++++++++- TODO | 1 - samples/com_inetfwpolicy2.py | 32 ++++++++++++++++++++++++++ samples/debugger_membp_singlestep.py | 2 +- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 samples/com_inetfwpolicy2.py diff --git a/README.md b/README.md index 21563af..01e5b99 100644 --- a/README.md +++ b/README.md @@ -129,9 +129,41 @@ To extract/play with even more information about the system, PythonForWindows is (u'"C:\\Python27\\python.exe"', 227) ``` +### Registry + +The project also contains some wrapping classes around `_winreg` for simpler use. + +```python +>>> import windows +>>> from windows.generated_def import KEY_WRITE, KEY_READ, REG_QWORD +>>> registry = windows.system.registry +>>> cuuser_software = registry(r'HKEY_CURRENT_USER\Software') +>>> cuuser_software + +>>> cuuser_software.sam +KEY_READ(0x20019L) +# Explore subkeys +>>> cuuser_software.subkeys[:3] +[, , ] +>>> tstkey = registry('HKEY_CURRENT_USER\TestKey', KEY_WRITE | KEY_READ) +# Get / Set individual value +>>> tstkey["VALUE"] = 'a_value_for_my_key' +>>> tstkey["VALUE"] +KeyValue(name='VALUE', value=u'a_value_for_my_key', type=1) +>>> tstkey["MYQWORD"] = (123456789987654321, REG_QWORD) # Default is REG_DWORD for int/long +>>> tstkey["MYQWORD"] +KeyValue(name='MYQWORD', value=123456789987654321L, type=11) +# Explore Values +>>> tstkey.values +[KeyValue(name='MYQWORD', value=123456789987654321L, type=11), KeyValue(name='VALUE', value=u'a_value_for_my_key', type=1)] + + + +``` ### Other stuff (see doc / samples) -- Registry +- Debugger +- LocalDebugger (VEH based) - Network - Services - COM diff --git a/TODO b/TODO index 9b2d4dd..1ed50a9 100644 --- a/TODO +++ b/TODO @@ -20,7 +20,6 @@ TODO: - Add test for debugger with breakpoint that add another breakpoint on trigger - Some test/doc on windows.system.handles - - Some test/doc on debugger and MemBP - registry - test ! diff --git a/samples/com_inetfwpolicy2.py b/samples/com_inetfwpolicy2.py new file mode 100644 index 0000000..62425da --- /dev/null +++ b/samples/com_inetfwpolicy2.py @@ -0,0 +1,32 @@ +import sys +import os.path +import pprint +sys.path.append(os.path.abspath(__file__ + "\..\..")) + +import windows +import windows.generated_def as gdef +from windows.generated_def import interfaces + +# This code is a simple version of the firewall code in windows.winoject.network +print("Initialisation of COM") +windows.com.init() +print("Creating INetFwPolicy2 variable") +firewall = interfaces.INetFwPolicy2() +print("{0} (value = {1})".format(firewall, firewall.value)) +print("") + +print("Generating CLSID") +NetFwPolicy2CLSID = windows.com.IID.from_string("E2B3C97F-6AE1-41AC-817A-F6F92166D7DD") +print(NetFwPolicy2CLSID) +print("") + +print("Creating COM instance") +windows.com.create_instance(NetFwPolicy2CLSID, firewall) +print("{0} (value = 0x{1:0})".format(firewall, firewall.value)) +print("") + +print("Checking for enabled profiles") +for profile in [gdef.NET_FW_PROFILE2_DOMAIN, gdef.NET_FW_PROFILE2_PRIVATE, gdef.NET_FW_PROFILE2_PUBLIC]: + enabled = gdef.VARIANT_BOOL() + firewall.get_FirewallEnabled(profile, enabled) + print(" * {0} -> {1}".format(profile, enabled.value)) diff --git a/samples/debugger_membp_singlestep.py b/samples/debugger_membp_singlestep.py index e35ec8c..9c1e496 100644 --- a/samples/debugger_membp_singlestep.py +++ b/samples/debugger_membp_singlestep.py @@ -11,7 +11,6 @@ import windows.native_exec.simple_x86 as x86 from windows.generated_def.winstructs import * - class MyDebugger(windows.debug.Debugger): def __init__(self, *args, **kwargs): super(MyDebugger, self).__init__(*args, **kwargs) @@ -41,6 +40,7 @@ class SingleStepOnWrite(windows.debug.MemoryBreakpoint): dbg.single_step_counter = 4 return dbg.single_step() + calc = windows.test.pop_calc_32(dwCreationFlags=DEBUG_PROCESS) d = MyDebugger(calc)