regex - Visual Basic 6 Regular Expression [Hexadecimal] failing to replace properly -
i'm trying replace native x86 asm c++ code can make emulator.
i got this
if ereg(asm, "push ([a-f0-9\s]+)", false) asm = ereg_replace(asm, "push ([a-f0-9\s]+)", _ "regs.d.esp -= 4;" & vbnewline & _ "*(unsigned int *)(regs.d.esp) = $1;", false) end if
functions found on internet.. should work.. on google.
function ereg(stroriginalstring, strpattern, varignorecase) ' function matches pattern, returns true or false ' varignorecase must true (match case insensitive) or false (match case sensitive) dim objregexp: set objregexp = new regexp objregexp .pattern = strpattern .ignorecase = varignorecase .global = true end ereg = objregexp.test(stroriginalstring) set objregexp = nothing end function function ereg_replace(stroriginalstring, strpattern, strreplacement, varignorecase) ' function replaces pattern replacement ' varignorecase must true (match case insensitive) or false (match case sensitive) dim objregexp: set objregexp = new regexp objregexp .pattern = strpattern .ignorecase = varignorecase .global = true end ereg_replace = objregexp.replace(stroriginalstring, strreplacement) set objregexp = nothing end function
i start with.
/* 401187 */ push 466f20
and want end with..
/* 401187 */ regs.d.esp -= 4; *(unsigned int *)(regs.d.esp) = 466f20;
but function above, ran ends with..
/* 401187 */ regs.d.esp -= 4; *(unsigned int *)(regs.d.esp) = 466f20 ;
..err don't worry not being 0x466f20; (that later second pass).
bad regular expression...
instead of
"push ([a-f0-9\s]+)"
i had use
"push ([a-f0-9]+)"
\s
capturing new lines.
Comments
Post a Comment