#调用joern将.c文件转成cpg.bin.zip
import os
import subprocess
def joern_parse(folder_path,output_path):
# 遍历文件夹中的所有文件
for filename in os.listdir(folder_path):
# 检查文件是否为.c文件
if filename.endswith('.c'):
# 构建输入文件路径/path/xx.c
input_file = os.path.join(folder_path, filename)
# 构建输出文件路径/path/xx.bin.zip
output_file = os.path.join(output_path, filename[:-2]+ '.bin.zip')
# 调用joern-parse命令
subprocess.call(['/joern_path/joern-parse', input_file, '--out', output_file])
# 打印成功信息
print(f'成功处理文件: {filename}')
#如果处理失败,则打印错误信息
if not os.path.exists(output_file):
print(f'处理文件失败: {filename}')
# 打印完成信息
print('所有文件处理完成')
if __name__ == '__main__':
# 定义要处理的文件夹路径
folder_path = 'c_file_path'
# 定义输出文件夹路径
output_path = 'cpg_path'
# 检查输出文件夹是否存在,如果不存在则创建
if not os.path.exists(output_path):
os.makedirs(output_path)
joern_parse(folder_path,output_path)
Devign数据集处理【2】利用joern将.c文件处理为cpg文件
于 2024-10-18 22:26:50 首次发布
765

被折叠的 条评论
为什么被折叠?



