int main (int argc, char *argv[]) { WCHAR *app_name; WCHAR *cmdline; BOOL ret; int result = 0; app_name = get_app_name (); cmdline = GetCommandLine (); TRACE ("starting %S %S\n", app_name, cmdline); /* Note that this does not spawn a new process, but just calls into the startup function of the app eventually, and returns with its exit code. */ ret = MyCreateProcessW (app_name, cmdline, &result); if (! ret) { ERR ("starting %S failed: %i\n", app_name, GetLastError()); return 1; } return result; }
void base::app::end_frame(base::frame_context *ctx, const bool nogl) { _canvas->fill_rect( ctx, glm::vec2(0), glm::vec2(220, 38), glm::vec4(0.2f, 0.2f, 0.2f, 1)); char tmp[512]; sprintf(tmp, "vel(%.2f,%.2f) visible: %i", _velocity.x, _velocity.z, 0); _canvas->draw_text( ctx, glm::vec2(0), tmp, glm::vec4(1, 1, 0, 1), _fnt_mono.get()); sprintf(tmp, "app::name: %s", get_app_name()); _canvas->draw_text( ctx, glm::vec2(0, 22), tmp, glm::vec4(1, 0.3, 0.3, 1), _fnt_arial.get()); if(!nogl) canvas::render(ctx); }
void service_udp4(packetinfo *pi, signature* sig_serv_udp) { int rc; /* PCRE */ int ovector[15]; signature *tmpsig; bstring app, service_name; app = service_name = NULL; if (pi->plen < 5 ) return; /* should make a config.tcp_client_flowdept etc * a range between 500-1000 should be good! */ tmpsig = sig_serv_udp; while (tmpsig != NULL) { rc = pcre_exec(tmpsig->regex, tmpsig->study, (const char*) pi->payload, pi->plen, 0, 0, ovector, 15); if (rc != -1) { app = get_app_name(tmpsig, pi->payload, ovector, rc); //printf("[*] - MATCH SERVICE IPv4/UDP: %s\n",(char *)bdata(app)); update_asset_service(pi, tmpsig->service, app); pi->cxt->check |= CXT_SERVICE_DONT_CHECK; bdestroy(app); return; } tmpsig = tmpsig->next; } /* * If no sig is found/mached, use default port to determin. */ if (pi->sc == SC_CLIENT && !ISSET_CLIENT_UNKNOWN(pi)) { if ((service_name = (bstring) check_known_port(IP_PROTO_UDP,ntohs(pi->d_port))) !=NULL ) { update_asset_service(pi, UNKNOWN, service_name); pi->cxt->check |= CXT_CLIENT_UNKNOWN_SET; bdestroy(service_name); } else if ((service_name = (bstring) check_known_port(IP_PROTO_UDP,ntohs(pi->s_port))) !=NULL ) { reverse_pi_cxt(pi); pi->d_port = pi->udph->src_port; update_asset_service(pi, UNKNOWN, service_name); pi->d_port = pi->udph->dst_port; pi->cxt->check |= CXT_CLIENT_UNKNOWN_SET; bdestroy(service_name); } } else if (pi->sc == SC_SERVER && !ISSET_SERVICE_UNKNOWN(pi)) { if ((service_name = (bstring) check_known_port(IP_PROTO_UDP,ntohs(pi->s_port))) !=NULL ) { update_asset_service(pi, UNKNOWN, service_name); pi->cxt->check |= CXT_SERVICE_UNKNOWN_SET; bdestroy(service_name); } else if ((service_name = (bstring) check_known_port(IP_PROTO_UDP,ntohs(pi->d_port))) !=NULL ) { reverse_pi_cxt(pi); update_asset_service(pi, UNKNOWN, service_name); pi->cxt->check |= CXT_SERVICE_UNKNOWN_SET; bdestroy(service_name); } } }
static void register_keybd_hook() { HINSTANCE hInstance = GetModuleHandle(NULL); if (!hInstance) { hInstance = LoadLibrary((LPSTR)get_app_name()); } if (!hInstance) { return; } hKeybdHook = SetWindowsHookEx( WH_KEYBOARD_LL, (HOOKPROC) keybd_hook, hInstance, 0 ); }
/* This will check if the application the user wanted exists will return that * application. If it doesn't exist, it will create one and return that. * It also sets the app info as the default for this type. */ static GAppInfo * add_or_find_application (CajaOpenWithDialog *dialog) { GAppInfo *app; char *app_name; const char *commandline; GError *error; gboolean success, should_set_default; char *message; GList *applications; error = NULL; app = NULL; if (dialog->details->selected_app_info) { app = g_object_ref (dialog->details->selected_app_info); } else { commandline = gtk_entry_get_text (GTK_ENTRY (dialog->details->entry)); app_name = get_app_name (commandline, &error); if (app_name != NULL) { app = g_app_info_create_from_commandline (commandline, app_name, G_APP_INFO_CREATE_NONE, &error); g_free (app_name); } } if (app == NULL) { message = g_strdup_printf (_("Could not add application to the application database: %s"), error->message); eel_show_error_dialog (_("Could not add application"), message, GTK_WINDOW (dialog)); g_free (message); g_error_free (error); return NULL; } should_set_default = (dialog->details->add_mode) || (!dialog->details->add_mode && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->details->checkbox))); success = TRUE; if (should_set_default) { if (dialog->details->content_type) { success = g_app_info_set_as_default_for_type (app, dialog->details->content_type, &error); } else { success = g_app_info_set_as_default_for_extension (app, dialog->details->extension, &error); } } else { applications = g_app_info_get_all_for_type (dialog->details->content_type); if (dialog->details->content_type && applications != NULL) { /* we don't care about reporting errors here */ g_app_info_add_supports_type (app, dialog->details->content_type, NULL); } if (applications != NULL) { g_list_foreach(applications, (GFunc) g_object_unref, NULL); g_list_free(applications); } } if (!success && should_set_default) { message = g_strdup_printf (_("Could not set application as the default: %s"), error->message); eel_show_error_dialog (_("Could not set as default application"), message, GTK_WINDOW (dialog)); g_free (message); g_error_free (error); } g_signal_emit_by_name (caja_signaller_get_current (), "mime_data_changed"); return app; }
/** * Parse a possible command pair - command and parameter * @param arg1 Command * @param arg2 Parameter (could be NULL) * @return How many parameters were used, 0,1,2 */ int raspicommonsettings_parse_cmdline(RASPICOMMONSETTINGS_PARAMETERS *state, const char *arg1, const char *arg2, void (*app_help)(char*)) { int command_id, used = 0, num_parameters; if (!arg1) return 0; command_id = raspicli_get_command_id(cmdline_commands, cmdline_commands_size, arg1, &num_parameters); // If invalid command, or we are missing a parameter, drop out if (command_id==-1 || (command_id != -1 && num_parameters > 0 && arg2 == NULL)) return 0; switch (command_id) { case CommandHelp: { display_valid_parameters(basename(get_app_name()), app_help); exit(0); break; } case CommandWidth: // Width > 0 if (sscanf(arg2, "%u", &state->width) == 1) used = 2; break; case CommandHeight: // Height > 0 if (sscanf(arg2, "%u", &state->height) == 1) used = 2; break; case CommandOutput: // output filename { int len = strlen(arg2); if (len) { // Ensure that any %<char> is either %% or %d. const char *percent = arg2; while(*percent && (percent=strchr(percent, '%')) != NULL) { int digits=0; percent++; while(isdigit(*percent)) { percent++; digits++; } if(!((*percent == '%' && !digits) || *percent == 'd')) { used = 0; fprintf(stderr, "Filename contains %% characters, but not %%d or %%%% - sorry, will fail\n"); break; } percent++; } state->filename = malloc(len + 10); // leave enough space for any timelapse generated changes to filename vcos_assert(state->filename); if (state->filename) strncpy(state->filename, arg2, len+1); used = 2; } else used = 0; break; } case CommandVerbose: // display lots of data during run state->verbose = 1; used = 1; break; case CommandCamSelect: //Select camera input port { if (sscanf(arg2, "%u", &state->cameraNum) == 1) used = 2; break; } case CommandSensorMode: { if (sscanf(arg2, "%u", &state->sensor_mode) == 1) used = 2; break; } case CommandGpsd: state->gps = 1; used = 1; break; } return used; }
/** * This is the main entry point of a native application that is using * android_native_app_glue. It runs in its own thread, with its own * event loop for receiving input events and doing other things. */ void android_main(struct android_app* state) { char confDir[PATH_MAX]; char buf[PATH_MAX]; char *nativeApp = NULL; // Make sure glue isn't stripped. app_dummy(); JNIEnv *env; state->activity->vm->AttachCurrentThread(&env, 0); jobject me = state->activity->clazz; jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Intent;"); jobject intent = env->CallObjectMethod(me, giid); //Got our intent jclass icl = env->GetObjectClass(intent); //class pointer of Intent jmethodID gseid = env->GetMethodID(icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;"); jstring jsParam1 = (jstring) env->CallObjectMethod(intent, gseid, env->NewStringUTF("nativeApp")); if (jsParam1) { const char *param1 = env->GetStringUTFChars(jsParam1, 0); LOGI("nativeApp=%s\n", param1); if (param1) { nativeApp = strdup(param1); } env->ReleaseStringUTFChars(jsParam1, param1); } state->activity->vm->DetachCurrentThread(); if (!nativeApp) { getcwd(buf, sizeof(buf)); LOGI("current path %s\n", buf); snprintf(confDir, sizeof(confDir), "%s/tmp/native-loader.conf", buf); nativeApp = get_app_name(confDir, buf, sizeof(buf)); if (!nativeApp) { LOGW("Fail-safe mode...\n"); nativeApp = get_app_name("/data/data/com.pdaxrom.cctools/root/tmp/native-loader.conf", buf, sizeof(buf)); if (!nativeApp) { nativeApp = get_app_name("/data/data/com.pdaxrom.cctools.free/cache/tmp/native-loader.conf", buf, sizeof(buf)); if (!nativeApp) { LOGE("Can't load native-loader.conf!\n"); return; } } } } void *handle; void (*newMain)(struct android_app* state); const char *error; LOGI("Load native activity %s\n", nativeApp); handle = dlopen(nativeApp, RTLD_LAZY); if (!handle) { LOGE("%s\n", dlerror()); return; } dlerror(); *(void **) (&newMain) = dlsym(handle, "android_main"); if ((error = dlerror()) != NULL) { LOGE("%s\n", error); return; } LOGI("start!!!\n"); (*newMain)(state); dlclose(handle); }
/** \fn int main(int argc, char *argv[]) \brief main routine \param argc number of commandline arguments + 1 \param argv string array containing commandline arguments (argv[0] contains name of executable) \return dummy return code (not used) Main routine for import, programming, and check routines */ int main(int argc, char ** argv) { char *appname; // name of application without path char portname[STRLEN]; // name of communication port int baudrate; // communication baudrate [Baud] uint8_t resetSTM8; // 0=no reset; 1=HW reset via DTR (RS232/USB) or GPIO18 (Raspi); 2=SW reset by sending 0x55+0xAA uint8_t enableBSL; // don't enable ROM bootloader after upload (caution!) uint8_t jumpFlash; // jump to flash after upload uint8_t pauseOnLaunch; // prompt for <return> prior to upload int flashsize; // size of flash (kB) for w/e routines uint8_t versBSL; // BSL version for w/e routines char hexfile[STRLEN]; // name of file to flash HANDLE ptrPort; // handle to communication port char buf[BUFSIZE]; // buffer for hexfiles char image[BUFSIZE]; // memory image buffer uint32_t imageStart; // starting address of image uint32_t numBytes; // number of bytes in image char *ptr=NULL; // pointer to memory int i, j; // generic variables //char Tx[100], Rx[100]; // debug: buffer for tests // initialize global variables g_pauseOnExit = 1; // wait for <return> before terminating g_UARTmode = 0; // 2-wire interface with UART duplex mode verbose = false; // verbose output when requested only // initialize default arguments portname[0] = '\0'; // no default port name baudrate = 230400; // default baudrate resetSTM8 = 0; // don't automatically reset STM8 jumpFlash = 1; // jump to flash after uploade pauseOnLaunch = 1; // prompt for return prior to upload enableBSL = 1; // enable bootloader after upload hexfile[0] = '\0'; // no default hexfile // for debugging only //sprintf(portname, "/dev/tty.usbserial-A4009I0O"); // required for strncpy() portname[STRLEN-1] = '\0'; hexfile[STRLEN-1] = '\0'; // reset console color (needs to be called once for Win32) setConsoleColor(PRM_COLOR_DEFAULT); //////// // parse commandline arguments //////// for (i=1; i<argc; i++) { // debug: print argument //printf("arg %d: '%s'\n", (int) i, argv[i]); // name of communication port if (!strcmp(argv[i], "-p")) strncpy(portname, argv[++i], STRLEN-1); // communication baudrate else if (!strcmp(argv[i], "-b")) sscanf(argv[++i],"%d",&baudrate); // UART mode: 0=duplex, 1=1-wire reply, 2=2-wire reply (default: duplex)\n"); else if (!strcmp(argv[i], "-u")) { sscanf(argv[++i], "%d", &j); g_UARTmode = j; } // name of hexfile else if (!strcmp(argv[i], "-f")) strncpy(hexfile, argv[++i], STRLEN-1); // HW reset STM8 via DTR line (RS232/USB) or GPIO18 (Raspi only) else if (!strcmp(argv[i], "-r")) { sscanf(argv[++i], "%d", &j); resetSTM8 = j; } // don't enable ROM bootloader after upload (caution!) else if (!strcmp(argv[i], "-x")) enableBSL = 0; // don't jump to address after upload else if (!strcmp(argv[i], "-j")) jumpFlash = 0; // don't prompt for <return> prior to upload else if (!strcmp(argv[i], "-Q")) pauseOnLaunch = 0; // don't prompt for <return> prior to exit else if (!strcmp(argv[i], "-q")) g_pauseOnExit = 0; // verbose output else if (!strcmp(argv[i], "-v")) verbose = true; // else print list of commandline arguments and language commands else { if (strrchr(argv[0],'\\')) appname = strrchr(argv[0],'\\')+1; // windows else if (strrchr(argv[0],'/')) appname = strrchr(argv[0],'/')+1; // Posix else appname = argv[0]; printf("\n"); printf("usage: %s [-h] [-p port] [-b rate] [-u mode] [-f file] [-r ch] [-x] [-j] [-Q] [-q] [-v]\n\n", appname); printf(" -h print this help\n"); printf(" -p port name of communication port (default: list all ports and query)\n"); printf(" -b rate communication baudrate in Baud (default: 230400)\n"); printf(" -u mode UART mode: 0=duplex, 1=1-wire reply, 2=2-wire reply (default: duplex)\n"); printf(" -f file name of s19 or intel-hex file to flash (default: none)\n"); #ifdef __ARMEL__ printf(" -r ch reset STM8: 1=DTR line (RS232), 2=send 'Re5eT!' @ 115.2kBaud, 3=GPIO18 pin (Raspi) (default: no reset)\n"); #else printf(" -r ch reset STM8: 1=DTR line (RS232), 2=send 'Re5eT!' @ 115.2kBaud (default: no reset)\n"); #endif printf(" -x don't enable ROM bootloader after upload (default: enable)\n"); printf(" -j don't jump to flash after upload (default: jump to flash)\n"); printf(" -Q don't prompt for <return> prior to upload (default: prompt)\n"); printf(" -q don't prompt for <return> prior to exit (default: prompt)\n"); printf(" -v verbose output\n"); printf("\n"); Exit(0, 0); } } // process commandline arguments //////// // print app name & version, and change console title //////// get_app_name(argv[0], VERSION, buf); printf("\n%s\n", buf); setConsoleTitle(buf); //////// // if no port name is given, list all available ports and query //////// if (strlen(portname) == 0) { printf(" enter comm port name ( "); list_ports(); printf(" ): "); scanf("%s", portname); getchar(); } // if no comm port name // If specified import hexfile - do it early here to be able to report file read errors before others if (strlen(hexfile)>0) { const char *shortname = strrchr(hexfile, '/'); if (!shortname) shortname = hexfile; // convert to memory image, depending on file type const char *dot = strrchr (hexfile, '.'); if (dot && !strcmp(dot, ".s19")) { if (verbose) printf(" Loading Motorola S-record file %s …\n", shortname); load_hexfile(hexfile, buf, BUFSIZE); convert_s19(buf, &imageStart, &numBytes, image); } else if (dot && (!strcmp(dot, ".hex") || !strcmp(dot, ".ihx"))) { if (verbose) printf(" Loading Intel hex file %s …\n", shortname); load_hexfile(hexfile, buf, BUFSIZE); convert_hex(buf, &imageStart, &numBytes, image); } else { if (verbose) printf(" Loading binary file %s …\n", shortname); load_binfile(hexfile, image, &imageStart, &numBytes, BUFSIZE); } } //////// // put STM8 into bootloader mode //////// if (pauseOnLaunch) { printf(" activate STM8 bootloader and press <return>"); fflush(stdout); fflush(stdin); getchar(); } //////// // open port with given properties //////// printf(" open port '%s' with %gkBaud ... ", portname, (float) baudrate / 1000.0); fflush(stdout); if (g_UARTmode == 0) ptrPort = init_port(portname, baudrate, 1000, 8, 2, 1, 0, 0); // use even parity else ptrPort = init_port(portname, baudrate, 1000, 8, 0, 1, 0, 0); // use no parity printf("ok\n"); fflush(stdout); // debug: communication test (echo+1 test-SW on STM8) /* printf("open: %d\n", ptrPort); for (i=0; i<254; i++) { Tx[0] = i; send_port(ptrPort, 1, Tx); receive_port(ptrPort, 1, Rx); printf("%d %d\n", (int) Tx[0], (int) Rx[0]); } printf("done\n"); Exit(1,0); */ //////// // communicate with STM8 bootloader //////// // HW reset STM8 using DTR line (USB/RS232) if (resetSTM8 == 1) { printf(" reset via DTR ... "); pulse_DTR(ptrPort, 10); printf("done\n"); SLEEP(5); // allow BSL to initialize } // SW reset STM8 via command 'Re5eT!' at 115.2kBaud (requires respective STM8 SW) else if (resetSTM8 == 2) { set_baudrate(ptrPort, 115200); // expect STM8 SW to receive at 115.2kBaud printf(" reset via UART command ... "); sprintf(buf, "Re5eT!"); // reset command (same as in STM8 SW!) for (i=0; i<6; i++) { send_port(ptrPort, 1, buf+i); // send reset command bytewise to account for slow handling SLEEP(10); } printf("done\n"); set_baudrate(ptrPort, baudrate); // restore specified baudrate } // HW reset STM8 using GPIO18 pin (only Raspberry Pi!) #ifdef __ARMEL__ else if (resetSTM8 == 3) { printf(" reset via GPIO18 ... "); pulse_GPIO(18, 10); printf("done\n"); SLEEP(5); // allow BSL to initialize } #endif // __ARMEL__ // synchronize baudrate bsl_sync(ptrPort); // get bootloader info for selecting flash w/e routines bsl_getInfo(ptrPort, &flashsize, &versBSL); // select device dependent flash routines for upload if ((flashsize==32) && (versBSL==0x10)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_32K_ver_1_0_s19; ptr[STM8_Routines_E_W_ROUTINEs_32K_ver_1_0_s19_len]=0; } else if ((flashsize==32) && (versBSL==0x12)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_32K_ver_1_2_s19; ptr[STM8_Routines_E_W_ROUTINEs_32K_ver_1_2_s19_len]=0; } else if ((flashsize==32) && (versBSL==0x13)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_32K_ver_1_3_s19; ptr[STM8_Routines_E_W_ROUTINEs_32K_ver_1_3_s19_len]=0; } else if ((flashsize==32) && (versBSL==0x14)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_32K_ver_1_4_s19; ptr[STM8_Routines_E_W_ROUTINEs_32K_ver_1_4_s19_len]=0; } else if ((flashsize==128) && (versBSL==0x20)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_128K_ver_2_0_s19; ptr[STM8_Routines_E_W_ROUTINEs_128K_ver_2_0_s19_len]=0; } else if ((flashsize==128) && (versBSL==0x21)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_128K_ver_2_1_s19; ptr[STM8_Routines_E_W_ROUTINEs_128K_ver_2_1_s19_len]=0; } else if ((flashsize==128) && (versBSL==0x22)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_128K_ver_2_2_s19; ptr[STM8_Routines_E_W_ROUTINEs_128K_ver_2_2_s19_len]=0; } else if ((flashsize==128) && (versBSL==0x24)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_128K_ver_2_4_s19; ptr[STM8_Routines_E_W_ROUTINEs_128K_ver_2_4_s19_len]=0; } else if ((flashsize==256) && (versBSL==0x10)) { ptr = (char*) STM8_Routines_E_W_ROUTINEs_256K_ver_1_0_s19; ptr[STM8_Routines_E_W_ROUTINEs_256K_ver_1_0_s19_len]=0; } else { setConsoleColor(PRM_COLOR_RED); fprintf(stderr, "\n\nerror: unsupported device, exit!\n\n"); Exit(1, g_pauseOnExit); } { char ramImage[8192]; uint32_t ramImageStart; uint32_t numRamBytes; convert_s19(ptr, &ramImageStart, &numRamBytes, ramImage); if (verbose) printf("Uploading RAM routines\n"); bsl_memWrite(ptrPort, ramImageStart, numRamBytes, ramImage, 0); } // if specified upload hexfile if (strlen(hexfile)>0) bsl_memWrite(ptrPort, imageStart, numBytes, image, 1); // memory read //imageStart = 0x8000; numBytes = 128*1024; // complete 128kB flash //imageStart = 0x00A0; numBytes = 352; // RAM //bsl_memRead(ptrPort, imageStart, numBytes, image); // enable ROM bootloader after upload (option bytes always on same address) if (enableBSL==1) { printf(" activate bootloader ... "); bsl_memWrite(ptrPort, 0x487E, 2, (char*)"\x55\xAA", 0); printf("done\n"); } // jump to flash start address after upload (reset vector always on same address) if (jumpFlash) bsl_jumpTo(ptrPort, 0x8000); //////// // clean up and exit //////// close_port(&ptrPort); if (verbose) printf("done with program\n"); Exit(0, g_pauseOnExit); // avoid compiler warnings return(0); } // main