Truxton file type get parent id

From truxwiki.com
Jump to navigation Jump to search

This returns the integer identifier for the more generic file type of this file type. In Truxton, the concept of file type is a bit fluid. During exploitation, a file may have several types. The type of a file will advance from a primitive type to a more sophisticated type. For example, ASCII is a primitive type of file, XML is a specialization of ASCII and KML is a specialization of XML. Setting the parent is not required. This corresponds to the [ParentFileTypeID] column of the [FileType] table.

Syntax

uint64_t truxton_file_type_get_parent_id( uint64_t file_type );

Parameters

file_type

The handle to the file type object. This handle comes from calling truxton_file_type_create().

Return value

The integer identifier for the parent file type.

Sample

void create_file_type( void )
{
   uint64_t truxton = truxton_create();

   uint64_t file_type = truxton_file_type_create( truxton );

   truxton_file_type_set_short_name( file_type, "My Type" );
   truxton_file_type_set_long_name( file_type, "A new custom type derived from XML" );
   truxton_file_type_set_parent_id( file_type, Type_XML );
   truxton_file_type_set_extension( file_type, "xm2" );
   truxton_file_type_set_mime_type( file_type, "text/xml" );

   if ( truxton_file_type_save( file_type ) == 0 )
   {
      printf( "Cannot save file type to the database.\n" );
   }

   uint64_t new_id = truxton_file_type_get_id( file_type );

   if ( new_id == 0 )
   {
      printf( "Failed to create new file type\n" );
   }
   else
   {
      printf( "Created new file type as id %" PRIu64 "\n", new_id );
   }

   uint64_t parent = truxton_file_type_get_parent_id( file_type )

   if ( parent != Type_XML )
   {
      printf( "Something really bad wrong just happened\n" );
   }

   truxton_file_type_destroy( file_type );
   truxton_destroy( truxton );
}

The PRIu64 in the sample code above is a standard way of formatting a 64-bit unsigned integer in C. Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.