forked from hasherezade/tiny_tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuncWatch.cpp
81 lines (70 loc) · 1.79 KB
/
FuncWatch.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
#include "FuncWatch.h"
#include <vector>
#include <fstream>
#include <sstream>
#include "Util.h"
bool WFuncInfo::load(const std::string &sline, char delimiter)
{
std::vector<std::string> args;
util::splitList(sline, delimiter, args);
if (args.size() < 3) return false;
this->dllName = args[0];
this->funcName = args[1];
this->paramCount = util::loadInt(args[2]);
return true;
}
bool WFuncInfo::update(const WFuncInfo &func_info)
{
bool isUpdated = false;
if (this->paramCount < func_info.paramCount) {
this->paramCount = func_info.paramCount;
isUpdated = true;
}
return isUpdated;
}
//---
WFuncInfo* FuncWatchList::findFunc(const std::string& dllName, const std::string &funcName)
{
for (size_t i = 0; i < funcs.size(); i++)
{
WFuncInfo& info = funcs[i];
if (util::iequals(info.dllName, dllName)
&& util::iequals(info.funcName, funcName))
{
return &info;
}
}
return NULL;
}
bool FuncWatchList::appendFunc(WFuncInfo &func_info)
{
if (!func_info.isValid()) {
return false;
}
WFuncInfo* found = findFunc(func_info.dllName, func_info.funcName);
if (!found) {
funcs.push_back(func_info);
}
else {
found->update(func_info);
}
return true;
}
size_t FuncWatchList::loadList(const char* filename)
{
std::ifstream myfile(filename);
if (!myfile.is_open()) {
std::cerr << "Coud not open file: " << filename << std::endl;
return 0;
}
const size_t MAX_LINE = 300;
char line[MAX_LINE] = { 0 };
while (!myfile.eof()) {
myfile.getline(line, MAX_LINE);
WFuncInfo func_info;
if (func_info.load(line, ';')) {
appendFunc(func_info);
}
}
return funcs.size();
}