-
-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathMetadataProcessor.cs
More file actions
46 lines (40 loc) · 1.92 KB
/
MetadataProcessor.cs
File metadata and controls
46 lines (40 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Cpp2IL.Core.ISIL;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.Core.Utils;
namespace Cpp2IL.Core.Graphs.Processors;
internal class MetadataProcessor : IBlockProcessor
{
public void Process(MethodAnalysisContext methodAnalysisContext, Block block)
{
foreach (var instruction in block.isilInstructions)
{
// TODO: Check if it shows up in any other
if (instruction.OpCode != InstructionSetIndependentOpCode.Move)
{
continue;
}
if (instruction.Operands[0].Type != InstructionSetIndependentOperand.OperandType.Register || instruction.Operands[1].Type != InstructionSetIndependentOperand.OperandType.Memory)
{
continue;
}
var memoryOp = (IsilMemoryOperand)instruction.Operands[1].Data;
if (memoryOp.Base == null && memoryOp.Index == null && memoryOp.Scale == 0)
{
var val = methodAnalysisContext.AppContext.LibCpp2IlContext.GetLiteralByAddress((ulong)memoryOp.Addend);
if (val == null)
{
// Try instead check if its type metadata usage
var metadataUsage = methodAnalysisContext.AppContext.LibCpp2IlContext.GetTypeGlobalByAddress((ulong)memoryOp.Addend);
if (metadataUsage != null && methodAnalysisContext.DeclaringType is not null)
{
var typeAnalysisContext = metadataUsage.ToContext(methodAnalysisContext.DeclaringType!.DeclaringAssembly);
if (typeAnalysisContext != null)
instruction.Operands[1] = InstructionSetIndependentOperand.MakeTypeMetadataUsage(typeAnalysisContext);
}
continue;
}
instruction.Operands[1] = InstructionSetIndependentOperand.MakeImmediate(val);
}
}
}
}