-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathmain.cpp
202 lines (163 loc) · 3.89 KB
/
main.cpp
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <wdm.h>
#include <ntstrsafe.h>
#include <luaplus.hpp>
#include <msgpack.hpp>
#include <EASTL/sort.h>
#include <EASTL/unique_ptr.h>
#include <EASTL/shared_ptr.h>
#include <EASTL/scoped_ptr.h>
#include <pugixml.hpp>
#include <luaffi/ffi.h>
class ThisIsAClass {
public:
ThisIsAClass() {
DbgPrint("%s\n", __FUNCTION__);
}
virtual ~ThisIsAClass() {
DbgPrint("%s\n", __FUNCTION__);
}
public:
void foo() {
DbgPrint("%s\n", __FUNCTION__);
}
};
ThisIsAClass test_global_class;
void DbgPrintS(const char* s) {
DbgPrint("%s\n", s);
}
struct TestPack
{
int a;
char b;
bool c;
float d;
double e;
eastl::string f;
eastl::vector<eastl::string> g;
MSGPACK_DEFINE(a, b, c, d, e, f, g);
};
void stl_test()
{
eastl::make_unique<DRIVER_OBJECT>();
eastl::make_shared<UNICODE_STRING>();
eastl::scoped_ptr<double> dptr(new double(3.6));
eastl::set<int> set_test;
set_test.insert(1);
set_test.insert(3);
set_test.insert(5);
set_test.erase(1);
eastl::map<int, int> map_test;
map_test[0] = 1;
map_test[10] = 11;
map_test[20] = 12;
map_test.erase(11);
eastl::vector<int> vec_test;
vec_test.push_back(2);
vec_test.push_back(3);
vec_test.push_back(1);
eastl::stable_sort(vec_test.begin(), vec_test.end(), eastl::less<int>());
for (auto e : vec_test) {
DbgPrint("%d\n", e);
}
eastl::string s;
s = "This a string";
s.append("any");
DbgPrint("%s\n", s.c_str());
eastl::wstring ws;
ws = L"wide string";
ws.clear();
eastl::unordered_set<float> us_test;
us_test.insert(333);
eastl::unordered_map<double, eastl::string> um_test;
um_test.insert(eastl::make_pair(6.6, "9.9"));
}
void lua_test()
{
LuaPlus::LuaStateAuto ls(LuaPlus::LuaState::Create(true));
luaopen_ffi(ls->GetCState());
{
LuaPlus::LuaModule _G(ls->GetGlobals());
_G.def("foo", &test_global_class, &ThisIsAClass::foo);
_G.def("DbgPrint", &DbgPrintS);
}
if (ls->LoadString("foo();\nDbgPrint([[Hello World]]);") == LUA_OK) {
ls->PCall(0, 0, 0);
}
/*
local function main()
local f, err = io.open("../dxx.log", "w");
if f then
for i = 1, 10, 1 do
f:write(i .. "\r\n");
end;
f:close();
end;
f, err = io.open("../dxx.log", "r");
if f then
for l in f:lines() do
print(l);
end;
f:close();
end;
end;
main();
*/
if (ls->LoadFile("../dxx.lua") == LUA_OK) // equal = C:\\dxx.lua
{
ls->PCall(0, 0, 0);
}
}
void pack_test()
{
TestPack tp;
tp.a = 1;
tp.b = '0';
tp.c = false;
tp.d = 666.666f;
tp.e = 520.1314;
tp.f = "ansi or utf8 string";
tp.g.push_back("many strings");
msgpack::sbuffer sb;
msgpack::pack(sb, tp);
TestPack tp2 = msgpack::unpack(sb.data(), sb.size()).get().as<TestPack>();
}
void xml_test()
{
pugi::xml_document doc;
/*
<?xml version='1.0' encoding='utf-8'?>
<root>
<dxx a="1" b="2" c="3.3" d="5.6" e="Hello kitty!">
<text><![CDATA[This is a CDATA String !!!]]></text>
</dxx>
</root>
*/
if (doc.load_file("././//System32/../../dxx.xml")) // equal = C:\\dxx.xml
{
pugi::xml_node root = doc.first_child();
pugi::xml_node node = root.child("dxx");
int a = node.attribute("a").as_int(0);
__int64 b = node.attribute("b").as_llong(0);
float c = node.attribute("c").as_float(0.0f);
double d = node.attribute("d").as_double(0.0);
eastl::string e = node.attribute("e").as_string("");
eastl::string cdata = node.child("text").text().as_string("");
// Driver cannot print float & double, view in WinDBG
DbgPrintEx(DPFLTR_SYSTEM_ID, DPFLTR_ERROR_LEVEL, "%d %d %s %s\n", a, b, (c, d, e.c_str()), cdata.c_str());
}
}
NTSTATUS SysMain(PDRIVER_OBJECT DrvObject, PUNICODE_STRING RegPath) {
UNREFERENCED_PARAMETER(DrvObject);
UNREFERENCED_PARAMETER(RegPath);
// NOTE OF PATH:
// SEPARATOR = '/' !!!
// BASE PATH = %SystemRoot% !!!
test_global_class.foo();
auto p1 = new CLIENT_ID[10];
delete[] p1;
stl_test();
lua_test();
pack_test();
xml_test();
return STATUS_UNSUCCESSFUL;
}