Skip to content

Commit

Permalink
Help automático, arquivo para flashbang e popups
Browse files Browse the repository at this point in the history
  • Loading branch information
GuiBrandt committed Feb 27, 2019
1 parent 3668389 commit e75a04e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 26 deletions.
13 changes: 11 additions & 2 deletions danger.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--- #-------------------------------------------------------------------------------
---
#===============================================================================
# * danger.yml
#===============================================================================
Expand All @@ -9,7 +9,8 @@
# Não conte com a execução contínua das instruções desse arquivo
#===============================================================================
#-------------------------------------------------------------------------------
# Lista de processos que serão fechados (.exe é opcional)
# Lista de processos que serão fechados (o .exe é opcional)
#-------------------------------------------------------------------------------
kill:
- mspaint
- chrome
Expand All @@ -24,5 +25,13 @@ cmd:
#- start mspaint
#-------------------------------------------------------------------------------
# Flashbang: Abre um bloco de notas maximizado, pra esconder a tela
#
# true ~> Habilita
# false ~> Desabilita
#-------------------------------------------------------------------------------
flashbang: false
#-------------------------------------------------------------------------------
# * Mensagem de aviso
#-------------------------------------------------------------------------------
# popup: Coooorrree berg!!
popup: false # Sem mensagem de aviso
15 changes: 9 additions & 6 deletions god/gui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Gerenciador de interface do usuário
Esse módulo tem funções para gerenciar a interface com o usuário, incluindo CLI
e GUI.
Esse módulo tem funções para gerenciar a interface gráfica com o usuário.
"""

Expand Down Expand Up @@ -30,7 +29,8 @@ def confirm(text, title="God"):

res = MessageBox(win32console.GetConsoleWindow(),
text, title,
win32con.MB_YESNO | win32con.MB_ICONINFORMATION)
win32con.MB_YESNO | win32con.MB_ICONINFORMATION |
win32con.MB_SYSTEMMODAL)
return res == win32con.IDYES


Expand All @@ -49,7 +49,8 @@ def info(text, title="God"):

MessageBox(win32console.GetConsoleWindow(),
text, title,
win32con.MB_OK | win32con.MB_ICONINFORMATION)
win32con.MB_OK | win32con.MB_ICONINFORMATION |
win32con.MB_SYSTEMMODAL)


def error(text, title="God"):
Expand All @@ -67,7 +68,8 @@ def error(text, title="God"):

MessageBox(win32console.GetConsoleWindow(),
text, title,
win32con.MB_OK | win32con.MB_ICONERROR)
win32con.MB_OK | win32con.MB_ICONERROR |
win32con.MB_SYSTEMMODAL)


def warning(text, title="God"):
Expand All @@ -85,4 +87,5 @@ def warning(text, title="God"):

MessageBox(win32console.GetConsoleWindow(),
text, title,
win32con.MB_OK | win32con.MB_ICONWARNING)
win32con.MB_OK | win32con.MB_ICONWARNING |
win32con.MB_SYSTEMMODAL)
8 changes: 7 additions & 1 deletion god/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import os
import json

import yaml
import win32con
Expand All @@ -17,6 +16,7 @@
import god
import god.config as config
import god.cli as cli
import god.gui as gui
import god.log as log


Expand Down Expand Up @@ -92,6 +92,9 @@ def danger():
for pname in danger_yml['cmd']:
os.system(pname)

if 'popup' in danger_yml and danger_yml['popup']:
gui.warning(danger_yml['popup'])

except RuntimeError as ex:
log.error("on_danger", ex)
cli.error("OH GOD OH FUCK, I CAN'T RUN THE INSTRUCTIONS!!!!1!!1!!!")
Expand Down Expand Up @@ -120,6 +123,9 @@ def safe():
for pname in safe_yml['cmd']:
os.system(pname)

if 'popup' in safe_yml and safe_yml['popup']:
gui.info(safe_yml['popup'])

except RuntimeError as ex:
log.error("on_safe", ex)
cli.info("Hmmmmm, não consigo rodar essas instruções aqui...")
64 changes: 48 additions & 16 deletions god/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import re
import sys
from functools import wraps

from colorama import Fore

Expand Down Expand Up @@ -38,14 +39,15 @@ def run():
break
else:
cli.error(
f"\tComando não reconhecido `{command}`. Veja `help`.")
f"\tComando não reconhecido: `{command}`. Veja `help`.")
except RuntimeError as ex:
log.error("interactive", ex)


def no_arg(cmd_func):
"""Wrapper para comandos sem parâmetro"""

@wraps(cmd_func)
def func_wrapper(*args):
if len(args) > 1:
cli.error("\tNão esperava parâmetros, mas OK.")
Expand All @@ -56,88 +58,118 @@ def func_wrapper(*args):
def require_arg(cmd_func):
"""Wrapper para comandos com parâmetro"""

@wraps(cmd_func)
def func_wrapper(*args):
if len(args) != 1:
cli.error("\tSintaxe incorreta. Veja `help`.")
return None
else:
return cmd_func(*args)
return cmd_func(*args)
return func_wrapper


def numeric(cmd_func):
"""Wrapper para comandos com parâmetro numérico"""

@wraps(cmd_func)
def func_wrapper(*args):
if not args[0].isnumeric():
cli.error("\tEsperava um número. Veja `help`.")
return None
else:
return cmd_func(int(args[0]))
return cmd_func(int(args[0]))
return func_wrapper


@no_arg
def cmd_quit():
"""Fecha o God"""

god.stop()
sys.exit(0)


@no_arg
def cmd_help():
"""Mostra ajuda para os comandos do God"""

def _syntax(command):
options, method = command
return ("|".join(options)).ljust(30) + " : " + method.__doc__

commands_help = "\r\n\t".join(map(_syntax, _COMMAND_MAP.items()))

print(Fore.YELLOW + f"""
GOD {version.current()}
sm|threshold X : Define o limite de memória para X Kb
sp|process X : Define o processo monitorado para X
sf|frequency X : Define a frequência de atualização para X Hz
ss|save : Salva as configurações
cc|clear : Limpa a tela
h|help : Mostra a ajuda
q|quit|exit : Sai do programa
{commands_help}
""")


@no_arg
def cmd_save():
"""Salva as configurações"""

config.save()


@no_arg
def cmd_load():
"""Carrega as configurações"""
config.load()


@no_arg
def cmd_clear():
"""Limpa a tela"""

cli.clear()
cli.interactive_header()


@require_arg
@numeric
def cmd_threshold(value):
"""Define o limite de memória para X Kb"""

config.set('threshold', value)
cli.print_settings()


@require_arg
@numeric
def cmd_frequency(value):
"""Define a frequência de atualização para X Hz"""
config.set('frequency', value)
cli.print_settings()


@require_arg
def cmd_process(*parts):
"""Define o processo monitorado para X"""

psname = ' '.join(parts)
if not psname.endswith(".exe"):
psname += ".exe"
config.set('psname', psname)
cli.print_settings()


@require_arg
def cmd_flashbang(*parts):
"""Define o arquivo de flashbang"""

fname = ' '.join(parts)
config.set('flashbang_file', fname)
cli.print_settings()


_COMMAND_MAP = {
('q', 'quit', 'exit'): cmd_quit,
('h', 'help'): cmd_help,
('ss', 'save'): cmd_save,
('cc', 'clear'): cmd_clear,
('cc', 'cls', 'clear'): cmd_clear,
('sm', 'threshold'): cmd_threshold,
('sf', 'frequency'): cmd_frequency,
('sp', 'process'): cmd_process
('sp', 'process'): cmd_process,
('fb', 'flashbang'): cmd_flashbang,
('ss', 'save'): cmd_save,
('ls', 'load'): cmd_load,
('q', 'quit', 'exit'): cmd_quit,
}
8 changes: 7 additions & 1 deletion safe.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
#===============================================================================
# * safe.yml
#-------------------------------------------------------------------------------
Expand All @@ -8,4 +9,9 @@
# Lista de linhas de comando que serão executadas
#-------------------------------------------------------------------------------
cmd:
- start mspaint
- start mspaint
#-------------------------------------------------------------------------------
# * Mensagem de aviso
#-------------------------------------------------------------------------------
# popup: false # Sem mensagem de aviso
popup: They're gone

0 comments on commit e75a04e

Please sign in to comment.