<bdo id='x7nqn'></bdo><ul id='x7nqn'></ul>
      <i id='x7nqn'><tr id='x7nqn'><dt id='x7nqn'><q id='x7nqn'><span id='x7nqn'><b id='x7nqn'><form id='x7nqn'><ins id='x7nqn'></ins><ul id='x7nqn'></ul><sub id='x7nqn'></sub></form><legend id='x7nqn'></legend><bdo id='x7nqn'><pre id='x7nqn'><center id='x7nqn'></center></pre></bdo></b><th id='x7nqn'></th></span></q></dt></tr></i><div id='x7nqn'><tfoot id='x7nqn'></tfoot><dl id='x7nqn'><fieldset id='x7nqn'></fieldset></dl></div>
      <legend id='x7nqn'><style id='x7nqn'><dir id='x7nqn'><q id='x7nqn'></q></dir></style></legend>
      <tfoot id='x7nqn'></tfoot>

      <small id='x7nqn'></small><noframes id='x7nqn'>

        在 DLL 中调用非导出函数

        Calling a non-exported function in a DLL(在 DLL 中调用非导出函数)
      1. <tfoot id='K7Xpz'></tfoot>

              <tbody id='K7Xpz'></tbody>

            <small id='K7Xpz'></small><noframes id='K7Xpz'>

            <legend id='K7Xpz'><style id='K7Xpz'><dir id='K7Xpz'><q id='K7Xpz'></q></dir></style></legend>
                <bdo id='K7Xpz'></bdo><ul id='K7Xpz'></ul>
              • <i id='K7Xpz'><tr id='K7Xpz'><dt id='K7Xpz'><q id='K7Xpz'><span id='K7Xpz'><b id='K7Xpz'><form id='K7Xpz'><ins id='K7Xpz'></ins><ul id='K7Xpz'></ul><sub id='K7Xpz'></sub></form><legend id='K7Xpz'></legend><bdo id='K7Xpz'><pre id='K7Xpz'><center id='K7Xpz'></center></pre></bdo></b><th id='K7Xpz'></th></span></q></dt></tr></i><div id='K7Xpz'><tfoot id='K7Xpz'></tfoot><dl id='K7Xpz'><fieldset id='K7Xpz'></fieldset></dl></div>
                  本文介绍了在 DLL 中调用非导出函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个加载 DLL 的程序,我需要调用它包含的非导出函数之一.有什么办法可以通过在调试器中搜索或其他方式来做到这一点吗?在有人问之前,是的,我有函数的原型和东西.

                  I have a program which loads DLLs and I need to call one of the non-exported functions it contains. Is there any way I can do this, via searching in a debugger or otherwise? Before anyone asks, yes I have the prototypes and stuff for the functions.

                  推荐答案

                  是的,至少有一点,但这不是一个好主意.

                  Yes there is, at least sort of, but it isn't a good idea.

                  在 C/C++ 中,函数指针就是内存中的地址.所以如果你能以某种方式找到这个函数的地址,你可以调用它.

                  In C/C++ all a function pointer is, is an address in memory. So if you somehow where able to find the address of this function you could call it.

                  让我问一些问题,你怎么知道这个DLL包含这个函数?你有源代码吗?否则我不知道您如何确定此函数存在或调用是否安全.但是,如果您有源代码,则只需公开该函数即可.如果 DLL 编写者没有公开这个函数,他们永远不会期望你调用它并且可以随时更改/删除实现.

                  Let me ask some questions though, how do you know this DLL contains this function? Do you have the source code? Otherwise I don't know how you could know for certain that this function exists or if it is safe to call. But if you have the source code, then just expose the function. If the DLL writer didn't expose this function, they never expect you to call it and can change/remove the implementation at any time.

                  除了警告之外,如果您有调试符号或MAP 文件,您可以在 DLL 中找到偏移量.如果您除了 DLL 之外什么都没有,那么就无法知道该函数在 DLL 中的位置——它没有存储在 DLL 本身中.

                  Warnings aside, you can find the function address if you have debug symbols or a MAP file you can find the offset in the DLL. If you don't have anything but the DLL, then there is no way to know where that function exists in the DLL - it is not stored in the DLL itself.

                  一旦你有了偏移量,你就可以像这样将它插入到代码中:

                  Once you have the offset you can then insert that into the code like so:

                  const DWORD_PTR funcOffset = 0xDEADBEEF;
                  typedef void (*UnExportedFunc)();
                  
                  ....
                  void CallUnExportedFunc() {
                       // This will get the DLL base address (which can vary)
                       HMODULE hMod = GetModuleHandle("My.dll"); 
                       // Calcualte the acutal address 
                       DWORD_PTR funcAddress = (DWORD_PTR)hMod + funcOffset;
                       // Cast the address to a function poniter
                       UnExportedFunc func = (UnExportedFunc)funcAddress;
                       // Call the function
                       func();
                  }
                  

                  还要意识到这个函数的偏移量会在每次重建 DLL 时发生变化,所以这非常脆弱,让我再说一遍,这不是一个好主意.

                  Also realize that the offset of this function WILL CHANGE EVERY TIME the DLL is rebuilt so this is very fragile and let me say again, not a good idea.

                  这篇关于在 DLL 中调用非导出函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                    <legend id='pfs4n'><style id='pfs4n'><dir id='pfs4n'><q id='pfs4n'></q></dir></style></legend>

                      <bdo id='pfs4n'></bdo><ul id='pfs4n'></ul>
                      • <i id='pfs4n'><tr id='pfs4n'><dt id='pfs4n'><q id='pfs4n'><span id='pfs4n'><b id='pfs4n'><form id='pfs4n'><ins id='pfs4n'></ins><ul id='pfs4n'></ul><sub id='pfs4n'></sub></form><legend id='pfs4n'></legend><bdo id='pfs4n'><pre id='pfs4n'><center id='pfs4n'></center></pre></bdo></b><th id='pfs4n'></th></span></q></dt></tr></i><div id='pfs4n'><tfoot id='pfs4n'></tfoot><dl id='pfs4n'><fieldset id='pfs4n'></fieldset></dl></div>

                          <small id='pfs4n'></small><noframes id='pfs4n'>

                            <tbody id='pfs4n'></tbody>
                          1. <tfoot id='pfs4n'></tfoot>