bool CESPServerLoggingAgent::updateLog(IEspUpdateLogRequestWrap& req, IEspUpdateLogResponse& resp) { try { StringBuffer soapreq( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"" " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\">" " <soap:Body>" ); soapreq.append(req.getUpdateLogRequest()); soapreq.append("</soap:Body></soap:Envelope>"); StringBuffer status, respStr; if (sendHTTPRequest(soapreq, respStr, status) && status.length() && strieq(status, "200 OK")) resp.setStatusCode(0); else if (status.length() && !strieq(status, "200 OK")) throw MakeStringException(EspLoggingErrors::UpdateLogFailed, "%s", status.str()); else if (respStr.length()) throw MakeStringException(EspLoggingErrors::UpdateLogFailed, "%s", respStr.str()); else throw MakeStringException(EspLoggingErrors::UpdateLogFailed, "Failed to send update log request to %s", serverUrl.str()); } catch (IException* e) {//retry will be in update log queue. StringBuffer errorStr, errorMessage; errorMessage.append("Failed to update log: error code ").append(e->errorCode()).append(", error message ").append(e->errorMessage(errorStr)); ERRLOG("%s", errorMessage.str()); resp.setStatusCode(-1); resp.setStatusMessage(errorMessage.str()); e->Release(); } return true; }
int CEclDirectSoapBindingEx::onGet(CHttpRequest* request, CHttpResponse* response) { const char *path = request->queryPath(); if (strieq(path, "/EclDirect/RunEclEx/Form")) return sendRunEclExForm(*request->queryContext(), request, response); if(strieq(path, "/EclDirect/RunEclEx/DisplayResult")) { IEspContext& context = *request->queryContext(); request->queryParameters()->setProp("display_xslt", 1); CRunEclExRequest reqObj(&context, "EclDirect", request->queryParameters(), request->queryAttachments()); CRunEclExResponse respObj("EclDirect"); theService->onRunEclEx(context, *QUERYINTERFACE(&reqObj, IEspRunEclExRequest), *QUERYINTERFACE(&respObj, IEspRunEclExResponse)); const char *result = respObj.getResults(); if (result && *result) { response->setContent(result); response->setContentType(runEclExFormatMimeType(reqObj.getFormat())); } else { response->setContent("No result in Ecl execution."); response->setContentType("text/html"); } response->setStatus(HTTP_STATUS_OK); response->send(); return 0; } return CEclDirectSoapBinding::onGet(request,response); }
IEclCommand *createCoreEclCommand(const char *cmdname) { if (!cmdname || !*cmdname) return NULL; if (strieq(cmdname, "deploy")) return new EclCmdDeploy(); if (strieq(cmdname, "publish")) return new EclCmdPublish(); if (strieq(cmdname, "activate")) return new EclCmdActivate(); if (strieq(cmdname, "deactivate")) return new EclCmdDeactivate(); return NULL; }
void WEXPORT WFileName::relativeTo( const char* f ) { int i; _splitpath( *this, _x.drive, _x.dir, _x.fname, _x.ext ); if( _x.dir[0] == PATHSEP_CHAR ) { FullName s; splitref( s, f, PATHSEP_STR ); if( s.dir[0] == PATHSEP_CHAR && strieq( s.drive, _x.drive ) ) { _x.drive[0] = '\0'; int b = 0; for( i=1; _x.dir[i] != '\0' && s.dir[i] != '\0'; i++ ) { if( tolower( (unsigned char)_x.dir[i] ) != tolower( (unsigned char)s.dir[i] ) ) break; if( s.dir[i] == PATHSEP_CHAR ) b = i; } if( b == 0 ) { strcpy( s.dir, _x.dir ); } else { int n = 0; for( ; s.dir[i] != '\0'; i++ ) { if( s.dir[i] == PATHSEP_CHAR ) n++; } s.dir[0] = '\0'; if( n > 0 ) { for( int j=0; j<n; j++ ) { strcpy( &s.dir[3 * j], PARENTSEP_STR ); } } strcpy( &s.dir[3 * n], &_x.dir[b + 1] ); } makepath( _x.path, _x.drive, s.dir, _x.fname, _x.ext ); *this = _x.path; } } }
const char *skipForeign(const char *name, StringBuffer *ip) { if (*name=='~') name++; const char *d1 = strstr(name, "::"); if (d1) { StringBuffer cmp; if (strieq("foreign", cmp.append(d1-name, name).trim().str())) { // foreign scope - need to strip off the ip and port d1 += 2; // skip :: const char *d2 = strstr(d1,"::"); if (d2) { if (ip) ip->append(d2-d1, d1).trim(); d2 += 2; while (*d2 == ' ') d2++; name = d2; } } } return name; }
void checkEndpointInfoAndOuput(IConstRoxieControlEndpointInfo &ep, unsigned flags, unsigned ¬Ok, unsigned *noHash=NULL, unsigned *noAddress=NULL, unsigned *attached=NULL, unsigned *detached=NULL) { FILE *f = NULL; const char *status = ep.getStatus(); bool ok = (status && strieq(status, "ok")); if (!ok) { f=stderr; notOk++; } else if (flags & CHK_VERBOSE) f=stdout; const char *hash = ep.getStateHash(); if (noHash && (!hash || !*hash)) (*noHash)++; const char *address = ep.getAddress(); if (noAddress && (!address || !*address)) (*noAddress)++; if (attached || detached) checkAttached(ep, attached, detached); if (f) { fputs(" ", f); StringBuffer s; fputs(s.set(address).padTo(21).append(' '), f); if (flags & CHK_SHOW_HASH) fputs(s.set(hash).padTo(20).append(' '), f); if (!ep.getAttached_isNull() && (flags & CHK_SHOW_ATTACH)) fputs(ep.getAttached() ? "Attached " : "Detached ", f); fputs((status && *status) ? status : "No-Status", f); fputs("\n", f); } }
bool extractEclCmdOption(bool & option, IProperties * globals, const char * envName, const char * propertyName, bool defval) { StringBuffer temp; bool ret = extractEclCmdOption(temp, globals, envName, propertyName, defval ? "1" : "0", NULL); option=(streq(temp.str(),"1")||strieq(temp.str(),"true")); return ret; }
const StringBuffer &CEspApplicationPort::getTitleBarHtml(IEspContext& ctx, bool rawXml) { if (xslp) { VStringBuffer titleBarXml("<EspHeader><BuildVersion>%s</BuildVersion><ConfigAccess>%d</ConfigAccess>", build_ver, viewConfig); const char* authMethod = ctx.getAuthenticationMethod(); if (authMethod && !strieq(authMethod, "none") && (ctx.getDomainAuthType() != AuthPerRequestOnly)) titleBarXml.append("<LogOut>1</LogOut>"); const char* user = ctx.queryUserId(); if (user && *user) titleBarXml.appendf("<LoginId>%s</LoginId>", user); titleBarXml.append("</EspHeader>"); if (rawXml) { titleBarHtml.set(titleBarXml); } else { Owned<IXslTransform> xform = xslp->createXslTransform(); xform->loadXslFromFile(StringBuffer(getCFD()).append("./xslt/espheader.xsl").str()); xform->setXmlSource(titleBarXml.str(), titleBarXml.length()+1); xform->transform(titleBarHtml.clear()); } } return titleBarHtml; }
void CCassandraLogAgent::ensureTransSeedTable() { //Create transaction seed table as needed StringBuffer transSeedTableKeys; StringArray transSeedTableColumnNames, transSeedTableColumnTypes; transSeedTableColumnNames.append("id"); transSeedTableColumnTypes.append("int"); transSeedTableColumnNames.append("application"); transSeedTableColumnTypes.append("varchar"); transSeedTableKeys.set("application"); //primary keys //The defaultDB has transactions table. setSessionOptions(defaultDB.str()); cassSession->connect(); createTable(defaultDB.str(), transactionTable.str(), transSeedTableColumnNames, transSeedTableColumnTypes, transSeedTableKeys.str()); unsigned id = 0; VStringBuffer st("SELECT id FROM %s LIMIT 1;", transactionTable.str()); if (!executeSimpleSelectStatement(st.str(), id)) { st.setf("INSERT INTO %s (id, application) values ( 10000, '%s');", transactionTable.str(), loggingTransactionApp.get()); executeSimpleStatement(st.str()); if (!strieq(defaultTransactionApp.get(), loggingTransactionApp.get())) { st.setf("INSERT INTO %s (id, application) values ( 10000, '%s');", transactionTable.str(), defaultTransactionApp.get()); executeSimpleStatement(st.str()); } } cassSession->disconnect(); }
/* * Process parameter name on command line */ int do_para(char *name) { int ret = FALSE; /* List of =name for fixed cf_* functions */ static struct st_parafunc { char *name; char *(*func)(void); } fixed[] = { { "=fqdn", cf_fqdn }, { "=hostname", cf_hostname }, { "=domainname", cf_domainname }, { "=hostsdomain", cf_hostsdomain }, { "=libdir", cf_p_libdir }, { "=spooldir", cf_p_spooldir }, { "=logdir", cf_p_logdir }, { "=inbound", cf_p_inbound }, { "=pinbound", cf_p_pinbound }, { "=uuinbound", cf_p_uuinbound }, { "=outbound", cf_p_btbasedir }, { NULL , NULL } }; /* Fixed parameter */ if(*name == '=') { struct st_parafunc *p; for(p=fixed; p->name; p++) if(strieq(p->name, name)) { if(!n_flag) printf("%s%s", p->func(), l_flag ? "" : "\n"); ret = TRUE; break; } } /* Arbitrary parameter */ else { char *p; if( (p = cf_get_string(name, TRUE)) ) { BUF_EXPAND(buffer, p); if(!n_flag) printf("%s%s", buffer, l_flag ? "" : "\n"); ret = TRUE; } } if(t_flag) printf("%s%s", ret ? "1" : "0", l_flag ? "" : "\n"); return ret; }
void CCassandraLogAgent::addField(CLogField& logField, const char* name, StringBuffer& value, StringBuffer& fields, StringBuffer& values) { const char* fieldType = logField.getType(); if(strieq(fieldType, "int")) { appendFieldInfo(logField.getMapTo(), value, fields, values, false); return; } if(strieq(fieldType, "raw")) { appendFieldInfo(logField.getMapTo(), value, fields, values, true);; return; } if(strieq(fieldType, "varchar") || strieq(fieldType, "text")) { if(fields.length() != 0) fields.append(','); fields.append(logField.getMapTo()); if(values.length() != 0) values.append(','); values.append('\''); const char* str = value.str(); int length = value.length(); for(int i = 0; i < length; i++) { unsigned char c = str[i]; if(c == '\t' || c == '\n' || c== '\r') values.append(' '); else if(c == '\'') values.append('"'); else if(c < 32 || c > 126) values.append('?'); else values.append(c); } values.append('\''); return; } DBGLOG("Unknown format %s", fieldType); }
void LogAnalyzer::run() { // la_log(LOG_INFO, "loganalyzer starting: built " __DATE__ " " __TIME__); // signal(SIGHUP, sighup_handler); init_config(); if (_show_version_information) { show_version_information(); exit(0); } if (_do_list_analyzers) { list_analyzers(); exit(0); } expand_names_to_run(); if (_use_telem_forwarder) { return run_live_analysis(); } if (_paths == NULL) { usage(); exit(1); } output_style = Analyze::OUTPUT_JSON; if (output_style_string != NULL) { output_style = Analyze::OUTPUT_JSON; if (strieq(output_style_string, "json")) { output_style = Analyze::OUTPUT_JSON; } else if(strieq(output_style_string, "plain-text")) { output_style = Analyze::OUTPUT_PLAINTEXT; } else if(strieq(output_style_string, "brief")) { output_style = Analyze::OUTPUT_BRIEF; } else if(strieq(output_style_string, "html")) { output_style = Analyze::OUTPUT_HTML; } else { usage(); exit(1); } } if (forced_format_string != NULL) { if (strieq(forced_format_string, "tlog")) { _force_format = log_format_tlog; } else if(strieq(forced_format_string, "df")) { _force_format = log_format_df; } else if(strieq(forced_format_string, "log")) { _force_format = log_format_log; } else { usage(); exit(1); } } for (uint8_t i=0; i<_pathcount; i++) { parse_path(_paths[i]); } }
WuAttr queryWuAttribute(const char * kind) { //MORE: This needs to use a hash table for (unsigned i=WANone; i < WAMax; i++) { if (strieq(kind, attrInfo[i-WANone].name)) return (WuAttr)i; } return WANone; }
static BOOL StringTimeNodeExists(StringTimeNode *head, char *s) { StringTimeNode *curr = head; while (curr) { if (strieq(curr->s, s)) return TRUE; curr = curr->next; } return FALSE; }
extern WORKUNIT_API WuAttr queryGraphAttrToWuAttr(const char * name) { //MORE: Create a hash table to implement this mapping efficiently for(unsigned i=1; i < WAMax-WANone; i++) { const WuAttrInfo & info = attrInfo[i]; const char * path = info.graphPath; if (path[0] == '@' && strieq(name, path+1)) return (WuAttr)(i+WANone); } return WANone; }
void FileFormat::updateMarkupType(const char *rowLocator, const char *kind) { if (kind) { if (strieq(kind, "xml")) markup = FMTxml; else if (strieq(kind, "json")) markup = FMTjson; else markup = FMTunknown; } else if (rowLocator) { if (rowLocationIsPath(rowLocator)) markup = FMTjson; else markup = FMTxml; } else markup = FMTunknown; }
extern WORKUNIT_API WuAttr queryGraphChildAttToWuAttr(const char * name) { //MORE: Create a hash table to implement this mapping efficiently for(unsigned i=1; i < WAMax-WANone; i++) { const WuAttrInfo & info = attrInfo[i]; const char * childPath = info.childPath; if (childPath && strieq(name, childPath)) return (WuAttr)(i+WANone); } return WANone; }
void LogAnalyzer::create_vehicle_from_commandline_arguments() { if (_model_string != NULL) { if (strieq(_model_string,"copter")) { _vehicle = new AnalyzerVehicle::Copter(); // _analyze->set_vehicle_copter(); if (_frame_string != NULL) { ((AnalyzerVehicle::Copter*)_vehicle)->set_frame(_frame_string); } } else if (strieq(_model_string,"plane")) { _vehicle = new AnalyzerVehicle::Plane(); // } else if (streq(model_string,"rover")) { // model = new AnalyzerVehicle::Rover(); } else { la_log(LOG_ERR, "Unknown model type (%s)", _model_string); exit(1); } _vehicle->set_vehicletype_is_forced(true); } else if (_frame_string != NULL) { la_log(LOG_ERR, "Can not specify frame type without specifying model type"); exit(1); } }
// general-header = Cache-Control ; Section 14.9 // | Connection ; Section 14.10 // | Date ; Section 14.18 // | Pragma ; Section 14.32 // | Trailer ; Section 14.40 // | Transfer-Encoding ; Section 14.41 // | Upgrade ; Section 14.42 // | Via ; Section 14.45 // | Warning ; Section 14.46 // // request-header = Accept ; Section 14.1 // | Accept-Charset ; Section 14.2 // | Accept-Encoding ; Section 14.3 // | Accept-Language ; Section 14.4 // | Authorization ; Section 14.8 // | Expect ; Section 14.20 // | From ; Section 14.22 // | Host ; Section 14.23 // | If-Match ; Section 14.24 // | If-Modified-Since ; Section 14.25 // | If-None-Match ; Section 14.26 // | If-Range ; Section 14.27 // | If-Unmodified-Since ; Section 14.28 // | Max-Forwards ; Section 14.31 // | Proxy-Authorization ; Section 14.34 // | Range ; Section 14.35 // | Referer ; Section 14.36 // | TE ; Section 14.39 // | User-Agent ; Section 14.43 // // response-header = Accept-Ranges ; Section 14.5 // | Age ; Section 14.6 // | ETag ; Section 14.19 // | Location ; Section 14.30 // | Proxy-Authenticate ; Section 14.33 // | Retry-After ; Section 14.37 // | Server ; Section 14.38 // | Vary ; Section 14.44 // | WWW-Authenticate ; Section 14.47 // // entity-header = Allow ; Section 14.7 // | Content-Encoding ; Section 14.11 // | Content-Language ; Section 14.12 // | Content-Length ; Section 14.13 // | Content-Location ; Section 14.14 // | Content-MD5 ; Section 14.15 // | Content-Range ; Section 14.16 // | Content-Type ; Section 14.17 // | Expires ; Section 14.21 // | Last-Modified ; Section 14.29 // | extension-header // // extension-header = message-header static int http_header_handler(struct http_context *ctx, size_t npos, size_t vpos) { // TODO: // RFC-2616 4.2 Message Headers p22 // Multiple message-header fields with the same field-name MAY be present in a message const char* name = ctx->raw + npos; const char* value = ctx->raw + vpos; if(0 == stricmp("Content-Length", name)) { // H4.4 Message Length, section 3, ignore content-length if in chunked mode if(is_transfer_encoding_chunked(ctx)) ctx->content_length = -1; else ctx->content_length = atoi(value); assert(ctx->content_length >= 0 && (0==s_body_max_size || ctx->content_length < (int)s_body_max_size)); } else if(0 == stricmp("Connection", name)) { ctx->connection = strieq("close", value) ? 1 : 0; } else if(0 == stricmp("Content-Encoding", name)) { // gzip/compress/deflate/identity(default) ctx->content_encoding = (int)vpos; } else if(0 == stricmp("Transfer-Encoding", name)) { ctx->transfer_encoding = (int)vpos; if(0 == strnicmp("chunked", value, 7)) { // chunked can't use with content-length // H4.4 Message Length, section 3, assert(-1 == ctx->content_length); ctx->raw[ctx->transfer_encoding + 7] = '\0'; // ignore parameters } } else if(0 == stricmp("Set-Cookie", name)) { // TODO: Multiple Set-Cookie headers ctx->cookie = (int)vpos; } else if(0 == stricmp("Location", name)) { ctx->location = (int)vpos; } return 0; }
IPropertyTree *CEsdlSvcEngine::createTargetContext(IEspContext &context, IPropertyTree *tgtcfg, IEsdlDefService &srvdef, IEsdlDefMethod &mthdef, IPropertyTree *req_pt) { const char *querytype = tgtcfg->queryProp("@querytype"); if (!querytype || !strieq(querytype, "ROXIE")) //only roxie? return NULL; StringBuffer trxid; generateTransactionId(context, trxid); Owned<IPropertyTree> localCtx(createPTreeFromIPT(m_service_ctx, ipt_none)); ensurePTree(localCtx, "Row/Common"); localCtx->setProp("Row/Common/TransactionId", trxid.str()); return localCtx.getLink(); }
int VMsgLog::findHelpFile( const char *file, WSystemHelp **hobj, int from ) { if( strlen( file ) > 0 ) { int hcount = _helpList.count(); if( hcount > 0 ) { WFileName f( file ); while( from < hcount ) { WSystemHelp *shf = (WSystemHelp *)_helpList[from++]; if( strieq( shf->getHelpTitle(), f.ext() ) ) { if( hobj ) *hobj = shf; return( from ); } } } } return( 0 ); }
/* * Read list of aliases from LIBDIR/ALIASES file. * * Format: * ALIAS NODE "FULL NAME" */ static Alias *alias_parse_line(char *buf) { Alias *p; char *u, *n, *f; Node node; char *un, *ud; u = xstrtok(buf, " \t"); /* User name */ n = xstrtok(NULL, " \t"); /* FTN node */ f = xstrtok(NULL, " \t"); /* Full name */ if(u==NULL || n==NULL) return NULL; if(strieq(u, "include")) { alias_do_file(n); return NULL; } if(f==NULL) return NULL; if( asc_to_node(n, &node, FALSE) == ERROR ) { logit("hosts: illegal FTN address %s", n); return NULL; } p = (Alias *)xmalloc(sizeof(Alias)); p->next = NULL; p->node = node; un = xstrtok(u, "@"); /* User name */ ud = xstrtok(NULL, " \t"); /* User domain */ p->username = strsave(un); p->userdom = ud ? strsave(ud) : NULL; p->fullname = strsave(f); if(p->userdom) debug(15, "aliases: %s@%s %s %s", p->username, p->userdom, znfp1(&p->node), p->fullname); else debug(15, "aliases: %s %s %s", p->username, znfp1(&p->node), p->fullname); return p; }
bool ResourceManager::getDuplicateResourceId(const char *srctype, const char *filename, int &id) { VStringBuffer xpath("Resource[@filename='%s']", filename); Owned<IPropertyTreeIterator> iter = manifest->getElements(xpath.str()); ForEach (*iter) { IPropertyTree &item = iter->query(); if (item.hasProp("@id")) { const char *type = item.queryProp("@type"); if (type && strieq(type, srctype)) { id=item.getPropInt("@id"); return true; } } } return false; }
static void buildJsonAppendValue(IXmlType* type, StringBuffer& out, const char* tag, const char *value, unsigned flags) { JSONField_Category ct = xsdTypeToJSONFieldCategory(type->queryName()); if (ct==JSONField_Present && (!value || !*value)) return; if (tag && *tag) out.appendf("\"%s\": ", tag); StringBuffer sample; if ((!value || !*value) && (flags & REQSF_SAMPLE_DATA)) { type->getSampleValue(sample, NULL); value = sample.str(); } if (value) { switch (ct) { case JSONField_String: appendJSONValue(out, NULL, value); break; case JSONField_Integer: appendJSONNumericString(out, value, false); break; case JSONField_Real: appendJSONNumericString(out, value, true); break; case JSONField_Boolean: if (strieq(value, "default")) out.append("null"); else appendJSONValue(out, NULL, strToBool(value)); break; case JSONField_Present: appendJSONValue(out, NULL, true); break; } } else out.append("null"); }
bool CESPServerLoggingAgent::getTransactionSeed(StringBuffer& soapreq, int& statusCode, StringBuffer& statusMessage, StringBuffer& seedID) { StringBuffer status, response; if (!sendHTTPRequest(soapreq, response, status) || !response.length() || !status.length()) throw MakeStringException(EspLoggingErrors::GetTransactionSeedFailed, "Failed to send Transaction Seed request to %s", serverUrl.str()); if (!strieq(status, "200 OK")) throw MakeStringException(EspLoggingErrors::GetTransactionSeedFailed, "%s", status.str()); Owned<IPropertyTree> pTree = createPTreeFromXMLString(response.str()); if (!pTree) throw MakeStringException(EspLoggingErrors::GetTransactionSeedFailed, "Failed to read response from %s", serverUrl.str()); statusCode = pTree->getPropInt("soap:Body/GetTransactionSeedResponse/StatusCode"); statusMessage.set(pTree->queryProp("soap:Body/GetTransactionSeedResponse/StatusMessage")); seedID.set(pTree->queryProp("soap:Body/GetTransactionSeedResponse/SeedId")); if (statusCode || !seedID.length()) throw MakeStringException(EspLoggingErrors::GetTransactionSeedFailed, "Failed to get Transaction Seed from %s", serverUrl.str()); return true; }
IEclCommand *createPackageSubCommand(const char *cmdname) { if (!cmdname || !*cmdname) return NULL; if (strieq(cmdname, "add")) return new EclCmdPackageAdd(); if (strieq(cmdname, "delete")) return new EclCmdPackageDelete(); if (strieq(cmdname, "activate")) return new EclCmdPackageActivate(); if (strieq(cmdname, "deactivate")) return new EclCmdPackageDeActivate(); if (strieq(cmdname, "info")) return new EclCmdPackageInfo(); if (strieq(cmdname, "list")) return new EclCmdPackageList(); if (strieq(cmdname, "copyFiles")) return new EclCmdPackageCopyFiles(); return NULL; }
int chain_select(int hop[], char *chainstr, int maxrem, REMAILER *remailer, int type, BUFFER *feedback) { /* hop[] is returned containing the chain as integers (0 means random like *) * chainstr is the input desired chain such as *,*,*,* * remailer is an input list of remailer details (see mix2_rlist()) */ int len = 0; int i, j, k; BUFFER *chain, *selected, *addr; chain = buf_new(); selected = buf_new(); addr = buf_new(); if (chainstr == NULL || chainstr[0] == '\0') buf_sets(chain, CHAIN); else buf_sets(chain, chainstr); /* put the chain backwards: final hop is in hop[0] */ for (i = chain->length; i >= 0; i--) if (i == 0 || chain->data[i - 1] == ',' || chain->data[i - 1] == ';' || chain->data[i - 1] == ':') { for (j = i; isspace(chain->data[j]);) /* ignore whitespace */ j++; if (chain->data[j] == '\0') break; if (chain->data[j] == '*') k = 0; #if 0 else if (isdigit(chain->data[j])) k = atoi(chain->data + j); #endif /* 0 */ else { buf_sets(selected, chain->data + j); rfc822_addr(selected, addr); buf_clear(selected); buf_getline(addr, selected); if (!selected->length) buf_sets(selected, chain->data + j); for (k = 0; k < maxrem; k++) if (((remailer[k].flags.mix && type == 0) || (remailer[k].flags.cpunk && type == 1) || (remailer[k].flags.newnym && type == 2)) && (streq(remailer[k].name, selected->data) || strieq(remailer[k].addr, selected->data) || (selected->data[0] == '@' && strifind(remailer[k].addr, selected->data)))) break; } if (k < 0 || k >= maxrem) { if (feedback != NULL) { buf_appendf(feedback, "No such remailer: %b", selected); buf_nl(feedback); } #if 0 k = 0; #else /* end of 0 */ len = -1; goto end; #endif /* else not 0 */ } hop[len++] = k; if (len >= 20) { /* array passed in is has length 20 */ if (feedback != NULL) { buf_appends(feedback, "Chain too long.\n"); } break; } if (i > 0) chain->data[i - 1] = '\0'; } end: buf_free(chain); buf_free(selected); buf_free(addr); return len; }
inline bool isPartTLK(IPropertyTree &pt) { const char *kind = pt.queryProp("@kind"); return kind&&strieq(kind,"topLevelKey"); }
inline bool isFileKey(IPropertyTree &pt) { const char *kind = pt.queryProp("@kind"); return kind&&strieq(kind,"key"); }
//-------------------------------------------------------------------------- static int idaapi callback( void * /*user_data*/, int notification_code, va_list va) { static int stage = 0; static bool is_dll; static char needed_file[QMAXPATH]; switch ( notification_code ) { case dbg_process_start: case dbg_process_attach: get_input_file_path(needed_file, sizeof(needed_file)); // no break case dbg_library_load: if ( stage == 0 ) { const debug_event_t *pev = va_arg(va, const debug_event_t *); if ( !strieq(pev->modinfo.name, needed_file) ) break; if ( notification_code == dbg_library_load ) is_dll = true; // remember the current module bounds if ( pev->modinfo.rebase_to != BADADDR ) curmod.startEA = pev->modinfo.rebase_to; else curmod.startEA = pev->modinfo.base; curmod.endEA = curmod.startEA + pev->modinfo.size; deb(IDA_DEBUG_PLUGIN, "UUNP: module space %a-%a\n", curmod.startEA, curmod.endEA); ++stage; } break; case dbg_library_unload: if ( stage != 0 && is_dll ) { const debug_event_t *pev = va_arg(va, const debug_event_t *); if ( curmod.startEA == pev->modinfo.base || curmod.startEA == pev->modinfo.rebase_to ) { deb(IDA_DEBUG_PLUGIN, "UUNP: unload unpacked module\n"); if ( stage > 2 ) enable_step_trace(false); stage = 0; curmod.startEA = 0; curmod.endEA = 0; _hide_wait_box(); } } break; case dbg_run_to: // Parameters: const debug_event_t *event dbg->stopped_at_debug_event(true); bp_gpa = get_name_ea(BADADDR, "kernel32_GetProcAddress"); #ifndef __X64__ if( (LONG)GetVersion() < 0 ) // win9x mode -- use thunk's { is_9x = true; win9x_resolve_gpa_thunk(); } #endif if ( bp_gpa == BADADDR ) { bring_debugger_to_front(); warning("Sorry, could not find kernel32.GetProcAddress"); FORCE_STOP: stage = 4; // last stage clear_requests_queue(); request_exit_process(); run_requests(); break; } else if( !my_add_bpt(bp_gpa) ) { bring_debugger_to_front(); warning("Sorry, can not set bpt to kernel32.GetProcAddress"); goto FORCE_STOP; } else { ++stage; set_wait_box("Waiting for a call to GetProcAddress()"); } continue_process(); break; case dbg_bpt: // A user defined breakpoint was reached. // Parameters: thid_t tid // ea_t breakpoint_ea // int *warn = -1 // Return (in *warn): // -1 - to display a breakpoint warning dialog // if the process is suspended. // 0 - to never display a breakpoint warning dialog. // 1 - to always display a breakpoint warning dialog. { thid_t tid = va_arg(va, thid_t); qnotused(tid); ea_t ea = va_arg(va, ea_t); //int *warn = va_arg(va, int*); if ( stage == 2 ) { if ( ea == bp_gpa ) { regval_t rv; if ( get_reg_val(REGNAME_ESP, &rv) ) { ea_t esp = ea_t(rv.ival); invalidate_dbgmem_contents(esp, 1024); ea_t gpa_caller = getPtr(esp); if ( !is_library_entry(gpa_caller) ) { ea_t nameaddr; if ( ptrSz == 4 ) { nameaddr = get_long(esp+8); } else { get_reg_val(REGNAME_ECX, &rv); nameaddr = ea_t(rv.ival); } invalidate_dbgmem_contents(nameaddr, 1024); char name[MAXSTR]; size_t len = get_max_ascii_length(nameaddr, ASCSTR_C, ALOPT_IGNHEADS); name[0] = '\0'; get_ascii_contents2(nameaddr, len, ASCSTR_C, name, sizeof(name)); if ( !ignore_win32_api(name) ) { deb(IDA_DEBUG_PLUGIN, "%a: found a call to GetProcAddress(%s)\n", gpa_caller, name); if ( !my_del_bpt(bp_gpa) || !my_add_bpt(gpa_caller) ) error("Can not modify breakpoint"); } } } } else if ( ea == bpt_ea ) { my_del_bpt(ea); if ( !is_library_entry(ea) ) { msg("Uunp: reached unpacker code at %a, switching to trace mode\n", ea); enable_step_trace(true); ++stage; uint64 eax; if ( get_reg_val(REGNAME_EAX, &eax) ) an_imported_func = ea_t(eax); set_wait_box("Waiting for the unpacker to finish"); } else { warning("%a: bpt in library code", ea); // how can it be? my_add_bpt(bp_gpa); } } // not our bpt? skip it else { // hide the wait box to allow others plugins to properly stop _hide_wait_box(); break; } } } // while continue_process() would work here too, request+run is more universal // because they do not ignore the request queue request_continue_process(); run_requests(); break; case dbg_trace: // A step occured (one instruction was executed). This event // notification is only generated if step tracing is enabled. // Parameter: none if ( stage == 3 ) { thid_t tid = va_arg(va, thid_t); qnotused(tid); ea_t ip = va_arg(va, ea_t); // ip reached the OEP range? if ( oep_area.contains(ip) ) { // stop the trace mode enable_step_trace(false); msg("Uunp: reached OEP %a\n", ip); set_wait_box("Reanalyzing the unpacked code"); // reanalyze the unpacked code do_unknown_range(oep_area.startEA, oep_area.size(), DOUNK_EXPAND); auto_make_code(ip); // plan to make code noUsed(oep_area.startEA, oep_area.endEA); // plan to reanalyze auto_mark_range(oep_area.startEA, oep_area.endEA, AU_FINAL); // plan to analyze move_entry(ip); // mark the program's entry point _hide_wait_box(); // inform the user bring_debugger_to_front(); if ( askyn_c(1, "HIDECANCEL\n" "The universal unpacker has finished its work.\n" "Do you want to take a memory snapshot and stop now?\n" "(you can do it yourself if you want)\n") > 0 ) { set_wait_box("Recreating the import table"); invalidate_dbgmem_config(); if ( is_9x ) find_thunked_imports(); create_impdir(); set_wait_box("Storing resources to 'resource.res'"); if ( resfile[0] != '\0' ) extract_resource(resfile); _hide_wait_box(); if ( take_memory_snapshot(true) ) goto FORCE_STOP; } suspend_process(); unhook_from_notification_point(HT_DBG, callback, NULL); } } break; case dbg_process_exit: { stage = 0; // stop the tracing _hide_wait_box(); unhook_from_notification_point(HT_DBG, callback, NULL); if ( success ) jumpto(inf.beginEA, -1); else tell_about_failure(); } break; case dbg_exception:// Parameters: const debug_event_t *event // int *warn = -1 // Return (in *warn): // -1 - to display an exception warning dialog // if the process is suspended. // 0 - to never display an exception warning dialog. // 1 - to always display an exception warning dialog. { // const debug_event_t *event = va_arg(va, const debug_event_t *); // int *warn = va_arg(va, int *); // FIXME: handle code which uses SEH to unpack itself if ( askyn_c(1, "AUTOHIDE DATABASE\n" "HIDECANCEL\n" "An exception occurred in the program.\n" "UUNP does not support exceptions yet.\n" "The execution has been suspended.\n" "Do you want to continue the unpacking?") <= 0 ) { _hide_wait_box(); stage = 0; enable_step_trace(false); // stop the trace mode suspend_process(); } else { continue_process(); } } break; case dbg_request_error: // An error occured during the processing of a request. // Parameters: ui_notification_t failed_command // dbg_notification_t failed_dbg_notification { ui_notification_t failed_cmd = va_arg(va, ui_notification_t); dbg_notification_t failed_dbg_notification = va_arg(va, dbg_notification_t); _hide_wait_box(); stage = 0; warning("dbg request error: command: %d notification: %d", failed_cmd, failed_dbg_notification); } break; } return 0; }