ntmemoryapi 1.7.2__tar.gz → 2.0__tar.gz
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.
- {ntmemoryapi-1.7.2 → ntmemoryapi-2.0}/PKG-INFO +1 -1
- {ntmemoryapi-1.7.2 → ntmemoryapi-2.0}/pyproject.toml +1 -1
- {ntmemoryapi-1.7.2 → ntmemoryapi-2.0}/src/ntmemoryapi/__init__.py +57 -45
- {ntmemoryapi-1.7.2 → ntmemoryapi-2.0}/README.md +0 -0
- {ntmemoryapi-1.7.2 → ntmemoryapi-2.0}/src/ntmemoryapi/embed.py +0 -0
- {ntmemoryapi-1.7.2 → ntmemoryapi-2.0}/src/ntmemoryapi/misc.py +0 -0
|
@@ -267,6 +267,20 @@ def list_processes(include_process_information: int = PROCESS_ID | PROCESS_NAME)
|
|
|
267
267
|
return processes
|
|
268
268
|
|
|
269
269
|
|
|
270
|
+
def __get_be_buffer(soure_c_type: typing.Any) -> ctypes.BigEndianStructure:
|
|
271
|
+
"""Create buffer to hold data in big-endian format."""
|
|
272
|
+
|
|
273
|
+
class BigEndianValue(ctypes.BigEndianStructure):
|
|
274
|
+
"""Big-endian value structure."""
|
|
275
|
+
|
|
276
|
+
_pack_ = 1
|
|
277
|
+
_fields_ = [
|
|
278
|
+
("value", soure_c_type)
|
|
279
|
+
]
|
|
280
|
+
|
|
281
|
+
return BigEndianValue
|
|
282
|
+
|
|
283
|
+
|
|
270
284
|
# ==-------------------------------------------------------------------== #
|
|
271
285
|
# Classes #
|
|
272
286
|
# ==-------------------------------------------------------------------== #
|
|
@@ -277,18 +291,18 @@ class Process:
|
|
|
277
291
|
# Methods #
|
|
278
292
|
# ==-------------------------------------------------------------------== #
|
|
279
293
|
|
|
280
|
-
def __init__(self, name_or_pid:
|
|
294
|
+
def __init__(self, name_or_pid: str | int, access: int = PROCESS_ALL_ACCESS) -> None:
|
|
281
295
|
"""Initialize instance to manipulate process."""
|
|
282
296
|
|
|
283
297
|
# Open process by it's ID or it's name
|
|
284
298
|
match name_or_pid:
|
|
285
299
|
|
|
286
|
-
case int():
|
|
287
|
-
self.handle, self.pid, self.name = self.__init_with_pid(name_or_pid, access)
|
|
288
|
-
|
|
289
300
|
case str():
|
|
290
301
|
self.handle, self.pid, self.name = self.__init_with_name(name_or_pid, access)
|
|
291
302
|
|
|
303
|
+
case int():
|
|
304
|
+
self.handle, self.pid, self.name = self.__init_with_pid(name_or_pid, access)
|
|
305
|
+
|
|
292
306
|
case _:
|
|
293
307
|
raise Exception("Invalid `name_or_pid` argument value, have to be `int` or `str` type")
|
|
294
308
|
|
|
@@ -481,7 +495,7 @@ class Process:
|
|
|
481
495
|
# Validate given pattern
|
|
482
496
|
for byte in pattern.strip().split():
|
|
483
497
|
|
|
484
|
-
# If pattern byte is
|
|
498
|
+
# If pattern byte is not wildcard and valid
|
|
485
499
|
if len(byte) == 2 and [item in "0123456789ABCDEFabcdef" for item in byte].count(True) == 2:
|
|
486
500
|
continue
|
|
487
501
|
|
|
@@ -552,29 +566,29 @@ class Process:
|
|
|
552
566
|
|
|
553
567
|
return buffer.value
|
|
554
568
|
|
|
555
|
-
def read_int16(self, address: int) -> int:
|
|
569
|
+
def read_int16(self, address: int, big_endian: bool = False) -> int:
|
|
556
570
|
"""Read 2 byte signed integer value located at given address."""
|
|
557
571
|
|
|
558
572
|
# If result failed
|
|
559
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_int16()), ctypes.sizeof(buffer), None)):
|
|
573
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_int16)() if big_endian else ctypes.c_int16()), ctypes.sizeof(buffer), None)):
|
|
560
574
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
561
575
|
|
|
562
576
|
return buffer.value
|
|
563
577
|
|
|
564
|
-
def read_int32(self, address: int) -> int:
|
|
578
|
+
def read_int32(self, address: int, big_endian: bool = False) -> int:
|
|
565
579
|
"""Read 4 byte signed integer value located at given address."""
|
|
566
580
|
|
|
567
581
|
# If result failed
|
|
568
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_int32()), ctypes.sizeof(buffer), None)):
|
|
582
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_int32)() if big_endian else ctypes.c_int32()), ctypes.sizeof(buffer), None)):
|
|
569
583
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
570
584
|
|
|
571
585
|
return buffer.value
|
|
572
586
|
|
|
573
|
-
def read_int64(self, address: int) -> int:
|
|
587
|
+
def read_int64(self, address: int, big_endian: bool = False) -> int:
|
|
574
588
|
"""Read 8 byte signed integer value located at given address."""
|
|
575
589
|
|
|
576
590
|
# If result failed
|
|
577
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_int64()), ctypes.sizeof(buffer), None)):
|
|
591
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_int64)() if big_endian else ctypes.c_int64()), ctypes.sizeof(buffer), None)):
|
|
578
592
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
579
593
|
|
|
580
594
|
return buffer.value
|
|
@@ -588,56 +602,56 @@ class Process:
|
|
|
588
602
|
|
|
589
603
|
return buffer.value
|
|
590
604
|
|
|
591
|
-
def read_uint16(self, address: int) -> int:
|
|
605
|
+
def read_uint16(self, address: int, big_endian: bool = False) -> int:
|
|
592
606
|
"""Read 2 byte unsigned integer value located at given address."""
|
|
593
607
|
|
|
594
608
|
# If result failed
|
|
595
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_uint16()), ctypes.sizeof(buffer), None)):
|
|
609
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_uint16)() if big_endian else ctypes.c_uint16()), ctypes.sizeof(buffer), None)):
|
|
596
610
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
597
611
|
|
|
598
612
|
return buffer.value
|
|
599
613
|
|
|
600
|
-
def read_uint32(self, address: int) -> int:
|
|
614
|
+
def read_uint32(self, address: int, big_endian: bool = False) -> int:
|
|
601
615
|
"""Read 4 byte unsigned integer value located at given address."""
|
|
602
616
|
|
|
603
617
|
# If result failed
|
|
604
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_uint32()), ctypes.sizeof(buffer), None)):
|
|
618
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_uint32)() if big_endian else ctypes.c_uint32()), ctypes.sizeof(buffer), None)):
|
|
605
619
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
606
620
|
|
|
607
621
|
return buffer.value
|
|
608
622
|
|
|
609
|
-
def read_uint64(self, address: int) -> int:
|
|
623
|
+
def read_uint64(self, address: int, big_endian: bool = False) -> int:
|
|
610
624
|
"""Read 8 byte unsigned integer value located at given address."""
|
|
611
625
|
|
|
612
626
|
# If result failed
|
|
613
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_uint64()), ctypes.sizeof(buffer), None)):
|
|
627
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_uint64)() if big_endian else ctypes.c_uint64()), ctypes.sizeof(buffer), None)):
|
|
614
628
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
615
629
|
|
|
616
630
|
return buffer.value
|
|
617
631
|
|
|
618
|
-
def read_float32(self, address: int) -> float:
|
|
632
|
+
def read_float32(self, address: int, big_endian: bool = False) -> float:
|
|
619
633
|
"""Read 4 byte floating-point digit value located at given address."""
|
|
620
634
|
|
|
621
635
|
# If result failed
|
|
622
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_float()), ctypes.sizeof(buffer), None)):
|
|
636
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_float)() if big_endian else ctypes.c_float()), ctypes.sizeof(buffer), None)):
|
|
623
637
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
624
638
|
|
|
625
639
|
return buffer.value
|
|
626
640
|
|
|
627
|
-
def read_float64(self, address: int) -> float:
|
|
641
|
+
def read_float64(self, address: int, big_endian: bool = False) -> float:
|
|
628
642
|
"""Read 8 byte floating-point digit value located at given address."""
|
|
629
643
|
|
|
630
644
|
# If result failed
|
|
631
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_double()), ctypes.sizeof(buffer), None)):
|
|
645
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_double)() if big_endian else ctypes.c_double()), ctypes.sizeof(buffer), None)):
|
|
632
646
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
633
647
|
|
|
634
648
|
return buffer.value
|
|
635
649
|
|
|
636
|
-
def read_bytes(self, address: int, size: int) -> bytes:
|
|
650
|
+
def read_bytes(self, address: int, size: int, big_endian: bool = False) -> bytes:
|
|
637
651
|
"""Read bytes array of variadic size located at given address."""
|
|
638
652
|
|
|
639
653
|
# If result failed
|
|
640
|
-
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := (ctypes.c_int8 * size)()), ctypes.sizeof(buffer), None)):
|
|
654
|
+
if (result := _nt_read_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_int8 * size)() if big_endian else (ctypes.c_int8 * size)()), ctypes.sizeof(buffer), None)):
|
|
641
655
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
642
656
|
|
|
643
657
|
return bytes(buffer)
|
|
@@ -658,28 +672,26 @@ class Process:
|
|
|
658
672
|
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_int8(value)), ctypes.sizeof(buffer), None)):
|
|
659
673
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
660
674
|
|
|
661
|
-
def write_int16(self, address: int, value: int) -> None:
|
|
675
|
+
def write_int16(self, address: int, value: int, big_endian: bool = False) -> None:
|
|
662
676
|
"""Write 2 byte signed integer value at given address."""
|
|
663
677
|
|
|
664
678
|
# If result failed
|
|
665
|
-
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_int16(value)), ctypes.sizeof(buffer), None)):
|
|
679
|
+
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_int16(value)) if big_endian else ctypes.c_int16(value)), ctypes.sizeof(buffer), None)):
|
|
666
680
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
667
681
|
|
|
668
|
-
def write_int32(self, address: int, value: int) -> None:
|
|
682
|
+
def write_int32(self, address: int, value: int, big_endian: bool = False) -> None:
|
|
669
683
|
"""Write 4 byte signed integer value at given address."""
|
|
670
684
|
|
|
671
685
|
# If result failed
|
|
672
|
-
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_int32(value)), ctypes.sizeof(buffer), None)):
|
|
686
|
+
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_int32(value)) if big_endian else ctypes.c_int32(value)), ctypes.sizeof(buffer), None)):
|
|
673
687
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
674
688
|
|
|
675
|
-
def write_int64(self, address: int, value: int) -> None:
|
|
689
|
+
def write_int64(self, address: int, value: int, big_endian: bool = False) -> None:
|
|
676
690
|
"""Write 8 byte signed integer value at given address."""
|
|
677
691
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_int64(value)), ctypes.sizeof(buffer), None)):
|
|
682
|
-
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
692
|
+
# If result failed
|
|
693
|
+
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_int64(value)) if big_endian else ctypes.c_int64(value)), ctypes.sizeof(buffer), None)):
|
|
694
|
+
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
683
695
|
|
|
684
696
|
def write_uint8(self, address: int, value: int) -> None:
|
|
685
697
|
"""Write 1 byte unsigned integer value at given address."""
|
|
@@ -688,46 +700,46 @@ class Process:
|
|
|
688
700
|
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_uint8(value)), ctypes.sizeof(buffer), None)):
|
|
689
701
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
690
702
|
|
|
691
|
-
def write_uint16(self, address: int, value: int) -> None:
|
|
703
|
+
def write_uint16(self, address: int, value: int, big_endian: bool = False) -> None:
|
|
692
704
|
"""Write 2 byte unsigned integer value at given address."""
|
|
693
705
|
|
|
694
706
|
# If result failed
|
|
695
|
-
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_uint16(value)), ctypes.sizeof(buffer), None)):
|
|
707
|
+
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_uint16(value)) if big_endian else ctypes.c_uint16(value)), ctypes.sizeof(buffer), None)):
|
|
696
708
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
697
709
|
|
|
698
|
-
def write_uint32(self, address: int, value: int) -> None:
|
|
710
|
+
def write_uint32(self, address: int, value: int, big_endian: bool = False) -> None:
|
|
699
711
|
"""Write 4 byte unsigned integer value at given address."""
|
|
700
712
|
|
|
701
713
|
# If result failed
|
|
702
|
-
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_uint32(value)), ctypes.sizeof(buffer), None)):
|
|
714
|
+
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_uint32(value)) if big_endian else ctypes.c_uint32(value)), ctypes.sizeof(buffer), None)):
|
|
703
715
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
704
716
|
|
|
705
|
-
def write_uint64(self, address: int, value: int) -> None:
|
|
717
|
+
def write_uint64(self, address: int, value: int, big_endian: bool = False) -> None:
|
|
706
718
|
"""Write 8 byte unsigned integer value at given address."""
|
|
707
719
|
|
|
708
720
|
# If result failed
|
|
709
|
-
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_uint64(value)), ctypes.sizeof(buffer), None)):
|
|
721
|
+
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_uint64(value)) if big_endian else ctypes.c_uint64(value)), ctypes.sizeof(buffer), None)):
|
|
710
722
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
711
723
|
|
|
712
|
-
def write_float32(self, address: int, value: float | int) -> float:
|
|
724
|
+
def write_float32(self, address: int, value: float | int, big_endian: bool = False) -> float:
|
|
713
725
|
"""Write 4 byte floating-point digit value at given address."""
|
|
714
726
|
|
|
715
727
|
# If result failed
|
|
716
|
-
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_float(value)), ctypes.sizeof(buffer), None)):
|
|
728
|
+
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_float(value)) if big_endian else ctypes.c_float(value)), ctypes.sizeof(buffer), None)):
|
|
717
729
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
718
730
|
|
|
719
|
-
def write_float64(self, address: int, value: float | int) -> float:
|
|
731
|
+
def write_float64(self, address: int, value: float | int, big_endian: bool = False) -> float:
|
|
720
732
|
"""Write 8 byte floating-point digit value at given address."""
|
|
721
733
|
|
|
722
734
|
# If result failed
|
|
723
|
-
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := ctypes.c_double(value)), ctypes.sizeof(buffer), None)):
|
|
735
|
+
if (result := _nt_write_virtual_memory(self.handle, address, ctypes.byref(buffer := __get_be_buffer(ctypes.c_double(value)) if big_endian else ctypes.c_double(value)), ctypes.sizeof(buffer), None)):
|
|
724
736
|
raise Exception("NtWriteVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
725
737
|
|
|
726
|
-
def write_bytes(self, address: int, value: bytes) -> None:
|
|
738
|
+
def write_bytes(self, address: int, value: bytes, big_endian: bool = False) -> None:
|
|
727
739
|
"""Write bytes array of variadic size at given address."""
|
|
728
740
|
|
|
729
741
|
# If result failed
|
|
730
|
-
if (result := _nt_write_virtual_memory(self.handle, address, value, len(value), None)):
|
|
742
|
+
if (result := _nt_write_virtual_memory(self.handle, address, value[::-1] if big_endian else value, len(value), None)):
|
|
731
743
|
raise Exception("NtReadVirtualMemory failed with status: 0x%s" % hex(result)[2:].upper())
|
|
732
744
|
|
|
733
745
|
def write_buffer(self, address: int, buffer: typing.Any) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|