将 Autoit 正则表达式转换为 C#

发布于 2024-11-18 07:11:34 字数 4262 浏览 2 评论 0原文

我无法解决这个问题,我得到了这个搜索表达式

.*?(8986(.{8})8A4F03)

,它在 autoit 中运行得非常快,并给了我 1 个结果,但如果我在 c# 中尝试它,它似乎挂起。我也尝试过,

(8986(.{8})8A4F03)

它在 autoit 和 c# 中都运行得非常快,但给了我 2 个结果,但我只想要第一个结果。我已经阅读了 autoit 和 c# 的“备忘单”,但我就是不明白。

部分自动代码

Global $SearchExression = _
    ".*?(8B0D(.{8})898D40F1FFFF6A01)" & _ ;Base_Address
    ".*?(8986(.{8})8A4F03)" & _ ;LVL_Offset
    ".*?(898E(.{8})8B5714)" & _ ;Culti_Offset
    ".*?(8996(.{8})8B4718)" & _ ;EXP_Offset
    ".*?(8986(.{8})8B4F04)" & _ ;Spirit_offset
    ".*?(898E(.{8})8B570C)" & _ ;HP_OffSet
    ".*?(8996(.{8})8B471C)" & _ ;MP_OffSet
    ".*?(8986(.{8})8B4F08)" & _ ;CHI_OffSet
    ".*?(898E(.{8})8B5710)" & _ ;MaxHP_OffSet
    ".*?(8996(.{8})8B4720)" & _ ;MaxMP_OffSet
    ".*?(8986(.{8})8A4702)" & _ ;MaxCHI_Offset
    ".*?(8B108996(.{8})8B4004)" & _ ;gold_Offset
    ".*?(6A0A8986(.{8}))" & _ ;state_Offset
    ".*?(8986(.{8})8B40048BC8)" & _ ;castid_Offset
    ".*?(A1(.{8})578B482081C1EC)" & _ ;BaseCall_Offset
    ".*?(568BF18B86(.{8})85C0)" & _ ;target_Offset
    ".*?(8B8E(.{8})3BCB740655)" & _ ;pet_Offset
    ".*?(8B8E(.{8})8B47503BC8)" & _ ;str_Offset
    ".*?(8B96(.{8})8B47543BD0)" & _ ;dex_Offset
    ".*?(8B86(.{8})8B4F5C3BC1)" & _ ;vit_Offset
    ".*?(8B8E(.{8})8B47603BC8)" & _ ;mag_Offset
    ".*?(8B96(.{8})8B47643BD0)" & _ ;reputation_Offset
    ".*?(EB5D8B8E(.{8})B801)" & _ ;class_Offset
    ".*?(8B491C33C08B91(.{8})85D2)" & _ ;jump_Offset
    ".*?(32C0C38B89(.{8})568BB0)" & _ ;charid_Offset
    ".*?(8B83(.{8})8D4C243C)" & _ ;name_Offset
    "";".*?((.{8}))" & _ ;
 Global $NameArray[26] = [ _
    "Base_Address", _
    "LVL_Offset", _
    "Culti_Offset", _
    "EXP_Offset", _
    "Spirit_Offset", _
    "HP_Offset", _
    "MP_Offset", _
    "CHI_Offset", _
    "MaxHP_Offset", _
    "MaxMP_OffSet", _
    "MaxCHI_Offset", _
    "Gold_Offset", _
    "State_Offset", _
    "CastID_Offset", _
    "BaseCall_Address", _
    "TargetID_Offset", _
    "Pet_Offset", _
    "STR_Offset", _
    "DEX_Offset", _
    "VIT_Offset", _
    "MAG_Offset", _
    "Reputation_Offset", _
    "Class_Offset", _
    "Jump_Offset", _
    "CharID_Offset", _
    "Name_Offset"]
If FileExists($File) Then
    $FileHnd = FileOpen($File, 16)
    Local $Data = FileRead($FileHnd, FileGetSize($File))
    FileClose($FileHnd)
Else
    Local $Data = ""
EndIf
If $Data <> "" Then
    Local $x = 0
    Local $check = StringRegExp($Data, $SearchExression, 3)
    If IsArray($check) Then
        Global $info[UBound($check) / 2][3]
        For $i = 1 To (UBound($check) - 1) Step 2
            MsgBox(0,"",$check[$i])
            $info[$x][0] = $NameArray[$x]
            $info[$x][1] = _RemoveZero(Reverse($check[$i]))
            $info[$x][2] = Dec(Reverse($check[$i]))
            $x += 1
        Next

到目前为止,

if (File.Exists(file) == true)
        {
            FileStream inputFile = new FileStream(file, FileMode.Open , FileAccess.Read,FileShare.ReadWrite);
            byte[] byteBuffer = new byte[inputFile.Length];
            inputFile.Read(byteBuffer, 0, (int) inputFile.Length);
            inputFile.Dispose();
            StringBuilder client = new StringBuilder();
            for (int i = 0; i < byteBuffer.Length; i++)
            {
                client.Append(byteBuffer[i].ToString("X2"));
            }
            // Clipboard.SetText(client.ToString()); //get string to paste into regexbuddy

            Regex rx = new Regex(@".*?(8986(.{8})8A4F03)"); //works perfect in autoit but hangs here
            //Regex rx = new Regex(@"(8986(.{8})8A4F03)"); // too many groups + too many matches
            //Regex rx = new Regex(@"8986(.{8})8A4F03"); //one group but too many matches

            foreach (Match mx in rx.Matches(client.ToString()))
            {
                Console.WriteLine(mx);
                //Console.WriteLine(mx.Groups[1]);
            }
        }

C# 代码我没有制作原始表达式,我不声称知道它们是如何工作的

字符串的第一部分是

4D5A90000300000004000000FFFF0000B8000000000000004000000

我想要的结果是

6C040000

I cant work this out, I have been given this search expression

.*?(8986(.{8})8A4F03)

which works really quick in autoit and gives me 1 result but if I try it in c# it seems to hang. I have also tried

(8986(.{8})8A4F03)

which works really quick in both autoit and c# but gives me 2 results but I only want the first result. I have read "cheat sheets" for autoit and c# but I just don't get it.

Part of the autoit code

Global $SearchExression = _
    ".*?(8B0D(.{8})898D40F1FFFF6A01)" & _ ;Base_Address
    ".*?(8986(.{8})8A4F03)" & _ ;LVL_Offset
    ".*?(898E(.{8})8B5714)" & _ ;Culti_Offset
    ".*?(8996(.{8})8B4718)" & _ ;EXP_Offset
    ".*?(8986(.{8})8B4F04)" & _ ;Spirit_offset
    ".*?(898E(.{8})8B570C)" & _ ;HP_OffSet
    ".*?(8996(.{8})8B471C)" & _ ;MP_OffSet
    ".*?(8986(.{8})8B4F08)" & _ ;CHI_OffSet
    ".*?(898E(.{8})8B5710)" & _ ;MaxHP_OffSet
    ".*?(8996(.{8})8B4720)" & _ ;MaxMP_OffSet
    ".*?(8986(.{8})8A4702)" & _ ;MaxCHI_Offset
    ".*?(8B108996(.{8})8B4004)" & _ ;gold_Offset
    ".*?(6A0A8986(.{8}))" & _ ;state_Offset
    ".*?(8986(.{8})8B40048BC8)" & _ ;castid_Offset
    ".*?(A1(.{8})578B482081C1EC)" & _ ;BaseCall_Offset
    ".*?(568BF18B86(.{8})85C0)" & _ ;target_Offset
    ".*?(8B8E(.{8})3BCB740655)" & _ ;pet_Offset
    ".*?(8B8E(.{8})8B47503BC8)" & _ ;str_Offset
    ".*?(8B96(.{8})8B47543BD0)" & _ ;dex_Offset
    ".*?(8B86(.{8})8B4F5C3BC1)" & _ ;vit_Offset
    ".*?(8B8E(.{8})8B47603BC8)" & _ ;mag_Offset
    ".*?(8B96(.{8})8B47643BD0)" & _ ;reputation_Offset
    ".*?(EB5D8B8E(.{8})B801)" & _ ;class_Offset
    ".*?(8B491C33C08B91(.{8})85D2)" & _ ;jump_Offset
    ".*?(32C0C38B89(.{8})568BB0)" & _ ;charid_Offset
    ".*?(8B83(.{8})8D4C243C)" & _ ;name_Offset
    "";".*?((.{8}))" & _ ;
 Global $NameArray[26] = [ _
    "Base_Address", _
    "LVL_Offset", _
    "Culti_Offset", _
    "EXP_Offset", _
    "Spirit_Offset", _
    "HP_Offset", _
    "MP_Offset", _
    "CHI_Offset", _
    "MaxHP_Offset", _
    "MaxMP_OffSet", _
    "MaxCHI_Offset", _
    "Gold_Offset", _
    "State_Offset", _
    "CastID_Offset", _
    "BaseCall_Address", _
    "TargetID_Offset", _
    "Pet_Offset", _
    "STR_Offset", _
    "DEX_Offset", _
    "VIT_Offset", _
    "MAG_Offset", _
    "Reputation_Offset", _
    "Class_Offset", _
    "Jump_Offset", _
    "CharID_Offset", _
    "Name_Offset"]
If FileExists($File) Then
    $FileHnd = FileOpen($File, 16)
    Local $Data = FileRead($FileHnd, FileGetSize($File))
    FileClose($FileHnd)
Else
    Local $Data = ""
EndIf
If $Data <> "" Then
    Local $x = 0
    Local $check = StringRegExp($Data, $SearchExression, 3)
    If IsArray($check) Then
        Global $info[UBound($check) / 2][3]
        For $i = 1 To (UBound($check) - 1) Step 2
            MsgBox(0,"",$check[$i])
            $info[$x][0] = $NameArray[$x]
            $info[$x][1] = _RemoveZero(Reverse($check[$i]))
            $info[$x][2] = Dec(Reverse($check[$i]))
            $x += 1
        Next

c# code so far

if (File.Exists(file) == true)
        {
            FileStream inputFile = new FileStream(file, FileMode.Open , FileAccess.Read,FileShare.ReadWrite);
            byte[] byteBuffer = new byte[inputFile.Length];
            inputFile.Read(byteBuffer, 0, (int) inputFile.Length);
            inputFile.Dispose();
            StringBuilder client = new StringBuilder();
            for (int i = 0; i < byteBuffer.Length; i++)
            {
                client.Append(byteBuffer[i].ToString("X2"));
            }
            // Clipboard.SetText(client.ToString()); //get string to paste into regexbuddy

            Regex rx = new Regex(@".*?(8986(.{8})8A4F03)"); //works perfect in autoit but hangs here
            //Regex rx = new Regex(@"(8986(.{8})8A4F03)"); // too many groups + too many matches
            //Regex rx = new Regex(@"8986(.{8})8A4F03"); //one group but too many matches

            foreach (Match mx in rx.Matches(client.ToString()))
            {
                Console.WriteLine(mx);
                //Console.WriteLine(mx.Groups[1]);
            }
        }

I didnt make the original expressions, i dont claim to know how they work

First part of the string is

4D5A90000300000004000000FFFF0000B8000000000000004000000

Result I want is

6C040000

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芯好空 2024-11-25 07:11:34

试试这个 C# 片段:

string resultString = null;
resultString = Regex.Match(text, "(?<=8986).{8}(?=8A4F03)").Value;

Try this C# snippet:

string resultString = null;
resultString = Regex.Match(text, "(?<=8986).{8}(?=8A4F03)").Value;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文