From 6e79b09cd4038b5c9434c30d796d23413bab5252 Mon Sep 17 00:00:00 2001 From: tinysec Date: Wed, 8 Jul 2026 13:35:02 +0800 Subject: [PATCH] fix: Platform calling-convention getters return null instead of throwing DefaultCallingConvention, Cdecl/Stdcall/FastcallCallingConvention, and SystemCallConvention wrapped their handle with CallingConvention.MustTakeHandle, which throws ArgumentNullException when the core returns a null handle. Python's default_calling_convention (and the four siblings) return None for an unset convention. Switch each getter to CallingConvention.TakeHandle (same owner=true ownership, but returns null on IntPtr.Zero) and widen the return type to CallingConvention?, mirroring Architecture.GetCdeclCallingConvention which already does this via NewFromHandle. --- Handle/BNPlatform.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Handle/BNPlatform.cs b/Handle/BNPlatform.cs index 75eacc0..7365c6d 100644 --- a/Handle/BNPlatform.cs +++ b/Handle/BNPlatform.cs @@ -166,51 +166,51 @@ public Architecture Architecture } } - public BinaryNinja.CallingConvention DefaultCallingConvention + public BinaryNinja.CallingConvention? DefaultCallingConvention { get { - return BinaryNinja.CallingConvention.MustTakeHandle( + return BinaryNinja.CallingConvention.TakeHandle( NativeMethods.BNGetPlatformDefaultCallingConvention(this.handle) ); } } - public BinaryNinja.CallingConvention CdeclCallingConvention + public BinaryNinja.CallingConvention? CdeclCallingConvention { get { - return BinaryNinja.CallingConvention.MustTakeHandle( + return BinaryNinja.CallingConvention.TakeHandle( NativeMethods.BNGetPlatformCdeclCallingConvention(this.handle) ); } } - public BinaryNinja.CallingConvention StdcallCallingConvention + public BinaryNinja.CallingConvention? StdcallCallingConvention { get { - return BinaryNinja.CallingConvention.MustTakeHandle( + return BinaryNinja.CallingConvention.TakeHandle( NativeMethods.BNGetPlatformStdcallCallingConvention(this.handle) ); } } - public BinaryNinja.CallingConvention FastcallCallingConvention + public BinaryNinja.CallingConvention? FastcallCallingConvention { get { - return BinaryNinja.CallingConvention.MustTakeHandle( + return BinaryNinja.CallingConvention.TakeHandle( NativeMethods.BNGetPlatformFastcallCallingConvention(this.handle) ); } } - public BinaryNinja.CallingConvention SystemCallConvention + public BinaryNinja.CallingConvention? SystemCallConvention { get { - return BinaryNinja.CallingConvention.MustTakeHandle( + return BinaryNinja.CallingConvention.TakeHandle( NativeMethods.BNGetPlatformSystemCallConvention(this.handle) ); }