Skip to content

SB2 File Format

ラ⭐ edited this page Dec 26, 2022 · 20 revisions

Layout

header
external_function_table_entry[header.function_count]
function_data_entry
code
  inst
  inst
  inst
  ...
function_local_data
function_data_entry
code
  inst
  inst
  inst
  ...
function_local_data

Parts

struct header
{
  char magic[4];               // "SB2\0"
  u32 unk_function_data_ptr;   // some unknown function
  u32 code_start_byte_offset;  // first function data entry
  u32 header_byte_count;       // end of the header (location of the function table)
  u32 external_function_count; // number of functions exported in function table
  u32 unk0;                    // usually 0
  u32 global_variable_count;   //

  // these are all usually 0
  u32 unk2;
  u32 unk3;
  u32 unk4;
  u32 unk5;
  u32 unk6;
  u32 unk7;
  u32 unk8;
  u32 unk9;
  u32 unk10;
};

struct external_function_table_entry
{
  u32 id;                        // usually aligned to 50
  u32 function_data_byte_offset; // location of the func_data_entry
};

struct function_data_entry
{
  u32 code_start_byte_offset; // start of code
  u32 name_byte_offset;       // location of the name (usually stripped)
  u32 stack_size;             // 
  u32 argument_count;         // number of arguments for this function

  // these are usually 0
  u32 unk0;
  u32 unk1;
  u32 unk2;
  u32 unk3;
  u32 unk4;
  u32 unk5;
  u32 unk6;
  u32 unk7;
  u32 unk8;
  u32 unk9; 
};

Instructions And Types

enum opcode : u32
{
  _nop        = 0,
  _push_stack = 1,
  _push_ptr   = 2,
  _push       = 3,
  _pop        = 4,
  _deref      = 5,
  _add        = 6,
  _sub        = 7,
  _mul        = 8,
  _div        = 9,
  _mod        = 10,
  _neg        = 11,
  _itof       = 12,
  _ftoi       = 13,
  _cmp        = 14,
  _ret        = 15,
  _jmp        = 16,
  _bf         = 17,
  _bt         = 18,
  _call       = 19,
  _print      = 20,
  _ext        = 21,
  _unk0       = 22,
  _yld        = 23,
  _and        = 24,
  _or         = 25,
  _not        = 26,
  _exit       = 27,
  _unk1       = 28,
  _sin        = 29,
  _cos        = 30,
  count
};

enum data_type : u32
{
  invalid,
  _int = 1,
  _flt = 2,
  _str = 3,
  _ptr = 4,
  count
};

// note: sub 40 from the arg for some reason
enum comparision_function : u32
{
  _eq = 0,
  _ne = 1,
  _lt = 2,
  _le = 3,
  _gt = 4,
  _ge = 5,
  count
};
Clone this wiki locally