-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
171 lines (142 loc) · 4.56 KB
/
index.js
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
var crazyCpp = require('./build/Release/crazy');
(function(){
var Craziness = function(process_name, debug){
this.debug = debug || false;
this.cpp = crazyCpp;
this.processName = process_name;
if(!this.processName)
throw new Error("Missing process name");
this.procHandle = this.openProcess(this.processName);
};
Craziness.prototype.setDebugAs = function(bool){
bool = Boolean(bool);
this.debug = bool;
return this.cpp.setDebugAs(bool);
};
Craziness.prototype.openProcess = function(){
return this.cpp.openProcess.call(this, this.processName);
};
/**
* Reading functions
*/
Craziness.prototype.readInt = function(address){
return this.cpp.readInt(this.procHandle, address);
};
Craziness.prototype.readFloat = function(address){
return this.cpp.readFloat(this.procHandle, address);
};
Craziness.prototype.readBool = function(address){
return this.cpp.readBool(this.procHandle, address);
};
Craziness.prototype.readChar = function(address, value){
return this.cpp.readChar(this.procHandle, address, value);
};
Craziness.prototype.readUnicodeString = function(address, length){
/*
Ok, let me explain this fucking piece of shit-code... basically I shuck at C++
so this is the only way I found to manage unicode in V8-Node.
*/
length = parseInt(length) / 2;
var buff = this.cpp.readUnicodeString(this.procHandle, address, length).toString('utf8', 0, length).split("\u0000");
return buff.join("").substr(0, length);
}
/**
* Writing functions
*/
Craziness.prototype.writeFloat = function(address, value){
return this.cpp.writeFloat(this.procHandle, address, value);
};
Craziness.prototype.writeInt = function(address, value){
return this.cpp.writeFloat(this.procHandle, address, value);
};
Craziness.prototype.writeChar = function(address, value){
return this.cpp.writeChar(this.procHandle, address, value);
};
Craziness.prototype.writeDouble = function(address, value){
return this.cpp.writeDouble(this.procHandle, address, value);
};
Craziness.prototype.writeBool = function(address, value){
return this.cpp.writeBool(this.procHandle, address, value);
};
Craziness.prototype.writeInt64 = function(address, value){
return this.cpp.writeInt64(this.procHandle, address, value);
};
/**
* Low level methods
*/
Craziness.prototype.writeAssembly = function(address, byteArray){
var assembly = [];
for (var i = 0; i < byteArray.length; i++) {
assembly.push(this.readChar(address + i, byteArray[i]));
this.writeChar(address + i, byteArray[i]);
};
return assembly;
};
Craziness.prototype.nop = function(address, length){
var assembly = [];
for (var i = 0; i < length; i++) {
assembly.push(this.readChar(address + i, byteArray[i]));
this.writeChar(address + i, 0x90);
};
return assembly;
};
Craziness.prototype.read = function(address, type){
switch(type){
case "ptr":
case "int":
return this.readInt(address);
break;
case "float":
return this.readFloat(address);
break;
case "bool":
return this.readBool(address);
break;
case "short":
return this.readShort(address);
break;
case "int64":
return this.readInt64(address);
break;
case "float64":
case "double":
return this.readDouble(address);
break;
}
// In case none of the aboves exists, then the type its a string
var length = 0;
if(type.indexOf("wchar") >= 0 || type.indexOf("char") >= 0){
if(type.substr(0,4) == "char"){
length = type.match(/(\d+)/)[0];
type = "char";
}else{
length = type.match(/(\d+)/)[0];
type = "wchar";
}
}
switch(type){
case "char":
return this.cpp.readCString(address, length);
break;
case "wchar":
return this.readUnicodeString(address, length);
break;
}
return null;
};
Craziness.prototype.readStruct = function(base, struct){
var rtn = {};
var ptr = base;
for(var prop in struct){
if(struct[prop].type == "ptr"){
rtn[prop] = this.readStruct(this.read(ptr + struct[prop].offset, "ptr"), struct[prop].struct);
}else if(struct[prop].type == "baseAddress"){
rtn[prop] = this.readStruct(ptr + struct[prop].offset, struct[prop].struct);
}else{
rtn[prop] = this.read(ptr + struct[prop].offset, struct[prop].type);
}
};
return rtn;
};
module.exports = Craziness;
})();