Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

86 lines
2.0 KiB
C

static MonoBundledAssembly **bundled;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
static int
my_inflate (const Byte *compr, uLong compr_len, Byte *uncompr, uLong uncompr_len)
{
int err;
z_stream stream;
memset (&stream, 0, sizeof (z_stream));
stream.next_in = (Byte *) compr;
stream.avail_in = (uInt) compr_len;
// http://www.zlib.net/manual.html
err = inflateInit2 (&stream, 16+MAX_WBITS);
if (err != Z_OK)
return 1;
for (;;) {
stream.next_out = uncompr;
stream.avail_out = (uInt) uncompr_len;
err = inflate (&stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
if (err != Z_OK) {
printf ("%d\n", err);
return 2;
}
}
err = inflateEnd (&stream);
if (err != Z_OK)
return 3;
if (stream.total_out != uncompr_len)
return 4;
return 0;
}
void mono_mkbundle_init ()
{
CompressedAssembly **ptr;
MonoBundledAssembly **bundled_ptr;
Bytef *buffer;
int nbundles;
install_dll_config_files ();
ptr = (CompressedAssembly **) compressed;
nbundles = 0;
while (*ptr++ != NULL)
nbundles++;
bundled = (MonoBundledAssembly **) malloc (sizeof (MonoBundledAssembly *) * (nbundles + 1));
bundled_ptr = bundled;
ptr = (CompressedAssembly **) compressed;
while (*ptr != NULL) {
uLong real_size;
uLongf zsize;
int result;
MonoBundledAssembly *current;
real_size = (*ptr)->assembly.size;
zsize = (*ptr)->compressed_size;
buffer = (Bytef *) malloc (real_size);
result = my_inflate ((*ptr)->assembly.data, zsize, buffer, real_size);
if (result != 0) {
fprintf (stderr, "mkbundle: Error %d decompressing data for %s\n", result, (*ptr)->assembly.name);
exit (1);
}
(*ptr)->assembly.data = buffer;
current = (MonoBundledAssembly *) malloc (sizeof (MonoBundledAssembly));
memcpy (current, *ptr, sizeof (MonoBundledAssembly));
current->name = (*ptr)->assembly.name;
*bundled_ptr = current;
bundled_ptr++;
ptr++;
}
*bundled_ptr = NULL;
mono_register_bundled_assemblies((const MonoBundledAssembly **) bundled);
}