Read process memory.
35{
36 PEPROCESS SourceProcess;
37 MM_COPY_ADDRESS CopyAddress = {0};
38 KAPC_STATE State = {0};
39 PHYSICAL_ADDRESS TempPhysicalAddress = {0};
40
41
42
43
44
45
46
47
48
49
51 {
52
53
54
55
56 if (PsLookupProcessByProcessId(PID, &SourceProcess) != STATUS_SUCCESS)
57 {
58
59
60
62 }
63 __try
64 {
65 KeStackAttachProcess(SourceProcess, &State);
66
67
68
69
70 TempPhysicalAddress = MmGetPhysicalAddress(
Address);
71
72 KeUnstackDetachProcess(&State);
73
74
75
76
77 CopyAddress.PhysicalAddress.QuadPart = TempPhysicalAddress.QuadPart;
78 MmCopyMemory(UserBuffer, CopyAddress, Size, MM_COPY_MEMORY_PHYSICAL, ReturnSize);
79
80 ObDereferenceObject(SourceProcess);
81
83 }
84 __except (EXCEPTION_EXECUTE_HANDLER)
85 {
86 KeUnstackDetachProcess(&State);
87
88 ObDereferenceObject(SourceProcess);
89
91 }
92 }
93 else
94 {
95
96
97
98 __try
99 {
101 {
102 CopyAddress.VirtualAddress =
Address;
103 MmCopyMemory(UserBuffer, CopyAddress, Size, MM_COPY_MEMORY_VIRTUAL, ReturnSize);
104 }
106 {
107
108
109
111 {
113 }
114
115 CopyAddress.PhysicalAddress.QuadPart = (LONGLONG)
Address;
116 MmCopyMemory(UserBuffer, CopyAddress, Size, MM_COPY_MEMORY_PHYSICAL, ReturnSize);
117 }
118 else
119 {
120
121
122
124 }
125
126
127
128
129
130
132 }
133 __except (EXCEPTION_EXECUTE_HANDLER)
134 {
136 }
137 }
138}
BOOLEAN CheckAddressPhysical(UINT64 PAddr)
Checks if the physical address is correct or not based on physical address width.
Definition AddressCheck.c:120
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
UINT64 Address
Definition HyperDbgScriptImports.h:67
@ DEBUGGER_READ_PHYSICAL_ADDRESS
Definition RequestStructures.h:229
@ DEBUGGER_READ_VIRTUAL_ADDRESS
Definition RequestStructures.h:230