/** * Return a string describing Research progress. * @return a string describing Research progress. */ std::string ResearchProject::getResearchProgress() const { float progress = (float)getSpent() / getRules()->getCost(); if (getAssigned() == 0) { return "STR_NONE"; } else if (progress < PROGRESS_LIMIT_UNKNOWN) { return "STR_UNKNOWN"; } else { float rating = (float)getAssigned(); rating /= getRules()->getCost(); if (rating < PROGRESS_LIMIT_POOR) { return "STR_POOR"; } else if (rating < PROGRESS_LIMIT_AVERAGE) { return "STR_AVERAGE"; } else if (rating < PROGRESS_LIMIT_GOOD) { return "STR_GOOD"; } return "STR_EXCELLENT"; } }
void Production::save(YAML::Emitter &out) { out << YAML::BeginMap; out << YAML::Key << "item" << YAML::Value << getRules ()->getName (); out << YAML::Key << "assigned" << YAML::Value << getAssignedEngineers (); out << YAML::Key << "spent" << YAML::Value << getTimeSpent (); out << YAML::Key << "amount" << YAML::Value << getAmountTotal (); out << YAML::EndMap; }
/** * Saves the research project to a YAML file. * @return YAML node. */ YAML::Node ResearchProject::save() const { YAML::Node node; node["project"] = getRules()->getName(); node["assigned"] = getAssigned(); node["spent"] = getSpent(); node["cost"] = getCost(); return node; }
YAML::Node Production::save() const { YAML::Node node; node["item"] = getRules ()->getName (); node["assigned"] = getAssignedEngineers (); node["spent"] = getTimeSpent (); node["amount"] = getAmountTotal (); return node; }
void script::parseStringScript(std::string in) { //FIX: Do we really need 4 functions when they all run at the same time anyway? getVariables(in); getFunctions(in); getRules(in); findSeed(in); rawStorage = seed; }
YAML::Node Production::save() const { YAML::Node node; node["item"] = getRules()->getName(); node["assigned"] = getAssignedEngineers(); node["spent"] = getTimeSpent(); node["amount"] = getAmountTotal(); node["infinite"] = getInfiniteAmount(); if (getSellItems()) node["sell"] = getSellItems(); return node; }
Format* RuleBasedNumberFormat::clone(void) const { RuleBasedNumberFormat * result = NULL; UnicodeString rules = getRules(); UErrorCode status = U_ZERO_ERROR; UParseError perror; result = new RuleBasedNumberFormat(rules, localizations, locale, perror, status); /* test for NULL */ if (result == 0) { status = U_MEMORY_ALLOCATION_ERROR; return 0; } if (U_FAILURE(status)) { delete result; result = 0; } else { result->lenient = lenient; } return result; }
void script::getRules(std::string in, unsigned startPos) { //Find first instance of "rule" in the string startPos = in.find("rule", startPos); if(startPos != std::string::npos) { //If not at end of string, we have found a rule, get corresponding variable by the fact that it is always 4 characters away from "rule" char varName = in.at(startPos+4); //Find the start of the replace string by finding the first "(" unsigned replaceStart = in.find_first_of("(", startPos); //Find the end of the replace string by finding the first ")" unsigned replaceEnd = in.find_first_of(")", startPos); //Find the replace string by clamping from replaceStart to replaceEnd std::string replaceString = in.substr(replaceStart+1, replaceEnd-replaceStart-1); //Put the rule in the vector for rules in the script class rules.push_back(rule(varName, replaceString)); //Function runs itself from the point after the found rule getRules(in, replaceEnd+1); } //If we are here we have found all the rules in the script and should exit }
void Country::newMonth(int xcomTotal, int alienTotal) { _satisfaction = 2; int funding = getFunding().back(); int good = (xcomTotal / 10) + _activityXcom.back(); int bad = (alienTotal / 20) + _activityAlien.back(); int oldFunding = _funding.back() / 1000; int newFunding = (oldFunding * RNG::generate(5, 20) / 100) * 1000; if (bad <= good + 30) { if (good > bad + 30) { if (RNG::generate(0, good) > bad) { // don't go over the cap int cap = getRules()->getFundingCap()*1000; if (funding + newFunding > cap) newFunding = cap - funding; if (newFunding) _satisfaction = 3; } } } else { if (RNG::generate(0, bad) > good) { if (newFunding) { newFunding = -newFunding; _satisfaction = 1; } } } // about to be in cahoots if(_newPact && !_pact) { _newPact = false; _pact = true; addActivityAlien(150); } // set the new funding and reset the activity meters if(_pact) _funding.push_back(0); else if (_satisfaction != 2) _funding.push_back(funding + newFunding); else _funding.push_back(funding); _activityAlien.push_back(0); _activityXcom.push_back(0); if(_activityAlien.size() > 12) _activityAlien.erase(_activityAlien.begin()); if(_activityXcom.size() > 12) _activityXcom.erase(_activityXcom.begin()); if(_funding.size() > 12) _funding.erase(_funding.begin()); }
int Ngn_Hashcat::run () { Application& app = Application::instance(); DJob *job = DJob::Instance(); string cmd; string hashcat(dengine->getBinaryPath("hashcat")); int eCode(-1); // clean results _results = string(""); // grab settings from job setAttackMode(job->getAttackMode()); setHashType(job->getHashType()); setMask(job->getMask()); setRules(job->getRules()); setDictionary(job->getDictionary()); setPot("disthc.pot"); // clean pot before working File f(getPot()); if(f.exists()) { f.remove(); } // setup command prefix (format command takes 7 args max) cmd = format("%s -o %s -s %lu -l %u", hashcat, getPot(), job->getChunk(), job->getChunkSize() ); // Attack modes: // 0 = Straight // 1 = Combination // 2 = Toggle-Case // 3 = Brute-force // 4 = Permutation // 5 = Table-Lookup // if mask minimum set, apply it if(job->getMaskMin()) { cmd = format("%s --pw-min %d", cmd, job->getMaskMin() ); } // if mask maximum set, apply it if(job->getMaskMax()) { cmd = format("%s --pw-min %d", cmd, job->getMaskMax() ); } // discover attack mode and create command to execute switch(getAttackMode()) { case 3: cmd = format("%s -a3 -m %d %s %s %s", cmd, getHashType(), getFlags(), getHashFile(), getMask() ); break; default: // default command uses attack mode 0 cmd = format("%s -m %d %s %s %s %s", cmd, getHashType(), getFlags(), getHashFile(), getDictionary(), getRules() ); } if(DEBUG) app.logger().information(format("%%Running command: %s", cmd)); // check for ghosts, and run as appropriate if(isGhost()) { app.logger().information("~~~ A ghost is loose! ~~~"); app.logger().information(" .-."); app.logger().information(" (o o) boo!"); app.logger().information(" \\| O \\/"); app.logger().information(" \\ \\ "); app.logger().information(" `~~~' "); } else { // run hashcat! :) // TODO change this over to use Poco Processes eCode = system(cmd.c_str()); // check for results if(f.exists()) { FileInputStream fis(getPot()); //std::ifstream in(pot,std::ios::in); string line; while(fis >> line) { _results.append(line + "\n"); } } // TODO might take this out? // see if it's worth it to just display hashcout output during // execution // if enabled, print pot to screen // if(false) { // app.logger().information("\n=== Recovered Hashes ==="); // if(!_results.empty()) app.logger().information(_results); // app.logger().information("========================"); // } }
bool FilterManager::getUsersRules(const std::wstring & filename) { return getRules(filename,FILE_RULE_UESR); }
bool FilterManager::getVideoRules(const std::wstring & filename) { return getRules(filename,FILE_RULE_VIDEO); }
bool FilterManager::getWebRules(const std::wstring & filename) { return getRules(filename,FILE_RULE_WEB); }
int main(int argc,char** argv) { SgProject* proj = frontend(argc,argv); fixAllPrefixPostfix(proj); initializeScopeInformation(proj); SgFunctionDeclaration* mainDecl = SageInterface::findMain(proj); SgFunctionDefinition* mainDef = mainDecl->get_definition(); //SageInterface::rebuildSymbolTable(mainDef); StaticCFG::CFG cfg(mainDef); SgIncidenceDirectedGraph *g = cfg.getGraph(); PathCollector* pathCollector = new PathCollector(g,&cfg); std::vector<SgNode*> scopeNodes = NodeQuery::querySubTree(mainDef,V_SgScopeStatement); std::vector<SgGraphNode*> visited; std::vector<SgNode*> nodes = NodeQuery::querySubTree(mainDef,V_SgWhileStmt); std::vector<SgNode*>::iterator node = nodes.begin(); for (; node != nodes.end(); node++) { SgScopeStatement* scopeOfWhile = SageInterface::getEnclosingScope(*node); SgStatementPtrList statementsInScope = scopeOfWhile->getStatementList(); SgStatementPtrList::iterator statPtr = statementsInScope.begin(); std::set<SgPragmaDeclaration*> prdecls; for (; statPtr!=statementsInScope.end();statPtr++) { if (isSgPragmaDeclaration(*statPtr)) { prdecls.insert(isSgPragmaDeclaration(*statPtr)); } } //SgExprStatement* boundingConditionStatement = isSgExprStatement(isSgWhileStmt(*node)->get_condition()); //SgExpression* boundingCondition = boundingConditionStatement->get_expression(); SgStatement* body = (isSgWhileStmt(*node)->get_body()); std::vector<std::vector<SgGraphNode*> > paths = pathCollector->getPaths(); std::cout << getPrelude() << std::endl; SgGraphNode* whileStart = cfg.cfgForBeginning(isSgWhileStmt(*node)); SgGraphNode* whileEnd = cfg.cfgForEnd(isSgWhileStmt(*node)); collectPaths(whileStart,whileEnd, pathCollector); SgGraphNode* whileOut = getWhileEndNode(isSgWhileStmt(*node),pathCollector); SgGraphNode* bodyStart = cfg.cfgForBeginning(isSgWhileStmt(*node)->get_body()); SgGraphNode* bodyEnd = cfg.cfgForEnd(isSgWhileStmt(*node)->get_body()); pathCollector->clearPaths(); collectPaths(bodyStart,whileOut,pathCollector); paths.clear(); paths = pathCollector->getPaths(); std::vector<std::vector<SgGraphNode*> >::iterator i = paths.begin(); std::set<SgVariableSymbol*> vars = getVars(pathCollector); std::string vardecls; std::string initrule; std::vector<std::string> rules= getRules(*node,pathCollector, vars, vardecls,initrule); std::cout << vardecls << std::endl; for (int i = 0; i < rules.size(); i++) { std::cout << rules[i] << std::endl; } std::set<SgPragmaDeclaration*>::iterator pr = prdecls.begin(); for (; pr != prdecls.end(); pr++) { std::set<std::string> variables; std::vector<std::string> s_expressions; std::string prag_str = get_pragma_string(*pr); bool initPrag; /*std::string rhs =*/ translateToS_Expr(prag_str,variables,s_expressions,initPrag); if (s_expressions.size() > 0) { std::string queryResult; if (initPrag) { queryResult = assumptionPragma(s_expressions,initrule); } else { queryResult = queryPragma(s_expressions,initrule); } std::cout << queryResult << std::endl; } } } backend(proj); return 0; }
BottomLang::BottomLang(const CondLang &clang) { // atoms { auto range=clang.getAtoms(); auto atoms=createAtoms(range.len); for(; +atoms ;++atoms,++range) { atoms->index=range->index; atoms->name=pool.dup(range->name); } } // synts { auto range=clang.getSynts(); auto synts=createSynts(range.len); for(; +synts ;++synts,++range) { synts->index=range->index; synts->name=pool.dup(range->name); synts->is_lang=range->is_lang; } } // rules { auto range=clang.getRules(); auto rules=createRules(range.len); for(; +rules ;++rules,++range) { rules->index=range->index; rules->name=pool.dup(range->name); } } // synts.rules { auto range=clang.getSynts(); auto synts=this->synts; ulen off=0; auto rules=getRules(); for(; +synts ;++synts,++range) { ulen len=range->rules.len; synts->rules=rules.part(off,len); off+=len; } } // rules.ret rules.args { auto range=clang.getRules(); auto rules=this->rules; auto atoms=getAtoms(); auto synts=getSynts(); for(; +rules ;++rules,++range) { rules->ret=&(synts[range->ret->index]); auto arange=range->args; auto args=createElements(*rules,arange.len); for(; +args ;++args,++arange) { arange->apply( [=] (const CondLangBase::AtomDesc *atom) { args->ptr=&(atoms[atom->index]); } , [=] (const CondLangBase::SyntDesc *synt) { args->ptr=&(synts[synt->index]); } ); } } } pool.shrink_extra(); }