55
66namespace BinaryNinja
77{
8- public sealed class Platform : AbstractSafeHandle < Platform >
8+ public partial class Platform : AbstractSafeHandle < Platform >
99 {
1010 public Platform ( Architecture arch , string name )
11- : this ( NativeMethods . BNCreatePlatform ( arch . DangerousGetHandle ( ) , name ) , true )
11+ : base ( true )
1212 {
13-
13+ this . custom = true ;
14+ this . InitializeCustomPlatform ( arch , name , null , Array . Empty < string > ( ) ) ;
15+ }
16+
17+ protected Platform (
18+ Architecture arch ,
19+ string name ,
20+ string typeFile ,
21+ string [ ] includeDirs
22+ )
23+ : base ( true )
24+ {
25+ this . custom = true ;
26+ this . InitializeCustomPlatform (
27+ arch , name , typeFile , includeDirs ?? Array . Empty < string > ( )
28+ ) ;
1429 }
1530
1631 internal Platform ( IntPtr handle , bool owner )
@@ -87,7 +102,7 @@ internal static Platform MustBorrowHandle(IntPtr handle)
87102
88103 protected override bool ReleaseHandle ( )
89104 {
90- if ( ! this . IsInvalid )
105+ if ( ! this . IsInvalid && ! this . registered )
91106 {
92107 NativeMethods . BNFreePlatform ( this . handle ) ;
93108 this . SetHandleAsInvalid ( ) ;
@@ -144,6 +159,7 @@ public static string[] GetOSList()
144159 public void RegisterPlatform ( string os )
145160 {
146161 NativeMethods . BNRegisterPlatform ( os , this . handle ) ;
162+ Platform . RootForRegistration ( this ) ;
147163 }
148164
149165 public string Name
@@ -280,10 +296,15 @@ public void SetSystemCallConvention(BinaryNinja.CallingConvention callConvention
280296 ) ;
281297 }
282298
283- public uint [ ] GlobalRegisters
299+ public virtual uint [ ] GlobalRegisters
284300 {
285301 get
286302 {
303+ if ( this . custom )
304+ {
305+ return this . GetDefaultGlobalRegisters ( ) ;
306+ }
307+
287308 IntPtr arrayPointer = NativeMethods . BNGetPlatformGlobalRegisters (
288309 this . handle ,
289310 out ulong arrayLength
@@ -297,10 +318,15 @@ out ulong arrayLength
297318 }
298319 }
299320
300- public ulong AddressSize
321+ public virtual ulong AddressSize
301322 {
302323 get
303324 {
325+ if ( this . custom )
326+ {
327+ return this . Architecture . AddressSize ;
328+ }
329+
304330 return NativeMethods . BNGetPlatformAddressSize ( this . handle ) ;
305331 }
306332 }
@@ -551,8 +577,13 @@ public static unsafe Platform[] GetListByOSAndArchitecture(string os, Architectu
551577 /// <summary>
552578 /// Gets the type of a global register on this platform.
553579 /// </summary>
554- public BinaryNinja . Type ? GetGlobalRegisterType ( uint reg )
580+ public virtual BinaryNinja . Type ? GetGlobalRegisterType ( uint reg )
555581 {
582+ if ( this . custom )
583+ {
584+ return null ;
585+ }
586+
556587 return BinaryNinja . Type . TakeHandle (
557588 NativeMethods . BNGetPlatformGlobalRegisterType ( this . handle , reg )
558589 ) ;
@@ -836,4 +867,4 @@ string[] includeDirs
836867 }
837868 }
838869
839- }
870+ }
0 commit comments