Files
Dec2017-Script-Dump/System/Text/RegularExpressions/Disassembler.cs
T
2026-06-04 11:42:34 +02:00

256 lines
5.9 KiB
C#

using System;
namespace System.Text.RegularExpressions
{
// Token: 0x020002CD RID: 717
internal class Disassembler
{
// Token: 0x06001A13 RID: 6675 RVA: 0x0005CC60 File Offset: 0x0005AE60
public static void DisassemblePattern(ushort[] image)
{
Disassembler.DisassembleBlock(image, 0, 0);
}
// Token: 0x06001A14 RID: 6676 RVA: 0x0005CC6C File Offset: 0x0005AE6C
public static void DisassembleBlock(ushort[] image, int pc, int depth)
{
while (pc < image.Length)
{
OpCode opCode;
OpFlags opFlags;
PatternCompiler.DecodeOp(image[pc], out opCode, out opFlags);
Console.Write(Disassembler.FormatAddress(pc) + ": ");
Console.Write(new string(' ', depth * 2));
Console.Write(Disassembler.DisassembleOp(image, pc));
Console.WriteLine();
int num;
switch (opCode)
{
case OpCode.False:
case OpCode.True:
case OpCode.Until:
num = 1;
break;
case OpCode.Position:
case OpCode.Reference:
case OpCode.Character:
case OpCode.Category:
case OpCode.NotCategory:
case OpCode.In:
case OpCode.Open:
case OpCode.Close:
case OpCode.Sub:
case OpCode.Branch:
case OpCode.Jump:
num = 2;
break;
case OpCode.String:
num = (int)(image[pc + 1] + 2);
break;
case OpCode.Range:
case OpCode.Balance:
case OpCode.IfDefined:
case OpCode.Test:
case OpCode.Anchor:
num = 3;
break;
case OpCode.Set:
num = (int)(image[pc + 2] + 3);
break;
case OpCode.BalanceStart:
goto IL_F7;
case OpCode.Repeat:
case OpCode.FastRepeat:
case OpCode.Info:
num = 4;
break;
default:
goto IL_F7;
}
IL_FE:
pc += num;
continue;
IL_F7:
num = 1;
goto IL_FE;
}
}
// Token: 0x06001A15 RID: 6677 RVA: 0x0005CD80 File Offset: 0x0005AF80
public static string DisassembleOp(ushort[] image, int pc)
{
OpCode opCode;
OpFlags opFlags;
PatternCompiler.DecodeOp(image[pc], out opCode, out opFlags);
string text = opCode.ToString();
if (opFlags != OpFlags.None)
{
text = text + "[" + opFlags.ToString("f") + "]";
}
switch (opCode)
{
case OpCode.Position:
text = text + " /" + (Position)image[pc + 1];
break;
case OpCode.String:
text = text + " '" + Disassembler.ReadString(image, pc + 1) + "'";
break;
case OpCode.Reference:
case OpCode.Open:
case OpCode.Close:
text = text + " " + image[pc + 1];
break;
case OpCode.Character:
text = text + " '" + Disassembler.FormatChar((char)image[pc + 1]) + "'";
break;
case OpCode.Category:
case OpCode.NotCategory:
text = text + " /" + (Category)image[pc + 1];
break;
case OpCode.Range:
text = text + " '" + Disassembler.FormatChar((char)image[pc + 1]) + "', ";
text = text + " '" + Disassembler.FormatChar((char)image[pc + 2]) + "'";
break;
case OpCode.Set:
text = text + " " + Disassembler.FormatSet(image, pc + 1);
break;
case OpCode.In:
case OpCode.Sub:
case OpCode.Branch:
case OpCode.Jump:
text = text + " :" + Disassembler.FormatAddress(pc + (int)image[pc + 1]);
break;
case OpCode.Balance:
{
string text2 = text;
text = string.Concat(new object[]
{
text2,
" ",
image[pc + 1],
" ",
image[pc + 2]
});
break;
}
case OpCode.IfDefined:
case OpCode.Anchor:
text = text + " :" + Disassembler.FormatAddress(pc + (int)image[pc + 1]);
text = text + " " + image[pc + 2];
break;
case OpCode.Test:
text = text + " :" + Disassembler.FormatAddress(pc + (int)image[pc + 1]);
text = text + ", :" + Disassembler.FormatAddress(pc + (int)image[pc + 2]);
break;
case OpCode.Repeat:
case OpCode.FastRepeat:
{
text = text + " :" + Disassembler.FormatAddress(pc + (int)image[pc + 1]);
string text2 = text;
text = string.Concat(new object[]
{
text2,
" (",
image[pc + 2],
", "
});
if (image[pc + 3] == 65535)
{
text += "Inf";
}
else
{
text += image[pc + 3];
}
text += ")";
break;
}
case OpCode.Info:
{
text = text + " " + image[pc + 1];
string text2 = text;
text = string.Concat(new object[]
{
text2,
" (",
image[pc + 2],
", ",
image[pc + 3],
")"
});
break;
}
}
return text;
}
// Token: 0x06001A16 RID: 6678 RVA: 0x0005D0DC File Offset: 0x0005B2DC
private static string ReadString(ushort[] image, int pc)
{
int num = (int)image[pc];
char[] array = new char[num];
for (int i = 0; i < num; i++)
{
array[i] = (char)image[pc + i + 1];
}
return new string(array);
}
// Token: 0x06001A17 RID: 6679 RVA: 0x0005D118 File Offset: 0x0005B318
private static string FormatAddress(int pc)
{
return pc.ToString("x4");
}
// Token: 0x06001A18 RID: 6680 RVA: 0x0005D128 File Offset: 0x0005B328
private static string FormatSet(ushort[] image, int pc)
{
int num = (int)image[pc++];
int num2 = ((int)image[pc++] << 4) - 1;
string text = "[";
bool flag = false;
char c = '\0';
for (int i = 0; i <= num2; i++)
{
bool flag2 = ((int)image[pc + (i >> 4)] & (1 << (i & 15))) != 0;
if (flag2 & !flag)
{
c = (char)(num + i);
flag = true;
}
else if (flag & (!flag2 || i == num2))
{
char c2 = (char)(num + i - 1);
text += Disassembler.FormatChar(c);
if (c2 != c)
{
text = text + "-" + Disassembler.FormatChar(c2);
}
flag = false;
}
}
return text + "]";
}
// Token: 0x06001A19 RID: 6681 RVA: 0x0005D1FC File Offset: 0x0005B3FC
private static string FormatChar(char c)
{
if (c == '-' || c == ']')
{
return "\\" + c;
}
if (char.IsLetterOrDigit(c) || char.IsSymbol(c))
{
return c.ToString();
}
if (char.IsControl(c))
{
return "^" + ('@' + c);
}
string text = "\\u";
int num = (int)c;
return text + num.ToString("x4");
}
}
}