diff --git a/.gitignore b/.gitignore index 07d95bc..91b7125 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ bin/ dist/ build/ Folder.DotSettings.user +temp/ diff --git a/Function/BNCreateAutoStackVariable.cs b/Function/BNCreateAutoStackVariable.cs index 7b17900..6776a2a 100644 --- a/Function/BNCreateAutoStackVariable.cs +++ b/Function/BNCreateAutoStackVariable.cs @@ -25,7 +25,7 @@ internal static extern void BNCreateAutoStackVariable( long offset , // BNTypeWithConfidence* type - IntPtr type , + in BNTypeWithConfidence type , // const char* name string name diff --git a/Function/BNCreateAutoVariable.cs b/Function/BNCreateAutoVariable.cs index 20a7dd2..0ac69eb 100644 --- a/Function/BNCreateAutoVariable.cs +++ b/Function/BNCreateAutoVariable.cs @@ -22,10 +22,10 @@ internal static extern void BNCreateAutoVariable( IntPtr func , // BNVariable* _var - IntPtr _var , + in BNVariable _var , // BNTypeWithConfidence* type - IntPtr type , + in BNTypeWithConfidence type , // const char* name string name , diff --git a/Function/BNCreateUserStackVariable.cs b/Function/BNCreateUserStackVariable.cs index 328364b..3e28fc3 100644 --- a/Function/BNCreateUserStackVariable.cs +++ b/Function/BNCreateUserStackVariable.cs @@ -25,7 +25,7 @@ internal static extern void BNCreateUserStackVariable( long offset , // BNTypeWithConfidence* type - IntPtr type , + in BNTypeWithConfidence type , // const char* name string name diff --git a/Function/BNCreateUserVariable.cs b/Function/BNCreateUserVariable.cs index 0aa2095..2681053 100644 --- a/Function/BNCreateUserVariable.cs +++ b/Function/BNCreateUserVariable.cs @@ -22,10 +22,10 @@ internal static extern void BNCreateUserVariable( IntPtr func , // BNVariable* _var - IntPtr _var , + in BNVariable _var , // BNTypeWithConfidence* type - IntPtr type , + in BNTypeWithConfidence type , // const char* name string name , diff --git a/Function/BNDeleteAutoStackVariable.cs b/Function/BNDeleteAutoStackVariable.cs index 72ee2cc..9e56ff1 100644 --- a/Function/BNDeleteAutoStackVariable.cs +++ b/Function/BNDeleteAutoStackVariable.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNDeleteAutoStackVariable" )] internal static extern void BNDeleteAutoStackVariable( @@ -23,7 +22,6 @@ internal static extern void BNDeleteAutoStackVariable( // int64_t offset long offset - ); } } \ No newline at end of file diff --git a/Function/BNDeleteUserStackVariable.cs b/Function/BNDeleteUserStackVariable.cs index 88e3c1e..fa3b8de 100644 --- a/Function/BNDeleteUserStackVariable.cs +++ b/Function/BNDeleteUserStackVariable.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNDeleteUserStackVariable" )] internal static extern void BNDeleteUserStackVariable( @@ -23,7 +22,6 @@ internal static extern void BNDeleteUserStackVariable( // int64_t offset long offset - ); } } \ No newline at end of file diff --git a/Function/BNDeleteUserVariable.cs b/Function/BNDeleteUserVariable.cs index e2e4c47..d3eeacb 100644 --- a/Function/BNDeleteUserVariable.cs +++ b/Function/BNDeleteUserVariable.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNDeleteUserVariable" )] internal static extern void BNDeleteUserVariable( @@ -22,8 +21,7 @@ internal static extern void BNDeleteUserVariable( IntPtr func , // BNVariable* _var - IntPtr _var - + in BNVariable _var ); } } \ No newline at end of file diff --git a/Function/BNGetCalleeForAnalysis.cs b/Function/BNGetCalleeForAnalysis.cs index 62697e2..fc01ee2 100644 --- a/Function/BNGetCalleeForAnalysis.cs +++ b/Function/BNGetCalleeForAnalysis.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNGetCalleeForAnalysis" )] internal static extern IntPtr BNGetCalleeForAnalysis( @@ -29,7 +28,6 @@ internal static extern IntPtr BNGetCalleeForAnalysis( // bool exact bool exact - ); } } \ No newline at end of file diff --git a/Function/BNGetInstructionHighlight.cs b/Function/BNGetInstructionHighlight.cs index 8bfc87f..ef8d4fa 100644 --- a/Function/BNGetInstructionHighlight.cs +++ b/Function/BNGetInstructionHighlight.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNGetInstructionHighlight" )] internal static extern BNHighlightColor BNGetInstructionHighlight( @@ -26,7 +25,6 @@ internal static extern BNHighlightColor BNGetInstructionHighlight( // uint64_t addr ulong addr - ); } } \ No newline at end of file diff --git a/Function/BNGetVariableType.cs b/Function/BNGetVariableType.cs index f93751c..037a7ba 100644 --- a/Function/BNGetVariableType.cs +++ b/Function/BNGetVariableType.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNGetVariableType" )] internal static extern BNTypeWithConfidence BNGetVariableType( @@ -22,8 +21,7 @@ internal static extern BNTypeWithConfidence BNGetVariableType( IntPtr func , // BNVariable* _var - IntPtr _var - + in BNVariable _var ); } } \ No newline at end of file diff --git a/Function/BNIsCallInstruction.cs b/Function/BNIsCallInstruction.cs index cfbd648..ae1eb27 100644 --- a/Function/BNIsCallInstruction.cs +++ b/Function/BNIsCallInstruction.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNIsCallInstruction" )] internal static extern bool BNIsCallInstruction( @@ -26,7 +25,6 @@ internal static extern bool BNIsCallInstruction( // uint64_t addr ulong addr - ); } } \ No newline at end of file diff --git a/Function/BNSetAutoFunctionCallingConvention.cs b/Function/BNSetAutoFunctionCallingConvention.cs index a30a5aa..9ac204a 100644 --- a/Function/BNSetAutoFunctionCallingConvention.cs +++ b/Function/BNSetAutoFunctionCallingConvention.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNSetAutoFunctionCallingConvention" )] internal static extern void BNSetAutoFunctionCallingConvention( @@ -22,8 +21,7 @@ internal static extern void BNSetAutoFunctionCallingConvention( IntPtr func , // BNCallingConventionWithConfidence* convention - IntPtr convention - + in BNCallingConventionWithConfidence convention ); } } \ No newline at end of file diff --git a/Function/BNSetAutoFunctionCanReturn.cs b/Function/BNSetAutoFunctionCanReturn.cs index 11108f1..c172013 100644 --- a/Function/BNSetAutoFunctionCanReturn.cs +++ b/Function/BNSetAutoFunctionCanReturn.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNSetAutoFunctionCanReturn" )] internal static extern void BNSetAutoFunctionCanReturn( @@ -22,8 +21,7 @@ internal static extern void BNSetAutoFunctionCanReturn( IntPtr func , // BNBoolWithConfidence* returns - IntPtr returns - + in BNBoolWithConfidence returns ); } } \ No newline at end of file diff --git a/Function/BNSetAutoFunctionHasVariableArguments.cs b/Function/BNSetAutoFunctionHasVariableArguments.cs index 4bff5e8..f78b6f2 100644 --- a/Function/BNSetAutoFunctionHasVariableArguments.cs +++ b/Function/BNSetAutoFunctionHasVariableArguments.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNSetAutoFunctionHasVariableArguments" )] internal static extern void BNSetAutoFunctionHasVariableArguments( @@ -22,8 +21,7 @@ internal static extern void BNSetAutoFunctionHasVariableArguments( IntPtr func , // BNBoolWithConfidence* varArgs - IntPtr varArgs - + in BNBoolWithConfidence varArgs ); } } \ No newline at end of file diff --git a/Function/BNSetAutoFunctionParameterVariables.cs b/Function/BNSetAutoFunctionParameterVariables.cs index f9b8caf..c26719f 100644 --- a/Function/BNSetAutoFunctionParameterVariables.cs +++ b/Function/BNSetAutoFunctionParameterVariables.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNSetAutoFunctionParameterVariables" )] internal static extern void BNSetAutoFunctionParameterVariables( @@ -22,8 +21,7 @@ internal static extern void BNSetAutoFunctionParameterVariables( IntPtr func , // BNParameterVariablesWithConfidence* vars - IntPtr vars - + in BNParameterVariablesWithConfidence vars ); } } \ No newline at end of file diff --git a/Function/BNSetAutoFunctionPure.cs b/Function/BNSetAutoFunctionPure.cs index 4acfeab..dad854a 100644 --- a/Function/BNSetAutoFunctionPure.cs +++ b/Function/BNSetAutoFunctionPure.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNSetAutoFunctionPure" )] internal static extern void BNSetAutoFunctionPure( @@ -22,8 +21,7 @@ internal static extern void BNSetAutoFunctionPure( IntPtr func , // BNBoolWithConfidence* pure - IntPtr pure - + in BNBoolWithConfidence pure ); } } \ No newline at end of file diff --git a/Function/BNSetAutoFunctionReturnType.cs b/Function/BNSetAutoFunctionReturnType.cs index 3f5392c..e642fef 100644 --- a/Function/BNSetAutoFunctionReturnType.cs +++ b/Function/BNSetAutoFunctionReturnType.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNSetAutoFunctionReturnType" )] internal static extern void BNSetAutoFunctionReturnType( @@ -22,8 +21,7 @@ internal static extern void BNSetAutoFunctionReturnType( IntPtr func , // BNTypeWithConfidence* type - IntPtr type - + in BNTypeWithConfidence type ); } } \ No newline at end of file diff --git a/Function/BNSetAutoInstructionHighlight.cs b/Function/BNSetAutoInstructionHighlight.cs index 07515fb..d7ab601 100644 --- a/Function/BNSetAutoInstructionHighlight.cs +++ b/Function/BNSetAutoInstructionHighlight.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNSetAutoInstructionHighlight" )] internal static extern void BNSetAutoInstructionHighlight( @@ -28,8 +27,7 @@ internal static extern void BNSetAutoInstructionHighlight( ulong addr , // BNHighlightColor color - HighlightColor color - + in BNHighlightColor color ); } } \ No newline at end of file diff --git a/Function/BNSetUserInstructionHighlight.cs b/Function/BNSetUserInstructionHighlight.cs index a0ad91d..172c569 100644 --- a/Function/BNSetUserInstructionHighlight.cs +++ b/Function/BNSetUserInstructionHighlight.cs @@ -13,7 +13,6 @@ internal static partial class NativeMethods [DllImport( "binaryninjacore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, - CharSet = CharSet.Ansi, EntryPoint = "BNSetUserInstructionHighlight" )] internal static extern void BNSetUserInstructionHighlight( @@ -28,8 +27,7 @@ internal static extern void BNSetUserInstructionHighlight( ulong addr , // BNHighlightColor color - HighlightColor color - + in BNHighlightColor color ); } } \ No newline at end of file diff --git a/Handle/BNActivity.cs b/Handle/BNActivity.cs index 9bef7de..33ea33a 100644 --- a/Handle/BNActivity.cs +++ b/Handle/BNActivity.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Activity : AbstractSafeHandle + public sealed class Activity : AbstractSafeHandle { internal Activity(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNAnalysisCompletionEvent.cs b/Handle/BNAnalysisCompletionEvent.cs index 2cffc3b..bc9ce26 100644 --- a/Handle/BNAnalysisCompletionEvent.cs +++ b/Handle/BNAnalysisCompletionEvent.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class AnalysisCompletionEvent : AbstractSafeHandle + public sealed class AnalysisCompletionEvent : AbstractSafeHandle { internal AnalysisCompletionEvent(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNAnalysisContext.cs b/Handle/BNAnalysisContext.cs index a1151ca..876ad7a 100644 --- a/Handle/BNAnalysisContext.cs +++ b/Handle/BNAnalysisContext.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class AnalysisContext : AbstractSafeHandle + public sealed class AnalysisContext : AbstractSafeHandle { internal AnalysisContext(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNAnalysisMergeConflict.cs b/Handle/BNAnalysisMergeConflict.cs index 6ee020f..f2c6839 100644 --- a/Handle/BNAnalysisMergeConflict.cs +++ b/Handle/BNAnalysisMergeConflict.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class AnalysisMergeConflict : AbstractSafeHandle + public sealed class AnalysisMergeConflict : AbstractSafeHandle { internal AnalysisMergeConflict(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNAnalysisMergeConflictSplitter.cs b/Handle/BNAnalysisMergeConflictSplitter.cs index df5f75c..a2c12e8 100644 --- a/Handle/BNAnalysisMergeConflictSplitter.cs +++ b/Handle/BNAnalysisMergeConflictSplitter.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class AnalysisMergeConflictSplitter : AbstractSafeHandle + public sealed class AnalysisMergeConflictSplitter : AbstractSafeHandle { internal AnalysisMergeConflictSplitter(IntPtr handle) :base(handle, false) diff --git a/Handle/BNArchitecture.cs b/Handle/BNArchitecture.cs index 7b11242..07d8d26 100644 --- a/Handle/BNArchitecture.cs +++ b/Handle/BNArchitecture.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Architecture : AbstractSafeHandle + public sealed class Architecture : AbstractSafeHandle { internal Architecture(IntPtr handle) :base(handle, false) @@ -53,6 +53,41 @@ out ulong arrayLength NativeMethods.BNFreeArchitectureList ); } + + public static string[] GetAllArchitectureNames() + { + List items = new List(); + + Architecture[] architectures = Architecture.GetAllArchitectures(); + + foreach (Architecture architecture in architectures) + { + if (!items.Contains(architecture.Name)) + { + items.Add(architecture.Name); + } + } + + return items.ToArray(); + } + + public static Architecture? ChooseArchitecture(string prompt = "Choose" , string title = "Choose a architecture") + { + string[] names = Architecture.GetAllArchitectureNames(); + + int? index = Core.GetLargeChoiceInput( + prompt , + title , + names + ); + + if (null == index) + { + return null; + } + + return Architecture.FromName(names[(int)index]); + } public static Architecture NativeTypeParserArchitecture() { @@ -124,7 +159,7 @@ public ulong OpcodeDisplayLength } } - public ILRegister[] FullWidthRegisters + public Register[] FullWidthRegisters { get { @@ -139,18 +174,18 @@ out ulong arrayLength NativeMethods.BNFreeRegisterList ); - List targets = new List(); + List targets = new List(); foreach (RegisterIndex index in indexes) { - targets.Add( new ILRegister(this , index) ); + targets.Add( new Register(this , index) ); } return targets.ToArray(); } } - public ILRegister[] Registers + public Register[] Registers { get { @@ -165,18 +200,18 @@ out ulong arrayLength NativeMethods.BNFreeRegisterList ); - List targets = new List(); + List targets = new List(); foreach (RegisterIndex index in indexes) { - targets.Add( new ILRegister(this , index) ); + targets.Add( new Register(this , index) ); } return targets.ToArray(); } } - public ILRegister[] GlobalRegister + public Register[] GlobalRegister { get { @@ -191,18 +226,18 @@ out ulong arrayLength NativeMethods.BNFreeRegisterList ); - List targets = new List(); + List targets = new List(); foreach (RegisterIndex index in indexes) { - targets.Add( new ILRegister(this , index) ); + targets.Add( new Register(this , index) ); } return targets.ToArray(); } } - public ILRegister[] SystemRegister + public Register[] SystemRegister { get { @@ -217,18 +252,18 @@ out ulong arrayLength NativeMethods.BNFreeRegisterList ); - List targets = new List(); + List targets = new List(); foreach (RegisterIndex index in indexes) { - targets.Add( new ILRegister(this , index) ); + targets.Add( new Register(this , index) ); } return targets.ToArray(); } } - public ILFlag[] Flags + public Flag[] Flags { get { @@ -243,11 +278,11 @@ out ulong arrayLength NativeMethods.BNFreeRegisterList ); - List targets = new List(); + List targets = new List(); foreach (FlagIndex index in indexes) { - targets.Add( new ILFlag(this , index) ); + targets.Add( new Flag(this , index) ); } return targets.ToArray(); @@ -486,41 +521,41 @@ public uint GetSemanticClassForFlagWriteType(uint writeType) ); } - - - - public bool GetInstructionInfo( + public InstructionInfo? GetInstructionInfo( byte[] data , - ulong address , - ulong maxLength , - out InstructionInfo info + ulong address ) { bool ok = false; - - BNInstructionInfo raw; - + ok = NativeMethods.BNGetInstructionInfo( this.handle , data , address , - maxLength , - out raw + Math.Min(this.MaxInstructionLength , (ulong)data.Length) , + out BNInstructionInfo raw ); - if (ok) - { - info = InstructionInfo.FromNative(raw); - } - else + if (!ok) { - info = new InstructionInfo(); + return null; } - return ok; - } - - public InstructionTextToken[] GetInstructionText(byte[]data , ulong address , ref ulong length ) + return InstructionInfo.FromNative(raw); + } + + /// + /// + /// + /// + /// + /// instruction length in bytes + /// + public InstructionTextToken[] GetInstructionText( + byte[]data , + ulong address , + out ulong length + ) { IntPtr arrayPointer = IntPtr.Zero; @@ -528,21 +563,23 @@ public InstructionTextToken[] GetInstructionText(byte[]data , ulong address , re bool ok = false; - length = (ulong)data.Length; + ulong bufferLength = (ulong)data.Length; ok = NativeMethods.BNGetInstructionText( this.handle , data , address , - ref length , + ref bufferLength , out arrayPointer , out arrayLength ); - + InstructionTextToken[] tokens = Array.Empty(); if (ok ) { + length = bufferLength; + tokens = UnsafeUtils.TakeStructArrayEx( arrayPointer , arrayLength, @@ -550,6 +587,10 @@ out arrayLength NativeMethods.BNFreeInstructionText ); } + else + { + length = 0; + } return tokens; } @@ -568,9 +609,9 @@ public RegisterInfo GetRegisterInfo(RegisterIndex reg) ); } - public ILRegister GetRegisterByName(string name) + public Register GetRegisterByName(string name) { - return new ILRegister( + return new Register( this , NativeMethods.BNGetArchitectureRegisterByName(this.handle , name) ); @@ -879,11 +920,11 @@ public void FinalizeArchitectureHook() NativeMethods.BNFinalizeArchitectureHook(this.handle); } - public ILRegister StackPointerRegister + public Register StackPointerRegister { get { - return new ILRegister( + return new Register( this , (RegisterIndex)NativeMethods.BNGetArchitectureStackPointerRegister(this.handle) ); diff --git a/Handle/BNBackgroundTask.cs b/Handle/BNBackgroundTask.cs index 4193372..417d982 100644 --- a/Handle/BNBackgroundTask.cs +++ b/Handle/BNBackgroundTask.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class BackgroundTask : AbstractSafeHandle + public sealed class BackgroundTask : AbstractSafeHandle { public BackgroundTask(string initialText , bool canCancel) : this( NativeMethods.BNBeginBackgroundTask(initialText, canCancel ) , true ) diff --git a/Handle/BNBaseAddressDetection.cs b/Handle/BNBaseAddressDetection.cs index 5ca6c9a..b28d727 100644 --- a/Handle/BNBaseAddressDetection.cs +++ b/Handle/BNBaseAddressDetection.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class BaseAddressDetection : AbstractSafeHandle + public sealed class BaseAddressDetection : AbstractSafeHandle { internal BaseAddressDetection(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNBasicBlock.cs b/Handle/BNBasicBlock.cs index a2d31b3..8f5c7cb 100644 --- a/Handle/BNBasicBlock.cs +++ b/Handle/BNBasicBlock.cs @@ -2,14 +2,14 @@ using System.Collections.Generic; using System.Data; using System.Drawing; +using System.Linq; using System.Runtime.InteropServices; using System.Text; using Microsoft.Win32.SafeHandles; namespace BinaryNinja { - public abstract class AbstractBasicBlock : AbstractSafeHandle - where T_SELF : AbstractBasicBlock + public abstract class AbstractBasicBlock: AbstractSafeHandle { internal AbstractBasicBlock(IntPtr handle , bool owner) : base(handle , owner) @@ -27,6 +27,7 @@ protected override bool ReleaseHandle() return true; } + public Function? Function { @@ -370,65 +371,10 @@ public HighlightColor Highlight } } - public DisassemblyTextLine[] GetLanguageRepresentationLines( - DisassemblySettings? settings = null, - string language = "Pseudo C" - ) - { - Function? function = this.Function; - - if (null == function) - { - return Array.Empty(); - } - - LanguageRepresentationFunction? pseudo = function.GetLanguageRepresentation(language); - - if (null == pseudo) - { - return Array.Empty(); - } - - IntPtr arrayPointer = NativeMethods.BNGetLanguageRepresentationFunctionBlockLines( - pseudo.DangerousGetHandle() , - this.DangerousGetHandle() , - null == settings ? IntPtr.Zero : settings.DangerousGetHandle() , - out ulong arrayLength - ); - - return UnsafeUtils.TakeStructArrayEx( - arrayPointer , - arrayLength , - DisassemblyTextLine.FromNative , - NativeMethods.BNFreeDisassemblyTextLines - ); - } - - public DisassemblyTextLine[] PseudoCLines - { - get - { - return this.GetLanguageRepresentationLines(); - } - } - - public string PseudoCText - { - get - { - StringBuilder builder = new StringBuilder(); - - foreach (DisassemblyTextLine line in this.PseudoCLines) - { - builder.AppendLine(line.ToString()); - } - - return builder.ToString(); - } - } + } - public class BasicBlock : AbstractBasicBlock + public class BasicBlock : AbstractBasicBlock { internal BasicBlock(IntPtr handle , bool owner) : base(handle , owner) @@ -680,7 +626,6 @@ public BasicBlock[] PostDominatorTreeChildren } } - public BasicBlock[] GetDominanceFrontier(bool post) { ulong arrayLength = 0; @@ -714,47 +659,65 @@ public BasicBlock[] PostDominanceFrontier return this.GetDominanceFrontier(true); } } - - public IEnumerable InstructionTextLines + + public IEnumerable Instructions { get { - return this.GetInstructionTextLines(); - } - } - - public IEnumerable GetInstructionTextLines() - { - if (null == this.View) - { - throw new Exception("View is null"); - } + if (null == this.View) + { + throw new Exception("View is null"); + } - ulong address = this.Start; + ulong address = this.Start; - while (address < this.End) - { - ulong length = this.End - address; + while (address < this.End) + { + ulong bufferLength = this.End - address; - length = Math.Min(this.Architecture.MaxInstructionLength, this.Length - address); + bufferLength = Math.Min(this.Architecture.MaxInstructionLength, this.Length - address); - byte[] data = this.View.ReadData(address , length); + byte[] buffer = this.View.ReadData(address , bufferLength); - InstructionTextToken[] tokens = this.Architecture.GetInstructionText( - data , - address , - ref length - ); + InstructionInfo? info = this.Architecture.GetInstructionInfo(buffer , address); - if (0 == length) - { - break; - } + if (null == info) + { + throw new Exception("get instruction info fail"); + } - yield return new InstructionTextLine(address , data , tokens); + if (0 == info.Length) + { + throw new Exception("Instruction length out of range"); + } + + byte[] data = new byte[info.Length]; + + Array.Copy(buffer, data, data.Length); - address += length; + InstructionTextToken[] tokens = this.Architecture.GetInstructionText( + data , + address , + out ulong instrLength + ); + + if (instrLength != info.Length) + { + throw new Exception("Instruction length mismatch"); + } + + yield return new Instruction( + this.Function, + address , + data, + info, + tokens + ); + + address += instrLength; + } } } + } } \ No newline at end of file diff --git a/Handle/BNBinaryReader.cs b/Handle/BNBinaryReader.cs index d988f42..c85d156 100644 --- a/Handle/BNBinaryReader.cs +++ b/Handle/BNBinaryReader.cs @@ -7,7 +7,7 @@ namespace BinaryNinja { - public sealed class BinaryReader : AbstractSafeHandle + public sealed class BinaryReader : AbstractSafeHandle { public BinaryReader(BinaryView view) : this(NativeMethods.BNCreateBinaryReader(view.DangerousGetHandle()) , true) diff --git a/Handle/BNBinaryView.cs b/Handle/BNBinaryView.cs index e648fbb..f3e2270 100644 --- a/Handle/BNBinaryView.cs +++ b/Handle/BNBinaryView.cs @@ -9,7 +9,7 @@ namespace BinaryNinja { - public sealed class BinaryView : AbstractSafeHandle + public sealed class BinaryView : AbstractSafeHandle { internal BinaryView(IntPtr handle , bool owner) : base(handle , owner) @@ -559,7 +559,7 @@ public IEnumerable BasicBlocks } } } - + public IEnumerable LowLevelILFunctions { get @@ -2864,7 +2864,10 @@ public string[] SymbolNames foreach (Symbol symbol in this.Symbols) { - items.Add(symbol.RawName); + if (!items.Contains(symbol.RawName)) + { + items.Add(symbol.RawName); + } } return items.ToArray(); @@ -2879,7 +2882,10 @@ public string[] SymbolFullNames foreach (Symbol symbol in this.Symbols) { - items.Add(symbol.FullName); + if (!items.Contains(symbol.FullName)) + { + items.Add(symbol.FullName); + } } return items.ToArray(); @@ -5743,10 +5749,12 @@ public Logger GetOrCreateLogger(string name) public Symbol? ChooseSymbol(string prompt = "Choose" , string title = "Choose a symbol") { + string[] names = this.SymbolNames; + int? index = Core.GetLargeChoiceInput( prompt , title , - this.SymbolNames + names ); if (null == index) @@ -5754,15 +5762,17 @@ public Logger GetOrCreateLogger(string name) return null; } - return this.GetSymbolByRawName(this.SymbolNames[(int)index]); + return this.GetSymbolByRawName(names[(int)index]); } public Function? ChooseFunction(string prompt = "Choose" , string title = "Choose a function") { + string[] names = this.SymbolNames; + int? index = Core.GetLargeChoiceInput( prompt , title , - this.SymbolNames + names ); if (null == index) @@ -5770,7 +5780,7 @@ public Logger GetOrCreateLogger(string name) return null; } - return this.GetFunctionByRawName(this.SymbolNames[(int)index]); + return this.GetFunctionByRawName(names[(int)index]); } } diff --git a/Handle/BNBinaryViewType.cs b/Handle/BNBinaryViewType.cs index a333d48..3c807e3 100644 --- a/Handle/BNBinaryViewType.cs +++ b/Handle/BNBinaryViewType.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class BinaryViewType : AbstractSafeHandle + public sealed class BinaryViewType : AbstractSafeHandle { internal BinaryViewType(IntPtr handle) :base(handle, false) diff --git a/Handle/BNBinaryWriter.cs b/Handle/BNBinaryWriter.cs index 5620d2d..978b2ee 100644 --- a/Handle/BNBinaryWriter.cs +++ b/Handle/BNBinaryWriter.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class BinaryWriter : AbstractSafeHandle + public sealed class BinaryWriter : AbstractSafeHandle { public BinaryWriter(BinaryView view) : this(NativeMethods.BNCreateBinaryWriter(view.DangerousGetHandle()) , true) diff --git a/Handle/BNCallingConvention.cs b/Handle/BNCallingConvention.cs index 9e943f4..6ee89de 100644 --- a/Handle/BNCallingConvention.cs +++ b/Handle/BNCallingConvention.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class CallingConvention : AbstractSafeHandle + public sealed class CallingConvention : AbstractSafeHandle { internal CallingConvention(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNCollaborationChangeset.cs b/Handle/BNCollaborationChangeset.cs index 88d23bb..bbae98c 100644 --- a/Handle/BNCollaborationChangeset.cs +++ b/Handle/BNCollaborationChangeset.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class CollaborationChangeset : AbstractSafeHandle + public sealed class CollaborationChangeset : AbstractSafeHandle { internal CollaborationChangeset(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNCollaborationGroup.cs b/Handle/BNCollaborationGroup.cs index 90fb2a5..f717184 100644 --- a/Handle/BNCollaborationGroup.cs +++ b/Handle/BNCollaborationGroup.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class CollaborationGroup : AbstractSafeHandle + public sealed class CollaborationGroup : AbstractSafeHandle { internal CollaborationGroup(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNCollaborationLazyT.cs b/Handle/BNCollaborationLazyT.cs index e0fa9c1..822f355 100644 --- a/Handle/BNCollaborationLazyT.cs +++ b/Handle/BNCollaborationLazyT.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class CollaborationLazyT : AbstractSafeHandle + public sealed class CollaborationLazyT : AbstractSafeHandle { public CollaborationLazyT(IntPtr handle) :base(handle, false) diff --git a/Handle/BNCollaborationPermission.cs b/Handle/BNCollaborationPermission.cs index 86d8387..99042b2 100644 --- a/Handle/BNCollaborationPermission.cs +++ b/Handle/BNCollaborationPermission.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class CollaborationPermission : AbstractSafeHandle + public sealed class CollaborationPermission : AbstractSafeHandle { public CollaborationPermission(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNCollaborationSnapshot.cs b/Handle/BNCollaborationSnapshot.cs index c4c7ad5..6c56b77 100644 --- a/Handle/BNCollaborationSnapshot.cs +++ b/Handle/BNCollaborationSnapshot.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class CollaborationSnapshot : AbstractSafeHandle + public sealed class CollaborationSnapshot : AbstractSafeHandle { public CollaborationSnapshot(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNCollaborationUndoEntry.cs b/Handle/BNCollaborationUndoEntry.cs index 12699e5..b241ba2 100644 --- a/Handle/BNCollaborationUndoEntry.cs +++ b/Handle/BNCollaborationUndoEntry.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class CollaborationUndoEntry : AbstractSafeHandle + public sealed class CollaborationUndoEntry : AbstractSafeHandle { public CollaborationUndoEntry(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNCollaborationUser.cs b/Handle/BNCollaborationUser.cs index 7e5e5c3..5a87a28 100644 --- a/Handle/BNCollaborationUser.cs +++ b/Handle/BNCollaborationUser.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class CollaborationUser : AbstractSafeHandle + public sealed class CollaborationUser : AbstractSafeHandle { internal CollaborationUser(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNComponent.cs b/Handle/BNComponent.cs index ff214b4..7a297f4 100644 --- a/Handle/BNComponent.cs +++ b/Handle/BNComponent.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Component : AbstractSafeHandle + public sealed class Component : AbstractSafeHandle { internal Component(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNDataBuffer.cs b/Handle/BNDataBuffer.cs index 019a93f..ac99d71 100644 --- a/Handle/BNDataBuffer.cs +++ b/Handle/BNDataBuffer.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class DataBuffer : AbstractSafeHandle , IEnumerable + public sealed class DataBuffer : AbstractSafeHandle , IEnumerable { public DataBuffer() :this( Array.Empty() ) diff --git a/Handle/BNDataRenderer.cs b/Handle/BNDataRenderer.cs index 463174a..ba0a7c3 100644 --- a/Handle/BNDataRenderer.cs +++ b/Handle/BNDataRenderer.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class DataRenderer : AbstractSafeHandle + public sealed class DataRenderer : AbstractSafeHandle { public DataRenderer(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNDataRendererContainer.cs b/Handle/BNDataRendererContainer.cs index 5b12f35..7e472f5 100644 --- a/Handle/BNDataRendererContainer.cs +++ b/Handle/BNDataRendererContainer.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class DataRendererContainer : AbstractSafeHandle + public sealed class DataRendererContainer : AbstractSafeHandle { internal DataRendererContainer(IntPtr handle) :base(handle , false) diff --git a/Handle/BNDatabase.cs b/Handle/BNDatabase.cs index be29262..8a4c43c 100644 --- a/Handle/BNDatabase.cs +++ b/Handle/BNDatabase.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Database : AbstractSafeHandle + public sealed class Database : AbstractSafeHandle { internal Database(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNDebugInfo.cs b/Handle/BNDebugInfo.cs index 218ae5e..53eefbe 100644 --- a/Handle/BNDebugInfo.cs +++ b/Handle/BNDebugInfo.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class DebugInfo : AbstractSafeHandle + public sealed class DebugInfo : AbstractSafeHandle { internal DebugInfo(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNDebugInfoParser.cs b/Handle/BNDebugInfoParser.cs index e7f42cc..0317284 100644 --- a/Handle/BNDebugInfoParser.cs +++ b/Handle/BNDebugInfoParser.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class DebugInfoParser : AbstractSafeHandle + public sealed class DebugInfoParser : AbstractSafeHandle { internal DebugInfoParser(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNDemangler.cs b/Handle/BNDemangler.cs index ba485eb..729e315 100644 --- a/Handle/BNDemangler.cs +++ b/Handle/BNDemangler.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Demangler : AbstractSafeHandle + public sealed class Demangler : AbstractSafeHandle { internal Demangler(IntPtr handle) :base(handle, false) diff --git a/Handle/BNDisassemblySettings.cs b/Handle/BNDisassemblySettings.cs index 65ad847..d24cc00 100644 --- a/Handle/BNDisassemblySettings.cs +++ b/Handle/BNDisassemblySettings.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class DisassemblySettings : AbstractSafeHandle + public sealed class DisassemblySettings : AbstractSafeHandle { public DisassemblySettings() : this( NativeMethods.BNDefaultDisassemblySettings() , true) diff --git a/Handle/BNDisassemblyTextRenderer.cs b/Handle/BNDisassemblyTextRenderer.cs index 6f7e562..ffdbb66 100644 --- a/Handle/BNDisassemblyTextRenderer.cs +++ b/Handle/BNDisassemblyTextRenderer.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class DisassemblyTextRenderer : AbstractSafeHandle + public sealed class DisassemblyTextRenderer : AbstractSafeHandle { internal DisassemblyTextRenderer(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNDownloadInstance.cs b/Handle/BNDownloadInstance.cs index cb5d4ea..2c33fb7 100644 --- a/Handle/BNDownloadInstance.cs +++ b/Handle/BNDownloadInstance.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class DownloadInstance : AbstractSafeHandle + public sealed class DownloadInstance : AbstractSafeHandle { internal DownloadInstance(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNDownloadProvider.cs b/Handle/BNDownloadProvider.cs index 5495ec4..95e6a12 100644 --- a/Handle/BNDownloadProvider.cs +++ b/Handle/BNDownloadProvider.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class DownloadProvider : AbstractSafeHandle + public sealed class DownloadProvider : AbstractSafeHandle { internal DownloadProvider(IntPtr handle) :base(handle , false) diff --git a/Handle/BNEnumeration.cs b/Handle/BNEnumeration.cs index a2a742f..d643848 100644 --- a/Handle/BNEnumeration.cs +++ b/Handle/BNEnumeration.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class Enumeration : AbstractSafeHandle + public sealed class Enumeration : AbstractSafeHandle { public Enumeration(EnumerationType type) : base( NativeMethods.BNGetTypeEnumeration(type.DangerousGetHandle()) , true) @@ -101,9 +101,16 @@ public override string ToString() { StringBuilder builder = new StringBuilder(); - foreach (EnumerationMember member in Members) + for (int i = 0; i < this.Members.Length; i++) { - builder.AppendLine( member.ToString() + ";"); + if (i == ( this.Members.Length - 1 )) + { + builder.Append( this.Members[i].ToString() + ";"); + } + else + { + builder.AppendLine( this.Members[i].ToString() + ";"); + } } return builder.ToString(); diff --git a/Handle/BNEnumerationBuilder.cs b/Handle/BNEnumerationBuilder.cs index 9b3f663..a803ae4 100644 --- a/Handle/BNEnumerationBuilder.cs +++ b/Handle/BNEnumerationBuilder.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class EnumerationBuilder : AbstractSafeHandle + public sealed class EnumerationBuilder : AbstractSafeHandle { public EnumerationBuilder() : this(NativeMethods.BNCreateEnumerationBuilder() , true) diff --git a/Handle/BNExternalLibrary.cs b/Handle/BNExternalLibrary.cs index 9e0a8f3..df89523 100644 --- a/Handle/BNExternalLibrary.cs +++ b/Handle/BNExternalLibrary.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class ExternalLibrary : AbstractSafeHandle + public sealed class ExternalLibrary : AbstractSafeHandle { internal ExternalLibrary(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNExternalLocation.cs b/Handle/BNExternalLocation.cs index 2cd7654..fd52b06 100644 --- a/Handle/BNExternalLocation.cs +++ b/Handle/BNExternalLocation.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class ExternalLocation : AbstractSafeHandle + public sealed class ExternalLocation : AbstractSafeHandle { internal ExternalLocation(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNFieldResolutionInfo.cs b/Handle/BNFieldResolutionInfo.cs index 8090c3e..c83180a 100644 --- a/Handle/BNFieldResolutionInfo.cs +++ b/Handle/BNFieldResolutionInfo.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class FieldResolutionInfo : AbstractSafeHandle + public sealed class FieldResolutionInfo : AbstractSafeHandle { public FieldResolutionInfo(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNFileMetadata.cs b/Handle/BNFileMetadata.cs index 8ef8e75..fe79f69 100644 --- a/Handle/BNFileMetadata.cs +++ b/Handle/BNFileMetadata.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class FileMetadata : AbstractSafeHandle + public sealed class FileMetadata : AbstractSafeHandle { public FileMetadata() : this(NativeMethods.BNCreateFileMetadata() , true) diff --git a/Handle/BNFirmwareNinja.cs b/Handle/BNFirmwareNinja.cs index 082f369..81522c1 100644 --- a/Handle/BNFirmwareNinja.cs +++ b/Handle/BNFirmwareNinja.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class FirmwareNinja : AbstractSafeHandle + public sealed class FirmwareNinja : AbstractSafeHandle { public FirmwareNinja(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNFirmwareNinjaReferenceNode.cs b/Handle/BNFirmwareNinjaReferenceNode.cs index 6b3b710..b256474 100644 --- a/Handle/BNFirmwareNinjaReferenceNode.cs +++ b/Handle/BNFirmwareNinjaReferenceNode.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class FirmwareNinjaReferenceNode : AbstractSafeHandle + public sealed class FirmwareNinjaReferenceNode : AbstractSafeHandle { internal FirmwareNinjaReferenceNode(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNFirmwareNinjaRelationship.cs b/Handle/BNFirmwareNinjaRelationship.cs index f1f9a79..1430873 100644 --- a/Handle/BNFirmwareNinjaRelationship.cs +++ b/Handle/BNFirmwareNinjaRelationship.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class FirmwareNinjaRelationship : AbstractSafeHandle + public sealed class FirmwareNinjaRelationship : AbstractSafeHandle { internal FirmwareNinjaRelationship(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNFlowGraph.cs b/Handle/BNFlowGraph.cs index 2578539..7ca0d82 100644 --- a/Handle/BNFlowGraph.cs +++ b/Handle/BNFlowGraph.cs @@ -7,8 +7,7 @@ namespace BinaryNinja { - public abstract class AbstractFlowGraph : AbstractSafeHandle - where T_SELF: AbstractFlowGraph + public abstract class AbstractFlowGraph : AbstractSafeHandle { internal AbstractFlowGraph(IntPtr handle , bool owner) : base(handle , owner) @@ -445,7 +444,7 @@ public bool IsNodeValid(FlowGraphNode node) } // x - public sealed class FlowGraph : AbstractFlowGraph + public sealed class FlowGraph : AbstractFlowGraph { public FlowGraph() :this( NativeMethods.BNCreateFlowGraph() , true) diff --git a/Handle/BNFlowGraphLayout.cs b/Handle/BNFlowGraphLayout.cs index 33280d3..6d5f0ef 100644 --- a/Handle/BNFlowGraphLayout.cs +++ b/Handle/BNFlowGraphLayout.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class FlowGraphLayout : AbstractSafeHandle + public sealed class FlowGraphLayout : AbstractSafeHandle { internal FlowGraphLayout(IntPtr handle) :base(handle , false) diff --git a/Handle/BNFlowGraphLayoutRequest.cs b/Handle/BNFlowGraphLayoutRequest.cs index 0047dd1..5e5c9d3 100644 --- a/Handle/BNFlowGraphLayoutRequest.cs +++ b/Handle/BNFlowGraphLayoutRequest.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public class FlowGraphLayoutRequest : AbstractSafeHandle + public class FlowGraphLayoutRequest : AbstractSafeHandle { internal FlowGraphLayoutRequest(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNFlowGraphNode.cs b/Handle/BNFlowGraphNode.cs index 8fa5f03..03ac4c0 100644 --- a/Handle/BNFlowGraphNode.cs +++ b/Handle/BNFlowGraphNode.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public class FlowGraphNode : AbstractSafeHandle + public class FlowGraphNode : AbstractSafeHandle { internal FlowGraphNode(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNFunction.cs b/Handle/BNFunction.cs index 6e46051..a04b40d 100644 --- a/Handle/BNFunction.cs +++ b/Handle/BNFunction.cs @@ -9,7 +9,7 @@ namespace BinaryNinja { - public sealed class Function : AbstractSafeHandle + public sealed class Function : AbstractSafeHandle { internal Function(IntPtr handle , bool owner) : base(handle , owner) @@ -284,6 +284,108 @@ public bool HasUserType return NativeMethods.BNFunctionHasUserType(this.handle); } } + + public void SetAutoReturnType(TypeWithConfidence type) + { + NativeMethods.BNSetAutoFunctionReturnType( + this.handle, + type.ToNative() + ); + } + + public void SetUserReturnType(TypeWithConfidence type) + { + NativeMethods.BNSetUserFunctionReturnType( + this.handle, + type.ToNative() + ); + } + + public void SetAutoCallingConvention(CallingConventionWithConfidence convention) + { + NativeMethods.BNSetAutoFunctionCallingConvention( + this.handle, + convention.ToNative() + ); + } + + public void SetUserCallingConvention(CallingConventionWithConfidence convention) + { + NativeMethods.BNSetUserFunctionCallingConvention( + this.handle, + convention.ToNative() + ); + } + + public void SetAutoParameterVariables(ParameterVariablesWithConfidence parameterVariables) + { + using (ScopedAllocator allocator = new ScopedAllocator()) + { + NativeMethods.BNSetAutoFunctionParameterVariables( + this.handle, + parameterVariables.ToNativeEx(allocator) + ); + } + } + + public void SetUserParameterVariables(ParameterVariablesWithConfidence parameterVariables) + { + using (ScopedAllocator allocator = new ScopedAllocator()) + { + NativeMethods.BNSetUserFunctionParameterVariables( + this.handle, + parameterVariables.ToNativeEx(allocator) + ); + } + } + + public void SetAutoHasVariableArguments(BoolWithConfidence hasVariableArguments) + { + NativeMethods.BNSetAutoFunctionHasVariableArguments( + this.handle , + hasVariableArguments.ToNative() + ); + } + + public void SetUserHasVariableArguments(BoolWithConfidence hasVariableArguments) + { + NativeMethods.BNSetUserFunctionHasVariableArguments( + this.handle , + hasVariableArguments.ToNative() + ); + } + + public void SetAutoCanReturn(BoolWithConfidence canReturn) + { + NativeMethods.BNSetAutoFunctionCanReturn( + this.handle , + canReturn.ToNative() + ); + } + + public void SetUserCanReturn(BoolWithConfidence canReturn) + { + NativeMethods.BNSetUserFunctionCanReturn( + this.handle , + canReturn.ToNative() + ); + } + + public void SetAutoPure(BoolWithConfidence pure) + { + NativeMethods.BNSetAutoFunctionPure( + this.handle , + pure.ToNative() + ); + } + + public void SetUserPure(BoolWithConfidence pure) + { + NativeMethods.BNSetUserFunctionPure( + this.handle , + pure.ToNative() + ); + } public bool HasExplicitlyDefinedType { @@ -821,7 +923,7 @@ out ulong arrayLength return UnsafeUtils.TakeStructArrayEx( arrayPointer , arrayLength , - VariableNameAndType.FromNative , + (_native) => VariableNameAndType.FromNativeEx(this, _native) , NativeMethods.BNFreeVariableNameAndTypeList ); } @@ -839,12 +941,30 @@ out ulong arrayLength return UnsafeUtils.TakeStructArrayEx( arrayPointer , arrayLength , - VariableNameAndType.FromNative, + (_native) => VariableNameAndType.FromNativeEx(this, _native), NativeMethods.BNFreeVariableNameAndTypeList ); } } + public string[] VariableNames + { + get + { + List items = new List(); + + foreach (VariableNameAndType item in this.Variables) + { + if (!items.Contains(item.Name)) + { + items.Add(item.Name); + } + } + + return items.ToArray(); + } + } + public VariableNameAndType? GetVariableByName(string name) { foreach (VariableNameAndType variable in Variables) @@ -1167,6 +1287,11 @@ public void Reanalyze(FunctionUpdateType type = FunctionUpdateType.FullAutoFunct public BasicBlock? GetBasicBlockAtAddress(ulong address , Architecture? arch = null) { + if (null == arch) + { + arch = this.Architecture; + } + return BasicBlock.TakeHandle( NativeMethods.BNGetFunctionBasicBlockAtAddress( this.handle, @@ -1174,6 +1299,121 @@ public void Reanalyze(FunctionUpdateType type = FunctionUpdateType.FullAutoFunct address) ); } + + public HighlightColor GetInstructionHighlight(ulong address , Architecture? arch = null) + { + return HighlightColor.FromNative( + NativeMethods.BNGetInstructionHighlight( + this.handle , + null == arch ? IntPtr.Zero : arch.DangerousGetHandle() , + address + ) + ); + } + + public void SetAutoInstructionHighlight(ulong address , HighlightColor color , Architecture? arch = null) + { + NativeMethods.BNSetAutoInstructionHighlight( + this.handle , + null == arch ? IntPtr.Zero : arch.DangerousGetHandle() , + address , + color.ToNative() + ); + } + + public void SetUserInstructionHighlight(ulong address , HighlightColor color , Architecture? arch = null) + { + NativeMethods.BNSetUserInstructionHighlight( + this.handle , + null == arch ? IntPtr.Zero : arch.DangerousGetHandle() , + address , + color.ToNative() + ); + } + + public void CreateAutoStackVariable( + long offset , + TypeWithConfidence type , + string name + ) + { + NativeMethods.BNCreateAutoStackVariable( + this.handle , + offset , + type.ToNative() , + name + ); + } + + public void CreateUserStackVariable( + long offset , + TypeWithConfidence type , + string name + ) + { + NativeMethods.BNCreateUserStackVariable( + this.handle , + offset , + type.ToNative() , + name + ); + } + + public void DeleteAutoStackVariable(long offset) + { + NativeMethods.BNDeleteAutoStackVariable(this.handle , offset ); + } + + public void DeleteUserStackVariable(long offset) + { + NativeMethods.BNDeleteUserStackVariable(this.handle , offset ); + } + + public void CreateAutoVariable( + AbstractVariable variable, + TypeWithConfidence type , + string name , + bool ignoreDisjointUses = false + ) + { + NativeMethods.BNCreateAutoVariable( + this.handle , + variable.ToNative() , + type.ToNative() , + name , + ignoreDisjointUses + ); + } + + public void CreateUserVariable( + AbstractVariable variable, + TypeWithConfidence type , + string name , + bool ignoreDisjointUses = false + ) + { + NativeMethods.BNCreateUserVariable( + this.handle , + variable.ToNative() , + type.ToNative() , + name , + ignoreDisjointUses + ); + } + + public void DeleteUserVariable(AbstractVariable variable) + { + NativeMethods.BNDeleteUserVariable(this.handle , variable.ToNative()); + } + + public bool IsCallInstruction(ulong address , Architecture? arch = null) + { + return NativeMethods.BNIsCallInstruction( + this.handle , + null == arch ? IntPtr.Zero : arch.DangerousGetHandle() , + address + ); + } public ReferenceSource[] CallSites { @@ -1211,6 +1451,59 @@ public Function[] Callers } } + public string[] CallerRawNames + { + get + { + List names = new List(); + + Function[] functions = this.Callers; + + foreach (Function function in functions) + { + if (!names.Contains(function.RawName)) + { + names.Add(function.RawName); + } + } + + return names.ToArray(); + } + } + + public Function? GetCallerByRawName(string name) + { + Function[] functions = this.Callers; + + foreach (Function function in functions) + { + if (function.RawName == name) + { + return function; + } + } + + return null; + } + + public Function? ChooseCaller(string prompt = "Choose" , string title = "Choose Caller") + { + string[] names = this.CallerRawNames; + + int? index = Core.GetLargeChoiceInput( + prompt , + title , + names + ); + + if (null == index) + { + return null; + } + + return this.GetCallerByRawName(names[(int)index]); + } + public Function[] Callees { get @@ -1231,6 +1524,59 @@ public Function[] Callees } } + public string[] CalleeRawNames + { + get + { + List names = new List(); + + Function[] functions = this.Callees; + + foreach (Function function in functions) + { + if (!names.Contains(function.RawName)) + { + names.Add(function.RawName); + } + } + + return names.ToArray(); + } + } + + public Function? GetCalleeByRawName(string name) + { + Function[] functions = this.Callees; + + foreach (Function function in functions) + { + if (function.RawName == name) + { + return function; + } + } + + return null; + } + + public Function? ChooseCallee(string prompt = "Choose" , string title = "Choose Callee") + { + string[] names = this.CalleeRawNames; + + int? index = Core.GetLargeChoiceInput( + prompt , + title , + names + ); + + if (null == index) + { + return null; + } + + return this.GetCalleeByRawName(names[(int)index]); + } + public ulong[] CalleeAddresses { get @@ -1245,6 +1591,8 @@ public ulong[] CalleeAddresses return addresses.ToArray(); } } + + public Workflow? Workflow { @@ -1540,7 +1888,7 @@ public LinearDisassemblyLine[] GetLinearDisassemblyLines(DisassemblySettings? se return targets.ToArray(); } - public IEnumerable LinearDisassemblyLines + public LinearDisassemblyLine[] LinearDisassemblyLines { get { @@ -1552,11 +1900,20 @@ public string GetLinearDisassemblyText(DisassemblySettings? settings = null) { StringBuilder builder = new StringBuilder(); - foreach (LinearDisassemblyLine line in this.GetLinearDisassemblyLines(settings)) + LinearDisassemblyLine[] lines = this.GetLinearDisassemblyLines(settings); + + for (int i = 0; i < lines.Length; i++) { - builder.AppendLine(line.ToString()); + if (i == ( lines.Length - 1 )) + { + builder.Append(lines[i].ToString()); + } + else + { + builder.AppendLine(lines[i].ToString()); + } } - + return builder.ToString(); } @@ -1568,8 +1925,7 @@ public string LinearDisassemblyText } } - - public PluginCommand[] ValidPluginCommands + public PluginCommand[] PluginCommands { get { @@ -1588,6 +1944,37 @@ out ulong arrayLength } } + public string[] PluginCommandNames + { + get + { + List items = new List(); + + foreach (PluginCommand command in this.PluginCommands) + { + if (!items.Contains(command.Name)) + { + items.Add(command.Name); + } + } + + return items.ToArray(); + } + } + + public PluginCommand? GetPluginCommandByName(string name) + { + foreach (PluginCommand command in this.PluginCommands) + { + if (name == command.Name) + { + return command; + } + } + + return null; + } + public string GetVariableNameOrDefault(CoreVariable variable) { return UnsafeUtils.TakeAnsiString( @@ -1633,6 +2020,41 @@ public DisassemblyTextLine[] TypeTokens return this.GetTypeTokens(); } } + + public VariableNameAndType? ChooseVariable(string prompt = "Choose" , string title = "Choose a variable") + { + string[] names = this.VariableNames; + + int? index = Core.GetLargeChoiceInput( + prompt , + title , + names + ); + if (null == index) + { + return null; + } + + return this.GetVariableByName(names[(int)index]); + } + + public PluginCommand? ChoosePluginCommand(string prompt = "Choose" , string title = "Choose a plugin command") + { + string[] names = this.PluginCommandNames; + + int? index = Core.GetLargeChoiceInput( + prompt , + title , + names + ); + + if (null == index) + { + return null; + } + + return this.GetPluginCommandByName(names[(int)index]); + } } } \ No newline at end of file diff --git a/Handle/BNHighLevelILFunction.cs b/Handle/BNHighLevelILFunction.cs index 0ef632a..10271a1 100644 --- a/Handle/BNHighLevelILFunction.cs +++ b/Handle/BNHighLevelILFunction.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class HighLevelILFunction : AbstractSafeHandle + public sealed class HighLevelILFunction : AbstractSafeHandle { public bool IsSSAForm { get; } = false; diff --git a/Handle/BNHighLevelILTokenEmitter.cs b/Handle/BNHighLevelILTokenEmitter.cs index da318d2..02df1b7 100644 --- a/Handle/BNHighLevelILTokenEmitter.cs +++ b/Handle/BNHighLevelILTokenEmitter.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class HighLevelILTokenEmitter : AbstractSafeHandle + public sealed class HighLevelILTokenEmitter : AbstractSafeHandle { internal HighLevelILTokenEmitter(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNKeyValueStore.cs b/Handle/BNKeyValueStore.cs index 89ce8e8..3cc9c7c 100644 --- a/Handle/BNKeyValueStore.cs +++ b/Handle/BNKeyValueStore.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class KeyValueStore : AbstractSafeHandle + public sealed class KeyValueStore : AbstractSafeHandle { public KeyValueStore() : this( NativeMethods.BNCreateKeyValueStore() , true ) diff --git a/Handle/BNLanguageRepresentationFunction.cs b/Handle/BNLanguageRepresentationFunction.cs index ae458ea..ef892ba 100644 --- a/Handle/BNLanguageRepresentationFunction.cs +++ b/Handle/BNLanguageRepresentationFunction.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class LanguageRepresentationFunction : AbstractSafeHandle + public sealed class LanguageRepresentationFunction : AbstractSafeHandle { internal LanguageRepresentationFunction(IntPtr handle , bool owner) : base(handle , owner) @@ -278,7 +278,7 @@ public string GetLinearDisassemblyText( settings , language ) - ) + ) { builder.AppendLine(line.ToString()); } @@ -293,8 +293,5 @@ public string LinearDisassemblyText return this.GetLinearDisassemblyText(); } } - - - } } \ No newline at end of file diff --git a/Handle/BNLanguageRepresentationFunctionType.cs b/Handle/BNLanguageRepresentationFunctionType.cs index 9cebdf2..f89e914 100644 --- a/Handle/BNLanguageRepresentationFunctionType.cs +++ b/Handle/BNLanguageRepresentationFunctionType.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class LanguageRepresentationFunctionType : AbstractSafeHandle + public sealed class LanguageRepresentationFunctionType : AbstractSafeHandle { internal LanguageRepresentationFunctionType(IntPtr handle) :base(handle, false) diff --git a/Handle/BNLineFormatter.cs b/Handle/BNLineFormatter.cs index b25e80f..afccfee 100644 --- a/Handle/BNLineFormatter.cs +++ b/Handle/BNLineFormatter.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class LineFormatter : AbstractSafeHandle + public sealed class LineFormatter : AbstractSafeHandle { internal LineFormatter(IntPtr handle) :base(handle , false) diff --git a/Handle/BNLinearViewCursor.cs b/Handle/BNLinearViewCursor.cs index 5bd9c0a..3f7b01f 100644 --- a/Handle/BNLinearViewCursor.cs +++ b/Handle/BNLinearViewCursor.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class LinearViewCursor : AbstractSafeHandle + public sealed class LinearViewCursor : AbstractSafeHandle { public LinearViewCursor(LinearViewObject root) : this( diff --git a/Handle/BNLinearViewObject.cs b/Handle/BNLinearViewObject.cs index d7da7a4..7b1eb9a 100644 --- a/Handle/BNLinearViewObject.cs +++ b/Handle/BNLinearViewObject.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class LinearViewObject : AbstractSafeHandle + public sealed class LinearViewObject : AbstractSafeHandle { public LinearViewObject? Parent { get; } = null; diff --git a/Handle/BNLogger.cs b/Handle/BNLogger.cs index 10eeab7..1ea0317 100644 --- a/Handle/BNLogger.cs +++ b/Handle/BNLogger.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Logger : AbstractSafeHandle + public sealed class Logger : AbstractSafeHandle { public Logger( string name , ulong sessionId = 0 ) :this ( Logger.rawGetOrCreateLogger(name , sessionId) , true) diff --git a/Handle/BNLowLevelILFunction.cs b/Handle/BNLowLevelILFunction.cs index d0c5f5f..49c7343 100644 --- a/Handle/BNLowLevelILFunction.cs +++ b/Handle/BNLowLevelILFunction.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class LowLevelILFunction : AbstractSafeHandle + public sealed class LowLevelILFunction : AbstractSafeHandle { public bool IsSSAForm { get; } = false; @@ -426,7 +426,7 @@ public FunctionGraphType GraphType } } - public ILRegister[] Registers + public Register[] Registers { get { @@ -441,11 +441,11 @@ out ulong arrayLength NativeMethods.BNFreeLLILVariablesList ); - List targets = new List(); + List targets = new List(); foreach (RegisterIndex index in indexes) { - targets.Add( new ILRegister(this.OwnerFunction.Architecture, index) ); + targets.Add( new Register(this.OwnerFunction.Architecture, index) ); } return targets.ToArray(); @@ -475,7 +475,7 @@ out ulong arrayLength foreach (ulong version in versions) { - ILRegister register = new ILRegister(this.OwnerFunction.Architecture, index); + Register register = new Register(this.OwnerFunction.Architecture, index); targets.Add( new LowLevelILSSARegister(this, register, version) @@ -548,7 +548,7 @@ out ulong arrayLength } } - public ILFlag[] Flags + public Flag[] Flags { get { @@ -563,11 +563,11 @@ out ulong arrayLength NativeMethods.BNFreeLLILVariablesList ); - List targets = new List(); + List targets = new List(); foreach (FlagIndex index in indexes) { - targets.Add( new ILFlag(this.OwnerFunction.Architecture, index) ); + targets.Add( new Flag(this.OwnerFunction.Architecture, index) ); } return targets.ToArray(); @@ -597,7 +597,7 @@ out ulong arrayLength foreach (ulong version in versions) { - ILFlag flag = new ILFlag(this.OwnerFunction.Architecture, index); + Flag flag = new Flag(this.OwnerFunction.Architecture, index); targets.Add( new LowLevelILSSAFlag(this , flag, version) @@ -706,13 +706,20 @@ public LowLevelILInstruction[] GetInstructionsAt(ulong address, Architecture? ar out ulong arrayLength ); - LowLevelILInstructionIndex[] indexes = UnsafeUtils.TakeNumberArray( + ulong[] indexes = UnsafeUtils.TakeNumberArray( arrayPointer , arrayLength , NativeMethods.BNFreeILInstructionList ); - - return this.MustGetInstructions(indexes); + + List instructions = new List(); + + foreach (LowLevelILInstructionIndex index in indexes) + { + instructions.Add( this.MustGetInstruction(index) ); + } + + return instructions.ToArray(); } public LowLevelILInstruction? CurrentInstruction @@ -1299,8 +1306,7 @@ LowLevelILInstructionIndex lowInstr return mlil.GetInstruction(mediumInstr); } - public MediumLevelILInstruction[] GetMediumLevelILExpressions( - LowLevelILExpressionIndex lowExpr) + public MediumLevelILInstruction[] GetMediumLevelILExpressions(LowLevelILExpressionIndex lowExpr) { MediumLevelILFunction? mlil = this.MediumLevelIL; @@ -1315,13 +1321,20 @@ public MediumLevelILInstruction[] GetMediumLevelILExpressions( out ulong arrayLength ); - MediumLevelILExpressionIndex[] mediumExprs = UnsafeUtils.TakeNumberArray( + ulong[] mediumExprIndexs = UnsafeUtils.TakeNumberArray( arrayPointer , arrayLength , NativeMethods.BNFreeILInstructionList ); - return mlil.MustGetExpressions(mediumExprs); + List expressions = new List(); + + foreach (MediumLevelILExpressionIndex mediumExprIndex in mediumExprIndexs) + { + expressions.Add( mlil.MustGetExpression(mediumExprIndex) ); + } + + return expressions.ToArray(); } // mapped @@ -1929,7 +1942,7 @@ public LowLevelILExpressionIndex EmitAdd( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -1947,7 +1960,7 @@ public LowLevelILExpressionIndex EmitAddCarray( LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, LowLevelILExpressionIndex carray, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -1965,7 +1978,7 @@ public LowLevelILExpressionIndex EmitSub( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -1983,7 +1996,7 @@ public LowLevelILExpressionIndex EmitSubBorrow( LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, LowLevelILExpressionIndex carray, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2002,7 +2015,7 @@ public LowLevelILExpressionIndex EmitAnd( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2019,7 +2032,7 @@ public LowLevelILExpressionIndex EmitOr( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2036,7 +2049,7 @@ public LowLevelILExpressionIndex EmitXor( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2053,7 +2066,7 @@ public LowLevelILExpressionIndex EmitLogicalShiftLeft( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2070,7 +2083,7 @@ public LowLevelILExpressionIndex EmitLogicalShiftRight( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2087,7 +2100,7 @@ public LowLevelILExpressionIndex EmitArithmeticShiftRight( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2104,7 +2117,7 @@ public LowLevelILExpressionIndex EmitRotateLeft( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2122,7 +2135,7 @@ public LowLevelILExpressionIndex EmitRotateLeftCarray( LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, LowLevelILExpressionIndex carray, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2140,7 +2153,7 @@ public LowLevelILExpressionIndex EmitRotateRight( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2158,7 +2171,7 @@ public LowLevelILExpressionIndex EmitRotateRightCarray( LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, LowLevelILExpressionIndex carray, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2176,7 +2189,7 @@ public LowLevelILExpressionIndex EmitMul( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2193,7 +2206,7 @@ public LowLevelILExpressionIndex EmitMulSignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2210,7 +2223,7 @@ public LowLevelILExpressionIndex EmitMulUnsignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2227,7 +2240,7 @@ public LowLevelILExpressionIndex EmitDivSigned( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2244,7 +2257,7 @@ public LowLevelILExpressionIndex EmitDivSignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2261,7 +2274,7 @@ public LowLevelILExpressionIndex EmitDivUnsigned( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2278,7 +2291,7 @@ public LowLevelILExpressionIndex EmitDivUnsignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2297,7 +2310,7 @@ public LowLevelILExpressionIndex EmitModSigned( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2314,7 +2327,7 @@ public LowLevelILExpressionIndex EmitModSignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2331,7 +2344,7 @@ public LowLevelILExpressionIndex EmitModUnsigned( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2348,7 +2361,7 @@ public LowLevelILExpressionIndex EmitModUnsignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2364,7 +2377,7 @@ public LowLevelILExpressionIndex EmitModUnsignedDoublePrecision( public LowLevelILExpressionIndex EmitNeg( ulong size , LowLevelILExpressionIndex value, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2379,7 +2392,7 @@ public LowLevelILExpressionIndex EmitNeg( public LowLevelILExpressionIndex EmitNot( ulong size , LowLevelILExpressionIndex value, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2394,7 +2407,7 @@ public LowLevelILExpressionIndex EmitNot( public LowLevelILExpressionIndex EmitSignExtend( ulong size , LowLevelILExpressionIndex value, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2409,7 +2422,7 @@ public LowLevelILExpressionIndex EmitSignExtend( public LowLevelILExpressionIndex EmitZeroExtend( ulong size , LowLevelILExpressionIndex value, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2424,7 +2437,7 @@ public LowLevelILExpressionIndex EmitZeroExtend( public LowLevelILExpressionIndex EmitLowPart( ulong size , LowLevelILExpressionIndex value, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( diff --git a/Handle/BNMainThreadAction.cs b/Handle/BNMainThreadAction.cs index cec3f8d..d5e83d2 100644 --- a/Handle/BNMainThreadAction.cs +++ b/Handle/BNMainThreadAction.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class MainThreadAction : AbstractSafeHandle + public sealed class MainThreadAction : AbstractSafeHandle { internal MainThreadAction(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNMediumLevelILFunction.cs b/Handle/BNMediumLevelILFunction.cs index 8eb9e58..7c2fa31 100644 --- a/Handle/BNMediumLevelILFunction.cs +++ b/Handle/BNMediumLevelILFunction.cs @@ -9,7 +9,7 @@ namespace BinaryNinja { - public sealed class MediumLevelILFunction : AbstractSafeHandle + public sealed class MediumLevelILFunction : AbstractSafeHandle { public bool IsSSAForm { get; } = false; @@ -537,13 +537,20 @@ public MediumLevelILInstruction[] GetSSAVariableUses(Variable variable , ulong v out ulong arrayLength ); - MediumLevelILInstructionIndex[] indexs = UnsafeUtils.TakeNumberArray( + ulong[] indexes = UnsafeUtils.TakeNumberArray( arrayPointer , arrayLength , NativeMethods.BNFreeILInstructionList ); - return this.MustGetInstructions(indexs); + List instructions = new List(); + + foreach (MediumLevelILInstructionIndex index in indexes) + { + instructions.Add( this.MustGetInstruction(index) ); + } + + return instructions.ToArray(); } public MediumLevelILInstruction[] GetSSAMemoryUses( ulong version) @@ -554,13 +561,20 @@ public MediumLevelILInstruction[] GetSSAMemoryUses( ulong version) out ulong arrayLength ); - MediumLevelILInstructionIndex[] indexs = UnsafeUtils.TakeNumberArray( + ulong[] indexes = UnsafeUtils.TakeNumberArray( arrayPointer , arrayLength , NativeMethods.BNFreeILInstructionList ); - return this.MustGetInstructions(indexs); + List instructions = new List(); + + foreach (MediumLevelILInstructionIndex index in indexes) + { + instructions.Add( this.MustGetInstruction(index) ); + } + + return instructions.ToArray(); } public bool IsSSAVariableLive(Variable variable , ulong version) @@ -599,13 +613,20 @@ public MediumLevelILInstruction[] GetVariableDefinitions(Variable variable ) out ulong arrayLength ); - MediumLevelILInstructionIndex[] indexs = UnsafeUtils.TakeNumberArray( + ulong[] indexes = UnsafeUtils.TakeNumberArray( arrayPointer , arrayLength , NativeMethods.BNFreeILInstructionList ); - return this.MustGetInstructions(indexs); + List instructions = new List(); + + foreach (MediumLevelILInstructionIndex index in indexes) + { + instructions.Add( this.MustGetInstruction(index) ); + } + + return instructions.ToArray(); } public MediumLevelILInstruction[] GetVariableUses(Variable variable ) @@ -616,13 +637,20 @@ public MediumLevelILInstruction[] GetVariableUses(Variable variable ) out ulong arrayLength ); - MediumLevelILInstructionIndex[] indexs = UnsafeUtils.TakeNumberArray( + ulong[] indexes = UnsafeUtils.TakeNumberArray( arrayPointer , arrayLength , NativeMethods.BNFreeILInstructionList ); - return this.MustGetInstructions(indexs); + List instructions = new List(); + + foreach (MediumLevelILInstructionIndex index in indexes) + { + instructions.Add( this.MustGetInstruction(index) ); + } + + return instructions.ToArray(); } public MediumLevelILInstruction[] GetLiveInstructionsForVariable( @@ -637,13 +665,20 @@ public MediumLevelILInstruction[] GetLiveInstructionsForVariable( out ulong arrayLength ); - MediumLevelILInstructionIndex[] indexs = UnsafeUtils.TakeNumberArray( + MediumLevelILInstructionIndex[] indexes = UnsafeUtils.TakeNumberArray( arrayPointer , arrayLength , NativeMethods.BNFreeILInstructionList ); - return this.MustGetInstructions(indexs); + List instructions = new List(); + + foreach (MediumLevelILInstructionIndex index in indexes) + { + instructions.Add( this.MustGetInstruction(index) ); + } + + return instructions.ToArray(); } public RegisterValue GetSSAVariableValue(Variable variable , ulong version) diff --git a/Handle/BNMetadata.cs b/Handle/BNMetadata.cs index befdd9d..a80b28e 100644 --- a/Handle/BNMetadata.cs +++ b/Handle/BNMetadata.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class Metadata : AbstractSafeHandle + public sealed class Metadata : AbstractSafeHandle { public Metadata() : this(Metadata.rawCreateMetadataDict( new Dictionary()) , true) diff --git a/Handle/BNNamedTypeReference.cs b/Handle/BNNamedTypeReference.cs index b99b1c6..52c3437 100644 --- a/Handle/BNNamedTypeReference.cs +++ b/Handle/BNNamedTypeReference.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class NamedTypeReference : AbstractSafeHandle + public sealed class NamedTypeReference : AbstractSafeHandle { public NamedTypeReference(NamedTypeReferenceClass cls , string id , QualifiedName name) : this( NamedTypeReference.rawCreate(cls , id , name) , true ) diff --git a/Handle/BNNamedTypeReferenceBuilder.cs b/Handle/BNNamedTypeReferenceBuilder.cs index 9fa1dfd..9fdc039 100644 --- a/Handle/BNNamedTypeReferenceBuilder.cs +++ b/Handle/BNNamedTypeReferenceBuilder.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class NamedTypeReferenceBuilder : AbstractSafeHandle + public sealed class NamedTypeReferenceBuilder : AbstractSafeHandle { internal NamedTypeReferenceBuilder(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNPlatform.cs b/Handle/BNPlatform.cs index b394c2f..ea2e8fc 100644 --- a/Handle/BNPlatform.cs +++ b/Handle/BNPlatform.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Platform : AbstractSafeHandle + public sealed class Platform : AbstractSafeHandle { public Platform(Architecture arch , string name) :this( NativeMethods.BNCreatePlatform(arch.DangerousGetHandle() , name) , true) @@ -96,7 +96,7 @@ protected override bool ReleaseHandle() return true; } - public static Platform[] GetPlatforms() + public static Platform[] GetAllPlatforms() { IntPtr arrayPointer = NativeMethods.BNGetPlatformList(out ulong arrayLength); @@ -108,6 +108,41 @@ public static Platform[] GetPlatforms() ); } + public static string[] GetAllPlatformNames() + { + List items = new List(); + + Platform[] platforms = Platform.GetAllPlatforms(); + + foreach (Platform platform in platforms) + { + if (!items.Contains(platform.Name)) + { + items.Add(platform.Name); + } + } + + return items.ToArray(); + } + + public static Platform? ChoosePlatform(string prompt = "Choose" , string title = "Choose a platform") + { + string[] names = Platform.GetAllPlatformNames(); + + int? index = Core.GetLargeChoiceInput( + prompt , + title , + names + ); + + if (null == index) + { + return null; + } + + return Platform.FromName(names[(int)index]); + } + public static Platform? FromName(string name) { return Platform.TakeHandle( diff --git a/Handle/BNProject.cs b/Handle/BNProject.cs index df7418d..740b775 100644 --- a/Handle/BNProject.cs +++ b/Handle/BNProject.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Project : AbstractSafeHandle + public sealed class Project : AbstractSafeHandle { internal Project(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNProjectFile.cs b/Handle/BNProjectFile.cs index 7ee4acc..4403c9c 100644 --- a/Handle/BNProjectFile.cs +++ b/Handle/BNProjectFile.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class ProjectFile : AbstractSafeHandle + public sealed class ProjectFile : AbstractSafeHandle { internal ProjectFile(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNProjectFolder.cs b/Handle/BNProjectFolder.cs index 48598a6..194ff3d 100644 --- a/Handle/BNProjectFolder.cs +++ b/Handle/BNProjectFolder.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class ProjectFolder : AbstractSafeHandle + public sealed class ProjectFolder : AbstractSafeHandle { internal ProjectFolder(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNRelocation.cs b/Handle/BNRelocation.cs index e47ce6d..18212c7 100644 --- a/Handle/BNRelocation.cs +++ b/Handle/BNRelocation.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Relocation : AbstractSafeHandle + public sealed class Relocation : AbstractSafeHandle { public Relocation(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNRelocationHandler.cs b/Handle/BNRelocationHandler.cs index fe53c9a..f7ad5c6 100644 --- a/Handle/BNRelocationHandler.cs +++ b/Handle/BNRelocationHandler.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class RelocationHandler : AbstractSafeHandle + public sealed class RelocationHandler : AbstractSafeHandle { internal RelocationHandler(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNRemote.cs b/Handle/BNRemote.cs index 581ea76..239c0fa 100644 --- a/Handle/BNRemote.cs +++ b/Handle/BNRemote.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Remote : AbstractSafeHandle + public sealed class Remote : AbstractSafeHandle { internal Remote(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNRemoteFile.cs b/Handle/BNRemoteFile.cs index 4c8b84a..3ce3e0d 100644 --- a/Handle/BNRemoteFile.cs +++ b/Handle/BNRemoteFile.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class RemoteFile : AbstractSafeHandle + public sealed class RemoteFile : AbstractSafeHandle { internal RemoteFile(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNRemoteFolder.cs b/Handle/BNRemoteFolder.cs index f9d31bf..9b85016 100644 --- a/Handle/BNRemoteFolder.cs +++ b/Handle/BNRemoteFolder.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class RemoteFolder : AbstractSafeHandle + public sealed class RemoteFolder : AbstractSafeHandle { internal RemoteFolder(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNRemoteProject.cs b/Handle/BNRemoteProject.cs index 9866a35..ab9c1ad 100644 --- a/Handle/BNRemoteProject.cs +++ b/Handle/BNRemoteProject.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class RemoteProject : AbstractSafeHandle + public sealed class RemoteProject : AbstractSafeHandle { internal RemoteProject(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNRenderLayer.cs b/Handle/BNRenderLayer.cs index c0184e6..694e9fc 100644 --- a/Handle/BNRenderLayer.cs +++ b/Handle/BNRenderLayer.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class RenderLayer : AbstractSafeHandle + public sealed class RenderLayer : AbstractSafeHandle { internal RenderLayer(IntPtr handle) :base(handle, false) diff --git a/Handle/BNRepoPlugin.cs b/Handle/BNRepoPlugin.cs index 70e5664..1b37c5c 100644 --- a/Handle/BNRepoPlugin.cs +++ b/Handle/BNRepoPlugin.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class RepoPlugin : AbstractSafeHandle + public sealed class RepoPlugin : AbstractSafeHandle { internal RepoPlugin(IntPtr handle) :base(handle , false) diff --git a/Handle/BNReportCollection.cs b/Handle/BNReportCollection.cs index 13e75b4..b6b7878 100644 --- a/Handle/BNReportCollection.cs +++ b/Handle/BNReportCollection.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class ReportCollection : AbstractSafeHandle + public sealed class ReportCollection : AbstractSafeHandle { public ReportCollection() : this( NativeMethods.BNCreateReportCollection() , true) diff --git a/Handle/BNRepository.cs b/Handle/BNRepository.cs index f5dfa41..325ebef 100644 --- a/Handle/BNRepository.cs +++ b/Handle/BNRepository.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Repository : AbstractSafeHandle + public sealed class Repository : AbstractSafeHandle { public Repository(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNRepositoryManager.cs b/Handle/BNRepositoryManager.cs index f0ec423..3573ec4 100644 --- a/Handle/BNRepositoryManager.cs +++ b/Handle/BNRepositoryManager.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class RepositoryManager : AbstractSafeHandle + public sealed class RepositoryManager : AbstractSafeHandle { internal RepositoryManager(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNSaveSettings.cs b/Handle/BNSaveSettings.cs index 9884d94..d218c38 100644 --- a/Handle/BNSaveSettings.cs +++ b/Handle/BNSaveSettings.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class SaveSettings : AbstractSafeHandle + public sealed class SaveSettings : AbstractSafeHandle { public SaveSettings() : this( NativeMethods.BNCreateSaveSettings() , true) diff --git a/Handle/BNScriptingInstance.cs b/Handle/BNScriptingInstance.cs index f26fa16..216b091 100644 --- a/Handle/BNScriptingInstance.cs +++ b/Handle/BNScriptingInstance.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class ScriptingInstance : AbstractSafeHandle + public sealed class ScriptingInstance : AbstractSafeHandle { public ScriptingInstance(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNScriptingProvider.cs b/Handle/BNScriptingProvider.cs index c80402e..786927f 100644 --- a/Handle/BNScriptingProvider.cs +++ b/Handle/BNScriptingProvider.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class ScriptingProvider : AbstractSafeHandle + public sealed class ScriptingProvider : AbstractSafeHandle { internal ScriptingProvider(IntPtr handle) :base(handle , false) diff --git a/Handle/BNSecretsProvider.cs b/Handle/BNSecretsProvider.cs index 7ba59d6..27936b4 100644 --- a/Handle/BNSecretsProvider.cs +++ b/Handle/BNSecretsProvider.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class SecretsProvider : AbstractSafeHandle + public sealed class SecretsProvider : AbstractSafeHandle { internal SecretsProvider(IntPtr handle) :base(handle , false) diff --git a/Handle/BNSection.cs b/Handle/BNSection.cs index 60748c6..95cefb3 100644 --- a/Handle/BNSection.cs +++ b/Handle/BNSection.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Section : AbstractSafeHandle
+ public sealed class Section : AbstractSafeHandle { internal Section(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNSegment.cs b/Handle/BNSegment.cs index cba5598..0550369 100644 --- a/Handle/BNSegment.cs +++ b/Handle/BNSegment.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Segment : AbstractSafeHandle + public sealed class Segment : AbstractSafeHandle { internal Segment(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNSettings.cs b/Handle/BNSettings.cs index f971dab..0833d62 100644 --- a/Handle/BNSettings.cs +++ b/Handle/BNSettings.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Settings : AbstractSafeHandle + public sealed class Settings : AbstractSafeHandle { public Settings(string schemaId = "default") : this(NativeMethods.BNCreateSettings(schemaId) , true) diff --git a/Handle/BNSnapshot.cs b/Handle/BNSnapshot.cs index 94934bf..5c9bd35 100644 --- a/Handle/BNSnapshot.cs +++ b/Handle/BNSnapshot.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Snapshot : AbstractSafeHandle + public sealed class Snapshot : AbstractSafeHandle { internal Snapshot(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNStringRef.cs b/Handle/BNStringRef.cs index 9c6bbac..1bb0b15 100644 --- a/Handle/BNStringRef.cs +++ b/Handle/BNStringRef.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class StringRef : AbstractSafeHandle + public sealed class StringRef : AbstractSafeHandle { internal StringRef(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNStructure.cs b/Handle/BNStructure.cs index e194962..f15c39e 100644 --- a/Handle/BNStructure.cs +++ b/Handle/BNStructure.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public sealed class Structure : AbstractSafeHandle + public sealed class Structure : AbstractSafeHandle { public Structure(StructureType type) : base( NativeMethods.BNGetTypeStructure(type.DangerousGetHandle()) , true) diff --git a/Handle/BNStructureBuilder.cs b/Handle/BNStructureBuilder.cs index 8bb8e1a..0fed191 100644 --- a/Handle/BNStructureBuilder.cs +++ b/Handle/BNStructureBuilder.cs @@ -7,7 +7,7 @@ namespace BinaryNinja { - public sealed class StructureBuilder : AbstractSafeHandle + public sealed class StructureBuilder : AbstractSafeHandle { public StructureBuilder( StructureVariant kind = StructureVariant.StructStructureType diff --git a/Handle/BNSymbol.cs b/Handle/BNSymbol.cs index 274517a..9ed1d1d 100644 --- a/Handle/BNSymbol.cs +++ b/Handle/BNSymbol.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Symbol : AbstractSafeHandle + public sealed class Symbol : AbstractSafeHandle { internal Symbol(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNSymbolQueue.cs b/Handle/BNSymbolQueue.cs index 6fc38e3..1c0869a 100644 --- a/Handle/BNSymbolQueue.cs +++ b/Handle/BNSymbolQueue.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class SymbolQueue : AbstractSafeHandle + public sealed class SymbolQueue : AbstractSafeHandle { public SymbolQueue() : this( NativeMethods.BNCreateSymbolQueue() , true) diff --git a/Handle/BNTag.cs b/Handle/BNTag.cs index 4eccf7e..acc19b0 100644 --- a/Handle/BNTag.cs +++ b/Handle/BNTag.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Tag : AbstractSafeHandle + public sealed class Tag : AbstractSafeHandle { public Tag(TagType kind , string data) :this( NativeMethods.BNCreateTag(kind.DangerousGetHandle() , data) ,true) diff --git a/Handle/BNTagType.cs b/Handle/BNTagType.cs index 5422b2f..fcbb7ea 100644 --- a/Handle/BNTagType.cs +++ b/Handle/BNTagType.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TagType : AbstractSafeHandle + public sealed class TagType : AbstractSafeHandle { internal TagType(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNTemporaryFile.cs b/Handle/BNTemporaryFile.cs index 7fe6445..1b4d445 100644 --- a/Handle/BNTemporaryFile.cs +++ b/Handle/BNTemporaryFile.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TemporaryFile : AbstractSafeHandle + public sealed class TemporaryFile : AbstractSafeHandle { public TemporaryFile() : this( NativeMethods.BNCreateTemporaryFile() , true) diff --git a/Handle/BNTransform.cs b/Handle/BNTransform.cs index 94fa991..3766ecd 100644 --- a/Handle/BNTransform.cs +++ b/Handle/BNTransform.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class Transform : AbstractSafeHandle + public sealed class Transform : AbstractSafeHandle { internal Transform(IntPtr handle) :base(handle , false) diff --git a/Handle/BNTransformContext.cs b/Handle/BNTransformContext.cs index cfc504e..e30f86c 100644 --- a/Handle/BNTransformContext.cs +++ b/Handle/BNTransformContext.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TransformContext : AbstractSafeHandle + public sealed class TransformContext : AbstractSafeHandle { internal TransformContext(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNTransformSession.cs b/Handle/BNTransformSession.cs index 369338f..a98e2a8 100644 --- a/Handle/BNTransformSession.cs +++ b/Handle/BNTransformSession.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TransformSession : AbstractSafeHandle + public sealed class TransformSession : AbstractSafeHandle { internal TransformSession(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNType.cs b/Handle/BNType.cs index c1ac6ca..7537f1e 100644 --- a/Handle/BNType.cs +++ b/Handle/BNType.cs @@ -6,7 +6,7 @@ namespace BinaryNinja { - public class Type: AbstractSafeHandle + public class Type: AbstractSafeHandle { internal Type(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNTypeArchive.cs b/Handle/BNTypeArchive.cs index 12e2db3..324bc58 100644 --- a/Handle/BNTypeArchive.cs +++ b/Handle/BNTypeArchive.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TypeArchive : AbstractSafeHandle + public sealed class TypeArchive : AbstractSafeHandle { internal TypeArchive(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNTypeArchiveMergeConflict.cs b/Handle/BNTypeArchiveMergeConflict.cs index 0385ce2..e17a69b 100644 --- a/Handle/BNTypeArchiveMergeConflict.cs +++ b/Handle/BNTypeArchiveMergeConflict.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TypeArchiveMergeConflict : AbstractSafeHandle + public sealed class TypeArchiveMergeConflict : AbstractSafeHandle { internal TypeArchiveMergeConflict(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNTypeBuilder.cs b/Handle/BNTypeBuilder.cs index 0b271f4..4a48a2d 100644 --- a/Handle/BNTypeBuilder.cs +++ b/Handle/BNTypeBuilder.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public class TypeBuilder : AbstractSafeHandle + public class TypeBuilder : AbstractSafeHandle { internal TypeBuilder(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNTypeContainer.cs b/Handle/BNTypeContainer.cs index 0d8664b..89a5f8d 100644 --- a/Handle/BNTypeContainer.cs +++ b/Handle/BNTypeContainer.cs @@ -7,7 +7,7 @@ namespace BinaryNinja { - public sealed class TypeContainer : AbstractSafeHandle + public sealed class TypeContainer : AbstractSafeHandle { public TypeContainer() : this( NativeMethods.BNGetEmptyTypeContainer() , true) diff --git a/Handle/BNTypeLibrary.cs b/Handle/BNTypeLibrary.cs index 8fc23b0..4f77bf0 100644 --- a/Handle/BNTypeLibrary.cs +++ b/Handle/BNTypeLibrary.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TypeLibrary : AbstractSafeHandle + public sealed class TypeLibrary : AbstractSafeHandle { public TypeLibrary(Architecture arch , string name) :this( NativeMethods.BNNewTypeLibrary(arch.DangerousGetHandle(), name) , true) @@ -213,7 +213,7 @@ out ulong arrayLength arrayPointer, arrayLength, NativeMethods.BNFreeStringList - ); + ); } } @@ -391,6 +391,5 @@ out ulong arrayLength ); } } - } } \ No newline at end of file diff --git a/Handle/BNTypeLibraryMapping.cs b/Handle/BNTypeLibraryMapping.cs index 016dcf5..5d8972a 100644 --- a/Handle/BNTypeLibraryMapping.cs +++ b/Handle/BNTypeLibraryMapping.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TypeLibraryMapping : AbstractSafeHandle + public sealed class TypeLibraryMapping : AbstractSafeHandle { internal TypeLibraryMapping(IntPtr handle) :base(handle , false) diff --git a/Handle/BNTypeParser.cs b/Handle/BNTypeParser.cs index 5cf3637..e424ec9 100644 --- a/Handle/BNTypeParser.cs +++ b/Handle/BNTypeParser.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TypeParser : AbstractSafeHandle + public sealed class TypeParser : AbstractSafeHandle { internal TypeParser(IntPtr handle) :base(handle , false) diff --git a/Handle/BNTypePrinter.cs b/Handle/BNTypePrinter.cs index 36ac373..ef1318e 100644 --- a/Handle/BNTypePrinter.cs +++ b/Handle/BNTypePrinter.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class TypePrinter : AbstractSafeHandle + public sealed class TypePrinter : AbstractSafeHandle { internal TypePrinter(IntPtr handle) : base(handle, false) diff --git a/Handle/BNUndoAction.cs b/Handle/BNUndoAction.cs index 866b497..b620d50 100644 --- a/Handle/BNUndoAction.cs +++ b/Handle/BNUndoAction.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class UndoAction : AbstractSafeHandle + public sealed class UndoAction : AbstractSafeHandle { internal UndoAction(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNUndoEntry.cs b/Handle/BNUndoEntry.cs index 7ab3cf0..6cda439 100644 --- a/Handle/BNUndoEntry.cs +++ b/Handle/BNUndoEntry.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class UndoEntry : AbstractSafeHandle + public sealed class UndoEntry : AbstractSafeHandle { internal UndoEntry(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNUser.cs b/Handle/BNUser.cs index 7911e91..b47b471 100644 --- a/Handle/BNUser.cs +++ b/Handle/BNUser.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class User : AbstractSafeHandle + public sealed class User : AbstractSafeHandle { internal User(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNWebsocketClient.cs b/Handle/BNWebsocketClient.cs index 2354eef..066750e 100644 --- a/Handle/BNWebsocketClient.cs +++ b/Handle/BNWebsocketClient.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class WebsocketClient : AbstractSafeHandle + public sealed class WebsocketClient : AbstractSafeHandle { internal WebsocketClient(IntPtr handle , bool owner) : base(handle , owner) diff --git a/Handle/BNWebsocketProvider.cs b/Handle/BNWebsocketProvider.cs index 5efe374..f37e5aa 100644 --- a/Handle/BNWebsocketProvider.cs +++ b/Handle/BNWebsocketProvider.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public sealed class WebsocketProvider : AbstractSafeHandle + public sealed class WebsocketProvider : AbstractSafeHandle { internal WebsocketProvider(IntPtr handle) :base(handle , false) diff --git a/Handle/BNWorkflow.cs b/Handle/BNWorkflow.cs index 030a188..1a0021b 100644 --- a/Handle/BNWorkflow.cs +++ b/Handle/BNWorkflow.cs @@ -5,7 +5,7 @@ namespace BinaryNinja { - public class Workflow : AbstractSafeHandle + public class Workflow : AbstractSafeHandle { public Workflow(string name) : base(true) { diff --git a/HighLevelIL/HighLevelILBasicBlock.cs b/HighLevelIL/HighLevelILBasicBlock.cs index 42c1900..fb02b43 100644 --- a/HighLevelIL/HighLevelILBasicBlock.cs +++ b/HighLevelIL/HighLevelILBasicBlock.cs @@ -4,7 +4,7 @@ namespace BinaryNinja { - public sealed class HighLevelILBasicBlock : AbstractBasicBlock + public sealed class HighLevelILBasicBlock : AbstractBasicBlock { public HighLevelILFunction ILFunction { get; } @@ -323,5 +323,68 @@ public HighLevelILBasicBlock[] PostDominanceFrontier } } + public DisassemblyTextLine[] GetLanguageRepresentationLines( + DisassemblySettings? settings = null, + string language = "Pseudo C" + ) + { + Function? function = this.Function; + + if (null == function) + { + return Array.Empty(); + } + + LanguageRepresentationFunction? pseudo = function.GetLanguageRepresentation(language); + + if (null == pseudo) + { + return Array.Empty(); + } + + IntPtr arrayPointer = NativeMethods.BNGetLanguageRepresentationFunctionBlockLines( + pseudo.DangerousGetHandle() , + this.DangerousGetHandle() , + null == settings ? IntPtr.Zero : settings.DangerousGetHandle() , + out ulong arrayLength + ); + + return UnsafeUtils.TakeStructArrayEx( + arrayPointer , + arrayLength , + DisassemblyTextLine.FromNative , + NativeMethods.BNFreeDisassemblyTextLines + ); + } + + public DisassemblyTextLine[] PseudoCLines + { + get + { + return this.GetLanguageRepresentationLines(); + } + } + + public string PseudoCText + { + get + { + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < this.PseudoCLines.Length; i++) + { + if (i == ( this.PseudoCLines.Length - 1 )) + { + builder.Append( this.PseudoCLines[i].ToString()); + } + else + { + builder.AppendLine( this.PseudoCLines[i].ToString()); + } + } + + return builder.ToString(); + } + } } } diff --git a/HighLevelIL/HighLevelILBasicBlockEdge.cs b/HighLevelIL/HighLevelILBasicBlockEdge.cs index ffa73ac..cfb0790 100644 --- a/HighLevelIL/HighLevelILBasicBlockEdge.cs +++ b/HighLevelIL/HighLevelILBasicBlockEdge.cs @@ -4,7 +4,7 @@ namespace BinaryNinja { - public sealed class HighLevelILBasicBlockEdge : AbstractBasicBlockEdge + public sealed class HighLevelILBasicBlockEdge : AbstractBasicBlockEdge { internal HighLevelILBasicBlockEdge( BNBasicBlockEdge native , diff --git a/HighLevelIL/HighLevelILFlowGraph.cs b/HighLevelIL/HighLevelILFlowGraph.cs index 34496bc..00c991f 100644 --- a/HighLevelIL/HighLevelILFlowGraph.cs +++ b/HighLevelIL/HighLevelILFlowGraph.cs @@ -2,7 +2,7 @@ namespace BinaryNinja { - public sealed class HighLevelILFlowGraph : AbstractFlowGraph + public sealed class HighLevelILFlowGraph : AbstractFlowGraph { public HighLevelILFunction ILFunction { get; } diff --git a/HighLevelIL/HighLevelILVariable.cs b/HighLevelIL/HighLevelILVariable.cs index 59bcfc0..c050d05 100644 --- a/HighLevelIL/HighLevelILVariable.cs +++ b/HighLevelIL/HighLevelILVariable.cs @@ -3,14 +3,14 @@ namespace BinaryNinja { - public sealed class HighLevelILVariable : AbstractFunctionVariable + public sealed class HighLevelILVariable : AbstractFunctionVariable { public HighLevelILFunction ILFunction { get; } internal HighLevelILVariable(HighLevelILVariable other) : base( other.ILFunction.OwnerFunction , - other.Type, + other.Source, other.Index, other.Storage ) diff --git a/IL/AbstractSSAVariable.cs b/IL/AbstractSSAVariable.cs index d946723..c21fa7e 100644 --- a/IL/AbstractSSAVariable.cs +++ b/IL/AbstractSSAVariable.cs @@ -5,7 +5,7 @@ namespace BinaryNinja public abstract class AbstractSSAVariable : IEquatable< AbstractSSAVariable>, IComparable< AbstractSSAVariable> - where T_VARIABLE : AbstractFunctionVariable + where T_VARIABLE : AbstractFunctionVariable { public T_VARIABLE Variable { get; } diff --git a/IL/ILFlag.cs b/IL/Flag.cs similarity index 75% rename from IL/ILFlag.cs rename to IL/Flag.cs index 9e68c05..d62eb16 100644 --- a/IL/ILFlag.cs +++ b/IL/Flag.cs @@ -2,19 +2,19 @@ namespace BinaryNinja { - public class ILFlag : IEquatable, IComparable + public class Flag : IEquatable, IComparable { internal Architecture Architecture { get; } public FlagIndex Index { get; } - internal ILFlag(Architecture arch , FlagIndex index) + internal Flag(Architecture arch , FlagIndex index) { this.Architecture = arch; this.Index = index; } - internal ILFlag(ILFlag other) + internal Flag(Flag other) { this.Architecture = other.Architecture; this.Index = other.Index; @@ -45,10 +45,10 @@ public string Name public override bool Equals(object? other) { - return Equals(other as ILFlag); + return Equals(other as Flag); } - public bool Equals(ILFlag? other) + public bool Equals(Flag? other) { if (other is null) { @@ -68,7 +68,7 @@ public override int GetHashCode() return this.Index.GetHashCode(); } - public static bool operator ==(ILFlag? left, ILFlag? right) + public static bool operator ==(Flag? left, Flag? right) { if (left is null) { @@ -78,12 +78,12 @@ public override int GetHashCode() return left.Equals(right); } - public static bool operator !=(ILFlag? left, ILFlag? right) + public static bool operator !=(Flag? left, Flag? right) { return !(left == right); } - public int CompareTo(ILFlag? other) + public int CompareTo(Flag? other) { if (other is null) { diff --git a/IL/FlagOrRegister.cs b/IL/FlagOrRegister.cs index b650d29..af04cd9 100644 --- a/IL/FlagOrRegister.cs +++ b/IL/FlagOrRegister.cs @@ -5,16 +5,16 @@ namespace BinaryNinja public sealed class FlagOrRegister : IEquatable, IComparable { - public ILFlag? Flag { get; } = null; + public Flag? Flag { get; } = null; - public ILRegister? Register { get; } = null; + public Register? Register { get; } = null; - internal FlagOrRegister(ILFlag flag) + internal FlagOrRegister(Flag flag) { this.Flag = flag; } - internal FlagOrRegister(ILRegister register) + internal FlagOrRegister(Register register) { this.Register = register; } diff --git a/IL/Instruction.cs b/IL/Instruction.cs new file mode 100644 index 0000000..d8ebfa6 --- /dev/null +++ b/IL/Instruction.cs @@ -0,0 +1,390 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Emit; +using System.Runtime.InteropServices; +using System.Text; + +namespace BinaryNinja +{ + public sealed class Instruction : + IEquatable, + IComparable + { + public Function? Function { get; } + + public ulong Address { get; } + + public byte[] Data { get; } = Array.Empty(); + + public InstructionInfo Info { get; } + + public InstructionTextToken[] Tokens { get; } = Array.Empty(); + + public Instruction( + Function? function, + ulong address, + byte[] data, + InstructionInfo info , + InstructionTextToken[] tokens + ) + { + this.Function = function; + this.Address = address; + this.Data = data; + this.Info = info; + this.Tokens = tokens; + } + + public ulong Length + { + get + { + return this.Info.Length; + } + } + + public string Text + { + get + { + StringBuilder builder = new StringBuilder(); + + foreach (InstructionTextToken token in this.Tokens) + { + builder.Append(token.Text); + } + + return builder.ToString(); + } + } + + public override bool Equals(object? other) + { + return this.Equals(other as Instruction); + } + + public bool Equals(Instruction? other) + { + if (other is null) + { + return false; + } + + if (ReferenceEquals(this , other)) + { + return true; + } + + if (this.Address != other.Address) + { + return false; + } + + return true; + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals")] + public override int GetHashCode() + { + return HashCode.Combine( + this.Address + ); + } + + public static bool operator ==(Instruction? left, Instruction? right) + { + if (left is null) + { + return right is null; + } + + return left.Equals(right); + } + + public static bool operator !=(Instruction? left, Instruction? right) + { + return !(left == right); + } + + public int CompareTo(Instruction? other) + { + if (other is null) + { + return 1; + } + + int result = this.Address.CompareTo(other.Address); + + return result; + } + + public HighlightColor? Highlight + { + get + { + return this.Function?.GetInstructionHighlight(this.Address); + } + + set + { + if (null != value) + { + this.Function?.SetUserInstructionHighlight(this.Address, value!); + } + } + } + + public bool IsCall + { + get + { + if (null == this.Function) + { + return false; + } + + return this.Function.IsCallInstruction(this.Address); + } + } + + public LowLevelILInstruction[] LowLevelILInstructions + { + get + { + if (null == this.Function) + { + return Array.Empty(); + } + + return this.Function.LowLevelIL.GetInstructionsAt( + this.Address + ); + } + } + + public MediumLevelILInstruction[] MediumLevelILExpressions + { + get + { + if (null == this.Function) + { + return Array.Empty(); + } + + List mediumExprs = new List(); + + foreach (LowLevelILInstruction lowInstr in this.LowLevelILInstructions) + { + foreach (MediumLevelILInstruction mediumExpr in lowInstr.MediumLevelILExpressions) + { + if (!mediumExprs.Contains(mediumExpr)) + { + mediumExprs.Add(mediumExpr); + } + } + } + + return mediumExprs.ToArray(); + } + } + + public MediumLevelILInstruction[] MediumLevelILInstructions + { + get + { + if (null == this.Function) + { + return Array.Empty(); + } + + List mediumInstrs = new List(); + + foreach (LowLevelILInstruction lowInstr in this.LowLevelILInstructions) + { + foreach (MediumLevelILInstruction mediumInstr in lowInstr.MediumLevelILInstructions) + { + if (!mediumInstrs.Contains(mediumInstr)) + { + mediumInstrs.Add(mediumInstr); + } + } + } + + return mediumInstrs.ToArray(); + } + } + + public HighLevelILInstruction[] HighLevelILExpressions + { + get + { + if (null == this.Function) + { + return Array.Empty(); + } + + List highExprs = new List(); + + foreach (LowLevelILInstruction lowInstr in this.LowLevelILInstructions) + { + foreach (HighLevelILInstruction highExpr in lowInstr.HighLevelILExpressions) + { + if (!highExprs.Contains(highExpr)) + { + highExprs.Add(highExpr); + } + } + } + + return highExprs.ToArray(); + } + } + + public HighLevelILInstruction[] HighLevelILInstructions + { + get + { + if (null == this.Function) + { + return Array.Empty(); + } + + List highInstrs = new List(); + + foreach (LowLevelILInstruction lowInstr in this.LowLevelILInstructions) + { + foreach (HighLevelILInstruction highInstr in lowInstr.HighLevelILInstructions) + { + if (!highInstrs.Contains(highInstr)) + { + highInstrs.Add(highInstr); + } + } + } + + return highInstrs.ToArray(); + } + } + + public DisassemblyTextLine[] GetLanguageRepresentationExpressionLines( + bool asFullAst = false , + OperatorPrecedence precedence = OperatorPrecedence.TopLevelOperatorPrecedence , + bool statement = false , + DisassemblySettings? settings = null , + string language = "Pseudo C" + ) + { + List pseudoLines = new List(); + + foreach (HighLevelILInstruction highExpr in this.HighLevelILExpressions) + { + DisassemblyTextLine[] lines = highExpr.GetLanguageRepresentationExpressionLines( + asFullAst , + precedence , + statement , + settings , + language + ); + + foreach (DisassemblyTextLine line in lines) + { + if (!pseudoLines.Contains(line)) + { + pseudoLines.Add(line); + } + } + } + + return pseudoLines.ToArray(); + } + + public DisassemblyTextLine[] PseudoCExpressionLines + { + get + { + return this.GetLanguageRepresentationExpressionLines(); + } + } + + public string PseudoCExpressionText + { + get + { + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < this.PseudoCExpressionLines.Length; i++) + { + if (i == ( this.PseudoCExpressionLines.Length - 1) ) + { + builder.Append(this.PseudoCExpressionLines[i].ToString()); + } + else + { + builder.AppendLine(this.PseudoCExpressionLines[i].ToString()); + } + } + + return builder.ToString(); + } + } + + public DisassemblyTextLine[] GetLanguageRepresentationLinearLines( + bool asFullAst = false, + DisassemblySettings? settings = null , + string language = "Pseudo C" + ) + { + List pseudoLines = new List(); + + foreach (HighLevelILInstruction highInstr in this.HighLevelILInstructions) + { + DisassemblyTextLine[] lines = highInstr.GetLanguageRepresentationLinearLines( + asFullAst, + settings , + language + ); + + foreach (DisassemblyTextLine line in lines) + { + if (!pseudoLines.Contains(line)) + { + pseudoLines.Add(line); + } + } + } + + return pseudoLines.ToArray(); + } + + public DisassemblyTextLine[] PseudoCLinearLines + { + get + { + return this.GetLanguageRepresentationLinearLines(); + } + } + + public string PseudoCLinearText + { + get + { + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < this.PseudoCLinearLines.Length; i++) + { + if (i == ( this.PseudoCLinearLines.Length - 1) ) + { + builder.Append(this.PseudoCLinearLines[i] .ToString()); + } + else + { + builder.AppendLine(this.PseudoCLinearLines[i].ToString()); + } + } + + return builder.ToString(); + } + } + } +} diff --git a/IL/ILLabel.cs b/IL/Label.cs similarity index 94% rename from IL/ILLabel.cs rename to IL/Label.cs index f7999b6..b41fdbf 100644 --- a/IL/ILLabel.cs +++ b/IL/Label.cs @@ -70,11 +70,11 @@ public int CompareTo(T_SELF? other) } } - public class ILLabel : AbstractLabel + public class Label : AbstractLabel