如何制作 C++ EXE 变大(人为)

发布于 2024-09-25 13:56:31 字数 239 浏览 1 评论 0原文

我想制作一个比应有的大得多的虚拟 Win32 EXE 文件。因此,默认情况下,样板 Win32 EXE 文件为 80 KB。我想要一个 5 MB 的文件来测试其他一些实用程序。

第一个想法是添加资源,但事实证明,在内存分配方面,嵌入式资源与 5 MB 代码不同。我想我可以引用一个大型库并最终得到一个巨大的 EXE 文件?如果没有,也许编写数千个类似方法的脚本,如 AddNum1、AddNum2 等?

任何简单的想法都非常受欢迎。

I want to make a dummy Win32 EXE file that is much larger than it should be. So by default a boiler plate Win32 EXE file is 80 KB. I want a 5 MB one for testing some other utilities.

The first idea is to add a resource, but as it turns out embedded resources are not the same as 5 MB of code when it comes to memory allocation. I am thinking I can reference a large library and end up with a huge EXE file? If not, perhaps scripting a few thousand similar methods like AddNum1, AddNum2, etc., etc.?

Any simple ideas are very appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

南巷近海 2024-10-02 13:56:32

如果您想要增加文件大小,则将文本文件附加到所需大小的 exe 末尾。

当顾客抱怨小前任时,我曾经这样做过。他们没有意识到小个子的前任和大个子的前任一样专业。事实上,在某些语言中,通常在 BASIC 编译器中,有一个 bloat() 命令来增加 exe 的大小。

编辑:找到人们使用的一段代码的旧链接: http://www.purebasic.fr/english/viewtopic.php?f=12&t=38994

示例:https://softwareengineering.stackexchange.com/questions/2051/what-is -客户老板要求你做的最疯狂最愚蠢的事情/2698#2698

If it's the file size you want to increase then append a text file to the end of the exe of the required size.

I used to do this when customers would complain of small exes. They didn't realize that small exes are just as professional as larger exes. In fact in some languages there is a bloat() command to increase the size of exes, usually in BASIC compilers.

EDIT: Found an old link to a piece of code that people use: http://www.purebasic.fr/english/viewtopic.php?f=12&t=38994

An example: https://softwareengineering.stackexchange.com/questions/2051/what-is-the-craziest-stupidest-silliest-thing-a-client-boss-asked-you-to-do/2698#2698

坏尐絯 2024-10-02 13:56:32

在汇编器中用 NOP 填充 EXE 文件。

Fill the EXE file with NOPs in assembler.

﹂绝世的画 2024-10-02 13:56:32

只在 .exe 末尾添加二进制零怎么样?

How about just adding binary zeroes to the end of the .exe?

冰魂雪魄 2024-10-02 13:56:32

使用大量常量数据,例如显式字符串:

char *dummy_data[] = {
    "blajkhsdlmf..(long script-generated random string)..",
    "kjsdfgkhsdfgsdgklj..(etc...)...jldsjglkhsdghlsdhgjkh",
};

与变量数据不同,常量数据通常与实际代码位于同一内存部分,尽管这可能取决于编译器或链接器。

编辑:我测试了以下内容,它可以在 Linux 上运行:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i, j;

    puts("char *dummy_data[] = {");
    for (i = 0; i < 5000; i++) {
        fputs("    \"", stdout);
        for (j = 0; j < 1000; j++) putchar('a' + rand() % 26);
        puts("\",");
    }
    puts("};");
    return 0;
}

此代码及其输出都可以干净地编译。

Use a big array of constant data, like explicit strings:

char *dummy_data[] = {
    "blajkhsdlmf..(long script-generated random string)..",
    "kjsdfgkhsdfgsdgklj..(etc...)...jldsjglkhsdghlsdhgjkh",
};

Unlike variable data, constant data often falls in the same memory section as the actual code, although this may be compiler- or linker-dependent.

Edit: I tested the following and it works on Linux:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i, j;

    puts("char *dummy_data[] = {");
    for (i = 0; i < 5000; i++) {
        fputs("    \"", stdout);
        for (j = 0; j < 1000; j++) putchar('a' + rand() % 26);
        puts("\",");
    }
    puts("};");
    return 0;
}

Both this code and its output compile cleanly.

两人的回忆 2024-10-02 13:56:32

您可以创建大型静态虚拟数据数组。这会增加你的exe文件的大小,但并不是真正的代码。

You can create big static arrays of dummy data. That would bump your exe size, would not be real code though.

夕嗳→ 2024-10-02 13:56:32

我发现即使进行了优化,原始字符串也会按原样保留在编译后的可执行文件中。

所以要走的路是:

  • http://lipsum.org/
  • 生成很多文本
  • ,添加一个 cpp您的程序
  • 添加一个静态常量字符串,它将生成的文本作为值
  • 编译
  • 检查大小。

如果您的编译器对原始字符串大小有限制(?),那么只需为每个静态字符串创建一个段落。

增加的尺寸应该很容易猜到。

I've found that even with optimizations, raw strings are kept as is in the compiled executable file.

So the way to go is :

  • go to http://lipsum.org/
  • generate a lot of text
  • add a cpp in your program
  • add a static const string that will have the generated text as value
  • compile
  • check the size.

If your compiler have a limit of raw string size (?) then just make a paragraph per static string.

The added size should be easy to guess.

一抹微笑 2024-10-02 13:56:32

您可以尝试创建某种递归模板来生成许多不同的实例。这可能会导致代码大小大幅增加。

You could try creating some sort of recursive template that would generate a lot of different instantiations. This could possibly cause a big increase in code size.

骑趴 2024-10-02 13:56:32

使用 Boost 并使用调试信息编译可执行文件。

Use Boost and compile the executable with debug information.

情深已缘浅 2024-10-02 13:56:32

编写一个生成大量代码的程序。

printf("000000000");
printf("000000001");
// ...
printf("010000000");

Write a program that generates a lot of code.

printf("000000000");
printf("000000001");
// ...
printf("010000000");
红墙和绿瓦 2024-10-02 13:56:32

如果一切都失败了,您仍然可以创建一个汇编语言源文件,其中有适当数量的 db 语句,将字节发送到代码段中,并将生成的代码对象作为 链接到您的程序外部“C”{...}

您可能需要使用编译器/链接器来防止链接器优化该虚拟“代码”对象。

If all else fails, you could still create an assembly language source file where you have an appropriate number of db statements emitting bytes into the code segment, and link the resulting code object to your program as extern "C" { ... }.

You might need to play with the compiler/linker to prevent the linker from optimizing away that dummy "code" object.

拥抱影子 2024-10-02 13:56:32

我承认,我是一个 Linux/UNIX 人。是否可以在 Windows 中静态链接可执行文件?然后,您可以引用一些繁重的库并根据需要扩大代码大小,而无需自己编写太多代码。

在阅读您对我的第一个答案的评论时,我思考的另一个想法是在您的文件中附加零。如前所述,我不是 Windows 专家,所以这可能行不通。

I admit, I'm a Linux/UNIX guy. Is it possible to statically link an executable in Windows? You then could reference some heavy libs and blow up your code size as much as you want without writing to much code by yourself.

Another idea I pondered while reading your comment to my first answer is appending zeros to your file. As said, I'm no Windows expert, so this might not work.

挖鼻大婶 2024-10-02 13:56:32

添加 5MB (bmp) 图像。

Add a 5MB (bmp) image.

新一帅帅 2024-10-02 13:56:32

执行此处列出的所有方法后,使用调试标志和最高优化标志 (gcc -g -O3) 进行编译。

After you do all the methods listed here, compile with the debug flag and with the highest optimization flag (gcc -g -O3).

不喜欢何必死缠烂打 2024-10-02 13:56:32

使用 #define 定义大量包含大长度字符串的宏,并在程序中的许多地方使用这些宏。

Use #define to define lots of macros which holds string with huge length, and use those macros inside your program in many places.

多孤肩上扛 2024-10-02 13:56:32

您可以这样做:

REM generate gibberish of the desired size
dd if=/dev/random of=entropy count=5000k bs=1
REM copy the entropy to the end of the file
copy /b someapp.exe + entropy somefatapp.exe

如果它是批处理文件,您甚至可以将其添加为编译后步骤,以便它自动发生。

通常,您可以将任意数量的信息复制到 exe 的末尾。所有代码/资源都存储为从文件开头的偏移量,因此增加其大小不会影响它。

(我假设您在 Windows 中有 dd。如果没有,请获取它)。

You could do this:

REM generate gibberish of the desired size
dd if=/dev/random of=entropy count=5000k bs=1
REM copy the entropy to the end of the file
copy /b someapp.exe + entropy somefatapp.exe

If it were a batch file, you could even add it as a post compilation step so it happened automatically.

You can generally copy as much information as you want to the end of an exe. All the code / resources are stored as offsets from the beginning of the file, so increasing it's size shouldn't affect it.

(I'm assuming you have dd in Windows. If not, get it).

魂ガ小子 2024-10-02 13:56:32

编写一个生成任意随机函数的代码生成器。唯一的技巧是确保它不会被优化,并且单独编译应该不难。

Write a code generator that generates arbitrary random functions. The only trick then is making sure that it doesn't get optimized out and with separate compilation that shouldn't be hard.

够运 2024-10-02 13:56:32

将 wxWidgets 静态链接到您的应用程序。
它会立即变成 5 MB 大。

Statically link wxWidgets to your application.
It will instantly become 5 MB large.

檐上三寸雪 2024-10-02 13:56:31

简单地定义一个大的静态字符数组怎么样?

char const bigarray[5*1024*1024] = { 1 };

另请参阅我在此线程中的其他答案,其中我建议静态链接到大型库。如果您引用足够的库代码,这肯定会引入真实的代码。

编辑:添加了非零初始化,因为编译器/链接器以优化的方式处理仅包含零的数据。

编辑:添加了对我的其他答案的引用。

编辑:添加了 const 限定符,因此 bigarray 将被许多编译器放置在代码中。

What about simply defining a large static char array?

char const bigarray[5*1024*1024] = { 1 };

See also my other answer in this thread where I suggest statically linking to big libraries. This surely will pull in real code if you just reference enough code of the libraries.

EDIT: Added a non-zero initialization, as data containing zeros only is treated in an optimized fashion by the compiler/linker.

EDIT: Added reference to my other answer.

EDIT: Added const qualifier, so bigarray will be placed amongst code by many compilers.

岁吢 2024-10-02 13:56:31
char big[5*1024*1024] = {1};

您需要将其初始化为 0 以外的值,否则编译器/链接器可能会对其进行优化。

char big[5*1024*1024] = {1};

You need to initialize it to something other than 0 or the compiler/linker may optimize it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文