def test_dump_record(self): docinfo_stream = self.hwp5file['DocInfo'] record = read_record(docinfo_stream.open(), 0) stream = BytesIO() dump_record(stream, record) stream.seek(0) record2 = read_record(stream, 0) self.assertEqual(record2, record)
def test_dump_record(self): from hwp5.recordstream import dump_record from hwp5.recordstream import read_record docinfo_stream = self.hwp5file['DocInfo'] record = read_record(docinfo_stream.open(), 0) from StringIO import StringIO stream = StringIO() dump_record(stream, record) stream.seek(0) record2 = read_record(stream, 0) self.assertEquals(record2, record)
def test_read_record(self): from hwp5.recordstream import read_record from hwp5.tagids import HWPTAG_DOCUMENT_PROPERTIES docinfo_stream = self.hwp5file['DocInfo'] record = read_record(docinfo_stream.open(), 0) self.assertEquals(HWPTAG_DOCUMENT_PROPERTIES, record['tagid'])
def test_distdoc_decode(self): section = self.section stream = hwp5.distdoc.decode(section.wrapped.open()) stream = hwp5.compressed.decompress(stream) record = read_record(stream, 0) self.assertEqual(0, record['level']) self.assertEqual(HWPTAG_PARA_HEADER, record['tagid']) self.assertEqual(22, record['size'])
def decode(stream): distdoc_data_record = read_record(stream, 0) if distdoc_data_record['tagid'] != HWPTAG_DISTRIBUTE_DOC_DATA: raise IOError('the first record is not an HWPTAG_DISTRIBUTE_DOC_DATA') distdoc_data = distdoc_data_record['payload'] key = decode_head_to_key(distdoc_data) tail = stream.read() decrypted = decrypt_tail(key, tail) return StringIO(decrypted)
def main(args): import sys import shutil if args['sha1']: head = read_record(sys.stdin, 0) sha1ucs16le = decode_head_to_sha1(head['payload']) sha1 = a2b_hex(sha1ucs16le.decode('utf-16le')) if not args['--raw']: sha1 = b2a_hex(sha1) sys.stdout.write(sha1) elif args['key']: head = read_record(sys.stdin, 0) key = decode_head_to_key(head['payload']) if not args['--raw']: key = b2a_hex(key) sys.stdout.write(key) else: result = decode(sys.stdin) shutil.copyfileobj(result, sys.stdout)
def test_viewtext_scripts(self): self.hwp5file_name = 'viewtext.hwp' hwp5file = self.hwp5file_compressed self.assertTrue(hwp5file.header.flags.distributable) JScriptVersion = self.scripts['JScriptVersion'].open() from hwp5.tagids import HWPTAG_DISTRIBUTE_DOC_DATA from hwp5.recordstream import read_record distdoc = read_record(JScriptVersion, 0) encrypted = JScriptVersion.read() self.assertEquals(HWPTAG_DISTRIBUTE_DOC_DATA, distdoc['tagid']) self.assertEquals(16, len(encrypted))
def test_distdoc_decrypt_tail(self): section = self.section key = section.head_key() tail = section.tail() decrypted = decrypt_tail(key, tail) decompressed = zlib.decompress(decrypted, -15) record = read_record(BytesIO(decompressed), 0) self.assertEqual(0, record['level']) self.assertEqual(HWPTAG_PARA_HEADER, record['tagid']) self.assertEqual(22, record['size']) self.assertEqual(390, len(decompressed))
class TestHwp5DistDocFunctions(TestBase): hwp5file_name = 'viewtext.hwp' password_sha1 = sha1('12345').digest() @property def hwp5distdoc(self): return Hwp5DistDoc(self.olestg) @property def section(self): return self.hwp5distdoc['ViewText']['Section0'] def test_distdoc_decode_head_to_sha1(self): expected = b2a_hex(self.password_sha1).upper().encode('utf-16le') self.assertEquals(expected, decode_head_to_sha1(self.section.head())) def test_distdoc_decode_head_to_key(self): section = self.section expected = b2a_hex(self.password_sha1).upper().encode('utf-16le')[:16] self.assertEquals(expected, decode_head_to_key(section.head())) self.assertEquals(expected, section.head_key()) def test_distdoc_decrypt_tail(self): section = self.section key = section.head_key() tail = section.tail() try: decrypted = decrypt_tail(key, tail) except NotImplementedError, e: if e.message == 'aes128ecb_decrypt': # skip this test return raise decompressed = zlib.decompress(decrypted, -15) record = read_record(StringIO(decompressed), 0) self.assertEquals(0, record['level']) self.assertEquals(HWPTAG_PARA_HEADER, record['tagid']) self.assertEquals(22, record['size']) self.assertEquals(390, len(decompressed))
try: decrypted = decrypt_tail(key, tail) except NotImplementedError, e: if e.message == 'aes128ecb_decrypt': # skip this test return raise decompressed = zlib.decompress(decrypted, -15) record = read_record(StringIO(decompressed), 0) self.assertEquals(0, record['level']) self.assertEquals(HWPTAG_PARA_HEADER, record['tagid']) self.assertEquals(22, record['size']) self.assertEquals(390, len(decompressed)) def test_distdoc_decode(self): section = self.section try: stream = hwp5.distdoc.decode(section.wrapped.open()) except NotImplementedError, e: if e.message == 'aes128ecb_decrypt': # skip this test return raise stream = hwp5.compressed.decompress(stream) record = read_record(stream, 0) self.assertEquals(0, record['level']) self.assertEquals(HWPTAG_PARA_HEADER, record['tagid']) self.assertEquals(22, record['size'])
def test_read_record(self): docinfo_stream = self.hwp5file['DocInfo'] record = read_record(docinfo_stream.open(), 0) self.assertEqual(HWPTAG_DOCUMENT_PROPERTIES, record['tagid'])
def test_bodytext_decompressed(self): record = read_record(self.bodytext['Section0'].open(), 0) self.assertEqual(HWPTAG_PARA_HEADER, record['tagid'])
def test_docinfo_decompressed(self): record = read_record(self.docinfo, 0) self.assertEquals(HWPTAG_DOCUMENT_PROPERTIES, record['tagid'])
def test_bodytext_uncompressed(self): from hwp5.recordstream import read_record from hwp5.tagids import HWPTAG_PARA_HEADER record = read_record(self.bodytext['Section0'].open(), 0) self.assertEquals(HWPTAG_PARA_HEADER, record['tagid'])
def test_docinfo_uncompressed(self): from hwp5.recordstream import read_record from hwp5.tagids import HWPTAG_DOCUMENT_PROPERTIES record = read_record(self.docinfo, 0) self.assertEquals(HWPTAG_DOCUMENT_PROPERTIES, record['tagid'])
def test_bodytext_decompressed(self): from hwp5.recordstream import read_record from hwp5.tagids import HWPTAG_PARA_HEADER record = read_record(self.bodytext['Section0'].open(), 0) self.assertEquals(HWPTAG_PARA_HEADER, record['tagid'])
def test_docinfo_decompressed(self): from hwp5.recordstream import read_record from hwp5.tagids import HWPTAG_DOCUMENT_PROPERTIES record = read_record(self.docinfo, 0) self.assertEquals(HWPTAG_DOCUMENT_PROPERTIES, record['tagid'])
def test_bodytext_decompressed(self): record = read_record(self.bodytext['Section0'].open(), 0) self.assertEquals(HWPTAG_PARA_HEADER, record['tagid'])
def test_docinfo_decompressed(self): record = read_record(self.docinfo, 0) self.assertEqual(HWPTAG_DOCUMENT_PROPERTIES, record['tagid'])