void android_main(struct android_app *state) { app_dummy(); //TODO-Have this update a variable, and use that to establish the pipes, sockets for improved compatibility with future android versions char *writeLocation = (char *) state->activity->internalDataPath; char *bootmsg = FINSBOOT_MSG; __android_log_print(ANDROID_LOG_INFO, "FINS", bootmsg); __android_log_print(ANDROID_LOG_INFO, "FINS", writeLocation); __android_log_print(ANDROID_LOG_INFO, "FINS", "Forking into capturermain() and main()"); /* int ret; __android_log_print(ANDROID_LOG_INFO, "FINS", "Gaining su status"); if ((ret = system("su"))) { __android_log_print(ANDROID_LOG_ERROR, "FINS", "SU failure: ret=%d, errno=%u, str='%s'", ret, errno, strerror(errno)); } */ if (0) { int i = 0; while (i < 1000) { __android_log_print(ANDROID_LOG_INFO, "FINS", "i=%d", i++); sleep(2); } return; } __android_log_print(ANDROID_LOG_INFO, "FINS", "Starting FINS: core_main()"); core_dummy(); core_main(); while (1) ; //sleep(1); __android_log_print(ANDROID_LOG_INFO, "FINS", "Exiting FINS: core_main()"); }
int main(int argc, char **argv) { log_t* loghandle; void* libhandle; int retcode; struct sigaction sa_quit; handler_api_t handler_api; sys_config_t* system_config; system_config = sys_get_config(); mcp_parse_arguments(argc, argv, system_config); if(system_config->debug == LOG_NOFLAGS && util_file_stat(system_config->pidfile) != 0) { fprintf(stderr, "%s: PID file %s exists! Not starting.\n", argv[0], system_config->pidfile); exit(EXIT_FAILURE); } libhandle = dlopen(system_config->libfile, RTLD_NOW); if(!libhandle) { fprintf(stderr, "%s: Could not load handler library: %s\n", argv[0], dlerror()); exit(EXIT_FAILURE); } if(sys_initapi(libhandle, &handler_api) != 0) { fprintf(stderr, "%s: Specified handler library is invalid", argv[0]); dlclose(libhandle); exit(EXIT_FAILURE); } loghandle = log_open(system_config->logfile, system_config->debug); if(!loghandle) { fprintf(stderr, "%s: Could not open log file: %s\n", argv[0], MCPROXY_LOGFILE); dlclose(libhandle); exit(EXIT_FAILURE); } log_set_default(loghandle); if(system_config->debug == LOG_NOFLAGS) mcp_daemonize(); memset(&sa_quit, 0, sizeof(struct sigaction)); sa_quit.sa_handler = sig_quit; sigaction(SIGTERM, &sa_quit, NULL); sigaction(SIGINT, &sa_quit, NULL); if(system_config->debug == LOG_NOFLAGS) util_file_writepid(system_config->pidfile); retcode = core_main(system_config, &handler_api); log_close(loghandle); dlclose(libhandle); if(system_config->debug == LOG_NOFLAGS) unlink(system_config->pidfile); exit(retcode); }
int main() { core_main(); return 0; }
void android_main(struct android_app *state) { app_dummy(); //TODO-Have this update a variable, and use that to establish the pipes, sockets for improved compatibility with future android versions char *writeLocation = (char *) state->activity->internalDataPath; char *bootmsg = FINSBOOT_MSG; LOGI(bootmsg); LOGI("internalDataPath='%s'", writeLocation); struct engine engine; memset(&engine, 0, sizeof(engine)); state->userData = &engine; state->onAppCmd = engine_handle_cmd; state->onInputEvent = engine_handle_input; engine.app = state; if (state->savedState != NULL) { // We are starting with a previous saved state; restore from it. engine.state = *(struct saved_state*) state->savedState; } int ret; if (0) { LOGI("Gaining su status"); if ((ret = system("su"))) { LOGE("SU failure: ret=%d, errno=%u, str='%s'", ret, errno, strerror(errno)); } } //apk can access files in /data as well but can't write to anything core_dummy(); //core_main((uint8_t *) (FINS_TMP_ROOT "/envi.cfg"), (uint8_t *) (FINS_TMP_ROOT "/stack.cfg"), 0); core_main((uint8_t *) ("/sdcard/fins/envi.cfg"), (uint8_t *) ("/sdcard/fins/stack.cfg"), 0); //core_tests(); //For random testing purposes //core_termination_handler(0); //############ terminating // loop waiting for stuff to do. while (1) { // Read all pending events. int ident; int events; struct android_poll_source* source; // If not animating, we will block forever waiting for events. // If animating, we loop until all events are read, then continue // to draw the next frame of animation. while ((ident = ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events, (void**) &source)) >= 0) { // Process this event. if (source != NULL) { source->process(state, source); } // If a sensor has data, process it now. if (ident == LOOPER_ID_USER) { } // Check if we are exiting. if (state->destroyRequested != 0) { //engine_term_display(&engine); engine.animating = 0; LOGE("exiting main return"); //return; } } if (engine.animating) { // Done with events; draw next animation frame. //engine.state.angle += .01f; //change state? // Drawing is throttled to the screen update rate, so there // is no need to do timing here. //engine_draw_frame(&engine); //LOGI("draw frame"); } } }
//TODO replace this option system with getopt, can see in SuperSU code //#include <getopt.h> int main(int argc, char *argv[]) { printf("argc=%u\n", argc); fflush(stdout); int i; #ifdef BUILD_FOR_ANDROID for (i = 0; i < 3; i++) { printf("argv[%d]='%s'\n", i, argv[i]); fflush(stdout); } core_main((uint8_t *)("envi.cfg"), (uint8_t *)("stack.cfg"), 0); #else for (i = 0; i < argc; i++) { printf("argv[%d]='%s'\n", i, argv[i]); fflush(stdout); } uint8_t envi_default = 1; uint8_t envi_name[FILE_NAME_SIZE]; memset((char *) envi_name, 0, FILE_NAME_SIZE); uint8_t stack_default = 1; uint8_t stack_name[FILE_NAME_SIZE]; memset((char *) stack_name, 0, FILE_NAME_SIZE); uint8_t capturer_default = 1; uint8_t capturer_name[FILE_NAME_SIZE]; memset((char *) capturer_name, 0, FILE_NAME_SIZE); uint8_t core_default = 1; uint8_t core_name[FILE_NAME_SIZE]; memset((char *) core_name, 0, FILE_NAME_SIZE); uint8_t seed_default = 1; uint32_t seed_num; int j; uint32_t len; uint8_t ch; for (i = 1; i < argc; i++) { if (argv[i][0] == '-' || argv[i][0] == '\\') { len = strlen(argv[i]); for (j = 1; j < len; j++) { ch = (uint8_t) argv[i][j]; if (ch == 'e' || ch == 'E') { if (j + 1 == len) { if (i + 1 < argc) { strcpy((char *) envi_name, argv[i + 1]); printf("Using environment configuration: '%s'\n", envi_name); fflush(stdout); envi_default = 0; i += 1; } else { printf("Incorrect format. Usage: -e <file>\n"); fflush(stdout); exit(-1); } } else { strcpy((char *) envi_name, &argv[i][j + 1]); printf("Using environment configuration: '%s'\n", envi_name); fflush(stdout); envi_default = 0; j = len; } } else if (ch == 's' || ch == 'S') { if (j + 1 == len) { if (i + 1 < argc) { strcpy((char *) stack_name, argv[i + 1]); printf("Using stack configuration: '%s'\n", stack_name); fflush(stdout); stack_default = 0; i += 1; } else { printf("Incorrect format. Usage: -s <file>\n"); fflush(stdout); exit(-1); } } else { strcpy((char *) stack_name, &argv[i][j + 1]); printf("Using stack configuration: '%s'\n", stack_name); fflush(stdout); stack_default = 0; j = len; } } else if (ch == 'c' || ch == 'C') { if (j + 1 == len) { if (i + 1 < argc) { strcpy((char *) capturer_name, argv[i + 1]); printf("Capturer output to: '%s'\n", capturer_name); fflush(stdout); capturer_default = 0; i += 1; } else { printf("Incorrect format. Usage: -c <file>\n"); fflush(stdout); exit(-1); } } else { strcpy((char *) capturer_name, &argv[i][j + 1]); printf("Capturer output to: '%s'\n", capturer_name); fflush(stdout); capturer_default = 0; j = len; } } else if (ch == 'o' || ch == 'O') { if (j + 1 == len) { if (i + 1 < argc) { strcpy((char *) core_name, argv[i + 1]); printf("Core output to: '%s'\n", core_name); fflush(stdout); core_default = 0; i += 1; } else { printf("Incorrect format. Usage: -o <file>\n"); fflush(stdout); exit(-1); } } else { strcpy((char *) core_name, &argv[i][j + 1]); printf("Core output to: '%s'\n", core_name); fflush(stdout); core_default = 0; j = len; } } else if (ch == 'x' || ch == 'X') { printf("option x\n"); fflush(stdout); } else { printf("Illegal option code = '%c'\n", ch); fflush(stdout); exit(-1); } } } else { printf("Illegal text: '%s'.\nUsage: core [-e <envi cfg>][-s <stack cfg>][-c <capturer output>][-o <core output>]\n", argv[i]); fflush(stdout); exit(-1); } } if (envi_default == 1) { strcpy((char *) envi_name, (char *) DEFAULT_ENVI_FILE); printf("Using default environment configuration: '%s'\n", envi_name); fflush(stdout); } if (stack_default == 1) { strcpy((char *) stack_name, (char *) DEFAULT_STACK_FILE); printf("Using default stack configuration: '%s'\n", stack_name); fflush(stdout); } if (capturer_default == 1) { strcpy((char *) capturer_name, (char *) DEFAULT_CAPTURER_FILE); //printf("Default: capturer output to: '%s'\n", capturer_name); //fflush(stdout); } if (core_default == 1) { strcpy((char *) core_name, (char *) DEFAULT_CORE_FILE); //printf("Default: core output to: '%s'\n", core_name); //fflush(stdout); } if (seed_default == 1) { seed_num = DEFAULT_SEED_NUM; //printf("Default: seed number used: %u\n", seed_num); fflush(stdout); } core_main(envi_name, stack_name, seed_num); #endif //core_tests(); //For random testing purposes //sleep(1); //printf("While (1) looping...\n"); fflush(stdout); while (1) { sleep(1000000); } //############ terminating //core_termination_handler(0); return 0; }