Difference between revisions of "C Sample Identification ETL"

From truxwiki.com
Jump to navigation Jump to search
(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...")
 
Line 10: Line 10:
 
0010h: CC
 
0010h: CC
 
</pre>
 
</pre>
 +
 +
=Visual Studio Configuration=
 +
The steps to creating a program to create a file content identification ETL are:
 +
# Start Visual Studio
 +
# File->New->Project
 +
# Empty Project - C++
 +
# Project name: IdentifyFile
 +
# Press "Create" button
 +
# Remove the <code>x86</code> configuration
 +
# Right button on the IdentifyFileproject in the Solution Explorer window
 +
# Add->New Item...->C++ File->Add button
 +
# Right button on the IdentifyFileproject in the Solution Explorer window
 +
# Select Properties
 +
# C/C++->Additional Include Directories: add "C:\Program Files\Truxton\SDK"
 +
# Linker->Additional Library Directories: add "C:\Truxton" (or wherever you generated the <code>TruxtonCAPI.lib</code> file)
  
 
=Source Code=
 
=Source Code=

Revision as of 16:00, 5 April 2021

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

Visual Studio Configuration

The steps to creating a program to create a file content identification ETL are:

  1. Start Visual Studio
  2. File->New->Project
  3. Empty Project - C++
  4. Project name: IdentifyFile
  5. Press "Create" button
  6. Remove the x86 configuration
  7. Right button on the IdentifyFileproject in the Solution Explorer window
  8. Add->New Item...->C++ File->Add button
  9. Right button on the IdentifyFileproject in the Solution Explorer window
  10. Select Properties
  11. C/C++->Additional Include Directories: add "C:\Program Files\Truxton\SDK"
  12. Linker->Additional Library Directories: add "C:\Truxton" (or wherever you generated the TruxtonCAPI.lib file)

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 }