actf 0.0.1
An acute CTF reader
Loading...
Searching...
No Matches
/home/adwe/code/actf/fld.h File Reference

Field related methods. More...

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "fld_cls.h"
#include "types.h"

Go to the source code of this file.

Enumerations

enum  actf_fld_type {
  ACTF_FLD_TYPE_NIL , ACTF_FLD_TYPE_BOOL , ACTF_FLD_TYPE_SINT , ACTF_FLD_TYPE_UINT ,
  ACTF_FLD_TYPE_BIT_MAP , ACTF_FLD_TYPE_REAL , ACTF_FLD_TYPE_STR , ACTF_FLD_TYPE_BLOB ,
  ACTF_FLD_TYPE_ARR , ACTF_FLD_TYPE_STRUCT
}
 Field types.

Functions

const actf_fld_clsactf_fld_fld_cls (const actf_fld *fld)
 Get the class of a field.
enum actf_fld_type actf_fld_type (const actf_fld *fld)
 Get the type of a field.
const char * actf_fld_type_name (enum actf_fld_type type)
 Get the name of a type.
bool actf_fld_bool (const actf_fld *fld)
 Get a bool representation of a field.
uint64_t actf_fld_uint64 (const actf_fld *fld)
 Get a uint64 representation of the field.
int64_t actf_fld_int64 (const actf_fld *fld)
 Get an int64 representation of the field.
float actf_fld_float (const actf_fld *fld)
 Get a float representation of the field.
double actf_fld_double (const actf_fld *fld)
 Get a double representation of the field.
const char * actf_fld_str_raw (const actf_fld *fld)
 Get the raw string data representation of a field.
size_t actf_fld_str_sz (const actf_fld *fld)
 Get the number of bytes the string data of a field occupies, including the null-terminator if it exists.
const void * actf_fld_blob (const actf_fld *fld)
 Get data of a blob field.
size_t actf_fld_blob_sz (const actf_fld *fld)
 Get the number of bytes a blob field occupies.
size_t actf_fld_arr_len (const actf_fld *fld)
 Get the number of elements in an array field.
const actf_fldactf_fld_arr_idx (const actf_fld *fld, size_t i)
 Get the element of a specific index in an array field.
const actf_fldactf_fld_struct_fld (const actf_fld *fld, const char *key)
 Get the member with a name matching key in a struct field.
const actf_fldactf_fld_struct_fldn (const actf_fld *fld, const char *key, size_t len)
 Same as actf_fld_struct_fld() but with an explicit key length.
size_t actf_fld_struct_len (const actf_fld *fld)
 Get the number of members in a struct field.
const actf_fldactf_fld_struct_fld_idx (const actf_fld *fld, size_t i)
 Get the i:th member of a struct field.
const char * actf_fld_struct_fld_name_idx (const actf_fld *fld, size_t i)
 Get the name of the ith member in a struct field.

Detailed Description

Field related methods.

Function Documentation

◆ actf_fld_fld_cls()

const actf_fld_cls * actf_fld_fld_cls ( const actf_fld * fld)

Get the class of a field.

Parameters
fldthe field
Returns
the field's class

◆ actf_fld_type()

enum actf_fld_type actf_fld_type ( const actf_fld * fld)

Get the type of a field.

Parameters
fldthe field
Returns
the field's type

◆ actf_fld_type_name()

const char * actf_fld_type_name ( enum actf_fld_type type)

Get the name of a type.

Parameters
typethe type
Returns
the type's name

◆ actf_fld_bool()

bool actf_fld_bool ( const actf_fld * fld)

Get a bool representation of a field.

  • BOOL -> Returned as is.
  • INT -> Converted to bool (non zero is true)
  • UINT -> Converted to bool (non zero is true)
  • Other -> false
Parameters
fldthe field
Returns
the bool representation of the field

◆ actf_fld_uint64()

uint64_t actf_fld_uint64 ( const actf_fld * fld)

Get a uint64 representation of the field.

  • BOOL -> Returned as 0/1
  • INT -> Positive values returned as is, negative values returned as 0.
  • UINT -> Returned as is.
  • BIT_MAP -> Returned as is.
  • Other -> UINT64_MAX
Parameters
fldthe field
Returns
the uint64 representation of the field

◆ actf_fld_int64()

int64_t actf_fld_int64 ( const actf_fld * fld)

Get an int64 representation of the field.

  • BOOL -> Returned as 0/1
  • INT -> Returned as is.
  • UINT -> Truncated to INT64_MAX.
  • BIT_MAP -> Truncated to INT64_MAX.
  • Other -> UINT64_MAX
Parameters
fldthe field
Returns
the int64 representation of the field

◆ actf_fld_float()

float actf_fld_float ( const actf_fld * fld)

Get a float representation of the field.

  • REAL(float) -> Returned as is.
  • REAL(double) -> Converted to float and returned.
  • Other -> FLT_MAX

NOTE: Requires class introspection to know which one is "true" for a field.

Parameters
fldthe field
Returns
the float representation of the field

◆ actf_fld_double()

double actf_fld_double ( const actf_fld * fld)

Get a double representation of the field.

  • REAL(float) -> Converted to double and returned.
  • REAL(double) -> Returned as is.
  • Other -> DBL_MAX

NOTE: Requires class introspection to know which one is "true" for a field.

Parameters
fldthe field
Returns
the double representation of the field

◆ actf_fld_str_raw()

const char * actf_fld_str_raw ( const actf_fld * fld)

Get the raw string data representation of a field.

  • STR -> Pointer to the start of the string
  • Other -> NULL

The returned data is read directly from the data stream and is NOT guaranteed to be a null-terminated string. The CTF specification puts no requirements on static or dynamic length strings being null-terminated. The encoding of the returned string is determined by the field class, see actf_fld_cls_encoding().

Use actf_fld_str_raw() together with actf_fld_str_sz() for thrilling zero-copy action with this footgun.

Parameters
fldthe string field
Returns
the raw string data of the field

◆ actf_fld_str_sz()

size_t actf_fld_str_sz ( const actf_fld * fld)

Get the number of bytes the string data of a field occupies, including the null-terminator if it exists.

  • STR -> Number of bytes
  • Other -> 0
Parameters
fldthe string field
Returns
the size of the raw string data

◆ actf_fld_blob()

const void * actf_fld_blob ( const actf_fld * fld)

Get data of a blob field.

  • BLOB -> Pointer to the start of the blob
  • Other -> NULL

Use actf_fld_blob_sz() to determine the size of the returned data.

Parameters
fldthe blob field
Returns
the blob data

◆ actf_fld_blob_sz()

size_t actf_fld_blob_sz ( const actf_fld * fld)

Get the number of bytes a blob field occupies.

  • BLOB -> Number of bytes
  • Other -> 0
Parameters
fldthe blob field
Returns
the size of the blob data

◆ actf_fld_arr_len()

size_t actf_fld_arr_len ( const actf_fld * fld)

Get the number of elements in an array field.

  • ARR -> Number of elements in array
  • Other -> 0
Parameters
fldthe array field
Returns
the number of elements in the array field

◆ actf_fld_arr_idx()

const actf_fld * actf_fld_arr_idx ( const actf_fld * fld,
size_t i )

Get the element of a specific index in an array field.

  • ARR -> Element in index position i if within array bounds, else NULL
  • Other -> NULL
Parameters
fldthe array field
ithe index of the element
Returns
the element at the index

◆ actf_fld_struct_fld()

const actf_fld * actf_fld_struct_fld ( const actf_fld * fld,
const char * key )

Get the member with a name matching key in a struct field.

  • STRUCT -> Member with a name matching key
  • Other -> NULL
Parameters
fldthe struct field
keythe member name to find
Returns
the member field

◆ actf_fld_struct_len()

size_t actf_fld_struct_len ( const actf_fld * fld)

Get the number of members in a struct field.

  • STRUCT -> Number of elements
  • Other -> 0
Parameters
fldthe struct field
Returns
the number of members in the struct field

◆ actf_fld_struct_fld_idx()

const actf_fld * actf_fld_struct_fld_idx ( const actf_fld * fld,
size_t i )

Get the i:th member of a struct field.

  • STRUCT -> The member at index i if within struct bounds, else NULL
  • Other -> NULL
Parameters
fldthe struct field
ithe index of the member
Returns
the member at the index

◆ actf_fld_struct_fld_name_idx()

const char * actf_fld_struct_fld_name_idx ( const actf_fld * fld,
size_t i )

Get the name of the ith member in a struct field.

  • STRUCT -> The member name at index i if within struct bounds, else NULL
  • Other -> NULL
Parameters
fldthe struct field
ithe index of the member
Returns
the name of the member at the index