【问题标题】:Visual Basic 6 Regular Expression [Hexadecimal] failing to replace properlyVisual Basic 6 正则表达式 [十六进制] 无法正确替换
【发布时间】:2011-12-05 19:39:59
【问题描述】:

我正在尝试将原生 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

我在互联网上找到的功能.. 应该可以工作.. 就像在 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

我开始了。

/* 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; (我稍后会通过第二次传递来完成)。

【问题讨论】:

  • “......应该可以工作......就像他们在谷歌上一样。”这是一个糟糕的假设
  • ^ 玩笑,但它看起来像一个值得信赖的好博客来源addedbytes.com/lab/vbscript-regular-expressions 我显然没有正确使用它。可能是C++语法符号与正则表达式冲突
  • 请不要(ab)使用这样的正则表达式。你需要写一个解析器。
  • 我确实为其中的大部分编写了一个解析器..作为 PUSH (EAX|EBX|ECX|ESI|EDI) 等...但是有数字..我不想弄乱我的解析器使其变得更加复杂。顺便说一句 ASM = 1 行汇编代码.. 不是整个块。
  • 几乎自己修复了它..用最新代码更新了帖子..现在的问题是分号总是放在一个新行而不是十六进制值之后。

标签: regex vb6 hex


【解决方案1】:

错误的正则表达式...

而不是

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

我不得不使用

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

\s 正在捕获新行。

【讨论】:

    猜你喜欢
    • 2019-04-25
    • 1970-01-01
    • 2014-03-05
    • 2011-10-03
    • 1970-01-01
    • 2017-11-13
    • 2021-06-04
    • 2017-02-27
    相关资源
    最近更新 更多