From c7784c8839497f3a3eac03c694c5d449f9dfe06b Mon Sep 17 00:00:00 2001 From: tinysec Date: Thu, 27 Nov 2025 14:02:01 +0800 Subject: [PATCH 01/30] fix: InstructionTextLine --- Struct/BNInstructionTextLine.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Struct/BNInstructionTextLine.cs b/Struct/BNInstructionTextLine.cs index 8ea90aa..3ef7a48 100644 --- a/Struct/BNInstructionTextLine.cs +++ b/Struct/BNInstructionTextLine.cs @@ -39,6 +39,8 @@ public InstructionTextLine( InstructionTextToken[] tokens ) { + this.Address = address; + this.Data = data; this.Tokens = tokens; } From 5954d6ca581a6a7885c4d50050fb143f2211fe86 Mon Sep 17 00:00:00 2001 From: tinysec Date: Thu, 27 Nov 2025 14:34:42 +0800 Subject: [PATCH 02/30] Instruction --- Handle/BNArchitecture.cs | 56 +++++++++++--------- Handle/BNBasicBlock.cs | 55 ++++++++++++------- IL/Instruction.cs | 25 +++++++++ Struct/BNInstructionInfo.cs | 94 ++++++++++++++------------------- Struct/BNInstructionTextLine.cs | 12 +---- 5 files changed, 134 insertions(+), 108 deletions(-) create mode 100644 IL/Instruction.cs diff --git a/Handle/BNArchitecture.cs b/Handle/BNArchitecture.cs index 7b11242..8fcb753 100644 --- a/Handle/BNArchitecture.cs +++ b/Handle/BNArchitecture.cs @@ -486,41 +486,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 +528,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 +552,10 @@ out arrayLength NativeMethods.BNFreeInstructionText ); } + else + { + length = 0; + } return tokens; } diff --git a/Handle/BNBasicBlock.cs b/Handle/BNBasicBlock.cs index a2d31b3..fd6ffbc 100644 --- a/Handle/BNBasicBlock.cs +++ b/Handle/BNBasicBlock.cs @@ -714,16 +714,8 @@ public BasicBlock[] PostDominanceFrontier return this.GetDominanceFrontier(true); } } - - public IEnumerable InstructionTextLines - { - get - { - return this.GetInstructionTextLines(); - } - } - - public IEnumerable GetInstructionTextLines() + + public IEnumerable GetInstructions() { if (null == this.View) { @@ -734,27 +726,54 @@ public IEnumerable GetInstructionTextLines() while (address < this.End) { - ulong length = this.End - address; + ulong bufferLength = this.End - address; - length = Math.Min(this.Architecture.MaxInstructionLength, this.Length - address); + bufferLength = Math.Min(this.Architecture.MaxInstructionLength, this.Length - address); + + byte[] buffer = this.View.ReadData(address , bufferLength); - byte[] data = this.View.ReadData(address , length); + InstructionInfo? info = this.Architecture.GetInstructionInfo(buffer , address); + + if (null == info) + { + throw new Exception("get instruction info fail"); + } + if (0 == info.Length) + { + throw new Exception("Instruction length out of range"); + } + + byte[] data = new byte[info.Length]; + InstructionTextToken[] tokens = this.Architecture.GetInstructionText( data , address , - ref length + out ulong instrLength ); - if (0 == length) + if (instrLength != info.Length) { - break; + throw new Exception("Instruction length mismatch"); } - yield return new InstructionTextLine(address , data , tokens); + yield return new Instruction( + data, + info, + tokens + ); - address += length; + address += instrLength; + } + } + + public IEnumerable Instructions + { + get + { + return this.GetInstructions(); } } + } } \ No newline at end of file diff --git a/IL/Instruction.cs b/IL/Instruction.cs new file mode 100644 index 0000000..14ddae4 --- /dev/null +++ b/IL/Instruction.cs @@ -0,0 +1,25 @@ +using System; +using System.Reflection.Emit; + +namespace BinaryNinja +{ + public sealed class Instruction + { + public byte[] Data { get; } = Array.Empty(); + + public InstructionInfo Info { get; } + + public InstructionTextToken[] Tokens { get; } = Array.Empty(); + + public Instruction( + byte[] data, + InstructionInfo info , + InstructionTextToken[] tokens + ) + { + this.Data = data; + this.Info = info; + this.Tokens = tokens; + } + } +} diff --git a/Struct/BNInstructionInfo.cs b/Struct/BNInstructionInfo.cs index 44897cd..afbe84c 100644 --- a/Struct/BNInstructionInfo.cs +++ b/Struct/BNInstructionInfo.cs @@ -53,91 +53,77 @@ public unsafe struct BNInstructionInfo internal IntPtr branchArch_2; } + public sealed class InstructionBranch + { + public BranchType Type { get; } = BranchType.UnconditionalBranch; + + public ulong Address { get; } = 0; + + public Architecture? Architecture { get; } = null; + + public InstructionBranch( + BranchType type , + ulong address , + Architecture? arch + ) + { + this.Type = type; + this.Address = address; + this.Architecture = arch; + } + } + public sealed class InstructionInfo { public ulong Length { get;} = 0; - public ulong BranchCount { get;} = 0; - public bool ArchTransitionByTargetAddr { get;} = false; public byte DelaySlots { get; } = 0; - public BranchType[] BranchType { get;} = Array.Empty(); - - public ulong[] BranchTarget { get;} = Array.Empty(); - - public Architecture[] BranchArch { get;} = Array.Empty(); - + public InstructionBranch[] Branches { get;} = Array.Empty(); + public InstructionInfo() { - + } public InstructionInfo(BNInstructionInfo native) { this.Length = native.length; - - this.BranchCount = native.branchCount; - + this.ArchTransitionByTargetAddr = native.archTransitionByTargetAddr; this.DelaySlots = native.delaySlots; - // BranchType - List branchTypes = new List(); - - for (ulong i = 0; i < this.BranchCount; i++) + this.Branches = new InstructionBranch[native.branchCount]; + + for (ulong i = 0; i < native.branchCount; i++) { - unsafe - { - branchTypes.Add( (BranchType)native.branchType[i] ); - } - } - - this.BranchType = branchTypes.ToArray(); - - // BranchTarget - List branchTargets = new List(); + Architecture? arch = null; - for (ulong i = 0; i < this.BranchCount; i++) - { - unsafe + if ( 0 == i) { - branchTargets.Add( native.branchTarget[i] ); + arch = Architecture.FromHandle(native.branchArch_0); } - } - - this.BranchTarget = branchTargets.ToArray(); - - // BranchArch - List branchArches = new List(); - - if (this.BranchCount >= 1) - { - if (IntPtr.Zero != native.branchArch_0) + else if ( 1 == i) { - branchArches.Add( new Architecture( native.branchArch_0 ) ); + arch = Architecture.FromHandle(native.branchArch_1); } - } - - if (this.BranchCount >= 2) - { - if (IntPtr.Zero != native.branchArch_1) + else if ( 2 == i) { - branchArches.Add( new Architecture( native.branchArch_1 ) ); + arch = Architecture.FromHandle(native.branchArch_2); } - } - if (this.BranchCount >= 3) - { - if (IntPtr.Zero != native.branchArch_2) + unsafe { - branchArches.Add( new Architecture( native.branchArch_2 ) ); + this.Branches[i] = new InstructionBranch( + (BranchType)native.branchType[i] , + native.branchTarget[i] , + arch + ); } } - - this.BranchArch = branchArches.ToArray(); } internal static InstructionInfo FromNative(BNInstructionInfo native) diff --git a/Struct/BNInstructionTextLine.cs b/Struct/BNInstructionTextLine.cs index 3ef7a48..541fc4f 100644 --- a/Struct/BNInstructionTextLine.cs +++ b/Struct/BNInstructionTextLine.cs @@ -22,10 +22,6 @@ internal unsafe struct BNInstructionTextLine public sealed class InstructionTextLine { - public ulong Address { get; } = 0; - - public byte[] Data { get; } = Array.Empty(); - public InstructionTextToken[] Tokens { get; } = Array.Empty(); public InstructionTextLine() @@ -33,14 +29,8 @@ public InstructionTextLine() } - public InstructionTextLine( - ulong address, - byte[] data, - InstructionTextToken[] tokens - ) + public InstructionTextLine(InstructionTextToken[] tokens) { - this.Address = address; - this.Data = data; this.Tokens = tokens; } From 84aec1be191a059ae47d94e8c72592400c3d9296 Mon Sep 17 00:00:00 2001 From: tinysec Date: Thu, 27 Nov 2025 14:35:49 +0800 Subject: [PATCH 03/30] Instructions --- Handle/BNBasicBlock.cs | 89 ++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/Handle/BNBasicBlock.cs b/Handle/BNBasicBlock.cs index fd6ffbc..e2f6ee2 100644 --- a/Handle/BNBasicBlock.cs +++ b/Handle/BNBasicBlock.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Drawing; +using System.Linq; using System.Runtime.InteropServices; using System.Text; using Microsoft.Win32.SafeHandles; @@ -680,7 +681,6 @@ public BasicBlock[] PostDominatorTreeChildren } } - public BasicBlock[] GetDominanceFrontier(bool post) { ulong arrayLength = 0; @@ -714,64 +714,59 @@ public BasicBlock[] PostDominanceFrontier return this.GetDominanceFrontier(true); } } - - public IEnumerable GetInstructions() + + public IEnumerable Instructions { - if (null == this.View) + get { - 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 bufferLength = this.End - address; + while (address < this.End) + { + ulong bufferLength = this.End - address; - bufferLength = Math.Min(this.Architecture.MaxInstructionLength, this.Length - address); + bufferLength = Math.Min(this.Architecture.MaxInstructionLength, this.Length - address); - byte[] buffer = this.View.ReadData(address , bufferLength); + byte[] buffer = this.View.ReadData(address , bufferLength); - InstructionInfo? info = this.Architecture.GetInstructionInfo(buffer , address); + InstructionInfo? info = this.Architecture.GetInstructionInfo(buffer , address); - if (null == info) - { - throw new Exception("get instruction info fail"); - } + if (null == info) + { + throw new Exception("get instruction info fail"); + } - if (0 == info.Length) - { - throw new Exception("Instruction length out of range"); - } + if (0 == info.Length) + { + throw new Exception("Instruction length out of range"); + } - byte[] data = new byte[info.Length]; + byte[] data = new byte[info.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( - data, - info, - tokens - ); + InstructionTextToken[] tokens = this.Architecture.GetInstructionText( + data , + address , + out ulong instrLength + ); + + if (instrLength != info.Length) + { + throw new Exception("Instruction length mismatch"); + } + + yield return new Instruction( + data, + info, + tokens + ); - address += instrLength; - } - } - - public IEnumerable Instructions - { - get - { - return this.GetInstructions(); + address += instrLength; + } } } From ab97959e3e53660e697eb3a9b2deb9eaf412d9aa Mon Sep 17 00:00:00 2001 From: tinysec Date: Thu, 27 Nov 2025 14:47:38 +0800 Subject: [PATCH 04/30] feat: add equals for InstructionInfo --- Struct/BNInstructionInfo.cs | 228 +++++++++++++++++++++++++++++++++++- 1 file changed, 226 insertions(+), 2 deletions(-) diff --git a/Struct/BNInstructionInfo.cs b/Struct/BNInstructionInfo.cs index afbe84c..065b23f 100644 --- a/Struct/BNInstructionInfo.cs +++ b/Struct/BNInstructionInfo.cs @@ -53,7 +53,9 @@ public unsafe struct BNInstructionInfo internal IntPtr branchArch_2; } - public sealed class InstructionBranch + public sealed class InstructionBranch : + IEquatable, + IComparable { public BranchType Type { get; } = BranchType.UnconditionalBranch; @@ -71,9 +73,102 @@ public InstructionBranch( this.Address = address; this.Architecture = arch; } + + public override bool Equals(object? other) + { + return this.Equals(other as InstructionBranch); + } + + public bool Equals(InstructionBranch? other) + { + if (other is null) + { + return false; + } + + if (ReferenceEquals(this , other)) + { + return true; + } + + if (this.Type != other.Type) + { + return false; + } + + if (this.Address != other.Address) + { + return false; + } + + return this.Architecture == other.Architecture; + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals")] + public override int GetHashCode() + { + return HashCode.Combine( + (uint)this.Type, + (ulong)this.Address, + null == this.Architecture ? 0 : this.Architecture.GetHashCode() + ); + } + + public static bool operator ==(InstructionBranch? left, InstructionBranch? right) + { + if (left is null) + { + return right is null; + } + + return left.Equals(right); + } + + public static bool operator !=(InstructionBranch? left, InstructionBranch? right) + { + return !(left == right); + } + + public int CompareTo(InstructionBranch? other) + { + if (other is null) + { + return 1; + } + + int result = this.Type.CompareTo(other.Type); + + if (0 == result) + { + result = this.Address.CompareTo(other.Address); + } + + if (0 == result) + { + if (null == this.Architecture) + { + if (null == other.Architecture) + { + result = 0; + } + else + { + result = -1; + } + } + else + { + result = this.Architecture.CompareTo(other.Architecture); + } + } + + return result; + } } - public sealed class InstructionInfo + public sealed class InstructionInfo : + IEquatable, + IComparable { public ulong Length { get;} = 0; @@ -130,5 +225,134 @@ internal static InstructionInfo FromNative(BNInstructionInfo native) { return new InstructionInfo(native); } + + public override bool Equals(object? other) + { + return this.Equals(other as InstructionInfo); + } + + public bool Equals(InstructionInfo? other) + { + if (other is null) + { + return false; + } + + if (ReferenceEquals(this , other)) + { + return true; + } + + if (this.Length != other.Length) + { + return false; + } + + if (this.ArchTransitionByTargetAddr != other.ArchTransitionByTargetAddr) + { + return false; + } + + if (this.DelaySlots != other.DelaySlots) + { + return false; + } + + if (this.Branches.Length != other.Branches.Length) + { + return false; + } + + for (int i = 0; i < this.Branches.Length; i++) + { + if (this.Branches[i] != other.Branches[i]) + { + return false; + } + } + + return true; + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals")] + public override int GetHashCode() + { + return HashCode.Combine( + this.Length, + this.ArchTransitionByTargetAddr, + this.DelaySlots, + this.Branches.GetHashCode() + ); + } + + public static bool operator ==(InstructionInfo? left, InstructionInfo? right) + { + if (left is null) + { + return right is null; + } + + return left.Equals(right); + } + + public static bool operator !=(InstructionInfo? left, InstructionInfo? right) + { + return !(left == right); + } + + public int CompareTo(InstructionInfo? other) + { + if (other is null) + { + return 1; + } + + int result = this.Length.CompareTo(other.Length); + + if (0 == result) + { + result = this.ArchTransitionByTargetAddr.CompareTo(other.ArchTransitionByTargetAddr); + } + + if (0 == result) + { + result = this.DelaySlots.CompareTo(other.DelaySlots); + } + + if (0 == result) + { + if (this.Branches.Length <= other.Branches.Length) + { + return -1; + } + else if (this.Branches.Length > other.Branches.Length) + { + return 1; + } + else + { + for (int i = 0; i < this.Branches.Length; i++) + { + int code = this.Branches[i].CompareTo(other.Branches[i]); + + if ( code < 0) + { + return -1; + } + else if ( code > 0 ) + { + return 1; + } + else + { + + } + } + } + } + + return result; + } + } } \ No newline at end of file From a4c51772c1b8fdaa4e0b2e264462a93eee1c7228 Mon Sep 17 00:00:00 2001 From: tinysec Date: Thu, 27 Nov 2025 14:54:32 +0800 Subject: [PATCH 05/30] feat: asm level Instruction --- Handle/BNBasicBlock.cs | 1 + IL/Instruction.cs | 92 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Handle/BNBasicBlock.cs b/Handle/BNBasicBlock.cs index e2f6ee2..06491a1 100644 --- a/Handle/BNBasicBlock.cs +++ b/Handle/BNBasicBlock.cs @@ -760,6 +760,7 @@ out ulong instrLength } yield return new Instruction( + address , data, info, tokens diff --git a/IL/Instruction.cs b/IL/Instruction.cs index 14ddae4..72abfe6 100644 --- a/IL/Instruction.cs +++ b/IL/Instruction.cs @@ -1,10 +1,15 @@ using System; using System.Reflection.Emit; +using System.Text; namespace BinaryNinja { - public sealed class Instruction + public sealed class Instruction : + IEquatable, + IComparable { + public ulong Address { get; } + public byte[] Data { get; } = Array.Empty(); public InstructionInfo Info { get; } @@ -12,14 +17,99 @@ public sealed class Instruction public InstructionTextToken[] Tokens { get; } = Array.Empty(); public Instruction( + ulong address, byte[] data, InstructionInfo info , InstructionTextToken[] tokens ) { + 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; + } } } From 3f72b4f2500a1614b16b3642961b01176c426e52 Mon Sep 17 00:00:00 2001 From: tinysec Date: Thu, 27 Nov 2025 14:57:20 +0800 Subject: [PATCH 06/30] fix: simple name --- Handle/BNArchitecture.cs | 38 +++++------ Handle/BNLowLevelILFunction.cs | 76 ++++++++++----------- IL/{ILFlag.cs => Flag.cs} | 16 ++--- IL/FlagOrRegister.cs | 8 +-- IL/{ILLabel.cs => Label.cs} | 4 +- IL/{ILRegister.cs => Register.cs} | 18 ++--- LowLevelIL/LLILAssert.cs | 2 +- LowLevelIL/LLILFlag.cs | 2 +- LowLevelIL/LLILFlagBit.cs | 2 +- LowLevelIL/LLILForceVersion.cs | 2 +- LowLevelIL/LLILRegister.cs | 2 +- LowLevelIL/LLILRegisterSSAPartial.cs | 2 +- LowLevelIL/LLILRegisterSplit.cs | 4 +- LowLevelIL/LLILRegisterStackAbsSSA.cs | 2 +- LowLevelIL/LLILRegisterStackFreeAbsSSA.cs | 2 +- LowLevelIL/LLILRegisterStackFreeRegister.cs | 2 +- LowLevelIL/LLILSetFlag.cs | 2 +- LowLevelIL/LLILSetRegister.cs | 2 +- LowLevelIL/LLILSetRegisterSSAPartial.cs | 2 +- LowLevelIL/LLILSetRegisterSplit.cs | 4 +- LowLevelIL/LLILSetRegisterStackAbsSSA.cs | 2 +- LowLevelIL/LowLevelILFlag.cs | 4 +- LowLevelIL/LowLevelILSSAFlag.cs | 2 +- LowLevelIL/LowLevelILSSARegister.cs | 4 +- Struct/BNLowLevelILInstruction.cs | 20 +++--- 25 files changed, 112 insertions(+), 112 deletions(-) rename IL/{ILFlag.cs => Flag.cs} (75%) rename IL/{ILLabel.cs => Label.cs} (94%) rename IL/{ILRegister.cs => Register.cs} (78%) diff --git a/Handle/BNArchitecture.cs b/Handle/BNArchitecture.cs index 8fcb753..63d8fc3 100644 --- a/Handle/BNArchitecture.cs +++ b/Handle/BNArchitecture.cs @@ -124,7 +124,7 @@ public ulong OpcodeDisplayLength } } - public ILRegister[] FullWidthRegisters + public Register[] FullWidthRegisters { get { @@ -139,18 +139,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 +165,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 +191,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 +217,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 +243,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(); @@ -574,9 +574,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) ); @@ -885,11 +885,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/BNLowLevelILFunction.cs b/Handle/BNLowLevelILFunction.cs index d0c5f5f..e86f9d9 100644 --- a/Handle/BNLowLevelILFunction.cs +++ b/Handle/BNLowLevelILFunction.cs @@ -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) @@ -1929,7 +1929,7 @@ public LowLevelILExpressionIndex EmitAdd( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -1947,7 +1947,7 @@ public LowLevelILExpressionIndex EmitAddCarray( LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, LowLevelILExpressionIndex carray, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -1965,7 +1965,7 @@ public LowLevelILExpressionIndex EmitSub( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -1983,7 +1983,7 @@ public LowLevelILExpressionIndex EmitSubBorrow( LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, LowLevelILExpressionIndex carray, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2002,7 +2002,7 @@ public LowLevelILExpressionIndex EmitAnd( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2019,7 +2019,7 @@ public LowLevelILExpressionIndex EmitOr( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2036,7 +2036,7 @@ public LowLevelILExpressionIndex EmitXor( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2053,7 +2053,7 @@ public LowLevelILExpressionIndex EmitLogicalShiftLeft( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2070,7 +2070,7 @@ public LowLevelILExpressionIndex EmitLogicalShiftRight( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2087,7 +2087,7 @@ public LowLevelILExpressionIndex EmitArithmeticShiftRight( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2104,7 +2104,7 @@ public LowLevelILExpressionIndex EmitRotateLeft( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2122,7 +2122,7 @@ public LowLevelILExpressionIndex EmitRotateLeftCarray( LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, LowLevelILExpressionIndex carray, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2140,7 +2140,7 @@ public LowLevelILExpressionIndex EmitRotateRight( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2158,7 +2158,7 @@ public LowLevelILExpressionIndex EmitRotateRightCarray( LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, LowLevelILExpressionIndex carray, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2176,7 +2176,7 @@ public LowLevelILExpressionIndex EmitMul( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2193,7 +2193,7 @@ public LowLevelILExpressionIndex EmitMulSignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2210,7 +2210,7 @@ public LowLevelILExpressionIndex EmitMulUnsignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2227,7 +2227,7 @@ public LowLevelILExpressionIndex EmitDivSigned( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2244,7 +2244,7 @@ public LowLevelILExpressionIndex EmitDivSignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2261,7 +2261,7 @@ public LowLevelILExpressionIndex EmitDivUnsigned( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2278,7 +2278,7 @@ public LowLevelILExpressionIndex EmitDivUnsignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2297,7 +2297,7 @@ public LowLevelILExpressionIndex EmitModSigned( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2314,7 +2314,7 @@ public LowLevelILExpressionIndex EmitModSignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2331,7 +2331,7 @@ public LowLevelILExpressionIndex EmitModUnsigned( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2348,7 +2348,7 @@ public LowLevelILExpressionIndex EmitModUnsignedDoublePrecision( ulong size , LowLevelILExpressionIndex a, LowLevelILExpressionIndex b, - ILFlag? flag = null, + Flag? flag = null, SourceLocation? location = null) { return this.AddExpression( @@ -2364,7 +2364,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 +2379,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 +2394,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 +2409,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 +2424,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/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/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