-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Arm64 field writes, post-processors.
- Loading branch information
Sam Byass
committed
Sep 17, 2021
1 parent
a4fe785
commit dc046b9
Showing
13 changed files
with
210 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Cpp2IL.Core/Analysis/Actions/ARM64/Arm64ImmediateToFieldAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Cpp2IL.Core.Analysis.Actions.Base; | ||
using Cpp2IL.Core.Analysis.ResultModels; | ||
using Gee.External.Capstone.Arm64; | ||
using Mono.Cecil.Cil; | ||
|
||
namespace Cpp2IL.Core.Analysis.Actions.ARM64 | ||
{ | ||
public class Arm64ImmediateToFieldAction : AbstractFieldWriteAction<Arm64Instruction> | ||
{ | ||
private long _immValue; | ||
|
||
public Arm64ImmediateToFieldAction(MethodAnalysis<Arm64Instruction> context, Arm64Instruction instruction) : base(context, instruction) | ||
{ | ||
var memReg = Utils.GetRegisterNameNew(instruction.MemoryBase()!.Id); | ||
InstanceBeingSetOn = context.GetLocalInReg(memReg); | ||
|
||
_immValue = instruction.Details.Operands[0].Immediate; | ||
|
||
if(InstanceBeingSetOn?.Type == null) | ||
return; | ||
|
||
RegisterUsedLocal(InstanceBeingSetOn); | ||
|
||
FieldWritten = FieldUtils.GetFieldBeingAccessed(InstanceBeingSetOn.Type, (ulong)instruction.MemoryOffset(), false); | ||
} | ||
|
||
protected override string? GetValueSummary() => _immValue.ToString(); | ||
|
||
protected override string? GetValuePseudocode() => _immValue.ToString(); | ||
|
||
protected override Instruction[] GetIlToLoadValue(MethodAnalysis<Arm64Instruction> context, ILProcessor processor) => new[] | ||
{ | ||
processor.Create(OpCodes.Ldc_I4, (int) _immValue), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Cpp2IL.Core/Analysis/Actions/ARM64/Arm64OrZeroAndImmAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using Cpp2IL.Core.Analysis.Actions.Base; | ||
using Cpp2IL.Core.Analysis.ResultModels; | ||
using Gee.External.Capstone.Arm64; | ||
using Mono.Cecil.Cil; | ||
|
||
namespace Cpp2IL.Core.Analysis.Actions.ARM64 | ||
{ | ||
public class Arm64OrZeroAndImmAction : BaseAction<Arm64Instruction> | ||
{ | ||
private readonly string _destReg; | ||
private readonly long _immValue; | ||
private readonly LocalDefinition _localMade; | ||
|
||
public Arm64OrZeroAndImmAction(MethodAnalysis<Arm64Instruction> context, Arm64Instruction instruction) : base(context, instruction) | ||
{ | ||
_destReg = Utils.GetRegisterNameNew(instruction.Details.Operands[0].Register.Id); | ||
_immValue = instruction.Details.Operands[2].Immediate; | ||
|
||
_localMade = context.MakeLocal(Utils.Int64Reference, reg: _destReg, knownInitialValue: _immValue); | ||
RegisterDefinedLocalWithoutSideEffects(_localMade); | ||
} | ||
|
||
public override Instruction[] ToILInstructions(MethodAnalysis<Arm64Instruction> context, ILProcessor processor) | ||
{ | ||
if (_localMade.Variable == null) | ||
return Array.Empty<Instruction>(); | ||
|
||
return new[] | ||
{ | ||
processor.Create(OpCodes.Ldc_I4, (int) _immValue), | ||
processor.Create(OpCodes.Stloc, _localMade.Variable) | ||
}; | ||
} | ||
|
||
public override string? ToPsuedoCode() | ||
{ | ||
return $"{_localMade.Type} {_localMade.Name} = {_immValue}"; | ||
} | ||
|
||
public override string ToTextSummary() | ||
{ | ||
return $"Creates new local {_localMade} in {_destReg} by ORing 0 with {_immValue}"; | ||
} | ||
|
||
public override bool IsImportant() => true; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Cpp2IL.Core/Analysis/Actions/ARM64/Arm64RegisterToFieldAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Cpp2IL.Core.Analysis.Actions.Base; | ||
using Cpp2IL.Core.Analysis.ResultModels; | ||
using Gee.External.Capstone.Arm64; | ||
using Mono.Cecil.Cil; | ||
|
||
namespace Cpp2IL.Core.Analysis.Actions.ARM64 | ||
{ | ||
public class Arm64RegisterToFieldAction : AbstractFieldWriteAction<Arm64Instruction> | ||
{ | ||
private IAnalysedOperand? _sourceOperand; | ||
|
||
public Arm64RegisterToFieldAction(MethodAnalysis<Arm64Instruction> context, Arm64Instruction instruction) : base(context, instruction) | ||
{ | ||
var memReg = Utils.GetRegisterNameNew(instruction.MemoryBase()!.Id); | ||
InstanceBeingSetOn = context.GetLocalInReg(memReg); | ||
|
||
var sourceReg = Utils.GetRegisterNameNew(instruction.Details.Operands[0].Register.Id); | ||
_sourceOperand = context.GetOperandInRegister(sourceReg); | ||
|
||
if(InstanceBeingSetOn?.Type == null) | ||
return; | ||
|
||
RegisterUsedLocal(InstanceBeingSetOn); | ||
|
||
if(_sourceOperand is LocalDefinition l) | ||
RegisterUsedLocal(l); | ||
|
||
FieldWritten = FieldUtils.GetFieldBeingAccessed(InstanceBeingSetOn.Type, (ulong)instruction.MemoryOffset(), sourceReg[0] == 'v'); | ||
} | ||
|
||
protected override string? GetValueSummary() => _sourceOperand?.ToString(); | ||
|
||
protected override string? GetValuePseudocode() => _sourceOperand?.GetPseudocodeRepresentation(); | ||
|
||
protected override Instruction[] GetIlToLoadValue(MethodAnalysis<Arm64Instruction> context, ILProcessor processor) => _sourceOperand?.GetILToLoad(context, processor) ?? Array.Empty<Instruction>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
using Cpp2IL.Core.Analysis.ResultModels; | ||
using Mono.Cecil; | ||
|
||
namespace Cpp2IL.Core.Analysis.PostProcessActions | ||
{ | ||
public abstract class PostProcessor<T> | ||
{ | ||
public abstract void PostProcess(MethodAnalysis<T> analysis, MethodDefinition definition); | ||
public abstract void PostProcess(MethodAnalysis<T> analysis); | ||
} | ||
} |