-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
134 lines (119 loc) · 2.72 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
var dp = require("./lib/DiskProxy");
var fs = require("fs");
var repl = require("repl");
var DiskProxy = dp.DiskProxy;
var dump = dp.dump;
var memory = dp.mem;
var context = {};
var swap = dp.setSwap(DiskProxy("swap","object",null));
context.rt = swap;
var rt = dp.getSwap();
var ram = {};
context.ram = ram;
const crypto = require('crypto');
const readline = require("readline");
context.lib = lib;
var diskproxy = DiskProxy("disk/alpha","object",context);
context.disk = diskproxy;
var alias = DiskProxy("disk/alias","object",context);
var documentation = DiskProxy("docs","object",context);
context.help = documentation;
var lib = {
fs : fs,
format : {
disk : function($) {
//console.log("$.disk.login.username + (?:password) = hmac digest");
//console.log( crypto.createHmac('sha256', $.disk.password).digest("hex") );
// for(var key in diskproxy) { delete diskproxy[key]; }
}
}
};
function _eval(code) {
eval(code);
}
const r = repl.start('> ');
function initialize() {
Object.defineProperty(r.context,"$",{
configurable: false,
enumerable: true,
value: r.context
});
Object.defineProperty(r.context,"eval",{
configurable: false,
enumerable: true,
value: function() {
var args = [];
for(var x = 0; x < arguments.length;x++) args.push(arguments[x]);
return _eval.apply(r.context,args);
}
});
Object.defineProperty(r.context,"lib",{
configurable: false,
enumerable: true,
value: lib
});
Object.defineProperty(r.context, 'ram', {
configurable: false,
enumerable: true,
value: ram
});
Object.defineProperty(r.context, "disk",{
configurable: false,
enumerable: true,
get : function() {
return diskproxy;
}
});
Object.defineProperty(r.context, "env",{
configurable: false,
enumerable: true,
get : function() {
return alias;
}
});
Object.defineProperty(r.context, 'help', {
configurable: false,
enumerable: true,
value: documentation
});
Object.defineProperty(r.context, 'rt', {
configurable: false,
enumerable: true,
value: rt
});
try { delete diskproxy.mock; } catch(e) {}
try { delete alias.mock; } catch(e) {}
try { delete documentation.mock; } catch(e) {}
try { delete swap.mock; } catch(e) {}
function set(key,val) {
Object.defineProperty(r.context, key, {
configurable: false,
enumerable: true,
value: val
});
}
for(var key in alias) {
var $ = r.context;
eval("var f = " + alias[key]);
set(key,f);
}
}
initialize();
r.on('exit', () => {
// shutdown
diskproxy.mock = 0;
alias.mock = 0;
swap.mock = 0;
documentation.mock = 0;
process.exit();
});
for(var x in diskproxy)
console.log(x);
r.on('reset',() => {
// shutdown
diskproxy.mock = 0;
alias.mock = 0;
swap.mock = 0;
documentation.mock = 0;
initialize();
});