-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathcmd_js
More file actions
177 lines (155 loc) · 5.21 KB
/
Copy pathcmd_js
File metadata and controls
177 lines (155 loc) · 5.21 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
NAME=js tests, variable scoping
FILE=-
CMDS=<<EOF
js var a = 123
js r2.log(a)
js!
js r2.log(a)
EOF
EXPECT=<<EOF
123
EOF
EXPECT_ERR=<<EOF
ERROR: ReferenceError: a is not defined
ERROR: at <eval> (-:1:8)
ERROR: [uninitialized]
EOF
RUN
NAME=qjs async test
BROKEN=1
FILE=-
CMDS=<<EOF
'js import("r2pipe").then((r2pipe)=> {console.log(r2pipe.open());}).catch(console.error);
EOF
EXPECT=<<EOF
[object Object]
EOF
EXPECT_ERR=
RUN
NAME=qjs loading, running and unloading of core plugins
FILE=-
CMDS=<<EOF
Lc~qjs?
?e
'js (function() { function examplePlugin() { function coreCall(input) { if (input.startsWith("t1")) { console.log("This is a QJS test"); return true; } return false; } return { name: "qjs-example", desc: "Example QJS plugin (type 't1') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example", r2.plugin("core", examplePlugin)); })();
Lc~qjs
?e
'js (function() { function examplePlugin() { function coreCall(input) { if (input.startsWith("t1")) { console.log("This is a QJS test"); return true; } return false; } return { name: "qjs-example", desc: "Example QJS plugin (type 't1') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example", r2.plugin("core", examplePlugin)); })();
Lc~qjs
?e
'js (function() { function examplePlugin2() { function coreCall(input) { if (input.startsWith("t2")) { console.log("This is another QJS test"); return true; } return false; } return { name: "qjs-example2", desc: "Example QJS plugin (type 't2') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example2", r2.plugin("core", examplePlugin2)); })();
Lc~qjs
t1
t2
'js console.log("unload unknown", r2.unload("core", "unknownPlugin"))
Lc~qjs
?e
'js console.log("unload qjs-example", r2.unload("core", "qjs-example"))
Lc~qjs
?e
'js console.log("unload qjs-example again", r2.unload("core", "qjs-example"))
Lc~qjs
?e
'js console.log("unload qjs-example2", r2.unload("core", "qjs-example2"))
?e
Lc~qjs?
EOF
EXPECT=<<EOF
0
qjs-example Example QJS plugin (type 't1') in the r2 shell
qjs-example Example QJS plugin (type 't1') in the r2 shell
qjs-example Example QJS plugin (type 't1') in the r2 shell
qjs-example2 Example QJS plugin (type 't2') in the r2 shell
qjs-example Example QJS plugin (type 't1') in the r2 shell
qjs-example2 Example QJS plugin (type 't2') in the r2 shell
qjs-example2 Example QJS plugin (type 't2') in the r2 shell
qjs-example2 Example QJS plugin (type 't2') in the r2 shell
0
load qjs-example true
load qjs-example false
load qjs-example2 true
This is a QJS test
This is another QJS test
unload unknown false
unload qjs-example true
unload qjs-example again false
unload qjs-example2 true
EOF
EXPECT_ERR=<<EOF
WARN: r2.plugin with name qjs-example is already registered
EOF
RUN
NAME=qjs loading and unloading of arch plugins
BROKEN=1
FILE=-
CMDS=<<EOF
LA~qjs?
?e
'js (function() { function archPlugin() { return { name: "myarch qjs plugin", arch: "myarch_qjs", desc: "this is a test arch", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin1', r2.plugin("arch", archPlugin)); })()
LA~qjs
?e
'js (function() { function archPlugin() { return { name: "myarch qjs plugin", arch: "myarch_qjs", desc: "this is a test arch", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin1 again', r2.plugin("arch", archPlugin)); })()
LA~qjs
?e
'js (function() { function archPlugin2() { return { name: "myarch qjs plugin2", arch: "myarch_qjs2", desc: "this is a test arch2", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin2', r2.plugin("arch", archPlugin2)); })()
LA~qjs
?e
'js console.log("unload unknown", r2.unload("arch", "unknownPlugin"))
LA~qjs
?e
'js console.log("unload qjs-example", r2.unload("arch", "myarch_qjs"))
LA~qjs
?e
'js console.log("unload qjs-example again", r2.unload("arch", "myarch_qjs"))
LA~qjs
?e
'js console.log("unload qjs-example2", r2.unload("arch", "myarch_qjs2"))
?e
LA~qjs?
EOF
EXPECT=<<EOF
0
myarch qjs plugin LGPL3 this is a test arch (myarch_qjs)
myarch qjs plugin LGPL3 this is a test arch (myarch_qjs)
myarch qjs plugin LGPL3 this is a test arch (myarch_qjs)
myarch qjs plugin2 LGPL3 this is a test arch2 (myarch_qjs2)
myarch qjs plugin2 LGPL3 this is a test arch2 (myarch_qjs2)
myarch qjs plugin2 LGPL3 this is a test arch2 (myarch_qjs2)
0
load plugin1 true
load plugin1 again false
load plugin2 true
unload unknown false
unload qjs-example true
unload qjs-example again false
unload qjs-example2 true
EOF
EXPECT_ERR=<<EOF
WARN: r2.plugin with name myarch qjs plugin is already registered
EOF
RUN
NAME=js ec changes
FILE=-
ARGS=-e scr.color=1
CMDS=<<EOF
'js r2.cmd("ec call blue");console.log(r2.cmd("ec*~call"));r2.cmd("ec call red");console.log(r2.cmd("ec*~call"))
EOF
EXPECT=<<EOF
ec call rgb:0037da
ec ucall rgb:13a10e
ec call rgb:c50f1f
ec ucall rgb:13a10e
EOF
EXPECT_ERR=
RUN
NAME=qjs r2pipe2 helpers
FILE=-
CMDS=<<EOF
s 0x10
'js const ok = r2.cmd2At("?v $$", 0x33).value === 0x33 && Number(r2.callAt("?v $$", 0x44).trim()) === 0x44 && r2.call2("?v $$").value === 0x10 && r2.call2At("?v $$", 0x55).value === 0x55 && !r2.call2j("?Vj").error && typeof r2.call2j("?Vj").res === "object"; console.log(ok ? "ok" : "no");
EOF
EXPECT=<<EOF
ok
EOF
EXPECT_ERR=
RUN