forked from zxh0/luago-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_chunk.go
More file actions
79 lines (71 loc) · 1.47 KB
/
Copy pathbinary_chunk.go
File metadata and controls
79 lines (71 loc) · 1.47 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
package binchunk
const (
LUA_SIGNATURE = "\x1bLua"
LUAC_VERSION = 0x53
LUAC_FORMAT = 0
LUAC_DATA = "\x19\x93\r\n\x1a\n"
CINT_SIZE = 4
CSIZET_SIZE = 8
INSTRUCTION_SIZE = 4
LUA_INTEGER_SIZE = 8
LUA_NUMBER_SIZE = 8
LUAC_INT = 0x5678
LUAC_NUM = 370.5
)
const (
TAG_NIL = 0x00
TAG_BOOLEAN = 0x01
TAG_NUMBER = 0x03
TAG_INTEGER = 0x13
TAG_SHORT_STR = 0x04
TAG_LONG_STR = 0x14
)
type binaryChunk struct {
header
sizeUpvalues byte // ?
mainFunc *Prototype
}
type header struct {
signature [4]byte
version byte
format byte
luacData [6]byte
cintSize byte
sizetSize byte
instructionSize byte
luaIntegerSize byte
luaNumberSize byte
luacInt int64
luacNum float64
}
// function prototype
type Prototype struct {
Source string // debug
LineDefined uint32
LastLineDefined uint32
NumParams byte
IsVararg byte
MaxStackSize byte
Code []uint32
Constants []interface{}
Upvalues []Upvalue
Protos []*Prototype
LineInfo []uint32 // debug
LocVars []LocVar // debug
UpvalueNames []string // debug
}
type Upvalue struct {
Instack byte
Idx byte
}
type LocVar struct {
VarName string
StartPC uint32
EndPC uint32
}
func Undump(data []byte) *Prototype {
reader := &reader{data}
reader.checkHeader()
reader.readByte() // size_upvalues
return reader.readProto("")
}