即使打开了一个简单的程序,x64dbg 是否也会显示整个内存信息?

逆向工程 记忆 x64dbg
2021-06-27 23:56:21

我在软件逆向工程方面很新。c使用 Visual Studio创建了一个非常简单的程序,代码如下所示。

#include <stdio.h>

void main()
{
    int x, y, z;

    while(1)
    {
        x = 0;
        y = 1;
        do
        {
            printf("%d\n", x);

            z = x + y;
            x = y;
            y = z;
        } while (x < 255);
    }

}

编译程序后,我使用x64dbg打开编译后的输出文件project1.exe

在此处输入图片说明

为什么对于这样一个简单的程序,x64dbg 会显示如此大量的汇编代码(这似乎也发生在其他反汇编程序中)?看看你得到的滚动条。是因为 x64dbg 在这里显示所有内存信息吗?如果是这样,那意味着我可以从这个面板找到在我的计算机上运行的所有其他程序,对吗?

在此先感谢您的澄清。这可能是一个菜鸟问题,但我在网上找不到答案。

1个回答

查询中的图像无法查看。

我想你在问----

为什么我看不到只与我的代码部分有关的汇编代码,以及那些我似乎没有写的额外汇编代码是什么,盯着我看

反汇编控制台应用程序时显示的明显额外代码由编译器插入,称为 c 运行时初始化代码 aka CRT代码

控制台应用程序需要输入机制和输出机制,因此在调用您的代码之前,编译器将这些代码放置到位,您可以在 Visual Studio 目录下找到此类代码的源代码

C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\crt\src\vcruntime>cd ..

C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\crt\src>ls
arm  concrt  i386  linkopts  stl  vccorlib  vcruntime  x64

C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\crt\src>cd vcruntime

C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\crt\src\vcruntime>ls *main*
dll_dllmain.cpp       exe_main.cpp     exe_wmain.cpp     ManagedMain.cpp
dll_dllmain_stub.cpp  exe_winmain.cpp  exe_wwinmain.cpp  vcruntime_dllmain.cpp

C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\crt\src\vcruntime>cat exe_main.cpp
//
// exe_wwinmain.cpp
//
//      Copyright (c) Microsoft Corporation. All rights reserved.
//
// The mainCRTStartup() entry point, linked into client executables that
// uses main().
//
#define _SCRT_STARTUP_MAIN
#include "exe_common.inl"



extern "C" int mainCRTStartup()
{
    return __scrt_common_main();
}

C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\crt\src\vcruntime> 

如果您不想看到这样的代码,请不要创建控制台应用程序,而是编写一个最低限度的 Windows 应用程序并自行处理所有输入和输出机制

例如你的代码可以像这样重写

#include <windows.h>

void mymain() {
    int x, y, z;
    char buff[0x100];

    while(1)
    {
        x = 0;
        y = 1;
        do
        {
            wsprintf(buff , "%d\n", x);
            MessageBoxA(NULL,buff,"test",MB_OK);

            z = x + y;
            x = y;
            y = z;
        } while (x < 255);
    }

}

并从 vc 命令提示符编译了这样的链接(您也可以从项目设置中设置这些选项,但我不会在这里讨论属性页)

cl /GS-  /Zi /W4 /analyze /nologo /Od bare.cpp /link /release /entry:mymain /subsystem:windows user32.lib

gs- 禁用缓冲区安全检查 /entry 对编译说我不想要你放入我的二进制文件的所有东西只是从这里开始

子系统说我不希望你的黑屏对我闪烁

写在我自己的超空间上并通过心灵感应阅读

和宾果游戏,您只需进行此拆卸即可获得纤薄的 3 kb 可执行文件

dumpbin /disasm bare.exe
Microsoft (R) COFF/PE Dumper Version 14.14.26430.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file bare.exe

File Type: EXECUTABLE IMAGE

?mymain@@YAXXZ:
  00401000: 55                 push        ebp
  00401001: 8B EC              mov         ebp,esp
  00401003: 81 EC 0C 01 00 00  sub         esp,10Ch
  00401009: B8 01 00 00 00     mov         eax,1
  0040100E: 85 C0              test        eax,eax
  00401010: 74 5D              je          0040106F
  00401012: C7 45 FC 00 00 00  mov         dword ptr [ebp-4],0
            00
  00401019: C7 45 F8 01 00 00  mov         dword ptr [ebp-8],1
            00
  00401020: 8B 4D FC           mov         ecx,dword ptr [ebp-4]
  00401023: 51                 push        ecx
  00401024: 68 10 20 40 00     push        402010h
  00401029: 8D 95 F4 FE FF FF  lea         edx,[ebp-10Ch]
  0040102F: 52                 push        edx
  00401030: FF 15 04 20 40 00  call        dword ptr [__imp__wsprintfA]
  00401036: 83 C4 0C           add         esp,0Ch
  00401039: 6A 00              push        0
  0040103B: 68 14 20 40 00     push        402014h
  00401040: 8D 85 F4 FE FF FF  lea         eax,[ebp-10Ch]
  00401046: 50                 push        eax
  00401047: 6A 00              push        0
  00401049: FF 15 00 20 40 00  call        dword ptr [__imp__MessageBoxA@16]
  0040104F: 8B 4D FC           mov         ecx,dword ptr [ebp-4]
  00401052: 03 4D F8           add         ecx,dword ptr [ebp-8]
  00401055: 89 4D F4           mov         dword ptr [ebp-0Ch],ecx
  00401058: 8B 55 F8           mov         edx,dword ptr [ebp-8]
  0040105B: 89 55 FC           mov         dword ptr [ebp-4],edx
  0040105E: 8B 45 F4           mov         eax,dword ptr [ebp-0Ch]
  00401061: 89 45 F8           mov         dword ptr [ebp-8],eax
  00401064: 81 7D FC FF 00 00  cmp         dword ptr [ebp-4],0FFh
            00
  0040106B: 7C B3              jl          00401020
  0040106D: EB 9A              jmp         00401009
  0040106F: 8B E5              mov         esp,ebp
  00401071: 5D                 pop         ebp
  00401072: C3                 ret
_wsprintfA:
  00401073: FF 25 04 20 40 00  jmp         dword ptr [__imp__wsprintfA]
_MessageBoxA@16:
  00401079: FF 25 00 20 40 00  jmp         dword ptr [__imp__MessageBoxA@16]

  Summary

        1000 .rdata
        1000 .reloc
        1000 .text

编辑

在我发布答案后,屏幕截图似乎已内联,并且屏幕截图中的代码属于 ntdll 而不是您的模块 ntdll 是任何应用程序都必须使用的 dll,它提供了用于转换到内核空间的低级资源和例程

转到模块窗格(alt+mi 会猜测 x64dbg 使用 ollydbg ui 快捷方式)

并选择您的模块并按照其入口点查看您的代码