forked from p15670423/monkey
Issue #9 - Remove deprecated component
This commit is contained in:
parent
48cad4488b
commit
88c18b0e62
|
@ -1 +0,0 @@
|
|||
__author__ = 'Administrator'
|
|
@ -1,17 +0,0 @@
|
|||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
__author__ = 'itamar'
|
||||
|
||||
class MonitorAction(object):
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractmethod
|
||||
def do_action(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def undo_action(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
from desktop import ChangeDesktopAction
|
|
@ -1,38 +0,0 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
import ctypes
|
||||
import shutil
|
||||
import logging
|
||||
from data import resource_path
|
||||
|
||||
__author__ = 'itamar'
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
SPI_SETDESKWALLPAPER = 20
|
||||
SPIF_UPDATEINIFILE = 0x01
|
||||
SPIF_SENDCHANGE = 0x02
|
||||
|
||||
class ChangeDesktopAction(object):
|
||||
def __init__(self, desktop_image):
|
||||
self._desktop_image = resource_path(desktop_image)
|
||||
|
||||
assert os.path.exists(self._desktop_image), "desktop image %s is missing" % (self._desktop_image, )
|
||||
|
||||
def do_action(self):
|
||||
ctypes_desktop_img = ctypes.c_char_p(self._desktop_image)
|
||||
|
||||
# set the image
|
||||
if not bool(ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, ctypes_desktop_img, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE)):
|
||||
LOG.warn("Error setting desktop wallpaper image to '%s' (error %d)",
|
||||
ctypes_desktop_img.value, ctypes.windll.kernel32.GetLastError())
|
||||
else:
|
||||
LOG.debug("Desktop wallpaper image is set to %r", ctypes_desktop_img.value)
|
||||
|
||||
def undo_action(self):
|
||||
if not bool(ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "" , SPIF_SENDCHANGE | SPIF_UPDATEINIFILE)):
|
||||
LOG.warn("Error resetting desktop wallpaper image (error %d)",
|
||||
ctypes.windll.kernel32.GetLastError())
|
||||
else:
|
||||
LOG.debug("Desktop wallpaper image reset")
|
|
@ -1,2 +0,0 @@
|
|||
c:\Python27\python -m PyInstaller.main -F -y --clean monitor.spec
|
||||
move /Y dist\monitor32.exe "%allusersprofile%\desktop\monitor32.exe"
|
|
@ -1,13 +0,0 @@
|
|||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
__author__ = 'itamar'
|
||||
|
||||
class MonitorCondition(object):
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractmethod
|
||||
def check_condition(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
from files import FilesExistCondition
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
import os
|
||||
from condition import MonitorCondition
|
||||
|
||||
__author__ = 'itamar'
|
||||
|
||||
class FilesExistCondition(MonitorCondition):
|
||||
def __init__(self, file_name):
|
||||
self._file_path = os.path.abspath(file_name)
|
||||
|
||||
def check_condition(self):
|
||||
return os.path.isfile(self._file_path)
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
import sys
|
||||
from condition import FilesExistCondition
|
||||
from action import ChangeDesktopAction
|
||||
|
||||
__author__ = 'itamar'
|
||||
|
||||
|
||||
class MonitorConfiguration(object):
|
||||
conditions = [FilesExistCondition(r"C:\windows\monkey.exe"),
|
||||
]
|
||||
|
||||
actions = [ChangeDesktopAction(r"infected.bmp")
|
||||
]
|
||||
|
||||
monitor_interval = 5000 # 5 seconds
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
|
||||
__author__ = 'itamar'
|
||||
|
||||
def resource_path(relative_path):
|
||||
""" Get absolute path to resource, works for dev and for PyInstaller """
|
||||
try:
|
||||
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
||||
base_path = sys._MEIPASS
|
||||
except Exception:
|
||||
base_path = os.path.abspath("data")
|
||||
|
||||
return os.path.join(base_path, relative_path)
|
Binary file not shown.
Before Width: | Height: | Size: 1.4 MiB |
|
@ -1,54 +0,0 @@
|
|||
|
||||
import time
|
||||
import logging
|
||||
from config import MonitorConfiguration
|
||||
|
||||
__author__ = 'itamar'
|
||||
|
||||
logging.basicConfig(format='%(asctime)s [%(process)d:%(levelname)s] %(module)s.%(funcName)s.%(lineno)d: %(message)s',
|
||||
level=logging.DEBUG)
|
||||
LOG = logging.getLogger()
|
||||
|
||||
def do_infected():
|
||||
LOG.info("Changed state to infected")
|
||||
|
||||
[action.do_action()
|
||||
for action in MonitorConfiguration.actions]
|
||||
|
||||
def do_not_infected():
|
||||
LOG.info("Changed state to not infected")
|
||||
[action.undo_action()
|
||||
for action in MonitorConfiguration.actions]
|
||||
|
||||
def main():
|
||||
infected = False
|
||||
|
||||
LOG.info("Monitor going up...")
|
||||
|
||||
do_not_infected()
|
||||
|
||||
try:
|
||||
while True:
|
||||
if any([condition.check_condition()
|
||||
for condition in MonitorConfiguration.conditions]):
|
||||
if not infected:
|
||||
do_infected()
|
||||
|
||||
infected = True
|
||||
else:
|
||||
if infected:
|
||||
do_not_infected()
|
||||
|
||||
infected = False
|
||||
|
||||
for _ in range(MonitorConfiguration.monitor_interval / 1000):
|
||||
time.sleep(1.0)
|
||||
finally:
|
||||
if infected:
|
||||
do_not_infected()
|
||||
|
||||
LOG.info("Monitor going down...")
|
||||
|
||||
|
||||
if "__main__" == __name__:
|
||||
main()
|
Binary file not shown.
Before Width: | Height: | Size: 348 KiB |
Loading…
Reference in New Issue