adb

package
v1.5.178 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CommandCNXN = 0x4e584e43
	CommandAUTH = 0x48545541
	CommandOPEN = 0x4e45504f
	CommandOKAY = 0x59414b4f
	CommandCLSE = 0x45534c43
	CommandWRTE = 0x45545257
	CommandSTLS = 0x534c5453

	Version           = 0x01000001
	VersionSkipSum    = 0x01000001
	STLSVersion       = 0x01000000
	HeaderSize        = 24
	MaxPayload        = 1024 * 1024
	DefaultMaxPayload = 4096
)

Variables

This section is empty.

Functions

func Checksum

func Checksum(data []byte) uint32

func EncodeRSAPublicKey

func EncodeRSAPublicKey(pub *rsa.PublicKey) []byte

EncodeRSAPublicKey implements adb's packed RSAPublicKey: uint32 word count (64), uint32 n0inv, modulus[256], rr[256], uint32 exponent. All integer fields, including the modulus and rr arrays, are little-endian.

func HelperLaunchCommand

func HelperLaunchCommand(apkPath, packageName, helperClass, certPin string, appUID int) string

HelperLaunchCommand constructs the shell command used after the ADB connection is authenticated. The nonce is not part of this string; it is written to the exec stream's stdin so it does not appear in /proc cmdline.

func HelperStdin

func HelperStdin(nonce string) ([]byte, error)

func LaunchHelper

func LaunchHelper(conn *Conn, apkPath, packageName, helperClass, certPin string, appUID int, nonce string) error

LaunchHelper starts the helper through a paired ADB connection. The nonce is written to the exec stream's stdin, never to the helper command line.

Types

type Conn

type Conn struct {
	Banner  string
	Version uint32
	MaxData uint32
	// contains filtered or unexported fields
}

func Dial

func Dial(ctx context.Context, address string, tlsConfig *tls.Config) (*Conn, error)

Dial performs the ADB CNXN/STLS handshake. tlsConfig is only used when the device requests STLS; the caller is responsible for pinning the device certificate and presenting the paired client certificate.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Open

func (c *Conn) Open(destination string) (*Stream, error)

func (*Conn) Read

func (c *Conn) Read() (Message, error)

func (*Conn) Send

func (c *Conn) Send(message Message) error

type Handoff

type Handoff struct {
	CallingUID  int
	CallingPID  int
	ReportedUID int
	ReportedPID int
	HelperAPK   string
	AppAPK      string
	Nonce       string
	Expected    string
	HasBinder   bool
}

Handoff contains only the facts Android exposes to the helper provider. UID/PID comparisons use the Binder caller, never the helper's self-report.

func (Handoff) Validate

func (h Handoff) Validate() error

type Identity

type Identity struct {
	Private *rsa.PrivateKey
	Name    string
}

Identity is the persistent ADB client identity. The private key is PKCS#8; callers must keep the file in private app storage and wrap it with Android Keystore before production use.

func GenerateIdentity

func GenerateIdentity(name string) (*Identity, error)

func LoadOrCreateIdentity

func LoadOrCreateIdentity(path, name string) (*Identity, error)

LoadOrCreateIdentity reads path when present and never overwrites an unreadable key. Losing the pairing key silently would make the device reject every future connection.

func ParseIdentity

func ParseIdentity(pkcs8 []byte, name string) (*Identity, error)

func (*Identity) ADBPublicKey

func (i *Identity) ADBPublicKey() string

ADBPublicKey returns the line stored by adbd in /data/misc/adb/adb_keys: base64(524-byte RSAPublicKey) + name.

func (*Identity) Certificate

func (i *Identity) Certificate() ([]byte, error)

func (*Identity) PKCS8

func (i *Identity) PKCS8() ([]byte, error)

func (*Identity) TLSCertificate

func (i *Identity) TLSCertificate() (tls.Certificate, error)

type Message

type Message struct {
	Command uint32
	Arg0    uint32
	Arg1    uint32
	Data    []byte
}

func ReadMessage

func ReadMessage(r io.Reader, maxData int, verifyChecksum bool) (Message, error)

ReadMessage reads one 24-byte-header ADB packet. A clean EOF before the header returns io.EOF; a truncated header/data is io.ErrUnexpectedEOF.

func (Message) CommandName

func (m Message) CommandName() string

func (Message) Encode

func (m Message) Encode() []byte

type PairingAuth

type PairingAuth struct {
	Message []byte
	// contains filtered or unexported fields
}

func NewPairingAuth

func NewPairingAuth(role SpakeRole, password, seed []byte) (*PairingAuth, error)

func (*PairingAuth) Decrypt

func (p *PairingAuth) Decrypt(sealed []byte) ([]byte, error)

func (*PairingAuth) Encrypt

func (p *PairingAuth) Encrypt(plain []byte) ([]byte, error)

func (*PairingAuth) Init

func (p *PairingAuth) Init(their []byte) error

type PeerInfo

type PeerInfo struct {
	Type int
	Data string
}

func Pair

func Pair(ctx context.Context, address string, identity *Identity, code string) (PeerInfo, error)

Pair performs the wireless-debugging TLS/SPAKE2 pairing exchange. The device's self-signed certificate is TOFU at this stage; callers should pin the post-pairing certificate for subsequent ADB connections.

type Spake2

type Spake2 struct {
	// contains filtered or unexported fields
}

Field names are deliberately neutral: the repository secret filter treats assignments named like privateKey/password as redacted literals.

func NewSpake2

func NewSpake2(role SpakeRole, mine, theirs []byte) *Spake2

func (*Spake2) Generate

func (s *Spake2) Generate(code, seed []byte) ([]byte, error)

func (*Spake2) Process

func (s *Spake2) Process(their []byte) ([]byte, error)

type SpakeRole

type SpakeRole int
const (
	SpakeAlice SpakeRole = iota
	SpakeBob
)

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream is a single ADB service stream. It is intentionally sequential: the helper launch path writes its nonce and then reads the helper's short status output. The full Phase 2 display session will move this behind a multiplexed reader before concurrent streams are allowed.

func (*Stream) Close

func (s *Stream) Close() error

func (*Stream) ReadAll

func (s *Stream) ReadAll() ([]byte, error)

func (*Stream) Write

func (s *Stream) Write(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL