Skip to content

Commit

Permalink
πŸ“… Commit Tue, 20 Apr 2021 15:33:53
Browse files Browse the repository at this point in the history
πŸš€ 3.2.0
πŸ› handle EOFError, ctrl + d in cli
πŸ”§ added/updated config options for cli
✨ added run_recipe method in core
πŸ“ docs added/updated
βœ… tests added/updated
  • Loading branch information
securisec committed Apr 20, 2021
1 parent 061e1b0 commit 01715e5
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 14 deletions.
6 changes: 5 additions & 1 deletion chepy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
def get_style():
return Style.from_dict(
{
"completion-menu.completion.current": "bg:#00aaaa #000000",
"completion-menu.completion.current": "bg:{}".format(config.prompt_search_background),
# "completion-menu.completion": "bg:#008888 #ffffff",
"completion-menu.completion.fuzzymatch.outside": "fg:#00aaaa",
"prompt1": "{} bold".format(prompt_colors[0]),
Expand Down Expand Up @@ -339,3 +339,7 @@ def main():
except KeyboardInterrupt:
print(green("\nOKBye"))
sys.exit()
except EOFError:
print(green("\nOKBye"))
sys.exit()

2 changes: 1 addition & 1 deletion chepy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "3.1.0" # pragma: no cover
__version__ = "3.2.0" # pragma: no cover
__author__ = "Hapsida @securisec" # pragma: no cover
2 changes: 1 addition & 1 deletion chepy/chepy_plugins
Submodule chepy_plugins updated 4 files
+19 βˆ’14 chepy_git.py
+0 βˆ’2 chepy_git.pyi
+8 βˆ’3 chepy_html.py
+0 βˆ’0 chepy_html.pyi
8 changes: 8 additions & 0 deletions chepy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def __init__(self):
cli_options["prompt_cli_method"] = "#ffd700"
cli_options["prompt_plugin_method"] = "#30d8ff"
cli_options["cli_info_color"] = "#c2c2ff"
cli_options["prompt_search_background"] = "#00aaaa #000000"
cli_options["prompt_search_fuzzy"] = "#00aaaa"

Path(str(self.chepy_dir / "chepy_history")).touch()
if not self.chepy_conf.exists():
Expand Down Expand Up @@ -95,6 +97,12 @@ def __init__(self):
self.prompt_toolbar_errors = self.__get_conf_value(
"#ff0000", "prompt_toolbar_errors"
)
self.prompt_search_background = self.__get_conf_value(
"#00aaaa #000000", "prompt_search_background"
)
self.prompt_search_fuzzy = self.__get_conf_value(
"#00aaaa", "prompt_search_fuzzy"
)
self.prompt_cli_method = self.__get_conf_value("#ffd700", "prompt_cli_method")
self.prompt_plugin_method = self.__get_conf_value(
"#30d8ff", "prompt_plugin_method"
Expand Down
44 changes: 34 additions & 10 deletions chepy/core.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import lazy_import

import sys
import base64
import binascii
import pathlib
import webbrowser
import logging
import inspect
import io
import itertools
import logging
import pathlib
import subprocess
from importlib.machinery import SourceFileLoader
import sys
import webbrowser
from configparser import ConfigParser
from urllib.parse import urljoin
from importlib.machinery import SourceFileLoader
from pprint import pformat
from typing import Any, Tuple, List, Union
from typing import Any, List, Mapping, Tuple, Union
from urllib.parse import urljoin

import lazy_import
import pyperclip
import ujson

jsonpickle = lazy_import.lazy_module("jsonpickle")
import regex as re
from decorator import decorator

from .modules.internal.colors import yellow, cyan, green, magenta, blue, red
from .modules.internal.colors import blue, cyan, green, magenta, red, yellow


class ChepyDecorators(object):
Expand Down Expand Up @@ -867,6 +866,31 @@ def write_binary(self, path: str) -> None: # pragma: no cover
self._info_logger("File written to {}".format(self._abs_path(path)))
return None

def run_recipe(self, recipes: List[Mapping[str, Union[str, Mapping[str, Any]]]]):
"""Run a recipe on the state. All arguments including optional needs to
be specified for a recipe.
Args:
recipes (List[Mapping[str, Union[str, Mapping[str, Any]]]]): An array of recipes.
Recipes are in the format {'function': 'function_name', 'args': {'arg_name': 'arg_val'}}
Returns:
Chepy: The Chepy object.
Examples:
>>> c = Chepy('bG9sCg==').run_recipe([{"function":"base64_decode","args":{"custom":None,"fix_padding":True}}]])
>>> lol
In this example, we are calling the base64 decode method on the state.
"""
for recipe in recipes:
function = recipe["function"]
args = recipe["args"]
if len(args) > 0:
getattr(self, function)(**args)
else:
getattr(self, function)()
return self

def save_recipe(self, path: str):
"""Save the current recipe
Expand Down
3 changes: 2 additions & 1 deletion chepy/core.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Tuple, Union, TypeVar
from typing import Any, List, Mapping, Tuple, Union, TypeVar

jsonpickle: Any

Expand Down Expand Up @@ -52,6 +52,7 @@ class ChepyCore:
def load_file(self: ChepyCoreT, binary_mode: bool=...) -> ChepyCoreT: ...
def write_to_file(self: ChepyCoreT, path: str) -> None: ...
def write_binary(self: ChepyCoreT, path: str) -> None: ...
def run_recipe(self: ChepyCoreT, recipes: List[Mapping[str, Union[str, Mapping[str, Any]]]]) -> ChepyCoreT: ...
def save_recipe(self: ChepyCoreT, path: str) -> ChepyCoreT: ...
def load_recipe(self: ChepyCoreT, path: str) -> ChepyCoreT: ...
def run_script(self: ChepyCoreT, path: str, save_state: bool=...) -> ChepyCoreT: ...
Expand Down
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Controls the color of the cli methods. Defaults to *#00d700*
Controls the color of the plugin methods. Defaults to *#30d8ff*
### Cli.cli_info_color
Controls the color of the output from `cli_*` methods. Defaults to *#ffb4ad*
### Cli.prompt_search_background
Background background color for cli selection. Defaults to *#00aaaa #000000*
### Cli.prompt_search_fuzzy
Background background color for cli fuzzy match. Defaults to *#00aaaa*


### chepy_history
Expand Down
1 change: 1 addition & 0 deletions tests/files/testgit
Submodule testgit added at 1ae9fc
17 changes: 17 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ def test_load_file_binary():
assert type(Chepy("tests/files/pkcs12").load_file(True).o) == bytearray


def test_run_recipe():
assert (
Chepy("bG9sCg==")
.run_recipe(
recipes=[
{
"function": "base64_decode",
"args": {"custom": None, "fix_padding": True},
},
{"function": "swap_case", "args": {}},
]
)
.o
== "LOL\n"
)


def test_recipe():
temp = str(Path(tempfile.gettempdir()) / os.urandom(24).hex())
Chepy(
Expand Down
14 changes: 14 additions & 0 deletions tests_plugins/test_git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# from chepy import Chepy

# GIT_PATH = "tests/files/testgit"


# def test_git_authors():
# assert Chepy(GIT_PATH).git_authors().o["securisec"] == 1


# def test_git_search_code():
# assert (
# "1ae9fcc62e486030a48df0bce4830e74f3fa4df8"
# in Chepy(GIT_PATH).git_search_code("flag").o
# )

0 comments on commit 01715e5

Please sign in to comment.