forked from Tasssadar/Team-Win-Recovery-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiromedify.h
124 lines (100 loc) · 2.64 KB
/
multiromedify.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
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
#ifndef MULTIROM_EDIFY_H
#define MULTIROM_EDIFY_H
#include <stdio.h>
#include <string>
#include <list>
#include <stack>
#include <vector>
enum EdifyElementType {
EDF_VALUE,
EDF_FUNC,
EDF_NEWLINE,
};
enum
{
// Internal flags
OFF_FORMAT_SYSTEM = 0x01,
OFF_BLOCK_UPDATES = 0x02,
OFF_CHANGED = 0x04,
// returned by EdifyHacker::getProcessFlags()
EDIFY_CHANGED = 0x01,
EDIFY_BLOCK_UPDATES = 0x02,
};
class EdifyElement
{
public:
EdifyElement(EdifyElementType type);
virtual ~EdifyElement();
EdifyElementType getType() const { return m_type; }
virtual void write(FILE *f) = 0;
protected:
EdifyElementType m_type;
};
class EdifyValue : public EdifyElement
{
public:
EdifyValue(const std::string& text);
const std::string& getText() const { return m_text; }
void write(FILE *f);
private:
std::string m_text;
};
class EdifyFunc : public EdifyElement
{
public:
EdifyFunc(const std::string& name);
virtual ~EdifyFunc();
void addArg(EdifyElement *arg);
void write(FILE *f);
const std::string& getName() const { return m_name; }
std::list<EdifyElement*> *getArgs() { return &m_args; }
const std::list<EdifyElement*> *getArgs() const { return &m_args; }
int replaceOffendings(std::list<EdifyElement*> **parentList, std::list<EdifyElement*>::iterator& lastNewlineRef);
std::string getArgsStr() const;
private:
void clearArgs();
std::string m_name;
std::list<EdifyElement*> m_args;
};
class EdifyNewline : public EdifyElement
{
public:
EdifyNewline();
void write(FILE *f);
};
class EdifyHacker
{
public:
EdifyHacker();
~EdifyHacker();
bool loadFile(const std::string& path);
bool loadBuffer(const char *buf, size_t len);
void replaceOffendings();
bool writeToFile(const std::string& path);
void clear();
void saveState();
bool restoreState();
int getProcessFlags() const { return m_processFlags; }
private:
enum ParserState {
ST_INIT,
ST_COMMENT,
ST_FUNCARGS,
ST_STRING,
};
bool add(char c);
void addElement(EdifyElement *el);
void addBufAsValue();
void applyOffendingMask(std::list<EdifyElement*>::iterator& itr, int mask);
void copyElements(std::list<EdifyElement*> *src, std::list<EdifyElement*> *dst);
void printStatsForState(const std::list<EdifyElement*>& state);
std::string m_buf;
std::stack<ParserState> m_state;
std::stack<EdifyFunc*> m_openFuncs;
bool m_strEscaped;
bool m_whitespace;
int m_processFlags;
std::list<EdifyElement*> m_elements;
std::vector<std::list<EdifyElement*> > m_savedStates;
};
#endif