mirror of
https://github.com/zu1k/nali.git
synced 2025-02-02 10:22:41 +08:00
fix common
This commit is contained in:
parent
a74c9c72c4
commit
9f4a447374
@ -254,6 +254,10 @@ export NALI_DB=geoip
|
|||||||
- [Cobra CLI库](https://github.com/spf13/cobra)
|
- [Cobra CLI库](https://github.com/spf13/cobra)
|
||||||
- [Nali-cli](https://github.com/SukkaW/nali-cli)
|
- [Nali-cli](https://github.com/SukkaW/nali-cli)
|
||||||
|
|
||||||
|
## Origin
|
||||||
|
|
||||||
|
Inspired by [](https://github.com/meteoral/Nali) and [nali-cli](https://github.com/SukkaW/nali-cli)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
|
@ -13,7 +13,6 @@ type FileData struct {
|
|||||||
type IPDB struct {
|
type IPDB struct {
|
||||||
Data *FileData
|
Data *FileData
|
||||||
Offset uint32
|
Offset uint32
|
||||||
ItemLen uint32
|
|
||||||
IndexLen uint32
|
IndexLen uint32
|
||||||
IPNum uint32
|
IPNum uint32
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func NewZXwry(filePath string) ZXwry {
|
|||||||
return ZXwry{
|
return ZXwry{
|
||||||
IPDB: common.IPDB{
|
IPDB: common.IPDB{
|
||||||
Data: &fileInfo,
|
Data: &fileInfo,
|
||||||
IndexLen: 7,
|
IndexLen: 11,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,22 +77,19 @@ func (db *ZXwry) getAddr(offset uint32) (string, string) {
|
|||||||
offset = db.ReadUInt24()
|
offset = db.ReadUInt24()
|
||||||
return db.getAddr(offset)
|
return db.getAddr(offset)
|
||||||
}
|
}
|
||||||
_offset := db.Offset - 1
|
realOffset := db.Offset - 1
|
||||||
c1 := db.ReadArea(_offset)
|
c1 := db.ReadArea(realOffset)
|
||||||
if mode == common.RedirectMode2 {
|
if mode == common.RedirectMode2 {
|
||||||
db.Offset = 4 + _offset
|
db.Offset = 4 + realOffset
|
||||||
} else {
|
} else {
|
||||||
db.Offset = _offset + uint32(1+len(c1))
|
db.Offset = realOffset + uint32(1+len(c1))
|
||||||
}
|
}
|
||||||
c2 := db.ReadArea(db.Offset)
|
c2 := db.ReadArea(db.Offset)
|
||||||
return string(c1), string(c2)
|
return string(c1), string(c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *ZXwry) searchIndex(ip uint64) uint32 {
|
func (db *ZXwry) searchIndex(ip uint64) uint32 {
|
||||||
db.ItemLen = 8
|
header := db.ReadData(16, 8)
|
||||||
db.IndexLen = 11
|
|
||||||
|
|
||||||
header := db.Data.Data[8:24]
|
|
||||||
start := binary.LittleEndian.Uint32(header[8:])
|
start := binary.LittleEndian.Uint32(header[8:])
|
||||||
counts := binary.LittleEndian.Uint32(header[:8])
|
counts := binary.LittleEndian.Uint32(header[:8])
|
||||||
end := start + counts*db.IndexLen
|
end := start + counts*db.IndexLen
|
||||||
@ -101,22 +98,22 @@ func (db *ZXwry) searchIndex(ip uint64) uint32 {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
mid := db.GetMiddleOffset(start, end)
|
mid := db.GetMiddleOffset(start, end)
|
||||||
buf = db.Data.Data[mid : mid+db.IndexLen]
|
buf = db.ReadData(11, mid)
|
||||||
_ip := binary.LittleEndian.Uint64(buf[:db.ItemLen])
|
ipBytes := binary.LittleEndian.Uint64(buf[:8])
|
||||||
|
|
||||||
if end-start == db.IndexLen {
|
if end-start == db.IndexLen {
|
||||||
if ip >= binary.LittleEndian.Uint64(db.Data.Data[end:end+db.ItemLen]) {
|
if ip >= binary.LittleEndian.Uint64(db.ReadData(8, end)) {
|
||||||
buf = db.Data.Data[end : end+db.IndexLen]
|
buf = db.ReadData(11, end)
|
||||||
}
|
}
|
||||||
return common.ByteToUInt32(buf[db.ItemLen:])
|
return common.ByteToUInt32(buf[8:])
|
||||||
}
|
}
|
||||||
|
|
||||||
if _ip > ip {
|
if ipBytes > ip {
|
||||||
end = mid
|
end = mid
|
||||||
} else if _ip < ip {
|
} else if ipBytes < ip {
|
||||||
start = mid
|
start = mid
|
||||||
} else if _ip == ip {
|
} else if ipBytes == ip {
|
||||||
return common.ByteToUInt32(buf[db.ItemLen:])
|
return common.ByteToUInt32(buf[8:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user