开发者

Visual Basic 6 Regular Expression [Hexadecimal] failing to replace properly

开发者 https://www.devze.com 2023-04-12 04:33 出处:网络
I\'m trying to replacenative x86 asm to C++ code so I can make a emulator. I got this If ereg(ASM, \"PUSH ([A-F0-9\\s]+)\", False) Then

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 = objRegEx开发者_开发问答p.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).


bad regular expression...

instead of

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

I had to use

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

\s was capturing new lines.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号