Skip to content

Instantly share code, notes, and snippets.

@grendello

grendello/temp.c Secret

Created May 17, 2018 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grendello/465ecec96b3bee801e6bbc5a28019833 to your computer and use it in GitHub Desktop.
Save grendello/465ecec96b3bee801e6bbc5a28019833 to your computer and use it in GitHub Desktop.
/* This source code was produced by mkbundle, do not edit */
#ifndef NULL
#define NULL (void *)0
#endif
typedef struct {
const char *name;
const unsigned char *data;
const unsigned int size;
} MonoBundledAssembly;
#define MONO_AOT_MODE_NORMAL 1
#define MONO_AOT_MODE_FULL 3
#define MONO_AOT_MODE_LLVMONLY 4
#ifndef __MKBUNDLE_API_H
#define __MKBUNDLE_API_H
typedef struct BundleMonoAPI
{
void (*mono_register_bundled_assemblies) (const MonoBundledAssembly **assemblies);
void (*mono_register_config_for_assembly) (const char* assembly_name, const char* config_xml);
void (*mono_jit_set_aot_mode) (int mode);
void (*mono_aot_register_module) (void* aot_info);
void (*mono_config_parse_memory) (const char *buffer);
void (*mono_register_machine_config) (const char *config_xml);
} BundleMonoAPI;
#if ANDROID
#include <stdarg.h>
#include <android/log.h>
static void
mkbundle_log_error (const char *format, ...)
{
va_list ap;
va_start (ap, format);
__android_log_vprint (ANDROID_LOG_ERROR, "mkbundle", format, ap);
va_end (ap);
}
#endif // ANDROID
#endif // __MKBUNDLE_API_H
typedef struct _compressed_data {
MonoBundledAssembly assembly;
int compressed_size;
} CompressedAssembly;
extern const unsigned char assembly_data_issue1651_dll [];
static CompressedAssembly assembly_bundle_issue1651_dll = {{"issue1651.dll", assembly_data_issue1651_dll, 5632}, 2345};
extern const unsigned char assembly_data_Java_Interop_dll [];
static CompressedAssembly assembly_bundle_Java_Interop_dll = {{"Java.Interop.dll", assembly_data_Java_Interop_dll, 180736}, 59448};
extern const unsigned char assembly_data_Mono_Android_dll [];
static CompressedAssembly assembly_bundle_Mono_Android_dll = {{"Mono.Android.dll", assembly_data_Mono_Android_dll, 632832}, 168031};
extern const unsigned char assembly_data_mscorlib_dll [];
static CompressedAssembly assembly_bundle_mscorlib_dll = {{"mscorlib.dll", assembly_data_mscorlib_dll, 1758720}, 622953};
extern const unsigned char assembly_data_System_Core_dll [];
static CompressedAssembly assembly_bundle_System_Core_dll = {{"System.Core.dll", assembly_data_System_Core_dll, 303104}, 123726};
extern const unsigned char assembly_data_System_dll [];
static CompressedAssembly assembly_bundle_System_dll = {{"System.dll", assembly_data_System_dll, 17408}, 8198};
extern const unsigned char assembly_data_System_Runtime_Serialization_dll [];
static CompressedAssembly assembly_bundle_System_Runtime_Serialization_dll = {{"System.Runtime.Serialization.dll", assembly_data_System_Runtime_Serialization_dll, 5120}, 1934};
static const CompressedAssembly *compressed [] = {
&assembly_bundle_issue1651_dll,
&assembly_bundle_Java_Interop_dll,
&assembly_bundle_Mono_Android_dll,
&assembly_bundle_mscorlib_dll,
&assembly_bundle_System_Core_dll,
&assembly_bundle_System_dll,
&assembly_bundle_System_Runtime_Serialization_dll,
NULL
};
/* -*- C -*- */
#include <stdlib.h>
static BundleMonoAPI mono_api;
void initialize_mono_api (const BundleMonoAPI *info)
{
if (info == NULL) {
mkbundle_log_error ("mkbundle: missing Mono API info\n");
exit (1);
}
mono_api.mono_register_bundled_assemblies = info->mono_register_bundled_assemblies;
mono_api.mono_register_config_for_assembly = info->mono_register_config_for_assembly;
mono_api.mono_jit_set_aot_mode = info->mono_jit_set_aot_mode;
mono_api.mono_aot_register_module = info->mono_aot_register_module;
mono_api.mono_config_parse_memory = info->mono_config_parse_memory;
mono_api.mono_register_machine_config = info->mono_register_machine_config;
}
static int
validate_api_pointer (const char *name, void *ptr)
{
if (ptr != NULL)
return 0;
mkbundle_log_error ("mkbundle: Mono API pointer '%s' missing\n", name);
return 1;
}
static void
validate_api_struct ()
{
int missing = 0;
missing += validate_api_pointer ("mono_register_bundled_assemblies", mono_api.mono_register_bundled_assemblies);
missing += validate_api_pointer ("mono_register_config_for_assembly", mono_api.mono_register_config_for_assembly);
missing += validate_api_pointer ("mono_jit_set_aot_mode", mono_api.mono_jit_set_aot_mode);
missing += validate_api_pointer ("mono_aot_register_module", mono_api.mono_aot_register_module);
missing += validate_api_pointer ("mono_config_parse_memory", mono_api.mono_config_parse_memory);
missing += validate_api_pointer ("mono_register_machine_config", mono_api.mono_register_machine_config);
if (missing <= 0)
return;
mkbundle_log_error ("mkbundle: bundle not initialized properly, %d Mono API pointers are missing\n", missing);
exit (1);
}
static void
init_default_mono_api_struct ()
{
#ifdef USE_DEFAULT_MONO_API_STRUCT
mono_api.mono_register_bundled_assemblies = mono_register_bundled_assemblies;
mono_api.mono_register_config_for_assembly = mono_register_config_for_assembly;
mono_api.mono_jit_set_aot_mode = mono_jit_set_aot_mode;
mono_api.mono_aot_register_module = mono_aot_register_module;
mono_api.mono_config_parse_memory = mono_config_parse_memory;
mono_api.mono_register_machine_config = mono_register_machine_config;
#endif
}
static void install_aot_modules (void) {
mono_api.mono_jit_set_aot_mode (MONO_AOT_MODE_NORMAL);
}
static char *image_name = "issue1651.dll";
static void install_dll_config_files (void) {
}
static const char *config_dir = NULL;
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;
init_default_mono_api_struct ();
validate_api_struct ();
install_dll_config_files ();
ptr = (CompressedAssembly **) compressed;
nbundles = 0;
while (*ptr++ != NULL)
nbundles++;
bundled = (MonoBundledAssembly **) malloc (sizeof (MonoBundledAssembly *) * (nbundles + 1));
if (bundled == NULL) {
// May fail...
mkbundle_log_error ("mkbundle: out of memory");
exit (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_api.mono_register_bundled_assemblies((const MonoBundledAssembly **) bundled);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment