-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcommon.go
62 lines (53 loc) · 1.6 KB
/
common.go
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
package main
import (
"bytes"
"compress/zlib"
"io"
"math/rand"
)
const (
PYINST20_COOKIE_SIZE = 24 // For pyinstaller 2.0
PYINST21_COOKIE_SIZE = 24 + 64 // For pyinstaller 2.1+
)
var PYINST_MAGIC [8]byte = [8]byte{'M', 'E', 'I', 014, 013, 012, 013, 016} // Magic number which identifies pyinstaller
type PyInst20Cookie struct {
Magic []byte `struct:"[8]byte"`
LengthOfPackage int `struct:"int32,big"`
Toc int `struct:"int32,big"`
TocLen int `struct:"int32,big"`
PythonVersion int `struct:"int32,big"`
}
type PyInst21Cookie struct {
Magic []byte `struct:"[8]byte"`
LengthOfPackage uint `struct:"uint32,big"`
Toc uint `struct:"uint32,big"`
TocLen int `struct:"int32,big"`
PythonVersion int `struct:"int32,big"`
PythonLibName []byte `struct:"[64]byte"`
}
type CTOCEntry struct {
EntrySize int `struct:"int32,big"`
EntryPosition uint `struct:"uint32,big"`
DataSize uint `struct:"uint32,big"`
UncompressedDataSize uint `struct:"uint32,big"`
ComressionFlag int8 `struct:"int8"`
TypeCompressedData byte `struct:"byte"`
Name string
}
func zlibDecompress(in []byte) (out []byte, err error) {
var zr io.ReadCloser
zr, err = zlib.NewReader(bytes.NewReader(in))
if err != nil {
return
}
out, err = io.ReadAll(zr)
return
}
func randomString() string {
const CHARSET = "0123456789abcdef"
var randomBytes []byte = make([]byte, 16)
for i := 0; i < 16; i++ {
randomBytes = append(randomBytes, CHARSET[rand.Intn(len(CHARSET))])
}
return string(randomBytes)
}