以调试ffmpeg为例,演示gdb如何定位内存被修改

本文演示了使用gdb定位avformat_find_stream_info函数破坏codecpar变量的问题

1.查看音频或视频stream index【以下以视频为例】

./ffprobe demo.avi 2>&1 | grep Stream
Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1920x1080, 4021 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc

以上视频的stream index=0

2.修改ffmpeg,在avformat_find_stream_info中将codecpar置NULL

vim libavformat/utils.c -> avformat_find_stream_info

av_opt_set(ic, "skip_clear", "1", AV_OPT_SEARCH_CHILDREN);
ic->streams[0]->codecpar=NULL;  //*破坏 codecpar
max_stream_analyze_duration = max_analyze_duration;

3.编译ffmpeg debug版本

./configure --enable-debug
make -j

4.启动gdb

gdb --args ./ffmpeg_g -i demo.avi  -qp 10  out.avi -y

5.在avformat_find_stream_info下断点

(gdb) b avformat_find_stream_info
Breakpoint 1 at 0x7ce180: file libavformat/utils.c, line 3623.

6.运行

(gdb) r
Starting program: ./ffmpeg_g -i demo.avi -qp 10 out.avi -y
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
ffmpeg version n4.3.4 Copyright (c) 2000-2021 the FFmpeg developersbuilt with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)configuration: --enable-debuglibavutil      56. 51.100 / 56. 51.100libavcodec     58. 91.100 / 58. 91.100libavformat    58. 45.100 / 58. 45.100libavdevice    58. 10.100 / 58. 10.100libavfilter     7. 85.100 /  7. 85.100libswscale      5.  7.100 /  5.  7.100libswresample   3.  7.100 /  3.  7.100Breakpoint 1, avformat_find_stream_info (ic=0x22ca500, options=0x22cc500) at libavformat/utils.c:3623
warning: Source file is more recent than executable.
3623    {
Missing separate debuginfos, use: debuginfo-install bzip2-libs-1.0.6-13.el7.x86_64 glibc-2.17-326.el7_9.x86_64 libXau-1.0.8-2.1.el7.x86_64 libdrm-2.4.91-3.el7.x86_64 libva-1.8.3-1.el7.x86_64 libxcb-1.13-1.el7.x86_64 zlib-1.2.7-19.el7_9.x86_64

7.查看变量

 (gdb) print(*(AVFormatContext*)ic)
$1 = {av_class = 0x128d300 <av_format_context_class>, iformat = 0x1892fe0 <ff_avi_demuxer>, oformat = 0x0, priv_data = 0x22cb040, pb = 0x22d31c0, ctx_flags = 0, nb_streams = 1, streams = 0x22cb100,filename = "demo.avi", '\000' <repeats 1009 times>, url = 0x22cacc0 "demo.avi", start_time = -9223372036854775808, duration = -9223372036854775808, bit_rate = 0, packet_size = 0, max_delay = -1, flags = 2097156,probesize = 5000000, max_analyze_duration = 0, key = 0x0, keylen = 0, nb_programs = 0, programs = 0x0, video_codec_id = AV_CODEC_ID_NONE, audio_codec_id = AV_CODEC_ID_NONE, subtitle_codec_id = AV_CODEC_ID_NONE,max_index_size = 1048576, max_picture_buffer = 3041280, nb_chapters = 0, chapters = 0x0, metadata = 0x22cc440, start_time_realtime = -9223372036854775808, fps_probe_size = -1, error_recognition = 1, interrupt_callback = {callback = 0x4a5fa0 <decode_interrupt_cb>, opaque = 0x0}, debug = 0, max_interleave_delta = 10000000, strict_std_compliance = 0, event_flags = 0, max_ts_probe = 50, avoid_negative_ts = -1, ts_id = 0, audio_preload = 0,max_chunk_duration = 0, max_chunk_size = 0, use_wallclock_as_timestamps = 0, avio_flags = 0, duration_estimation_method = AVFMT_DURATION_FROM_PTS, skip_initial_bytes = 0, correct_ts_overflow = 1, seek2any = 0,flush_packets = -1, probe_score = 100, format_probesize = 1048576, codec_whitelist = 0x0, format_whitelist = 0x0, internal = 0x22cab80, io_repositioned = 0, video_codec = 0x0, audio_codec = 0x0, subtitle_codec = 0x0,data_codec = 0x0, metadata_header_padding = -1, opaque = 0x0, control_message_cb = 0x0, output_ts_offset = 0, dump_separator = 0x22ca010 ", ", data_codec_id = AV_CODEC_ID_NONE, open_cb = 0x0,protocol_whitelist = 0x22ca2b0 "file,crypto,data", io_open = 0x77bdf0 <io_open_default>, io_close = 0x77bde0 <io_close_default>, protocol_blacklist = 0x0, max_streams = 1000, skip_estimate_duration_from_pts = 0,max_probe_packets = 2500}
(gdb) print(*(AVStream *)((*(AVFormatContext*)ic)->streams[0]))
$2 = {index = 0, id = 0, codec = 0x22cb580, priv_data = 0x22cbf00, time_base = {num = 1, den = 25}, start_time = 0, duration = 1656, nb_frames = 1656, disposition = 0, discard = AVDISCARD_DEFAULT, sample_aspect_ratio = {num = 0,den = 1}, metadata = 0x0, avg_frame_rate = {num = 25, den = 1}, attached_pic = {buf = 0x0, pts = 0, dts = 0, data = 0x0, size = 0, stream_index = 0, flags = 0, side_data = 0x0, side_data_elems = 0, duration = 0, pos = 0,convergence_duration = 0}, side_data = 0x0, nb_side_data = 0, event_flags = 0, r_frame_rate = {num = 0, den = 0}, recommended_encoder_configuration = 0x0, codecpar = 0x22cba00, info = 0x22cb4c0, pts_wrap_bits = 64,first_dts = -9223372036854775808, cur_dts = 9223090561878065151, last_IP_pts = -9223372036854775808, last_IP_duration = 0, probe_packets = 2500, codec_info_nb_frames = 0, need_parsing = AVSTREAM_PARSE_HEADERS, parser = 0x0,last_in_packet_buffer = 0x0, probe_data = {filename = 0x0, buf = 0x0, buf_size = 0, mime_type = 0x0}, pts_buffer = {-9223372036854775808 <repeats 17 times>}, index_entries = 0x22db2e0, nb_index_entries = 1656,index_entries_allocated_size = 41495, stream_identifier = 0, program_num = 0, pmt_version = 0, pmt_stream_idx = 0, interleaver_chunk_size = 0, interleaver_chunk_duration = 0, request_probe = 0, skip_to_keyframe = 0,skip_samples = 0, start_skip_samples = 0, first_discard_sample = 0, last_discard_sample = 0, nb_decoded_frames = 0, mux_ts_offset = 0, pts_wrap_reference = -9223372036854775808, pts_wrap_behavior = 0,update_initial_durations_done = 0, pts_reorder_error = {0 <repeats 17 times>}, pts_reorder_error_count = '\000' <repeats 16 times>, last_dts_for_order_check = -9223372036854775808, dts_ordered = 0 '\000',dts_misordered = 0 '\000', inject_global_side_data = 0, display_aspect_ratio = {num = 0, den = 0}, internal = 0x22cad00}
(gdb) print ((*(AVStream *)((*(AVFormatContext*)ic)->streams[0]))->codecpar)
$3 = (AVCodecParameters *) 0x22cba00
(gdb) print *(AVCodecParameters*)((*(AVStream *)((*(AVFormatContext*)ic)->streams[0]))->codecpar)
$4 = {codec_type = AVMEDIA_TYPE_VIDEO, codec_id = AV_CODEC_ID_H264, codec_tag = 875967048, extradata = 0x0, extradata_size = 0, format = -1, bit_rate = 4021700, bits_per_coded_sample = 24, bits_per_raw_sample = 0, profile = -99,level = -99, width = 1920, height = 1080, sample_aspect_ratio = {num = 0, den = 1}, field_order = AV_FIELD_UNKNOWN, color_range = AVCOL_RANGE_UNSPECIFIED, color_primaries = AVCOL_PRI_UNSPECIFIED,color_trc = AVCOL_TRC_UNSPECIFIED, color_space = AVCOL_SPC_UNSPECIFIED, chroma_location = AVCHROMA_LOC_UNSPECIFIED, video_delay = 0, channel_layout = 0, channels = 0, sample_rate = 0, block_align = 0, frame_size = 0,initial_padding = 0, trailing_padding = 0, seek_preroll = 0}

8.监控 codecpar 变量

(gdb) watch ((*(AVStream *)((*(AVFormatContext*)ic)->streams[0]))->codecpar)
Watchpoint 2: ((*(AVStream *)((*(AVFormatContext*)ic)->streams[0]))->codecpar)

9.继续运行【如果变量被修改,程序会停住】

(gdb) c
Continuing.
Watchpoint 2: ((*(AVStream *)((*(AVFormatContext*)ic)->streams[0]))->codecpar)Old value = (AVCodecParameters *) 0x22cba00
New value = (AVCodecParameters *) 0x0
avformat_find_stream_info (ic=0x22ca500, options=0x22cc500) at libavformat/utils.c:3646
3646        if (!max_analyze_duration) {

10.查看调用栈

(gdb) bt
#0  avformat_find_stream_info (ic=0x22ca500, options=0x22cc500) at libavformat/utils.c:3646
#1  0x0000000000496e7b in open_input_file (o=o@entry=0x7fffffffe0a0, filename=<optimized out>) at fftools/ffmpeg_opt.c:1184
#2  0x000000000049b9cf in open_files (inout=0x1298fb1 "input", open_file=0x496290 <open_input_file>, l=<optimized out>, l=<optimized out>) at fftools/ffmpeg_opt.c:3299
#3  ffmpeg_parse_options (argc=argc@entry=7, argv=argv@entry=0x7fffffffe5a8) at fftools/ffmpeg_opt.c:3339
#4  0x000000000048f5fd in main (argc=7, argv=0x7fffffffe5a8) at fftools/ffmpeg.c:4849

10.查看代码上下文

(gdb) list
3641
3642        av_opt_set(ic, "skip_clear", "1", AV_OPT_SEARCH_CHILDREN);
3643        ic->streams[0]->codecpar=NULL;
3644        max_stream_analyze_duration = max_analyze_duration;
3645        max_subtitle_analyze_duration = max_analyze_duration;
3646        if (!max_analyze_duration) {
3647            max_stream_analyze_duration =
3648            max_analyze_duration        = 5*AV_TIME_BASE;
3649            max_subtitle_analyze_duration = 30*AV_TIME_BASE;
3650            if (!strcmp(ic->iformat->name, "flv"))

11.修复BUG

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/750983.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

sqllab第二十七A关通关笔记

知识点&#xff1a; 双引号闭合union select 大小写绕过 Union Select这里不能进行错误注入&#xff0c;无回显 经过测试发现这是一个双引号闭合 构造payload:id1"%09and%091"1 页面成功回显 构造payload:id0"%09uNion%09SElect%091,2,3%09"1 页面成功…

在雄安新区买新房要注意什么?有哪些注意事项?

雄安新区新建住宅均价每平方米11735元起&#xff0c;二手房每平方米8950元起。 整体价格非常有优势。 雄安新区房价走势与区域发展直接相关。 而且&#xff0c;雄安新区已经成立五周年了。 2022年&#xff0c;雄安新区多项重点项目将陆续竣工。 雄安新区城市基础设施建设已初具…

Linux之shell循环

华子目录 for循环带列表的for循环格式分析示例shell允许用户指定for语句的步长&#xff0c;格式如下示例 不带列表的for循环示例 基于C语言风格的for循环格式示例注意 while循环格式示例 until循环作用格式示例 循环控制breakcontinue详细语法示例 循环嵌套示例 for循环 for循…

深度学习——SAM(Segment-Anything)代码详解

目录 引言代码目录segment-anything 代码详解build_sam.pypredictor.pyautomatic_mask_generator.py 引言 从去年年初至今&#xff0c;SAM(Segment Anything )已经问世快一年了&#xff0c;SAM凭借其强大而突出的泛化性能在各项任务上取得了优异的表现&#xff0c;广大的研究者…

代码随想录 二叉树—翻转二叉树

思路&#xff1a;想到递归&#xff0c;遍历方法&#xff1a;前序遍历&#xff08;中左右&#xff09;&#xff0c;swap就是 中 的操作。 题解c&#xff1a; /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *…

源码编译部署LAMP

编译部署LAMP 配置apache [rootzyq ~]#: wget https://downloads.apache.org/apr/apr-1.7.4.tar.gz --2023-12-11 14:35:57-- https://downloads.apache.org/apr/apr-1.7.4.tar.gz Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104…

Winform编程详解九:LinkLabel 链接标签控件

一、属性介绍 1. (Name) 控件的对象标识符ID 2. ActiveLinkColor 单击链接时的颜色 3. BackColor 控件的背景颜色 4. BorderStyle 控件的边框样式 5. Cursor 鼠标移过该控件显示的光标样式 6. DisabledLinkColor 不激活链接时的颜色 7. Font 控件的字体样式 8. ForeCol…

BUUCTF-WEB1

[ACTF2020 新生赛]Exec1 1.打开靶机 是一个ping命令 2.利用管道符“|” ping一下本地主机并查看ls ping 127.0.0.1 | ls 可以看到回显的内容是一个文件 127.0.0.1 | cat index.php #查看主机下index.php 127.0.0.1 | ls / #查看主机根目录下的文件 看的一个flag文件 …

数据仓库数据分层详解

数据仓库中的数据分层是一种重要的数据组织方式&#xff0c;其目的是为了在管理数据时能够对数据有一个更加清晰的掌控。以下是数据仓库中的数据分层详解&#xff1a; 原始数据层&#xff08;Raw Data Layer&#xff09;&#xff1a;这是数仓中最底层的层级&#xff0c;用于存…

jupyter闪退和自动跳转问题

1.闪退问题 当我们点击jupyter时&#xff0c;它会闪一下&#xff0c;然后无法进入&#xff0c;这个时候我们可以去prompt命令行输入jupyter notebook启动试试&#xff0c;如果还不行&#xff0c;我们可以根据报错去解决&#xff0c;一般csdn上都有对应情况&#xff0c;直接搜索…

Linux-新手小白速秒Hadoop集群全生态搭建(图文混编超详细)

在之前的文章中&#xff0c;我教会大家如何一步一步搭建一个Hadoop集群&#xff0c;但是只提供了代码&#xff0c;怕有些朋友会在一些地方产生疑惑&#xff0c;今天我来以图文混排的方式&#xff0c;一站式交给大家如何搭建一个Hadoop高可用集群包括&#xff08;HadoopHA&#…

ros | 怎么导出.bag中的文件

前面有一篇文章说了怎么录制包 ros | 如何录制包 这篇文章简单说一下怎么导出文件 1、先了解.bag 文件中都有什么 ls找到.bag 文件&#xff0c;一般为一堆日期然后后缀为.bag rosbag info 2020-10-28-10-13-39.bag 看到其中topics中的很多文件 然后导出文本 rostopic …

el-select使用filterable下拉无法关闭得问题

这里推荐一个前端框架 sakuya / SCUI&#xff0c;他里面有个formTable&#xff0c;可以解决很多订单明细保存得问题。基本沿用element-plus的前端使用模式&#xff0c;让表单表格变的非常容易。 这个的供应商插件&#xff0c;当使用filterable后&#xff0c;点击表格重的选项&…

Redis Desktop Manager:一站式Redis数据库管理与优化

Redis Desktop Manager是一款功能强大的Redis桌面管理工具&#xff0c;也被称作Redis可视化工具。以下是其主要的功能特色&#xff1a; 连接管理&#xff1a;Redis Desktop Manager支持连接多个Redis服务器&#xff0c;用户可以在同一界面下管理多个数据库&#xff0c;大大提高…

接口测试及接口测试工具【Postman】相关的面试题

Postman是一种接口调试与http接口测试的工具&#xff0c;可以非常方便的模拟get、post或其他请求来调试和测试接口 文章目录 Postman优点Postman使用流程Postman参数化有哪几种方式Postman如何设置关联接口测试能发现什么问题如何分析bug是前端还是后端当一个接口出现异常时&am…

transformer入门学习(二)

import torch# pytorch import torch.nn as nn# 模型工具包 import torch.nn.functional as F# 函数运算工具包 from torch.autograd import Variable# 变量处理包 import math import matplotlib.pyplot as pyp import numpy as np import copy import math # embedding class…

记录一下在Pycharm中虚拟环境的创建

如果在Pycharm中要新建一个虚拟环境&#xff0c;那你可以在Terminal中选择Command Prompt&#xff0c;在这里面执行相关命令 一、安装了Anaconda&#xff0c;创建虚拟环境 当你使用解释器是Anaconda提供的时&#xff0c;你可以使用conda命令执行&#xff0c;见以下操作&#x…

前端Vue与uni-app中的九宫格、十二宫格和十五宫格菜单组件实现

在前端 Vue 开发中&#xff0c;我们经常会遇到需要开发九宫格、十二宫格和十五宫格菜单按钮的需求。这些菜单按钮通常用于展示不同的内容或功能&#xff0c;提供给用户快速访问和选择。 一、引言 在前端开发中&#xff0c;九宫格、十二宫格和十五宫格菜单按钮是一种常见的布局…

202206 CSP认证 | 角色授权

角色授权 fine&#xff0c;又是一道acwing上TLE但是平台通过了的&#xff0c;那就酱吧… 直接跟着题目来模拟的…先找到每个用户授予的所有角色&#xff0c;包括用户本身和它所属的用户组。 然后遍历这个角色集合&#xff0c;看是否有操作权限&#xff0c;种类权限以及资源名称…

Android 辅助功能 -抢红包

Android 辅助功能 -抢红包 本篇文章主要介绍下通过android辅助功能的方式来实现类似抢红包的功能. 1:权限声明 <uses-permissionandroid:name"android.permission.BIND_ACCESSIBILITY_SERVICE"tools:ignore"ProtectedPermissions" />2: 配置信息 …