80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
// Copyright (c) StellaOps. All rights reserved.
|
|
// Licensed under BUSL-1.1. See LICENSE in the project root.
|
|
using StellaOps.BinaryIndex.Semantic;
|
|
using System.Collections.Immutable;
|
|
|
|
namespace StellaOps.BinaryIndex.Disassembly.B2R2;
|
|
|
|
public sealed partial class B2R2LowUirLiftingService
|
|
{
|
|
private static IrStatementKind MapB2R2StmtTypeToKind(string stmtType) => stmtType switch
|
|
{
|
|
"Put" or "Store" => IrStatementKind.Assign,
|
|
"Jmp" => IrStatementKind.Jump,
|
|
"CJmp" => IrStatementKind.ConditionalJump,
|
|
"Call" => IrStatementKind.Call,
|
|
"Ret" => IrStatementKind.Return,
|
|
"BinOp" => IrStatementKind.BinaryOp,
|
|
"UnOp" => IrStatementKind.UnaryOp,
|
|
"Load" => IrStatementKind.Load,
|
|
_ => IrStatementKind.Unknown
|
|
};
|
|
|
|
private static (IrOperand? Dest, ImmutableArray<IrOperand> Sources) ExtractOperandsFromB2R2Stmt(object b2r2Stmt)
|
|
{
|
|
try
|
|
{
|
|
var stmtType = b2r2Stmt.GetType().Name;
|
|
|
|
var destProp = b2r2Stmt.GetType().GetProperty("Dst") ??
|
|
b2r2Stmt.GetType().GetProperty("Destination");
|
|
var srcProp = b2r2Stmt.GetType().GetProperty("Src") ??
|
|
b2r2Stmt.GetType().GetProperty("Source");
|
|
var srcsProp = b2r2Stmt.GetType().GetProperty("Srcs") ??
|
|
b2r2Stmt.GetType().GetProperty("Sources");
|
|
|
|
IrOperand? dest = null;
|
|
var sources = new List<IrOperand>();
|
|
|
|
if (destProp != null)
|
|
{
|
|
var destVal = destProp.GetValue(b2r2Stmt);
|
|
if (destVal != null)
|
|
{
|
|
dest = CreateOperandFromB2R2Expr(destVal);
|
|
}
|
|
}
|
|
|
|
if (srcProp != null)
|
|
{
|
|
var srcVal = srcProp.GetValue(b2r2Stmt);
|
|
if (srcVal != null)
|
|
{
|
|
sources.Add(CreateOperandFromB2R2Expr(srcVal));
|
|
}
|
|
}
|
|
|
|
if (srcsProp != null)
|
|
{
|
|
var srcVals = srcsProp.GetValue(b2r2Stmt) as System.Collections.IEnumerable;
|
|
if (srcVals != null)
|
|
{
|
|
foreach (var src in srcVals)
|
|
{
|
|
if (src != null)
|
|
{
|
|
sources.Add(CreateOperandFromB2R2Expr(src));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return (dest, [.. sources]);
|
|
}
|
|
catch
|
|
{
|
|
return (null, ImmutableArray<IrOperand>.Empty);
|
|
}
|
|
}
|
|
}
|