Package modules :: Package auxiliary :: Module screenshots
[hide private]
[frames] | no frames]

Source Code for Module modules.auxiliary.screenshots

 1  # Copyright (C) 2010-2014 Cuckoo Foundation. 
 2  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org 
 3  # See the file 'docs/LICENSE' for copying permission. 
 4   
 5  import time 
 6  import logging 
 7  import StringIO 
 8  from threading import Thread 
 9   
10  from lib.common.abstracts import Auxiliary 
11  from lib.common.results import NetlogFile 
12  from lib.api.screenshot import Screenshot 
13   
14  log = logging.getLogger(__name__) 
15  SHOT_DELAY = 1 
16   
17 -class Screenshots(Auxiliary, Thread):
18 """Take screenshots.""" 19
20 - def __init__(self):
21 Thread.__init__(self) 22 self.do_run = True
23
24 - def stop(self):
25 """Stop screenshotting.""" 26 self.do_run = False
27
28 - def run(self):
29 """Run screenshotting. 30 @return: operation status. 31 """ 32 if not Screenshot().have_pil(): 33 log.warning("Python Image Library is not installed, " 34 "screenshots are disabled") 35 return False 36 37 img_counter = 0 38 img_last = None 39 40 while self.do_run: 41 time.sleep(SHOT_DELAY) 42 43 try: 44 img_current = Screenshot().take() 45 except IOError as e: 46 log.error("Cannot take screenshot: %s", e) 47 continue 48 49 if img_last: 50 if Screenshot().equal(img_last, img_current): 51 continue 52 53 img_counter += 1 54 55 # workaround as PIL can't write to the socket file object :( 56 tmpio = StringIO.StringIO() 57 img_current.save(tmpio, format="JPEG") 58 tmpio.seek(0) 59 60 # now upload to host from the StringIO 61 nf = NetlogFile("shots/%s.jpg" % str(img_counter).rjust(4, "0")) 62 63 for chunk in tmpio: 64 nf.sock.sendall(chunk) 65 66 nf.close() 67 68 img_last = img_current 69 70 return True
71