-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathInterpreter.cs
More file actions
54 lines (51 loc) · 1.9 KB
/
Interpreter.cs
File metadata and controls
54 lines (51 loc) · 1.9 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
47
48
49
50
51
52
53
54
using System;
using System.Diagnostics.Contracts;
using ReClassNET.Extensions;
using ReClassNET.Memory;
namespace ReClassNET.AddressParser
{
public class Interpreter : IExecutor
{
public IntPtr Execute(IExpression expression, IProcessReader processReader)
{
Contract.Requires(expression != null);
Contract.Requires(processReader != null);
switch (expression)
{
case ConstantExpression constantExpression:
return IntPtrExtension.From(constantExpression.Value);
case NegateExpression negateExpression:
return Execute(negateExpression.Expression, processReader).Negate();
case ModuleExpression moduleExpression:
{
var module = processReader.GetModuleByName(moduleExpression.Name);
if (module != null)
{
return module.Start;
}
return IntPtr.Zero;
}
case AddExpression addExpression:
return Execute(addExpression.Lhs, processReader).Add(Execute(addExpression.Rhs, processReader));
case SubtractExpression subtractExpression:
return Execute(subtractExpression.Lhs, processReader).Sub(Execute(subtractExpression.Rhs, processReader));
case MultiplyExpression multiplyExpression:
return Execute(multiplyExpression.Lhs, processReader).Mul(Execute(multiplyExpression.Rhs, processReader));
case DivideExpression divideExpression:
return Execute(divideExpression.Lhs, processReader).Div(Execute(divideExpression.Rhs, processReader));
case ReadMemoryExpression readMemoryExpression:
var readFromAddress = Execute(readMemoryExpression.Expression, processReader);
if (readMemoryExpression.ByteCount == 4)
{
return IntPtrExtension.From(processReader.ReadRemoteInt32(readFromAddress));
}
else
{
return IntPtrExtension.From(processReader.ReadRemoteInt64(readFromAddress));
}
default:
throw new ArgumentException($"Unsupported operation '{expression.GetType().FullName}'.");
}
}
}
}