static MonoBundledAssembly **bundled; int mono_main (int argc, char* argv[]); #include #include #include 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; err = inflateInit (&stream); 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; } int main (int argc, char* argv[]) { char **newargs = (char **) malloc (sizeof (char *) * (argc + 2)); int i; CompressedAssembly **ptr; MonoBundledAssembly **bundled_ptr; Bytef *buffer; int nbundles; newargs [0] = argv [0]; newargs [1] = image_name; for (i = 1; i < argc; i++) newargs [i+1] = argv [i]; newargs [++i] = NULL; if (config_dir != NULL && getenv ("MONO_CFG_DIR") == NULL) mono_set_dirs (getenv ("MONO_PATH"), config_dir); 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, "Error %d decompresing 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); return mono_main (argc+1, newargs); }