Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
evm-store
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanli
evm-store
Commits
df724099
Commit
df724099
authored
Apr 22, 2021
by
wanli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6830a350
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
7 deletions
+38
-7
backend/utils/epk.py
backend/utils/epk.py
+38
-7
No files found.
backend/utils/epk.py
View file @
df724099
...
@@ -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
.
real
path
(
__file__
))
lib_path
=
os
.
path
.
dirname
(
os
.
path
.
abs
path
(
__file__
))
if
platform
.
system
()
==
'Windows'
:
if
platform
.
system
()
==
'Windows'
:
pDll
=
CDLL
(
os
.
sep
.
join
([
current_abs
path
,
"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_abs
path
,
"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
)
...
@@ -118,10 +127,15 @@ class EpkApp(object):
...
@@ -118,10 +127,15 @@ class EpkApp(object):
self
.
fileMD5
(
finfo
)
self
.
fileMD5
(
finfo
)
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"
]])
...
@@ -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
):
...
@@ -197,16 +221,24 @@ class EpkApp(object):
...
@@ -197,16 +221,24 @@ class EpkApp(object):
with
open
(
self
.
_epkName
,
"wb"
)
as
f
:
with
open
(
self
.
_epkName
,
"wb"
)
as
f
:
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment