sparse

package module
v0.0.0-...-c5e0720 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2016 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Golang implementation of simg2img

Overview

A go (golang) library for decoding android sparse image formatted files into raw images.

Examples

For a full example see example utility in ./cmd/

Using the writer. The performance of the writer is much better than the performance of the reader, as we can seek-past any "don't care" chunks in the sparse format, instead of writing random data.

func simg2img(in_filename, out_filename string) error {
    in, err := os.Open(in_filename)
    if err != nil {
        return err
    }
    defer in.Close()

    out, err := os.OpenFile(out_filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
    if err != nil {
        return err
    }
    defer out.Close()

    writer := sparse.Simg2imgWriter(out)
    _, err = io.Copy(writer, in)
    return err
}

Using the reader (slower!! Read Above!)

func simg2img_alt(in_filename, out_filename string) error {
    in, err := os.Open(in_filename)
    if err != nil {
        return err
    }
    defer in.Close()

    out, err := os.OpenFile(out_filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
    if err != nil {
        return err
    }
    defer out.Close()

    reader, err := sparse.Simg2imgReader(in)
    if err != nil {
        return err
    }

    _, err = io.Copy(out, reader)
    return err
}

License

See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Simg2imgReader

func Simg2imgReader(input io.Reader) (io.Reader, error)

func Simg2imgWriter

func Simg2imgWriter(output io.WriteSeeker) io.Writer

Types

type ChunkHeader

type ChunkHeader struct {
	ChunkType uint16 // 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care
	Reserved  uint16
	ChunkSize uint32 // in blocks in output image
	TotalSize uint32 // in bytes of chunk input file including chunk header and data
}

type SparseHeader

type SparseHeader struct {
	Magic           uint32 // 0xed26ff3a
	MajorVersion    uint16 // (0x1) - reject images with higher major versions
	MinorVersion    uint16 // (0x0) - allow images with higer minor versions
	FileHeaderSize  uint16 // 28 bytes for first revision of the file format
	ChunkHeaderSize uint16 // 12 bytes for first revision of the file format
	BlockSize       uint32 // block size in bytes, must be a multiple of 4 (4096)
	TotalBlocks     uint32 // total blocks in the non-sparse output image
	TotalChunks     uint32 // total chunks in the sparse input image
	ImageChecksum   uint32 // CRC32 checksum of the original data, counting "don't care"
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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