int main(int argc, char **argv) { extern int Py_FrozenMain(int, char **); PyImport_FrozenModules = _PyImport_FrozenModules; return Py_FrozenMain(argc, argv); }
int wmain(int argc, wchar_t *argv[]) { #else int main(int argc, char *argv[]) { #endif int retval; struct _frozen *moddef; const char *log_filename; void *blob = NULL; log_filename = NULL; /* printf("blob_offset: %d\n", (int)blobinfo.blob_offset); printf("blob_size: %d\n", (int)blobinfo.blob_size); printf("version: %d\n", (int)blobinfo.version); printf("num_pointers: %d\n", (int)blobinfo.num_pointers); printf("codepage: %d\n", (int)blobinfo.codepage); printf("flags: %d\n", (int)blobinfo.flags); printf("reserved: %d\n", (int)blobinfo.reserved); */ // If we have a blob offset, we have to map the blob to memory. if (blobinfo.version == 0 || blobinfo.blob_offset != 0) { void *blob = map_blob((off_t)blobinfo.blob_offset, (size_t)blobinfo.blob_size); assert(blob != NULL); // Offset the pointers in the header using the base mmap address. if (blobinfo.version > 0 && blobinfo.num_pointers > 0) { uint32_t i; assert(blobinfo.num_pointers <= MAX_NUM_POINTERS); for (i = 0; i < blobinfo.num_pointers; ++i) { // Only offset if the pointer is non-NULL. Except for the first // pointer, which may never be NULL and usually (but not always) // points to the beginning of the blob. if (i == 0 || blobinfo.pointers[i] != 0) { blobinfo.pointers[i] = (void *)((uintptr_t)blobinfo.pointers[i] + (uintptr_t)blob); } } if (blobinfo.num_pointers >= 12) { log_filename = blobinfo.pointers[11]; } } else { blobinfo.pointers[0] = blob; } // Offset the pointers in the module table using the base mmap address. moddef = blobinfo.pointers[0]; while (moddef->name) { moddef->name = (char *)((uintptr_t)moddef->name + (uintptr_t)blob); if (moddef->code != 0) { moddef->code = (unsigned char *)((uintptr_t)moddef->code + (uintptr_t)blob); } //printf("MOD: %s %p %d\n", moddef->name, (void*)moddef->code, moddef->size); moddef++; } } if (log_filename != NULL) { setup_logging(log_filename, (blobinfo.flags & F_log_append) != 0); } #ifdef _WIN32 if (blobinfo.codepage != 0) { SetConsoleCP(blobinfo.codepage); SetConsoleOutputCP(blobinfo.codepage); } #endif // Run frozen application PyImport_FrozenModules = blobinfo.pointers[0]; retval = Py_FrozenMain(argc, argv); unmap_blob(blob); return retval; }