Commit df724099 authored by wanli's avatar wanli

update

parent 6830a350
...@@ -14,12 +14,12 @@ import hashlib ...@@ -14,12 +14,12 @@ import hashlib
from ctypes import * from ctypes import *
import platform import platform
current_abspath = os.path.dirname(os.path.realpath(__file__)) lib_path = os.path.dirname(os.path.abspath(__file__))
if platform.system() == 'Windows': if platform.system() == 'Windows':
pDll = CDLL(os.sep.join([current_abspath, "lib", "eheatshrink.dll"])) pDll = CDLL(os.sep.join([lib_path, "lib", "eheatshrink.dll"]))
elif platform.system() == 'Linux': elif platform.system() == 'Linux':
pDll = CDLL(os.sep.join([current_abspath, "lib", "libeheatshrink.so"])) pDll = CDLL(os.sep.join([lib_path, "lib", "libeheatshrink.so"]))
pDll.ecompress_size.restype = c_uint32 pDll.ecompress_size.restype = c_uint32
pDll.ecompress_size.argtypes = [c_void_p, c_uint32] pDll.ecompress_size.argtypes = [c_void_p, c_uint32]
...@@ -52,6 +52,10 @@ def str_to_bin(s): ...@@ -52,6 +52,10 @@ def str_to_bin(s):
def bin_to_str(s): def bin_to_str(s):
return ''.join([chr(i) for i in [int(b, 2) for b in s.split(' ')]]) return ''.join([chr(i) for i in [int(b, 2) for b in s.split(' ')]])
def eprint(*args, **kwargs):
# print(*args, **kwargs)
pass
class EpkApp(object): class EpkApp(object):
...@@ -61,6 +65,10 @@ class EpkApp(object): ...@@ -61,6 +65,10 @@ class EpkApp(object):
self._appName = appName self._appName = appName
self._appDir = os.path.abspath(appDir) self._appDir = os.path.abspath(appDir)
self.algorithm = algorithm self.algorithm = algorithm
eprint(sys.argv)
eprint(appName)
eprint(appDir)
eprint(self._appDir)
self._appVersion = appVersion self._appVersion = appVersion
self._appCRCCode = None self._appCRCCode = None
self._files = [] self._files = []
...@@ -110,6 +118,7 @@ class EpkApp(object): ...@@ -110,6 +118,7 @@ class EpkApp(object):
} }
if self._infoPath == os.sep.join([path, fname]): if self._infoPath == os.sep.join([path, fname]):
eprint(finfo)
files.insert(0, finfo) files.insert(0, finfo)
else: else:
files.append(finfo) files.append(finfo)
...@@ -119,10 +128,15 @@ class EpkApp(object): ...@@ -119,10 +128,15 @@ class EpkApp(object):
return files return files
def header(self, epk_start=0xAAAA, md5_offset=0, file_count=0): def header(self, epk_start=0xAA, md5_offset=0, file_count=0):
bytes_header = struct.pack("<HLH", epk_start, md5_offset, file_count) if self.algorithm == 'zlib':
bytes_header = struct.pack("<BBLH", epk_start, 1 ,md5_offset, file_count)
else:
bytes_header = struct.pack("<BBLH", epk_start, 2 ,md5_offset, file_count)
return bytes_header return bytes_header
def fileMD5(self, info): def fileMD5(self, info):
md5path = os.sep.join([self._appDir, "%s.md5" % info["basename"]]) md5path = os.sep.join([self._appDir, "%s.md5" % info["basename"]])
fpath = os.sep.join([self._appDir, info["name"]]) fpath = os.sep.join([self._appDir, info["name"]])
...@@ -149,6 +163,7 @@ class EpkApp(object): ...@@ -149,6 +163,7 @@ class EpkApp(object):
md5 = hashlib.md5() #获取一个md5加密算法对象 md5 = hashlib.md5() #获取一个md5加密算法对象
md5.update(content) #指定需要加密的字符串 md5.update(content) #指定需要加密的字符串
newmd5 = md5.hexdigest() #获取加密后的16进制字符串 newmd5 = md5.hexdigest() #获取加密后的16进制字符串
eprint("md5 == ",newmd5)
content = self.sign(newmd5) content = self.sign(newmd5)
ret = b"" ret = b""
...@@ -162,6 +177,7 @@ class EpkApp(object): ...@@ -162,6 +177,7 @@ class EpkApp(object):
fpath = os.sep.join([self._appDir, fname]) fpath = os.sep.join([self._appDir, fname])
fext = info["ext"] fext = info["ext"]
fileBytes = b"" fileBytes = b""
if fext == "md5": if fext == "md5":
fileBytes += struct.pack("<B", 1) fileBytes += struct.pack("<B", 1)
...@@ -174,6 +190,8 @@ class EpkApp(object): ...@@ -174,6 +190,8 @@ class EpkApp(object):
fileBytes += struct.pack("<%ds" % len(_name), fname.encode("utf-8")) fileBytes += struct.pack("<%ds" % len(_name), fname.encode("utf-8"))
with open(fpath, "rb") as fc: with open(fpath, "rb") as fc:
fileContentBytes = fc.read() fileContentBytes = fc.read()
eprint(info["name"])
eprint(len(fileContentBytes))
fileBytes += struct.pack("<L", len(fileContentBytes)) fileBytes += struct.pack("<L", len(fileContentBytes))
if fext == "md5": if fext == "md5":
...@@ -181,8 +199,14 @@ class EpkApp(object): ...@@ -181,8 +199,14 @@ class EpkApp(object):
else: else:
fileCompressBytes = self.compress()(fileContentBytes, level) fileCompressBytes = self.compress()(fileContentBytes, level)
eprint("===",fileCompressBytes[0])
eprint(fileCompressBytes)
fileBytes += struct.pack("<L", len(fileCompressBytes)) fileBytes += struct.pack("<L", len(fileCompressBytes))
eprint(fileBytes)
fileBytes += fileCompressBytes fileBytes += fileCompressBytes
return fileBytes return fileBytes
def pack(self, level=9): def pack(self, level=9):
...@@ -198,15 +222,23 @@ class EpkApp(object): ...@@ -198,15 +222,23 @@ class EpkApp(object):
for info in infos["files"]: for info in infos["files"]:
epkFileContentBytes += self.packFile(info) epkFileContentBytes += self.packFile(info)
epkFileContentLength = len(epkFileContentBytes) epkFileContentLength = len(epkFileContentBytes)
epkFileBytes += self.header(md5_offset= 8 + epkFileContentLength, file_count=file_count) epkFileBytes += self.header(md5_offset= 8 + epkFileContentLength, file_count=file_count)
epkFileBytes += epkFileContentBytes epkFileBytes += epkFileContentBytes
epkmd5Bytes = self.md5(epkFileBytes) epkmd5Bytes = self.md5(epkFileBytes)
epkFileBytes += struct.pack("<H", len(epkmd5Bytes)) epkFileBytes += struct.pack("<H", len(epkmd5Bytes))
epkFileBytes += epkmd5Bytes epkFileBytes += epkmd5Bytes
crcBytes = zlib.crc32(epkFileBytes) crcBytes = zlib.crc32(epkFileBytes)
epkFileBytes += struct.pack("<L", crcBytes) epkFileBytes += struct.pack("<L", crcBytes)
f.write(epkFileBytes) f.write(epkFileBytes)
ret = { ret = {
...@@ -222,7 +254,6 @@ class EpkApp(object): ...@@ -222,7 +254,6 @@ class EpkApp(object):
} }
pprint.pprint(ret) pprint.pprint(ret)
return ret
def main(path, appName, algorithm): def main(path, appName, algorithm):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment