Difference between revisions of "Python 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 Python. <syntaxhighlight line lang="python"> import truxton def main(): etl = truxton.etl() etl...")
 
Line 1: Line 1:
 
This sample shows the steps needed to implement a byte identifier ETL in Python.
 
This sample shows the steps needed to implement a byte identifier ETL in Python.
  
 +
=Sample File Format=
 +
This sample will identify a fake file format we call Acme.
 +
[https://en.wikipedia.org/wiki/Acme_Corporation Acme Corporation] is a known supplier of nefarious tools and explosives.
 +
Their file format begins with a five byte magic value
 +
<pre>
 +
0000h: 88 77 66 55 00 11 22 33 44 55 66 77 88 99 AA BB
 +
0010h: CC                                              Ì
 +
</pre>
 +
 +
=Source Code=
 
<syntaxhighlight line lang="python">
 
<syntaxhighlight line lang="python">
 
import truxton
 
import truxton

Revision as of 14:22, 12 June 2020

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

Sample File Format

This sample will identify a fake file format we call Acme. Acme Corporation is a known supplier of nefarious tools and explosives. Their file format begins with a five byte magic value

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

Source Code

 1 import truxton
 2 
 3 def main():
 4 
 5   etl = truxton.etl()
 6   etl.name = "Acme Identifier"
 7   etl.description = "This ETL identifies files using the Acme method"
 8   etl.queue = "acme"
 9   etl.stage = 2
10   etl.id = 26572
11   etl.addtype(truxton.Type_Unknown)
12 
13   message = etl.getmessage()
14 
15   while message is not None:
16     if message.length >= 16:
17       if message.signature == 0x55667788:
18         file_in_truxton = message.file()
19 
20         file_in_truxton.seek(4)
21 
22         if file_in_truxton.read(1) == 0:
23           file_in_truxton.changetype(10111)
24           message.file_type = 10111
25           message.route()
26 
27     message = etl.getmessage()
28 
29 if __name__ == "__main__":
30     main()

Code Walkthrough