Hexrays Toolbox (HXTB) เป็นชุดที่ทรงพลังของสคริปต์ Idapython ที่สามารถใช้ในการค้นหาและค้นหารูปแบบรหัสในไบนารีซึ่งเป็นอิสระจากสถาปัตยกรรมโปรเซสเซอร์พื้นฐาน
แบบสอบถามที่แสดงโดยแอนิเมชั่นด้านล่างเป็นตัวอย่างสำหรับความเสี่ยงที่ส่งผลกระทบต่อ WhatsApp สำหรับ Android (CVE-2019-3568, Libwhatsapp.so) โดยใช้กล่องเครื่องมือ hexrays สิ่งนี้ทำได้โดยการกำหนดรูปแบบรหัสที่ต้องการซึ่งจะอยู่โดยใช้ฟังก์ชัน Idapython Lambda ค้นหาสคริปต์ตัวอย่าง
-

ต้องใช้ใบอนุญาต IDA ที่ถูกต้องและต้องใช้ใบอนุญาต hexrays decompiler ที่ถูกต้องต่อสถาปัตยกรรมเป้าหมาย
มีหลายวิธีในการใช้กล่องเครื่องมือ hexrays แต่ละอันมีระดับความยืดหยุ่นที่แตกต่างกัน
interactive.py สคริปต์ที่เพิ่มฟังก์ชั่นความสะดวกที่จะใช้กับอินเตอร์เฟสบรรทัดคำสั่ง IDAautomation.py สคริปต์ที่ประมวลผลและเรียกใช้การสืบค้น HXTB ในชุดไฟล์ที่กำหนดในโหมดแบทช์ การดำเนินการสคริปต์ hxtb_shell.py ที่รวมอยู่จากภายใน IDA เปิดหน้าต่าง GUI ที่สามารถใช้ในการพัฒนาโหลดและเรียกใช้การสืบค้น HXTB ภาพหน้าจอด้านล่างแสดงให้เห็นว่าแบบสอบถามที่โหลดด้วย HXTB-Shell อาจมีลักษณะอย่างไร

HXTB-Shell ยังยอมรับการแสดงออกของ Python ที่สร้างขึ้นโดยผู้ชมบริบทของปลั๊กอิน Hrdevhelper พวกเขาสามารถคัดลอกได้จากมันและวางลงใน HXTB-Shell GUI โดยตรง

ตัวอย่างเพิ่มเติมที่สามารถโหลดได้ด้วย HXTB-Shell สามารถพบได้ในโฟลเดอร์ย่อย hxtbshell_queries ที่มาพร้อมกับกล่องเครื่องมือ Hexrays
การโหลด hxtb.py ด้วย IDA (ALT-F7) ทำให้ฟังก์ชั่นเช่น find_expr() และ find_item() มีให้ทั้ง Idapython CLI และ Interpreter สคริปต์ (Shift-F2) ในบรรดาฟังก์ชั่นเหล่านี้สามารถใช้เพื่อเรียกใช้การสืบค้นบนฐานข้อมูล IDA ที่โหลดในปัจจุบัน โปรดตรวจสอบตัวอย่างบางส่วนที่แสดงด้านล่าง
find_item(ea, q)
find_expr(ea, q)
Positional arguments:
ea: address of a valid function within
the current database
q: lambda function
custom lambda function with the following arguments:
1. cfunc: cfunc_t
2. i/e: cinsn_t/cexpr_t
Returns:
list of query_result_t objects
Example:
find_expr(here(), lambda cf, e: e.op is cot_call)
-> finds and returns all function calls within a current function.
The returned data is a list of query_result_t objects (see hxtb.py).
The returned list can be passed to an instance of the ic_t class,
which causes the data to be displayed by a chooser as follows:
from idaapi import *
import hxtb
hxtb.ic_t(find_expr(here(), lambda cf,e:e.op is cot_call))
Please find the cfunc_t, citem_t, cinsn_t and cexpr_t structures
within hexrays.hpp for further help and details.
cot_eq
/
x / y
(anything) cot_num --- n.numval() == 0
from idaapi import *
from hxtb import find_expr
query = lambda cfunc , e : e . op is cot_eq and e . y . op is cot_num and e . y . numval () == 0
r = find_expr ( here (), query )
for e in r :
print ( e ) cot_call
/
x /
cot_obj
from idaapi import *
from hxtb import find_expr
query = lambda cfunc , e : e . op is cot_call and e . x . op is cot_obj
r = find_expr ( here (), query )
for e in r :
print ( e )
cot_call --- arg1 is cot_var
/ arg1 is on stack
x /
cot_obj --- name(obj_ea) == 'memcpy'
from idaapi import *
from hxtb import find_expr
r = []
query = lambda cfunc , e : ( e . op is cot_call and
e . x . op is cot_obj and
get_name ( e . x . obj_ea ) == 'memcpy' and
len ( e . a ) == 3 and
e . a [ 0 ]. op is cot_var and
cfunc . lvars [ e . a [ 0 ]. v . idx ]. is_stk_var ())
for ea in Functions ():
r += find_expr ( ea , query )
for e in r :
print ( e ) cot_call --- arg2 ('fmt') contains '%s'
/
x /
cot_obj --- name(obj_ea) == 'sprintf'
from idaapi import *
from hxtb import find_expr
r = []
query = lambda cfunc , e : ( e . op is cot_call and
e . x . op is cot_obj and
get_name ( e . x . obj_ea ) == 'sprintf' and
len ( e . a ) >= 2 and
e . a [ 1 ]. op is cot_obj and
is_strlit ( get_flags ( get_item_head ( e . a [ 1 ]. obj_ea ))) and
b'%s' in get_strlit_contents ( e . a [ 1 ]. obj_ea , - 1 , 0 , STRCONV_ESCAPE ))
for ea in Functions ():
r += find_expr ( ea , query )
for e in r :
print ( e ) from idaapi import *
from hxtb import ic_t
query = lambda cfunc , e : ( e . op in
[ cot_asgsshr , cot_asgsdiv ,
cot_asgsmod , cot_sge ,
cot_sle , cot_sgt ,
cot_slt , cot_sshr ,
cot_sdiv , cot_smod ])
ic_t ( query )
from idaapi import *
from hxtb import ic_t
ic_t ( lambda cf , i : i . op is cit_if )
from idaapi import *
from hxtb import ic_t , query_db
ic_t ( query_db ( lambda cf , i : is_loop ( i . op )))
from hxtb import ic_t , query_db , find_child_expr
from ida_hexrays import *
find_copy_query = lambda cfunc , i : ( i . op is cot_asg and
i . x . op is cot_ptr and
i . y . op is cot_ptr )
find_loop_query = lambda cfunc , i : ( is_loop ( i . op ) and
find_child_expr ( cfunc , i , find_copy_query ))
ic_t ( query_db ( find_loop_query ))