-
Notifications
You must be signed in to change notification settings - Fork 21
/
functionVirtualManager.cpp
83 lines (63 loc) · 2.07 KB
/
functionVirtualManager.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
#include <functionVirtualManager.h>
#include <global.h>
time_t FunctionVirtualManager::getTimestamp(const char* functionName)
{
time_t timestamp = 0;
functionVirtualNameToTimestamp.retrieve(functionName, ×tamp);
return timestamp ? timestamp : 0;
}
void FunctionVirtualManager::add(FunctionStructure* functionStructure, time_t timestamp)
{
char* functionName = (char*)functionStructure->name.chars();
unsigned int id;
if (functionVirtualNameToFunctionStructureID.retrieve(functionName, &id))
{
//delete functionsStructures->at(id);
functionStructures.at(id) = functionStructure;
}
else
{
id = functionStructures.length();
functionStructures.append(functionStructure);
}
functionVirtualNameToFunctionStructureID.replace(functionName, id);
functionVirtualNameToTimestamp.replace(functionName, timestamp);
}
unsigned short int FunctionVirtualManager::makeFunction(FunctionStructure* functionStructure, long object)
{
TypeHandler* class_ = functionStructure->argumentsHandlers[0];
if (class_->hasVirtualTableOffset())
{
long offset = class_->getVirtualTableOffset();
void **vtable = *((void***)(((char*)object) + offset));
int **ivtable = (int**)vtable;
void* address = (void*)ivtable[functionStructure->virtualTableIndex];
FunctionStructure::VFuncTableMap::Insert i = functionStructure->virtualFunctionsCreated.findForAdd(address);
Function* function;
if (!i.found())
{
function = new Function(address, functionStructure->argumentsHandlers, functionStructure->argumentsCount, functionStructure->returnHandler, functionStructure->library, functionStructure->isMethod);
Global::FunctionManagerObj->addFunction("", function, 0);
if (functionStructure->virtualFunctionsCreated.add(i))
{
i->key = address;
}
i->value = function;
}
else
{
function = i->value;
}
return function->getID();
}
return 0;
}
FunctionStructure* FunctionVirtualManager::get(const char* functionName)
{
unsigned int id;
if (functionVirtualNameToFunctionStructureID.retrieve(functionName, &id))
{
return functionStructures.at(id);
}
return NULL;
}