home *** CD-ROM | disk | FTP | other *** search
- def fill_string(string, size):
- assert len(string) <= size
- while len(string) != size:
- string = "%s\x00" % string
- return string
-
- def string_shortener(string):
- new_string = ""
- for char in string:
- if char == "\x00":
- break
- new_string = "%s%s" % (new_string, char)
- return new_string
-
- def is_string_invalid(string):
- for char in string:
- c = ord(char)
- if c in xrange(0, 0x20) or c not in xrange(20, 128):
- return True
- return False
-
- def is_data_a_string(data):
- # mat1\x00\x00\x00\x23 -> False
- # ma\x03t -> False
- # lower\x02\x00\x00 -> False
- # \x03\x00\x00 -> False
- # \x00\x00 -> False
- string = string_shortener(data)
- if not string:
- return False
- for x in xrange(len(string)+1, len(data)):
- if data[x] != '\x00':
- return False
- counter = 0
- for char in string:
- c = ord(char)
- if c in xrange(0, 0x20) or c not in xrange(20, 128):
- break
- else:
- counter += 1
- if counter == len(string):
- return True
- else:
- return False