Skip to content

Instantly share code, notes, and snippets.

@slashvar
Created June 30, 2017 12:40
Show Gist options
  • Save slashvar/014cb091f66c413d39009c08afc92c69 to your computer and use it in GitHub Desktop.
Save slashvar/014cb091f66c413d39009c08afc92c69 to your computer and use it in GitHub Desktop.
Change for module creation
static
PyObject* pepi_module_init(void) {
PyObject *m;
if (PyType_Ready(&pepy_parsed_type) < 0 ||
PyType_Ready(&pepy_section_type) < 0 ||
PyType_Ready(&pepy_import_type) < 0 ||
PyType_Ready(&pepy_export_type) < 0 ||
PyType_Ready(&pepy_relocation_type) < 0 ||
PyType_Ready(&pepy_resource_type) < 0)
return NULL;
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"pepy",
"Python interface to pe-parse.",
-1,
pepy_methods,
NULL,
NULL,
NULL,
NULL,
};
#endif
#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule3("pepy", pepy_methods, "Python interface to pe-parse.");
#endif
if (!m)
return NULL;
pepy_error = PyErr_NewException((char *) "pepy.error", NULL, NULL);
Py_INCREF(pepy_error);
PyModule_AddObject(m, "error", pepy_error);
Py_INCREF(&pepy_parsed_type);
PyModule_AddObject(m, "pepy_parsed", (PyObject *) &pepy_parsed_type);
Py_INCREF(&pepy_section_type);
PyModule_AddObject(m, "pepy_section", (PyObject *) &pepy_section_type);
Py_INCREF(&pepy_import_type);
PyModule_AddObject(m, "pepy_import", (PyObject *) &pepy_import_type);
Py_INCREF(&pepy_export_type);
PyModule_AddObject(m, "pepy_export", (PyObject *) &pepy_export_type);
Py_INCREF(&pepy_relocation_type);
PyModule_AddObject(m, "pepy_relocation", (PyObject *) &pepy_relocation_type);
Py_INCREF(&pepy_resource_type);
PyModule_AddObject(m, "pepy_resource", (PyObject *) &pepy_resource_type);
PyModule_AddStringMacro(m, PEPY_VERSION);
PyModule_AddIntMacro(m, MZ_MAGIC);
PyModule_AddIntMacro(m, NT_MAGIC);
PyModule_AddIntMacro(m, NUM_DIR_ENTRIES);
PyModule_AddIntMacro(m, NT_OPTIONAL_32_MAGIC);
PyModule_AddIntMacro(m, NT_SHORT_NAME_LEN);
PyModule_AddIntMacro(m, DIR_EXPORT);
PyModule_AddIntMacro(m, DIR_IMPORT);
PyModule_AddIntMacro(m, DIR_RESOURCE);
PyModule_AddIntMacro(m, DIR_EXCEPTION);
PyModule_AddIntMacro(m, DIR_SECURITY);
PyModule_AddIntMacro(m, DIR_BASERELOC);
PyModule_AddIntMacro(m, DIR_DEBUG);
PyModule_AddIntMacro(m, DIR_ARCHITECTURE);
PyModule_AddIntMacro(m, DIR_GLOBALPTR);
PyModule_AddIntMacro(m, DIR_TLS);
PyModule_AddIntMacro(m, DIR_LOAD_CONFIG);
PyModule_AddIntMacro(m, DIR_BOUND_IMPORT);
PyModule_AddIntMacro(m, DIR_IAT);
PyModule_AddIntMacro(m, DIR_DELAY_IMPORT);
PyModule_AddIntMacro(m, DIR_COM_DESCRIPTOR);
PyModule_AddIntMacro(m, IMAGE_SCN_TYPE_NO_PAD);
PyModule_AddIntMacro(m, IMAGE_SCN_CNT_CODE);
PyModule_AddIntMacro(m, IMAGE_SCN_CNT_INITIALIZED_DATA);
PyModule_AddIntMacro(m, IMAGE_SCN_CNT_UNINITIALIZED_DATA);
PyModule_AddIntMacro(m, IMAGE_SCN_LNK_OTHER);
PyModule_AddIntMacro(m, IMAGE_SCN_LNK_INFO);
PyModule_AddIntMacro(m, IMAGE_SCN_LNK_REMOVE);
PyModule_AddIntMacro(m, IMAGE_SCN_LNK_COMDAT);
PyModule_AddIntMacro(m, IMAGE_SCN_NO_DEFER_SPEC_EXC);
PyModule_AddIntMacro(m, IMAGE_SCN_GPREL);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_FARDATA);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_PURGEABLE);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_16BIT);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_LOCKED);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_PRELOAD);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_1BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_2BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_4BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_8BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_16BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_32BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_64BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_128BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_256BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_512BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_1024BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_2048BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_4096BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_8192BYTES);
PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_MASK);
PyModule_AddIntMacro(m, IMAGE_SCN_LNK_NRELOC_OVFL);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_DISCARDABLE);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_NOT_CACHED);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_NOT_PAGED);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_SHARED);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_EXECUTE);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_READ);
PyModule_AddIntMacro(m, IMAGE_SCN_MEM_WRITE);
return m;
}
#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit_pepi(void)
{
return pepi_module_init();
}
#else
PyMODINIT_FUNC initpepi(void)
{
pepi_module_init();
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment