Commit df724099 authored by wanli's avatar wanli

update

parent 6830a350
......@@ -14,12 +14,12 @@ import hashlib
from ctypes import *
import platform
current_abspath = os.path.dirname(os.path.realpath(__file__))
lib_path = os.path.dirname(os.path.abspath(__file__))
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':
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.argtypes = [c_void_p, c_uint32]
......@@ -52,6 +52,10 @@ def str_to_bin(s):
def bin_to_str(s):
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):
......@@ -61,6 +65,10 @@ class EpkApp(object):
self._appName = appName
self._appDir = os.path.abspath(appDir)
self.algorithm = algorithm
eprint(sys.argv)
eprint(appName)
eprint(appDir)
eprint(self._appDir)
self._appVersion = appVersion
self._appCRCCode = None
self._files = []
......@@ -110,6 +118,7 @@ class EpkApp(object):
}
if self._infoPath == os.sep.join([path, fname]):
eprint(finfo)
files.insert(0, finfo)
else:
files.append(finfo)
......@@ -118,10 +127,15 @@ class EpkApp(object):
self.fileMD5(finfo)
return files
def header(self, epk_start=0xAAAA, md5_offset=0, file_count=0):
bytes_header = struct.pack("<HLH", epk_start, md5_offset, file_count)
def header(self, epk_start=0xAA, md5_offset=0, file_count=0):
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
def fileMD5(self, info):
md5path = os.sep.join([self._appDir, "%s.md5" % info["basename"]])
......@@ -149,6 +163,7 @@ class EpkApp(object):
md5 = hashlib.md5() #获取一个md5加密算法对象
md5.update(content) #指定需要加密的字符串
newmd5 = md5.hexdigest() #获取加密后的16进制字符串
eprint("md5 == ",newmd5)
content = self.sign(newmd5)
ret = b""
......@@ -162,6 +177,7 @@ class EpkApp(object):
fpath = os.sep.join([self._appDir, fname])
fext = info["ext"]
fileBytes = b""
if fext == "md5":
fileBytes += struct.pack("<B", 1)
......@@ -174,6 +190,8 @@ class EpkApp(object):
fileBytes += struct.pack("<%ds" % len(_name), fname.encode("utf-8"))
with open(fpath, "rb") as fc:
fileContentBytes = fc.read()
eprint(info["name"])
eprint(len(fileContentBytes))
fileBytes += struct.pack("<L", len(fileContentBytes))
if fext == "md5":
......@@ -181,8 +199,14 @@ class EpkApp(object):
else:
fileCompressBytes = self.compress()(fileContentBytes, level)
eprint("===",fileCompressBytes[0])
eprint(fileCompressBytes)
fileBytes += struct.pack("<L", len(fileCompressBytes))
eprint(fileBytes)
fileBytes += fileCompressBytes
return fileBytes
def pack(self, level=9):
......@@ -197,16 +221,24 @@ class EpkApp(object):
with open(self._epkName, "wb") as f:
for info in infos["files"]:
epkFileContentBytes += self.packFile(info)
epkFileContentLength = len(epkFileContentBytes)
epkFileBytes += self.header(md5_offset= 8 + epkFileContentLength, file_count=file_count)
epkFileBytes += epkFileContentBytes
epkmd5Bytes = self.md5(epkFileBytes)
epkFileBytes += struct.pack("<H", len(epkmd5Bytes))
epkFileBytes += epkmd5Bytes
crcBytes = zlib.crc32(epkFileBytes)
epkFileBytes += struct.pack("<L", crcBytes)
f.write(epkFileBytes)
ret = {
......@@ -222,7 +254,6 @@ class EpkApp(object):
}
pprint.pprint(ret)
return ret
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