grep working

This commit is contained in:
Michel Oosterhof 2018-07-15 13:39:40 +04:00
parent e5a7600b31
commit f049877cca
2 changed files with 25 additions and 10 deletions

View File

@ -35,19 +35,19 @@ class command_grep(HoneyPotCommand):
def grep_application(self, contents, match):
match = os.path.basename(match)
match = match.replace("\"", "")
contentsplit = contents.split('\n')
matches = re.compile(".*" + match + ".*")
match = match.replace('\"', '')
contentsplit = contents.split(b'\n')
matches = re.compile('.*' + match + '.*')
for line in contentsplit:
if matches.match(line):
self.write(line + '\n')
if matches.match(line.decode()):
self.writeBytes(line + b'\n')
def help(self):
self.write('usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n')
self.write('\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n')
self.write('\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n')
self.write('\t[--null] [pattern] [file ...]\n')
self.writeBytes(b'usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n')
self.writeBytes(b'\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n')
self.writeBytes(b'\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n')
self.writeBytes(b'\t[--null] [pattern] [file ...]\n')
def start(self):
@ -73,7 +73,7 @@ class command_grep(HoneyPotCommand):
self.help()
if not self.input_data:
files = self.check_arguments("grep", args[1:])
files = self.check_arguments('grep', args[1:])
for pname in files:
self.grep_get_contents(pname, args[0])
else:

View File

@ -97,5 +97,20 @@ class ShellEchoCommandTests(unittest.TestCase):
self.assertEquals(self.tr.value(), b'test\ntest\n' + PROMPT)
def test_echo_command_9(self):
"""
echo test | grep test
"""
self.proto.lineReceived(b'echo test | grep test')
self.assertEquals(self.tr.value(), b'test\n' + PROMPT)
def test_echo_command_9(self):
"""
echo test | grep test
"""
self.proto.lineReceived(b'echo test | grep test2')
self.assertEquals(self.tr.value(), PROMPT)
def tearDown(self):
self.proto.connectionLost("tearDown From Unit Test")