Skip to content

Commit 0084531

Browse files
committed
Expose AnalysisContext::GetLiftedILFunction properly
It was already grabbing the Lifted IL through the function object, which may not be the most up to date
1 parent 7734615 commit 0084531

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

binaryninjaapi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10028,6 +10028,12 @@ namespace BinaryNinja {
1002810028
*/
1002910029
Ref<Function> GetFunction();
1003010030

10031+
/*! Get the lifted IL function for the current AnalysisContext
10032+
10033+
\return The Lifted IL LowLevelILFunction for the current context
10034+
*/
10035+
Ref<LowLevelILFunction> GetLiftedILFunction();
10036+
1003110037
/*! Get the low level IL function for the current AnalysisContext
1003210038

1003310039
\return The LowLevelILFunction for the current context

binaryninjacore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5485,6 +5485,7 @@ extern "C"
54855485
BINARYNINJACOREAPI void BNFreeAnalysisContext(BNAnalysisContext* analysisContext);
54865486
BINARYNINJACOREAPI BNBinaryView* BNAnalysisContextGetBinaryView(BNAnalysisContext* analysisContext);
54875487
BINARYNINJACOREAPI BNFunction* BNAnalysisContextGetFunction(BNAnalysisContext* analysisContext);
5488+
BINARYNINJACOREAPI BNLowLevelILFunction* BNAnalysisContextGetLiftedILFunction(BNAnalysisContext* analysisContext);
54885489
BINARYNINJACOREAPI BNLowLevelILFunction* BNAnalysisContextGetLowLevelILFunction(BNAnalysisContext* analysisContext);
54895490
BINARYNINJACOREAPI BNMediumLevelILFunction* BNAnalysisContextGetMediumLevelILFunction(
54905491
BNAnalysisContext* analysisContext);

python/workflow.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, handle: core.BNAnalysisContextHandle):
5353
self.handle = handle
5454

5555
@property
56-
def view(self) -> 'binaryview.BinaryView':
56+
def view(self) -> Optional['binaryview.BinaryView']:
5757
"""
5858
BinaryView for the current AnalysisContext (writable)
5959
"""
@@ -63,7 +63,7 @@ def view(self) -> 'binaryview.BinaryView':
6363
return binaryview.BinaryView(handle=result)
6464

6565
@property
66-
def function(self) -> '_function.Function':
66+
def function(self) -> Optional['_function.Function']:
6767
"""
6868
Function for the current AnalysisContext (read-only)
6969
"""
@@ -73,18 +73,21 @@ def function(self) -> '_function.Function':
7373
return _function.Function(handle=result)
7474

7575
@property
76-
def lifted_il(self) -> lowlevelil.LowLevelILFunction:
76+
def lifted_il(self) -> Optional[lowlevelil.LowLevelILFunction]:
7777
"""
7878
LowLevelILFunction used to represent lifted IL (writable)
7979
"""
80-
return self.function.lifted_il
80+
result = core.BNAnalysisContextGetLiftedILFunction(self.handle)
81+
if not result:
82+
return None
83+
return lowlevelil.LowLevelILFunction(handle=result)
8184

8285
@lifted_il.setter
8386
def lifted_il(self, lifted_il: lowlevelil.LowLevelILFunction) -> None:
8487
core.BNSetLiftedILFunction(self.handle, lifted_il.handle)
8588

8689
@property
87-
def llil(self) -> lowlevelil.LowLevelILFunction:
90+
def llil(self) -> Optional[lowlevelil.LowLevelILFunction]:
8891
"""
8992
LowLevelILFunction used to represent Low Level IL (writable)
9093
"""
@@ -98,7 +101,7 @@ def llil(self, value: lowlevelil.LowLevelILFunction) -> None:
98101
core.BNSetLowLevelILFunction(self.handle, value.handle)
99102

100103
@property
101-
def mlil(self) -> mediumlevelil.MediumLevelILFunction:
104+
def mlil(self) -> Optional[mediumlevelil.MediumLevelILFunction]:
102105
"""
103106
MediumLevelILFunction used to represent Medium Level IL (writable)
104107
"""
@@ -112,7 +115,7 @@ def mlil(self, value: mediumlevelil.MediumLevelILFunction) -> None:
112115
core.BNSetMediumLevelILFunction(self.handle, value.handle)
113116

114117
@property
115-
def hlil(self) -> highlevelil.HighLevelILFunction:
118+
def hlil(self) -> Optional[highlevelil.HighLevelILFunction]:
116119
"""
117120
HighLevelILFunction used to represent High Level IL (writable)
118121
"""

rust/src/workflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl AnalysisContext {
5151
&self,
5252
) -> Option<Ref<MutableLiftedILFunction<CoreArchitecture>>> {
5353
let func = self.function();
54-
let result = unsafe { BNGetFunctionLiftedIL(func.handle) };
54+
let result = unsafe { BNAnalysisContextGetLiftedILFunction(self.handle.as_ptr()) };
5555
let arch = self.function().arch();
5656
unsafe {
5757
Some(LowLevelILFunction::ref_from_raw(

workflow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ Ref<Function> AnalysisContext::GetFunction()
4141
}
4242

4343

44+
Ref<LowLevelILFunction> AnalysisContext::GetLiftedILFunction()
45+
{
46+
BNLowLevelILFunction* func = BNAnalysisContextGetLiftedILFunction(m_object);
47+
if (!func)
48+
return nullptr;
49+
return new LowLevelILFunction(func);
50+
}
51+
52+
4453
Ref<LowLevelILFunction> AnalysisContext::GetLowLevelILFunction()
4554
{
4655
BNLowLevelILFunction* func = BNAnalysisContextGetLowLevelILFunction(m_object);

0 commit comments

Comments
 (0)