Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用regex从objdump提取地址和函数调用_Python_Regex - Fatal编程技术网

Python 使用regex从objdump提取地址和函数调用

Python 使用regex从objdump提取地址和函数调用,python,regex,Python,Regex,我正试图用正则表达式来表达我的想法,但我仍然有问题。我有这个输出(来自objdump-D): 804869f:e8 cc fe ff ff ff呼叫8048570 8048713:e8 38 fe ff ff呼叫8048550 8048750:e8 0b fe ff ff呼叫8048560 我想得到调用发生的地址(第一列)和函数名(即:socket、bind、listen) 我试过这个: match = re.match(r' (.*): (.*) <(.*)@plt>', lin

我正试图用正则表达式来表达我的想法,但我仍然有问题。我有这个输出(来自
objdump-D
):

804869f:e8 cc fe ff ff ff呼叫8048570
8048713:e8 38 fe ff ff呼叫8048550
8048750:e8 0b fe ff ff呼叫8048560
我想得到调用发生的地址(第一列)和函数名(即:socket、bind、listen)

我试过这个:

match = re.match(r' (.*): (.*) <(.*)@plt>', line)
print match.group(1)
print match.group(3)
match=re.match(r'(.*):(.*),第行)
打印匹配组(1)
打印匹配。组(3)

据我所知,我认为这是可行的。第一组应该是第一个空格字符和冒号之间的字符串,第三组应该是执行非贪婪匹配的
之间的字符串

*
会吃掉所有字符,如果事先知道了事情,则要具体

更好的模式可以如下所示:

st=re.match(r'\s+([0-9A-Fa-f]+):'    # Address starting with one or more space
            r'\s+.+?'                # Skip characters (non-greedy using ?)
            r'([0-9A-Fa-f]+)\s+'     # Address followed by space
            r'<(\S+)@plt>',          # function name, anything except space
            line)     

+1就像一个符咒,我仍然不明白为什么我的不起作用。@Juicy,请参见
*。?
,但正如所说的,如果事先知道情况,则应相应地形成模式,在您的情况下,地址是固定的,只包含数字或字母
a-f
,等等
st=re.match(r'\s+([0-9A-Fa-f]+):'    # Address starting with one or more space
            r'\s+.+?'                # Skip characters (non-greedy using ?)
            r'([0-9A-Fa-f]+)\s+'     # Address followed by space
            r'<(\S+)@plt>',          # function name, anything except space
            line)     
if st: # Use st or some different variable other then 'match' itself
   print st.group(1)
   print st.group(2)
   print st.group(3)