Visual Basic 6 正则表达式 [十六进制] 无法正确替换
我正在尝试将本机 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误的正则表达式...
而不是
"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.