C Sample Identification ETL

From truxwiki.com
Revision as of 15:59, 5 April 2021 by Sam (talk | contribs) (Created page with "This sample shows the steps needed to implement a byte identifier ETL in C. =Sample File Format= This sample will identify a fake file format we call Acme. [https://en.wikipe...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This sample shows the steps needed to implement a byte identifier ETL in C.

Sample File Format

This sample will identify a fake file format we call Acme. Acme Corporation is a known supplier of nefarious devices and explosives. Their file format begins with a five byte magic value followed by eleven bytes in a data structure.

0000h: 88 77 66 55 00 11 22 33 44 55 66 77 88 99 AA BB
0010h: CC

Source Code

 1 #include <stdio.h>
 2 #include <memory.h>
 3 #include <inttypes.h>
 4 #include <TruxtonCAPI.h>
 5 #include <TruxtonFileTypes.h>
 6 #include <TruxtonDefines.h>
 7 #pragma comment (lib, "TruxtonCAPI.lib")
 8 
 9 int main(void)
10 {
11   uint8_t buffer[10];
12 
13   uint64_t message = 0;
14 
15   uint64_t etl_application = truxton_etl_create();
16 
17   truxton_etl_set_application_name(etl_application, "My Identify File");
18   truxton_etl_set_description(etl_application, "Identifier ETL for new file type");
19   truxton_etl_set_queue_name(etl_application, "mif");
20   truxton_etl_set_stage_number(etl_application, 2);
21 
22   truxton_etl_add_desired_file_type(etl_application, Type_Unknown);
23 
24   //truxton_etl_send_me_file_id(etl_application, "6068992f-af6b-06b8-28ce-094b0000000d");
25 
26   message = truxton_etl_get_message(etl_application);
27 
28   while (message != 0)
29   {
30     if (truxton_message_get_depot_length(message) >= 16 &&
31         truxton_message_get_signature(message) == 0x88776655)
32     {
33       uint64_t file_in_truxton = truxton_message_get_file(message);
34 
35       if (file_in_truxton != 0)
36       {
37         truxton_file_seek(file_in_truxton, 4, SEEK_SET);
38 
39         if (truxton_file_read(file_in_truxton, buffer, 1) == 1)
40         {
41           if (buffer[0] == 0x00)
42           {
43             truxton_file_change_type(file_in_truxton, 11111);
44             truxton_message_set_file_type(message, 11111);
45             truxton_route_message(truxton_file_get_truxton(file_in_truxton), message);
46           }
47         }
48       }
49 
50       truxton_file_free(file_in_truxton);
51     }
52 
53     truxton_message_destroy(message);
54 
55     message = truxton_etl_get_message(etl_application);
56   }
57 
58   truxton_etl_destroy(etl_application);
59   return(0);
60 }