tbcload

package module
v0.0.0-...-b997fde Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 12 Imported by: 1

README

TBC (Tcl ByteCode) decoder

The .tbc file is generated by Tcl Pro. This repo try to add comments on .tbc file and disassemble .tbc file for human reading.
test .tbc file can be found here

Install

go get github.com/corbamico/tbcload/tbcload

Usage

Usage:
  tbcload [command]

Available Commands:
  decode      encode a string into ascii85(re-map), which tbc file used
  decompile   disassemble a .tbc file, which can be on disk/url
  encode      A brief description of your command

Example:
    tbcload encode 123456
    tbcload encode  --hex "00010203"
    tbcload decompile test.tbc  #disassemble a file named test.tbc
    tbcload decompile --detail test.tbc
    tbcload decompile http://127.0.0.1/test.tcl #disassemble from a url

    example url, can be found as https://github.com/ActiveState/teapot/raw/master/lib/tbcload/tests/tbc10/proc.tbc

Code Example

func ExampleEncode() {
    src := []byte("proc")
    dst := make([]byte, 150)
    length := Encode(dst, src)
    fmt.Printf("%s", dst[:length])
    // Output:
    // ,CHr@
}

func ExampleDecode() {
    r, _ := os.Open(uri)
    p := tbcload.NewParser(r, os.Stdout)
    p.Parse()
}

Reference

License

  • MIT

  • ActiveState/teapot/cmpWrite.c BSD-3 license Copyright (c) 2017,ActiveState Software All rights reserved.

Documentation

Index

Examples

Constants

View Source
const (
	OPERAND_NONE    byte = iota
	OPERAND_INT1         /* One byte signed integer. */
	OPERAND_INT4         /* Four byte signed integer. */
	OPERAND_UINT1        /* One byte unsigned integer. */
	OPERAND_UINT4        /* Four byte unsigned integer. */
	OPERAND_IDX4         /* Four byte signed index (actually an * integer, but displayed differently.) */
	OPERAND_LVT1         /* One byte unsigned index into the local * variable table. */
	OPERAND_LVT4         /* Four byte unsigned index into the local * variable table. */
	OPERAND_AUX4         /* Four byte unsigned index into the aux data * table. */
	OPERAND_OFFSET1      /* One byte signed jump offset. */
	OPERAND_OFFSET4      /* Four byte signed jump offset. */
	OPERAND_LIT1         /* One byte unsigned index into table of * literals. */
	OPERAND_LIT4         /* Four byte unsigned index into table of * literals. */
	OPERAND_SCLS1        /* Index into tclStringClassTable. */
)
View Source
const INT_MIN = 0x8000

Variables

View Source
var ErrDecodeErr = errors.New("error decoding from bytes")

ErrDecodeErr mean error while decoding from bytes

View Source
var ErrUnsupoortedObjectType = errors.New("object type is not supported")

ErrUnsupoortedObjectType means object type is not correct

Functions

func Decode

func Decode(dst, src []byte) (ndst int)

Decode encodes src into at most len(src) bytes of dst, returning the actual number of bytes written.

The encoding handles 5-byte chunks, using a special encoding for the last fragment, so Encode is not appropriate for use on individual blocks of a large data stream. Use NewEncoder() instead.

Example
src := []byte("4;,>!?.EH&ih-(!e2xi6zyiE<!22>:v35>:v22Ppv2j:U!*|yTv0#>6#5cSs!)'!")
//src := []byte("z")
dst := make([]byte, 280)
length := Decode(dst, src)
fmt.Printf("%s", string(dst[:length]))
Output:

,CHr@

func Encode

func Encode(dst, src []byte) int

Encode encodes src into at most MaxEncodedLen(len(src)) bytes of dst, returning the actual number of bytes written.

The encoding handles 4-byte chunks, using a special encoding for the last fragment, so Encode is not appropriate for use on individual blocks of a large data stream. Use NewEncoder() instead.

Example
//src := []byte("testing aliases for non-existent targets")
src := []byte{0, 0, 0, 0}
dst := make([]byte, 280)
length := Encode(dst, src)
fmt.Printf("%s", dst[:length])
Output:

,CHr@

Types

type Decoder

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

Decoder wrap decode for stream reader

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder return Decoder which wrap Decode for stream reader

func (*Decoder) Read

func (d *Decoder) Read(p []byte) (nRead int, err error)

func (*Decoder) ReadRaw

func (d *Decoder) ReadRaw(p []byte) (nRead int, err error)

ReadRaw only read from wrapped io without Decoding

type InstructionDesc

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

type Parser

type Parser struct {
	Detail bool //true: disassemble bytecode
	// contains filtered or unexported fields
}

Parser read tbc file and write 'dissemble' to w

func NewParser

func NewParser(r io.Reader, w io.Writer) *Parser

NewParser create Parser

func (*Parser) Parse

func (p *Parser) Parse() (err error)

Parse from io.Reader

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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