readwrite

package module
v0.0.0-...-533d3cb Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: AGPL-3.0 Imports: 6 Imported by: 3

README

readwrite

A simple Go module to read and write data.

Reader & Writer
  • reader, err := readwrite.NewReader(path)
  • writer, err := readwrite.NewWriter(path, append=false)
UTF
  • bytes := Utf8ToUtf16("aaabbbccc")
PE

License

See LICENSE file.

Documentation

Index

Constants

View Source
const (
	COFFStartBytesLen = 4
	COFFHeaderSize    = 20
)
View Source
const (
	DataDirSize      = 128
	DataDirEntrySize = 8
)

DataDirectory 16 entries * 8 bytes / entry.

View Source
const (
	SH32EntrySize           = 64
	SH32NameSize            = 8
	SH32CharacteristicsSize = 4
)

Variables

View Source
var COFFStartBytes = []byte{0x50, 0x45, 0x00, 0x00} //nolint:gochecknoglobals // wontfix

COFFHeader 0x50, 0x45 = PE COFF_START_BYTES_LEN == len(COFFStartBytes).

View Source
var OH64ByteSize = binary.Size(OptionalHeader64X110{}) //nolint:exhaustruct,gochecknoglobals // wontfix

OptionalHeader64 https://github.com/golang/go/blob/master/src/debug/pe/pe.go uint byte size of OptionalHeader64 without magic mumber(2 bytes) or data directory(128 bytes) OptionalHeader64 size is 240 (110).

View Source
var SH32ByteSize = binary.Size(SectionHeader32X28{}) //nolint:exhaustruct,gochecknoglobals // wontfix

SectionHeader32 https://github.com/golang/go/blob/master/src/debug/pe/section.go uint byte size of SectionHeader32 without name(8 bytes) or characteristics(4 bytes) (28).

Functions

func FindBytes

func FindBytes(src []byte, dst []byte) (int, error)

func MatchBytes

func MatchBytes(src []byte, dst []byte) bool

func PadBytes

func PadBytes(bytes []byte, size int) []byte

func ReadCOFFHeaderOffset

func ReadCOFFHeaderOffset(bytes []byte) (int, error)

func ReadDDBytes

func ReadDDBytes(bytes []byte) ([]byte, error)

func ReadDDEntryOffset

func ReadDDEntryOffset(bytes []byte, entryVirtualAddress uint32, entrySize uint32) (int, error)

func ReadSHBytes

func ReadSHBytes(bytes []byte, shSize int) ([]byte, error)

func ReadSHEntryOffset

func ReadSHEntryOffset(bytes []byte, address int) (int, error)

func ReadSHSize

func ReadSHSize(file pe.File) (int, error)

func ReadSectionBytes

func ReadSectionBytes(file *Data, sectionVirtualAddress uint32, sectionSize uint32) ([]byte, error)

func Utf8ToUtf16

func Utf8ToUtf16(utf8str string) []byte

func WriteBytes

func WriteBytes(bytes []byte, offset int, replace []byte) error

Types

type Data

type Data struct {
	Bytes []byte
	PE    pe.File
}

Data structure.

func Open

func Open(path string) (*Data, error)

type DataDir

type DataDir struct {
	VA   uint32
	Size uint32
}

DataDir structure (.ooa).

func ReadDataDir

func ReadDataDir(reader io.Reader) (DataDir, error)

type DataEntry

type DataEntry struct {
	Hash     uint32
	FileName string
}

func FindByFileName

func FindByFileName(data []DataEntry, fileName string) *DataEntry

func FindByHash

func FindByHash(data []DataEntry, hash uint32) *DataEntry

type EncBlock

type EncBlock struct {
	VA          uint32
	RawSize     uint32
	VirtualSize uint32
	Unk         uint32
	CRC         uint32
	Unk2        uint32
	CRC2        uint32
	Pad         uint32
	FileOffset  uint32
	Pad2        uint64
	Pad3        uint32
}

EncBlock structure (.ooa).

func ReadEncBlock

func ReadEncBlock(reader io.Reader) (EncBlock, error)

type FileEntry

type FileEntry struct {
	FileName      string
	FileNameLower uint32
	FileNameUpper uint32
	Offset        uint64
	UncompSize    uint64
}

type Import

type Import struct {
	Characteristics uint32
	Timedatestamp   uint32
	ForwarderChain  uint32
	Name            uint32
	FThunk          uint32
}

Import structure (.ooa).

func ReadImport

func ReadImport(reader io.Reader) (Import, error)

type OptionalHeader64X110

type OptionalHeader64X110 struct {
	MajorLinkerVersion          uint8
	MinorLinkerVersion          uint8
	SizeOfCode                  uint32
	SizeOfInitializedData       uint32
	SizeOfUninitializedData     uint32
	AddressOfEntryPoint         uint32
	BaseOfCode                  uint32
	ImageBase                   uint64
	SectionAlignment            uint32
	FileAlignment               uint32
	MajorOperatingSystemVersion uint16
	MinorOperatingSystemVersion uint16
	MajorImageVersion           uint16
	MinorImageVersion           uint16
	MajorSubsystemVersion       uint16
	MinorSubsystemVersion       uint16
	Win32VersionValue           uint32
	SizeOfImage                 uint32
	SizeOfHeaders               uint32
	CheckSum                    uint32
	Subsystem                   uint16
	DllCharacteristics          uint16
	SizeOfStackReserve          uint64
	SizeOfStackCommit           uint64
	SizeOfHeapReserve           uint64
	SizeOfHeapCommit            uint64
	LoaderFlags                 uint32
	NumberOfRvaAndSizes         uint32
}

type Reader

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

func NewReader

func NewReader(fileName string) (*Reader, error)

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) IsValid

func (r *Reader) IsValid() bool

func (*Reader) Position

func (r *Reader) Position() (int64, error)

func (*Reader) Read

func (r *Reader) Read(data []byte) (int, error)

func (*Reader) ReadChar

func (r *Reader) ReadChar() (byte, error)

func (*Reader) ReadUInt32

func (r *Reader) ReadUInt32() (uint32, error)

func (*Reader) ReadUInt64

func (r *Reader) ReadUInt64() (uint64, error)

func (*Reader) Seek

func (r *Reader) Seek(position int64, whence int) (int64, error)

func (*Reader) SeekFromBeginning

func (r *Reader) SeekFromBeginning(position int64) (int64, error)

func (*Reader) SeekFromCurrent

func (r *Reader) SeekFromCurrent(position int64) (int64, error)

func (*Reader) SeekFromEnd

func (r *Reader) SeekFromEnd(position int64) (int64, error)

func (*Reader) Size

func (r *Reader) Size() (int64, error)

type Section

type Section struct {
	ContentID   string
	OEP         uint64
	EncBlocks   []EncBlock
	ImageBase   uint64
	SizeOfImage uint32
	ImportDir   DataDir
	IATDir      DataDir
	RelocDir    DataDir
}

Section structure (.ooa).

type SectionHeader32X28

type SectionHeader32X28 struct {
	VirtualSize          uint32
	VirtualAddress       uint32
	SizeOfRawData        uint32
	PointerToRawData     uint32
	PointerToRelocations uint32
	PointerToLineNumbers uint32
	NumberOfRelocations  uint16
	NumberOfLineNumbers  uint16
}

type Thunk

type Thunk struct {
	Function uint32
	DataAddr uint32
}

Thunk structure (.ooa).

func ReadThunk

func ReadThunk(reader io.Reader) (Thunk, error)

type Writer

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

func NewWriter

func NewWriter(fileName string, appendMode bool) (*Writer, error)

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Position

func (w *Writer) Position() (int64, error)

func (*Writer) Seek

func (w *Writer) Seek(position int64, whence int) (int64, error)

func (*Writer) SeekFromBeginning

func (w *Writer) SeekFromBeginning(position int64) (int64, error)

func (*Writer) SeekFromCurrent

func (w *Writer) SeekFromCurrent(position int64) (int64, error)

func (*Writer) SeekFromEnd

func (w *Writer) SeekFromEnd(position int64) (int64, error)

func (*Writer) Size

func (w *Writer) Size() (int64, error)

func (*Writer) Write

func (w *Writer) Write(data []byte) (int, error)

func (*Writer) WriteChar

func (w *Writer) WriteChar(data string) (int, error)

func (*Writer) WriteUInt32

func (w *Writer) WriteUInt32(value uint32) error

func (*Writer) WriteUInt64

func (w *Writer) WriteUInt64(value uint64) error

Jump to

Keyboard shortcuts

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