atomicshop 2.15.11__py3-none-any.whl → 3.10.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- atomicshop/__init__.py +1 -1
- atomicshop/{addons/mains → a_mains}/FACT/update_extract.py +3 -2
- atomicshop/a_mains/dns_gateway_setting.py +11 -0
- atomicshop/a_mains/get_local_tcp_ports.py +85 -0
- atomicshop/a_mains/github_wrapper.py +11 -0
- atomicshop/a_mains/install_ca_certificate.py +172 -0
- atomicshop/a_mains/process_from_port.py +119 -0
- atomicshop/a_mains/set_default_dns_gateway.py +90 -0
- atomicshop/a_mains/update_config_toml.py +38 -0
- atomicshop/basics/ansi_escape_codes.py +3 -1
- atomicshop/basics/argparse_template.py +2 -0
- atomicshop/basics/booleans.py +27 -30
- atomicshop/basics/bytes_arrays.py +43 -0
- atomicshop/basics/classes.py +149 -1
- atomicshop/basics/enums.py +2 -2
- atomicshop/basics/exceptions.py +5 -1
- atomicshop/basics/list_of_classes.py +29 -0
- atomicshop/basics/multiprocesses.py +374 -50
- atomicshop/basics/strings.py +72 -3
- atomicshop/basics/threads.py +14 -0
- atomicshop/basics/tracebacks.py +13 -3
- atomicshop/certificates.py +153 -52
- atomicshop/config_init.py +11 -6
- atomicshop/console_user_response.py +7 -14
- atomicshop/consoles.py +9 -0
- atomicshop/datetimes.py +1 -1
- atomicshop/diff_check.py +3 -3
- atomicshop/dns.py +128 -3
- atomicshop/etws/_pywintrace_fix.py +17 -0
- atomicshop/etws/trace.py +40 -42
- atomicshop/etws/traces/trace_dns.py +56 -44
- atomicshop/etws/traces/trace_tcp.py +130 -0
- atomicshop/file_io/csvs.py +27 -5
- atomicshop/file_io/docxs.py +34 -17
- atomicshop/file_io/file_io.py +31 -17
- atomicshop/file_io/jsons.py +49 -0
- atomicshop/file_io/tomls.py +139 -0
- atomicshop/filesystem.py +616 -291
- atomicshop/get_process_list.py +3 -3
- atomicshop/http_parse.py +149 -93
- atomicshop/ip_addresses.py +6 -1
- atomicshop/mitm/centered_settings.py +132 -0
- atomicshop/mitm/config_static.py +207 -0
- atomicshop/mitm/config_toml_editor.py +55 -0
- atomicshop/mitm/connection_thread_worker.py +875 -357
- atomicshop/mitm/engines/__parent/parser___parent.py +4 -17
- atomicshop/mitm/engines/__parent/recorder___parent.py +108 -51
- atomicshop/mitm/engines/__parent/requester___parent.py +116 -0
- atomicshop/mitm/engines/__parent/responder___parent.py +75 -114
- atomicshop/mitm/engines/__reference_general/parser___reference_general.py +10 -7
- atomicshop/mitm/engines/__reference_general/recorder___reference_general.py +5 -5
- atomicshop/mitm/engines/__reference_general/requester___reference_general.py +47 -0
- atomicshop/mitm/engines/__reference_general/responder___reference_general.py +95 -13
- atomicshop/mitm/engines/create_module_template.py +58 -14
- atomicshop/mitm/import_config.py +359 -139
- atomicshop/mitm/initialize_engines.py +160 -80
- atomicshop/mitm/message.py +64 -23
- atomicshop/mitm/mitm_main.py +892 -0
- atomicshop/mitm/recs_files.py +183 -0
- atomicshop/mitm/shared_functions.py +4 -10
- atomicshop/mitm/ssh_tester.py +82 -0
- atomicshop/mitm/statistic_analyzer.py +136 -40
- atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +265 -83
- atomicshop/monitor/checks/dns.py +1 -1
- atomicshop/networks.py +671 -0
- atomicshop/on_exit.py +39 -9
- atomicshop/package_mains_processor.py +84 -0
- atomicshop/permissions/permissions.py +22 -0
- atomicshop/permissions/ubuntu_permissions.py +239 -0
- atomicshop/permissions/win_permissions.py +33 -0
- atomicshop/print_api.py +24 -42
- atomicshop/process.py +24 -6
- atomicshop/process_poller/process_pool.py +0 -1
- atomicshop/process_poller/simple_process_pool.py +204 -5
- atomicshop/python_file_patcher.py +1 -1
- atomicshop/python_functions.py +27 -75
- atomicshop/speech_recognize.py +8 -0
- atomicshop/ssh_remote.py +158 -172
- atomicshop/system_resource_monitor.py +61 -47
- atomicshop/system_resources.py +8 -8
- atomicshop/tempfiles.py +1 -2
- atomicshop/urls.py +6 -0
- atomicshop/venvs.py +28 -0
- atomicshop/versioning.py +27 -0
- atomicshop/web.py +98 -27
- atomicshop/web_apis/google_custom_search.py +44 -0
- atomicshop/web_apis/google_llm.py +188 -0
- atomicshop/websocket_parse.py +450 -0
- atomicshop/wrappers/certauthw/certauth.py +1 -0
- atomicshop/wrappers/cryptographyw.py +29 -8
- atomicshop/wrappers/ctyping/etw_winapi/const.py +97 -47
- atomicshop/wrappers/ctyping/etw_winapi/etw_functions.py +178 -49
- atomicshop/wrappers/ctyping/file_details_winapi.py +67 -0
- atomicshop/wrappers/ctyping/msi_windows_installer/cabs.py +2 -1
- atomicshop/wrappers/ctyping/msi_windows_installer/extract_msi_main.py +2 -2
- atomicshop/wrappers/ctyping/setup_device.py +466 -0
- atomicshop/wrappers/ctyping/win_console.py +39 -0
- atomicshop/wrappers/dockerw/dockerw.py +113 -2
- atomicshop/wrappers/elasticsearchw/config_basic.py +0 -12
- atomicshop/wrappers/elasticsearchw/elastic_infra.py +75 -0
- atomicshop/wrappers/elasticsearchw/elasticsearchw.py +2 -20
- atomicshop/wrappers/factw/get_file_data.py +12 -5
- atomicshop/wrappers/factw/install/install_after_restart.py +89 -5
- atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py +20 -14
- atomicshop/wrappers/githubw.py +537 -54
- atomicshop/wrappers/loggingw/consts.py +1 -1
- atomicshop/wrappers/loggingw/filters.py +23 -0
- atomicshop/wrappers/loggingw/formatters.py +12 -0
- atomicshop/wrappers/loggingw/handlers.py +214 -107
- atomicshop/wrappers/loggingw/loggers.py +19 -0
- atomicshop/wrappers/loggingw/loggingw.py +860 -22
- atomicshop/wrappers/loggingw/reading.py +134 -112
- atomicshop/wrappers/mongodbw/mongo_infra.py +31 -0
- atomicshop/wrappers/mongodbw/mongodbw.py +1324 -36
- atomicshop/wrappers/netshw.py +271 -0
- atomicshop/wrappers/playwrightw/engine.py +34 -19
- atomicshop/wrappers/playwrightw/infra.py +5 -0
- atomicshop/wrappers/playwrightw/javascript.py +7 -3
- atomicshop/wrappers/playwrightw/keyboard.py +14 -0
- atomicshop/wrappers/playwrightw/scenarios.py +172 -5
- atomicshop/wrappers/playwrightw/waits.py +9 -7
- atomicshop/wrappers/powershell_networking.py +80 -0
- atomicshop/wrappers/psutilw/processes.py +37 -1
- atomicshop/wrappers/psutilw/psutil_networks.py +85 -0
- atomicshop/wrappers/pyopensslw.py +9 -2
- atomicshop/wrappers/pywin32w/cert_store.py +116 -0
- atomicshop/wrappers/pywin32w/win_event_log/fetch.py +174 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_create.py +3 -105
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_terminate.py +3 -57
- atomicshop/wrappers/pywin32w/wmis/msft_netipaddress.py +113 -0
- atomicshop/wrappers/pywin32w/wmis/win32_networkadapterconfiguration.py +259 -0
- atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +112 -0
- atomicshop/wrappers/pywin32w/wmis/wmi_helpers.py +236 -0
- atomicshop/wrappers/socketw/accepter.py +21 -7
- atomicshop/wrappers/socketw/certificator.py +216 -150
- atomicshop/wrappers/socketw/creator.py +190 -50
- atomicshop/wrappers/socketw/dns_server.py +491 -182
- atomicshop/wrappers/socketw/exception_wrapper.py +45 -52
- atomicshop/wrappers/socketw/process_getter.py +86 -0
- atomicshop/wrappers/socketw/receiver.py +144 -102
- atomicshop/wrappers/socketw/sender.py +65 -35
- atomicshop/wrappers/socketw/sni.py +334 -165
- atomicshop/wrappers/socketw/socket_base.py +134 -0
- atomicshop/wrappers/socketw/socket_client.py +137 -95
- atomicshop/wrappers/socketw/socket_server_tester.py +11 -7
- atomicshop/wrappers/socketw/socket_wrapper.py +717 -116
- atomicshop/wrappers/socketw/ssl_base.py +15 -14
- atomicshop/wrappers/socketw/statistics_csv.py +148 -17
- atomicshop/wrappers/sysmonw.py +1 -1
- atomicshop/wrappers/ubuntu_terminal.py +65 -26
- atomicshop/wrappers/win_auditw.py +189 -0
- atomicshop/wrappers/winregw/__init__.py +0 -0
- atomicshop/wrappers/winregw/winreg_installed_software.py +58 -0
- atomicshop/wrappers/winregw/winreg_network.py +232 -0
- {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info}/METADATA +31 -51
- atomicshop-3.10.5.dist-info/RECORD +306 -0
- {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info}/WHEEL +1 -1
- atomicshop/_basics_temp.py +0 -101
- atomicshop/a_installs/win/fibratus.py +0 -9
- atomicshop/a_installs/win/mongodb.py +0 -9
- atomicshop/a_installs/win/pycharm.py +0 -9
- atomicshop/addons/a_setup_scripts/install_psycopg2_ubuntu.sh +0 -3
- atomicshop/addons/a_setup_scripts/install_pywintrace_0.3.cmd +0 -2
- atomicshop/addons/mains/__pycache__/install_fibratus_windows.cpython-312.pyc +0 -0
- atomicshop/addons/mains/__pycache__/msi_unpacker.cpython-312.pyc +0 -0
- atomicshop/addons/mains/install_docker_rootless_ubuntu.py +0 -11
- atomicshop/addons/mains/install_docker_ubuntu_main_sudo.py +0 -11
- atomicshop/addons/mains/install_elastic_search_and_kibana_ubuntu.py +0 -10
- atomicshop/addons/mains/install_wsl_ubuntu_lts_admin.py +0 -9
- atomicshop/addons/package_setup/CreateWheel.cmd +0 -7
- atomicshop/addons/package_setup/Setup in Edit mode.cmd +0 -6
- atomicshop/addons/package_setup/Setup.cmd +0 -7
- atomicshop/archiver/_search_in_zip.py +0 -189
- atomicshop/archiver/archiver.py +0 -34
- atomicshop/archiver/search_in_archive.py +0 -250
- atomicshop/archiver/sevenz_app_w.py +0 -86
- atomicshop/archiver/sevenzs.py +0 -44
- atomicshop/archiver/zips.py +0 -293
- atomicshop/file_types.py +0 -24
- atomicshop/mitm/config_editor.py +0 -37
- atomicshop/mitm/engines/create_module_template_example.py +0 -13
- atomicshop/mitm/initialize_mitm_server.py +0 -268
- atomicshop/pbtkmultifile_argparse.py +0 -88
- atomicshop/permissions.py +0 -151
- atomicshop/script_as_string_processor.py +0 -38
- atomicshop/ssh_scripts/process_from_ipv4.py +0 -37
- atomicshop/ssh_scripts/process_from_port.py +0 -27
- atomicshop/wrappers/_process_wrapper_curl.py +0 -27
- atomicshop/wrappers/_process_wrapper_tar.py +0 -21
- atomicshop/wrappers/dockerw/install_docker.py +0 -209
- atomicshop/wrappers/elasticsearchw/infrastructure.py +0 -265
- atomicshop/wrappers/elasticsearchw/install_elastic.py +0 -232
- atomicshop/wrappers/ffmpegw.py +0 -125
- atomicshop/wrappers/fibratusw/install.py +0 -81
- atomicshop/wrappers/mongodbw/infrastructure.py +0 -53
- atomicshop/wrappers/mongodbw/install_mongodb.py +0 -190
- atomicshop/wrappers/msiw.py +0 -149
- atomicshop/wrappers/nodejsw/install_nodejs.py +0 -139
- atomicshop/wrappers/process_wrapper_pbtk.py +0 -16
- atomicshop/wrappers/psutilw/networks.py +0 -45
- atomicshop/wrappers/pycharmw.py +0 -81
- atomicshop/wrappers/socketw/base.py +0 -59
- atomicshop/wrappers/socketw/get_process.py +0 -107
- atomicshop/wrappers/wslw.py +0 -191
- atomicshop-2.15.11.dist-info/RECORD +0 -302
- /atomicshop/{addons/mains → a_mains}/FACT/factw_fact_extractor_docker_image_main_sudo.py +0 -0
- /atomicshop/{addons → a_mains/addons}/PlayWrightCodegen.cmd +0 -0
- /atomicshop/{addons → a_mains/addons}/ScriptExecution.cmd +0 -0
- /atomicshop/{addons → a_mains/addons}/inits/init_to_import_all_modules.py +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/ReadMe.txt +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/compile.cmd +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.dll +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.exp +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.lib +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/process_list.cpp +0 -0
- /atomicshop/{archiver → permissions}/__init__.py +0 -0
- /atomicshop/{wrappers/fibratusw → web_apis}/__init__.py +0 -0
- /atomicshop/wrappers/{nodejsw → pywin32w/wmis}/__init__.py +0 -0
- /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
- {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info/licenses}/LICENSE.txt +0 -0
- {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Union
|
|
3
|
+
|
|
4
|
+
import win32com.client
|
|
5
|
+
from win32com.client import CDispatch
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class WmiMethodExecutionError(Exception):
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WmiMethodParameterError(Exception):
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class EmptyValue:
|
|
17
|
+
pass
|
|
18
|
+
_EMPTY_VALUE = EmptyValue()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class WMINetworkAdapterNotFoundError(Exception):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
LOCAL_SERVER: str = '.'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_wmi_instance(
|
|
29
|
+
server: str = LOCAL_SERVER,
|
|
30
|
+
namespace: str = 'root\\cimv2',
|
|
31
|
+
wmi_instance: CDispatch = None,
|
|
32
|
+
locator: CDispatch = None
|
|
33
|
+
) -> tuple[CDispatch, CDispatch]:
|
|
34
|
+
"""
|
|
35
|
+
Get the WMI instance.
|
|
36
|
+
|
|
37
|
+
:param server: str, The server you want to connect to. Default is '.' (local machine).
|
|
38
|
+
:param namespace: str, WMI namespace. Default is 'root\\cimv2'.
|
|
39
|
+
Other examples:
|
|
40
|
+
'root\\StandardCimv2'
|
|
41
|
+
:param wmi_instance: WMI connected instance.
|
|
42
|
+
:param locator: WMI locator instance. If not provided, a new one will be created.
|
|
43
|
+
:return: WMI instance.
|
|
44
|
+
|
|
45
|
+
===================
|
|
46
|
+
|
|
47
|
+
If you want to connect directly to a WMI namespace, you can use the following code:
|
|
48
|
+
return win32com.client.GetObject(f"winmgmts:\\\\{location}\\{namespace}")
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
if not locator:
|
|
52
|
+
# This is a better way to get the WMI instance, since you have more control over the WMI object.
|
|
53
|
+
locator: CDispatch = win32com.client.Dispatch('WbemScripting.SWbemLocator')
|
|
54
|
+
|
|
55
|
+
if wmi_instance:
|
|
56
|
+
server_from_instance, namespace_from_instance = get_connection_details(wmi_instance)
|
|
57
|
+
|
|
58
|
+
# If current server name of the wmi connection is not the same as was passed to the function,
|
|
59
|
+
# then create a new connection to the server.
|
|
60
|
+
if server_from_instance.lower() != server.lower():
|
|
61
|
+
if not (server_from_instance.lower() == os.environ["COMPUTERNAME"].lower() and server.lower() == LOCAL_SERVER):
|
|
62
|
+
wmi_instance = locator.ConnectServer(server, namespace)
|
|
63
|
+
# If the namespace is not the same as was passed to the function.
|
|
64
|
+
if namespace_from_instance != namespace:
|
|
65
|
+
wmi_instance = locator.ConnectServer(server, namespace)
|
|
66
|
+
|
|
67
|
+
else:
|
|
68
|
+
wmi_instance: CDispatch = locator.ConnectServer(server, namespace)
|
|
69
|
+
|
|
70
|
+
return wmi_instance, locator
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def get_connection_details(wmi_instance: CDispatch) -> tuple[str, str]:
|
|
74
|
+
"""
|
|
75
|
+
Get the connection details: connected server and namespace.
|
|
76
|
+
|
|
77
|
+
:param wmi_instance: WMI instance.
|
|
78
|
+
:return: tuple of server and namespace.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
# Get the current connection details.
|
|
82
|
+
# Get the security object for the WMI instance.
|
|
83
|
+
security_object: CDispatch = wmi_instance.Get("__SystemSecurity=@")
|
|
84
|
+
# Get the Paths.
|
|
85
|
+
path: CDispatch = security_object.Path_
|
|
86
|
+
|
|
87
|
+
server_from_instance: str = path.Server
|
|
88
|
+
namespace_from_instance: str = path.Namespace
|
|
89
|
+
|
|
90
|
+
return server_from_instance, namespace_from_instance
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def get_method(
|
|
94
|
+
wmi_object: win32com.client.CDispatch,
|
|
95
|
+
method_name: str
|
|
96
|
+
):
|
|
97
|
+
"""
|
|
98
|
+
Get the WMI method.
|
|
99
|
+
|
|
100
|
+
:param wmi_object: WMI object.
|
|
101
|
+
:param method_name: str, name of the method.
|
|
102
|
+
:return: WMI method object.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
return wmi_object.Methods_(method_name)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def get_method_parameter_instance(
|
|
109
|
+
method: win32com.client.CDispatch
|
|
110
|
+
):
|
|
111
|
+
"""
|
|
112
|
+
Get the WMI method parameter.
|
|
113
|
+
|
|
114
|
+
:param method: WMI method object.
|
|
115
|
+
:return: WMI method parameter object.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
return method.inParameters.SpawnInstance_()
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def call_method(
|
|
122
|
+
wmi_object: win32com.client.CDispatch,
|
|
123
|
+
method_name: str,
|
|
124
|
+
value: Union[
|
|
125
|
+
Union[tuple, dict],
|
|
126
|
+
Union[bool, str, list]] = _EMPTY_VALUE
|
|
127
|
+
):
|
|
128
|
+
"""
|
|
129
|
+
Call the WMI method.
|
|
130
|
+
|
|
131
|
+
:param wmi_object: WMI object.
|
|
132
|
+
:param method_name: str, name of the method.
|
|
133
|
+
:param value: tuple, value to pass to the method.
|
|
134
|
+
tuple: If ou pass a tuple, it will be unpacked and passed as positional arguments.
|
|
135
|
+
Dor example if a method requires 2 parameters, you can pass a tuple with 2 values.
|
|
136
|
+
dict: If you pass a dictionary, it will be unpacked and passed as keyword arguments.
|
|
137
|
+
|
|
138
|
+
If you pass a single value, which is not a dict or tuple, it will be passed as a single parameter.
|
|
139
|
+
|
|
140
|
+
Methods can receive a None value if they don't require any parameters.
|
|
141
|
+
If the method doesn't require any parameters, leave it as 'EmptyValue' class.
|
|
142
|
+
:return: WMI method object.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
# Assign the single value to a tuple if it is not already a tuple or dict and not an EmptyValue.
|
|
146
|
+
if not isinstance(value, (EmptyValue, tuple, dict)):
|
|
147
|
+
value = (value,)
|
|
148
|
+
|
|
149
|
+
# Get the method instance out of the WMI object.
|
|
150
|
+
method = get_method(wmi_object, method_name)
|
|
151
|
+
|
|
152
|
+
# ── discover the method’s IN parameters up-front ─────────────────────────────
|
|
153
|
+
if method.InParameters:
|
|
154
|
+
input_properties: list = [(in_property.Name, in_property.IsArray) for in_property in method.InParameters.Properties_]
|
|
155
|
+
else:
|
|
156
|
+
input_properties: list = [] # no inputs expected
|
|
157
|
+
|
|
158
|
+
expected = len(input_properties) # how many inputs the method wants
|
|
159
|
+
|
|
160
|
+
got_tuple = isinstance(value, tuple)
|
|
161
|
+
got_dict = isinstance(value, dict)
|
|
162
|
+
got_empty = isinstance(value, EmptyValue)
|
|
163
|
+
|
|
164
|
+
# ── validate the caller’s intent ─────────────────────────────────────────────
|
|
165
|
+
if expected == 0 and not got_empty:
|
|
166
|
+
raise WmiMethodParameterError(
|
|
167
|
+
f"Method '{method_name}' takes no parameters, got: {value!r}"
|
|
168
|
+
)
|
|
169
|
+
if expected > 0 and got_empty:
|
|
170
|
+
raise WmiMethodParameterError(
|
|
171
|
+
f"Method '{method_name}' expects {expected} parameter(s); none given."
|
|
172
|
+
)
|
|
173
|
+
if got_tuple and len(value) != expected:
|
|
174
|
+
raise WmiMethodParameterError(
|
|
175
|
+
f"Method '{method_name}' expects {expected} parameter(s); "
|
|
176
|
+
f"{len(value)} positional value(s) given."
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
# ── prepare the parameter object if needed ──────────────────────────────────
|
|
180
|
+
if expected == 0: # simple – no inputs
|
|
181
|
+
result = wmi_object.ExecMethod_(method_name)
|
|
182
|
+
|
|
183
|
+
else:
|
|
184
|
+
param_obj = get_method_parameter_instance(method)
|
|
185
|
+
|
|
186
|
+
if got_tuple: # positional list / tuple
|
|
187
|
+
for (name, is_array), val in zip(input_properties, value):
|
|
188
|
+
setattr(param_obj, name, val)
|
|
189
|
+
|
|
190
|
+
elif got_dict: # mapping by name
|
|
191
|
+
for name, _ in input_properties:
|
|
192
|
+
if name in value:
|
|
193
|
+
setattr(param_obj, name, value[name])
|
|
194
|
+
|
|
195
|
+
else: # single scalar for one-input method
|
|
196
|
+
name, is_array = input_properties[0]
|
|
197
|
+
if is_array and not (isinstance(value, list) or value is None):
|
|
198
|
+
raise WmiMethodParameterError(
|
|
199
|
+
f"Parameter '{name}' must be a list.\nValue: {value!r}"
|
|
200
|
+
)
|
|
201
|
+
setattr(param_obj, name, value)
|
|
202
|
+
|
|
203
|
+
result = wmi_object.ExecMethod_(method_name, param_obj)
|
|
204
|
+
|
|
205
|
+
# ── collect OUT parameters & check return code ──────────────────────────────
|
|
206
|
+
out_vals = []
|
|
207
|
+
if method.OutParameters:
|
|
208
|
+
for parameter in method.OutParameters.Properties_:
|
|
209
|
+
out_vals.append(result.Properties_(parameter.Name).Value)
|
|
210
|
+
|
|
211
|
+
# return-code conventions: 0 = OK, 1 = OK-needs-reboot
|
|
212
|
+
if out_vals and out_vals[0] not in (0, 1):
|
|
213
|
+
result_code: int = out_vals[0]
|
|
214
|
+
if result_code == 91:
|
|
215
|
+
raise PermissionError(
|
|
216
|
+
f"Method '{method_name}' failed (code {result_code}) – try with admin rights."
|
|
217
|
+
)
|
|
218
|
+
if result_code == 68:
|
|
219
|
+
raise WmiMethodExecutionError(
|
|
220
|
+
f"Method '{method_name}' failed (code {result_code}) – Invalid input parameter"
|
|
221
|
+
)
|
|
222
|
+
raise WmiMethodExecutionError(
|
|
223
|
+
f"Method '{method_name}' failed with error code {result_code}"
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
return out_vals or None
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
"""
|
|
230
|
+
# Setting SeDebugPrivilege
|
|
231
|
+
import win32security, ntsecuritycon, win32con, win32api
|
|
232
|
+
privs = ((win32security.LookupPrivilegeValue('',ntsecuritycon.SE_DEBUG_NAME), win32con.SE_PRIVILEGE_ENABLED),)
|
|
233
|
+
hToken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32security.TOKEN_ALL_ACCESS)
|
|
234
|
+
win32security.AdjustTokenPrivileges(hToken, False, privs)
|
|
235
|
+
win32api.CloseHandle(hToken)
|
|
236
|
+
"""
|
|
@@ -2,17 +2,21 @@ from . import exception_wrapper
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
@exception_wrapper.connection_exception_decorator
|
|
5
|
-
def accept_connection(
|
|
5
|
+
def accept_connection(
|
|
6
|
+
socket_object,
|
|
7
|
+
domain_from_dns_server: str = None,
|
|
8
|
+
print_kwargs: dict = None
|
|
9
|
+
):
|
|
6
10
|
"""
|
|
7
11
|
Accept connection from client.
|
|
8
12
|
This function is wrapped with exception wrapper.
|
|
9
13
|
After you execute the function, you can get the error message if there was any with:
|
|
10
14
|
error_message = accept_connection.message
|
|
11
15
|
|
|
12
|
-
:param socket_object:
|
|
13
|
-
:param
|
|
14
|
-
|
|
15
|
-
:
|
|
16
|
+
:param socket_object: The socket object to accept the connection on.
|
|
17
|
+
:param domain_from_dns_server: The domain that will be printed to console on logger, needed for the decorator.
|
|
18
|
+
If not provided, the TCP data will be used.
|
|
19
|
+
:param print_kwargs: Additional arguments for the print_api function, needed for the decorator.
|
|
16
20
|
"""
|
|
17
21
|
|
|
18
22
|
client_socket = None
|
|
@@ -33,8 +37,18 @@ def accept_connection(socket_object, dns_domain, print_kwargs: dict = None):
|
|
|
33
37
|
return client_socket, client_address_tuple
|
|
34
38
|
|
|
35
39
|
|
|
36
|
-
def accept_connection_with_error(
|
|
37
|
-
|
|
40
|
+
def accept_connection_with_error(
|
|
41
|
+
socket_object,
|
|
42
|
+
domain_from_dns_server,
|
|
43
|
+
print_kwargs: dict = None
|
|
44
|
+
):
|
|
45
|
+
"""
|
|
46
|
+
:param socket_object: The socket object to accept the connection on.
|
|
47
|
+
:param domain_from_dns_server: The domain that will be printed to console on logger.
|
|
48
|
+
:param print_kwargs: Additional arguments for the print_api function.
|
|
49
|
+
"""
|
|
50
|
+
client_socket, client_address_tuple = accept_connection(
|
|
51
|
+
socket_object, domain_from_dns_server, print_kwargs=print_kwargs)
|
|
38
52
|
error_message = accept_connection.message
|
|
39
53
|
|
|
40
54
|
return client_socket, client_address_tuple, error_message
|