-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathsearch.h
80 lines (61 loc) · 2.23 KB
/
search.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
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
#pragma once
#include "memory.h"
#include "utils.h"
#include <vector>
namespace Retro {
struct Variable;
struct SearchResult {
size_t address;
uint64_t mult;
uint64_t div;
int64_t bias;
bool operator<(const SearchResult&) const;
bool operator==(const SearchResult&) const;
bool operator!=(const SearchResult&) const;
};
struct TypedSearchResult : public SearchResult {
TypedSearchResult(SearchResult&&, DataType&& type);
TypedSearchResult(const SearchResult&, const DataType& type);
TypedSearchResult(const TypedSearchResult&) = default;
DataType type;
bool operator==(const TypedSearchResult&) const;
operator Variable() const;
};
class Search {
public:
Search();
Search(const std::vector<DataType>& types);
void search(const AddressSpace& mem, int64_t value);
void delta(const AddressSpace& mem, const AddressSpace& oldMem, Operation op, int64_t reference);
std::vector<SearchResult> results() const;
const std::vector<TypedSearchResult>& typedResults() const;
std::vector<DataType> validTypes() const;
void stuff(const std::vector<TypedSearchResult>&);
void remove(const std::vector<TypedSearchResult>&);
size_t numResults() const;
bool hasUniqueResult() const;
TypedSearchResult uniqueResult() const;
Search& operator=(const Search&);
private:
std::vector<SearchResult> makeResults(std::vector<size_t> addrs, uint64_t mult = 1, uint64_t div = 1, int64_t bias = 0);
std::vector<size_t> searchValue(const AddressSpace& mem, int64_t value);
std::vector<size_t> searchByte(const AddressSpace& mem, uint8_t value, const std::vector<size_t> addresses = {}, ssize_t offset = 0);
std::vector<size_t> overlap(const std::vector<size_t> start, std::vector<size_t> end, size_t width);
void reduceOnTypes(const AddressSpace& mem, const std::vector<SearchResult>&, int64_t value);
void intersectCurrent(std::vector<TypedSearchResult>&&);
void differenceCurrent(const std::vector<TypedSearchResult>&);
std::vector<TypedSearchResult> m_current;
std::vector<DataType> m_types;
bool m_hasStarted = false;
};
}
namespace std {
template<>
struct hash<Retro::SearchResult> {
size_t operator()(const Retro::SearchResult&) const;
};
template<>
struct hash<Retro::TypedSearchResult> {
size_t operator()(const Retro::TypedSearchResult&) const;
};
}