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
2 changes: 1 addition & 1 deletion Function/BNGetStringRecognizerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static partial class NativeMethods
internal static extern IntPtr BNGetStringRecognizerList(

// size_t* count
IntPtr count
out ulong count
);
}
}
2 changes: 1 addition & 1 deletion Function/BNRegisterStringRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static extern IntPtr BNRegisterStringRecognizer(
[MarshalAs(UnmanagedType.LPUTF8Str)] string name ,

// BNCustomStringRecognizer* recognizer
IntPtr recognizer
in BNCustomStringRecognizer recognizer
);
}
}
2 changes: 1 addition & 1 deletion Function/BNStringRecognizerRecognizeConstant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static extern bool BNStringRecognizerRecognizeConstant(
long val ,

// BNDerivedString* out
IntPtr @out
out BNDerivedString @out
);
}
}
2 changes: 1 addition & 1 deletion Function/BNStringRecognizerRecognizeConstantPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static extern bool BNStringRecognizerRecognizeConstantPointer(
long val ,

// BNDerivedString* out
IntPtr @out
out BNDerivedString @out
);
}
}
2 changes: 1 addition & 1 deletion Function/BNStringRecognizerRecognizeExternPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal static extern bool BNStringRecognizerRecognizeExternPointer(
ulong offset ,

// BNDerivedString* out
IntPtr @out
out BNDerivedString @out
);
}
}
2 changes: 1 addition & 1 deletion Function/BNStringRecognizerRecognizeImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static extern bool BNStringRecognizerRecognizeImport(
long val ,

// BNDerivedString* out
IntPtr @out
out BNDerivedString @out
);
}
}
38 changes: 31 additions & 7 deletions NavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,33 @@ public sealed class DerivedString

public ulong Length { get; }

public CustomStringType? CustomType { get; }

/// <summary>
/// Constructs a value-only DerivedString with no location, mirroring Python
/// <c>DerivedString(value=..., location=None, custom_type=None)</c> for the common case of
/// attaching a derived string via
/// <see cref="HighLevelILFunction.SetDerivedStringReferenceForExpr"/>.
/// </summary>
public DerivedString(string value)
: this(value, false, 0, 0UL, 0UL)
: this(value, false, 0, 0UL, 0UL, null)
{
}

/// <summary>Constructs a derived string with an explicit source location and type.</summary>
public DerivedString(
string value,
DerivedStringLocationType locationType,
ulong address,
ulong length,
CustomStringType? customType = null)
: this(value, true, (int)locationType, address, length, customType)
{
}

/// <summary>Constructs a value-only derived string with an explicit custom type.</summary>
public DerivedString(string value, CustomStringType customType)
: this(value, false, 0, 0UL, 0UL, customType)
{
}

Expand All @@ -96,13 +115,15 @@ private DerivedString(
bool locationValid,
int locationType,
ulong addr,
ulong len)
ulong len,
CustomStringType? customType)
{
this.Value = value;
this.LocationValid = locationValid;
this.LocationType = (DerivedStringLocationType)locationType;
this.Address = addr;
this.Length = len;
this.CustomType = customType;
}

// Reads one BNDerivedString out of a by-value native array. Must run before the array
Expand All @@ -117,17 +138,18 @@ internal static DerivedString FromNative(BNDerivedString raw)
raw.locationValid,
raw.location.locationType,
raw.location.addr,
raw.location.len
raw.location.len,
CustomStringType.FromHandle(raw.customType)
);
}

// Re-materializes this projection as a native BNDerivedString for the Set path
// (BNSetHighLevelILDerivedStringReferenceForExpr). The Value text is rebuilt as a fresh
// BNStringRef* because this projection reads eagerly and does not retain the original core
// handle. The caller owns that BNStringRef* and must free it (BNFreeStringRef) once the
// core has consumed the struct: core copies/add-refs the string, mirroring Python's
// owned=False borrow. custom_type is not surfaced by this read-only projection (Python
// CustomStringType handle is dropped), so it is left null.
// core has consumed the struct: core copies/add-refs the string for setter calls, while
// recognizer callbacks transfer the owned reference to the core caller. The custom type
// is a static core handle and is passed through without an additional reference.
internal BNDerivedString ToNativeEx()
{
ulong byteCount = (ulong)Encoding.UTF8.GetByteCount(this.Value);
Expand All @@ -147,7 +169,9 @@ internal BNDerivedString ToNativeEx()
native.location.len = this.Length;
}

native.customType = IntPtr.Zero;
native.customType = null == this.CustomType
? IntPtr.Zero
: this.CustomType.DangerousGetHandle();

return native;
}
Expand Down
Loading
Loading