forked from rafzi/hacklib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPatternScanner.h
54 lines (41 loc) · 1.91 KB
/
PatternScanner.h
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
//https://github.com/rafzi/hacklib
#ifndef HACKLIB_PATTERNSCANNER_H
#define HACKLIB_PATTERNSCANNER_H
#include "Memory.h"
#include "ExeFile.h"
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <cstdint>
namespace hl {
class PatternScanner
{
public:
PatternScanner();
// Searches for referenced strings in code of the module.
std::vector<uintptr_t> find(const std::vector<std::string>& strings, const std::string& moduleName = "");
uintptr_t findString(const std::string& str, const std::string& moduleName = "");
std::map<std::string, uintptr_t> findMap(const std::vector<std::string>& strings, const std::string& moduleName = "");
private:
std::unordered_map<std::string, hl::ModuleHandle> moduleMap;
std::unordered_map<std::string, std::unique_ptr<hl::ExeFile>> exeFileMap;
std::unordered_map<std::string, bool> verifyRelocsMap;
std::vector<hl::MemoryRegion> memoryMap;
};
// Finds a binary pattern with mask in executable sections of a module.
// The mask is a string containing 'x' to match and '?' to ignore.
// If moduleName is nullptr the module of the main module is searched.
uintptr_t FindPatternMask(const char *byteMask, const char *checkMask, const std::string& moduleName = "");
// Variant for arbitrary memory.
uintptr_t FindPatternMask(const char *byteMask, const char *checkMask, uintptr_t address, size_t len);
// More convenient and less error prone alternative.
// Example: "12 45 ?? 89 ?? ?? ?? cd ef"
uintptr_t FindPattern(const std::string& pattern, const std::string& moduleName = "");
uintptr_t FindPattern(const std::string& pattern, uintptr_t address, size_t len);
// Helper to follow relative addresses in instructions.
// Instruction is assumed to end after the relative address. for example jmp, call
uintptr_t FollowRelativeAddress(uintptr_t adr);
const std::vector<hl::MemoryRegion>& GetCodeRegions(const std::string& moduleName = "");
}
#endif