| 187 | } |
| 188 | |
| 189 | void Preference::patchOperate(const OperatePtr &opt) { |
| 190 | if (!this->_doInputFuzzing) |
| 191 | return; |
| 192 | |
| 193 | // input texts |
| 194 | char prelog[30]; |
| 195 | std::srand((unsigned int) std::time(nullptr)); |
| 196 | if (opt->editable && opt->getText().empty() |
| 197 | && (opt->act == ActionType::CLICK || opt->act == ActionType::LONG_CLICK)) { |
| 198 | if (this->_randomInputText && |
| 199 | this->_inputTexts.size() > 0) { |
| 200 | int randIdx = randomInt(0, (int) this->_inputTexts.size()); |
| 201 | std::string &txt = this->_inputTexts[randIdx]; |
| 202 | opt->setText(txt); |
| 203 | strcpy(prelog, "user preset strings"); |
| 204 | } else { |
| 205 | float rate = randomInt(0, 100); |
| 206 | if (!this->_fuzzingTexts.empty() && rate < 50) { |
| 207 | int randIdx = randomInt(0, (int) this->_fuzzingTexts.size()); |
| 208 | std::string &txt = this->_fuzzingTexts[randIdx]; |
| 209 | opt->setText(txt); |
| 210 | strcpy(prelog, "fuzzing text"); |
| 211 | } else if (rate < 85) { |
| 212 | int randIdx = randomInt(0, (int) this->_pageTextsCache.size()); |
| 213 | std::string &txt = this->_pageTextsCache[randIdx]; |
| 214 | opt->setText(txt); |
| 215 | strcpy(prelog, "page text"); |
| 216 | } |
| 217 | } |
| 218 | BLOG("patch %s input text: %s", prelog, opt->getText().c_str()); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /// Before exploring page, prune the UI tree of this page if possible |
| 223 | /// \param activity |