Module binary

read and write (little endian) binary.

This is apart of the LEEF-filesystem module.

expected function inputs

read_byte () read_byte is a param name which refers to a function which reads the next byte- returning a whole number between 0-255.
write_byte () write_byte is similar to read_byte, however it is given an input and expected to write it to the file.

functions

read_single (function) read an IEEE 754 single precision (32-bit) floating point number
read_double (function) read an IEEE 754 double-precision (64-bit) floating point number
read_uint (function, int) read an unsigned integer of any given length
read_uint (function, int) read a signed integer of any given length
write_uint (write_byte, unit, bytes) writing binary

misc binary helpers

fround (number) "returns nearest 32-bit single precision float representation of a number" (or something)


expected function inputs

functions will expect either a read_byte or write_byte function as inputs
read_byte ()

read_byte is a param name which refers to a function which reads the next byte- returning a whole number between 0-255.

function byte()
    left = left - 1
    return assert(file_handle:read(1):byte())
    --reads the next chracter, and converts it to a "numerical code" using string.byte()
    --it's important that this function moves forward in the file stream (as :read(1) does)
end

Returns:

    a bytecode (an int between 0 and 255.)
write_byte ()
write_byte is similar to read_byte, however it is given an input and expected to write it to the file. (example needed)

functions

read_single (function)
read an IEEE 754 single precision (32-bit) floating point number

Parameters:

Returns:

    number
read_double (function)
read an IEEE 754 double-precision (64-bit) floating point number

Parameters:

Returns:

    number
read_uint (function, int)
read an unsigned integer of any given length

Parameters:

  • function read_byte
  • int length in bytes of unsigned integer

Returns:

    unit number
read_uint (function, int)
read a signed integer of any given length

Parameters:

  • function read_byte
  • int length in bytes of integer

Returns:

    int number
write_uint (write_byte, unit, bytes)
writing binary

Parameters:

  • write_byte write_byte
  • unit int unit to write
  • bytes int number of bytes to right

misc binary helpers

fround (number)
"returns nearest 32-bit single precision float representation of a number" (or something)

Parameters:

  • number

Returns:

    nearest 32-bit single precision float representation of a number
generated by LDoc 1.5.0 Last updated 2025-01-20 00:28:08