-
-
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.
Enable attribute restoration for arm64
- Loading branch information
Sam Byass
committed
Oct 24, 2021
1 parent
0514bcc
commit 80bc423
Showing
17 changed files
with
269 additions
and
47 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
Cpp2IL.Core/Analysis/Actions/ARM64/Arm64LoadAttributeFromAttributeListAction.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,26 @@ | ||
using System.Collections.Generic; | ||
using Cpp2IL.Core.Analysis.Actions.Base; | ||
using Cpp2IL.Core.Analysis.ResultModels; | ||
using Gee.External.Capstone.Arm64; | ||
using LibCpp2IL; | ||
using Mono.Cecil; | ||
|
||
namespace Cpp2IL.Core.Analysis.Actions.ARM64 | ||
{ | ||
public class Arm64LoadAttributeFromAttributeListAction : AbstractAttributeLoadFromListAction<Arm64Instruction> | ||
{ | ||
public Arm64LoadAttributeFromAttributeListAction(MethodAnalysis<Arm64Instruction> context, Arm64Instruction instruction, List<TypeDefinition> attributes) : base(context, instruction) | ||
{ | ||
var ptrSize = LibCpp2IlMain.Binary!.is32Bit ? 4 : 8; | ||
OffsetInList = instruction.MemoryOffset() / ptrSize; | ||
|
||
if(OffsetInList < 0 || OffsetInList >= attributes.Count) | ||
return; | ||
|
||
_attributeType = attributes[(int) OffsetInList]; | ||
|
||
var destReg = Utils.GetRegisterNameNew(instruction.Details.Operands[0].Register.Id); | ||
LocalMade = context.MakeLocal(_attributeType, reg: destReg); | ||
} | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
Cpp2IL.Core/Analysis/Actions/ARM64/Arm64UnmanagedToManagedStringAction.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,52 @@ | ||
using Cpp2IL.Core.Analysis.Actions.Base; | ||
using Cpp2IL.Core.Analysis.ResultModels; | ||
using Gee.External.Capstone.Arm64; | ||
using LibCpp2IL; | ||
using Mono.Cecil.Cil; | ||
|
||
namespace Cpp2IL.Core.Analysis.Actions.ARM64 | ||
{ | ||
public class Arm64UnmanagedToManagedStringAction : BaseAction<Arm64Instruction> | ||
{ | ||
private string? _stringValue; | ||
private LocalDefinition? _localMade; | ||
|
||
public Arm64UnmanagedToManagedStringAction(MethodAnalysis<Arm64Instruction> context, Arm64Instruction instruction) : base(context, instruction) | ||
{ | ||
var stringConstant = context.GetConstantInReg("x0"); | ||
|
||
if (LibCpp2IlMain.Binary!.is32Bit && stringConstant != null) | ||
context.Stack.Pop(); | ||
|
||
_stringValue = (stringConstant?.Value as Il2CppString)?.ContainedString; | ||
|
||
if(_stringValue == null) | ||
return; | ||
|
||
_localMade = context.MakeLocal(Utils.StringReference, reg: "x0", knownInitialValue: _stringValue); | ||
} | ||
|
||
public override Mono.Cecil.Cil.Instruction[] ToILInstructions(MethodAnalysis<Arm64Instruction> context, ILProcessor processor) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public override string? ToPsuedoCode() | ||
{ | ||
return $"System.String {_localMade?.GetPseudocodeRepresentation()} = \"{_stringValue}\""; | ||
} | ||
|
||
public override string ToTextSummary() | ||
{ | ||
if (_localMade == null) | ||
return "[!!] Calls il2cpp_string_new with unknown string literal!"; | ||
|
||
return $"[!] Creates a new System.String with the value \"{_stringValue}\" and stores it in new local {_localMade?.Name}"; | ||
} | ||
|
||
public override bool IsImportant() | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.