Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/gas/gas.js
1293 views
1
CodeMirror.defineMode("gas", function(_config, parserConfig) {
2
'use strict';
3
4
// If an architecture is specified, its initialization function may
5
// populate this array with custom parsing functions which will be
6
// tried in the event that the standard functions do not find a match.
7
var custom = [];
8
9
// The symbol used to start a line comment changes based on the target
10
// architecture.
11
// If no architecture is pased in "parserConfig" then only multiline
12
// comments will have syntax support.
13
var lineCommentStartSymbol = "";
14
15
// These directives are architecture independent.
16
// Machine specific directives should go in their respective
17
// architecture initialization function.
18
// Reference:
19
// http://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops
20
var directives = {
21
".abort" : "builtin",
22
".align" : "builtin",
23
".altmacro" : "builtin",
24
".ascii" : "builtin",
25
".asciz" : "builtin",
26
".balign" : "builtin",
27
".balignw" : "builtin",
28
".balignl" : "builtin",
29
".bundle_align_mode" : "builtin",
30
".bundle_lock" : "builtin",
31
".bundle_unlock" : "builtin",
32
".byte" : "builtin",
33
".cfi_startproc" : "builtin",
34
".comm" : "builtin",
35
".data" : "builtin",
36
".def" : "builtin",
37
".desc" : "builtin",
38
".dim" : "builtin",
39
".double" : "builtin",
40
".eject" : "builtin",
41
".else" : "builtin",
42
".elseif" : "builtin",
43
".end" : "builtin",
44
".endef" : "builtin",
45
".endfunc" : "builtin",
46
".endif" : "builtin",
47
".equ" : "builtin",
48
".equiv" : "builtin",
49
".eqv" : "builtin",
50
".err" : "builtin",
51
".error" : "builtin",
52
".exitm" : "builtin",
53
".extern" : "builtin",
54
".fail" : "builtin",
55
".file" : "builtin",
56
".fill" : "builtin",
57
".float" : "builtin",
58
".func" : "builtin",
59
".global" : "builtin",
60
".gnu_attribute" : "builtin",
61
".hidden" : "builtin",
62
".hword" : "builtin",
63
".ident" : "builtin",
64
".if" : "builtin",
65
".incbin" : "builtin",
66
".include" : "builtin",
67
".int" : "builtin",
68
".internal" : "builtin",
69
".irp" : "builtin",
70
".irpc" : "builtin",
71
".lcomm" : "builtin",
72
".lflags" : "builtin",
73
".line" : "builtin",
74
".linkonce" : "builtin",
75
".list" : "builtin",
76
".ln" : "builtin",
77
".loc" : "builtin",
78
".loc_mark_labels" : "builtin",
79
".local" : "builtin",
80
".long" : "builtin",
81
".macro" : "builtin",
82
".mri" : "builtin",
83
".noaltmacro" : "builtin",
84
".nolist" : "builtin",
85
".octa" : "builtin",
86
".offset" : "builtin",
87
".org" : "builtin",
88
".p2align" : "builtin",
89
".popsection" : "builtin",
90
".previous" : "builtin",
91
".print" : "builtin",
92
".protected" : "builtin",
93
".psize" : "builtin",
94
".purgem" : "builtin",
95
".pushsection" : "builtin",
96
".quad" : "builtin",
97
".reloc" : "builtin",
98
".rept" : "builtin",
99
".sbttl" : "builtin",
100
".scl" : "builtin",
101
".section" : "builtin",
102
".set" : "builtin",
103
".short" : "builtin",
104
".single" : "builtin",
105
".size" : "builtin",
106
".skip" : "builtin",
107
".sleb128" : "builtin",
108
".space" : "builtin",
109
".stab" : "builtin",
110
".string" : "builtin",
111
".struct" : "builtin",
112
".subsection" : "builtin",
113
".symver" : "builtin",
114
".tag" : "builtin",
115
".text" : "builtin",
116
".title" : "builtin",
117
".type" : "builtin",
118
".uleb128" : "builtin",
119
".val" : "builtin",
120
".version" : "builtin",
121
".vtable_entry" : "builtin",
122
".vtable_inherit" : "builtin",
123
".warning" : "builtin",
124
".weak" : "builtin",
125
".weakref" : "builtin",
126
".word" : "builtin"
127
};
128
129
var registers = {};
130
131
function x86(_parserConfig) {
132
lineCommentStartSymbol = "#";
133
134
registers.ax = "variable";
135
registers.eax = "variable-2";
136
registers.rax = "variable-3";
137
138
registers.bx = "variable";
139
registers.ebx = "variable-2";
140
registers.rbx = "variable-3";
141
142
registers.cx = "variable";
143
registers.ecx = "variable-2";
144
registers.rcx = "variable-3";
145
146
registers.dx = "variable";
147
registers.edx = "variable-2";
148
registers.rdx = "variable-3";
149
150
registers.si = "variable";
151
registers.esi = "variable-2";
152
registers.rsi = "variable-3";
153
154
registers.di = "variable";
155
registers.edi = "variable-2";
156
registers.rdi = "variable-3";
157
158
registers.sp = "variable";
159
registers.esp = "variable-2";
160
registers.rsp = "variable-3";
161
162
registers.bp = "variable";
163
registers.ebp = "variable-2";
164
registers.rbp = "variable-3";
165
166
registers.ip = "variable";
167
registers.eip = "variable-2";
168
registers.rip = "variable-3";
169
170
registers.cs = "keyword";
171
registers.ds = "keyword";
172
registers.ss = "keyword";
173
registers.es = "keyword";
174
registers.fs = "keyword";
175
registers.gs = "keyword";
176
}
177
178
function armv6(_parserConfig) {
179
// Reference:
180
// http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf
181
// http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301h/DDI0301H_arm1176jzfs_r0p7_trm.pdf
182
lineCommentStartSymbol = "@";
183
directives.syntax = "builtin";
184
185
registers.r0 = "variable";
186
registers.r1 = "variable";
187
registers.r2 = "variable";
188
registers.r3 = "variable";
189
registers.r4 = "variable";
190
registers.r5 = "variable";
191
registers.r6 = "variable";
192
registers.r7 = "variable";
193
registers.r8 = "variable";
194
registers.r9 = "variable";
195
registers.r10 = "variable";
196
registers.r11 = "variable";
197
registers.r12 = "variable";
198
199
registers.sp = "variable-2";
200
registers.lr = "variable-2";
201
registers.pc = "variable-2";
202
registers.r13 = registers.sp;
203
registers.r14 = registers.lr;
204
registers.r15 = registers.pc;
205
206
custom.push(function(ch, stream) {
207
if (ch === '#') {
208
stream.eatWhile(/\w/);
209
return "number";
210
}
211
});
212
}
213
214
var arch = parserConfig.architecture.toLowerCase();
215
if (arch === "x86") {
216
x86(parserConfig);
217
} else if (arch === "arm" || arch === "armv6") {
218
armv6(parserConfig);
219
}
220
221
function nextUntilUnescaped(stream, end) {
222
var escaped = false, next;
223
while ((next = stream.next()) != null) {
224
if (next === end && !escaped) {
225
return false;
226
}
227
escaped = !escaped && next === "\\";
228
}
229
return escaped;
230
}
231
232
function clikeComment(stream, state) {
233
var maybeEnd = false, ch;
234
while ((ch = stream.next()) != null) {
235
if (ch === "/" && maybeEnd) {
236
state.tokenize = null;
237
break;
238
}
239
maybeEnd = (ch === "*");
240
}
241
return "comment";
242
}
243
244
return {
245
startState: function() {
246
return {
247
tokenize: null
248
};
249
},
250
251
token: function(stream, state) {
252
if (state.tokenize) {
253
return state.tokenize(stream, state);
254
}
255
256
if (stream.eatSpace()) {
257
return null;
258
}
259
260
var style, cur, ch = stream.next();
261
262
if (ch === "/") {
263
if (stream.eat("*")) {
264
state.tokenize = clikeComment;
265
return clikeComment(stream, state);
266
}
267
}
268
269
if (ch === lineCommentStartSymbol) {
270
stream.skipToEnd();
271
return "comment";
272
}
273
274
if (ch === '"') {
275
nextUntilUnescaped(stream, '"');
276
return "string";
277
}
278
279
if (ch === '.') {
280
stream.eatWhile(/\w/);
281
cur = stream.current().toLowerCase();
282
style = directives[cur];
283
return style || null;
284
}
285
286
if (ch === '=') {
287
stream.eatWhile(/\w/);
288
return "tag";
289
}
290
291
if (ch === '{') {
292
return "braket";
293
}
294
295
if (ch === '}') {
296
return "braket";
297
}
298
299
if (/\d/.test(ch)) {
300
if (ch === "0" && stream.eat("x")) {
301
stream.eatWhile(/[0-9a-fA-F]/);
302
return "number";
303
}
304
stream.eatWhile(/\d/);
305
return "number";
306
}
307
308
if (/\w/.test(ch)) {
309
stream.eatWhile(/\w/);
310
if (stream.eat(":")) {
311
return 'tag';
312
}
313
cur = stream.current().toLowerCase();
314
style = registers[cur];
315
return style || null;
316
}
317
318
for (var i = 0; i < custom.length; i++) {
319
style = custom[i](ch, stream, state);
320
if (style) {
321
return style;
322
}
323
}
324
},
325
326
lineComment: lineCommentStartSymbol,
327
blockCommentStart: "/*",
328
blockCommentEnd: "*/"
329
};
330
});
331
332