optimized

This commit is contained in:
HynoR 2024-02-02 10:34:34 +08:00
parent c55aaa5502
commit f7498b26d8

View File

@ -11,9 +11,7 @@ const (
) )
// OICQAnalyzer OICQ is an IM Software protocol, Usually used by QQ // OICQAnalyzer OICQ is an IM Software protocol, Usually used by QQ
var ( var _ analyzer.UDPAnalyzer = (*OICQAnalyzer)(nil)
_ analyzer.UDPAnalyzer = (*OICQAnalyzer)(nil)
)
type OICQAnalyzer struct{} type OICQAnalyzer struct{}
@ -50,35 +48,30 @@ func (s *OICQStream) Close(limited bool) *analyzer.PropUpdate {
func parseOICQMessage(data []byte) analyzer.PropMap { func parseOICQMessage(data []byte) analyzer.PropMap {
/* preInfo struct /* preInfo struct
SFlag: 0x02 EFlag: 0x03
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|Flag | Version | Command | Sequence | Number | |SFlag| Version | Command | Sequence | Number |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| ................Data................(Dynamic Len) | | ................Data................(Dynamic Len)|EFlag|
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
*/ */
// At least 8 bytes // At least 12 bytes
if len(data) < 7 { if len(data) < 12 {
return nil return nil
} }
if data[0] != OICQPacketStartFlag { // OICQ Packet Start With 0x02 if data[0] != OICQPacketStartFlag || data[len(data)-1] != OICQPacketEndFlag { // OICQ Packet Start With 0x02
return nil return nil
} }
if data[len(data)-1] != OICQPacketEndFlag { // OICQ Packet End With 0x03 data = data[1:] // Remove Start Flag
return nil
}
data = data[1:]
m := analyzer.PropMap{ m := analyzer.PropMap{
"version": binary.BigEndian.Uint16(data[0:2]), "version": binary.BigEndian.Uint16(data[0:2]), // OICQ Version (2 bytes)
"command": binary.BigEndian.Uint16(data[2:4]), "command": binary.BigEndian.Uint16(data[2:4]), // OICQ Command (2 bytes)
"seq": binary.BigEndian.Uint16(data[4:6]), "seq": binary.BigEndian.Uint16(data[4:6]), // OICQ Sequence (2 bytes)
"number": 0, "number": binary.BigEndian.Uint32(data[6:10]), // OICQ Number, Mostly QQ Number (4 bytes)
} }
data = data[6:] if m["number"] == 0 || m["command"] == 0 {
if len(data) < 5 { return nil
// Valid OICQ packet, but no Number field
return m
} }
m["number"] = binary.BigEndian.Uint32(data[0:4])
// Valid OICQ packet with Number field // Valid OICQ packet with Number field
return m return m
} }