fileservice

package
v1.0.184 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package fileservice provides functions to pull and push files on iOS 17+ devices using RemoteXPC.

Index

Examples

Constants

View Source
const (
	// ControlServiceName is the RemoteXPC service name for file operations control
	ControlServiceName = "com.apple.coredevice.fileservice.control"
	// DataServiceName is the RemoteXPC service name for file data transfer
	DataServiceName = "com.apple.coredevice.fileservice.data"

	// MaxFileSize is the maximum file size we'll process (1GB) to prevent OOM
	MaxFileSize = 1024 * 1024 * 1024
	// MaxInlineDataSize is the maximum file size that can be sent inline in XPC message
	// Files larger than this must use the data service
	MaxInlineDataSize = 500 // bytes - based on Ghidra code checking for 500 bytes
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

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

Connection represents a connection to the file service on an iOS 17+ device. It manages file operations like listing, pulling, and pushing files. Note: Connection is not safe for concurrent use. Each goroutine should have its own Connection.

func New

func New(device ios.DeviceEntry, domain Domain, identifier string) (*Connection, error)

New creates a new connection to the file service on the device for iOS 17+. The domain parameter specifies which file system domain to access. The identifier parameter is typically an app bundle ID (e.g., "com.example.app") for app domains. For system domains like DomainSystemCrashLogs, the identifier can be empty.

func (*Connection) Close

func (c *Connection) Close() error

Close closes the connection to the file service

func (*Connection) ListDirectory

func (c *Connection) ListDirectory(path string) ([]string, error)

ListDirectory returns a list of file names in the specified directory path. The path is relative to the domain root.

Example

Example usage documentation

package main

import (
	"fmt"

	"github.com/danielpaulus/go-ios/ios"
	"github.com/danielpaulus/go-ios/ios/fileservice"
)

func main() {
	device, _ := ios.GetDevice("")

	// Create a connection to an app's Documents directory
	conn, _ := fileservice.New(device, fileservice.DomainAppDataContainer, "com.example.myapp")
	defer conn.Close()

	// List files in the root directory
	files, _ := conn.ListDirectory(".")
	for _, file := range files {
		fmt.Println(file)
	}
}

func (*Connection) PullFile

func (c *Connection) PullFile(path string, writer io.Writer) error

PullFile downloads a file from the device by streaming to an io.Writer. This is memory-efficient as it streams the file in chunks rather than loading it entirely into memory. The path is relative to the domain root.

Example

Example of pulling a file

package main

import (
	"os"
	"path/filepath"

	"github.com/danielpaulus/go-ios/ios"
	"github.com/danielpaulus/go-ios/ios/fileservice"
)

func main() {
	device, _ := ios.GetDevice("")

	conn, _ := fileservice.New(device, fileservice.DomainAppDataContainer, "com.example.myapp")
	defer conn.Close()

	// Create output file for streaming
	outputFile, _ := os.Create(filepath.Join(".", "myfile.txt"))
	defer outputFile.Close()

	// Download file (streaming)
	_ = conn.PullFile("Documents/myfile.txt", outputFile)
}

func (*Connection) PushFile

func (c *Connection) PushFile(path string, reader io.Reader, fileSize int64, permissions int64, uid, gid int64) error

PushFile uploads a file to the device by streaming from an io.Reader. This is memory-efficient as it streams the file in chunks rather than loading it entirely into memory. The path is relative to the domain root. permissions should be in octal format (e.g., 0o644 or 420 in decimal)

Example

Example of pushing a file

package main

import (
	"os"

	"github.com/danielpaulus/go-ios/ios"
	"github.com/danielpaulus/go-ios/ios/fileservice"
)

func main() {
	device, _ := ios.GetDevice("")

	conn, _ := fileservice.New(device, fileservice.DomainAppDataContainer, "com.example.myapp")
	defer conn.Close()

	// Open local file for streaming
	file, _ := os.Open("local_file.txt")
	defer file.Close()

	// Get file info for size and permissions
	fileInfo, _ := file.Stat()

	// Upload to device (streaming, preserves permissions)
	_ = conn.PushFile("Documents/uploaded.txt", file, fileInfo.Size(), int64(fileInfo.Mode().Perm()), 501, 501)
}

type Domain

type Domain uint64

Domain represents a file system domain on the iOS device

const (
	// DomainAppDataContainer is the app's Documents directory
	DomainAppDataContainer Domain = 1
	// DomainAppGroupDataContainer is the app group shared container
	DomainAppGroupDataContainer Domain = 2
	// DomainTemporary is the temporary directory
	DomainTemporary Domain = 3
	// DomainRootStaging is the root staging directory (no idea what that would be)
	DomainRootStaging Domain = 4
	// DomainSystemCrashLogs is the system crash logs directory
	DomainSystemCrashLogs Domain = 5
)

Jump to

Keyboard shortcuts

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