utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMountResourceBusy = errors.New("hdiutil: mount failed - Resource busy")

Functions

func ClangFormat

func ClangFormat(src, filename string, color bool) string

func CodeSign

func CodeSign(filePath, signature string) error

CodeSign codesigns a given binary

func CodeSignAdHoc

func CodeSignAdHoc(filePath string) error

CodeSignAdHoc codesigns a given binary with ad-hoc signature

func CodeSignWithEntitlements

func CodeSignWithEntitlements(filePath, entitlementsPath, signature string) error

CodeSignWithEntitlements codesigns a given binary with given entitlements

func CodesignShow

func CodesignShow(path string) (string, error)

func CodesignVerify

func CodesignVerify(path string) (string, error)

func Compare

func Compare(v, w string) int

Compare returns an integer comparing two versions according to semantic version precedence. The result will be 0 if v == w, -1 if v < w, or +1 if v > w.

An invalid semantic version string is considered less than a valid one. All invalid semantic version strings compare equal to each other.

func ConvertStrToInt

func ConvertStrToInt(intStr string) (uint64, error)

ConvertStrToInt converts an input string to uint64

func Copy

func Copy(src, dst string) error

Copy recursively copies src into dst with src's file modes. CREDIT: https://github.com/goreleaser/goreleaser/blob/main/internal/gio/copy.go

func CopyWithMode

func CopyWithMode(src, dst string, mode os.FileMode) error

CopyWithMode recursively copies src into dst with the given mode. The given mode applies only to files. Their parent dirs will have the same mode as their src counterparts.

func Cp

func Cp(src, dst string) error

Cp copies a file from src to dest

func CreateCompressedDMG

func CreateCompressedDMG(appPath, diskimagePath string) error

CreateCompressedDMG creates a compressed r/o disk image containing Install macOS.app

func CreateInstaller

func CreateInstaller(distPath, targetVol string) error

CreateInstaller creates an macOS installer

func CreateSparseDiskImage

func CreateSparseDiskImage(volumeName, diskPath string) (string, error)

CreateSparseDiskImage creates a sparse disk image and returns it's path

func DiffVersion

func DiffVersion(v, w string) (string, error)

func Difference

func Difference[T comparable](l1 []T, l2 []T) (diff []T)

func DisplayImageInTerminal

func DisplayImageInTerminal(r io.Reader, width, height int) error

DisplayImageInTerminal displays an image in the terminal (supported in iTerm2 and VSCode)

func Dumper

func Dumper(w io.Writer, vaddr uint) io.WriteCloser

Dumper returns a WriteCloser that writes a hex dump of all written data to w. The format of the dump matches the output of `hexdump -C` on the command line.

func ExtractFromDMG

func ExtractFromDMG(ipswPath, dmgPath, destPath string, pattern *regexp.Regexp) ([]string, error)

func FilterStrFromSlice

func FilterStrFromSlice(slice []string, filter string) []string

FilterStrFromSlice removes all the strings that contain the filter from a string slice

func FilterStrSlice

func FilterStrSlice(slice []string, filter string) []string

FilterStrSlice removes all the strings that do NOT contain the filter from a string slice

func GetKernelCollectionPath

func GetKernelCollectionPath() (string, error)

func GetKernelPath

func GetKernelPath() (string, error)

func GetXCodePath

func GetXCodePath() (string, error)

func GitClone

func GitClone(repo, dst string) (string, error)

GitClone clones a git repo

func GitDiff

func GitDiff(src, dst string, conf *GitDiffConfig) (string, error)

func GitRefresh

func GitRefresh(repoPath string) (string, error)

GitRefresh refreshes a git repo

func GrepStrings

func GrepStrings(data []byte, searchStr string) []string

GrepStrings returns all matching strings in []byte

func HexDump

func HexDump(data []byte, vaddr uint64) string

HexDump returns a string that contains a hex dump of the given data. The format of the hex dump matches the output of `hexdump -C` on the command line.

func Indent

func Indent(f func(s string), level int) func(string)

Indent indents apex log line to supplied level

func InstallKDK

func InstallKDK(path string) error

func InstallXCodeSimRuntime

func InstallXCodeSimRuntime(path string) error

func IsASCII

func IsASCII(s string) bool

IsASCII checks if given string is ascii

func IsAlnum

func IsAlnum(c byte) bool

func IsAlreadyMounted

func IsAlreadyMounted(image, mountPoint string) (string, bool, error)

func IsDeveloperImageMounted

func IsDeveloperImageMounted(udid string) error

func IsDeveloperModeEnabled

func IsDeveloperModeEnabled(udid string) (bool, error)

func IsHex

func IsHex(c rune) bool

func IsLetter

func IsLetter(c byte) bool

func IsPunctuation

func IsPunctuation(c byte) bool

func IsSpace

func IsSpace(c byte) bool

func KmutilCreate

func KmutilCreate(conf *KMUConfig) (err error)

func Mount

func Mount(image, mountPoint string) error

Mount mounts a DMG with hdiutil

func MountDMG

func MountDMG(image string) (string, bool, error)

func Pad

func Pad(length int) string

Pad creates left padding for printf members

func PickDevice

func PickDevice() (*lockdownd.DeviceValues, error)

func PickDevices

func PickDevices() ([]*lockdownd.DeviceValues, error)

func PkgUtilExpand

func PkgUtilExpand(src, dst string) (string, error)

func PrintAsn1Data

func PrintAsn1Data(data []byte)

func PrintCMSData

func PrintCMSData(data []byte)

func RandomAgent

func RandomAgent() string

func RemoveStrFromSlice

func RemoveStrFromSlice(s []string, r string) []string

RemoveStrFromSlice removes a single string from a string slice

func Retry

func Retry(attempts int, sleep time.Duration, f func() error) (err error)

Retry will retry a function f a number of attempts with a sleep duration in between

func Reverse

func Reverse[T any](input []T)

func ReverseBytes

func ReverseBytes(a []byte) []byte

ReverseBytes reverse byte array order

func SearchFileName

func SearchFileName(name string, files []os.FileInfo) (os.FileInfo, error)

func SearchZip

func SearchZip(files []*zip.File, pattern *regexp.Regexp, folder string, flat, progress bool) ([]string, error)

SearchZip searches for files in a zip.Reader

func Slugify

func Slugify(s string) string

func SortDevices

func SortDevices(devices []string) []string

SortDevices sorts a list of device names

func SortFileNameAscend

func SortFileNameAscend(files []os.FileInfo)

func SortFileNameDescend

func SortFileNameDescend(files []os.FileInfo)

func SortMachoVersions

func SortMachoVersions(list []MachoVersion)

func SortVersions

func SortVersions(list []string)

SortVersions sorts a list of semantic version strings using ByVersion.

func StrContainsStrSliceItem

func StrContainsStrSliceItem(item string, slice []string) bool

StrContainsStrSliceItem returns true if given string contains any item in the string slice

func StrSliceAddSuffix

func StrSliceAddSuffix(slice []string, suffix string) []string

func StrSliceContains

func StrSliceContains(slice []string, item string) bool

StrSliceContains returns true if string slice contains given string

func StrSliceHas

func StrSliceHas(slice []string, item string) bool

StrSliceHas returns true if string slice has an exact given string

func TrimPrefixStrSlice

func TrimPrefixStrSlice(slice []string, prefix string) []string

TrimPrefixStrSlice trims the prefix from all strings in string slice

func Uint64SliceContains

func Uint64SliceContains(slice []uint64, item uint64) bool

Uint64SliceContains returns true if uint64 slice contains given uint64

func UnTarGz

func UnTarGz(tarfile, destPath string) error

UnTarGz - https://stackoverflow.com/a/57640231

func UnicodeSanitize

func UnicodeSanitize(s string) string

UnicodeSanitize sanitizes string to be used in Hugo URL's, allowing only a predefined set of special Unicode characters. If RemovePathAccents configuration flag is enabled, Unicode accents are also removed. Hyphens in the original input are maintained. Spaces will be replaced with a single hyphen, and sequential replacement hyphens will be reduced to one.

func Unique

func Unique[T comparable](s []T) []T

Unique returns a slice with only unique elements

func UniqueAppend

func UniqueAppend[T comparable](slice []T, i T) []T

func UniqueConcat

func UniqueConcat[T comparable](slice []T, in []T) []T

func Unmount

func Unmount(mountPoint string, force bool) error

Unmount unmounts a DMG with hdiutil

func Unzip

func Unzip(src, dest string, filter func(f *zip.File) bool) ([]string, error)

Unzip - https://stackoverflow.com/a/24792688

func Verify

func Verify(sha1sum, name string) (bool, error)

Verify verifies the downloaded against it's hash

Types

type BuildInfo

type BuildInfo struct {
	ProductNames   string
	ProductVersion string
	BuildVersion   string
}

func GetBuildInfo

func GetBuildInfo() (*BuildInfo, error)

GetBuildInfo returns the current device OS build info

type ByMachoVersion

type ByMachoVersion []MachoVersion

func (ByMachoVersion) Len

func (vs ByMachoVersion) Len() int

func (ByMachoVersion) Less

func (vs ByMachoVersion) Less(i, j int) bool

func (ByMachoVersion) Swap

func (vs ByMachoVersion) Swap(i, j int)

type ByVersion

type ByVersion []string

ByVersion implements sort.Interface for sorting semantic version strings.

func (ByVersion) Len

func (vs ByVersion) Len() int

func (ByVersion) Less

func (vs ByVersion) Less(i, j int) bool

func (ByVersion) Swap

func (vs ByVersion) Swap(i, j int)

type Device

type Device struct {
	Family string
	Major  int
	Minor  int
}

Device is an Apple device

func DeconstructDevice

func DeconstructDevice(deviceName string) Device

func (Device) String

func (d Device) String() string

type DeviceID

type DeviceID struct {
	IOObjectClass           string
	IOObjectRetainCount     int
	IORegistryEntryChildren []IORegistryEntryChild
	IORegistryEntryID       int
	IORegistryEntryName     string
}

func GetDeviceID

func GetDeviceID() (*DeviceID, error)

GetDeviceID returns the ioreg IOPlatformExpertDevice of the current device

type Devices

type Devices []Device

func (Devices) Len

func (d Devices) Len() int

func (Devices) Less

func (d Devices) Less(i, j int) bool

func (Devices) Swap

func (d Devices) Swap(i, j int)

type GitDiffConfig

type GitDiffConfig struct {
	Tool  string
	Color bool
}

type HdiUtilInfo

type HdiUtilInfo struct {
	Framework string  `plist:"framework,omitempty" xml:"framework,omitempty"`
	Revision  string  `plist:"revision,omitempty" xml:"revision,omitempty"`
	Vendor    string  `plist:"vendor,omitempty" xml:"vendor,omitempty"`
	Images    []image `plist:"images,omitempty" xml:"images,omitempty"`
}

func MountInfo

func MountInfo() (*HdiUtilInfo, error)

func (HdiUtilInfo) Mount

func (i HdiUtilInfo) Mount(mount string) *image

type IORegistryEntryChild

type IORegistryEntryChild struct {
	IOBusyInterest              string
	IOConsoleSecurityInterest   string
	IOInterruptControllers      []string
	IOInterruptSpecifiers       [][]byte
	IOObjectClass               string
	IOObjectRetainCount         int
	IOPlatformSerialNumber      string
	IOPlatformSystemSleepPolicy []byte
	IOPlatformUUID              string
	IOPolledInterface           string
	IORegistryEntryID           int
	IORegistryEntryName         string
	IOServiceBusyState          int
	IOServiceBusyTime           int
	IOServiceState              int
	BoardID                     []byte `plist:"board-id,omitempty"`
	BridgeModel                 []byte `plist:"bridge-model,omitempty"`
	ClockFrequency              []byte `plist:"clock-frequency,omitempty"`
	Compatible                  []byte `plist:"compatible,omitempty"`
	Manufacturer                []byte `plist:"manufacturer,omitempty"`
	Model                       []byte `plist:"model,omitempty"`
	Name                        []byte `plist:"name,omitempty"`
	PlatformFeature             []byte `plist:"platform-feature,omitempty"`
	ProductName                 []byte `plist:"product-name,omitempty"`
	SerialNumber                []byte `plist:"serial-number,omitempty"`
	SystemType                  []byte `plist:"system-type,omitempty"`
	TargetType                  []byte `plist:"target-type,omitempty"`
	Version                     []byte `plist:"version,omitempty"`
}

func (IORegistryEntryChild) String

func (e IORegistryEntryChild) String() string

type KMUConfig

type KMUConfig struct {
	Suffix  string
	Arch    string
	KDK     string
	Name    string
	Kernel  string
	Exclude []string
}

type MachoVersion

type MachoVersion struct {
	Name    string
	Version string
}

type Pair

type Pair[T, U any] struct {
	First  T
	Second U
}

func Zip

func Zip[T, U any](ts []T, us []U) ([]Pair[T, U], error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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