[kernel] r16919 - people/benh
Ben Hutchings
benh at alioth.debian.org
Sat Feb 19 18:17:16 UTC 2011
Author: benh
Date: Sat Feb 19 18:17:09 2011
New Revision: 16919
Log:
Add script to find blobs embedded in C code
Added:
people/benh/grep-int-array (contents, props changed)
Added: people/benh/grep-int-array
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ people/benh/grep-int-array Sat Feb 19 18:17:09 2011 (r16919)
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+# Copyright 2010 Ben Hutchings
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import re
+int_array_re = re.compile(r'\+?\s*\{?(?:\s*(?:0x)?[0-9A-Fa-f]+\s*[,\}])+')
+blank_re = re.compile(r'\+?\s*(?:/\*|$)|-')
+
+def grep_file(f, verbose, debug=False):
+ result = False
+ count = 0
+ matched = False
+ for i, line in enumerate(f):
+ if int_array_re.match(line):
+ if count == 0:
+ match_begin = 1 + i
+ count += line.count(',')
+ if debug:
+ print 1 + i, 'matched; count =', count
+ if count >= 100 and not matched:
+ if verbose:
+ result = True
+ matched = True
+ # Use format that emacs expects in compilation-mode
+ print "%s:%d: here" % (f.name, match_begin)
+ else:
+ return True
+ elif blank_re.match(line):
+ pass
+ else:
+ if debug:
+ print 1 + i, 'did not match'
+ count = 0
+ matched = False
+ return result
+
+if __name__ == '__main__':
+ import sys
+ verbose = False
+ if sys.argv[1] == '-v':
+ del sys.argv[1:2]
+ verbose = True
+ for name in sys.argv[1:]:
+ f = open(name)
+ if grep_file(f, verbose) and not verbose:
+ print name
+ f.close()
More information about the Kernel-svn-changes
mailing list