img3

package
v0.0.0-prerelease Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Magic = "Img3"

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(data, iv, key []byte) ([]byte, error)

Decrypt decrypts an IMG3 file using the provided IV and key This function assumes the IV and key are already decrypted

func DecryptData

func DecryptData(data, iv, key []byte) ([]byte, error)

DecryptData decrypts IMG3 data using the provided IV and key

func DecryptKBag

func DecryptKBag(kbag *KBagData, gidKey []byte) error

DecryptKBag decrypts the KBAG using the provided GID key The gidKey should be the device's GID key (usually obtained through exploits)

func DecryptWithGIDKey

func DecryptWithGIDKey(data, gidKey []byte) ([]byte, error)

DecryptWithGIDKey decrypts an IMG3 file using the provided GID key This function handles the complete decryption process including KBAG decryption It tries all available KBAGs until one works

func DecryptWithKBAGKey

func DecryptWithKBAGKey(data, kbagKey []byte) ([]byte, error)

DecryptWithKBAGKey decrypts an IMG3 file using the provided KBAG decryption key This function implements the two-stage decryption process: 1. Use the provided key to decrypt the KBAG (which contains the encrypted IV+Key for the data) 2. Use the decrypted KBAG's IV+Key to decrypt the actual data

func ExtractData

func ExtractData(data []byte) ([]byte, error)

ExtractData extracts and decompresses data from an unencrypted IMG3 file This function is for IMG3 files that don't require decryption

Types

type Header struct {
	Magic        [4]byte // ASCII_LE("Img3")
	FullSize     uint32  // full size of fw image
	SizeNoPack   uint32  // size of fw image without header
	SigCheckArea uint32  // although that is just my name for it, this is the
	// size of the start of the data section (the code) up to
	// the start of the RSA signature (SHSH section)
	Ident [4]byte // identifier of image, used when bootrom is parsing images

}

Header img3 header object

type Img3

type Img3 struct {
	Header
	Tags []Tag // continues until end of file
}

Img3 object

func ParseImg3

func ParseImg3(data []byte) (*Img3, error)

ParseImg3 parses an IMG3 file from a byte slice

func (*Img3) GetAllKBagTags

func (i *Img3) GetAllKBagTags() ([][]byte, error)

GetAllKBagTags returns all KBAG tags from the IMG3 file

func (*Img3) GetDataTag

func (i *Img3) GetDataTag() ([]byte, error)

GetDataTag returns the DATA tag from the IMG3 file

func (*Img3) GetKBagTag

func (i *Img3) GetKBagTag() ([]byte, error)

GetKBagTag returns the KBAG tag from the IMG3 file

func (Img3) String

func (i Img3) String() string

type KBAG128

type KBAG128 struct {
	KBagHeader
	EncIV  [16]byte // IV for the firmware file, encrypted with the GID Key
	EncKey [16]byte // Key for the firmware file, encrypted with the GID Key
}

type KBAG192

type KBAG192 struct {
	KBagHeader
	EncIV  [16]byte // IV for the firmware file, encrypted with the GID Key
	EncKey [24]byte // Key for the firmware file, encrypted with the GID Key
}

type KBAG256

type KBAG256 struct {
	KBagHeader
	EncIV  [16]byte // IV for the firmware file, encrypted with the GID Key
	EncKey [32]byte // Key for the firmware file, encrypted with the GID Key
}

type KBagData

type KBagData struct {
	CryptState uint32
	AESType    uint32
	IV         []byte
	Key        []byte
}

KBagData represents the decrypted KBAG data

func ParseKBag

func ParseKBag(data []byte) (*KBagData, error)

ParseKBag parses a KBAG tag and returns the encrypted IV and key

type KBagHeader

type KBagHeader struct {
	CryptState uint32 // 1 if encrypted with GID Key, 2 if encrypted with Development GID Key
	AESType    uint32 // 0x80 = aes128, 0xc0 = aes192, 0x100 = aes256
}

KBAG structures for different AES key sizes Note: The IMG3 tag header (magic, fullSize, tagDataSize) is handled by the Tag structure KBAG data starts directly with cryptState and aesType

type Tag

type Tag struct {
	TagHeader
	Data []byte // [dataLength]
	Pad  []byte // Typically padded to 4 byte multiple [totalLength - dataLength - 12]
}

Tag img3 tag object

type TagHeader

type TagHeader struct {
	Magic       [4]byte // see below
	TotalLength uint32  // length of tag including "magic" and these two length values
	DataLength  uint32  // length of tag data
}

TagHeader img3 tag header object

Jump to

Keyboard shortcuts

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