forked from bloomberg/pystack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpytypes.h
More file actions
183 lines (150 loc) Β· 3.94 KB
/
pytypes.h
File metadata and controls
183 lines (150 loc) Β· 3.94 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma once
#include <memory>
#include <string>
#include <variant>
#include <vector>
#include "mem.h"
#include "process.h"
#include "structure.h"
namespace pystack {
std::string
addrToString(const std::shared_ptr<const AbstractProcessManager>& manager, remote_addr_t addr);
class TupleObject
{
public:
// Constructors
TupleObject(const std::shared_ptr<const AbstractProcessManager>& manager, remote_addr_t addr);
// Getters
const std::vector<remote_addr_t>& Items() const;
// Methods
std::string toString(ssize_t max_size) const;
private:
// Data members
std::vector<remote_addr_t> d_items{};
std::shared_ptr<const AbstractProcessManager> d_manager{nullptr};
};
class ListObject
{
public:
// Constructors
ListObject(const std::shared_ptr<const AbstractProcessManager>& manager, remote_addr_t addr);
// Getters
const std::vector<remote_addr_t>& Items() const;
// Methods
std::string toString(ssize_t max_size) const;
private:
// Data members
std::vector<remote_addr_t> d_items{};
std::shared_ptr<const AbstractProcessManager> d_manager{nullptr};
};
class DictObject
{
public:
// Constructors
DictObject(std::shared_ptr<const AbstractProcessManager> manager, remote_addr_t addr);
// Methods
std::string toString(ssize_t max_size) const;
// Getters
bool Invalid() const;
const std::vector<remote_addr_t>& Keys() const;
const std::vector<remote_addr_t>& Values() const;
private:
// Data members
bool d_invalid{false};
std::shared_ptr<const AbstractProcessManager> d_manager{nullptr};
std::vector<remote_addr_t> d_keys{};
std::vector<remote_addr_t> d_values{};
// Methods
void loadFromPython2(remote_addr_t addr);
void loadFromPython3(remote_addr_t addr);
};
class LongObject
{
public:
// Constructors
LongObject(
const std::shared_ptr<const AbstractProcessManager>& manager,
remote_addr_t addr,
bool is_bool = false);
// Methods
std::string toString(ssize_t max_size) const;
private:
// Data members
long long d_value{0};
bool d_overflowed{false};
bool d_is_bool{false};
public:
long long int Value() const;
bool Overflowed() const;
};
class GenericObject
{
public:
GenericObject(remote_addr_t addr, std::string classname);
// Methods
std::string toString(ssize_t max_size) const;
private:
remote_addr_t d_addr;
std::string d_classname;
};
class NoneObject
{
public:
explicit NoneObject(remote_addr_t addr);
// Methods
std::string toString(ssize_t max_size) const;
};
class Object
{
public:
// Alias
using PythonObject = std::variant<
std::string,
bool,
long,
double,
TupleObject,
ListObject,
DictObject,
LongObject,
NoneObject,
GenericObject>;
// Enums
enum class ObjectType {
BYTES,
STRING,
NONE,
INT_BOOL,
LONG_BOOL,
INT,
LONG,
FLOAT,
TUPLE,
LIST,
DICT,
CODE,
OTHER
};
static constexpr int MAX_LOCAL_STR_SIZE = 80;
// Constructors
Object(const std::shared_ptr<const AbstractProcessManager>& manager, remote_addr_t addr);
// Methods
ObjectType objectType() const;
PythonObject toConcreteObject() const;
bool hasFlags(unsigned long flags) const;
std::string toString(ssize_t max_size = MAX_LOCAL_STR_SIZE) const;
remote_addr_t typeAddr() const;
private:
// Data members
remote_addr_t d_addr;
remote_addr_t d_type_addr;
std::string d_classname{};
unsigned long d_flags{};
std::shared_ptr<const AbstractProcessManager> d_manager{nullptr};
// Methods
bool toBool() const;
long toInteger() const;
double toFloat() const;
std::string guessClassName(Structure<py_type_v>& type) const;
};
} // namespace pystack