/* ### * IP: GHIDRA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ifacedecomp.hh" namespace ghidra { void FunctionTestProperty::startTest(void) const { count = 0; patnum = 0; } void FunctionTestProperty::processLine(const string &line) const { if (std::regex_search(line,pattern[patnum])) { patnum += 1; if (patnum >= pattern.size()) { count += 1; // Full pattern has matched. Count it. patnum = 0; } } else if (patnum > 0) { patnum = 0; // Abort current multi-line match, restart trying to match first line if (std::regex_search(line,pattern[patnum])) { patnum += 1; } } } bool FunctionTestProperty::endTest(void) const { return (count >= minimumMatch && count <= maximumMatch); } void FunctionTestProperty::restoreXml(const Element *el) { name = el->getAttributeValue("name"); istringstream s1(el->getAttributeValue("min")); s1 >> minimumMatch; istringstream s2(el->getAttributeValue("max")); s2 >> maximumMatch; string::size_type pos = 0; const string &line(el->getContent()); do { while(pos < line.size() && (line[pos] == ' ' || line[pos] == '\t')) // Remove whitespace at front of pattern pos += 1; if (pos >= line.size()) break; string::size_type nextpos = line.find('\n',pos); // A newline in the pattern indicates a multi-line regex string::size_type n; if (nextpos == string::npos) n = string::npos; // If no (additional) newlines, take all remaining chars else { n = nextpos - pos; // Create a line regex upto newline char nextpos += 1; // Skip newline when creating next line regex } pattern.emplace_back(line.substr(pos, n)); // Add a regex to list of lines to match pos = nextpos; } while(pos != string::npos); } void ConsoleCommands::readLine(string &line) { if (pos >= commands.size()) { line.clear(); return; } line = commands[pos]; pos += 1; } /// \param s is the stream where command output is printed /// \param comms is the list of commands to be issued ConsoleCommands::ConsoleCommands(ostream &s,vector &comms) : IfaceStatus("> ", s), commands(comms) { pos = 0; IfaceCapability::registerAllCommands(this); } void ConsoleCommands::reset(void) { pos = 0; inerror = false; done = false; } void FunctionTestCollection::clear(void) { dcp->clearArchitecture(); commands.clear(); testList.clear(); console->reset(); } /// \param el is the root \