-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscope_config.lua
More file actions
442 lines (398 loc) · 14.4 KB
/
scope_config.lua
File metadata and controls
442 lines (398 loc) · 14.4 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/usr/bin/lua
--[[
Configuration for Lua Scope
A Lua 5.1/5.2/5.3 binary chunk disassembler
LuaScope was inspired by Jein-Hong Man's ChunkSpy
--]]
config = {}
--
--[[
-- Configuration table
-- * Contains fixed constants, display constants and options, and
-- platform-dependent configuration constants
--
-- Configuration settings of binary chunks to be processed. Such tables
-- may be used to sort of "auto-detect" binary chunks from different
-- platforms. More or less equivalent to the global header.
-- * There is currently only one supported host, "x86 standard"
-- * MAX_STACK is no longer required for decoding RK register indices,
-- instead, the MSB bit in the field is used as a flag (Lua 5.1)
-- * number_type is also used to lookup conversion function, etc.
--]]
--
CONFIGURATION = {
["x86 standard"] = {
description = "x86 standard (32-bit, little endian, doubles)",
endianness = 1, -- 1 = little endian
size_int = 4, -- (data type sizes in bytes)
size_size_t = 4,
size_Instruction = 4,
size_lua_Number = 8, -- this & integral identifies the
integral = 0, -- type of lua_Number
number_type = "double", -- used for lookups
},
["x86_64"] = {
description = "x86_64 (64-bit, little endian, doubles)",
endianness = 1, -- 1 = little endian
size_int = 4, -- (data type sizes in bytes)
size_size_t = 8,
size_Instruction = 4,
size_lua_Number = 8, -- this & integral identifies the
integral = 0, -- type of lua_Number
number_type = "double", -- used for lookups
},
["big endian int"] = {
description = "(32-bit, big endian, ints)",
endianness = 0,
size_int = 4,
size_size_t = 4,
size_Instruction = 4,
size_lua_Number = 4,
integral = 1,
number_type = "int",
},
-- you can add more platforms here
}
--
-- chunk constants
-- * changed in 5.1: VERSION, FPF, SIZE_* are now fixed; LUA_TBOOLEAN
-- added for constant table; TEST_NUMBER removed; FORMAT added
--
config.SIGNATURE = "\27Lua"
-- TEST_NUMBER no longer needed, using size_lua_Number + integral
config.LUA_TNIL = 0
config.LUA_TBOOLEAN = 1
config.LUA_TNUMBER = 3
config.LUA_TSTRING = 4
config.VERSION = 81 -- 0x51
config.FORMAT = 0 -- LUAC_FORMAT (new in 5.1)
config.FPF = 50 -- LFIELDS_PER_FLUSH
config.SIZE_OP = 6 -- instruction field bits
config.SIZE_A = 8
config.SIZE_B = 9
config.SIZE_C = 9
-- MAX_STACK no longer needed for instruction decoding, removed
-- LUA_FIRSTINDEX currently not supported; used in SETLIST
config.LUA_FIRSTINDEX = 1
--
-- display options: you can set your defaults here
--
config.DISPLAY_FLAG = true -- global listing output on/off
config.DISPLAY_BRIEF = nil -- brief listing style
config.DISPLAY_INDENT = nil -- indent flag for brief style
config.STATS = nil -- set if always display stats
config.DISPLAY_OFFSET_HEX = true -- use hexadecimal for position
config.DISPLAY_SEP = " " -- column separator
config.DISPLAY_COMMENT = "; " -- comment sign
config.DISPLAY_HEX_DATA = true -- show hex data column
config.WIDTH_HEX = 8 -- width of hex data column
config.WIDTH_OFFSET = nil -- width of position column
config.DISPLAY_LOWERCASE = true -- lower-case operands
config.WIDTH_OPCODE = nil -- width of opcode field
config.VERBOSE_TEST = false -- more verbosity for --test
--
-- Detected run time configs
--
config.version = { "5.1", "5.2", "5.3" }
--
-- primitive platform auto-detection
--
function init_scope_config_description()
if config.AUTO_DETECT then
config.description = nil
for _, cfg in pairs(CONFIGURATION) do
if cfg.endianness == config.endianness and
cfg.size_int == config.size_int and
cfg.size_size_t == config.size_size_t and
cfg.size_Instruction == config.size_Instruction and
cfg.size_lua_Number == config.size_lua_Number and
cfg.integral == config.integral and
cfg.number_type == config.number_type then
config.description = cfg.description
end
end
if not config.description then
config.description = "chunk platform unrecognized"
end
-- some parameters are not in the global header, e.g. FPF
-- see the config table for more on these constants
end
end
function init_print_width(size)
if not config.WIDTH_OFFSET then config.WIDTH_OFFSET = 0 end
if config.DISPLAY_OFFSET_HEX then
local w = string.len(string.format("%X", size))
if w > config.WIDTH_OFFSET then config.WIDTH_OFFSET = w end
if (config.WIDTH_OFFSET % 2) == 1 then
config.WIDTH_OFFSET = config.WIDTH_OFFSET + 1
end
else
config.WIDTH_OFFSET = string.len(tonumber(size))
end
end
function init_display_config()
if config.WIDTH_OFFSET < 4 then config.WIDTH_OFFSET = 4 end
if not config.DISPLAY_SEP then config.DISPLAY_SEP = " " end
if config.DISPLAY_HEX_DATA == nil then config.DISPLAY_HEX_DATA = true end
if not config.WIDTH_HEX then config.WIDTH_HEX = 8 end
config.BLANKS_HEX_DATA = string.rep(" ", config.WIDTH_HEX * 2 + 1)
end
function SetProfile(profile)
if profile == "local" then
-- arrives here only for --rewrite and --run option
local flag1, flag2 = config.DISPLAY_FLAG, config.AUTO_DETECT
config.DISPLAY_FLAG, config.AUTO_DETECT = false, true
local LUA_SAMPLE = string.dump(function() end)
config.DISPLAY_FLAG, config.AUTO_DETECT = flag1, flag2
-- resume normal operation
else
local c = CONFIGURATION[profile]
if not c then return false end
for i, v in pairs(c) do config[i] = v end
end
return true
end
function get_config()
return config
end
function GetTypeNIL()
return config.LUA_TNIL
end
function GetTypeBoolean()
return config.LUA_TBOOLEAN
end
function GetTypeNumber()
return config.LUA_TNUMBER
end
function GetTypeString()
return config.LUA_TSTRING
end
function GetOutputSep()
return config.DISPLAY_SEP
end
function GetOutputShowHexData()
return config.DISPLAY_HEX_DATA
end
function GetOutputBlankHex()
return config.BLANKS_HEX_DATA
end
function GetOutputHexWidth()
return config.WIDTH_HEX
end
function GetOutputPosWidth()
return config.WIDTH_OFFSET
end
function GetOutputComment()
return config.DISPLAY_COMMENT
end
function GetOutputPosString(i)
if config.DISPLAY_OFFSET_HEX then
return string.format("%X", i - 1)
else
return tonumber(i - 1)
end
end
function GetLuaDescription()
return config.description
end
function GetLuaIntSize()
return config.size_int
end
function GetLuaSizetSize()
return config.size_size_t
end
function GetLuaNumberSize()
return config.size_lua_Number
end
function GetLuaInstructionSize()
return config.size_Instruction
end
function GetLuaNumberType()
return config.number_type
end
function SetLuaNumberType(t)
config.number_type = t
end
function GetLuaEndianness()
return config.endianness
end
function SetLuaEndianness(e)
config.endianness = e
end
function GetLuaIntegral()
return config.integral
end
function SetLuaIntegral(b)
config.integral = b
end
function ShouldIPrintStats()
return config.STATS and not config.DISPLAY_BRIEF
end
-- TODO : combine next 4 functions
function ShouldIPrintLess()
return not config.DISPLAY_FLAG or config.DISPLAY_BRIEF
end
function ShouldIPrintBrief()
return config.DISPLAY_BRIEF
end
function ShouldIPrintXYZ()
return not config.DISPLAY_FLAG or not config.DISPLAY_BRIEF
end
function ShouldIPrintParts()
return config.DISPLAY_FLAG and config.DISPLAY_BRIEF
end
function ShouldIPrintHexData()
return config.DISPLAY_HEX_DATA
end
function ShouldIPrintLowercase()
return config.DISPLAY_LOWERCASE
end
Oconfig = {
GetVersion = function (self)
vs = {}
for k,v in pairs(config.version) do
if v == "5.1" then
vs[#vs+1] = 0x51
elseif v == "5.2" then
vs[#vs+1] = 0x52
elseif v == "5.3" then
vs[#vs+1] = 0x53
else
vs[#vs+1] = 0
end
end
return vs
end,
IsVersionOK = function (self, v)
vs = self.GetVersion()
for _,vi in pairs(vs) do
--print("Compare ", vi, v)
if vi == v then return true end
end
return false
end,
GetSign = function (self)
return config.SIGNATURE
end,
GetFormat = function (self)
return config.FORMAT
end,
GetTypeNIL = function (self)
return GetTypeNIL()
end,
GetTypeBoolean = function (self)
return GetTypeBoolean()
end,
GetTypeNumber = function (self)
return GetTypeNumber()
end,
GetTypeString = function (self)
return GetTypeString()
end,
GetOutputSep = function (self)
return GetOutputSep()
end,
GetOutputShowHexData = function (self)
return GetOutputShowHexData()
end,
GetOutputBlankHex = function (self)
return GetOutputBlankHex()
end,
GetOutputHexWidth = function (self)
return GetOutputHexWidth()
end,
GetOutputPosWidth = function (self)
return GetOutputPosWidth()
end,
GetOutputComment = function (self)
return GetOutputComment()
end,
GetOutputPosString= function (self, i)
return GetOutputPosString(i)
end,
GetLuaDescription = function (self)
return GetLuaDescription()
end,
GetLuaIntSize = function (self)
return GetLuaIntSize()
end,
GetLuaSizetSize = function (self)
return GetLuaSizetSize()
end,
GetLuaNumberSize = function (self)
return GetLuaNumberSize()
end,
GetLuaInstructionSize = function (self)
return GetLuaInstructionSize()
end,
GetLuaNumberType = function (self)
return GetLuaNumberType()
end,
GetLuaEndianness = function (self)
return GetLuaEndianness()
end,
GetLuaIntegral = function (self)
return GetLuaIntegral()
end,
GetConfigDetect = function (self)
return config.AUTO_DETECT
end,
GetLuaSize_A = function (self)
return config.SIZE_A
end,
GetLuaSize_B = function (self)
return config.SIZE_B
end,
GetLuaSize_C = function (self)
return config.SIZE_C
end,
GetLuaSize_OP = function (self)
return config.SIZE_OP
end,
GetLuavm_Size_Int = function (self)
return config.size_int
end,
GetLuavm_Size_Sizet = function (self)
return config.size_size_t
end,
GetLuavm_Size_Instruction = function (self)
return config.size_Instruction
end,
GetLuavm_Size_Number = function (self)
return config.size_lua_Number
end,
SetLuavm_Size_Int = function (self, v)
config.size_int = v
end,
SetLuavm_Size_Sizet = function (self, v)
config.size_size_t = v
end,
SetLuavm_Size_Instruction = function (self, v)
config.size_Instruction = v
end,
SetLuavm_Size_Number = function (self, v)
config.size_lua_Number = v
end,
GetLuavmSizeTbl = function (self, type)
l = {}
l["int"] = {}
l["int"]["get"] = self.GetLuavm_Size_Int
l["int"]["set"] = self.SetLuavm_Size_Int
l["size_t"] = {}
l["size_t"]["get"] = self.GetLuavm_Size_Sizet
l["size_t"]["set"] = self.SetLuavm_Size_Sizet
l["Instruction"] = {}
l["Instruction"]["get"] = self.GetLuavm_Size_Instruction
l["Instruction"]["set"] = self.SetLuavm_Size_Instruction
l["number"] = {}
l["number"]["get"] = self.GetLuavm_Size_Number
l["number"]["set"] = self.SetLuavm_Size_Number
return l[type]
end,
GetLuaFPF = function (self)
return config.FPF
end,
ShouldIPrintStats = function (self)
return ShouldIPrintStats()
end,
}