代码拉取完成,页面将自动刷新
import os
import sys
import subprocess
import re
from utils import rpm_detect
from readelf import Read_ELF
def get_rpm_name(rpm):
rpm_name_list = rpm.split('/')[-1]
rpm_sub_name_list = rpm_name_list.split('-')
name = ''
for idx, rpm_sub_name in enumerate(rpm_sub_name_list):
if len(re.findall(r'^[0-9]\.', rpm_sub_name)) > 0:
break
if idx > 0:
name = name + '-' + rpm_sub_name
else:
name = rpm_sub_name
return name
def rpm_to_source_or_bin(path):
source_dir = ''
type = ''
name = ''
if os.path.isfile(path):
file_name = path.split('/')[-1]
if file_name.endswith('.src.rpm') > 0:
stdout = subprocess.run('rpm -ivh %s'%path, shell=True, check=True, stdout=subprocess.PIPE).stdout.decode()
name = get_rpm_name(file_name)
rpm_file_list = subprocess.run('rpm -qpl %s'%path, shell=True, check=True, stdout=subprocess.PIPE).stdout.decode().split('\n')
spec_name = ''
tar_name = ''
for rpm_file in rpm_file_list:
spec_name_tmp = re.findall(r'[0-9a-z\.\-]+\.spec$', rpm_file, re.I)
tar_name_tmp = re.findall(r'[0-9a-z\.\-]+\.tar.gz$', rpm_file, re.I)
if len(spec_name_tmp) > 0:
spec_name = spec_name_tmp[0]
if len(tar_name_tmp) > 0:
tar_name = tar_name_tmp[0]
if spec_name != '' and tar_name != '':
break
print(spec_name)
rpm_path = '/root/rpmbuild/SOURCES/%s'%tar_name
rpm_detect('tar', 'tar')
stdout = subprocess.run('tar -xzvf %s'%rpm_path, shell=True, check=True, stdout=subprocess.PIPE).stdout.decode()
tar_name = re.findall(r'([a-z0-9\-\.]+)\.tar.gz$', tar_name, re.I)[0]
source_dir = os.path.join(os.getcwd(), tar_name)
type = 'src.rpm'
elif file_name.endswith('.rpm'):
stdout = subprocess.run('rpm2cpio %s | cpio -div'%path, shell=True, check=True, stdout=subprocess.PIPE).stdout.decode()
name = get_rpm_name(file_name)
source_dir = os.getcwd()
type = 'rpm'
elif file_name.endswith('.zip'):
rpm_detect('unzip', 'unzip')
stdout = subprocess.run('unzip %s'%path, shell=True, check=True, stdout=subprocess.PIPE).stdout.decode()
zip_name = re.findall(r'([a-z0-9\-\.]+)\.zip$', file_name, re.I)[0]
print(zip_name)
source_dir = os.path.join(os.getcwd(), zip_name)
type = 'src'
elif file_name.endswith('.tar.gz'):
rpm_detect('tar', 'tar')
stdout = subprocess.run('tar -xzvf %s'%path, shell=True, check=True, stdout=subprocess.PIPE).stdout.decode()
tar_name = re.findall(r'([a-z0-9\-\.]+)\.tar.gz$', file_name, re.I)[0]
source_dir = os.path.join(os.getcwd(), tar_name)
type = 'src'
else:
source_dir = ''
type = 'unkown'
return source_dir, type
def get_api_from_EFI(debuginfo_path, func_name):
pass
def searh_api(path, path_debuginfo):
source, type = rpm_to_source_or_bin(path)
if type == 'rpm':
debuginfo, _ = rpm_to_source_or_bin(path_debuginfo)
if debuginfo == '':
print('No debuginfo rpm found.')
debuginfo_list = []
else:
debuginfo_list = subprocess.run("find %s -name '*.debug'"%debuginfo, shell=True, check=True, stdout=subprocess.PIPE).stdout.decode().split('\n')
so_list = subprocess.run("find %s -name '*.so*'"%source, shell=True, check=True, stdout=subprocess.PIPE).stdout.decode().split('\n')[:-1]
#print('_______________')
#print(so_list)
func_lists = []
for so in so_list:
#print(so)
so = re.findall(r'(.+\.so[\.0-9]*)$', so, re.I)
if len(so)==0:
continue
so_name = so[0].split('/')[-1]
for debuginfo_path in debuginfo_list:
if debuginfo_path.find(so_name)>=0:
#print('*' + debuginfo_path)
break
try:
stdout = subprocess.run("nm -D %s | grep ' T '"%so[0], shell=True, check=True, stdout=subprocess.PIPE).stdout.decode().split('\n')[:-1]
except Exception:
continue
if len(stdout)==0:
continue
func_list = []
for line in stdout:
#print(line)
func = re.findall(r'\sT\s(.+)$', line)
if len(func)==0:
continue
func_list.append(func[0])
#print(func_list)
elf = Read_ELF(debuginfo_path)
for func in func_list:
elf.get_api_from_EFI(func)
if __name__ == '__main__':
path = sys.argv[1]
path_debuginfo = sys.argv[2]
print(path)
print(searh_api(path, path_debuginfo))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。