sym

package module
v0.0.0-...-05222d7 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Unlicense Imports: 10 Imported by: 0

README

sym

Build Status GoDoc

Parse Playstation 1 symbol files (*.SYM).

Installation

git clone https://github.com/sanctuary/sym
cd sym
go install -v ./cmd/sym_dump

Usage

The default output of sym_dump is in Psy-Q format and is identical to the DUMPSYM.EXE tool of the Psy-Q SDK.

sym_dump DIABPSX.SYM
# Output:
#
# Header : MND version 1
# Target unit 0
# 000008: $800b031c overlay length $000009e4 id $4
# 000015: $800b031c overlay length $00000004 id $5
# 000022: $80139bf8 overlay length $00023234 id $b
# 00002f: $80139bf8 overlay length $00029dcc id $c
# 00003c: $80139bf8 overlay length $0002a228 id $d
# 000049: $80139bf8 overlay length $0001ec70 id $e
# 000056: $00000000 94 Def class TPDEF type UCHAR size 0 name u_char

Documentation

Overview

Package sym provides access to Playstation 1 symbol files (*.SYM).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base uint8

Base is a base type.

const (
	BaseNull   Base = 0x0 // NULL
	BaseVoid   Base = 0x1 // VOID
	BaseChar   Base = 0x2 // CHAR
	BaseShort  Base = 0x3 // SHORT
	BaseInt    Base = 0x4 // INT
	BaseLong   Base = 0x5 // LONG
	BaseFloat  Base = 0x6 // FLOAT
	BaseDouble Base = 0x7 // DOUBLE
	BaseStruct Base = 0x8 // STRUCT
	BaseUnion  Base = 0x9 // UNION
	BaseEnum   Base = 0xA // ENUM
	// Member of enum.
	BaseMOE    Base = 0xB // MOE
	BaseUChar  Base = 0xC // UCHAR
	BaseUShort Base = 0xD // USHORT
	BaseUInt   Base = 0xE // UINT
	BaseULong  Base = 0xF // ULONG
)

Base types.

func (Base) String

func (i Base) String() string

type BlockEnd

type BlockEnd struct {
	// Line number.
	Line uint32 `struc:"uint32,little"`
}

A BlockEnd symbol specifies the end of a block.

Value of the symbol header specifies the associated address.

func (*BlockEnd) BodySize

func (body *BlockEnd) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*BlockEnd) String

func (body *BlockEnd) String() string

String returns the string representation of the block end symbol.

type BlockStart

type BlockStart struct {
	// Line number.
	Line uint32 `struc:"uint32,little"`
}

A BlockStart symbol specifies the start of a block.

Value of the symbol header specifies the associated address.

func (*BlockStart) BodySize

func (body *BlockStart) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*BlockStart) String

func (body *BlockStart) String() string

String returns the string representation of the block start symbol.

type Class

type Class uint16

Class specifies the class of a definition.

const (
	// Storage class auto.
	ClassAUTO Class = 0x0001 // AUTO
	// Storage class extern.
	ClassEXT Class = 0x0002 // EXT
	// Storage class static.
	ClassSTAT Class = 0x0003 // STAT
	// Storage class register.
	ClassREG Class = 0x0004 // REG
	// TODO: Figure out when LABEL is used.
	ClassLABEL Class = 0x0006 // LABEL
	// Member of struct.
	ClassMOS Class = 0x0008 // MOS
	// Function parameter passed on stack.
	ClassARG Class = 0x0009 // ARG
	// Struct tag.
	ClassSTRTAG Class = 0x000A // STRTAG
	// Member of union.
	ClassMOU Class = 0x000B // MOU
	// Union tag.
	ClassUNTAG Class = 0x000C // UNTAG
	// Storage class typedef.
	ClassTPDEF Class = 0x000D // TPDEF
	// Enum tag.
	ClassENTAG Class = 0x000F // ENTAG
	// Member of enum.
	ClassMOE Class = 0x0010 // MOE
	// Function parameter passed in register.
	ClassREGPARM Class = 0x0011 // REGPARM
	// TODO: Figure out when FIELD is used.
	ClassFIELD Class = 0x0012 // FIELD
	// End of symbol.
	ClassEOS Class = 0x0066 // EOS
)

Definition classes.

func (Class) String

func (i Class) String() string

type Def

type Def struct {
	// Definition class.
	Class Class `struc:"uint16,little"`
	// Definition type.
	Type Type `struc:"uint16,little"`
	// Definition size.
	Size uint32 `struc:"uint32,little"`
	// Name length.
	NameLen uint8 `struc:"uint8,sizeof=Name"`
	// Definition name,
	Name string
}

A Def symbol specifies the class, type, size and name of a definition.

Value of the symbol header specifies the associated address.

func (*Def) BodySize

func (body *Def) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*Def) String

func (body *Def) String() string

String returns the string representation of the definition symbol.

type Def2

type Def2 struct {
	// Definition class.
	Class Class `struc:"uint16,little"`
	// Definition type.
	Type Type `struc:"uint16,little"`
	// Definition size.
	Size uint32 `struc:"uint32,little"`
	// Dimensions length.
	DimsLen uint16 `struc:"uint16,little,sizeof=Dims"`
	// Dimensions.
	Dims []uint32 `struc:"[]uint32,little"`
	// Tag length.
	TagLen uint8 `struc:"uint8,sizeof=Tag"`
	// Definition tag,
	Tag string
	// Name length.
	NameLen uint8 `struc:"uint8,sizeof=Name"`
	// Definition name,
	Name string
}

A Def2 symbol specifies the class, type, size, dimensions, tag and name of a definition.

Value of the symbol header specifies the associated address.

func (*Def2) BodySize

func (body *Def2) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*Def2) String

func (body *Def2) String() string

String returns the string representation of the definition symbol.

type EndSLD

type EndSLD struct {
}

An EndSLD symbol indicates the end of a line number specifier.

Value of the symbol header specifies the associated address.

func (*EndSLD) BodySize

func (body *EndSLD) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*EndSLD) String

func (body *EndSLD) String() string

String returns the string representation of the end of line number symbol.

type File

type File struct {
	// File header.
	Hdr *FileHeader
	// Symbols.
	Syms []*Symbol
}

A File is PS1 symbol file.

func Parse

func Parse(r io.Reader) (*File, error)

Parse parses the given PS1 symbol file, reading from r.

func ParseBytes

func ParseBytes(b []byte) (*File, error)

ParseBytes parses the given PS1 symbol file, reading from b.

func ParseFile

func ParseFile(path string) (*File, error)

ParseFile parses the given PS1 symbol file.

func (*File) String

func (f *File) String() string

String returns the string representation of the symbol file.

type FileHeader

type FileHeader struct {
	// File signature; MND.
	Signature [3]byte `struc:"[3]byte"`
	// File format version.
	Version uint8 `struc:"uint8"`
	// Target unit.
	TargetUnit uint32 `struc:"uint32,little"`
}

A FileHeader is a PS1 symbol file header.

func (*FileHeader) String

func (hdr *FileHeader) String() string

String returns the string representation of the symbol file header.

type FuncEnd

type FuncEnd struct {
	// Line number.
	Line uint32 `struc:"uint32,little"`
}

A FuncEnd symbol specifies the end of a function.

Value of the symbol header specifies the associated address.

func (*FuncEnd) BodySize

func (body *FuncEnd) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*FuncEnd) String

func (body *FuncEnd) String() string

String returns the string representation of the function end symbol.

type FuncStart

type FuncStart struct {
	// Frame pointer register.
	FP uint16 `struc:"uint16,little"`
	// Function size.
	FSize uint32 `struc:"uint32,little"`
	// Return address register.
	RetReg uint16 `struc:"uint16,little"`
	// Mask.
	Mask uint32 `struc:"uint32,little"`
	// Mask offset.
	MaskOffset int32 `struc:"int32,little"`
	// Line number.
	Line uint32 `struc:"uint32,little"`
	// Path length.
	PathLen uint8 `struc:"uint8,sizeof=Path"`
	// Source file.
	Path string
	// Name length.
	NameLen uint8 `struc:"uint8,sizeof=Name"`
	// Symbol name.
	Name string
}

A FuncStart symbol specifies the start of a function.

Value of the symbol header specifies the associated address.

func (*FuncStart) BodySize

func (body *FuncStart) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*FuncStart) String

func (body *FuncStart) String() string

String returns the string representation of the function start symbol.

type IncSLD

type IncSLD struct {
}

An IncSLD symbol increments the current line number.

Value of the symbol header specifies the associated address.

func (*IncSLD) BodySize

func (body *IncSLD) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*IncSLD) String

func (body *IncSLD) String() string

String returns the string representation of the line number increment symbol.

type IncSLDByte

type IncSLDByte struct {
	Inc uint8 `struc:"uint8"`
}

An IncSLDByte symbol specifies the increment of the current line number.

Value of the symbol header specifies the associated address.

func (*IncSLDByte) BodySize

func (body *IncSLDByte) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*IncSLDByte) String

func (body *IncSLDByte) String() string

String returns the string representation of the line number increment symbol.

type IncSLDWord

type IncSLDWord struct {
	Inc uint16 `struc:"uint16,little"`
}

An IncSLDWord symbol specifies the increment of the current line number.

Value of the symbol header specifies the associated address.

func (*IncSLDWord) BodySize

func (body *IncSLDWord) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*IncSLDWord) String

func (body *IncSLDWord) String() string

String returns the string representation of the line number increment symbol.

type Kind

type Kind uint8

Kind specifies the kind of a symbol.

const (
	KindName1      Kind = 0x01 // 1
	KindName2      Kind = 0x02 // 2
	KindName5      Kind = 0x05 // 5
	KindName6      Kind = 0x06 // 6
	KindIncSLD     Kind = 0x80 // 80
	KindIncSLDByte Kind = 0x82 // 82
	KindIncSLDWord Kind = 0x84 // 84
	KindSetSLD     Kind = 0x86 // 86
	KindSetSLD2    Kind = 0x88 // 88
	KindEndSLD     Kind = 0x8A // 8a
	KindFuncStart  Kind = 0x8C // 8c
	KindFuncEnd    Kind = 0x8E // 8e
	KindBlockStart Kind = 0x90 // 90
	KindBlockEnd   Kind = 0x92 // 92
	KindDef        Kind = 0x94 // 94
	KindDef2       Kind = 0x96 // 96
	KindOverlay    Kind = 0x98 // overlay
	KindSetOverlay Kind = 0x9A // set overlay
)

Symbol kinds.

func (Kind) String

func (i Kind) String() string

type Mod

type Mod uint8

Mod is a type modifier.

const (
	ModPointer  Mod = 0x1 // PTR
	ModFunction Mod = 0x2 // FCN
	ModArray    Mod = 0x3 // ARY
)

Type modifiers.

func (Mod) String

func (i Mod) String() string

type Name1

type Name1 struct {
	// Name length.
	NameLen uint8 `struc:"uint8,sizeof=Name"`
	// Symbol name,
	Name string
}

A Name1 symbol specifies the name of a symbol.

Value of the symbol header specifies the associated address.

func (*Name1) BodySize

func (body *Name1) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*Name1) String

func (body *Name1) String() string

String returns the string representation of the name symbol.

type Name2

type Name2 struct {
	// Name length.
	NameLen uint8 `struc:"uint8,sizeof=Name"`
	// Symbol name,
	Name string
}

A Name2 symbol specifies the name of a symbol.

Value of the symbol header specifies the associated address.

func (*Name2) BodySize

func (body *Name2) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*Name2) String

func (body *Name2) String() string

String returns the string representation of the name symbol.

type Name5

type Name5 struct {
	// Name length.
	NameLen uint8 `struc:"uint8,sizeof=Name"`
	// Symbol name,
	Name string
}

A Name5 symbol specifies the name of a symbol.

Value of the symbol header specifies the associated address.

func (*Name5) BodySize

func (body *Name5) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*Name5) String

func (body *Name5) String() string

String returns the string representation of the name symbol.

type Name6

type Name6 struct {
	// Name length.
	NameLen uint8 `struc:"uint8,sizeof=Name"`
	// Symbol name,
	Name string
}

A Name6 symbol specifies the name of a symbol.

Value of the symbol header specifies the associated address.

func (*Name6) BodySize

func (body *Name6) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*Name6) String

func (body *Name6) String() string

String returns the string representation of the name symbol.

type Overlay

type Overlay struct {
	// Overlay length in bytes.
	Length uint32 `struc:"uint32,little"`
	// Overlay ID.
	ID uint32 `struc:"uint32,little"`
}

An Overlay symbol specifies the length and id of a file overlay (e.g. a shared library).

Value of the symbol header specifies the base address at which the overlay is loaded.

func (*Overlay) BodySize

func (body *Overlay) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*Overlay) String

func (body *Overlay) String() string

String returns the string representation of the overlay symbol.

type SetOverlay

type SetOverlay struct {
}

A SetOverlay specifies the active overlay.

Value of the symbol header specifies the active overlay ID.

func (*SetOverlay) BodySize

func (body *SetOverlay) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*SetOverlay) String

func (body *SetOverlay) String() string

String returns the string representation of the set overlay symbol.

type SetSLD

type SetSLD struct {
	// Line number.
	Line uint32 `struc:"uint32,little"`
}

A SetSLD symbol specifies the current line number.

Value of the symbol header specifies the associated address.

func (*SetSLD) BodySize

func (body *SetSLD) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*SetSLD) String

func (body *SetSLD) String() string

String returns the string representation of the set line number symbol.

type SetSLD2

type SetSLD2 struct {
	// Line number.
	Line uint32 `struc:"uint32,little"`
	// Path length.
	PathLen uint8 `struc:"uint8,sizeof=Path"`
	// Source file,
	Path string
}

A SetSLD2 symbol specifies the current line number and source file.

Value of the symbol header specifies the associated address.

func (*SetSLD2) BodySize

func (body *SetSLD2) BodySize() int

BodySize returns the size of the symbol body in bytes.

func (*SetSLD2) String

func (body *SetSLD2) String() string

String returns the string representation of the set line number symbol.

type Symbol

type Symbol struct {
	// Symbol header.
	Hdr *SymbolHeader
	// Symbol body.
	Body SymbolBody
}

A Symbol is a PS1 symbol.

func (*Symbol) Size

func (sym *Symbol) Size() int

Size returns the size of the symbol in bytes.

func (*Symbol) String

func (sym *Symbol) String() string

String returns the string representation of the symbol.

type SymbolBody

type SymbolBody interface {
	fmt.Stringer
	// BodySize returns the size of the symbol body in bytes.
	BodySize() int
}

SymbolBody is the sum-type of all symbol bodies.

type SymbolHeader

type SymbolHeader struct {
	// Address or value of symbol.
	Value uint32 `struc:"uint32,little"`
	// Symbol kind; specifies type of symbol body.
	Kind Kind `struc:"uint8"`
}

A SymbolHeader is a PS1 symbol header.

func (*SymbolHeader) String

func (hdr *SymbolHeader) String() string

String returns the string representation of the symbol header.

type Type

type Type uint16

Type specifies the type of a definition.

A type is made up of a 4-bit basic type specifier, and a set of 2-bit type modifiers.

Basic type                                            xxxx
   Modifier                                        xx
      Modifier                                  xx
         Modifier                            xx
            Modifier                      xx
               Modifier                xx
                  Modifier          xx

Example.

int * f_0064() {}

Interpretation.

int                                                   0100
   function                                        10
      pointer                                   01
                                             00
                                          00
                                       00
                                    00

                             0x64 = 00 00 00 00 01 10 0100

Example.

int (*v_0094)();

Interpretation.

int                                                   0100
   pointer                                         01
      function                                  10
                                             00
                                          00
                                       00
                                    00

                             0x94 = 00 00 00 00 10 01 0100

func (Type) Base

func (t Type) Base() Base

Base returns the base type of the type.

func (Type) Mods

func (t Type) Mods() []Mod

Mods returns the modifiers of the type.

func (Type) String

func (t Type) String() string

String returns a string representation of the type.

Directories

Path Synopsis
cmd
sym_dump
The sym_dump tool converts Playstation 1 SYM files to C headers (*.sym -> *.h) and scripts for importing symbol information into IDA.
The sym_dump tool converts Playstation 1 SYM files to C headers (*.sym -> *.h) and scripts for importing symbol information into IDA.
Package csym translates Playstation 1 symbol information to C declarations.
Package csym translates Playstation 1 symbol information to C declarations.
c
Package c provides an AST for a subset of C.
Package c provides an AST for a subset of C.

Jump to

Keyboard shortcuts

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