开发者

parsing assembly code in perl

0000000000033a1b subq $0x28,%rsp

开发者_如何学C

I am having trouble extracting 0x28 from the above line. I am able to extract subq from a big list of assembly code but i only want 0x28 since this gives me the stack size. I was thinking of using substr() function buy there are variations to it, another one could look like this:

0000000000033a1c subq $0x000000b8,%rsp

in this case i only want 0x000000b8.

I am using perl.

Thank you.


Without code, my guess is that you're not escaping the dollar sign. Thus you are asking for it to match the end of the line, and then '0x28'.

In any regex, /\$0x(\p{XDigit}+)/ should capture '28' out of that string.


If your input of the following format always:

instruction_address operand $stack_size,register

you can do:

$a = '0000000000033a1b subq $0x28,%rsp';
$a =~s/^.*?\$(.*?),.*$/\1/;
print $a; # prints 0x28
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜