File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ from binaryninja .function import Function , DisassemblySettings
2+ from binaryninja .enums import DisassemblyOption
3+ from binaryninja .lineardisassembly import LinearViewObject , LinearViewCursor , \
4+ LinearDisassemblyLine
5+ from binaryninja import BinaryView
6+
7+
8+ class Pseudo_C :
9+
10+ def __init__ (self , bv : BinaryView , func : Function ) -> None :
11+ self .bv = bv
12+ self .func = func
13+
14+ def get_c_source (self ) -> list [str ]:
15+ '''Returns a list of strings representing the C source code for the
16+ function.'''
17+ lines : list [str ] = []
18+ settings : DisassemblySettings = DisassemblySettings ()
19+ settings .set_option (DisassemblyOption .ShowAddress , False )
20+
21+ linear_view : LinearViewObject = LinearViewObject .language_representation (
22+ self .bv , settings )
23+ cursor_end : LinearViewCursor = LinearViewCursor (linear_view )
24+ cursor_end .seek_to_address (self .func .highest_address )
25+
26+ body : list [
27+ LinearDisassemblyLine ] = self .bv .get_next_linear_disassembly_lines (
28+ cursor_end )
29+ cursor_end .seek_to_address (self .func .highest_address )
30+
31+ header : list [
32+ LinearDisassemblyLine ] = self .bv .get_previous_linear_disassembly_lines (
33+ cursor_end )
34+
35+ for line in header :
36+ lines .append (str (line ))
37+ for line in body :
38+ lines .append (str (line ))
39+ return lines
You can’t perform that action at this time.
0 commit comments