Skip to content

Instantly share code, notes, and snippets.

@kosta
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosta/6a17365c71ca88031740 to your computer and use it in GitHub Desktop.
Save kosta/6a17365c71ca88031740 to your computer and use it in GitHub Desktop.
Empty Win32 MessageBox using rust no_std
This generates a win 32bit exe with of ~48 KB (~35 KB after upx compression). Tested with rust nightly of May 16th 2015
https://static.rust-lang.org/dist/2015-05-16/rust-nightly-i686-pc-windows-gnu.msi
Command line:
cargo clean && cargo build -v --release
Cargo.toml:
[package]
name = "msgbox"
version = "0.1.0"
authors = ["kosta"]
[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
src/main.rs:
#![feature(lang_items, start, no_std, core, libc)]
#![no_std]
// Pull in the system libc library for what crt0.o likely requires
extern crate libc;
extern crate core;
use core::ptr;
// These functions and traits are used by the compiler, but not
// for a bare-bones hello world. These are normally
// provided by libstd.
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
mod ffi {
extern "stdcall" {
pub fn MessageBoxW(
hWnd: *const (),
lpText: *const u16,
lpCaption: *const u16,
uType: u32
) -> i32;
}
}
// Entry point for this program
#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
unsafe {
ffi::MessageBoxW(
ptr::null(),
ptr::null(),
ptr::null(),
0);
}
0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment