-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSafeRead.cpp
More file actions
36 lines (31 loc) · 827 Bytes
/
SafeRead.cpp
File metadata and controls
36 lines (31 loc) · 827 Bytes
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
#include "SafeRead.h"
#include "skse64/GameData.h"
#include "skse64/GameTypes.h"
namespace Lib {
UInt32 SafeRead32(UInt32 addr){
UInt32 oldProtect;
UInt32 returnValue;
try {
VirtualProtect((void *)addr, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
returnValue = *((UInt32 *)addr);
VirtualProtect((void *)addr, 4, oldProtect, &oldProtect);
}
catch (std::exception&){
_MESSAGE("SafeRead32 Exception: %d", (int)addr);
}
return returnValue;
}
char SafeRead8(UInt32 addr){
UInt32 oldProtect;
char returnValue;
try{
VirtualProtect((void *)addr, 1, PAGE_EXECUTE_READWRITE, &oldProtect);
returnValue = *((char *)addr);
VirtualProtect((void *)addr, 1, oldProtect, &oldProtect);
}
catch (std::exception&){
_MESSAGE("SafeRead8 Exception: %d", (int)addr);
}
return returnValue;
}
}