Rebase of the AWG obf graft (wase5feca7on v0.0.3) onto v0.0.5 (2c27bbf4f9, 'Add L3 forwarding support'). 15 of 16 graft files applied clean via 3-way; only send.go conflicted, on a single line (upstream queuedOutboundPackets backpressure decrement vs a graft blank line — took upstream). Key invariant preserved: MessageEncapsulatingTransportSize=0 (graft zeroes the sagernet encapsulating headroom; AWG obfuscation composes the prefix itself via SendBuffers, not Bind.Send prepend). Upstream's InputPacket/InputPackets and the new size-based outbound buffer pool (GetOutboundBuffer/PutOutboundBuffer) are taken verbatim; the graft's RoutineEncryption (header at buffer start) and transport-padding shift in RoutineSequentialSender re-woven around them. Builds clean on linux/android/windows/darwin (device/conn/tun).
38 lines
623 B
Go
38 lines
623 B
Go
package device
|
|
|
|
import "strconv"
|
|
|
|
func newDataSizeObf(val string) (obf, error) {
|
|
length, err := strconv.Atoi(val)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &dataSizeObf{
|
|
length: length,
|
|
}, nil
|
|
}
|
|
|
|
type dataSizeObf struct {
|
|
length int
|
|
}
|
|
|
|
func (o *dataSizeObf) Obfuscate(dst, src []byte) {
|
|
srcLen := len(src)
|
|
for i := o.length - 1; i >= 0; i-- {
|
|
dst[i] = byte(srcLen & 0xFF)
|
|
srcLen >>= 8
|
|
}
|
|
}
|
|
|
|
func (o *dataSizeObf) Deobfuscate(dst, src []byte) bool {
|
|
return true
|
|
}
|
|
|
|
func (o *dataSizeObf) ObfuscatedLen(srcLen int) int {
|
|
return o.length
|
|
}
|
|
|
|
func (o *dataSizeObf) DeobfuscatedLen(srcLen int) int {
|
|
return 0
|
|
}
|