Visual Basic 6 正则表达式 [十六进制] 无法正确替换

发布于 2024-12-09 12:17:12 字数 1673 浏览 0 评论 0原文

我正在尝试将本机 x86 asm 替换为 C++ 代码,这样我就可以制作一个模拟器。

这个

If ereg(ASM, "PUSH ([A-F0-9\s]+)", False) Then
    ASM = ereg_replace(ASM, "PUSH ([A-F0-9\s]+)", _
    "regs.d.esp -= 4;" & vbNewLine & _
    "*(unsigned int *)(regs.d.esp) = $1;", False)
End If

我在互联网上找到了

Function ereg(strOriginalString, strPattern, varIgnoreCase)
    ' Function matches pattern, returns true or false
    ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
    Dim objRegExp: Set objRegExp = New RegExp
    With objRegExp
        .Pattern = strPattern
        .IgnoreCase = varIgnoreCase
        .Global = True
    End With
    ereg = objRegExp.test(strOriginalString)
    Set objRegExp = Nothing
End Function

Function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
    ' Function replaces pattern with replacement
    ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
    Dim objRegExp: Set objRegExp = New RegExp
    With objRegExp
        .Pattern = strPattern
        .IgnoreCase = varIgnoreCase
        .Global = True
    End With
    ereg_replace = objRegExp.Replace(strOriginalString, strReplacement)
    Set objRegExp = Nothing
End Function

功能..应该可以工作..就像它们在谷歌上一样。我开始。

/* 401187 */
PUSH 466F20

并希望最终得到..

/* 401187 */
regs.d.esp -= 4;
*(unsigned int *)(regs.d.esp) = 466F20;

但是上面的函数,运行最终得到

/* 401187 */
regs.d.esp -= 4;
*(unsigned int *)(regs.d.esp) = 466F20
;

....Err,不要担心它不是0x466F20; (稍后我将进行第二遍)。

I'm trying to replace native x86 asm to C++ code so I can make a emulator.

I got this

If ereg(ASM, "PUSH ([A-F0-9\s]+)", False) Then
    ASM = ereg_replace(ASM, "PUSH ([A-F0-9\s]+)", _
    "regs.d.esp -= 4;" & vbNewLine & _
    "*(unsigned int *)(regs.d.esp) = $1;", False)
End If

Functions I found on the internet.. should work.. as they are on google.

Function ereg(strOriginalString, strPattern, varIgnoreCase)
    ' Function matches pattern, returns true or false
    ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
    Dim objRegExp: Set objRegExp = New RegExp
    With objRegExp
        .Pattern = strPattern
        .IgnoreCase = varIgnoreCase
        .Global = True
    End With
    ereg = objRegExp.test(strOriginalString)
    Set objRegExp = Nothing
End Function

Function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
    ' Function replaces pattern with replacement
    ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
    Dim objRegExp: Set objRegExp = New RegExp
    With objRegExp
        .Pattern = strPattern
        .IgnoreCase = varIgnoreCase
        .Global = True
    End With
    ereg_replace = objRegExp.Replace(strOriginalString, strReplacement)
    Set objRegExp = Nothing
End Function

I start up with.

/* 401187 */
PUSH 466F20

and want to end up with..

/* 401187 */
regs.d.esp -= 4;
*(unsigned int *)(regs.d.esp) = 466F20;

But function above, ran ends up with..

/* 401187 */
regs.d.esp -= 4;
*(unsigned int *)(regs.d.esp) = 466F20
;

..Err don't worry about it not being 0x466F20; (that I will do later with a second pass).

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

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

发布评论

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

评论(1

九公里浅绿 2024-12-16 12:17:12

错误的正则表达式...

而不是

"PUSH ([A-F0-9\s]+)"

我必须使用

"PUSH ([A-F0-9]+)"

\s 正在捕获新行。

bad regular expression...

instead of

"PUSH ([A-F0-9\s]+)"

I had to use

"PUSH ([A-F0-9]+)"

\s was capturing new lines.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文