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

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

        <bdo id='AILqA'></bdo><ul id='AILqA'></ul>
    1. Visual C++ 在函数末尾附加 0xCC (int3) 字节

      Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
        <tbody id='NRVbl'></tbody>
      <tfoot id='NRVbl'></tfoot>

              • <bdo id='NRVbl'></bdo><ul id='NRVbl'></ul>

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

                <legend id='NRVbl'><style id='NRVbl'><dir id='NRVbl'><q id='NRVbl'></q></dir></style></legend>

                <i id='NRVbl'><tr id='NRVbl'><dt id='NRVbl'><q id='NRVbl'><span id='NRVbl'><b id='NRVbl'><form id='NRVbl'><ins id='NRVbl'></ins><ul id='NRVbl'></ul><sub id='NRVbl'></sub></form><legend id='NRVbl'></legend><bdo id='NRVbl'><pre id='NRVbl'><center id='NRVbl'></center></pre></bdo></b><th id='NRVbl'></th></span></q></dt></tr></i><div id='NRVbl'><tfoot id='NRVbl'></tfoot><dl id='NRVbl'><fieldset id='NRVbl'></fieldset></dl></div>
              • 本文介绍了Visual C++ 在函数末尾附加 0xCC (int3) 字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                这是我第一次来,我真的希望你们能帮助我,因为我现在已经没有想法了.

                This is my first time around, and I really hope you guys can help me, as I have ran out of ideas by now.

                我已经搜索了几个小时的答案,但找不到实际可行的答案.

                I have searched for an answer for a couple of hours now, and could not find an answer that would actually work.

                我想直接将代码注入正在运行的进程中.是的,你没有看错.我正在尝试将代码注入另一个应用程序,并且 - 不管你信不信 - 这只是为了扩展它的功能.

                I would like to directly inject code into a running process. Yes, you have read it right. I am trying to inject code into another application, and - believe it or not - this is only to extend the functionality of it.

                我在 Windows 上使用 Visual Studio 2012 Express Edition.

                I am using Visual Studio 2012 Express Edition on Windows.

                我有以下代码:

                __declspec(naked) void Foo()
                {
                    __asm
                    {
                        // Inline assembly code here
                    }
                }
                __declspec(naked) void FooEnd() {}
                
                int main()
                {
                    cout << HEX(Foo) << endl;
                    cout << HEX(FooEnd) <<  endl;
                    cout << (int)FooEnd - (int)Foo << endl;
                
                    // Inject code here using WriteProcessMemory
                
                    return 0;
                }
                

                为了保持可读性,大部分代码已被删除,但我可以根据要求发布其他部分.

                Most of the code has been removed in order to maintain readability, though I can post other portions of it on request.

                输出如下:

                0x010B1000
                0x010B1010
                16
                

                结果大小实际上是不正确的.这些函数以正确的顺序编译(确保使用/ORDER),但是编译器在每个扩展其大小的方法之后添加了一堆 0xCC(int 3)字节,所以我无法获得真正的(有用的)数字包含实际可执行代码的字节数.

                The resulting size is actually incorrect. The functions are compiled in the right order (made sure using /ORDER), but the compiler adds a bunch of 0xCC (int 3) bytes after each method which extends it's size, and so I can't get the real (useful) number of bytes that contains actual executable code.

                在另一个 stackoverflow 问题中,据说禁用编辑并继续"会使这些额外的字节消失,但无论如何,这对我不起作用.

                In another stackoverflow question, it has been said that disabling "Edit and Continue" would make these extra bytes go away, but no matter what, that didn't work for me.

                我也尝试使用 Release setup 而不是 Debug,更改了一堆优化设置,但这些都没有任何效果.您认为可能的解决方案是什么?我可能遗漏了一些明显的东西.

                I also tried using Release setup instead of Debug, changed a bunch of optimization settings, but none of these had any effect. What do you think could be the solution? I may be missing something obvious.

                无论如何,这是(在您看来)获取函数长度(可读性、可靠性、易用性)的最佳方式吗?

                Anyway, is this (in your opinion) the best way to acquire a function's length (readability, reliability, ease of use)?

                我希望我解释了我必须做的一切,以便您能够提供帮助.如果您还有其他问题,请随时发表评论.

                I hope I explained everything I had to in order for you to be able to help. If you have further questions, please feel free to leave a comment.

                感谢您的时间和努力.

                推荐答案

                在注入代码时不需要额外的填充,因此可以丢弃它们.复制它们也应该没问题,它只会导致复制一些额外的字节.无论如何,您注入的内存可能会被页面对齐的块所占用,因此通过剥离它您并没有真正获得任何东西.

                You don't need the extra padding when you're injecting the code, so it's fine to discard them. It should also be fine to copy them over, it will just result in a few extra bytes of copying. Chances are the memory you're injecting to will by a page-aligned block anyway, so you're not really gaining anything by stripping it out.

                但是如果你真的想去掉它,一个简单的解决你的问题的方法是从下一个函数之前的最后一个字节向后迭代,直到没有更多的 0xcc 字节.

                But if you really want to strip it out, a simple solution to your problem would be to just iterate backwards from the last byte before the next function, until there are no more 0xcc bytes.

                即:

                __declspec(naked) void Foo()
                {
                   __asm
                   {
                      _emit 0x4A
                      _emit 0x4B
                   }
                }
                __declspec(naked) void FooEnd() {}
                
                
                int main(int argc, char** argv)
                {
                   //start at the last byte of the memory-aligned code instead of the first byte of FooEnd
                   unsigned char* fooLast = (unsigned char*)FooEnd-1;
                
                   //keep going backwards until we don't have a 0xcc
                   while(*fooLast == 0xCC)
                      fooLast--;
                
                   //fooLast will now point at the last byte of your function, so you need to add 1
                   int length = ((int)fooLast - (int)Foo) + 1;
                
                   //should output 2 for the length of Foo
                   std::cout << length;
                }
                

                这篇关于Visual C++ 在函数末尾附加 0xCC (int3) 字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to print vector#39;s data(如何打印矢量的数据)
                How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                MSVC++ warning flags(MSVC++ 警告标志)
                How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                std::unordered_map very high memory usage(std::unordered_map 非常高的内存使用率)
                  <tbody id='3K4SX'></tbody>

                • <bdo id='3K4SX'></bdo><ul id='3K4SX'></ul>

                  <small id='3K4SX'></small><noframes id='3K4SX'>

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

                    • <legend id='3K4SX'><style id='3K4SX'><dir id='3K4SX'><q id='3K4SX'></q></dir></style></legend>
                      • <tfoot id='3K4SX'></tfoot>