@@ -32,8 +32,8 @@ class DisassemblerError(Exception):
32
32
33
33
34
34
class Assembler :
35
- def __init__ (self ):
36
- self .arch = None
35
+ def __init__ (self ) -> None :
36
+ self .arch : Architecture = None
37
37
38
38
def set_architecture (self , arch_name : str ) -> None :
39
39
try :
@@ -98,7 +98,7 @@ def format_output(
98
98
assembled_instructions : List [Dict ],
99
99
output_format : str ,
100
100
total_bytes : int ,
101
- mnemonic_options : Dict = None ,
101
+ mnemonic_options : Dict = {} ,
102
102
) -> str :
103
103
if total_bytes == 0 :
104
104
return "No instructions to assemble"
@@ -133,7 +133,7 @@ def format_output(
133
133
else :
134
134
lines .append (f' b"{ instr ["bytes" ].hex ()} ", # { instr ["asm" ]} ' )
135
135
return (
136
- f "shellcode = [\n "
136
+ "shellcode = [\n "
137
137
+ "\n " .join (lines )
138
138
+ f"\n ]\n \n # Total length: { total_bytes } bytes\n "
139
139
f"shellcode_length = { total_bytes } \n "
@@ -151,7 +151,7 @@ def format_output(
151
151
hex_bytes = [f"0x{ b :02x} " for b in instr ["bytes" ]]
152
152
lines .append (f" { ', ' .join (hex_bytes )} , // { instr ['asm' ]} " )
153
153
return (
154
- f "unsigned char shellcode[] = {{\n "
154
+ "unsigned char shellcode[] = {{\n "
155
155
+ "\n " .join (lines )
156
156
+ f"\n }};\n \n // Total length: { total_bytes } bytes\n "
157
157
f"const size_t shellcode_length = { total_bytes } ;"
@@ -563,6 +563,8 @@ def highlight_bad_patterns(
563
563
highlight_format = QTextCharFormat ()
564
564
highlight_format .setBackground (QColor (255 , 200 , 200 )) # Light red background
565
565
highlight_format .setForeground (QColor (0 , 0 , 0 )) # Black text
566
+ start = 0
567
+ length = 0
566
568
567
569
for result in found_bad_patterns :
568
570
offset , pattern = result ["offset" ], result ["pattern" ]
@@ -592,6 +594,10 @@ def highlight_bad_patterns(
592
594
start = offset * 3
593
595
length = pattern_length * 3 - 1
594
596
597
+ if not start :
598
+ self .show_error ("Could not find the start position for highlighting" )
599
+ if not length :
600
+ self .show_error ("Could not find the length for highlighting" )
595
601
cursor .setPosition (start )
596
602
cursor .movePosition (QTextCursor .Right , QTextCursor .KeepAnchor , length )
597
603
cursor .mergeCharFormat (highlight_format )
0 commit comments