|
| 1 | +using System; |
| 2 | + |
1 | 3 | namespace BinaryNinja |
2 | 4 | { |
3 | | - public sealed class HighLevelILFlowGraphEdge : AbstractFlowGraphEdge<HighLevelILFlowGraphNode> |
| 5 | + public sealed class HighLevelILFlowGraphEdge |
| 6 | + : AbstractFlowGraphEdge<HighLevelILFlowGraphNode>, |
| 7 | + IEquatable<HighLevelILFlowGraphEdge>, |
| 8 | + IComparable<HighLevelILFlowGraphEdge> |
4 | 9 | { |
5 | | - internal HighLevelILFunction ILFunction { get; set; } |
6 | | - |
7 | 10 | internal HighLevelILFlowGraphEdge( |
8 | | - HighLevelILFunction ilFunction, |
9 | | - BNFlowGraphEdge native) |
10 | | - : base(native , HighLevelILFlowGraphNode.NewFromHandleEx(ilFunction, native.target)) |
| 11 | + BNFlowGraphEdge native, |
| 12 | + HighLevelILFlowGraphNode source, |
| 13 | + HighLevelILFlowGraphNode target, |
| 14 | + bool outgoing |
| 15 | + ) : base(native , source, target, outgoing) |
11 | 16 | { |
12 | | - this.ILFunction = ilFunction; |
| 17 | + |
13 | 18 | } |
14 | 19 |
|
15 | 20 | internal static HighLevelILFlowGraphEdge FromNativeEx( |
16 | | - HighLevelILFunction ilFunction, |
17 | | - BNFlowGraphEdge native |
| 21 | + BNFlowGraphEdge native, |
| 22 | + HighLevelILFlowGraphNode me, |
| 23 | + bool outgoing |
18 | 24 | ) |
19 | 25 | { |
20 | | - return new HighLevelILFlowGraphEdge( |
21 | | - ilFunction , |
22 | | - native |
| 26 | + if (outgoing) |
| 27 | + { |
| 28 | + return new HighLevelILFlowGraphEdge( |
| 29 | + native, |
| 30 | + me , |
| 31 | + HighLevelILFlowGraphNode.MustNewFromHandleEx(me.ILFunction, native.target), |
| 32 | + outgoing |
| 33 | + ); |
| 34 | + } |
| 35 | + else |
| 36 | + { |
| 37 | + return new HighLevelILFlowGraphEdge( |
| 38 | + native, |
| 39 | + HighLevelILFlowGraphNode.MustNewFromHandleEx(me.ILFunction,native.target) , |
| 40 | + me, |
| 41 | + outgoing |
| 42 | + ); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public override bool Equals(object? other) |
| 47 | + { |
| 48 | + return this.Equals(other as HighLevelILFlowGraphEdge); |
| 49 | + } |
| 50 | + |
| 51 | + public bool Equals(HighLevelILFlowGraphEdge? other) |
| 52 | + { |
| 53 | + if (other is null) |
| 54 | + { |
| 55 | + return false; |
| 56 | + } |
| 57 | + |
| 58 | + if (ReferenceEquals(this , other)) |
| 59 | + { |
| 60 | + return true; |
| 61 | + } |
| 62 | + |
| 63 | + if (this.Type != other.Type) |
| 64 | + { |
| 65 | + return false; |
| 66 | + } |
| 67 | + |
| 68 | + if (this.Source != other.Source) |
| 69 | + { |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | + if (this.Target != other.Target) |
| 74 | + { |
| 75 | + return false; |
| 76 | + } |
| 77 | + |
| 78 | + return true; |
| 79 | + } |
| 80 | + |
| 81 | + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals")] |
| 82 | + public override int GetHashCode() |
| 83 | + { |
| 84 | + return HashCode.Combine<uint,int,int>( |
| 85 | + (uint)this.Type, |
| 86 | + this.Source.GetHashCode(), |
| 87 | + this.Target.GetHashCode() |
23 | 88 | ); |
24 | 89 | } |
| 90 | + |
| 91 | + public static bool operator ==(HighLevelILFlowGraphEdge? left, HighLevelILFlowGraphEdge? right) |
| 92 | + { |
| 93 | + if (left is null) |
| 94 | + { |
| 95 | + return right is null; |
| 96 | + } |
| 97 | + |
| 98 | + return left.Equals(right); |
| 99 | + } |
| 100 | + |
| 101 | + public static bool operator !=(HighLevelILFlowGraphEdge? left, HighLevelILFlowGraphEdge? right) |
| 102 | + { |
| 103 | + return !(left == right); |
| 104 | + } |
| 105 | + |
| 106 | + public int CompareTo(HighLevelILFlowGraphEdge? other) |
| 107 | + { |
| 108 | + if (other is null) |
| 109 | + { |
| 110 | + return 1; |
| 111 | + } |
| 112 | + |
| 113 | + int result = this.Type.CompareTo(other.Type); |
| 114 | + |
| 115 | + if (0 == result) |
| 116 | + { |
| 117 | + result = this.Source.CompareTo(other.Source); |
| 118 | + } |
| 119 | + |
| 120 | + if (0 == result) |
| 121 | + { |
| 122 | + result = this.Target.CompareTo(other.Target); |
| 123 | + } |
| 124 | + |
| 125 | + return result; |
| 126 | + } |
25 | 127 | } |
26 | 128 | } |
0 commit comments