-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a2c43e7
Showing
17 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
|
||
# Created by https://www.gitignore.io/api/python | ||
# Edit at https://www.gitignore.io/?templates=python | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
### Python Patch ### | ||
.venv/ | ||
|
||
# End of https://www.gitignore.io/api/python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import time | ||
|
||
import god | ||
import god.interactive | ||
import god.cli as cli | ||
import god.log as log | ||
import god.quotes as quotes | ||
import god.config as config | ||
|
||
|
||
def load_settings(): | ||
cli.i_am("Carregando configurações...") | ||
config.load() | ||
cli.success("OK") | ||
cli.print_settings() | ||
|
||
|
||
def use_inet_phrases(): | ||
cli.i_am("Pegando umas frases aleatórias...") | ||
try: | ||
n = quotes.load_inet() | ||
cli.success("{} frases".format(n)) | ||
except: | ||
cli.error("Falhou :(") | ||
use_stored_phrases() | ||
|
||
|
||
def use_stored_phrases(): | ||
cli.i_am("Usando frases aleatórias locais...") | ||
n = quotes.load_local() | ||
cli.success("Got {} phrases".format(n)) | ||
|
||
|
||
def load_phrases(): | ||
cli.i_am("Checando conexão com a internet...") | ||
|
||
if god.check_internet(): | ||
cli.success("OK") | ||
cli.list_begin() | ||
use_inet_phrases() | ||
cli.list_end() | ||
else: | ||
cli.error("Internet indisponível") | ||
cli.list_begin() | ||
use_stored_phrases() | ||
cli.list_end() | ||
|
||
|
||
def main(): | ||
cli.clear() | ||
cli.header() | ||
|
||
load_settings() | ||
load_phrases() | ||
|
||
cli.success("Pronto.") | ||
print() | ||
cli.i_am("Iniciando ambiente interativo. Se divirta!") | ||
time.sleep(2) | ||
|
||
cli.clear() | ||
cli.interactive_header() | ||
|
||
god.start() | ||
god.interactive.run() | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
main() | ||
except Exception as e: | ||
log.error("main", e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
pyinstaller --onefile -n god -i god.ico --add-data %PY_HOME%/Lib/site-packages/pyfiglet;./pyfiglet __main__.py god\__init__.py god\cli.py | ||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
frequency: 30 | ||
psname: notepad.exe | ||
threshold: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#=============================================================================== | ||
# * danger.yml | ||
#=============================================================================== | ||
# Arquivo de configuração do God para situações em que o programa de | ||
# monitoramento começa a ser usado. | ||
# | ||
# Obs.: Esse arquivo roda SÓ UMA VEZ, quando o programa é aberto pelo professor, | ||
# Não conte com a execução contínua das instruções desse arquivo | ||
#=============================================================================== | ||
#------------------------------------------------------------------------------- | ||
# Lista de processos que serão fechados (.exe é opcional) | ||
#------------------------------------------------------------------------------- | ||
kill: | ||
- mspaint | ||
- chrome | ||
- osu! | ||
- cs | ||
- halflife | ||
- Game | ||
#------------------------------------------------------------------------------- | ||
# Lista de linhas de comando que serão executadas | ||
#------------------------------------------------------------------------------- | ||
cmd: | ||
#- start mspaint | ||
#------------------------------------------------------------------------------- | ||
# Flashbang: Abre um bloco de notas maximizado, pra esconder a tela | ||
#------------------------------------------------------------------------------- | ||
flashbang: false |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import god.checker as checker | ||
|
||
from urllib.request import urlopen, URLError | ||
|
||
god_thread = None | ||
|
||
|
||
def check_internet(): | ||
try: | ||
urlopen('http://google.com', timeout=5) | ||
return True | ||
except URLError: | ||
return False | ||
|
||
|
||
def start(): | ||
global god_thread | ||
god_thread = checker.Thread() | ||
god_thread.start() | ||
|
||
|
||
def stop(): | ||
god_thread.kill() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import threading | ||
import pythoncom | ||
import time | ||
import yaml | ||
|
||
import god.cli as cli | ||
import god.log as log | ||
import god.config as config | ||
import god.handler as handler | ||
|
||
from wmi import WMI | ||
from enum import Enum, auto | ||
|
||
|
||
class _GodState(Enum): | ||
IDLE = auto() | ||
SAFE = auto() | ||
ALERT = auto() | ||
|
||
|
||
class Thread(threading.Thread): | ||
|
||
def __init__(self): | ||
threading.Thread.__init__(self) | ||
self.die = False | ||
self.state = _GodState.IDLE | ||
|
||
def check_memory(self): | ||
processes = self.wmi.Win32_Process(Name=config.get("psname")) | ||
for process in processes: | ||
working_set = int(process.WorkingSetSize) | ||
if working_set / 1024 >= config.get("threshold"): | ||
self.danger() | ||
break | ||
else: | ||
self.safe() | ||
|
||
def danger(self): | ||
if self.state != _GodState.ALERT: | ||
self.state = _GodState.ALERT | ||
handler.danger() | ||
cli.clear() | ||
cli.header('red') | ||
cli.print_random_phrase() | ||
cli.warning("Run, berg! Run!".center(cli.width())) | ||
print() | ||
cli.print_settings() | ||
print(">", end=' ', flush=True) | ||
|
||
def safe(self): | ||
if self.state == _GodState.ALERT: | ||
self.state = _GodState.SAFE | ||
handler.safe() | ||
cli.clear() | ||
cli.header() | ||
cli.print_random_phrase() | ||
cli.success("Back to business...".center(cli.width())) | ||
print() | ||
cli.print_settings() | ||
print(">", end=' ', flush=True) | ||
|
||
def kill(self): | ||
self.die = True | ||
|
||
def run(self): | ||
try: | ||
pythoncom.CoInitialize() | ||
self.wmi = WMI() | ||
|
||
while not self.die: | ||
self.check_memory() | ||
time.sleep(1.0 / config.get("frequency")) | ||
|
||
pythoncom.CoUninitialize() | ||
|
||
except Exception as e: | ||
log.error('memory_checker_thread', e) |
Oops, something went wrong.