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
4 changes: 2 additions & 2 deletions Function/BNAddHighLevelILPointerTextToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal static extern SymbolDisplayResult BNAddHighLevelILPointerTextToken(
OperatorPrecedence precedence ,

// bool allowShortString
bool allowShortString
[MarshalAs(UnmanagedType.I1)] bool allowShortString
);
}
}
}
4 changes: 2 additions & 2 deletions Function/BNHighLevelILTokenEmitterRestoreCurrentExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static extern void BNHighLevelILTokenEmitterRestoreCurrentExpr(
IntPtr emitter ,

// BNTokenEmitterExpr expr
in BNTokenEmitterExpr expr
BNTokenEmitterExpr expr
);
}
}
}
4 changes: 2 additions & 2 deletions Function/BNHighLevelILTokenEmitterScopeContinuation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static extern void BNHighLevelILTokenEmitterScopeContinuation(
IntPtr emitter ,

// bool forceSameLine
bool forceSameLine
[MarshalAs(UnmanagedType.I1)] bool forceSameLine
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ internal static extern void BNHighLevelILTokenEmitterSetBracesAroundSwitchCases(
IntPtr emitter ,

// bool braces
bool braces
[MarshalAs(UnmanagedType.I1)] bool braces

);
}
}
}
4 changes: 2 additions & 2 deletions Function/BNHighLevelILTokenEmitterSetCurrentExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static extern BNTokenEmitterExpr BNHighLevelILTokenEmitterSetCurrentExp
IntPtr emitter ,

// BNTokenEmitterExpr expr
in BNTokenEmitterExpr expr
BNTokenEmitterExpr expr
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ internal static extern void BNHighLevelILTokenEmitterSetDefaultBracesOnSameLine(
IntPtr emitter ,

// bool sameLine
bool sameLine
[MarshalAs(UnmanagedType.I1)] bool sameLine

);
}
}
}
4 changes: 2 additions & 2 deletions Function/BNHighLevelILTokenEmitterSetHasCollapsableRegions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static extern void BNHighLevelILTokenEmitterSetHasCollapsableRegions(
IntPtr emitter ,

// bool state
bool state
[MarshalAs(UnmanagedType.I1)] bool state
);
}
}
}
4 changes: 2 additions & 2 deletions Function/BNHighLevelILTokenEmitterSetSimpleScopeAllowed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ internal static extern void BNHighLevelILTokenEmitterSetSimpleScopeAllowed(
IntPtr emitter ,

// bool allowed
bool allowed
[MarshalAs(UnmanagedType.I1)] bool allowed

);
}
}
}
41 changes: 37 additions & 4 deletions Handle/BNHighLevelILTokenEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace BinaryNinja
{
public sealed class HighLevelILTokenEmitter : AbstractSafeHandle<HighLevelILTokenEmitter>
public sealed partial class HighLevelILTokenEmitter : AbstractSafeHandle<HighLevelILTokenEmitter>
{
internal HighLevelILTokenEmitter(IntPtr handle , bool owner)
: base(handle , owner)
Expand Down Expand Up @@ -181,16 +181,29 @@ public void EndForceZeroConfidence()
);
}

public void SetCurrentExpr(TokenEmitterExpression expr)
public TokenEmitterExpression SetCurrentExpr(TokenEmitterExpression expr)
{
NativeMethods.BNHighLevelILTokenEmitterSetCurrentExpr(
if (null == expr)
{
throw new ArgumentNullException(nameof(expr));
}

BNTokenEmitterExpr previous =
NativeMethods.BNHighLevelILTokenEmitterSetCurrentExpr(
this.handle ,
expr.ToNative()
);

return TokenEmitterExpression.FromNative(previous);
}

public void RestoreCurrentExpr(TokenEmitterExpression expr)
{
if (null == expr)
{
throw new ArgumentNullException(nameof(expr));
}

NativeMethods.BNHighLevelILTokenEmitterRestoreCurrentExpr(
this.handle,
expr.ToNative()
Expand All @@ -206,6 +219,11 @@ public void FinalizeEmit()

public void Append(InstructionTextToken token)
{
if (null == token)
{
throw new ArgumentNullException(nameof(token));
}

using (ScopedAllocator allocator = new ScopedAllocator())
{
NativeMethods.BNHighLevelILTokenEmitterAppend(
Expand Down Expand Up @@ -272,6 +290,11 @@ public BraceRequirement BraceRequirement
this.handle
);
}

set
{
this.SetBraceRequirement(value);
}
}

public InstructionTextToken[] GetCurrentTokens()
Expand All @@ -298,6 +321,11 @@ public InstructionTextToken[] GetCurrentTokens()

public void SetCurrentTokens(InstructionTextToken[] tokens)
{
if (null == tokens)
{
throw new ArgumentNullException(nameof(tokens));
}

using (ScopedAllocator allocator = new ScopedAllocator())
{
NativeMethods.BNHighLevelILTokenEmitterSetCurrentTokens(
Expand Down Expand Up @@ -403,6 +431,11 @@ public ulong GetMaxTernarySimplficationTokens()
);
}

public ulong GetMaxTernarySimplificationTokens()
{
return this.GetMaxTernarySimplficationTokens();
}

/// <summary>
/// Emits a floating-point size token (e.g., "float", "double") into the given token emitter.
/// This is a static utility that operates on a token emitter instance.
Expand Down Expand Up @@ -437,4 +470,4 @@ public static void AddSizeToken(ulong size , InstructionTextTokenType type , Hig
);
}
}
}
}
88 changes: 88 additions & 0 deletions Handle/BNHighLevelILTokenEmitterExpressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;

namespace BinaryNinja
{
public sealed partial class HighLevelILTokenEmitter
{
/// <summary>Restores a previous expression when disposed.</summary>
public sealed class CurrentExpressionScope : IDisposable
{
private HighLevelILTokenEmitter? emitter;

private readonly TokenEmitterExpression previous;

internal CurrentExpressionScope(
HighLevelILTokenEmitter emitter,
TokenEmitterExpression expression
)
{
this.emitter = emitter;
this.previous = emitter.SetCurrentExpr(expression);
}

public void Dispose()
{
HighLevelILTokenEmitter? current = this.emitter;
if (null == current)
{
return;
}

this.emitter = null;
current.RestoreCurrentExpr(this.previous);
}
}

/// <summary>Sets the current expression until the scope is disposed.</summary>
public CurrentExpressionScope SetCurrentExpr(
HighLevelILInstruction instruction
)
{
return new CurrentExpressionScope(
this,
TokenEmitterExpression.FromInstruction(instruction)
);
}

/// <summary>Prepends a blank collapse indicator.</summary>
public void PrependCollapseIndicator()
{
this.PrependCollapseBlankIndicator();
}

/// <summary>Prepends a collapse indicator for an instruction region.</summary>
public void PrependCollapseIndicator(
Function? function,
HighLevelILInstruction instruction,
ulong discriminator = 0
)
{
if (null == instruction)
{
throw new ArgumentNullException(nameof(instruction));
}

if (!this.HasCollapsableRegions)
{
return;
}

InstructionTextTokenContext context =
InstructionTextTokenContext.ContentCollapsiblePadding;
if (instruction.CanCollapse)
{
bool collapsed = null != function && function.IsRegionCollapsed(
instruction.GetInstructionHash(discriminator)
);
context = collapsed
? InstructionTextTokenContext.ContentCollapsedContext
: InstructionTextTokenContext.ContentExpandedContext;
}

this.PrependCollapseIndicator(
context,
instruction.GetInstructionHash(discriminator)
);
}
}
}
Loading
Loading