This repository has been archived by the owner on Mar 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
swf_meta.py
74 lines (56 loc) · 2.25 KB
/
swf_meta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
''' SWFMeta worker: This code heavily utilizes https://github.com/timknip/pyswf, all credit for good
stuff goes to them, all credit for bad stuff goes to me. :)
'''
from swf.movie import SWF
import StringIO
class SWFMeta():
''' This worker computes a bunch of meta-data about a SWF file '''
dependencies = ['sample', 'meta']
def execute(self, input_data):
# Spin up SWF class
swf = SWF()
# Get the raw_bytes
raw_bytes = input_data['sample']['raw_bytes']
# Parse it
swf.parse(StringIO.StringIO(raw_bytes))
# Header info
head = swf.header
output = {'version':head.version,'file_length':head.file_length,'frame_count':head.frame_count,
'frame_rate':head.frame_rate,'frame_size':head.frame_size.__str__(),'compressed':head.compressed}
# Loop through all the tags
output['tags'] = [tag.__str__() for tag in swf.tags]
# Add the meta data to the output
output.update(input_data['meta'])
return output
'''
# Map all tag names to indexes
tag_map = {tag.name:index for tag,index in enumerate(swf.tags)}
# FileAttribute Info
file_attr_tag = swf.tags[tag_map]
'''
'''
# Build up return data structure
output = {name:value for name,value in locals().iteritems()
if name not in ['self', 'input_data','raw_bytes']}
output.update(input_data['meta'])
return output
'''
# Unit test: Create the class, the proper input and run the execute() method for a test
def test():
''' swf_meta.py: Unit test'''
# This worker test requires a local server running
import zerorpc
workbench = zerorpc.Client()
workbench.connect("tcp://127.0.0.1:4242")
# Generate the input data for this worker
md5 = workbench.store_sample('unknown.swf', open('../data/swf/unknown.swf', 'rb').read(), 'pe')
input_data = workbench.get_sample(md5)
input_data.update(workbench.work_request('meta', md5))
# Execute the worker
worker = SWFMeta()
output = worker.execute(input_data)
print 'SWFMeta: '
import pprint
pprint.pprint(output)
if __name__ == "__main__":
test()