HelloAssembly 最精简的完整 Windows 应用程序
HelloAssembly The smallest possible complete Windows application

原始链接: https://github.com/PlummersSoftwareLLC/HelloAssembly

该项目曾在 *Dave’s Garage* 节目中展示,旨在探索使用 x86 汇编语言创建全球最小功能性 Windows 应用程序的技术挑战。其目标是构建一个合法的窗口化应用程序(具备消息循环、标题栏和系统菜单),并在不使用传统压缩的前提下尽可能减小文件体积。 该仓库提供了几种实现方案: * **TinyOriginal**:一个经过优化的汇编版本。 * **Lasse**:一个利用激进 Shellcode 技术的版本。 * **Theron**:一个通过手动构建 PE 头以实现极致效率的版本。 由于这些激进的优化技术与恶意软件所使用的方法类似,杀毒软件可能会将生成的可执行文件标记为威胁。该仓库明确提醒用户,运行这些文件时可能需要将其加入白名单或暂时禁用安全软件。 项目中提供了多种构建方法,涵盖了从标准的 MASM32 汇编到使用专用压缩链接器 *Crinkler* 以及 *Yasm*。截至 2023 年末,实现的最小版本为“Theron”目录下的 383 字节版本。建议用户仔细研读代码中的注释,以了解如何将 Windows 可执行文件精简至其最基础的功能需求。

Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 HelloAssembly:Windows 下最小的完整应用程序 (github.com/plummerssoftwarellc) 9 分,由 Bluestein 发布于 49 分钟前 | 隐藏 | 过往 | 收藏 | 2 条评论 帮助 eggy 0 分钟前 | 下一条 [–] 我应该试试 FASM,看看它能不能生成体积更小的 exe。COM 文件确实很小,但 16 位 DOS 是过去的事了——100H,基本上就是一个内存转储。 回复 taf2 10 分钟前 | 上一条 [–] 很喜欢这个,而且正当其时,因为我觉得随着 AI 的发展,我会有更多的代码直接使用原生汇编,例如:https://github.com/taf2/tic-tac-toe,这是我基于 M 系列原生汇编的井字棋窗口游戏…… 非常便携,你只需要执行 codex --yolo 将我的应用移植到 x y z 主机…… 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 加入 YC | 联系 搜索:
相关文章

原文

The smallest possible complete Windows application.

From the episode "Hello, Assembly! Retrocoding the World's Smallest Windows App in x86 ASM" on Dave's Garage:
Hello, Assembly! Retrocoding the World's Smallest Windows App in x86 ASM

And the follow-up episode "C vs ASM: Making the World's SMALLEST Windows App":
C vs ASM: Making the World's SMALLEST Windows App

Code in the repository:

  • Optimized version of the original code is in the folder "TinyOriginal"
  • Version applying shell coding tactics is in the folder "Lasse"
  • Version using a manually written PE header is in the folder "Theron"
  • QRCode is dead code, was the exe embedded into a QRCode, kept just for posterity

The goal of this project is to make the smallest possible application, without compression, that has the following features:

  • Runs a Windows message loop
  • Has a title bar, minimize, maximize, and close buttons, which all work as expected
  • Has a system menu with the same
  • Paints the background and some text centered in the middle, equal to or larger than "Dave's Tiny App"

Please keep it readable and explain what you're doing in the comments! And the smaller, the better!

The optimizations embedded in the current code in the Lasse directory, and those applied by Crinkler in general (if used) are rather aggressive, and seem to resemble strategies applied by certain types of malware. Because of this, your virus scanner may flag the executables you build out of the source code as "suspected malware". That can make it impossible to start them, or your virus scanner can even put them in quarantine. Depending on the antivirus solution you use, you may be able to whitelist/exclude the executables to restore them and get them to work (this is known to happen with F-Secure SAFE). It's also possible that you have to temporarily disable your virus scanner altogether (which has been observed with Microsoft Defender).

Please note:

  • It is entirely your responsibility to decide if you want to disable your virus scanner or not.
  • If you do temporarily disable your virus scanner, we strongly recommend you re-enable it immediately after you test the executables you build out of this repository's code.
  • Although we do promise that this repository does not contain any malicious code, we cannot guarantee that this is true for any code or executables (like supposed builds of this repository's applications) that you get from other sources.

If your virus scanner intervenes when you try to run the executables that come out of this repository's source code, and you don't feel comfortable with (partly) disabling your virus scanner, then don't do it. We do understand and we really won't hold it against you. :)

The code in the Lasse directory can be built with plain MASM32 11.0, which can be obtained from a number of sources. Build instructions using it are:

ml /coff LittleWindows.asm /link /merge:.rdata=.text /merge:.data=.text /align:4 /subsystem:windows LittleWindows.obj

The executable will be named LittleWindows.exe.

Crinkler is a compressing linker for Windows, specifically targeted towards executables with a size of just a few kilobytes. A copy of the tool is included in this repository in the Crinkler directory. It can also be acquired from its GitHub repository.

Crinkler requires the Windows SDK to be installed. Best (i.e. smallest) results have been achieved with version 10.0.20348.0 of the Windows 10 SDK. It, and other versions can be downloaded from the Windows SDK archive page on the Microsoft website.

After installing it, the build instructions for the applications that can be built using it are:

  • Code in the Lasse directory:

    ml /c /coff LittleWindows.asm
    crinkler.exe /NODEFAULTLIB /ENTRY:start /SUBSYSTEM:WINDOWS /TINYHEADER /NOINITIALIZERS /UNSAFEIMPORT /ORDERTRIES:1000 /TINYIMPORT /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\um\x86" kernel32.lib LittleWindows.obj

    The executable will be named out.exe.

  • Code in the TinyOriginal directory:

    ml /c /coff /IC:\masm32\include Tiny.asm 
    crinkler.exe /ENTRY:MainEntry /SUBSYSTEM:WINDOWS /TINYHEADER /NOINITIALIZERS /UNSAFEIMPORT /ORDERTRIES:2000 /TINYIMPORT /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\um\x86" kernel32.lib user32.lib gdi32.lib Tiny.obj /OUT:tiny.exe

    The executable will be named tiny.exe.

The code in the Theron directory has to be built with Yasm, which is a rewrite of the NASM assembler under the "new" BSD license. It can be acquired from the Yasm project download page; choose the version "for general use". The assembler is assumed to be renamed to yasm.exe. Build instructions using it are:

yasm -fbin -o HelloWindows.exe HelloWindows.asm

The executable will be named HelloWindows.exe.

Current smallest known working executable sizes as of 03/11/2023 are as follows:

Program Linker Size in bytes
Lasse\LittleWindows.asm MASM32 1104
Lasse\LittleWindows.asm Crinkler 818
Theron\HelloWindows.asm Yasm 383
TinyOriginal\Tiny.asm Crinkler 540
联系我们 contact @ memedata.com