Skip to content

Commit 599192f

Browse files
committed
Add class to output the decompule C syntax.
Relate #11.
1 parent be32b09 commit 599192f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/c.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

0 commit comments

Comments
 (0)