Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ obj/
bin/
dist/
build/
Folder.DotSettings.user/
Folder.DotSettings.user
3 changes: 0 additions & 3 deletions Handle/BNFlowGraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,5 @@ public void SetOutgoingEdgePoints(ulong edgeNum, Point[] points)
(ulong)points.Length
);
}



}
}
4 changes: 1 addition & 3 deletions HighLevelIL/HighLevelILBasicBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BinaryNinja
{
public sealed class HighLevelILBasicBlock : AbstractBasicBlock<HighLevelILBasicBlock>
{
internal HighLevelILFunction ILFunction { get; }
public HighLevelILFunction ILFunction { get; }

internal HighLevelILBasicBlock(
HighLevelILFunction function ,
Expand Down Expand Up @@ -46,7 +46,6 @@ IntPtr handle
true
);
}


public HighLevelILInstruction this[HighLevelILInstructionIndex index]
{
Expand Down Expand Up @@ -290,7 +289,6 @@ public HighLevelILBasicBlock[] PostDominatorTreeChildren
}
}


public HighLevelILBasicBlock[] GetDominanceFrontier(bool post)
{
ulong arrayLength = 0;
Expand Down
7 changes: 2 additions & 5 deletions HighLevelIL/HighLevelILFlowGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace BinaryNinja
{
public sealed class HighLevelILFlowGraph : AbstractFlowGraph<HighLevelILFlowGraph>
{
internal HighLevelILFunction ILFunction { get; set; }
public HighLevelILFunction ILFunction { get; }

internal HighLevelILFlowGraph(
HighLevelILFunction ilFunction,
Expand Down Expand Up @@ -95,8 +95,6 @@ internal static HighLevelILFlowGraph MustBorrowHandleEx(
return new HighLevelILFlowGraph(ilFunction , handle, false);
}



public HighLevelILFlowGraph? Update()
{
return HighLevelILFlowGraph.TakeHandleEx(
Expand Down Expand Up @@ -130,8 +128,7 @@ out ulong arrayLength
NativeMethods.BNGetFlowGraphNode(this.handle, index)
);
}



public HighLevelILFlowGraphNode[] GetNodesInRegion(
int left ,
int top ,
Expand Down
126 changes: 114 additions & 12 deletions HighLevelIL/HighLevelILFlowGraphEdge.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,128 @@
using System;

namespace BinaryNinja
{
public sealed class HighLevelILFlowGraphEdge : AbstractFlowGraphEdge<HighLevelILFlowGraphNode>
public sealed class HighLevelILFlowGraphEdge
: AbstractFlowGraphEdge<HighLevelILFlowGraphNode>,
IEquatable<HighLevelILFlowGraphEdge>,
IComparable<HighLevelILFlowGraphEdge>
{
internal HighLevelILFunction ILFunction { get; set; }

internal HighLevelILFlowGraphEdge(
HighLevelILFunction ilFunction,
BNFlowGraphEdge native)
: base(native , HighLevelILFlowGraphNode.NewFromHandleEx(ilFunction, native.target))
BNFlowGraphEdge native,
HighLevelILFlowGraphNode source,
HighLevelILFlowGraphNode target,
bool outgoing
) : base(native , source, target, outgoing)
{
this.ILFunction = ilFunction;

}

internal static HighLevelILFlowGraphEdge FromNativeEx(
HighLevelILFunction ilFunction,
BNFlowGraphEdge native
BNFlowGraphEdge native,
HighLevelILFlowGraphNode me,
bool outgoing
)
{
return new HighLevelILFlowGraphEdge(
ilFunction ,
native
if (outgoing)
{
return new HighLevelILFlowGraphEdge(
native,
me ,
HighLevelILFlowGraphNode.MustNewFromHandleEx(me.ILFunction, native.target),
outgoing
);
}
else
{
return new HighLevelILFlowGraphEdge(
native,
HighLevelILFlowGraphNode.MustNewFromHandleEx(me.ILFunction,native.target) ,
me,
outgoing
);
}
}

public override bool Equals(object? other)
{
return this.Equals(other as HighLevelILFlowGraphEdge);
}

public bool Equals(HighLevelILFlowGraphEdge? other)
{
if (other is null)
{
return false;
}

if (ReferenceEquals(this , other))
{
return true;
}

if (this.Type != other.Type)
{
return false;
}

if (this.Source != other.Source)
{
return false;
}

if (this.Target != other.Target)
{
return false;
}

return true;
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals")]
public override int GetHashCode()
{
return HashCode.Combine<uint,int,int>(
(uint)this.Type,
this.Source.GetHashCode(),
this.Target.GetHashCode()
);
}

public static bool operator ==(HighLevelILFlowGraphEdge? left, HighLevelILFlowGraphEdge? right)
{
if (left is null)
{
return right is null;
}

return left.Equals(right);
}

public static bool operator !=(HighLevelILFlowGraphEdge? left, HighLevelILFlowGraphEdge? right)
{
return !(left == right);
}

public int CompareTo(HighLevelILFlowGraphEdge? other)
{
if (other is null)
{
return 1;
}

int result = this.Type.CompareTo(other.Type);

if (0 == result)
{
result = this.Source.CompareTo(other.Source);
}

if (0 == result)
{
result = this.Target.CompareTo(other.Target);
}

return result;
}
}
}
23 changes: 13 additions & 10 deletions HighLevelIL/HighLevelILFlowGraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace BinaryNinja
{
public sealed class HighLevelILFlowGraphNode : FlowGraphNode
{
internal HighLevelILFunction ILFunction { get; set; }
public HighLevelILFunction ILFunction { get; }

internal HighLevelILFlowGraphNode(
HighLevelILFunction ilFunction,
Expand Down Expand Up @@ -107,7 +107,6 @@ internal static HighLevelILFlowGraphNode MustBorrowHandleEx(
false);
}


public HighLevelILBasicBlock? BasicBlock
{
get
Expand All @@ -131,17 +130,19 @@ public HighLevelILFlowGraphEdge[] IncomingEdges
{
get
{
ulong arrayLength = 0;

IntPtr arrayPointer = NativeMethods.BNGetFlowGraphNodeIncomingEdges(
this.handle,
out arrayLength
out ulong arrayLength
);

return UnsafeUtils.TakeStructArrayEx<BNFlowGraphEdge,HighLevelILFlowGraphEdge>(
arrayPointer,
arrayLength,
(_native) => HighLevelILFlowGraphEdge.FromNativeEx(this.ILFunction, _native),
(_native) => HighLevelILFlowGraphEdge.FromNativeEx(
_native,
this,
false
),
NativeMethods.BNFreeFlowGraphNodeEdgeList
);
}
Expand All @@ -151,17 +152,19 @@ public HighLevelILFlowGraphEdge[] OutgoingEdges
{
get
{
ulong arrayLength = 0;

IntPtr arrayPointer = NativeMethods.BNGetFlowGraphNodeOutgoingEdges(
this.handle,
out arrayLength
out ulong arrayLength
);

return UnsafeUtils.TakeStructArrayEx<BNFlowGraphEdge,HighLevelILFlowGraphEdge>(
arrayPointer,
arrayLength,
(_native) => HighLevelILFlowGraphEdge.FromNativeEx(this.ILFunction, _native),
(_native) => HighLevelILFlowGraphEdge.FromNativeEx(
_native,
this,
true
),
NativeMethods.BNFreeFlowGraphNodeEdgeList
);
}
Expand Down
35 changes: 26 additions & 9 deletions LowLevelIL/LowLevelILFlowGraphEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@ namespace BinaryNinja
public sealed class LowLevelILFlowGraphEdge : AbstractFlowGraphEdge<LowLevelILFlowGraphNode>
{
public LowLevelILFlowGraphEdge(
LowLevelILFunction ilFunction,
BNFlowGraphEdge native)
: base(native , LowLevelILFlowGraphNode.NewFromHandleEx(ilFunction, native.target))
BNFlowGraphEdge native,
LowLevelILFlowGraphNode source,
LowLevelILFlowGraphNode target,
bool outgoing
) : base(native , source, target, outgoing)
{

}

internal static LowLevelILFlowGraphEdge FromNativeEx(
LowLevelILFunction ilFunction,
BNFlowGraphEdge native
BNFlowGraphEdge native,
LowLevelILFlowGraphNode me,
bool outgoing
)
{
return new LowLevelILFlowGraphEdge(
ilFunction ,
native
);
if (outgoing)
{
return new LowLevelILFlowGraphEdge(
native,
me ,
LowLevelILFlowGraphNode.MustNewFromHandleEx(me.ILFunction, native.target),
outgoing
);
}
else
{
return new LowLevelILFlowGraphEdge(
native,
LowLevelILFlowGraphNode.MustNewFromHandleEx(me.ILFunction,native.target) ,
me,
outgoing
);
}
}
}
}
20 changes: 12 additions & 8 deletions LowLevelIL/LowLevelILFlowGraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,19 @@ public LowLevelILFlowGraphEdge[] IncomingEdges
{
get
{
ulong arrayLength = 0;

IntPtr arrayPointer = NativeMethods.BNGetFlowGraphNodeIncomingEdges(
this.handle,
out arrayLength
out ulong arrayLength
);

return UnsafeUtils.TakeStructArrayEx<BNFlowGraphEdge,LowLevelILFlowGraphEdge>(
arrayPointer,
arrayLength,
(_native) => LowLevelILFlowGraphEdge.FromNativeEx(this.ILFunction, _native),
(_native) => LowLevelILFlowGraphEdge.FromNativeEx(
_native,
this,
false
),
NativeMethods.BNFreeFlowGraphNodeEdgeList
);
}
Expand All @@ -151,17 +153,19 @@ public LowLevelILFlowGraphEdge[] OutgoingEdges
{
get
{
ulong arrayLength = 0;

IntPtr arrayPointer = NativeMethods.BNGetFlowGraphNodeOutgoingEdges(
this.handle,
out arrayLength
out ulong arrayLength
);

return UnsafeUtils.TakeStructArrayEx<BNFlowGraphEdge,LowLevelILFlowGraphEdge>(
arrayPointer,
arrayLength,
(_native) => LowLevelILFlowGraphEdge.FromNativeEx(this.ILFunction, _native),
(_native) => LowLevelILFlowGraphEdge.FromNativeEx(
_native,
this,
true
),
NativeMethods.BNFreeFlowGraphNodeEdgeList
);
}
Expand Down
Loading