@@ -99,6 +99,23 @@ def __eq__(self, other):
99
99
else :
100
100
raise ValueError ("Tried to compare UcAflError to {} ({})" .format ((type (other ), other )))
101
101
102
+ def __handle_input_string (input_file : Optional [str | bytes ]) -> int :
103
+ if isinstance (input_file , str ):
104
+ return \
105
+ ctypes .cast (
106
+ ctypes .create_string_buffer (input_file .encode ('utf-8' )),
107
+ ctypes .c_void_p
108
+ ).value
109
+ elif isinstance (input_file , bytes ):
110
+ return \
111
+ ctypes .cast (
112
+ ctypes .create_string_buffer (input_file ),
113
+ ctypes .c_void_p
114
+ ).value
115
+ elif input_file is None :
116
+ return 0
117
+ else :
118
+ raise TypeError ("Input file should be string or bytes or None" )
102
119
103
120
def uc_afl_fuzz (uc : Uc ,
104
121
input_file : Optional [str | bytes ],
@@ -129,22 +146,7 @@ def uc_afl_fuzz(uc: Uc,
129
146
cb2 = ctypes .cast (UC_AFL_VALIDATE_CRASH_CB (
130
147
_validate_crash_cb ), UC_AFL_VALIDATE_CRASH_CB )
131
148
132
- if isinstance (input_file , str ):
133
- input_file = \
134
- ctypes .cast (
135
- ctypes .create_string_buffer (input_file .encode ('utf-8' )),
136
- ctypes .c_void_p
137
- ).value
138
- elif isinstance (input_file , bytes ):
139
- input_file = \
140
- ctypes .cast (
141
- ctypes .create_string_buffer (input_file ),
142
- ctypes .c_void_p
143
- ).value
144
- elif input_file is None :
145
- input_file = 0
146
- else :
147
- raise TypeError ("Input file should be string or bytes or None" )
149
+ input_file = __handle_input_string (input_file )
148
150
err = uc_afl_fuzz_impl (
149
151
uc ._uch .value ,
150
152
input_file ,
@@ -192,14 +194,7 @@ def uc_afl_fuzz_custom(uc: Uc,
192
194
cb3 = ctypes .cast (UC_AFL_FUZZ_CALLBACK_CB (
193
195
_fuzz_callback_cb ), UC_AFL_FUZZ_CALLBACK_CB )
194
196
195
- if isinstance (input_file , str ):
196
- input_file = ctypes .create_string_buffer (input_file .encode ('utf-8' ))
197
- elif isinstance (input_file , bytes ):
198
- input_file = ctypes .create_string_buffer (input_file )
199
- elif input_file is None :
200
- input_file = 0
201
- else :
202
- raise TypeError ("Input file should be string or bytes or None" )
197
+ input_file = __handle_input_string (input_file )
203
198
err = uc_afl_fuzz_custom_impl (
204
199
uc ._uch .value ,
205
200
input_file ,
0 commit comments