Skip to content

Commit 1096ecb

Browse files
committed
feat: complete MLIL helper builders
1 parent dc2218d commit 1096ecb

4 files changed

Lines changed: 109 additions & 10 deletions

File tree

‎Handle/BNMediumLevelILFunction.cs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,12 +1932,7 @@ public MediumLevelILExpressionIndex EmitFloatConst(
19321932
SourceLocation? location = null
19331933
)
19341934
{
1935-
return this.AddExpression(
1936-
MediumLevelILOperation.MLIL_FLOAT_CONST,
1937-
location,
1938-
size,
1939-
value
1940-
);
1935+
return this.EmitFloatConstRaw(size, value, location);
19411936
}
19421937

19431938
public MediumLevelILExpressionIndex EmitImport(

‎MediumLevelIL/MLILFloatConst.cs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ public double Constant
1717
{
1818
get
1919
{
20-
return BitConverter.UInt64BitsToDouble(
21-
this.RawOperands[0]
22-
);
20+
if (4 == this.Size)
21+
{
22+
return this.GetOperandAsFloat(0);
23+
}
24+
25+
if (8 == this.Size)
26+
{
27+
return this.GetOperandAsDouble(0);
28+
}
29+
30+
return this.RawOperands[0];
2331
}
2432
}
2533
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
3+
namespace BinaryNinja
4+
{
5+
public sealed partial class MediumLevelILFunction
6+
{
7+
/// <summary>
8+
/// Creates a floating-point constant from its raw binary representation.
9+
/// </summary>
10+
public MediumLevelILExpressionIndex EmitFloatConstRaw(
11+
ulong size,
12+
ulong value,
13+
SourceLocation? location = null)
14+
{
15+
return this.AddExpression(
16+
MediumLevelILOperation.MLIL_FLOAT_CONST,
17+
location,
18+
size,
19+
value);
20+
}
21+
22+
/// <summary>
23+
/// Creates a single-precision floating-point constant.
24+
/// </summary>
25+
public MediumLevelILExpressionIndex EmitFloatConstSingle(
26+
float value,
27+
SourceLocation? location = null)
28+
{
29+
uint bits = BitConverter.SingleToUInt32Bits(value);
30+
31+
return this.EmitFloatConstRaw(4, bits, location);
32+
}
33+
34+
/// <summary>
35+
/// Creates a double-precision floating-point constant.
36+
/// </summary>
37+
public MediumLevelILExpressionIndex EmitFloatConstDouble(
38+
double value,
39+
SourceLocation? location = null)
40+
{
41+
ulong bits = BitConverter.DoubleToUInt64Bits(value);
42+
43+
return this.EmitFloatConstRaw(8, bits, location);
44+
}
45+
46+
/// <summary>
47+
/// Creates a helper expression holding a separately allocated parameter list.
48+
/// </summary>
49+
public MediumLevelILExpressionIndex EmitSeparateParamList(
50+
MediumLevelILExpressionIndex[] parameters,
51+
SourceLocation? location = null)
52+
{
53+
if (null == parameters)
54+
{
55+
throw new ArgumentNullException(nameof(parameters));
56+
}
57+
58+
return this.AddExpression(
59+
MediumLevelILOperation.MLIL_SEPARATE_PARAM_LIST,
60+
location,
61+
0,
62+
(ulong)parameters.Length,
63+
(ulong)this.AddOperandList(parameters));
64+
}
65+
66+
/// <summary>
67+
/// Creates a helper expression holding parameters that share a parameter slot.
68+
/// </summary>
69+
public MediumLevelILExpressionIndex EmitSharedParamSlot(
70+
MediumLevelILExpressionIndex[] parameters,
71+
SourceLocation? location = null)
72+
{
73+
if (null == parameters)
74+
{
75+
throw new ArgumentNullException(nameof(parameters));
76+
}
77+
78+
return this.AddExpression(
79+
MediumLevelILOperation.MLIL_SHARED_PARAM_SLOT,
80+
location,
81+
0,
82+
(ulong)parameters.Length,
83+
(ulong)this.AddOperandList(parameters));
84+
}
85+
}
86+
}

‎Struct/BNMediumLevelILInstruction.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,17 @@ public virtual IList<ILOperand> DetailedOperands
13761376
return this.GetOperandAsSSAVariableList(index);
13771377

13781378
case ILOperandKind.Float:
1379-
return this.GetOperandAsDouble(index);
1379+
if (4 == this.Size)
1380+
{
1381+
return (double)this.GetOperandAsFloat(index);
1382+
}
1383+
1384+
if (8 == this.Size)
1385+
{
1386+
return this.GetOperandAsDouble(index);
1387+
}
1388+
1389+
return (double)this.RawOperands[(ulong)index];
13801390

13811391
case ILOperandKind.ConstantData:
13821392
return this.GetOperandAsConstantData(index, secondaryIndex);

0 commit comments

Comments
 (0)