Skip to content

Commit

Permalink
Add wrapper exe to set OPENSSL_MODULES
Browse files Browse the repository at this point in the history
  • Loading branch information
ojwb committed Dec 23, 2024
1 parent 1071e7d commit c1d8643
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ aven_LDADD += avenrc.o

avenrc.o: $(srcdir)/aven.rc ../lib/icons/aven.ico
cd $(srcdir) && `$(WX_CONFIG) --rescomp` --include-dir '$(abs_top_builddir)/lib/icons' -o '$(abs_builddir)/avenrc.o' aven.rc

bin_PROGRAMS += wrapmsw

wrapmsw_SOURCES = wrapmsw.c
wrapmsw_LDFLAGS = -mwindows
endif

AM_CFLAGS += $(PROJ_CFLAGS)
Expand Down
73 changes: 73 additions & 0 deletions src/wrapmsw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* wrapmsw.c
* Set OPENSSL_MODULES to .exe's directory and run real .exe
*
* Copyright (C) 2002,2010,2014,2024 Olly Betts
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <stdlib.h>
#include <string.h>
#include <windows.h>

int APIENTRY
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
DWORD len = 256;
wchar_t *buf = NULL;
PWSTR cmd_line;
(void)hInst; /* suppress compiler warning */
(void)hPrevInst; /* suppress compiler warning */
(void)lpCmdLine; /* suppress compiler warning */
while (1) {
DWORD got;
buf = realloc(buf, len * sizeof(wchar_t));
if (!buf) exit(1);
got = GetModuleFileNameW(NULL, buf, len);
if (got + 1 < len) {
/* Strange Microsoft nastiness - skip prefix "\\?\" if present. */
if (wcsncmp(buf, L"\\\\?\\", 4) == 0) {
buf += 4;
got -= 4;
}
wchar_t *p = wcsrchr(buf, L'\\');
wchar_t *e_val = buf;
size_t e_len;
if (p) {
++p;
e_len = p - buf;
} else {
e_val = L".";
e_len = 1;
}
wchar_t *e = malloc((e_len + strlen("OPENSSL_MODULES=") + 1) * sizeof(wchar_t));
if (!e) return 1;
wcscpy(e, L"OPENSSL_MODULES=");
memcpy(e + strlen("OPENSSL_MODULES=") * sizeof(wchar_t), e_val, e_len * sizeof(wchar_t));
e[strlen("OPENSSL_MODULES=") + e_len] = L'\0';
_wputenv(e);
wcscpy(buf + got - 4, L"_.exe");
}
len += len;
}
cmd_line = GetCommandLineW();
/* ShellExecute returns an HINSTANCE for some strange reason - the docs say
* the only valid operation is to convert it to "INT_PTR" (which seems to
* actually be an integer type. Marvellous. */
if ((INT_PTR)ShellExecuteW(NULL, NULL, buf, cmd_line, NULL, nCmdShow) <= 32) {
return 1;
}
return 0;
}
8 changes: 7 additions & 1 deletion survex.iss.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ Name: "{app}\proj"
Type: files; Name: "{app}\cad3d.exe"

[Files]
Source: "*.exe"; DestDir: "{app}"
Source: "*.exe"; Excludes: "wrapmsw.exe,aven.exe,survexport.exe"; DestDir: "{app}"
; Install aven.exe as aven_.exe and survexport.exe as survexport_.exe.
Source: "aven.exe"; DestDir: "{app}"; DestName: "aven_.exe"
Source: "survexport.exe"; DestDir: "{app}"; DestName: "survexport_.exe"
; Install wrapmsw.exe as aven.exe and survexport.exe.
Source: "wrapmsw.exe"; DestDir: "{app}"; DestName: "aven.exe"
Source: "wrapmsw.exe"; DestDir: "{app}"; DestName: "survexport.exe"
Source: "*.dll"; DestDir: "{app}"; Flags: skipifsourcedoesntexist
Source: "*.svx"; DestDir: "{app}"
Source: "*.ico"; DestDir: "{app}"
Expand Down

0 comments on commit c1d8643

Please sign in to comment.