OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding=utf-8 | 2 # coding=utf-8 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Traces an executable and its child processes and extract the files accessed | 7 """Traces an executable and its child processes and extract the files accessed |
8 by them. | 8 by them. |
9 | 9 |
10 The implementation uses OS-specific API. The native Kernel logger and the ETL | 10 The implementation uses OS-specific API. The native Kernel logger and the ETL |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 """Processes a dtrace log line and keeps the list of existent and non | 707 """Processes a dtrace log line and keeps the list of existent and non |
708 existent files accessed. | 708 existent files accessed. |
709 | 709 |
710 Ignores directories. | 710 Ignores directories. |
711 """ | 711 """ |
712 # This is the most common format. index pid function(args) = result | 712 # This is the most common format. index pid function(args) = result |
713 RE_HEADER = re.compile(r'^\d+ (\d+):(\d+) ([a-zA-Z_\-]+)\((.*?)\) = (.+)$') | 713 RE_HEADER = re.compile(r'^\d+ (\d+):(\d+) ([a-zA-Z_\-]+)\((.*?)\) = (.+)$') |
714 | 714 |
715 # Arguments parsing. | 715 # Arguments parsing. |
716 RE_CHDIR = re.compile(r'^\"(.+?)\"$') | 716 RE_CHDIR = re.compile(r'^\"(.+?)\"$') |
717 RE_OPEN = re.compile(r'^\"(.+?)\", (\d+), (\d+)$') | 717 RE_OPEN = re.compile(r'^\"(.+?)\", (\d+), (-?\d+)$') |
718 RE_RENAME = re.compile(r'^\"(.+?)\", \"(.+?)\"$') | 718 RE_RENAME = re.compile(r'^\"(.+?)\", \"(.+?)\"$') |
719 | 719 |
720 O_DIRECTORY = 0x100000 | 720 O_DIRECTORY = 0x100000 |
721 | 721 |
722 def __init__(self, blacklist): | 722 def __init__(self, blacklist): |
723 # TODO(maruel): Handling chdir() and cwd in general on OSX is tricky | 723 # TODO(maruel): Handling chdir() and cwd in general on OSX is tricky |
724 # because OSX only keeps relative directory names. In addition, cwd is a | 724 # because OSX only keeps relative directory names. In addition, cwd is a |
725 # process local variable so forks need to be properly traced and cwd | 725 # process local variable so forks need to be properly traced and cwd |
726 # saved. | 726 # saved. |
727 self._cwd = {} | 727 self._cwd = {} |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 self._cwd[pid] = cwd2 | 769 self._cwd[pid] = cwd2 |
770 else: | 770 else: |
771 logging.debug('handle_chdir(%d, %s)' % (pid, cwd)) | 771 logging.debug('handle_chdir(%d, %s)' % (pid, cwd)) |
772 self._cwd[pid] = cwd | 772 self._cwd[pid] = cwd |
773 else: | 773 else: |
774 assert False, 'Unexecpected fail: %s' % result | 774 assert False, 'Unexecpected fail: %s' % result |
775 | 775 |
776 def handle_open_nocancel(self, ppid, pid, function, args, result): | 776 def handle_open_nocancel(self, ppid, pid, function, args, result): |
777 return self.handle_open(ppid, pid, function, args, result) | 777 return self.handle_open(ppid, pid, function, args, result) |
778 | 778 |
779 def handle_open(self, _ppid, pid, _function, args, result): | 779 def handle_open(self, _ppid, pid, function, args, result): |
780 args = self.RE_OPEN.match(args).groups() | 780 match = self.RE_OPEN.match(args) |
| 781 assert match, (pid, function, args, result) |
| 782 args = match.groups() |
781 flag = int(args[1]) | 783 flag = int(args[1]) |
782 if self.O_DIRECTORY & flag == self.O_DIRECTORY: | 784 if self.O_DIRECTORY & flag == self.O_DIRECTORY: |
783 # Ignore directories. | 785 # Ignore directories. |
784 return | 786 return |
785 self._handle_file(pid, args[0], result) | 787 self._handle_file(pid, args[0], result) |
786 | 788 |
787 def handle_rename(self, _ppid, pid, _function, args, result): | 789 def handle_rename(self, _ppid, pid, _function, args, result): |
788 args = self.RE_RENAME.match(args).groups() | 790 args = self.RE_RENAME.match(args).groups() |
789 self._handle_file(pid, args[0], result) | 791 self._handle_file(pid, args[0], result) |
790 self._handle_file(pid, args[1], result) | 792 self._handle_file(pid, args[1], result) |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 os.path.abspath(options.log), | 1629 os.path.abspath(options.log), |
1628 args, | 1630 args, |
1629 options.root_dir, | 1631 options.root_dir, |
1630 options.cwd, | 1632 options.cwd, |
1631 options.product_dir, | 1633 options.product_dir, |
1632 options.force) | 1634 options.force) |
1633 | 1635 |
1634 | 1636 |
1635 if __name__ == '__main__': | 1637 if __name__ == '__main__': |
1636 sys.exit(main()) | 1638 sys.exit(main()) |
OLD | NEW |