regex - Regular expression for extracting a series of hex numbers from a file -
i examining object dump of file , want figure out possible addresses.
the approach using involves using perl , regex extract words
the format of object file this
00000000000044444 <function> 44448: 48 ca add .... 4444c: 48 ca 55 call .... 44450: 48 ca 8d 55 jmp.. i trying extract 48 ca 48 ca 55 48 ca 8d 55
currently, thought regex /(\s[0-9a-f][0-9a-f]\s)/g however, extracts every other, i.e48, 8d, 55, parse 48 , cant parse ca because previous space character has been consumed (at least understanding)
/(\s[0-9a-f][0-9a-f]\s)|([0-9a-f][0-9a-f]\s)/g parses things shouldnt add instruction dd
any how can extract these pairs of numbers deliminated space?
edit: updated more realistic format of file.
thank you
instead of \s, want word boundary \b.
while (<data>) { @nums = m/\b([[:xdigit:]]{2})\b/g; print "@nums\n"; } __data__ 00000000000044444 <function> 44448: 48 ca 8d 55 4444c: 48 ca 8d 55 44450: 48 ca 8d 55 update
given, made data more complicated instructions after hex codes, i'd lean toward making regex more restrictive so;
while (<data>) { if (/^\s+\w+:((?:\s[[:xdigit:]]{2})+)\b/) { @nums = split ' ', $1; print "@nums\n"; } } __data__ 00000000000044444 <function> 44448: 48 ca add .... 4444c: 48 ca 55 call .... 44450: 48 ca 8d 55 jmp.. outputs:
48 ca 48 ca 55 48 ca 8d 55
Comments
Post a Comment