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
4 changes: 2 additions & 2 deletions Function/BNGetDerivedStringCodeReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ internal static extern IntPtr BNGetDerivedStringCodeReferences(
IntPtr str ,

// size_t* count
IntPtr count ,
out UIntPtr count,

// bool limit
bool limit ,
[MarshalAs(UnmanagedType.I1)] bool limit,

// size_t maxItems
UIntPtr maxItems
Expand Down
49 changes: 49 additions & 0 deletions NavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,55 @@ public static DerivedString[] GetDerivedStrings(this BinaryView view)
}
}

/// <summary>
/// Returns code references associated with an analyzed derived string.
/// </summary>
public static ReferenceSource[] GetDerivedStringCodeReferences(
this BinaryView view,
DerivedString derivedString,
ulong? maxItems = null
)
{
if (null == view)
{
throw new ArgumentNullException(nameof(view));
}

if (null == derivedString)
{
throw new ArgumentNullException(nameof(derivedString));
}

BNDerivedString native = derivedString.ToNativeEx();
try
{
using (ScopedAllocator allocator = new ScopedAllocator())
{
IntPtr references = NativeMethods.BNGetDerivedStringCodeReferences(
view.DangerousGetHandle(),
allocator.AllocStruct(native),
out UIntPtr countValue,
maxItems.HasValue,
new UIntPtr(maxItems.GetValueOrDefault())
);

return UnsafeUtils.TakeStructArrayEx<BNReferenceSource, ReferenceSource>(
references,
countValue.ToUInt64(),
ReferenceSource.FromNative,
NativeMethods.BNFreeCodeReferences
);
}
}
finally
{
if (IntPtr.Zero != native.value)
{
NativeMethods.BNFreeStringRef(native.value);
}
}
}

// Adapts BNFreeDerivedStringList (which takes a UIntPtr count) to the
// Action<IntPtr, ulong> signature TakeStructArrayEx expects. Named method, not a
// lambda, per the project's C# style rules.
Expand Down
Loading