int main () { printf("Antidebug test...\n"); AmIBeingDebugged(); printf("End...\n"); return(0); }
int main(int argc, char *argv[]) { sys_argc = argc; sys_argv = argv; origPid = getpid(); #ifdef __APPLE__ extern void install_breakpoint_handlers(); install_breakpoint_handlers(); #endif forkExecProc = haveArg("--forkExecProc"); bool shell = haveArg("--shell"); bool pyShell = haveArg("--pyshell"); bool pyExec = haveArg("--pyexec"); bool noLog = haveArg("--nolog"); bool help = haveArg("--help") || haveArg("-h"); bool beingDebugged = AmIBeingDebugged(); const char* logDisabledReason = NULL; if(pyShell || pyExec || shell || forkExecProc || help) {} // be quiet else if(beingDebugged) { logDisabledReason = "debugger detected, not redirecting stdout/stderr"; } else if(noLog) { logDisabledReason = "not redirecting stdout/stderr"; } else { // current workaround to log stdout/stderr. see http://stackoverflow.com/questions/13104588/how-to-get-stdout-into-console-app logEnabled = true; printf("MusicPlayer: stdout/stderr goes to %s now\n", logFilename.c_str()); fflush(stdout); int newFd = open(getTildeExpandedPath(logFilename).c_str(), O_WRONLY|O_APPEND|O_CREAT); dup2(newFd, fileno(stdout)); dup2(newFd, fileno(stderr)); close(newFd); //freopen(logFilename.c_str(), "a", stdout); //freopen(logFilename.c_str(), "a", stderr); stderr = stdout; // well, hack, ... I don't like two seperate buffers. just messes up the output } if(!forkExecProc) { printf("%s", StartupStr); install_signal_handler(); } if(help) { printf( "Help: Available options:\n" " --nolog : don't redirect stdout/stderr to log. also implied when run in debugger\n" ); } if(!logEnabled && logDisabledReason) printf("%s\n", logDisabledReason); std::string mainPyFilename = getResourcePath() + "/Python/main.py"; Py_SetProgramName(argv[0]); if(!forkExecProc) printf("Python version: %s, prefix: %s, main: %s\n", Py_GetVersion(), Py_GetPrefix(), mainPyFilename.c_str()); Py_Initialize(); PyEval_InitThreads(); addPyPath(); if(logEnabled) { PySys_SetObject((char*)"stdout", PyFile_FromFile(stdout, (char*)"<stdout>", (char*)"w", fclose)); PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"stdout")); } PySys_SetObject((char*)"MusicPlayerBin", PyString_FromString(argv[0])); // Preload imp and thread. I hope to fix this bug: https://github.com/albertz/music-player/issues/8 , there was a crash in initthread which itself has called initimp PyObject* m = NULL; m = PyImport_ImportModule("imp"); Py_XDECREF(m); m = PyImport_ImportModule("thread"); Py_XDECREF(m); PySys_SetArgvEx(argc, argv, 0); FILE* fp = fopen((char*)mainPyFilename.c_str(), "r"); if(fp) PyRun_SimpleFile(fp, "main.py"); else printf("Could not open main.py!\n"); if(!forkExecProc && !help && !pyShell && !pyExec && !shell) { bool successStartup = checkStartupSuccess(); if(!successStartup) { printf("Error at startup.\n"); handleFatalError("There was an error at startup."); } } return 0; }