Merge branch 'mr/winetest-compress' into 'master'

winetest: Compress embedded test executables.

See merge request wine/wine!6679
This commit is contained in:
Rémi Bernon 2024-11-19 02:02:17 +00:00
commit ee3c500eed
9 changed files with 90 additions and 5 deletions

View file

@ -84,6 +84,7 @@ AC_ARG_WITH(xshm, AS_HELP_STRING([--without-xshm],[do not use XShm (shared
[if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_XShm_h=no; fi])
AC_ARG_WITH(xxf86vm, AS_HELP_STRING([--without-xxf86vm],[do not use XFree video mode extension]),
[if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_xf86vmode_h=no; ac_cv_header_X11_extensions_xf86vmproto_h=no; fi])
AC_ARG_WITH(zlib, AS_HELP_STRING([--without-zlib],[do not use zlib]))
AC_ARG_WITH(system-dllpath,AS_HELP_STRING([--with-system-dllpath=PATH],[load external PE dependencies from colon-separated path PATH]),
AC_SUBST(system_dllpath,[$withval]))
@ -1530,6 +1531,15 @@ WINE_NOTICE_WITH(gphoto,[test "$ac_cv_lib_gphoto2_gp_camera_new" != "yes"],
WINE_NOTICE_WITH(gphoto,[test "$ac_cv_lib_gphoto2_port_gp_port_info_list_new" != "yes"],
[libgphoto2_port ${notice_platform}development files not found, digital cameras won't be auto-detected.])
dnl **** Check for zlib ****
if test "x$with_zlib" != "xno"
then
WINE_PACKAGE_FLAGS(ZLIB,[zlib],,,,
[AC_CHECK_HEADERS([zlib.h])
AC_CHECK_LIB(z,compress,[:],[ZLIB_LIBS=""],[$ZLIB_LIBS])])
fi
WINE_NOTICE_WITH(zlib,[test "$ac_cv_header_zlib_h" != "yes"],
[libz ${notice_platform}development files not found (or too old), wrc compressed resources won't be supported.])
dnl **** Check for resolver library ***
if test "$ac_cv_header_resolv_h" = "yes"

View file

@ -1,5 +1,6 @@
MODULE = winetest.exe
IMPORTS = uuid comctl32 version user32 gdi32 advapi32 wsock32 msvcrt
IMPORTS = uuid comctl32 version user32 gdi32 advapi32 wsock32 msvcrt $(ZLIB_PE_LIBS)
EXTRAINCL = $(ZLIB_PE_CFLAGS)
DELAYIMPORTS = ole32
EXTRADLLFLAGS = -mconsole

View file

@ -32,6 +32,7 @@
#include <commctrl.h>
#include <winternl.h>
#include <mshtml.h>
#include <zlib.h>
#include "winetest.h"
#include "resource.h"
@ -657,11 +658,45 @@ static void* extract_rcdata (LPCSTR name, LPCSTR type, DWORD* size)
return addr;
}
static void *zalloc( void *priv, unsigned int items, unsigned int sz )
{
return malloc( items * sz );
}
static void zfree( void *priv, void *addr )
{
free( addr );
}
static void *decompress( const char *res_name, UINT size,
const void *comp, UINT comp_size )
{
z_stream z = {.next_in = (BYTE *)comp, .avail_in = comp_size,
.zalloc = zalloc, .zfree = zfree};
BYTE *data = malloc( size );
int res;
res = inflateInit( &z );
if (res != Z_OK)
report( R_FATAL, "Can't decompress test resource %s: %d",
res_name, GetLastError() );
do
{
z.next_out = data + z.total_out;
z.avail_out = size - z.total_out;
res = inflate( &z, Z_FINISH );
} while (z.avail_in && res == Z_STREAM_END);
if (res != Z_STREAM_END) inflateEnd( &z );
return data;
}
/* Fills in the name and exename fields */
static void
extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
{
BYTE* code;
BYTE* code, *buffer = NULL;
DWORD size;
char *exepos;
HANDLE hfile;
@ -670,6 +705,14 @@ extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
code = extract_rcdata (res_name, "TESTRES", &size);
if (!code) report (R_FATAL, "Can't find test resource %s: %d",
res_name, GetLastError ());
if (*(DWORD *)code == 0)
{
DWORD comp_size = size - 8;
size = *(DWORD *)(code + 4);
buffer = decompress( res_name, size, code + 8, comp_size );
code = buffer;
}
test->name = xstrdup( res_name );
test->exename = strmake("%s\\%s", dir, test->name);
exepos = strstr (test->name, testexe);
@ -687,6 +730,7 @@ extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
report (R_FATAL, "Failed to write file %s.", test->exename);
CloseHandle(hfile);
free( buffer );
}
static HANDLE get_admin_token(void)

View file

@ -3670,7 +3670,7 @@ static void output_test_module( struct makefile *make, unsigned int arch )
output( "programs/winetest/%s%s_test.res: %s\n", arch_dirs[arch], basemodule,
obj_dir_path( make, stripped ));
output( "\t%secho \"%s_test.exe TESTRES \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ),
output( "\t%secho \"%s_test.exe TESTRES \\\"%s\\\"\" | %s -z -u -o $@\n", cmd_prefix( "WRC" ),
basemodule, obj_dir_path( make, stripped ), tools_path( make, "wrc" ));
if (make->disabled[arch] || (parent && parent->disabled[arch]))

View file

@ -1,5 +1,5 @@
PROGRAMS = wrc
UNIX_LIBS = $(GETTEXTPO_LIBS)
UNIX_LIBS = $(GETTEXTPO_LIBS) $(ZLIB_LIBS)
SOURCES = \
genres.c \

View file

@ -34,6 +34,10 @@
#include <assert.h>
#include <ctype.h>
#ifdef HAVE_ZLIB_H
# include <zlib.h>
#endif
#include "../tools.h"
#include "wrc.h"
#include "utils.h"
@ -959,6 +963,21 @@ static void user2res(name_id_t *name, user_t *usr)
put_dword(4); /* ResSize overwritten later*/
}
#ifdef HAVE_ZLIB_H
if (compress_data)
{
uLongf size = compressBound(usr->data->size);
Bytef *compressed = xmalloc(size);
compress(compressed, &size, (Bytef *)usr->data->data, usr->data->size);
put_dword(0);
put_dword(usr->data->size);
put_data(compressed, size);
free(compressed);
set_res_size(tag);
return;
}
#endif
put_data(usr->data->data, usr->data->size);
set_res_size(tag);
}

View file

@ -64,6 +64,7 @@ static const char usage[] =
" -v, --verbose Enable verbose mode\n"
" --verify-translations Check the status of the various translations\n"
" --version Print version and exit\n"
" -z Compress the resource with zlib\n"
"Input is taken from stdin if no sourcefile specified.\n"
"Debug level 'n' is a bitmask with following meaning:\n"
" * 0x01 Tell which resource is parsed (verbose mode)\n"
@ -127,6 +128,8 @@ int utf8_input = 0;
int check_utf8 = 1; /* whether to check for valid utf8 */
int compress_data = 0;
static char *output_name; /* The name given by the -o option */
const char *input_name = NULL; /* The name given on the command-line */
static struct strarray input_files;
@ -165,7 +168,7 @@ enum long_options_values
};
static const char short_options[] =
"b:D:Ef:F:hi:I:J:l:m:o:O:ruU:v";
"b:D:Ef:F:hi:I:J:l:m:o:O:ruU:vz";
static const struct long_option long_options[] = {
{ "debug", 1, LONG_OPT_DEBUG },
{ "define", 1, 'D' },
@ -376,6 +379,9 @@ static void option_callback( int optc, char *optarg )
case 'v':
debuglevel = DEBUGLEVEL_CHAT;
break;
case 'z':
compress_data = 1;
break;
case '?':
fprintf(stderr, "wrc: %s\n\n%s", optarg, usage);
exit(1);

View file

@ -40,6 +40,7 @@ extern int preprocess_only;
extern int no_preprocess;
extern int utf8_input;
extern int check_utf8;
extern int compress_data;
extern const char *input_name;
extern const char *nlsdirs[];

View file

@ -135,6 +135,10 @@ Turns on verbose mode (equivalent to \fB-d 1\fR).
.TP
.I \fB\-\-version\fR
Print version and exit.
.TP
.I \fB\-z\fR
Compress the resource data, prepending a 32bit zero value followed by the
decompressed size as a 32bit integer.
.SH PREPROCESSOR
The preprocessor is ANSI\-C compatible with some of the extensions of
the gcc preprocessor.