Skip to content

Commit

Permalink
fix common
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Jul 19, 2020
1 parent 32bf2cd commit 7a6a0c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ export NALI_DB=geoip
- [Cobra CLI库](https://github.com/spf13/cobra)
- [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

MIT
1 change: 0 additions & 1 deletion pkg/common/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type FileData struct {
type IPDB struct {
Data *FileData
Offset uint32
ItemLen uint32
IndexLen uint32
IPNum uint32
}
Expand Down
33 changes: 15 additions & 18 deletions pkg/zxipv6wry/zxipv6wry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewZXwry(filePath string) ZXwry {
return ZXwry{
IPDB: common.IPDB{
Data: &fileInfo,
IndexLen: 7,
IndexLen: 11,
},
}
}
Expand Down Expand Up @@ -77,22 +77,19 @@ func (db *ZXwry) getAddr(offset uint32) (string, string) {
offset = db.ReadUInt24()
return db.getAddr(offset)
}
_offset := db.Offset - 1
c1 := db.ReadArea(_offset)
realOffset := db.Offset - 1
c1 := db.ReadArea(realOffset)
if mode == common.RedirectMode2 {
db.Offset = 4 + _offset
db.Offset = 4 + realOffset
} else {
db.Offset = _offset + uint32(1+len(c1))
db.Offset = realOffset + uint32(1+len(c1))
}
c2 := db.ReadArea(db.Offset)
return string(c1), string(c2)
}

func (db *ZXwry) searchIndex(ip uint64) uint32 {
db.ItemLen = 8
db.IndexLen = 11

header := db.Data.Data[8:24]
header := db.ReadData(16, 8)
start := binary.LittleEndian.Uint32(header[8:])
counts := binary.LittleEndian.Uint32(header[:8])
end := start + counts*db.IndexLen
Expand All @@ -101,22 +98,22 @@ func (db *ZXwry) searchIndex(ip uint64) uint32 {

for {
mid := db.GetMiddleOffset(start, end)
buf = db.Data.Data[mid : mid+db.IndexLen]
_ip := binary.LittleEndian.Uint64(buf[:db.ItemLen])
buf = db.ReadData(11, mid)
ipBytes := binary.LittleEndian.Uint64(buf[:8])

if end-start == db.IndexLen {
if ip >= binary.LittleEndian.Uint64(db.Data.Data[end:end+db.ItemLen]) {
buf = db.Data.Data[end : end+db.IndexLen]
if ip >= binary.LittleEndian.Uint64(db.ReadData(8, end)) {
buf = db.ReadData(11, end)
}
return common.ByteToUInt32(buf[db.ItemLen:])
return common.ByteToUInt32(buf[8:])
}

if _ip > ip {
if ipBytes > ip {
end = mid
} else if _ip < ip {
} else if ipBytes < ip {
start = mid
} else if _ip == ip {
return common.ByteToUInt32(buf[db.ItemLen:])
} else if ipBytes == ip {
return common.ByteToUInt32(buf[8:])
}
}
}

0 comments on commit 7a6a0c9

Please sign in to comment.