mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
refactor: standardize logging on zap across all packages
Replace all fmt.Printf/Println and log.Printf/Fatal with structured zap.Logger calls to eliminate inconsistent logging (anti-pattern #12). - network/crypt_conn: inject logger via NewCryptConn, replace 6 fmt calls - signserver/session: use existing s.logger for debug packet dumps - entranceserver: use s.logger for inbound/outbound debug logging - api/utils: accept logger param in verifyPath, replace fmt.Println - api/endpoints: use s.logger for screenshot path diagnostics - config: replace log.Fatal with error return in getOutboundIP4 - deltacomp: replace log.Printf with zap.L() global logger
This commit is contained in:
@@ -5,9 +5,10 @@ import (
|
||||
"errors"
|
||||
"erupe-ce/config"
|
||||
"erupe-ce/network/crypto"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Conn defines the interface for a packet-based connection.
|
||||
@@ -23,6 +24,7 @@ type Conn interface {
|
||||
// CryptConn represents a MHF encrypted two-way connection,
|
||||
// it automatically handles encryption, decryption, and key rotation via it's methods.
|
||||
type CryptConn struct {
|
||||
logger *zap.Logger
|
||||
conn net.Conn
|
||||
realClientMode _config.Mode
|
||||
readKeyRot uint32
|
||||
@@ -33,8 +35,12 @@ type CryptConn struct {
|
||||
}
|
||||
|
||||
// NewCryptConn creates a new CryptConn with proper default values.
|
||||
func NewCryptConn(conn net.Conn, mode _config.Mode) *CryptConn {
|
||||
func NewCryptConn(conn net.Conn, mode _config.Mode, logger *zap.Logger) *CryptConn {
|
||||
if logger == nil {
|
||||
logger = zap.NewNop()
|
||||
}
|
||||
cc := &CryptConn{
|
||||
logger: logger,
|
||||
conn: conn,
|
||||
realClientMode: mode,
|
||||
readKeyRot: 995117,
|
||||
@@ -80,18 +86,19 @@ func (cc *CryptConn) ReadPacket() ([]byte, error) {
|
||||
|
||||
out, combinedCheck, check0, check1, check2 := crypto.Crypto(encryptedPacketBody, cc.readKeyRot, false, nil)
|
||||
if cph.Check0 != check0 || cph.Check1 != check1 || cph.Check2 != check2 {
|
||||
fmt.Printf("got c0 %X, c1 %X, c2 %X\n", check0, check1, check2)
|
||||
fmt.Printf("want c0 %X, c1 %X, c2 %X\n", cph.Check0, cph.Check1, cph.Check2)
|
||||
fmt.Printf("headerData:\n%s\n", hex.Dump(headerData))
|
||||
fmt.Printf("encryptedPacketBody:\n%s\n", hex.Dump(encryptedPacketBody))
|
||||
cc.logger.Warn("Crypto checksum mismatch",
|
||||
zap.String("got", hex.EncodeToString([]byte{byte(check0 >> 8), byte(check0), byte(check1 >> 8), byte(check1), byte(check2 >> 8), byte(check2)})),
|
||||
zap.String("want", hex.EncodeToString([]byte{byte(cph.Check0 >> 8), byte(cph.Check0), byte(cph.Check1 >> 8), byte(cph.Check1), byte(cph.Check2 >> 8), byte(cph.Check2)})),
|
||||
zap.String("headerData", hex.Dump(headerData)),
|
||||
zap.String("encryptedPacketBody", hex.Dump(encryptedPacketBody)),
|
||||
)
|
||||
|
||||
// Attempt to bruteforce it.
|
||||
fmt.Println("Crypto out of sync? Attempting bruteforce")
|
||||
cc.logger.Warn("Crypto out of sync, attempting bruteforce")
|
||||
for key := byte(0); key < 255; key++ {
|
||||
out, combinedCheck, check0, check1, check2 = crypto.Crypto(encryptedPacketBody, 0, false, &key)
|
||||
//fmt.Printf("Key: 0x%X\n%s\n", key, hex.Dump(out))
|
||||
if cph.Check0 == check0 && cph.Check1 == check1 && cph.Check2 == check2 {
|
||||
fmt.Printf("Bruceforce successful, override key: 0x%X\n", key)
|
||||
cc.logger.Info("Bruteforce successful", zap.Uint8("overrideKey", key))
|
||||
|
||||
// Try to fix key for subsequent packets?
|
||||
//cc.readKeyRot = (uint32(key) << 1) + 999983
|
||||
|
||||
Reference in New Issue
Block a user