-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhys32.cpp
More file actions
118 lines (88 loc) · 2.35 KB
/
Phys32.cpp
File metadata and controls
118 lines (88 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// ---------------------------------------------------- //
// WinIo v3.0 //
// Direct Hardware Access Under Windows //
// Copyright 1998-2010 Yariv Kaplan //
// http://www.internals.com
// 对物理内存访问的相关函数 //
// ---------------------------------------------------- //
#include <windows.h>
#include <winioctl.h>
#include "phys32.h"
#include "./WinIoNoteSys/OpenLibSys.h"
#include "winio.h"
PBYTE _stdcall MapPhysToLin(tagPhysStruct &PhysStruct)
{
PBYTE pbLinAddr = NULL;
DWORD dwBytesReturned;
if (!IsWinIoInitialized)
return false;
// 通Port32处的调用驱动的,使用IOCTL_WINIO_MAPPHYSTOLIN 控制代码 传入传出参数
if (!DeviceIoControl(hDriver, IOCTL_WINIO_MAPPHYSTOLIN, &PhysStruct,
sizeof(tagPhysStruct), &PhysStruct, sizeof(tagPhysStruct),
&dwBytesReturned, NULL))
{
return NULL;
}
return (PBYTE)PhysStruct.pvPhysMemLin;
}
bool _stdcall UnmapPhysicalMemory(tagPhysStruct &PhysStruct)
{
DWORD dwBytesReturned;
if (!IsWinIoInitialized)
{
return false;
}
if (!DeviceIoControl(hDriver, IOCTL_WINIO_UNMAPPHYSADDR, &PhysStruct,
sizeof(tagPhysStruct), NULL, 0, &dwBytesReturned, NULL))
{
return false;
}
return true;
}
// Support functions 通过调用 MapPhysToLin方法 来进行实现
bool _stdcall GetPhysLong(PBYTE pbPhysAddr, PDWORD pdwPhysVal)
{
PDWORD pdwLinAddr;
tagPhysStruct PhysStruct;
if (!IsWinIoInitialized)
return false;
if (g_Is64BitOS)
{
PhysStruct.pvPhysAddress = (DWORD64)pbPhysAddr;
}
else
{
// Avoid sign extension issues
PhysStruct.pvPhysAddress = (DWORD64)(DWORD32)pbPhysAddr;
}
PhysStruct.dwPhysMemSizeInBytes = 4;
pdwLinAddr = (PDWORD)MapPhysToLin(PhysStruct);
if (pdwLinAddr == NULL)
return false;
*pdwPhysVal = *pdwLinAddr;
UnmapPhysicalMemory(PhysStruct);
return true;
}
bool _stdcall SetPhysLong(PBYTE pbPhysAddr, DWORD dwPhysVal)
{
PDWORD pdwLinAddr;
tagPhysStruct PhysStruct;
if (!IsWinIoInitialized)
return false;
if (g_Is64BitOS)
{
PhysStruct.pvPhysAddress = (DWORD64)pbPhysAddr;
}
else
{
// Avoid sign extension issues
PhysStruct.pvPhysAddress = (DWORD64)(DWORD32)pbPhysAddr;
}
PhysStruct.dwPhysMemSizeInBytes = 4;
pdwLinAddr = (PDWORD)MapPhysToLin(PhysStruct);
if (pdwLinAddr == NULL)
return false;
*pdwLinAddr = dwPhysVal;
UnmapPhysicalMemory(PhysStruct);
return true;
}