【问题标题】:How to locate where a built-in function is defined?如何定位内置函数的定义位置?
【发布时间】:2019-10-09 17:56:04
【问题描述】:

在 MATLAB 中,定义函数的方法大致有 3 种:非仅注释 .m 文件、.p 文件和编译代码(例如 DLL、MEX)。

知道函数的定义位置在某些情况下可能会有所帮助,例如在我们无法控制的某个函数中引入了重大更改,并且我们想尝试恢复到旧的希望我们的代码再次运行的版本;或者在尝试对某些未公开的算法进行逆向工程时。

which 函数通常非常擅长识别函数定义及其位置(适用于 .m.p 和 MEX),但在涉及共享库函数时不是很有用,其中 (充其量)它指向一个仅注释的文档文件:

>> which _mcheck
built-in (undocumented)

>> which svd
built-in (D:\Program Files\MATLAB\R2019a\toolbox\matlab\matfun\svd)

如果是这样,假设在我的代码执行期间调用了在共享库中找到的函数,我如何找到包含它的特定文件 (DLL)

【问题讨论】:

    标签: matlab shared-libraries reverse-engineering built-in function-definition


    【解决方案1】:

    事实证明dbstop 可以用于此。例如:

    >> which svd
    built-in (D:\Program Files\MATLAB\R2019a\toolbox\matlab\matfun\svd)
    
    >> dbstop svd
    Warning: Entering debug mode is only supported within running MATLAB code files. 
    Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwmathlinalg>svd" is not a MATLAB code file.
             Instead, the debugger will stop at the point right before "libmwmathlinalg>svd" is called.
    

    从那里只需找到一个名为 libmwmathlinalg(带有相关扩展名)的文件 - 如果您的驱动器被索引,这不是一项艰巨的任务。

    【讨论】:

    • 哈!不确定这是否是 Mathworks 的预期行为(即披露 dll),但很好
    • @AnderBiguri 有点用意,因为在这些 DLL 旁边通常有一个 XML 文件,其中包含所有导出的符号和一些附加信息。
    猜你喜欢
    • 2022-01-21
    • 2018-08-10
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 2022-11-23
    相关资源
    最近更新 更多