This repository was archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAnalysisInfo.h
More file actions
146 lines (115 loc) · 3.5 KB
/
AnalysisInfo.h
File metadata and controls
146 lines (115 loc) · 3.5 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Copyright (c) 2022 Jon Palmisciano. All rights reserved.
*
* Use of this source code is governed by the BSD 3-Clause license; the full
* terms of the license can be found in the LICENSE.txt file.
*/
#pragma once
#include "../Vendor/ModernJSON/JSON.hpp"
namespace ObjectiveNinja {
/**
* A description of a CFString instance.
*/
struct CFStringInfo {
uint64_t address {};
uint64_t dataAddress {};
size_t size {};
};
/**
* A description of a selector reference.
*/
struct SelectorRefInfo {
uint64_t address {};
std::string name {};
uint64_t rawSelector {};
uint64_t nameAddress {};
};
using SharedSelectorRefInfo = std::shared_ptr<SelectorRefInfo>;
/**
* A description of an Objective-C method.
*/
struct MethodInfo {
uint64_t address {};
std::string selector;
std::string type;
uint64_t nameAddress {};
uint64_t typeAddress {};
uint64_t implAddress {};
/**
* Get the selector as a series of tokens, split at ':' characters.
*/
std::vector<std::string> selectorTokens() const;
/**
* Get the method's type as series of C-style tokens.
*/
std::vector<std::string> decodedTypeTokens() const;
};
/**
* A description of an Objective-C method list.
*/
struct MethodListInfo {
uint64_t address {};
uint32_t flags {};
std::vector<MethodInfo> methods {};
/**
* Tells whether the method list uses relative offsets or not.
*/
bool hasRelativeOffsets() const;
/**
* Tells whether the method list uses direct selectors or not.
*/
bool hasDirectSelectors() const;
};
/**
* A description of an Objective-C class.
*/
struct ClassInfo {
uint64_t address {};
std::string name {};
MethodListInfo methodList {};
uint64_t listPointer {};
uint64_t dataAddress {};
uint64_t nameAddress {};
uint64_t methodListAddress {};
};
/**
* A description of an Objective-C category.
*/
struct CategoryInfo {
uint64_t address {};
std::string name {};
MethodListInfo instanceMethods {};
MethodListInfo classMethods {};
uint64_t listPointer {};
uint64_t nameAddress {};
uint64_t instanceMethodListAddress {};
uint64_t classMethodListAddress {};
};
/**
* Analysis info storage.
*
* AnalysisInfo is intended to be a common structure for persisting information
* during and after analysis. All significant info obtained or produced through
* analysis should be stored here, ideally in the form of other *Info structs.
*/
struct AnalysisInfo {
std::vector<CFStringInfo> cfStrings {};
std::vector<SharedSelectorRefInfo> selectorRefs {};
std::unordered_map<uint64_t, SharedSelectorRefInfo> selectorRefsByKey {};
std::vector<ClassInfo> classes {};
std::vector<CategoryInfo> categories {};
std::unordered_map<uint64_t, uint64_t> methodImpls;
std::string dump() const;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CFStringInfo, address, dataAddress, size)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SelectorRefInfo, address, name, rawSelector,
nameAddress)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MethodInfo, address, selector, type,
nameAddress, typeAddress, implAddress)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MethodListInfo, address, flags, methods)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ClassInfo, listPointer, address, dataAddress,
nameAddress, name, methodListAddress, methodList)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CategoryInfo, listPointer, address, nameAddress,
name, instanceMethodListAddress, instanceMethods, classMethodListAddress,
classMethods)
}