SImple C++ code to D
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 13 19:23:58 PDT 2014
Alexandre:
> When the PE file is generate in EXE have just the "M" of "MZ"...
Let's try again, is this better?
import std.c.windows.windows: WORD, LONG;
struct IMAGE_DOS_HEADER {
WORD e_magic = ('M' << 8) + 'Z',
e_cblp,
e_cp,
e_crlc,
e_cparhdr,
e_minalloc,
e_maxalloc,
e_ss,
e_sp,
e_csum,
e_ip,
e_cs,
e_lfarlc,
e_ovno;
WORD[4] e_res;
WORD e_oemid,
e_oeminfo;
WORD[10] e_res2;
LONG e_lfanew;
}
alias PIMAGE_DOS_HEADER = IMAGE_DOS_HEADER*;
__gshared ubyte[0x800] image;
void main() {
import std.stdio;
import core.stdc.string;
auto dosh = cast(PIMAGE_DOS_HEADER)image.ptr;
immutable stub = x"b8 01 4c cd 21";
memcpy(&image[IMAGE_DOS_HEADER.sizeof],
stub.ptr, stub.length);
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list