Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
213 lines (191 loc) · 6.97 KB
/
Copy pathmain.cpp
File metadata and controls
213 lines (191 loc) · 6.97 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
Copyright 2024 ÜreTech Software
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
char shitpost[] = "Balina kumanyasi icinde kitap okuyan tavsan, uzayda kosan devekuzu ve denizde yuzerek gozu acik kalmis kartal ile bulustu, sonra birden bire telefon kulubesinin etrafinda donen aslanlar ve sehirde dondurma satan kedi ile dans eden yunuslarla birlikte kosmaya basladi, sonunda ise kaykayla ulkeye giden kuzugozu ve yolda kosan koyunlarin arasinda kayboldu.";
#include <malloc.h>
#include <iostream>
#include <string>
#include <vector>
#include "vHeap/nHeap/nHeapConfig.h"
#include "vHeap/vHeap.h"
#include "vHeap/nHeap/nHeap.h"
using namespace vhp::v120;
std::string readCon() {
std::string res;
std::getline(std::cin, res);
return res;
}
int main() {
printCon("vhp.ver-->", vhp_version_str);
printCon("vhp.vde-->", vhp_version_desc);
printCon("nhp.ver-->", nhp_version_str);
printCon("nhp.vde-->", nhp_version_desc);
printCon("nhp.sys-->", "Enter mode (c/s)");
std::string rd = readCon();
nhp::init_nhp_runtime();
if (rd == "s") {
nhp::_nhp->initServer(3306);
}
else if (rd == "c") {
nhp::_nhp->initClient("127.0.0.1", 3306);
while (1) {
if (nhp::_nhp->getMode() == nhp::n_client) {
nhp::_nhp->sendToServer((uint8_t*)shitpost, sizeof(shitpost));
}
Sleep(6000);
}
}
else {
LOG_ERROR("Unknown mode!")
}
LOG_INFO("main end")
while (1);//end for now
//*******************
init_vhp_runtime();
bool exitCon = false;
while (!exitCon) {
printCon("vhp.sys()-->", "Enter console var or list (type exit for exiting vhp)");
std::string inp = readCon();
if (inp == "exit") {
exitCon = true;
}
else if (inp == "cls") {
system("cls");
}
else if (inp == "dump") {
printCon("vhp.sys()-->", " vhp dump:\n" + _vhp->createHeapDump());
}
else if (inp == "add") {
printCon("vhp.sys()-->", "Enter var type (int8 / uint8...)");
std::string varTypeStr = readCon();
printCon("vhp.sys()-->", "Enter var name (don't use space)");
std::string varNameStr = readCon();
printCon("vhp.sys()-->", "use Index flag on the name (y/n)");
std::string useFlagStr = readCon();
bool useFlag = true;
if (useFlagStr == "y") {
useFlag = true;
}
else {
useFlag = false;
}
if (varTypeStr.empty() or varNameStr.empty()) {
printCon("vhp.sys.arg.error-->", "arguments can't be empty!");
continue;
}
try
{
void* ptr;
size_t varIndex = _vhp->addNewVar(varNameStr, varType_string_to_enum(varTypeStr), ptr, useFlag);
printCon("vhp.sys.add.info-->", "varIndex--> " + std::to_string(varIndex));
}
catch (std::string msg)
{
printCon("vhp.sys.add.error-->", msg);
continue;
}
}
else if (inp == "string") {
printCon("vhp.sys()-->", "Enter var name (don't use space)");
std::string varNameStr = readCon();
printCon("vhp.sys()-->", "use Index flag on the name (y/n)");
std::string useFlagStr = readCon();
printCon("vhp.sys()-->", "Enter string");
std::string varStr = readCon();
bool useFlag = true;
if (useFlagStr == "y") {
useFlag = true;
}
else {
useFlag = false;
}
if (varNameStr.empty()) {
printCon("vhp.sys.arg.error-->", "arguments can't be empty!");
continue;
}
try
{
void* ptr;
size_t varIndex = _vhp->addNewStringVar(varNameStr, varStr, ptr, useFlag);
printCon("vhp.sys.add.info-->", "varIndex--> " + std::to_string(varIndex));
}
catch (std::string msg)
{
printCon("vhp.sys.add.error-->", msg);
continue;
}
}
else if (inp == "getstr") {
printCon("vhp.sys()-->", "Enter var name");
std::string varNameStr = readCon();
try
{
vHeap* _vh = _vhp->getVarByName(varNameStr);
if (_vh->getVarType() != t_flex) {
printCon("vhp.sys.getstr.error-->", "var type is not flex");
}
else {
printCon("vhp.sys.set.info-->", " varData:" + std::string((char*)_vh->getVar(), _vh->getVarSize()));
//std::cout << " f " << (char*)_vh->getVar();
}
}
catch (std::string msg)
{
printCon("vhp.sys.getstr.error-->", msg);
continue;
}
}
else if (inp == "set") {
printCon("vhp.sys()-->", "Enter var name");
std::string varNameStr = readCon();
try
{
vHeap* _vh = _vhp->getVarByName(varNameStr);
printCon("vhp.sys.set.info-->", " varType:" + _vh->getVarTypeName());
printCon("vhp.sys.set.info-->", " varData:" + vHeap_to_string(_vh));
printCon("vhp.sys()-->", "Enter set value");
std::string varValueStr = readCon();
vHeap_setValueByString(varValueStr, _vh);
printCon("vhp.sys.set.info-->", " set to: varData:" + vHeap_to_string(_vh));
}
catch (std::string msg)
{
printCon("vhp.sys.set.error-->", msg);
continue;
}
}
else {
printCon("vhp.sys()-->", "unknown command");
}
}
printCon("MemX: ", "Reading 'memRefAddr'...");
Sleep(3000);
vHeap* v_ = nullptr;
try
{
v_ = _vhp->getVarByName("memRefAddr");
}
catch (std::string err)
{
printCon("vhp.sys.get.error-->", err);
}
if (v_ == nullptr) {
printCon("MemX: ", "'memRefAddr' not found! Please add with vhpAPI!");
while (1);
}
if (v_->getVarType() != t_uint8) {
printCon("MemX: ", "'memRefAddr' is not uint8! varType->" + v_->getVarTypeName());
while (1);
}
printCon("MemX: ", "memRefAddr-VALUE->" + vHeap_to_string(v_));
while (1);
}