-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
116 lines (110 loc) · 2.99 KB
/
main.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
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
package main
import (
"encoding/binary"
"fmt"
"log"
"net"
"os"
"golang.org/x/text/encoding/simplifiedchinese"
)
var A []byte
var B []byte
func FindFlag(Ip uint32, file []byte) uint32 {
var flag = []byte{0x00, 0x00, 0x00, 0x00}
fastFlag := binary.LittleEndian.Uint32(file[0:4])
lastFlag := binary.LittleEndian.Uint32(file[4:8])
for {
mid := (lastFlag - fastFlag) / 7 / 2
mid = mid*7 + fastFlag
if binary.LittleEndian.Uint32(file[mid : mid+7][0:4]) == Ip {
copy(flag, file[mid : mid+7][4:7])
ipIndex := binary.LittleEndian.Uint32(flag)
return ipIndex
} else if binary.LittleEndian.Uint32(file[mid : mid+7][0:4]) > Ip {
lastFlag = mid
} else if binary.LittleEndian.Uint32(file[mid : mid+7][0:4]) < Ip {
fastFlag = mid
}
if lastFlag-fastFlag <= 7 {
if binary.LittleEndian.Uint32(file[lastFlag : lastFlag+7][0:4]) <= Ip {
copy(flag, file[lastFlag : lastFlag+7][4:7])
} else {
copy(flag, file[fastFlag : fastFlag+7][4:7])
}
ipIndex := binary.LittleEndian.Uint32(flag)
return ipIndex
}
}
}
func GetData(flagIndex uint32, file []byte, k uint32) {
var OffsetFlag = []byte{0x00, 0x00, 0x00, 0x00}
var i uint32
var j uint32
if file[flagIndex] == 0x01 {
copy(OffsetFlag, file[flagIndex+1:flagIndex+4])
GetData(binary.LittleEndian.Uint32(OffsetFlag), file, 0)
} else if file[flagIndex] == 0x02 {
copy(OffsetFlag, file[flagIndex+1:flagIndex+4])
GetData(binary.LittleEndian.Uint32(OffsetFlag), file, 1)
if file[flagIndex+4] == 0x01 || file[flagIndex+4] == 0x02 {
copy(OffsetFlag, file[flagIndex+5:flagIndex+8])
GetData(binary.LittleEndian.Uint32(OffsetFlag), file, 1)
} else {
GetData(flagIndex+4, file, 1)
}
} else {
i = 0
for {
if file[flagIndex+i] == 0x00 {
if len(A) == 0 {
A = file[flagIndex : flagIndex+i]
} else if len(B) == 0 {
B = file[flagIndex : flagIndex+i]
}
break
}
i++
}
if k == 0 {
if file[flagIndex+i+1] == 0x01 || file[flagIndex+i+1] == 0x02 {
GetData(flagIndex+i+1, file, 1)
} else {
j = flagIndex + i + 1
i = 0
for {
if file[j+i] == 0x00 {
if len(A) == 0 {
A = file[j : j+i]
} else if len(B) == 0 {
B = file[j : j+i]
}
break
}
i++
}
}
}
}
// fmt.Println("------")
// fmt.Printf("A: %v\n", A)
// fmt.Printf("B: %v\n", B)
// fmt.Printf("file[flagIndex]: %v\n", file[flagIndex])
}
func main() {
file, err := os.ReadFile("qqwry.dat")
if err != nil {
log.Panic(err)
}
// findFlag("8.8.8.8")
ip := net.ParseIP("255.255.255.0")
ip = ip.To4()
// fmt.Printf("FindFlag(binary.BigEndian.Uint32(ip), file): %v\n", FindFlag(binary.BigEndian.Uint32(ip), file))
GetData(FindFlag(binary.BigEndian.Uint32(ip), file)+4, file, 0)
decoder := simplifiedchinese.GB18030.NewDecoder()
AgbkString, _ := decoder.Bytes(A)
BgbkString, _ := decoder.Bytes(B)
// fmt.Printf("A: %v\n", A)
fmt.Printf("string(AgbkString): %v\n", string(AgbkString))
// fmt.Printf("B: %v\n", B)
fmt.Printf("string(BgbkString): %v\n", string(BgbkString))
}