Problem with parse_binpat_str

Hi
i have problem using parse_binpat_str

pattern = idaapi.compiled_binpat_vec_t()
start_ea = idaapi.get_screen_ea()
bin_str= "0F A3 0A 08"
if not ida_bytes.parse_binpat_str(pattern, start_ea, bin_str, 16, idaapi.BIN_SEARCH_CASE):
            idaapi.msg(f"❌ Error: Failed to parse binary pattern {bin_str}\n")

is there any other way to search for binary string?

1 Like

Adding

print(len(pattern))
print(pattern[0].bytes)
print(pattern[0].mask)

after your code prints

1
b'\x0f\xa3\n\x08'
b''

So it was parsed successfully.

You might want to change the last parameter though. It should be one of the PBSENC_xxx constants or index of the encoding you want to use.

1 Like

I think you can use ida_bytes.find_bytes if you have a fixed byte sequence.

2 Likes

Self promotion:

I have written some code that will make your life easier when writing scripts. Maybe this will help you?

1 Like

Thanks Igor
I done it with ida_bytes.find_bytes

another question:

before i use

inf = idaapi.get_inf_structure()
is_be = inf.is_be()

to check big/litlle endian, but now this not work

1 Like

Use idaapi.inf_is_be() it’s even documented https://docs.hex-rays.com/developer-guide/idapython/idapython-porting-guide-ida-9#:~:text=inf_is_flat_off32()%20->%20"bool"-,inf_is_be,-()%20->%20"bool".

2 Likes