161 global PESieve_version
162 ptr_size = ctypes.sizeof(ctypes.c_voidp)
164 pesieve_dll =
"pe-sieve32.dll"
166 pesieve_dll =
"pe-sieve64.dll"
168 if 'PESIEVE_DIR' in os.environ:
169 pesieve_dir = os.environ.get(
'PESIEVE_DIR')
171 pesieve_dir = os.path.abspath(os.getcwd())
172 pesieve_path = pesieve_dir + os.path.sep + pesieve_dll
173 lib = ctypes.cdll.LoadLibrary(pesieve_path)
174 PESieve_version = ctypes.cast(lib.PESieve_version, ctypes.POINTER(ctypes.c_uint32)).contents.value
175 if (PESieve_version < PESIEVE_MIN_VER
or PESieve_version > PESIEVE_MAX_VER):
177 exception_msg = f
"Version mismatch: the PE-sieve.dll version ({dll_version_str}) doesn't match the bindings version"
178 raise Exception(exception_msg)
188 if (
not isinstance(params, t_params)):
191 params_size = ctypes.sizeof(t_params)
192 pp = ctypes.create_string_buffer(bytes(params), params_size)
193 pr = ctypes.create_string_buffer(ctypes.sizeof(t_report))
194 lib.PESieve_scan(pr, pp)
195 report = t_report.from_buffer(pr)
198def PESieve_scan_ex(params: t_params, rtype: t_report_type, buf_size: int) -> (t_report, str, int):
201 if (
not isinstance(params, t_params)):
204 pp = ctypes.create_string_buffer(bytes(params), ctypes.sizeof(t_params))
205 pr = ctypes.create_string_buffer(ctypes.sizeof(t_report))
206 out_size = ctypes.c_ulong(0)
207 json_buf = ctypes.create_string_buffer(buf_size)
208 lib.PESieve_scan_ex(pr, pp, rtype, json_buf, buf_size, ctypes.byref(out_size))
209 report = t_report.from_buffer(pr)
211 json_str = json_buf.value.decode(
'UTF-8')
214 return (report, json_str, out_size.value)