Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Function/BNSetAutoFunctionInlinedDuringAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BinaryNinja
internal static partial class NativeMethods
{
/// <summary>
/// void BNSetAutoFunctionInlinedDuringAnalysis(BNFunction* func, BNBoolWithConfidence inlined)
/// void BNSetAutoFunctionInlinedDuringAnalysis(BNFunction* func, BNInlineDuringAnalysisWithConfidence inlined)
/// </summary>
[DllImport(
"binaryninjacore",
Expand All @@ -21,9 +21,9 @@ internal static extern void BNSetAutoFunctionInlinedDuringAnalysis(
// BNFunction* func
IntPtr func ,

// BNBoolWithConfidence inlined
BoolWithConfidence inlined
// BNInlineDuringAnalysisWithConfidence inlined
BNInlineDuringAnalysisWithConfidence inlined

);
}
}
}
8 changes: 4 additions & 4 deletions Function/BNSetUserFunctionInlinedDuringAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BinaryNinja
internal static partial class NativeMethods
{
/// <summary>
/// void BNSetUserFunctionInlinedDuringAnalysis(BNFunction* func, BNBoolWithConfidence inlined)
/// void BNSetUserFunctionInlinedDuringAnalysis(BNFunction* func, BNInlineDuringAnalysisWithConfidence inlined)
/// </summary>
[DllImport(
"binaryninjacore",
Expand All @@ -21,9 +21,9 @@ internal static extern void BNSetUserFunctionInlinedDuringAnalysis(
// BNFunction* func
IntPtr func ,

// BNBoolWithConfidence inlined
BoolWithConfidence inlined
// BNInlineDuringAnalysisWithConfidence inlined
BNInlineDuringAnalysisWithConfidence inlined

);
}
}
}
6 changes: 6 additions & 0 deletions Handle/BNBasicBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ public byte[] GetInstructionData(ulong address)

return data;
}

/// <summary>Gets whether instruction data has been attached to this block.</summary>
public bool HasInstructionData
{
get { return NativeMethods.BNBasicBlockHasInstructionData(this.handle); }
}

public void AddInstructionData(byte[] data)
{
Expand Down
5 changes: 5 additions & 0 deletions Handle/BNBinaryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,11 @@ public bool IsOffsetWritableSemantics(ulong offset)
return NativeMethods.BNIsOffsetWritableSemantics(this.handle , offset);
}

public bool IsOffsetReadOnlySemantics(ulong offset)
{
return NativeMethods.BNIsOffsetReadOnlySemantics(this.handle, offset);
}

public bool SaveToFile(FileAccessor accessor)
{
return NativeMethods.BNSaveToFile(this.handle , accessor.ToNative());
Expand Down
18 changes: 18 additions & 0 deletions Handle/BNFileMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ public string Filename
}
}

/// <summary>Gets or sets the user-facing display name for this file.</summary>
public string DisplayName
{
get
{
return UnsafeUtils.TakeUtf8String(NativeMethods.BNGetDisplayName(this.handle));
}
set
{
if (null == value)
{
throw new ArgumentNullException(nameof(value));
}

NativeMethods.BNSetDisplayName(this.handle, value);
}
}

public string OriginalFilename
{
get
Expand Down
80 changes: 75 additions & 5 deletions Handle/BNFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2176,17 +2176,35 @@ public void SetAutoPure(BoolWithConfidence value)
/// </summary>
public void SetAutoFunctionInlinedDuringAnalysis(BoolWithConfidence inlined)
{
// pass the struct directly (by value), matching the P/Invoke signature
NativeMethods.BNSetAutoFunctionInlinedDuringAnalysis(this.handle , inlined);
if (null == inlined)
{
throw new ArgumentNullException(nameof(inlined));
}

InlineDuringAnalysis value = inlined.Value
? InlineDuringAnalysis.InlinePreservingTargetInstructionAddresses
: InlineDuringAnalysis.DoNotInlineCall;
this.SetAutoInlinedDuringAnalysis(
new InlineDuringAnalysisWithConfidence(value, inlined.Confidence)
);
}

/// <summary>
/// Sets the user-defined inlined-during-analysis property for this function.
/// </summary>
public void SetUserFunctionInlinedDuringAnalysis(BoolWithConfidence inlined)
{
// pass the struct directly (by value), matching the P/Invoke signature
NativeMethods.BNSetUserFunctionInlinedDuringAnalysis(this.handle , inlined);
if (null == inlined)
{
throw new ArgumentNullException(nameof(inlined));
}

InlineDuringAnalysis value = inlined.Value
? InlineDuringAnalysis.InlinePreservingTargetInstructionAddresses
: InlineDuringAnalysis.DoNotInlineCall;
this.SetUserInlinedDuringAnalysis(
new InlineDuringAnalysisWithConfidence(value, inlined.Confidence)
);
}

/// <summary>
Expand All @@ -2203,6 +2221,58 @@ public BoolWithConfidence IsFunctionInlinedDuringAnalysis
}
}

/// <summary>Gets the function's current inline-during-analysis mode and confidence.</summary>
public InlineDuringAnalysisWithConfidence InlinedDuringAnalysis
{
get
{
return InlineDuringAnalysisWithConfidence.FromNative(
NativeMethods.BNGetFunctionInlinedDuringAnalysis(this.handle)
);
}
set { this.SetUserInlinedDuringAnalysis(value); }
}

public void SetAutoInlinedDuringAnalysis(InlineDuringAnalysisWithConfidence inlined)
{
if (null == inlined)
{
throw new ArgumentNullException(nameof(inlined));
}

NativeMethods.BNSetAutoFunctionInlinedDuringAnalysis(
this.handle,
inlined.ToNative()
);
}

public void SetAutoInlinedDuringAnalysis(InlineDuringAnalysis inlined)
{
this.SetAutoInlinedDuringAnalysis(
new InlineDuringAnalysisWithConfidence(inlined, byte.MaxValue)
);
}

public void SetUserInlinedDuringAnalysis(InlineDuringAnalysisWithConfidence inlined)
{
if (null == inlined)
{
throw new ArgumentNullException(nameof(inlined));
}

NativeMethods.BNSetUserFunctionInlinedDuringAnalysis(
this.handle,
inlined.ToNative()
);
}

public void SetUserInlinedDuringAnalysis(InlineDuringAnalysis inlined)
{
this.SetUserInlinedDuringAnalysis(
new InlineDuringAnalysisWithConfidence(inlined, byte.MaxValue)
);
}

// ===================================================================
// Clobbered registers (get / set auto / set user)
// ===================================================================
Expand Down Expand Up @@ -5030,4 +5100,4 @@ private unsafe VariableReferenceSource[] MarshalVariableReferenceSources(IntPtr
}

}
}
}
34 changes: 3 additions & 31 deletions Handle/BNLinearViewCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,37 +276,9 @@ public LinearViewObject? CurrentObject
{
get
{
IntPtr arrayPointer = NativeMethods.BNGetLinearViewCursorPathObjects(
this.handle,
out ulong arrayLength
return LinearViewObject.TakeHandle(
NativeMethods.BNGetLinearViewCursorCurrentObject(this.handle)
);

LinearViewObject? view = null;

if (( IntPtr.Zero != arrayPointer ) && ( 0 != arrayLength ))
{
for (ulong i = 0; i < arrayLength; i++)
{
int offset = checked((int)(i * (ulong)IntPtr.Size));

IntPtr addressOfElement = IntPtr.Add(arrayPointer, offset);

IntPtr element = Marshal.ReadIntPtr(addressOfElement);

if (element != IntPtr.Zero)
{
// object chain
view = LinearViewObject.MustNewFromHandle(element, view);
}
}
}

if (arrayPointer != IntPtr.Zero )
{
NativeMethods.BNFreeLinearViewCursorPathObjects(arrayPointer ,arrayLength);
}

return view;
}
}

Expand Down Expand Up @@ -456,4 +428,4 @@ out ulong arrayLength
}
}
}
}
}
6 changes: 6 additions & 0 deletions Handle/BNLowLevelILFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,12 @@ public void ClearIndirectBranches()
NativeMethods.BNLowLevelILClearIndirectBranches(this.handle);
}

/// <summary>Gets whether this LLIL function contains unresolved indirect branches.</summary>
public bool HasIndirectBranches
{
get { return NativeMethods.BNLowLevelILFunctionHasIndirectBranches(this.handle); }
}

public void SetIndirectBranches(ArchitectureAndAddress[] branches)
{
NativeMethods.BNLowLevelILSetIndirectBranches(
Expand Down
33 changes: 33 additions & 0 deletions Struct/BNInlineDuringAnalysisWithConfidence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,37 @@ internal unsafe struct BNInlineDuringAnalysisWithConfidence
/// </summary>
internal byte confidence;
}

public sealed class InlineDuringAnalysisWithConfidence
{
public InlineDuringAnalysis Value { get; set; } = InlineDuringAnalysis.DoNotInlineCall;

public byte Confidence { get; set; } = 0;

public InlineDuringAnalysisWithConfidence()
{
}

public InlineDuringAnalysisWithConfidence(InlineDuringAnalysis value, byte confidence = 0)
{
this.Value = value;
this.Confidence = confidence;
}

internal static InlineDuringAnalysisWithConfidence FromNative(
BNInlineDuringAnalysisWithConfidence native
)
{
return new InlineDuringAnalysisWithConfidence(native.value, native.confidence);
}

internal BNInlineDuringAnalysisWithConfidence ToNative()
{
return new BNInlineDuringAnalysisWithConfidence()
{
value = this.Value,
confidence = this.Confidence,
};
}
}
}
Loading