atomicshop 2.21.0__py3-none-any.whl → 3.0.0__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.
Potentially problematic release.
This version of atomicshop might be problematic. Click here for more details.
- atomicshop/__init__.py +1 -1
- atomicshop/basics/multiprocesses.py +228 -30
- atomicshop/dns.py +2 -0
- atomicshop/mitm/config_static.py +2 -1
- atomicshop/mitm/connection_thread_worker.py +124 -157
- atomicshop/mitm/engines/__parent/responder___parent.py +43 -43
- atomicshop/mitm/engines/__reference_general/responder___reference_general.py +43 -43
- atomicshop/mitm/engines/create_module_template.py +2 -7
- atomicshop/mitm/import_config.py +30 -26
- atomicshop/mitm/initialize_engines.py +9 -24
- atomicshop/mitm/mitm_main.py +187 -59
- atomicshop/networks.py +448 -0
- atomicshop/wrappers/ctyping/setup_device.py +466 -0
- atomicshop/wrappers/dockerw/dockerw.py +17 -21
- atomicshop/wrappers/mongodbw/mongodbw.py +1 -0
- atomicshop/wrappers/psutilw/{networks.py → psutil_networks.py} +3 -1
- atomicshop/wrappers/pywin32w/wmis/msft_netipaddress.py +76 -0
- atomicshop/wrappers/pywin32w/wmis/win32_networkadapterconfiguration.py +262 -0
- atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +51 -82
- atomicshop/wrappers/pywin32w/wmis/wmi_helpers.py +235 -0
- atomicshop/wrappers/socketw/accepter.py +15 -1
- atomicshop/wrappers/socketw/creator.py +7 -1
- atomicshop/wrappers/socketw/dns_server.py +33 -39
- atomicshop/wrappers/socketw/exception_wrapper.py +20 -11
- atomicshop/wrappers/socketw/socket_wrapper.py +29 -78
- atomicshop/wrappers/winregw/winreg_network.py +20 -0
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/METADATA +2 -1
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/RECORD +31 -27
- atomicshop/wrappers/pywin32w/wmis/helpers.py +0 -131
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/LICENSE.txt +0 -0
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/WHEEL +0 -0
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/top_level.txt +0 -0
atomicshop/__init__.py
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import multiprocessing
|
|
2
2
|
import multiprocessing.managers
|
|
3
|
+
import os
|
|
3
4
|
import queue
|
|
5
|
+
import threading
|
|
4
6
|
import concurrent.futures
|
|
5
7
|
from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
8
|
+
from collections import deque
|
|
6
9
|
from typing import Callable
|
|
7
10
|
|
|
8
11
|
from ..import system_resources
|
|
9
12
|
|
|
10
13
|
|
|
11
|
-
def process_wrap_queue(function_reference, *args, **kwargs):
|
|
14
|
+
def process_wrap_queue(function_reference: Callable, *args, **kwargs):
|
|
12
15
|
"""
|
|
13
16
|
The function receives function reference and arguments, and executes the function in a thread.
|
|
14
17
|
"_queue" means that a queue.put() is used to store the result of the function and queue.get() to output it.
|
|
@@ -154,38 +157,63 @@ class MultiProcessorRecursive:
|
|
|
154
157
|
self.async_results: list = []
|
|
155
158
|
|
|
156
159
|
def run_process(self):
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
"""
|
|
161
|
+
Start with the items currently in self.input_list, but whenever a task
|
|
162
|
+
finishes schedule the children it returns *right away*.
|
|
163
|
+
The loop ends when there are no more outstanding tasks.
|
|
164
|
+
"""
|
|
165
|
+
# ---------- internal helpers ----------
|
|
166
|
+
outstanding = 0 # tasks that have been submitted but not yet finished
|
|
167
|
+
done_event = threading.Event() # let the main thread wait until work is over
|
|
168
|
+
|
|
169
|
+
def _submit(item):
|
|
170
|
+
nonlocal outstanding
|
|
171
|
+
# Wait for resources *before* submitting a new job
|
|
172
|
+
system_resources.wait_for_resource_availability(
|
|
173
|
+
cpu_percent_max=self.cpu_percent_max,
|
|
174
|
+
memory_percent_max=self.memory_percent_max,
|
|
175
|
+
wait_time=self.wait_time,
|
|
176
|
+
system_monitor_manager_dict=self.system_monitor_manager_dict
|
|
177
|
+
)
|
|
178
|
+
outstanding += 1
|
|
179
|
+
self.pool.apply_async(
|
|
180
|
+
self.process_function,
|
|
181
|
+
(item,),
|
|
182
|
+
callback=_on_finish, # called in the main process when result is ready
|
|
183
|
+
error_callback=_on_error
|
|
184
|
+
)
|
|
166
185
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
186
|
+
def _on_finish(result):
|
|
187
|
+
"""Pool calls this in the parent process thread when a job completes."""
|
|
188
|
+
nonlocal outstanding
|
|
189
|
+
outstanding -= 1
|
|
170
190
|
|
|
171
|
-
#
|
|
172
|
-
|
|
191
|
+
# The worker returned a list of new items – submit them immediately
|
|
192
|
+
if result:
|
|
193
|
+
for child in result:
|
|
194
|
+
_submit(child)
|
|
195
|
+
|
|
196
|
+
# If no work left, release the waiter
|
|
197
|
+
if outstanding == 0:
|
|
198
|
+
done_event.set()
|
|
173
199
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
200
|
+
def _on_error(exc):
|
|
201
|
+
"""Propagate the first exception and stop everything cleanly."""
|
|
202
|
+
done_event.set()
|
|
203
|
+
raise exc # let your code deal with it – you can customise this
|
|
204
|
+
|
|
205
|
+
# ---------- kick‑off ----------
|
|
206
|
+
# Schedule the items we already have
|
|
207
|
+
for item in self.input_list:
|
|
208
|
+
_submit(item)
|
|
209
|
+
|
|
210
|
+
# Clear the input list; after this point everything is driven by callbacks
|
|
211
|
+
self.input_list.clear()
|
|
212
|
+
|
|
213
|
+
# Wait until all recursively spawned work is finished
|
|
214
|
+
done_event.wait()
|
|
215
|
+
|
|
216
|
+
def shutdown(self):
|
|
189
217
|
"""Shuts down the pool gracefully."""
|
|
190
218
|
if self.pool:
|
|
191
219
|
self.pool.close() # Stop accepting new tasks
|
|
@@ -193,6 +221,176 @@ class MultiProcessorRecursive:
|
|
|
193
221
|
self.pool = None
|
|
194
222
|
|
|
195
223
|
|
|
224
|
+
class _MultiProcessorRecursiveWithProcessPoolExecutor:
|
|
225
|
+
def __init__(
|
|
226
|
+
self,
|
|
227
|
+
process_function: Callable,
|
|
228
|
+
input_list: list,
|
|
229
|
+
max_workers: int = None,
|
|
230
|
+
cpu_percent_max: int = 80,
|
|
231
|
+
memory_percent_max: int = 80,
|
|
232
|
+
wait_time: float = 5,
|
|
233
|
+
system_monitor_manager_dict: multiprocessing.managers.DictProxy = None
|
|
234
|
+
):
|
|
235
|
+
"""
|
|
236
|
+
THIS CLASS USES THE concurrent.futures.ProcessPoolExecutor to achieve parallelism.
|
|
237
|
+
For some reason I got freezes on exceptions without the exception output after the run_process() method finished
|
|
238
|
+
and the pool remained open. So, using the MultiProcessorRecursive instead.
|
|
239
|
+
|
|
240
|
+
MultiProcessor class. Used to execute functions in parallel. The result of each execution is fed back
|
|
241
|
+
to the provided function. Making it sort of recursive execution.
|
|
242
|
+
:param process_function: function, function to execute on the input list.
|
|
243
|
+
:param input_list: list, list of inputs to process.
|
|
244
|
+
:param max_workers: integer, number of workers to execute functions in parallel. Default is None, which
|
|
245
|
+
is the number of CPUs that will be counted automatically by the multiprocessing module.
|
|
246
|
+
:param cpu_percent_max: integer, maximum CPU percentage. Above that usage, we will wait before starting new
|
|
247
|
+
execution.
|
|
248
|
+
:param memory_percent_max: integer, maximum memory percentage. Above that usage, we will wait, before starting
|
|
249
|
+
new execution.
|
|
250
|
+
:param wait_time: float, time to wait if the CPU or memory usage is above the maximum percentage.
|
|
251
|
+
:param system_monitor_manager_dict: multiprocessing.managers.DictProxy, shared manager dict for
|
|
252
|
+
system monitoring. The object is the output of atomicshop.system_resource_monitor.
|
|
253
|
+
If you are already running this monitor, you can pass the manager_dict to both the system monitor and this
|
|
254
|
+
class to share the system resources data.
|
|
255
|
+
If this is used, the system resources will be checked before starting each new execution from this
|
|
256
|
+
shared dict instead of performing new checks.
|
|
257
|
+
|
|
258
|
+
Usage Examples:
|
|
259
|
+
def unpack_file(file_path):
|
|
260
|
+
# Process the file at file_path and unpack it.
|
|
261
|
+
# Return a list of new file paths that were extracted from the provided path.
|
|
262
|
+
return [new_file_path1, new_file_path2] # Example return value
|
|
263
|
+
|
|
264
|
+
# List of file paths to process
|
|
265
|
+
file_paths = ["path1", "path2", "path3"]
|
|
266
|
+
|
|
267
|
+
# Note: unpack_file Callable is passed to init without parentheses.
|
|
268
|
+
|
|
269
|
+
1. Providing the list directly to process at once:
|
|
270
|
+
# Initialize the processor.
|
|
271
|
+
processor = MultiProcessor(
|
|
272
|
+
process_function=unpack_file,
|
|
273
|
+
input_list=file_paths,
|
|
274
|
+
max_workers=4, # Number of parallel workers
|
|
275
|
+
cpu_percent_max=80, # Max CPU usage percentage
|
|
276
|
+
memory_percent_max=80, # Max memory usage percentage
|
|
277
|
+
wait_time=5 # Time to wait if resources are overused
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
# Process the list of files at once.
|
|
281
|
+
processor.run_process()
|
|
282
|
+
# Shutdown the pool processes after processing.
|
|
283
|
+
processor.shutdown_pool()
|
|
284
|
+
|
|
285
|
+
2. Processing each file in the list differently then adding to the list of the multiprocessing instance then executing.
|
|
286
|
+
# Initialize the processor once, before the loop, with empty input_list.
|
|
287
|
+
processor = MultiProcessor(
|
|
288
|
+
process_function=unpack_file,
|
|
289
|
+
input_list=[],
|
|
290
|
+
max_workers=4, # Number of parallel workers
|
|
291
|
+
cpu_percent_max=80, # Max CPU usage percentage
|
|
292
|
+
memory_percent_max=80, # Max memory usage percentage
|
|
293
|
+
wait_time=5 # Time to wait if resources are overused
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
for file_path in file_paths:
|
|
297
|
+
# <Process each file>.
|
|
298
|
+
# Add the result to the input_list of the processor.
|
|
299
|
+
processor.input_list.append(file_path)
|
|
300
|
+
|
|
301
|
+
# Process the list of files at once.
|
|
302
|
+
processor.run_process()
|
|
303
|
+
# Shutdown the pool processes after processing.
|
|
304
|
+
processor.shutdown_pool()
|
|
305
|
+
|
|
306
|
+
3. Processing each file in the list separately, since we're using an unpacking function that
|
|
307
|
+
will create more files, but the context for this operation is different for extraction
|
|
308
|
+
of each main file inside the list:
|
|
309
|
+
|
|
310
|
+
# Initialize the processor once, before the loop, with empty input_list.
|
|
311
|
+
processor = MultiProcessor(
|
|
312
|
+
process_function=unpack_file,
|
|
313
|
+
input_list=[],
|
|
314
|
+
max_workers=4, # Number of parallel workers
|
|
315
|
+
cpu_percent_max=80, # Max CPU usage percentage
|
|
316
|
+
memory_percent_max=80, # Max memory usage percentage
|
|
317
|
+
wait_time=5 # Time to wait if resources are overused
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
for file_path in file_paths:
|
|
321
|
+
# <Process each file>.
|
|
322
|
+
# Add the result to the input_list of the processor.
|
|
323
|
+
processor.input_list.append(file_path)
|
|
324
|
+
# Process the added file path separately.
|
|
325
|
+
processor.run_process()
|
|
326
|
+
|
|
327
|
+
# Shutdown the pool processes after processing.
|
|
328
|
+
processor.shutdown_pool()
|
|
329
|
+
"""
|
|
330
|
+
|
|
331
|
+
self.process_function: Callable = process_function
|
|
332
|
+
self.input_list: list = input_list
|
|
333
|
+
self.cpu_percent_max: int = cpu_percent_max
|
|
334
|
+
self.memory_percent_max: int = memory_percent_max
|
|
335
|
+
self.wait_time: float = wait_time
|
|
336
|
+
self.system_monitor_manager_dict: multiprocessing.managers.DictProxy = system_monitor_manager_dict
|
|
337
|
+
|
|
338
|
+
if max_workers is None:
|
|
339
|
+
max_workers = os.cpu_count()
|
|
340
|
+
self.max_workers: int = max_workers
|
|
341
|
+
|
|
342
|
+
# Create the executor once and reuse it.
|
|
343
|
+
# noinspection PyTypeChecker
|
|
344
|
+
self.executor: ProcessPoolExecutor = None
|
|
345
|
+
|
|
346
|
+
def _ensure_executor(self):
|
|
347
|
+
"""Create a new pool if we do not have one or if the old one was shut."""
|
|
348
|
+
if self.executor is None or getattr(self.executor, '_shutdown', False):
|
|
349
|
+
self.executor = ProcessPoolExecutor(max_workers=self.max_workers)
|
|
350
|
+
|
|
351
|
+
def run_process(self):
|
|
352
|
+
# Make sure we have a live executor
|
|
353
|
+
self._ensure_executor()
|
|
354
|
+
|
|
355
|
+
work_q = deque(self.input_list) # breadth‑first queue
|
|
356
|
+
self.input_list.clear()
|
|
357
|
+
futures = set()
|
|
358
|
+
|
|
359
|
+
# helper to submit jobs up to the concurrency limit
|
|
360
|
+
def _fill():
|
|
361
|
+
while work_q and len(futures) < self.max_workers:
|
|
362
|
+
item = work_q.popleft()
|
|
363
|
+
system_resources.wait_for_resource_availability(
|
|
364
|
+
cpu_percent_max=self.cpu_percent_max,
|
|
365
|
+
memory_percent_max=self.memory_percent_max,
|
|
366
|
+
wait_time=self.wait_time,
|
|
367
|
+
system_monitor_manager_dict=self.system_monitor_manager_dict
|
|
368
|
+
)
|
|
369
|
+
futures.add(self.executor.submit(self.process_function, item))
|
|
370
|
+
|
|
371
|
+
_fill() # start the first wave
|
|
372
|
+
|
|
373
|
+
while futures:
|
|
374
|
+
for fut in as_completed(futures):
|
|
375
|
+
futures.remove(fut) # a slot just freed up
|
|
376
|
+
|
|
377
|
+
# propagate worker exceptions immediately
|
|
378
|
+
children = fut.result()
|
|
379
|
+
|
|
380
|
+
# schedule the newly discovered items
|
|
381
|
+
if children:
|
|
382
|
+
work_q.extend(children)
|
|
383
|
+
|
|
384
|
+
_fill() # keep the pool saturated
|
|
385
|
+
break # leave the for‑loop so as_completed resets
|
|
386
|
+
|
|
387
|
+
def shutdown(self):
|
|
388
|
+
"""Shuts down the executor gracefully."""
|
|
389
|
+
if self.executor:
|
|
390
|
+
self.executor.shutdown(wait=True) # blocks until all tasks complete
|
|
391
|
+
self.executor = None
|
|
392
|
+
|
|
393
|
+
|
|
196
394
|
class ConcurrentProcessorRecursive:
|
|
197
395
|
def __init__(
|
|
198
396
|
self,
|
atomicshop/dns.py
CHANGED
atomicshop/mitm/config_static.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from dataclasses import dataclass
|
|
3
|
+
from typing import Literal
|
|
3
4
|
|
|
4
5
|
from . import import_config
|
|
5
6
|
|
|
@@ -157,7 +158,7 @@ class ProcessName:
|
|
|
157
158
|
ssh_user: str
|
|
158
159
|
ssh_pass: str
|
|
159
160
|
|
|
160
|
-
ssh_script_to_execute = 'process_from_port'
|
|
161
|
+
ssh_script_to_execute: Literal['process_from_port', 'process_from_ipv4'] = 'process_from_port'
|
|
161
162
|
|
|
162
163
|
|
|
163
164
|
def load_config(config_toml_file_path: str):
|