-
Notifications
You must be signed in to change notification settings - Fork 0
/
trionic_common.go
60 lines (49 loc) · 1.33 KB
/
trionic_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
package symbol
import (
"bytes"
"errors"
"fmt"
"strings"
"github.com/roffe/ecusymbol/blowfish"
"github.com/roffe/ecusymbol/lzhuf"
)
const (
SIGNED = 0x01 /* signed flag in type */
KONST = 0x02 /* konstant flag in type */
CHAR = 0x04 /* character flag in type */
LONG = 0x08 /* long flag in type */
BITFIELD = 0x10 /* bitfield flag in type */
STRUCT = 0x20 /* struct flag in type */
)
func ExpandCompressedSymbolNames(in []byte) ([]string, error) {
if len(in) < 0x1000 {
return nil, errors.New("invalid symbol table size")
}
if bytes.HasPrefix(in, []byte{0xF1, 0x1A, 0x06, 0x5B, 0xA2, 0x6B, 0xCC, 0x6F}) {
return blowfish.DecryptSymbolNames(in)
}
expandedFileSize := int(in[0]) | (int(in[1]) << 8) | (int(in[2]) << 16) | (int(in[3]) << 24)
if expandedFileSize == -1 {
return nil, errors.New("invalid expanded file size")
}
out := make([]byte, expandedFileSize)
returnedSize := lzhuf.Decode(in, out)
if returnedSize != expandedFileSize {
return nil, fmt.Errorf("decoded data size missmatch: %d != %d", returnedSize, expandedFileSize)
}
return strings.Split(string(out), "\r\n"), nil
}
func CString(data []byte) string {
n := -1
for i, v := range data {
if v == 0 {
n = i
break
}
}
// If there was no null byte, convert the whole slice.
if n == -1 {
n = len(data)
}
return string(data[:n])
}