From 174d10fd7f140ecdc31e2a5e4897ccaa4959fa19 Mon Sep 17 00:00:00 2001 From: tinysec Date: Thu, 23 Jul 2026 03:15:35 +0800 Subject: [PATCH] Add context-aware instruction text --- Function/BNGetInstructionTextWithContext.cs | 8 ++--- Handle/BNArchitecture.cs | 38 ++++++++++++++++++++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Function/BNGetInstructionTextWithContext.cs b/Function/BNGetInstructionTextWithContext.cs index 4c4c23c..0f19ef3 100644 --- a/Function/BNGetInstructionTextWithContext.cs +++ b/Function/BNGetInstructionTextWithContext.cs @@ -23,22 +23,22 @@ internal static extern bool BNGetInstructionTextWithContext( IntPtr arch , // const uint8_t* data - IntPtr data , + byte[] data, // uint64_t addr ulong addr , // size_t* len - IntPtr len , + ref UIntPtr len, // void* context IntPtr context , // BNInstructionTextToken** result - IntPtr result , + out IntPtr result, // size_t* count - IntPtr count + out UIntPtr count ); } } diff --git a/Handle/BNArchitecture.cs b/Handle/BNArchitecture.cs index cd3dcbd..5f6c086 100644 --- a/Handle/BNArchitecture.cs +++ b/Handle/BNArchitecture.cs @@ -572,6 +572,42 @@ out arrayLength return tokens; } + public InstructionTextToken[] GetInstructionTextWithContext( + byte[] data, + ulong address, + ref ulong length, + IntPtr context + ) + { + if (null == data) + { + throw new ArgumentNullException(nameof(data)); + } + + UIntPtr nativeLength = new UIntPtr(length); + bool ok = NativeMethods.BNGetInstructionTextWithContext( + this.handle, + data, + address, + ref nativeLength, + context, + out IntPtr tokens, + out UIntPtr count + ); + length = nativeLength.ToUInt64(); + if (!ok) + { + return Array.Empty(); + } + + return UnsafeUtils.TakeStructArrayEx( + tokens, + count.ToUInt64(), + InstructionTextToken.FromNative, + NativeMethods.BNFreeInstructionText + ); + } + public string GetRegisterName(RegisterIndex reg) { return UnsafeUtils.TakeAnsiString( @@ -1190,4 +1226,4 @@ public void SetStdcallCallingConvention(CallingConvention cc) } -} \ No newline at end of file +}