/*---------------------------------------------------------------------------*/ PROCESS_THREAD(tcp_socket_process, ev, data) { PROCESS_BEGIN(); while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { appcall(data); } } PROCESS_END(); }
PROCESS_THREAD(jennic_bootloader_process, ev, data) { PROCESS_BEGIN(); tcp_listen(UIP_HTONS(2048)); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); appcall(data); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(cgterm_process, ev, data) { u16_t *ipaddr; char *cptr; PROCESS_POLLHANDLER(pollhandler()); PROCESS_BEGIN(); ctk_window_new(&window, 38, 5, "C/G term"); CTK_WIDGET_ADD(&window, &hostlabel); CTK_WIDGET_ADD(&window, &hostentry); CTK_WIDGET_ADD(&window, &portlabel); CTK_WIDGET_ADD(&window, &portentry); CTK_WIDGET_ADD(&window, &connectbutton); CTK_WIDGET_ADD(&window, &switchbutton); CTK_WIDGET_ADD(&window, &helplabel); ctk_window_open(&window); while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { appcall(data); } else if(ev == ctk_signal_widget_activate) { if(data == &switchbutton) { textmode(); } else if(data == &connectbutton) { serverport = 0; for(cptr = port; *cptr != ' ' && *cptr != 0; ++cptr) { if(*cptr < '0' || *cptr > '9') { continue; } serverport = 10 * serverport + *cptr - '0'; } ipaddr = serveraddr; if(uiplib_ipaddrconv(host, (u8_t *)serveraddr) == 0) { ipaddr = resolv_lookup(host); if(ipaddr == NULL) { resolv_query(host); } else { uip_ipaddr_copy(serveraddr, ipaddr); } } if(ipaddr != NULL) { conn = connect(serveraddr, serverport); if(conn != NULL) { memset((char *)0x0400, 0x20, 40*25); memset((char *)0xd800, 0x01, 40*25); textmode(); } } } } else if(ev == resolv_event_found) { ipaddr = resolv_lookup(host); if(ipaddr != NULL) { uip_ipaddr_copy(serveraddr, ipaddr); conn = connect(serveraddr, serverport); if(conn != NULL) { memset((char *)0x0400, 0x20, 40*25); memset((char *)0xd800, 0x01, 40*25); textmode(); } } } else if(ev == PROCESS_EVENT_EXIT || ev == ctk_signal_window_close) { break; } } ctk_window_close(&window); PROCESS_END(); }
//------------------------------------------------------------------------- PyObject *py_appcall( ea_t func_ea, thid_t tid, PyObject *py_type, PyObject *py_fields, PyObject *arg_list) { PYW_GIL_CHECK_LOCKED_SCOPE(); if ( !PyList_Check(arg_list) ) return NULL; const char *type = py_type == Py_None ? NULL : PyString_AS_STRING(py_type); const char *fields = py_fields == Py_None ? NULL : PyString_AS_STRING(py_fields); // Convert Python arguments into IDC values qvector<idc_value_t> idc_args; int sn = 0; Py_ssize_t nargs = PyList_Size(arg_list); idc_args.resize(nargs); bool ok = true; for ( Py_ssize_t i=0; i<nargs; i++ ) { // Get argument borref_t py_item(PyList_GetItem(arg_list, i)); if ( (debug & IDA_DEBUG_APPCALL) != 0 ) { qstring s; PyW_ObjectToString(py_item.o, &s); msg("obj[%d]->%s\n", int(i), s.c_str()); } // Convert it if ( pyvar_to_idcvar(py_item, &idc_args[i], &sn) < CIP_OK ) { ok = false; break; } } // Set exception message if ( !ok ) { PyErr_SetString( PyExc_ValueError, "PyAppCall: Failed to convert Python values to IDC values"); return NULL; } error_t ret; idc_value_t idc_result; Py_BEGIN_ALLOW_THREADS; if ( (debug & IDA_DEBUG_APPCALL) != 0 ) { msg("input variables:\n" "----------------\n"); qstring s; for ( Py_ssize_t i=0; i<nargs; i++ ) { VarPrint(&s, &idc_args[i]); msg("%d]\n%s\n-----------\n", int(i), s.c_str()); s.qclear(); } } // Do Appcall ret = appcall( func_ea, tid, (type_t *)type, (p_list *)fields, idc_args.size(), idc_args.begin(), &idc_result); Py_END_ALLOW_THREADS; if ( ret != eOk ) { // An exception was thrown? if ( ret == eExecThrow ) { // Convert the result (which is a debug_event) into a Python object ref_t py_appcall_exc; idcvar_to_pyvar(idc_result, &py_appcall_exc); PyErr_SetObject(PyExc_OSError, py_appcall_exc.o); return NULL; } // An error in the Appcall? (or an exception but AppCallOptions/DEBEV is not set) else { char err_str[MAXSTR]; qstrerror(ret, err_str, sizeof(err_str)); PyErr_SetString(PyExc_Exception, err_str); return NULL; } } if ( (debug & IDA_DEBUG_APPCALL) != 0 ) { msg("return variables:\n" "-----------------\n"); qstring s; for ( Py_ssize_t i=0; i<nargs; i++ ) { VarPrint(&s, &idc_args[i]); msg("%d]\n%s\n-----------\n", int(i), s.c_str()); s.qclear(); } } // Convert IDC values back to Python values for ( Py_ssize_t i=0; i<nargs; i++ ) { // Get argument borref_t py_item(PyList_GetItem(arg_list, i)); // We convert arguments but fail only on fatal errors // (we ignore failure because of immutable objects) if ( idcvar_to_pyvar(idc_args[i], &py_item) == CIP_FAILED ) { PyErr_SetString(PyExc_ValueError, "PyAppCall: Failed while converting IDC values to Python values"); return NULL; } } // Convert the result from IDC back to Python ref_t py_result; if ( idcvar_to_pyvar(idc_result, &py_result) <= CIP_IMMUTABLE ) { PyErr_SetString(PyExc_ValueError, "PyAppCall: Failed while converting IDC return value to Python return value"); return NULL; } QASSERT(30413, py_result.o->ob_refcnt == 1); if ( (debug & IDA_DEBUG_APPCALL) != 0 ) { msg("return var:\n" "-----------\n"); qstring s; VarPrint(&s, &idc_result); msg("%s\n-----------\n", s.c_str()); } py_result.incref(); return py_result.o; }