-
-
Save kexplo/1878366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
struct scriptinfo { | |
int tag; | |
int optimize; | |
int unbuffered; | |
int data_bytes; | |
char zippath[0]; | |
}; | |
int main(int argc,char *argv[]) { | |
HMODULE hTarget; | |
HRSRC hRes; | |
HGLOBAL hResLoaded; | |
char *pScript; | |
struct scriptinfo *p_script_info; | |
int numScriptBytes; | |
FILE *file; | |
// print usage | |
if(argc < 3) | |
{ | |
printf("Usage: exe2py target.exe out.marshal\r\n"); | |
printf("you can marshal.load(open(\"out.marshal\")) to load PyCodeObject.\r\n"); | |
return 0; | |
} | |
// open target | |
hTarget = LoadLibrary(argv[1]); | |
// find and load resource | |
hRes = FindResource(hTarget, MAKEINTRESOURCE(1), "PYTHONSCRIPT"); | |
hResLoaded = LoadResource(hTarget, hRes); | |
p_script_info = (struct scriptinfo *)pScript = LockResource(hResLoaded); | |
// validate script resource | |
numScriptBytes = p_script_info->data_bytes; | |
pScript += sizeof(struct scriptinfo); | |
// let pScript point to the start of the python script resource | |
pScript += strlen(p_script_info->zippath) + 1; | |
// out | |
file = fopen(argv[2],"wb"); | |
fwrite(pScript,numScriptBytes,1,file); | |
fclose(file); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment