[Pymoul-svn] SF.net SVN: pymoul: [28] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-01-15 19:01:47
|
Revision: 28
http://pymoul.svn.sourceforge.net/pymoul/?rev=28&view=rev
Author: tiran
Date: 2007-01-15 11:01:38 -0800 (Mon, 15 Jan 2007)
Log Message:
-----------
* Added example WDYS, ELF and KI image
* Added unittests for ELF and WDYS files
* Fixed implementation of WDYS and ELF crypt functions
Modified Paths:
--------------
pymoul/trunk/src/moul/crypt/elf.py
pymoul/trunk/src/moul/crypt/whatdoyousee.py
Added Paths:
-----------
pymoul/trunk/src/moul/crypt/tests/test_elf.py
pymoul/trunk/src/moul/file/tests/audio.ini
pymoul/trunk/src/moul/file/tests/audio.txt
pymoul/trunk/src/moul/file/tests/audiocaps.0.elf
pymoul/trunk/src/moul/file/tests/audiocaps.0.txt
pymoul/trunk/src/moul/file/tests/avatar.jpg
pymoul/trunk/src/moul/file/tests/graphics.ini
pymoul/trunk/src/moul/file/tests/graphics.txt
Modified: pymoul/trunk/src/moul/crypt/elf.py
===================================================================
--- pymoul/trunk/src/moul/crypt/elf.py 2007-01-15 19:00:16 UTC (rev 27)
+++ pymoul/trunk/src/moul/crypt/elf.py 2007-01-15 19:01:38 UTC (rev 28)
@@ -19,6 +19,8 @@
Based on the C++ code from Marack
"""
+import struct
+
def list2int(lst):
return [ord(s) for s in lst]
@@ -26,7 +28,7 @@
return [chr(s) for s in lst]
def decryptElf(fin):
- """Decrypts an encrypted log file (MOUL elf file)
+ """Decrypt an encrypted log file (MOUL elf file)
fin - log file opened in binary mode
result - list of unencrypted lines
@@ -40,21 +42,30 @@
out = []
while True:
fpos = fin.tell()
- if fpos == fsize:
+ if fpos >= fsize:
+ # EOF reached, add an empty line
+ out.append('')
break
seghead = fin.read(2)
# Kudos to the programmer who thought up this little trick
# Very nice work (and highly confusing to reverse engineer)!
- segsize = str2int(seghead) ^ (fpos & 0xffff)
+ segsize = struct.unpack("<H", seghead)[0] ^ (fpos & 0xffff)
key = fpos & 0xff
-
- #print "Pos: %s, size: %s, key: %s" % (fpos, segsize, key)
seg = fin.read(segsize)
uncrypt = decipher(seg, segsize, key)
out.append(uncrypt)
return out
+def encryptElf(instr, fout):
+ """Encrypt an encrypted log file (MOUL elf file)
+
+ instr - input as string
+ fout - log file to write (binary mode)
+ """
+ # XXX NotImplemented
+ raise NotImplementedError
+
def decipher(crypt, size, key):
"""decipher for ELF (encrypted log files)
Added: pymoul/trunk/src/moul/crypt/tests/test_elf.py
===================================================================
--- pymoul/trunk/src/moul/crypt/tests/test_elf.py (rev 0)
+++ pymoul/trunk/src/moul/crypt/tests/test_elf.py 2007-01-15 19:01:38 UTC (rev 28)
@@ -0,0 +1,52 @@
+# pyMoul - Python interface to Myst Online URU Live
+# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
+
+# 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., 59
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""moul.crypt.elf unit tests
+"""
+import os
+import unittest
+from doctest import DocTestSuite
+
+import moul.file
+from moul.crypt.elf import decryptElf
+
+base = os.path.dirname(moul.file.__file__)
+elf_enc = os.path.join(base, 'tests', 'audiocaps.0.elf')
+elf_dec = os.path.join(base, 'tests', 'audiocaps.0.txt')
+
+class ElfTest(unittest.TestCase):
+ def setUp(self):
+ self.enc = open(elf_enc, 'rb')
+ self.dec = open(elf_dec, 'r')
+
+ def tearDown(self):
+ self.enc.close()
+ self.dec.close()
+
+ def test_compare(self):
+ data = '\n'.join(decryptElf(self.enc))
+ self.failUnlessEqual(data, self.dec.read())
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(ElfTest),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest="test_suite")
+
+
Modified: pymoul/trunk/src/moul/crypt/whatdoyousee.py
===================================================================
--- pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-01-15 19:00:16 UTC (rev 27)
+++ pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-01-15 19:01:38 UTC (rev 28)
@@ -46,7 +46,7 @@
raise IOError("Not a whatdoyousee/xTEA encrypted file")
header = fin.read(4)
- struct.unpack(ENDIAN+"L", header)
+ length = struct.unpack(ENDIAN+"L", header)[0]
out = []
pos = 0
@@ -59,7 +59,9 @@
else:
out.append(block)
pos += 8
- return ''.join(out)
+ data = ''.join(out)
+ # XXX: dos format
+ return data.replace("\r\n", "\n")
def encryptWDYS(instr, fout):
"""Encrypt whatdoyousee files
@@ -68,6 +70,8 @@
fout - out file descriptor in write and binary mode
return - None
"""
+ # XXX: dos format
+ instr = instr.replace("\n", "\r\n")
fin.seek(0)
fout.write(HEADER)
Added: pymoul/trunk/src/moul/file/tests/audio.ini
===================================================================
(Binary files differ)
Property changes on: pymoul/trunk/src/moul/file/tests/audio.ini
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: pymoul/trunk/src/moul/file/tests/audio.txt
===================================================================
--- pymoul/trunk/src/moul/file/tests/audio.txt (rev 0)
+++ pymoul/trunk/src/moul/file/tests/audio.txt 2007-01-15 19:01:38 UTC (rev 28)
@@ -0,0 +1,11 @@
+Audio.Initialize true
+Audio.UseEAX true
+Audio.SetPriorityCutoff 6
+Audio.MuteAll 0
+Audio.SetChannelVolume SoundFX 1
+Audio.SetChannelVolume BgndMusic 1
+Audio.SetChannelVolume Ambience 1
+Audio.SetChannelVolume NPCVoice 1
+Audio.EnableVoiceRecording 1
+Audio.SetDeviceName "Generic Hardware"
+Audio.SetChannelVolume GUI 1
Property changes on: pymoul/trunk/src/moul/file/tests/audio.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: pymoul/trunk/src/moul/file/tests/audiocaps.0.elf
===================================================================
(Binary files differ)
Property changes on: pymoul/trunk/src/moul/file/tests/audiocaps.0.elf
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: pymoul/trunk/src/moul/file/tests/audiocaps.0.txt
===================================================================
--- pymoul/trunk/src/moul/file/tests/audiocaps.0.txt (rev 0)
+++ pymoul/trunk/src/moul/file/tests/audiocaps.0.txt 2007-01-15 19:01:38 UTC (rev 28)
@@ -0,0 +1,6 @@
+SB Audigy 2 ZS Audio [C800]
+Bluetooth Audio
+Default DirectSound Device
+Default WaveOut Device
+DirectSound: Bluetooth Audio
+DirectSound: SB Audigy 2 ZS Audio [C800]
Property changes on: pymoul/trunk/src/moul/file/tests/audiocaps.0.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: pymoul/trunk/src/moul/file/tests/avatar.jpg
===================================================================
(Binary files differ)
Property changes on: pymoul/trunk/src/moul/file/tests/avatar.jpg
___________________________________________________________________
Name: svn:mime-type
+ image/jpeg
Added: pymoul/trunk/src/moul/file/tests/graphics.ini
===================================================================
(Binary files differ)
Property changes on: pymoul/trunk/src/moul/file/tests/graphics.ini
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: pymoul/trunk/src/moul/file/tests/graphics.txt
===================================================================
--- pymoul/trunk/src/moul/file/tests/graphics.txt (rev 0)
+++ pymoul/trunk/src/moul/file/tests/graphics.txt 2007-01-15 19:01:38 UTC (rev 28)
@@ -0,0 +1,12 @@
+Graphics.Width 1024
+Graphics.Height 768
+Graphics.ColorDepth 32
+Graphics.Windowed true
+Graphics.AntiAliasAmount 2
+Graphics.AnisotropicLevel 2
+Graphics.TextureQuality 2
+Quality.Level 2
+Graphics.Shadow.Enable 1
+Graphics.EnablePlanarReflections 1
+Graphics.EnableVSync false
+Graphics.Shadow.VisibleDistance 0.337126016617
Property changes on: pymoul/trunk/src/moul/file/tests/graphics.txt
___________________________________________________________________
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|