diff --git a/js/xpconnect/loader/script_cache.py b/js/xpconnect/loader/script_cache.py new file mode 100755 index 000000000000..e6cc73fab593 --- /dev/null +++ b/js/xpconnect/loader/script_cache.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +import io +import os +import struct +import sys + +MAGIC = b'mozXDRcachev001\0' + + +def usage(): + print("""Usage: script_cache.py ... + + Decodes and prints out the contents of a startup script cache file + (e.g., startupCache/scriptCache.bin) in human-readable form.""") + + sys.exit(1) + + +class ProcessTypes: + Default = 0 + Web = 1 + Extension = 2 + + def __init__(self, val): + self.val = val + + def __str__(self): + res = [] + if self.val & (1 << self.Default): + res.append('Parent') + if self.val & (1 << self.Web): + res.append('Web') + if self.val & (1 << self.Extension): + res.append('Extension') + return '|'.join(res) + + +class InputBuffer(object): + + def __init__(self, data): + self.data = data + self.offset = 0 + + @property + def remaining(self): + return len(self.data) - self.offset + + def unpack(self, fmt): + res = struct.unpack_from(fmt, self.data, self.offset) + self.offset += struct.calcsize(fmt) + return res + + def unpack_str(self): + size, = self.unpack('9,}'.format(*hdr.unpack('9,}'.format(*hdr.unpack('