portable executableimage files, i.e. applications and DLLs, can’t be replaced or updated.
Create the text file myth.c
with the following content
in an arbitrary, preferable empty directory:
// Copyright © 2004-2025, Stefan Kanthak <stefan.kanthak@nexgo.de>
#define STRICT
#define UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#ifdef _DLL
__declspec(safebuffers)
BOOL WINAPI _DllMainCRTStartup(HMODULE hModule, DWORD dwReason, CONTEXT *lpContext)
{
WCHAR szBuffer[MAX_PATH];
WCHAR szModule[MAX_PATH];
WCHAR szProcess[MAX_PATH];
if ((dwReason != DLL_PROCESS_ATTACH)
|| (GetModuleFileName((HMODULE) NULL, szProcess, sizeof(szProcess) / sizeof(*szProcess)) == 0)
|| (GetModuleFileName(hModule, szModule, sizeof(szModule) / sizeof(*szModule)) == 0)
|| (GetTempPath(sizeof(szBuffer) / sizeof(*szBuffer), szBuffer) == 0)
|| (GetTempFileName(szBuffer, L"dll", 0, szBuffer) == 0)
#ifdef MYTHS
|| !DeleteFile(szBuffer)
|| !MoveFile(szModule, szBuffer)
|| !CopyFile(szProcess, szModule, FALSE))
#else
|| !MoveFileEx(szModule, szBuffer, MOVEFILE_REPLACE_EXISTING)
|| !MoveFileEx(szProcess, szModule, MOVEFILE_CREATE_HARDLINK))
#endif
return FALSE;
return TRUE;
}
__declspec(dllexport)
const WCHAR szConsole[] = L"com";
__declspec(dllexport)
const WCHAR szWindows[] = L"exe";
#else // _DLL
#ifndef CONSOLE
__declspec(dllimport)
extern WCHAR szWindows[];
__declspec(noreturn)
VOID CDECL wWinMainCRTStartup(VOID)
{
WCHAR szBuffer[MAX_PATH];
WCHAR szProcess[MAX_PATH];
if ((GetModuleFileName((HMODULE) NULL, szProcess, sizeof(szProcess) / sizeof(*szProcess)) == 0)
|| (GetTempPath(sizeof(szBuffer) / sizeof(*szBuffer), szBuffer) == 0)
|| (GetTempFileName(szBuffer, szWindows, 0, szBuffer) == 0)
|| !DeleteFile(szBuffer)
|| !MoveFile(szProcess, szBuffer))
ExitProcess(GetLastError());
ExitProcess(ERROR_SUCCESS);
}
#else // CONSOLE
__declspec(dllimport)
extern WCHAR szConsole[];
__declspec(safebuffers)
BOOL CDECL PrintConsole(HANDLE hConsole, [SA_FormatString(Style="printf")] LPCWSTR lpFormat, ...)
{
WCHAR szOutput[1024];
DWORD dwOutput;
DWORD dwConsole;
va_list vaInput;
va_start(vaInput, lpFormat);
dwOutput = wvsprintf(szOutput, lpFormat, vaInput);
va_end(vaInput);
if (dwOutput == 0)
return FALSE;
if (!WriteConsole(hConsole, szOutput, dwOutput, &dwConsole, NULL))
return FALSE;
return dwConsole == dwOutput;
}
__declspec(noreturn)
VOID CDECL wmainCRTStartup(VOID)
{
WCHAR szProcess[MAX_PATH];
DWORD dwProcess;
WCHAR szBuffer[MAX_PATH];
DWORD dwBuffer;
DWORD dwError = ERROR_SUCCESS;
HANDLE hConsole = GetStdHandle(STD_ERROR_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE)
dwError = GetLastError();
else
{
dwProcess = GetModuleFileName((HMODULE) NULL,
szProcess,
sizeof(szProcess) / sizeof(*szProcess));
if (dwProcess == 0)
PrintConsole(hConsole,
L"GetModuleFileName() returned error %lu\n",
dwError = GetLastError());
else
{
dwBuffer = GetTempPath(sizeof(szBuffer) / sizeof(*szBuffer),
szBuffer);
if (dwBuffer == 0)
PrintConsole(hConsole,
L"GetTempPath() returned error %lu\n",
dwError = GetLastError());
else
if (GetTempFileName(szBuffer, szConsole, 0, szBuffer) == 0)
PrintConsole(hConsole,
L"GetTempFileName() returned error %lu\n",
dwError = GetLastError());
else
if (!DeleteFile(szBuffer))
PrintConsole(hConsole,
L"DeleteFile() returned error %lu\n",
dwError = GetLastError());
else
if (!MoveFile(szProcess, szBuffer))
PrintConsole(hConsole,
L"MoveFile() returned error %lu\n",
dwError = GetLastError());
}
if (!CloseHandle(hConsole))
PrintConsole(hConsole,
L"CloseHandle() returned error %lu\n",
GetLastError());
}
ExitProcess(dwError);
}
#endif // CONSOLE
#endif // _DLL
Build the
DLL
myth.dll
and its import library
myth.lib
from the source file myth.c
created in step 1., then build the Windows
application myth.exe
and the console application
myth.com
, linking both with the import library
myth.lib
:
SET CL=/GAFy /Osy /W4 /Zl SET LINK=/NODEFAULTLIB CL.EXE /LD /MD myth.c kernel32.lib SET LINK=/ENTRY:wWinMainCRTStartup /NODEFAULTLIB /SUBSYSTEM:Windows CL.EXE myth.c myth.lib kernel32.lib SET LINK=/ENTRY:wmainCRTStartup /NODEFAULTLIB /SUBSYSTEM:Console CL.EXE /DCONSOLE /Femyth.com myth.c myth.lib kernel32.lib user32.libFor details and reference see the MSDN articles Compiler Options and Linker Options.
Note: if necessary, see the MSDN article Use the Microsoft C++ toolset from the command line for an introduction.
Note: myth.dll
, myth.exe
and myth.com
are pure Win32 executables and
build without the
MSVCRT
libraries.
Note: the command lines can be copied and pasted as block into a Command Processor window.
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. myth.c myth.c(11) : warning C4100: 'lpContext' : unreferenced formal parameter Microsoft (R) Incremental Linker Version 10.00.40219.386 Copyright (C) Microsoft Corporation. All rights reserved. /NODEFAULTLIB /out:myth.dll /dll /implib:myth.lib myth.obj kernel32.lib Creating library myth.lib and object myth.exp Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. myth.c Microsoft (R) Incremental Linker Version 10.00.40219.386 Copyright (C) Microsoft Corporation. All rights reserved. /ENTRY:wWinMainCRTStartup /NODEFAULTLIB /SUBSYSTEM:Windows /out:myth.exe myth.obj myth.lib kernel32.lib Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. myth.c Microsoft (R) Incremental Linker Version 10.00.40219.386 Copyright (C) Microsoft Corporation. All rights reserved. /ENTRY:wmainCRTStartup /NODEFAULTLIB /SUBSYSTEM:Console /out:myth.com myth.obj myth.lib kernel32.lib user32.lib
Execute the console application myth.com
together with
its statically linked myth.dll
built in step 2.
and display its exit code:
.\myth.com ECHO %ERRORLEVEL%
0
Verify that the console application myth.com
has moved
itself as com‹4 random characters›.tmp
into your TMP
directory, that the
DLL
myth.dll
has also moved itself as
dll‹4 random characters›.tmp
there and
replaced itself with its caller myth.com
, then
restore them both:
DIR myth.* DIR "%TMP%\com????.tmp" "%TMP%\dll????.tmp" FC.EXE /B "%TMP%\com????.tmp" myth.dll MOVE /Y "%TMP%\dll????.tmp" myth.dll MOVE "%TMP%\com????.tmp" myth.com
Volume in drive C has no label. Volume Serial Number is 1957-0427 Directory of C:\Users\Stefan\Desktop 04/27/2010 08:15 PM 3.962 myth.c 04/27/2010 08:15 PM 3.584 myth.dll 04/27/2010 08:15 PM 2.560 myth.exe 04/27/2010 08:15 PM 691 myth.exp 04/27/2010 08:15 PM 1.784 myth.lib 04/27/2010 08:15 PM 4.004 myth.obj 6 File(s) 16.585 bytes 0 Dir(s) 9,876,543,210 bytes free Volume in drive C has no label. Volume Serial Number is 1957-0427 Directory of C:\Users\Stefan\AppData\Local\Temp 04/27/2010 08:15 PM 2.560 dll4707.tmp Directory of C:\Users\Stefan\AppData\Local\Temp 04/27/2010 08:15 PM 3.584 com4711.tmp 2 File(s) 6.144 bytes 0 Dir(s) 9,876,543,210 bytes free Compare the files C:\USERS\STEFAN\APPDATA\LOCAL\TEMP\com4711.tmp and MYTH.DLL FC: no differences found 1 file(s) moved. 1 file(s) moved.
Create the text file myth.txt
with the following content
in an arbitrary, preferable empty directory:
4d 5a 90 00 01 00 00 00 04 00 00 00 ff ff 00 00 MZ..............
e0 00 00 00 43 00 00 00 40 00 00 00 00 00 00 00 ....C...@.......
00 00 00 00 19 57 04 27 00 00 00 00 00 00 00 00 .....W.'........
00 00 00 00 00 00 00 00 00 00 00 00 90 00 00 00 ................
28 43 29 6f 70 79 72 69 67 68 74 20 32 30 30 34 (C)opyright 2004
2d 32 30 32 35 2c 20 53 74 65 66 61 6e 20 4b 61 -2025, Stefan Ka
6e 74 68 61 6b 20 3c 73 74 65 66 61 6e 2e 6b 61 nthak <stefan.ka
6e 74 68 61 6b 40 6e 65 78 67 6f 2e 64 65 3e 0d nthak@nexgo.de>.
0a 07 24 0e 1f 33 d2 b4 09 cd 21 b8 01 4c cd 21 ..$..3....!..L.!
50 45 00 00 4c 01 03 00 56 4f 49 44 00 00 00 00 PE..L...VOID....
00 00 00 00 e0 00 22 2d 0b 01 0a 00 00 02 00 00 ......"-........
00 04 00 00 00 00 00 00 00 10 00 00 00 10 00 00 ................
00 20 00 00 00 00 00 10 00 10 00 00 00 02 00 00 . ..............
04 00 00 00 00 00 2f 03 04 00 00 00 00 00 00 00 ....../.........
00 40 00 00 00 02 00 00 65 78 00 00 02 00 40 05 .@......ex....@.
00 00 10 00 00 10 00 00 00 00 10 00 00 10 00 00 ................
00 00 00 00 10 00 00 00 c0 20 00 00 59 00 00 00 ......... ..Y...
2c 20 00 00 28 00 00 00 00 00 00 00 00 00 00 00 , ..(...........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 30 00 00 14 00 00 00 00 00 00 00 00 00 00 00 .0..............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 20 00 00 14 00 00 00 ......... ......
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 2e 63 6f 64 65 00 00 00 .........code...
ab 00 00 00 00 10 00 00 00 02 00 00 00 02 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 60 ............ ..`
2e 63 6f 6e 73 74 00 00 19 01 00 00 00 20 00 00 .const....... ..
00 02 00 00 00 04 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 40 00 00 40 2e 72 65 6c 6f 63 00 00 ....@..@.reloc..
14 00 00 00 00 30 00 00 00 02 00 00 00 06 00 00 .....0..........
00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 42 ............@..B
55 8b ec 81 ec 18 06 00 00 83 7d 0c 01 56 57 0f U.........}..VW.
85 8e 00 00 00 8b 3d 08 20 00 10 be 04 01 00 00 ......=. .......
56 8d 85 e8 f9 ff ff 50 6a 00 ff d7 85 c0 74 73 V......Pj.....ts
56 8d 85 f0 fb ff ff 50 ff 75 08 ff d7 85 c0 74 V......P.u.....t
62 8d 85 f8 fd ff ff 50 56 ff 15 04 20 00 10 85 b......PV... ...
c0 74 50 8d 85 f8 fd ff ff 50 6a 00 68 24 20 00 .tP......Pj.h$ .
10 50 ff 15 00 20 00 10 85 c0 74 37 8b 35 0c 20 .P... ....t7.5.
00 10 6a 01 8d 85 f8 fd ff ff 50 8d 85 f0 fb ff ..j.......P.....
ff 50 ff d6 85 c0 74 1b 6a 10 8d 85 f0 fb ff ff .P....t.j.......
50 8d 85 e8 f9 ff ff 50 ff d6 85 c0 74 05 33 c0 P......P....t.3.
40 eb 02 33 c0 5f 5e c9 c2 0c 00 00 00 00 00 00 @..3._^.........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
76 20 00 00 8a 20 00 00 9a 20 00 00 68 20 00 00 v ... ... ..h ..
00 00 00 00 63 00 6f 00 6d 00 00 00 65 00 78 00 ....c.o.m...e.x.
65 00 00 00 64 00 6c 00 6c 00 00 00 54 20 00 00 e...d.l.l...T ..
00 00 00 00 00 00 00 00 b0 20 00 00 00 20 00 00 ......... ... ..
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 76 20 00 00 8a 20 00 00 9a 20 00 00 ....v ... ... ..
68 20 00 00 00 00 00 00 60 03 4d 6f 76 65 46 69 h ......`.MoveFi
6c 65 45 78 57 00 83 02 47 65 74 54 65 6d 70 46 leExW...GetTempF
69 6c 65 4e 61 6d 65 57 00 00 85 02 47 65 74 54 ileNameW....GetT
65 6d 70 50 61 74 68 57 00 00 14 02 47 65 74 4d empPathW....GetM
6f 64 75 6c 65 46 69 6c 65 4e 61 6d 65 57 00 00 oduleFileNameW..
4b 45 52 4e 45 4c 33 32 2e 64 6c 6c 00 00 00 00 KERNEL32.dll....
00 00 00 00 ff ff ff ff 00 00 00 00 fc 20 00 00 ............. ..
01 00 00 00 02 00 00 00 02 00 00 00 e8 20 00 00 ............. ..
f0 20 00 00 f8 20 00 00 14 20 00 00 1c 20 00 00 . ... ... ... ..
05 21 00 00 0f 21 00 00 00 00 01 00 6d 79 74 68 .!...!......myth
2e 64 6c 6c 00 73 7a 43 6f 6e 73 6f 6c 65 00 73 .dll.szConsole.s
7a 57 69 6e 64 6f 77 73 00 00 00 00 00 00 00 00 zWindows........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 10 00 00 14 00 00 00 17 30 4b 30 5d 30 64 30 .........0K0]0d0
6e 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 n0..............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Decode the dump file myth.txt
created in
step 5. to recreate the
DLL
myth.dll
:
CERTUTIL.EXE /DecodeHex myth.txt myth.dll
Input Length = 8704 Output Length = 2048 CertUtil: -decodehex command completed successfully.
Overwrite the text file myth.txt
with the following
content:
4d 5a 90 00 01 00 00 00 04 00 00 00 ff ff 00 00 MZ..............
e0 00 00 00 43 00 00 00 40 00 00 00 00 00 00 00 ....C...@.......
00 00 00 00 19 57 04 27 00 00 00 00 00 00 00 00 .....W.'........
00 00 00 00 00 00 00 00 00 00 00 00 90 00 00 00 ................
28 43 29 6f 70 79 72 69 67 68 74 20 32 30 30 34 (C)opyright 2004
2d 32 30 32 35 2c 20 53 74 65 66 61 6e 20 4b 61 -2025, Stefan Ka
6e 74 68 61 6b 20 3c 73 74 65 66 61 6e 2e 6b 61 nthak <stefan.ka
6e 74 68 61 6b 40 6e 65 78 67 6f 2e 64 65 3e 0d nthak@nexgo.de>.
0a 07 24 0e 1f 33 d2 b4 09 cd 21 b8 01 4c cd 21 ..$..3....!..L.!
50 45 00 00 4c 01 02 00 56 4f 49 44 00 00 00 00 PE..L...VOID....
00 00 00 00 e0 00 23 0d 0b 01 0a 00 00 02 00 00 ......#.........
00 02 00 00 00 00 00 00 00 10 00 00 00 10 00 00 ................
00 20 00 00 00 00 40 00 00 10 00 00 00 02 00 00 . ....@.........
04 00 00 00 00 00 2f 03 04 00 00 00 00 00 00 00 ....../.........
00 30 00 00 00 02 00 00 1d 12 00 00 02 00 00 85 .0..............
00 00 10 00 00 10 00 00 00 00 10 00 00 10 00 00 ................
00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 ................
28 20 00 00 3c 00 00 00 00 00 00 00 00 00 00 00 ( ..<...........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 20 00 00 28 00 00 00 ......... ..(...
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 2e 63 6f 64 65 00 00 00 .........code...
89 00 00 00 00 10 00 00 00 02 00 00 00 02 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 60 ............ ..`
2e 63 6f 6e 73 74 00 00 22 01 00 00 00 20 00 00 .const..".... ..
00 02 00 00 00 04 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 40 00 00 40 00 00 00 00 00 00 00 00 ....@..@........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
55 8b ec 81 ec 10 04 00 00 56 be 04 01 00 00 56 U........V.....V
8d 85 f0 fb ff ff 50 6a 00 ff 15 04 20 40 00 85 ......Pj.... @..
c0 74 5d 8d 85 f8 fd ff ff 50 56 ff 15 18 20 40 .t]......PV... @
00 85 c0 74 4b 8d 85 f8 fd ff ff 50 6a 00 ff 35 ...tK......Pj..5
20 20 40 00 50 ff 15 14 20 40 00 85 c0 74 31 8d @.P... @...t1.
85 f8 fd ff ff 50 ff 15 00 20 40 00 85 c0 74 20 .....P... @...t
8d 85 f8 fd ff ff 50 8d 85 f0 fb ff ff 50 ff 15 ......P......P..
10 20 40 00 85 c0 74 08 6a 00 ff 15 0c 20 40 00 . @...t.j.... @.
ff 15 08 20 40 00 50 eb f1 00 00 00 00 00 00 00 ... @.P.........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
cc 20 00 00 fe 20 00 00 a2 20 00 00 b2 20 00 00 . ... ... ... ..
c0 20 00 00 da 20 00 00 ee 20 00 00 00 00 00 00 . ... ... ......
8c 20 00 00 00 00 00 00 84 20 00 00 00 00 00 00 . ....... ......
00 00 00 00 98 20 00 00 20 20 00 00 64 20 00 00 ..... .. ..d ..
00 00 00 00 00 00 00 00 14 21 00 00 00 20 00 00 .........!... ..
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 cc 20 00 00 fe 20 00 00 a2 20 00 00 ..... ... ... ..
b2 20 00 00 c0 20 00 00 da 20 00 00 ee 20 00 00 . ... ... ... ..
00 00 00 00 8c 20 00 00 00 00 00 00 01 00 73 7a ..... ........sz
57 69 6e 64 6f 77 73 00 6d 79 74 68 2e 64 6c 6c Windows.myth.dll
00 00 02 02 47 65 74 4c 61 73 74 45 72 72 6f 72 ....GetLastError
00 00 19 01 45 78 69 74 50 72 6f 63 65 73 73 00 ....ExitProcess.
63 03 4d 6f 76 65 46 69 6c 65 57 00 d6 00 44 65 c.MoveFileW...De
6c 65 74 65 46 69 6c 65 57 00 83 02 47 65 74 54 leteFileW...GetT
65 6d 70 46 69 6c 65 4e 61 6d 65 57 00 00 85 02 empFileNameW....
47 65 74 54 65 6d 70 50 61 74 68 57 00 00 14 02 GetTempPathW....
47 65 74 4d 6f 64 75 6c 65 46 69 6c 65 4e 61 6d GetModuleFileNam
65 57 00 00 4b 45 52 4e 45 4c 33 32 2e 64 6c 6c eW..KERNEL32.dll
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Decode the dump file myth.txt
created in
step 7. to recreate the Windows application
myth.exe
:
CERTUTIL.EXE /DecodeHex myth.txt myth.exe
Input Length = 6528 Output Length = 1536 CertUtil: -decodehex command completed successfully.
Overwrite the text file myth.txt
with the following
content:
4d 5a 90 00 01 00 00 00 04 00 00 00 ff ff 00 00 MZ..............
e0 00 00 00 43 00 00 00 40 00 00 00 00 00 00 00 ....C...@.......
00 00 00 00 19 57 04 27 00 00 00 00 00 00 00 00 .....W.'........
00 00 00 00 00 00 00 00 00 00 00 00 90 00 00 00 ................
28 43 29 6f 70 79 72 69 67 68 74 20 32 30 30 34 (C)opyright 2004
2d 32 30 32 35 2c 20 53 74 65 66 61 6e 20 4b 61 -2025, Stefan Ka
6e 74 68 61 6b 20 3c 73 74 65 66 61 6e 2e 6b 61 nthak <stefan.ka
6e 74 68 61 6b 40 6e 65 78 67 6f 2e 64 65 3e 0d nthak@nexgo.de>.
0a 07 24 0e 1f 33 d2 b4 09 cd 21 b8 01 4c cd 21 ..$..3....!..L.!
50 45 00 00 4c 01 02 00 56 4f 49 44 00 00 00 00 PE..L...VOID....
00 00 00 00 e0 00 23 0d 0b 01 0a 00 00 02 00 00 ......#.........
00 04 00 00 00 00 00 00 4e 10 00 00 00 10 00 00 ........N.......
00 20 00 00 00 00 40 00 00 10 00 00 00 02 00 00 . ....@.........
04 00 00 00 00 00 2f 03 04 00 00 00 00 00 00 00 ....../.........
00 30 00 00 00 02 00 00 d2 58 00 00 03 00 00 85 .0.......X......
00 00 10 00 00 10 00 00 00 00 10 00 00 10 00 00 ................
00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 ................
f8 21 00 00 50 00 00 00 00 00 00 00 00 00 00 00 .!..P...........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 20 00 00 3c 00 00 00 ......... ..<...
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 2e 63 6f 64 65 00 00 00 .........code...
58 01 00 00 00 10 00 00 00 02 00 00 00 02 00 00 X...............
00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 60 ............ ..`
2e 63 6f 6e 73 74 00 00 62 03 00 00 00 20 00 00 .const..b.... ..
00 04 00 00 00 04 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 40 00 00 40 00 00 00 00 00 00 00 00 ....@..@........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
55 8b ec 81 ec 04 08 00 00 56 8d 45 10 50 ff 75 U........V.E.P.u
0c 8d 85 fc f7 ff ff 50 ff 15 2c 20 40 00 8b f0 .......P.., @...
85 f6 75 04 33 c0 eb 23 6a 00 8d 45 fc 50 56 8d ..u.3..#j..E.PV.
85 fc f7 ff ff 50 ff 75 08 ff 15 08 20 40 00 85 .....P.u.... @..
c0 74 e1 33 c0 39 75 fc 0f 94 c0 5e c9 c3 55 8b .t.3.9u....^..U.
ec 81 ec 10 04 00 00 53 56 57 6a f4 33 ff ff 15 .......SVWj.3...
04 20 40 00 8b d8 83 fb ff 75 0d ff 15 1c 20 40 . @......u.... @
00 8b f8 e9 d8 00 00 00 68 04 01 00 00 8d 85 f0 ........h.......
fb ff ff 50 57 ff 15 24 20 40 00 8b 35 1c 20 40 ...PW..$ @..5. @
00 85 c0 75 0f ff d6 8b f8 57 68 a8 21 40 00 e9 ...u.....Wh.!@..
87 00 00 00 8d 85 f8 fd ff ff 50 68 04 01 00 00 ..........Ph....
ff 15 20 20 40 00 85 c0 75 0c ff d6 8b f8 57 68 .. @...u.....Wh
60 21 40 00 eb 65 8d 85 f8 fd ff ff 50 6a 00 ff `!@..e......Pj..
35 34 20 40 00 50 ff 15 00 20 40 00 85 c0 75 0c 54 @.P... @...u.
ff d6 8b f8 57 68 10 21 40 00 eb 3f 8d 85 f8 fd ....Wh.!@..?....
ff ff 50 ff 15 18 20 40 00 85 c0 75 0c ff d6 8b ..P... @...u....
f8 57 68 c8 20 40 00 eb 22 8d 85 f8 fd ff ff 50 .Wh. @.."......P
8d 85 f0 fb ff ff 50 ff 15 14 20 40 00 85 c0 75 ......P... @...u
13 ff d6 8b f8 57 68 84 20 40 00 53 e8 cf fe ff .....Wh. @.S....
ff 83 c4 0c 53 ff 15 10 20 40 00 85 c0 75 11 ff ....S... @...u..
d6 50 68 40 20 40 00 53 e8 b3 fe ff ff 83 c4 0c .Ph@ @.S........
57 ff 15 0c 20 40 00 cc 00 00 00 00 00 00 00 00 W... @..........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0 22 00 00 2a 23 00 00 9a 22 00 00 aa 22 00 00 ."..*#..."..."..
b8 22 00 00 c6 22 00 00 d2 22 00 00 1a 23 00 00 ."..."..."...#..
f4 22 00 00 04 23 00 00 00 00 00 00 48 23 00 00 ."...#......H#..
00 00 00 00 84 22 00 00 00 00 00 00 00 00 00 00 ....."..........
43 00 6c 00 6f 00 73 00 65 00 48 00 61 00 6e 00 C.l.o.s.e.H.a.n.
64 00 6c 00 65 00 28 00 29 00 20 00 72 00 65 00 d.l.e.(.). .r.e.
74 00 75 00 72 00 6e 00 65 00 64 00 20 00 65 00 t.u.r.n.e.d. .e.
72 00 72 00 6f 00 72 00 20 00 25 00 6c 00 75 00 r.r.o.r. .%.l.u.
0a 00 00 00 4d 00 6f 00 76 00 65 00 46 00 69 00 ....M.o.v.e.F.i.
6c 00 65 00 28 00 29 00 20 00 72 00 65 00 74 00 l.e.(.). .r.e.t.
75 00 72 00 6e 00 65 00 64 00 20 00 65 00 72 00 u.r.n.e.d. .e.r.
72 00 6f 00 72 00 20 00 25 00 6c 00 75 00 0a 00 r.o.r. .%.l.u...
00 00 00 00 00 00 00 00 44 00 65 00 6c 00 65 00 ........D.e.l.e.
74 00 65 00 46 00 69 00 6c 00 65 00 28 00 29 00 t.e.F.i.l.e.(.).
20 00 72 00 65 00 74 00 75 00 72 00 6e 00 65 00 .r.e.t.u.r.n.e.
64 00 20 00 65 00 72 00 72 00 6f 00 72 00 20 00 d. .e.r.r.o.r. .
25 00 6c 00 75 00 0a 00 00 00 00 00 00 00 00 00 %.l.u...........
47 00 65 00 74 00 54 00 65 00 6d 00 70 00 46 00 G.e.t.T.e.m.p.F.
69 00 6c 00 65 00 4e 00 61 00 6d 00 65 00 28 00 i.l.e.N.a.m.e.(.
29 00 20 00 72 00 65 00 74 00 75 00 72 00 6e 00 ). .r.e.t.u.r.n.
65 00 64 00 20 00 65 00 72 00 72 00 6f 00 72 00 e.d. .e.r.r.o.r.
20 00 25 00 6c 00 75 00 0a 00 00 00 00 00 00 00 .%.l.u.........
47 00 65 00 74 00 54 00 65 00 6d 00 70 00 50 00 G.e.t.T.e.m.p.P.
61 00 74 00 68 00 28 00 29 00 20 00 72 00 65 00 a.t.h.(.). .r.e.
74 00 75 00 72 00 6e 00 65 00 64 00 20 00 65 00 t.u.r.n.e.d. .e.
72 00 72 00 6f 00 72 00 20 00 25 00 6c 00 75 00 r.r.o.r. .%.l.u.
0a 00 00 00 00 00 00 00 47 00 65 00 74 00 4d 00 ........G.e.t.M.
6f 00 64 00 75 00 6c 00 65 00 46 00 69 00 6c 00 o.d.u.l.e.F.i.l.
65 00 4e 00 61 00 6d 00 65 00 28 00 29 00 20 00 e.N.a.m.e.(.). .
72 00 65 00 74 00 75 00 72 00 6e 00 65 00 64 00 r.e.t.u.r.n.e.d.
20 00 65 00 72 00 72 00 6f 00 72 00 20 00 25 00 .e.r.r.o.r. .%.
6c 00 75 00 0a 00 00 00 7c 22 00 00 00 00 00 00 l.u.....|"......
00 00 00 00 90 22 00 00 34 20 00 00 48 22 00 00 ....."..4 ..H"..
00 00 00 00 00 00 00 00 3a 23 00 00 00 20 00 00 ........:#... ..
74 22 00 00 00 00 00 00 00 00 00 00 56 23 00 00 t"..........V#..
2c 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 , ..............
00 00 00 00 00 00 00 00 e0 22 00 00 2a 23 00 00 ........."..*#..
9a 22 00 00 aa 22 00 00 b8 22 00 00 c6 22 00 00 ."..."..."..."..
d2 22 00 00 1a 23 00 00 f4 22 00 00 04 23 00 00 ."...#..."...#..
00 00 00 00 48 23 00 00 00 00 00 00 84 22 00 00 ....H#......."..
00 00 00 00 00 00 73 7a 43 6f 6e 73 6f 6c 65 00 ......szConsole.
6d 79 74 68 2e 64 6c 6c 00 00 24 05 57 72 69 74 myth.dll..$.Writ
65 43 6f 6e 73 6f 6c 65 57 00 19 01 45 78 69 74 eConsoleW...Exit
50 72 6f 63 65 73 73 00 52 00 43 6c 6f 73 65 48 Process.R.CloseH
61 6e 64 6c 65 00 63 03 4d 6f 76 65 46 69 6c 65 andle.c.MoveFile
57 00 d6 00 44 65 6c 65 74 65 46 69 6c 65 57 00 W...DeleteFileW.
83 02 47 65 74 54 65 6d 70 46 69 6c 65 4e 61 6d ..GetTempFileNam
65 57 00 00 85 02 47 65 74 54 65 6d 70 50 61 74 eW....GetTempPat
68 57 00 00 14 02 47 65 74 4d 6f 64 75 6c 65 46 hW....GetModuleF
69 6c 65 4e 61 6d 65 57 00 00 02 02 47 65 74 4c ileNameW....GetL
61 73 74 45 72 72 6f 72 00 00 64 02 47 65 74 53 astError..d.GetS
74 64 48 61 6e 64 6c 65 00 00 4b 45 52 4e 45 4c tdHandle..KERNEL
33 32 2e 64 6c 6c 00 00 35 03 77 76 73 70 72 69 32.dll..5.wvspri
6e 74 66 57 00 00 55 53 45 52 33 32 2e 64 6c 6c ntfW..USER32.dll
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Decode the dump file myth.txt
created in
step 9. to recreate the console application
myth.com
:
CERTUTIL.EXE /DecodeHex myth.txt myth.com
Input Length = 8704 Output Length = 2048 CertUtil: -decodehex command completed successfully.
Create the text file myth.c
with the following content
in an arbitrary, preferable empty directory:
// Copyright © 2004-2025, Stefan Kanthak <stefan.kanthak@nexgo.de>
#define STRICT
#define UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
__declspec(safebuffers)
BOOL CDECL PrintConsole(HANDLE hConsole, [SA_FormatString(Style="printf")] LPCWSTR lpFormat, ...)
{
WCHAR szOutput[1024];
DWORD dwOutput;
DWORD dwConsole;
va_list vaInput;
va_start(vaInput, lpFormat);
dwOutput = wvsprintf(szOutput, lpFormat, vaInput);
va_end(vaInput);
if (dwOutput == 0)
return FALSE;
if (!WriteConsole(hConsole, szOutput, dwOutput, &dwConsole, NULL))
return FALSE;
return dwConsole == dwOutput;
}
const FILE_DISPOSITION_INFO fdi = {TRUE};
const FILE_RENAME_INFO fri = {TRUE, (HANDLE) NULL, sizeof(L'€'), L'€'};
__declspec(noreturn)
VOID CDECL wmainCRTStartup(VOID)
{
DWORD dwError = ERROR_SUCCESS;
DWORD dwModule;
WCHAR szModule[MAX_PATH];
HANDLE hModule;
HANDLE hConsole = GetStdHandle(STD_ERROR_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE)
dwError = GetLastError();
else
{
dwModule = GetModuleFileName((HMODULE) NULL,
szModule,
sizeof(szModule) / sizeof(*szModule));
if (dwModule == 0)
PrintConsole(hConsole,
L"GetModuleFileName() returned error %lu\n",
dwError = GetLastError());
else
{
hModule = CreateFile(szModule,
DELETE,
FILE_SHARE_DELETE,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
if (hModule == INVALID_HANDLE_VALUE)
PrintConsole(hConsole,
L"CreateFile() returned error %lu\n",
dwError = GetLastError());
else
{
if (!SetFileInformationByHandle(hModule,
#ifdef MYTHS
FileDispositionInfo,
&fdi,
sizeof(fdi)))
#else
FileRenameInfo,
&fri,
sizeof(fri)))
#endif
PrintConsole(hConsole,
L"SetFileInformationByHandle() returned error %lu\n",
dwError = GetLastError());
if (!CloseHandle(hModule))
PrintConsole(hConsole,
L"CloseHandle() returned error %lu\n",
GetLastError());
}
}
if (!CloseHandle(hConsole))
PrintConsole(hConsole,
L"CloseHandle() returned error %lu\n",
GetLastError());
}
ExitProcess(dwError);
}
SetFileInformationByHandle function
FILE_INFO_BY_HANDLE_CLASS enumeration
FILE_DISPOSITION_INFO structure
FILE_RENAME_INFO structure
Build the console application myth.exe
from the source
file myth.c
created in step 1.:
SET CL=/GAFy /Osy /W4 /Zl SET LINK=/ENTRY:wmainCRTStartup /NODEFAULTLIB /SUBSYSTEM:Console CL.EXE myth.c kernel32.lib user32.libFor details and reference see the MSDN articles Compiler Options and Linker Options.
Note: if necessary, see the MSDN article Use the Microsoft C++ toolset from the command line for an introduction.
Note: the console application myth.exe
is a pure Win32 executable and builds without the
MSVCRT
libraries.
Note: the command lines can be copied and pasted as block into a Command Processor window.
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. myth.c myth.c(78) : warning C4090: 'function' : different 'const' qualifiers Microsoft (R) Incremental Linker Version 10.00.40219.386 Copyright (C) Microsoft Corporation. All rights reserved. /ENTRY:wmainCRTStartup /NODEFAULTLIB /SUBSYSTEM:Console /out:myth.exe myth.obj kernel32.lib user32.lib
Execute the console application myth.exe
built in
step 2. and display its exit code:
.\myth.exe ECHO %ERRORLEVEL%
0
Verify that the console application myth.exe
has renamed
itself to €
by restoring its original name:
RENAME € myth.exe
Use the X.509 certificate to send S/MIME encrypted mail.
Note: email in weird format and without a proper sender name is likely to be discarded!
I dislike
HTML (and even
weirder formats too) in email, I prefer to receive plain text.
I also expect to see your full (real) name as sender, not your
nickname.
I abhor top posts and expect inline quotes in replies.
as iswithout any warranty, neither express nor implied.
cookiesin the web browser.
The web service is operated and provided by
Telekom Deutschland GmbH The web service provider stores a session cookie
in the web
browser and records every visit of this web site with the following
data in an access log on their server(s):