From 6dd8f39f846c3f628524a5ab282f41bc947ef475 Mon Sep 17 00:00:00 2001 From: 0x434b Date: Mon, 22 Jul 2024 13:12:50 +0400 Subject: [PATCH 1/2] chore(plugin.json): update metadata --- plugin.json | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugin.json b/plugin.json index c246668..fc0028b 100644 --- a/plugin.json +++ b/plugin.json @@ -1,16 +1,24 @@ { - "api": ["python3"], + "api": [ + "python3" + ], "author": "434b", - "description": "Instruction assembler", + "description": "Interactive shellcode disassembler/assembler", "license": { "name": "Apache 2.0", - "text": "Copyright 2024 0x434b " + "text": "Copyright 2024 0x434b Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." }, "longdescription": "", "minimumbinaryninjaversion": 4526, "name": "Shellcoder", - "platforms": ["Darwin", "Linux", "Windows"], + "platforms": [ + "Darwin", + "Linux", + "Windows" + ], "pluginmetadataversion": 2, - "type": ["helper"], + "type": [ + "helper" + ], "version": "1.0.0" } From d675df45b4fcc0e9f0389313db9a75fe7a9ebe72 Mon Sep 17 00:00:00 2001 From: 0x434b Date: Mon, 22 Jul 2024 13:18:32 +0400 Subject: [PATCH 2/2] chore(__init__): minor error handling improvement --- __init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/__init__.py b/__init__.py index 55b5eb8..0568f61 100644 --- a/__init__.py +++ b/__init__.py @@ -32,8 +32,8 @@ class DisassemblerError(Exception): class Assembler: - def __init__(self): - self.arch = None + def __init__(self) -> None: + self.arch: Architecture = None def set_architecture(self, arch_name: str) -> None: try: @@ -98,7 +98,7 @@ def format_output( assembled_instructions: List[Dict], output_format: str, total_bytes: int, - mnemonic_options: Dict = None, + mnemonic_options: Dict = {}, ) -> str: if total_bytes == 0: return "No instructions to assemble" @@ -133,7 +133,7 @@ def format_output( else: lines.append(f' b"{instr["bytes"].hex()}", # {instr["asm"]}') return ( - f"shellcode = [\n" + "shellcode = [\n" + "\n".join(lines) + f"\n]\n\n# Total length: {total_bytes} bytes\n" f"shellcode_length = {total_bytes}\n" @@ -151,7 +151,7 @@ def format_output( hex_bytes = [f"0x{b:02x}" for b in instr["bytes"]] lines.append(f" {', '.join(hex_bytes)}, // {instr['asm']}") return ( - f"unsigned char shellcode[] = {{\n" + "unsigned char shellcode[] = {{\n" + "\n".join(lines) + f"\n}};\n\n// Total length: {total_bytes} bytes\n" f"const size_t shellcode_length = {total_bytes};" @@ -563,6 +563,8 @@ def highlight_bad_patterns( highlight_format = QTextCharFormat() highlight_format.setBackground(QColor(255, 200, 200)) # Light red background highlight_format.setForeground(QColor(0, 0, 0)) # Black text + start = 0 + length = 0 for result in found_bad_patterns: offset, pattern = result["offset"], result["pattern"] @@ -592,6 +594,10 @@ def highlight_bad_patterns( start = offset * 3 length = pattern_length * 3 - 1 + if not start: + self.show_error("Could not find the start position for highlighting") + if not length: + self.show_error("Could not find the length for highlighting") cursor.setPosition(start) cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, length) cursor.mergeCharFormat(highlight_format)