Skip to content

Commit

Permalink
style: Automatic code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jul 31, 2024
1 parent cc86e43 commit dc4813f
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions modules/auxiliary/QemuScreenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# for comparing screenshots.

import logging
import time
import os
import math
import os
import time
from io import BytesIO
from threading import Thread

Expand Down Expand Up @@ -47,13 +47,14 @@
# SKIP_AREA = ((735, 575), (790, 595))
SKIP_AREA = None


class QEMUScreenshots(Auxiliary):
"""QEMU screenshots module."""

def __init__(self):
Auxiliary.__init__(self)
Thread.__init__(self)
log.info('QEMU screenshots module loaded')
log.info("QEMU screenshots module loaded")
self.screenshot_thread = None

def start(self):
Expand All @@ -67,17 +68,17 @@ def stop(self):
if self.screenshot_thread:
self.screenshot_thread.stop()


class ScreenshotThread(Thread):
"""Thread responsible for taking screenshots."""

def __init__(self, task, machine):
Thread.__init__(self)
self.task = task
self.machine = machine
self.do_run = True

self.screenshots_path = os.path.join(
CUCKOO_ROOT, "storage", "analyses", str(self.task.id), "shots"
)

self.screenshots_path = os.path.join(CUCKOO_ROOT, "storage", "analyses", str(self.task.id), "shots")
os.makedirs(self.screenshots_path, exist_ok=True)

def stop(self):
Expand All @@ -98,22 +99,21 @@ def run(self):
img_last = img_current
file_path = os.path.join(self.screenshots_path, f"{img_counter}.png")
img_current.save(file_path, format="PNG")
#log.info(f'Screenshot saved to {file_path}')
# log.info(f'Screenshot saved to {file_path}')
img_counter += 1
except (IOError, libvirt.libvirtError) as e:
log.error(f"Cannot take screenshot: {e}")
continue


def _take_screenshot(self):
"""Take screenshot from QEMU and return the PIL Image object."""
conn = libvirt.open('qemu:///system')
conn = libvirt.open("qemu:///system")
try:
dom = conn.lookupByName(self.machine.label)
stream = conn.newStream()
dom.screenshot(stream, 0) # 0 for primary display

image_data = b''
image_data = b""
while True:
chunk = stream.recv(262120)
if not chunk:
Expand All @@ -127,7 +127,6 @@ def _take_screenshot(self):
if conn:
conn.close()


def _draw_rectangle(self, img, xy):
"""Draw a black rectangle.
@param img: PIL Image object
Expand Down Expand Up @@ -169,4 +168,4 @@ def _equal(self, img1, img2, skip_area=None):
rms = math.sqrt(sum_of_squares / float(img1.size[0] * img1.size[1]))

# Might need to tweak the threshold.
return rms < 8
return rms < 8

0 comments on commit dc4813f

Please sign in to comment.