Skip to content

Instantly share code, notes, and snippets.

@Stehfyn
Created May 22, 2025 13:13
Show Gist options
  • Select an option

  • Save Stehfyn/80c4ab1c5a97fde7af0e6b44743bd5b9 to your computer and use it in GitHub Desktop.

Select an option

Save Stehfyn/80c4ab1c5a97fde7af0e6b44743bd5b9 to your computer and use it in GitHub Desktop.
Relaunches an executable with the cwd of its image on disk
#define STRICT
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdlib.h>
#include <tchar.h>
#define wtf2(y) \
((__targv[0] = (((TCHAR**)malloc(3 * sizeof(TCHAR*)))[0] = _tcsdup(__targv[0]))), __targv[1] = __targv[0], __targv[2] = 0, __targv[0])
#define wtf(x) \
(_tsplitpath(x, 0, (__targv[0] = _tcsdup(x), __targv[0]), 0, 0), ((__argc - 1) && !_tcsicmp(__targv[0], __targv[1])) ? _T("") : wtf2(2))
static TCHAR buf[260]; // juss to pwint
void _tmain()
{
MessageBox(0, _tgetcwd(buf, _countof(buf)), 0, MB_OK);
if (!!!_tchdir(wtf(_wpgmptr)))
{
_texecve(_wpgmptr, __targv, _tenviron);
}
else
{
MessageBox(0, _T("POSIX RULEZ"), 0, MB_OK);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment