例如,函数名称为“ Player_GetStats_m29275”,此处的“ m292755”为
随机字符。因此,我只想通过“ Player_GetStats”搜索函数的名称,以便为我提供函数的地址。我可以使用find_text搜索该函数,但是即使提到了该段,它的速度也很慢并且要花费很多时间。谢谢
#1 楼
据我所知,IDA没有提供模式并返回地址的function_name_to_address()
。您可以遍历所有功能,并检查它们的名称是否与所需的名称匹配。它应该不会花太长时间。 from idautils import *
from idaapi import *
from idc import *
ea = BeginEA()
for funcAddr in Functions(SegStart(ea), SegEnd(ea)):
funcName = GetFunctionName(funcAddr)
# Check if the function name starts with "Player_GetStats"
if funcName.startswith("Player_GetStats"):
print "Function %s is at 0x%x" % (funcName, funcAddr)
或者,您可以使用正则表达式匹配所需的名称:
import re
funcName = "Player_GetStats_m29275"
re.compile("^Player_GetStats_\w\d{5}$")
if pattern.match(funcName):
"%s match the pattern" % funcName
解释:
^
用于“开头为” \w
匹配一个单词字符(在这种情况下为“ m”)\d
匹配一个数字{5}
检查前一个表达式(\d
)是否重复5次$
用于“行尾”