debugger

package
v0.0.0-...-199b158 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: Apache-2.0 Imports: 10 Imported by: 13

Documentation

Index

Constants

View Source
const (
	Calling_Default = iota
	Calling_Cdecl
	Calling_Stdcall
	Calling_Fastcall
	Calling_ATPCS = Calling_Fastcall
)

Variables

View Source
var (
	ErrContextInvalid     = errors.New("context invalid")
	ErrModuleNotFound     = errors.New("module not found")
	ErrSymbolNotFound     = errors.New("symbol not found")
	ErrHookCallbackType   = errors.New("hook callback type exception")
	ErrTaskInvalid        = errors.New("task invalid")
	ErrCallingUnsupported = errors.New("calling unsupported")
	ErrUnhandledException = errors.New("unhandled exception")
	ErrArgumentInvalid    = errors.New("argument invalid")
	ErrEmulatorStop       = errors.New("emulator stop")
	ErrAddressInvalid     = errors.New("address invalid")
	ErrNotImplemented     = errors.New("not implemented")
)

Functions

func Align

func Align[I constraints.Integer](a, b I) I

func Register

func Register(arch emulator.Arch, ctor DbgCtor) bool

Types

type Args

type Args interface {
	Extract(...any) error
}

type Calling

type Calling int

type CodeCallback

type CodeCallback = func(ctx Context, addr, size uint64, data any)

type Context

type Context interface {
	Debugger() Debugger
	PC() emulator.Reg
	SP() emulator.Reg
	TaskID() int
	ParentID() int
	TaskFork() (Task, error)
	RegisterContext
	GetArgs(calling Calling) (Args, error)
	ArgExtract(calling Calling, args ...any) error
	ArgWrite(calling Calling, args ...any) error
	RetExtract(val any) error
	RetWrite(val any) error
	Return() error
	Goto(addr uint64) error
	MemoryContext
	StorageContext
}

type ControlCallback

type ControlCallback = func(ctx Context, data any)

type ControlHandler

type ControlHandler interface {
	io.Closer
	Addr() uint64
}

type DbgCtor

type DbgCtor func(emulator.Emulator) (Debugger, error)

type DebuggerInfo

type DebuggerInfo interface {
	Emulator() emulator.Emulator
	Arch() emulator.Arch
	PointerSize() uint64
	StackSize() uint64
	StackAlign() uint64
}

type DefaultFileHandler

type DefaultFileHandler struct {
}

func (DefaultFileHandler) Mkdir

func (DefaultFileHandler) Mkdir(name string, perm fs.FileMode) (filesystem.DirFS, error)

func (DefaultFileHandler) NewSocket

func (DefaultFileHandler) NewSocket(network socket.Network) (socket.Socket, error)

func (DefaultFileHandler) OpenFile

func (DefaultFileHandler) ReadDir

func (DefaultFileHandler) ReadDir(name string) ([]fs.DirEntry, error)
func (DefaultFileHandler) Readlink(name string) (string, error)

func (DefaultFileHandler) Stat

func (DefaultFileHandler) Stat(name string) (fs.FileInfo, error)

type FileHandler

type FileHandler interface {
	OpenFile(name string, flag filesystem.FileFlag, perm fs.FileMode) (filesystem.File, error)
	Stat(name string) (fs.FileInfo, error)
	ReadDir(name string) ([]fs.DirEntry, error)
	Mkdir(name string, perm fs.FileMode) (filesystem.DirFS, error)
	Readlink(name string) (string, error)
	NewSocket(network socket.Network) (socket.Socket, error)
}

type FileManager

type FileManager interface {
	AddFileHandler(handler FileHandler)
	RemoveFileHandler(handler FileHandler)
	CreateFileDescriptor(file filesystem.File) int
	CloseFileDescriptor(fd int) (filesystem.File, error)
	GetFile(fd int) (filesystem.File, error)
	DupFile(fd int) (int, error)
	Dup2File(oldfd, newfd int) error
	GetFS() filesystem.FS
	OpenFile(name string, flag filesystem.FileFlag, perm fs.FileMode) (filesystem.File, error)
	Stat(name string) (fs.FileInfo, error)
	ReadDir(name string) ([]fs.DirEntry, error)
	Mkdir(name string, perm fs.FileMode) (filesystem.DirFS, error)
	Readlink(name string) (string, error)
	NewSocket(network socket.Network) (socket.Socket, error)
}

type HookHandler

type HookHandler interface {
	io.Closer
	Type() emulator.HookType
}

type HookManger

type HookManger interface {
	AddHook(typ emulator.HookType, callback any, data any, begin, end uint64) (HookHandler, error)
	AddControl(callback ControlCallback, data any) (ControlHandler, error)
}

type HookResult

type HookResult int
const (
	HookResult_Done HookResult = -1
	HookResult_Next HookResult = 0
)

type InterruptCallback

type InterruptCallback = func(ctx Context, intno uint64, data any) HookResult

type InterruptException

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

func (*InterruptException) Context

func (e *InterruptException) Context() Context

func (*InterruptException) Error

func (e *InterruptException) Error() string

func (*InterruptException) Number

func (e *InterruptException) Number() uint64

func (*InterruptException) String

func (e *InterruptException) String() string

type InvalidCallback

type InvalidCallback = func(ctx Context, data any) HookResult

type InvalidInstructionException

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

func (*InvalidInstructionException) Context

func (e *InvalidInstructionException) Context() Context

func (*InvalidInstructionException) Error

func (*InvalidInstructionException) String

func (e *InvalidInstructionException) String() string

type InvalidMemoryException

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

func (*InvalidMemoryException) Address

func (e *InvalidMemoryException) Address() uint64

func (*InvalidMemoryException) Context

func (e *InvalidMemoryException) Context() Context

func (*InvalidMemoryException) Error

func (e *InvalidMemoryException) Error() string

func (*InvalidMemoryException) Size

func (e *InvalidMemoryException) Size() uint64

func (*InvalidMemoryException) String

func (e *InvalidMemoryException) String() string

func (*InvalidMemoryException) Type

func (*InvalidMemoryException) Value

func (e *InvalidMemoryException) Value() uint64

type MemoryCallback

type MemoryCallback = func(ctx Context, typ emulator.HookType, addr, size, value uint64, data any) HookResult

type MemoryContext

type MemoryContext interface {
	ToPointer(addr uint64) emulator.Pointer
}

type MemoryManager

type MemoryManager interface {
	MemMap(addr, size uint64, prot emulator.MemProt) (emulator.MemRegion, error)
	MemUnmap(addr uint64, size uint64) error
	MemProtect(addr, size uint64, prot emulator.MemProt) error
	MapAlloc(size uint64, prot emulator.MemProt) (emulator.MemRegion, error)
	MapFree(addr uint64, size uint64) error
	MemAlloc(size uint64) (uint64, error)
	MemFree(addr uint64) error
	MemSize(addr uint64) uint64
	ToPointer(addr uint64) emulator.Pointer
	MemImport(val any) ([]uint64, error)
	MemWrite(addr uint64, val any) ([]uint64, error)
	MemExtract(addr uint64, val any) error
	MemBind(p unsafe.Pointer, size uint64) (uint64, error)
	MemUnbind(addr uint64) error
}

type Module

type Module interface {
	io.Closer
	Name() string
	Region() (uint64, uint64)
	BaseAddr() uint64
	EntryAddr() uint64
	Init(ctx context.Context) error
	FindSymbol(name string) (uint64, error)
}
var InternalModule Module = new(module)

type ModuleManager

type ModuleManager interface {
	Load(module Module)
	Unload(module Module)
	FindModule(name string) (Module, error)
	FindModuleByAddr(addr uint64) (Module, error)
	FindSymbol(name string) (Module, uint64, error)
	GetModule(addr uint64) Module
}

type PanicException

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

func (*PanicException) Context

func (e *PanicException) Context() Context

func (*PanicException) Error

func (e *PanicException) Error() string

func (*PanicException) Panic

func (e *PanicException) Panic() any

func (*PanicException) String

func (e *PanicException) String() string

type RegisterContext

type RegisterContext interface {
	StackAlloc(size uint64) (emulator.Pointer, error)
	StackFree(size uint64) error
	emulator.RegisterContext
}

type SimulateException

type SimulateException interface {
	error
	Context() Context
}

func NewInterruptException

func NewInterruptException(ctx Context, intno uint64) SimulateException

func NewInvalidInstructionException

func NewInvalidInstructionException(ctx Context) SimulateException

func NewInvalidMemoryException

func NewInvalidMemoryException(ctx Context, typ emulator.HookType, addr, size, value uint64) SimulateException

func NewPanicException

func NewPanicException(ctx Context, v any, stack []byte) SimulateException

type StorageContext

type StorageContext interface {
	LocalStore(key, val any)
	LocalLoad(key any) (any, bool)
	LocalDelete(key any)
}

type Symbol

type Symbol struct {
	Name  string
	Value uint64
}

type SymbolIter

type SymbolIter interface {
	Symbols(yield func(Symbol) bool)
}

type Task

type Task interface {
	io.Closer
	ID() int
	ParentID() int
	Status() TaskStatus
	Context() Context
	Run() error
	SyncRun() error
	Done() <-chan struct{}
	Err() error
	CancelCause(err error)
	Fork() (Task, error)
}

type TaskManager

type TaskManager interface {
	GetMainTask(ctx context.Context) (Task, error)
	CreateTask(ctx context.Context) (Task, error)
	CallTaskOf(task Task, addr uint64) error
}

type TaskStatus

type TaskStatus int
const (
	TaskStatus_Pending TaskStatus = iota
	TaskStatus_Running
	TaskStatus_Done
	TaskStatus_Close
)

func (TaskStatus) Error

func (s TaskStatus) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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