mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-02 08:21:56 +03:00
Introduce pools to obfuscated2
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
package obfuscated2
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
import "encoding/binary"
|
||||
|
||||
const (
|
||||
handshakeFrameLen = 64
|
||||
@@ -32,48 +28,24 @@ const (
|
||||
// - 4 bytes of 'magic' - this has some settings like a connection type
|
||||
// - 2 bytes of 'DC'. DC is little endian int16
|
||||
// - 2 bytes of noise
|
||||
type HandhakeFrame struct {
|
||||
type handshakeFrame struct {
|
||||
data [handshakeFrameLen]byte
|
||||
}
|
||||
|
||||
func (f *HandhakeFrame) Fingerprint() []byte {
|
||||
return f.data[handshakeFrameOffsetStart:handshakeFrameOffsetEnd]
|
||||
}
|
||||
|
||||
func (f *HandhakeFrame) dc() int16 {
|
||||
data := f.data[handshakeFrameOffsetDC:handshakeFrameOffsetEnd]
|
||||
func (h *handshakeFrame) dc() int16 {
|
||||
data := h.data[handshakeFrameOffsetDC:handshakeFrameOffsetEnd]
|
||||
|
||||
return int16(binary.LittleEndian.Uint16(data))
|
||||
}
|
||||
|
||||
func (f *HandhakeFrame) key() []byte {
|
||||
return f.data[handshakeFrameLenKey:handshakeFrameOffsetIV]
|
||||
func (h *handshakeFrame) key() []byte {
|
||||
return h.data[handshakeFrameLenKey:handshakeFrameOffsetIV]
|
||||
}
|
||||
|
||||
func (f *HandhakeFrame) iv() []byte {
|
||||
return f.data[handshakeFrameOffsetIV:handshakeFrameOffsetMagic]
|
||||
func (h *handshakeFrame) iv() []byte {
|
||||
return h.data[handshakeFrameOffsetIV:handshakeFrameOffsetMagic]
|
||||
}
|
||||
|
||||
func (f *HandhakeFrame) magic() []byte {
|
||||
return f.data[handshakeFrameOffsetMagic:handshakeFrameOffsetDC]
|
||||
}
|
||||
|
||||
func (f *HandhakeFrame) invert() *HandhakeFrame {
|
||||
newFrame := &HandhakeFrame{}
|
||||
|
||||
for i, v := range f.data {
|
||||
newFrame.data[handshakeFrameLen-1-i] = v
|
||||
}
|
||||
|
||||
return newFrame
|
||||
}
|
||||
|
||||
func ReadHandshakeFrame(reader io.Reader) (*HandhakeFrame, error) {
|
||||
frame := &HandhakeFrame{}
|
||||
|
||||
if _, err := io.ReadFull(reader, frame.data[:]); err != nil {
|
||||
return nil, fmt.Errorf("cannot read frame data: %w", err)
|
||||
}
|
||||
|
||||
return frame, nil
|
||||
func (h *handshakeFrame) magic() []byte {
|
||||
return h.data[handshakeFrameOffsetMagic:handshakeFrameOffsetDC]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user