/** Write ELF contents back to a file. */ void SgAsmElfFileHeader::unparse(std::ostream &f) const { /* Write unreferenced areas back to the file before anything else. */ unparse_holes(f); /* Write the ELF segment table and segments first since they generally overlap with more specific things which may have * been modified when walking the AST. (We generally don't modify segments, just the more specific sections.) */ if (p_segment_table) { ROSE_ASSERT(p_segment_table->get_header()==this); p_segment_table->unparse(f); } /* Write the ELF section table and, indirectly, the sections themselves. */ if (p_section_table) { ROSE_ASSERT(p_section_table->get_header()==this); p_section_table->unparse(f); } /* Encode and write the ELF file header */ Elf32FileHeader_disk disk32; Elf64FileHeader_disk disk64; void *disk = NULL; size_t struct_size = 0; if (4 == get_word_size()) { disk = encode(get_sex(), &disk32); struct_size = sizeof(disk32); } else if (8 == get_word_size()) { disk = encode(get_sex(), &disk64); struct_size = sizeof(disk64); } else { ROSE_ASSERT(!"unsupported word size"); } write(f, 0, struct_size, disk); }
/* * Helper function for 'player_birth()'. * * See "display_player" for screen layout code. */ static bool player_birth_aux(void) { /* Ask questions */ if (!player_birth_aux_1()) return (FALSE); /* Point-based stats */ if (!player_birth_aux_2()) return (FALSE); /* Point-based skills */ if (!gain_skills()) return (FALSE); /* Choose sex */ if (!get_sex()) return (FALSE); /* Roll for history */ if (!get_history()) return (FALSE); /* Roll for age/height/weight */ if (!get_ahw()) return (FALSE); /* Get a name, prepare savefile */ if (!get_name()) return (FALSE); // Reset the number of artefacts p_ptr->artefacts = 0; /* Accept */ return (TRUE); }
/* Print some debugging info */ void SgAsmGenericFormat::dump(FILE *f, const char *prefix, ssize_t idx) const { char p[4096]; if (idx>=0) { snprintf(p, sizeof(p),"%sFormat[%zd].", prefix, idx); } else { snprintf(p, sizeof(p),"%sFormat.", prefix); } const int w = std::max(1, DUMP_FIELD_WIDTH-(int)strlen(p)); fprintf(f, "%s%-*s = %s\n", p, w, "family", to_string(get_family()).c_str()); fprintf(f, "%s%-*s = %s\n", p, w, "purpose", to_string(get_purpose()).c_str()); fprintf(f, "%s%-*s = %s\n", p, w, "sex", to_string(get_sex()).c_str()); fprintf(f, "%s%-*s = %u (%scurrent)\n", p, w, "version", get_version(), get_is_current_version() ? "" : "not-" ); fprintf(f, "%s%-*s = %s\n", p, w, "ABI", to_string(get_abi()).c_str()); fprintf(f, "%s%-*s = %u\n", p, w, "ABIvers", get_abi_version()); fprintf(f, "%s%-*s = %zu\n", p, w, "wordsize", get_word_size()); }
/** Update prior to unparsing */ bool SgAsmElfFileHeader::reallocate() { /* Reallocate superclass. This also calls reallocate() for all the sections associated with this ELF File Header. */ bool reallocated = SgAsmGenericHeader::reallocate(); /* Resize header based on current word size */ rose_addr_t need; if (4==get_word_size()) { need = sizeof(Elf32FileHeader_disk); } else if (8==get_word_size()) { need = sizeof(Elf64FileHeader_disk); } else { throw FormatError("unsupported ELF word size"); } if (need < get_size()) { if (is_mapped()) { ROSE_ASSERT(get_mapped_size()==get_size()); set_mapped_size(need); } set_size(need); reallocated = true; } else if (need > get_size()) { get_file()->shift_extend(this, 0, need-get_size(), SgAsmGenericFile::ADDRSP_ALL, SgAsmGenericFile::ELASTIC_HOLE); reallocated = true; } /* Update ELF-specific file class data member from generic data. */ switch(get_word_size()) { case 4: p_e_ident_file_class = 1; break; case 8: p_e_ident_file_class = 2; break; default: ROSE_ASSERT(!"invalid word size"); break; } /* Byte order. According to the spec, valid values are 1 (little-endian) and 2 (big-endian). However, we've seen cases * where a value of zero is used to indicate "native" order (loader assumes words are in the order of the machine on which * the loader is running, and the ROSE ELF parser determines the order by looking at other fields in the header). Any * original value other than 1 or 2 will be written to the new output; otherwise we choose 1 or 2 based on the currently * defined byte order. */ if (p_e_ident_data_encoding==1 || p_e_ident_data_encoding==2) { p_e_ident_data_encoding = ByteOrder::ORDER_LSB==get_sex() ? 1 : 2; } /* Update ELF-specific file type from generic data. */ switch (p_exec_format->get_purpose()) { case PURPOSE_UNSPECIFIED: case PURPOSE_PROC_SPECIFIC: case PURPOSE_OS_SPECIFIC: case PURPOSE_OTHER: /* keep as is */ break; case PURPOSE_LIBRARY: if (p_e_type==1 || p_e_type==3) { /* keep as is */ } else { p_e_type = 1; } break; case PURPOSE_EXECUTABLE: p_e_type = 2; break; case PURPOSE_CORE_DUMP: p_e_type = 4; } /* Update ELF machine type. */ p_e_machine = isa_to_machine(get_isa()); /* The ELF header stores its own size */ p_e_ehsize = get_size(); return reallocated; }
int parse_condition(const char* condition, const Json::Value& input) { if ( !condition ) { return -1; } if ( !*condition ) { return 1; } std::string o_Location; std::string o_Uid; std::string dati; nlp::nlptime o_Time; if (input.isMember("usr_id")) { o_Uid = input["usr_id"].asString(); } //o_Uid = input["usr_id"].asString(); dati = input["time"].asString(); o_Location = input["pos"].asString(); if ( dati.length() ) { o_Time.set(dati.c_str()); } else { o_Time.set(time(NULL)); } char szStringValue[1024]; //规则中的字符串型值缓存 char szNodeString[1024]; //节点中的字符串信息 float nIntValue; //规则中的整型值缓存 float nNodeInt; //节点中的整型信息 const char* pChar = condition; int nReturnValue2 = 1; //条件部分 int nFindPos; while (*pChar) { if (strchr("pu",*pChar))//char * 型:q { switch (*pChar) { case 'p'://place,地点信息 pChar ++; sprintf(szNodeString,START_END_CHAR"%s"START_END_CHAR, o_Location.c_str()); break; case 'u'://usrid pChar ++; sprintf(szNodeString,START_END_CHAR"%s"START_END_CHAR, o_Uid.c_str()); break; default: return -1; } char cOp = *pChar; if (*(pChar+1) != '\"') { return -1; } nFindPos = (int)strcspn(pChar+2,"\""); strncpy(szStringValue,pChar+2,nFindPos);//取得规则中的字符串型数据 nFindPos = (int)strcspn(pChar+2,"\""); szStringValue[nFindPos] = '\0'; //printf("%s-------%s------\n", szNodeString, szStringValue); nReturnValue2 = 1; switch (cOp) { case '{': if (smstrstr(szStringValue,szNodeString,true)==NULL) //Modified begin by zgchen ,2002-8-13 9:48:27 { nReturnValue2 = 0; } break; case '}': if (smstrstr(szNodeString,szStringValue,true)==NULL) //Modified begin by zgchen ,2002-8-13 9:48:37 { nReturnValue2 = 0; } break; case '#': //if (stricmp(szNodeString,szStringValue)) if (strcasecmp(szNodeString,szStringValue)) { nReturnValue2 = 0; } break; case '!': //Modifided begin by zgchen ,2003-3-18 11:58:39 if (*(pChar+1) == '{') //不被包括 { if (smstrstr(szStringValue,szNodeString)) { nReturnValue2 = 0; } } else if (*(pChar+1) == '}') //不包括 { if (smstrstr(szNodeString,szStringValue)) { nReturnValue2 = 0; } } else { if (!strcmp(szNodeString,szStringValue)) { nReturnValue2 = 0; } } break; //Added/Modified end by zgchen2003-3-18 11:58:43 default: //SMASSERT(0,"pChar must be in {}#"); return -1; break; } } else if (strchr("hwdse",*pChar))//int 型 { switch (*pChar) { case 'h'://小时 nNodeInt = get_time(o_Time); break; case 'w'://周几 nNodeInt = get_weekday(o_Time); break; case 'd'://日期 nNodeInt = get_date(o_Time); break; case 's'://性别 nNodeInt = get_sex(); break; case 'e'://年龄 nNodeInt = get_age(); break; default: return -1; break; } pChar ++; nIntValue = (float)atof(pChar + 1); //取得规则中的整型数据 switch (*pChar) { case '<': if (nNodeInt > nIntValue) { nReturnValue2 = 0; } break; case '>': if (nNodeInt < nIntValue) { nReturnValue2 = 0; } break; case '=': if (nNodeInt != nIntValue) { nReturnValue2 = 0; } break; case '!': if (nNodeInt == nIntValue) { nReturnValue2 = 0; } break; default: return -1; break; } } else { return -1; } if (nReturnValue2) { nFindPos = (int)strcspn(pChar,"+*"); if(pChar[nFindPos]) { if (pChar[nFindPos]=='+') { //nFindPos = strcspn(pChar,")"); pChar += strlen(pChar); } else { pChar += nFindPos + 1; } } else { pChar +=nFindPos; } } else { nFindPos = (int)strcspn(pChar,"+"); if (pChar[nFindPos]=='+') { pChar += nFindPos + 1; } else { pChar += nFindPos; } } } return nReturnValue2; }