From 1dbc03b1f4c807a975be5f28443bd29b037342b0 Mon Sep 17 00:00:00 2001 From: securisec Date: Sun, 26 May 2024 22:53:03 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=93=20May=2026,=202024=2010:52:12?= =?UTF-8?q?=E2=80=AFPM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ increment/decrement bytes ✨ print method in core to print state 🤖 types added/updated --- chepy/__version__.py | 2 +- chepy/core.py | 12 ++++++++- chepy/core.pyi | 5 ++-- chepy/modules/dataformat.py | 40 +++++++++++++++++++++++++++-- chepy/modules/dataformat.pyi | 2 ++ chepy/modules/encryptionencoding.py | 1 - tests/test_dataformat.py | 11 ++++++++ 7 files changed, 66 insertions(+), 7 deletions(-) diff --git a/chepy/__version__.py b/chepy/__version__.py index a183113..e57f66b 100644 --- a/chepy/__version__.py +++ b/chepy/__version__.py @@ -1,2 +1,2 @@ -__version__ = "7.0.0" # pragma: no cover +__version__ = "7.1.0" # pragma: no cover __author__ = "@securisec" # pragma: no cover diff --git a/chepy/core.py b/chepy/core.py index 3563771..13a1d4b 100644 --- a/chepy/core.py +++ b/chepy/core.py @@ -1344,6 +1344,16 @@ def debug(self, verbose: bool = False): print(magenta("Buffers:"), self.buffers) return self + @ChepyDecorators.call_stack + def print(self, *args): # pragma: no cover + """Print the state + + Returns: + Chepy: The Chepy object. + """ + print(*args, self.state) + return self + @ChepyDecorators.call_stack def reset(self): """Reset states back to their initial values @@ -1494,7 +1504,7 @@ def register( Examples: >>> c = Chepy("hello world") - >>> c.register("(hello)\s(world)") + >>> c.register(r"(hello)\s(world)") >>> c._registers {'$R0': 'hello', '$R1': 'world'} """ diff --git a/chepy/core.pyi b/chepy/core.pyi index 9be0e93..39994ea 100644 --- a/chepy/core.pyi +++ b/chepy/core.pyi @@ -74,8 +74,9 @@ class ChepyCore: def loop_list(self: ChepyCoreT, callback: Union[str, Callable], args: dict=...) -> ChepyCoreT: ... def loop_dict(self: ChepyCoreT, keys: list, callback: Union[str, Callable], args: dict=...) -> ChepyCoreT: ... def debug(self: ChepyCoreT, verbose: bool=...) -> ChepyCoreT: ... - def reset(self: ChepyCoreT): ... - def load_command(self: ChepyCoreT): ... + def reset(self: ChepyCoreT) -> ChepyCoreT: ... + def print(self: ChepyCoreT) -> ChepyCoreT: ... + def load_command(self: ChepyCoreT) -> ChepyCoreT: ... def pretty(self: ChepyCoreT, indent: int=...) -> ChepyCoreT: ... def plugins(self: ChepyCoreT, enable: Literal['true', 'false']) -> None: ... def set_plugin_path(self: ChepyCoreT, path: str) -> None: ... diff --git a/chepy/modules/dataformat.py b/chepy/modules/dataformat.py index 11561ae..c8a24b0 100644 --- a/chepy/modules/dataformat.py +++ b/chepy/modules/dataformat.py @@ -2157,7 +2157,7 @@ def to_quoted_printable(self) -> DataFormatT: return self @ChepyDecorators.call_stack - def from_rison(self): + def from_rison(self) -> DataFormatT: """Encode to RISON Returns: @@ -2167,7 +2167,7 @@ def from_rison(self): return self @ChepyDecorators.call_stack - def to_rison(self): + def to_rison(self) -> DataFormatT: """Decode from RISON Returns: @@ -2184,3 +2184,39 @@ def to_rison(self): # else: # self._log.error('Invalid data type') return self + + @ChepyDecorators.call_stack + def increment_bytes(self, n: int) -> DataFormatT: + """Loop through each byte and increment + + Args: + n (int): increment by. + + Returns: + Chepy: The Chepy object. + """ + count = int(n) + hold = bytearray() + data = self._convert_to_bytes() + for d in data: + hold.append(d + count) + self.state = bytes(hold) + return self + + @ChepyDecorators.call_stack + def decrement_bytes(self, n: int) -> DataFormatT: + """Loop through each byte and decrement + + Args: + n (int): decrement by. + + Returns: + Chepy: The Chepy object. + """ + count = int(n) + hold = bytearray() + data = self._convert_to_bytes() + for d in data: + hold.append(d - count) + self.state = bytes(hold) + return self diff --git a/chepy/modules/dataformat.pyi b/chepy/modules/dataformat.pyi index e741916..a57c620 100644 --- a/chepy/modules/dataformat.pyi +++ b/chepy/modules/dataformat.pyi @@ -118,3 +118,5 @@ class DataFormat(ChepyCore): def to_quoted_printable(self: DataFormatT) -> DataFormatT: ... def from_rison(self: DataFormatT) -> DataFormatT: ... def to_rison(self: DataFormatT) -> DataFormatT: ... + def increment_bytes(self: DataFormatT, n: int) -> DataFormatT: ... + def decrement_bytes(self: DataFormatT, n: int) -> DataFormatT: ... diff --git a/chepy/modules/encryptionencoding.py b/chepy/modules/encryptionencoding.py index f809465..c090bb4 100644 --- a/chepy/modules/encryptionencoding.py +++ b/chepy/modules/encryptionencoding.py @@ -16,7 +16,6 @@ import lazy_import jwt = lazy_import.lazy_module("jwt") -import pathlib import regex as re import json diff --git a/tests/test_dataformat.py b/tests/test_dataformat.py index 4804b7b..5d98c46 100644 --- a/tests/test_dataformat.py +++ b/tests/test_dataformat.py @@ -783,3 +783,14 @@ def test_base92(): def test_base45(): assert Chepy("+8D VDL2").from_base45().o == b"hello" assert Chepy("hello").to_base45().o == b"+8D VDL2" + + +def test_inc_dec_bytes(): + assert ( + Chepy("gmbh|cc265ceg113b731ec768c9eg95b98175~").decrement_bytes(1).o + == b"flag{bb154bdf002a620db657b8df84a87064}" + ) + assert ( + Chepy("flag{bb154bdf002a620db657b8df84a87064}").increment_bytes(1).o + == b"gmbh|cc265ceg113b731ec768c9eg95b98175~" + )