Skip to content

Commit 0b0cf83

Browse files
committed
HarExport
1 parent fa0ace8 commit 0b0cf83

14 files changed

+189
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ Tools/ffmpeg/*
1212
!/Tools/ffmpeg/ffmpeg.zip
1313
*.pyc
1414
Tools/APKTool/*
15-
!/Tools/APKTool/APKTool.zip
15+
!/Tools/APKTool/APKTool.zip
16+
Tools/HarExport/Export

GameDevTools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22
# -*- coding: UTF-8 -*-
3+
import os
34

45
from Tools import Helper
56
Helper.Checkpip()
@@ -37,6 +38,12 @@
3738
from Tools import Audio_HZ_KBPS_Tools
3839
from Tools import MergeVideo
3940
from Tools import APKTools
41+
from Tools.HarExport import HarExport
42+
43+
44+
os.system("mode con cols=121 lines=35")
45+
46+
HarExport.Helper.ShowLogo("游戏开发 工具套装")
4047

4148
toolSets=\
4249
{
@@ -141,6 +148,9 @@
141148

142149
# APKTool APK反编译工具套装
143150
APKTools:[['apktools','adb','jdjui','aapt'],u'APK反编译工具套装'],
151+
152+
# HarExport H5网页游戏资源提取
153+
HarExport:[['harexport','h5','html','web'],u'H5网页游戏资源提取'],
144154
}
145155

146156
toolSets_old=toolSets

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ toolSets=\
6060
# 更新日志
6161

6262
```
63+
2019/5/17 HarExport H5网页游戏资源提取 ,关键词 ['harexport','h5','html','web']
64+
6365
2019/4/30 APKTools APK反编译工具套装 ,关键词 ['apktools','adb','jdjui','aapt']
6466
6567
2019/4/24 MergeVideo 视频合并工具 ,关键词 ['mergevideo','combine','add','mp4','flv','wmv','mkv']

Tools/HarExport/HarExport.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/python
2+
# -*- coding: UTF-8 -*-
3+
4+
import json
5+
import codecs
6+
import base64
7+
import os
8+
from . import Helper
9+
10+
# 设置导出目录
11+
tmpExportDirPath="./Tools/HarExport/Export"
12+
13+
def SaveFileWithUrl(varUrl,varBytes):
14+
tmpUrlStr=varUrl.replace("https://","").replace("http://","")
15+
16+
global tmpExportDirPath
17+
tmpDirPath=tmpExportDirPath+"/"
18+
tmpFileName=""
19+
20+
# 以/ 拆分网址,创建文件夹
21+
while True:
22+
if tmpUrlStr=="":
23+
break
24+
tmpStrParts=tmpUrlStr.partition('/')
25+
if tmpStrParts[1]=='/':
26+
tmpUrlStr=tmpStrParts[2]
27+
28+
tmpDirPath=tmpDirPath+"/"+tmpStrParts[0]
29+
print(tmpDirPath)
30+
31+
# 创建文件夹
32+
if os.path.exists(tmpDirPath)==False:
33+
os.makedirs(tmpDirPath)
34+
else:
35+
tmpFileName=tmpStrParts[0]
36+
# 去除 ? 后面部分
37+
tmpStrParts=tmpFileName.partition('?')
38+
if tmpStrParts[1]=='?':
39+
tmpFileName=tmpStrParts[0]
40+
print(tmpFileName)
41+
tmpFilePath=tmpDirPath+"/"+tmpFileName
42+
43+
if os.path.exists(tmpFilePath):
44+
os.remove(tmpFilePath)
45+
fo = open(tmpFilePath, "xb")
46+
fo.write(varBytes)
47+
fo.close()
48+
49+
break
50+
51+
52+
def run():
53+
Helper.ShowLogo(u"H5网页游戏素材提取工具\n\n第一次使用请阅读 README.pdf \n\n")
54+
Helper.OpenOneToolDir("HarExport/")
55+
56+
tmpHarFilePath=str(input(u"输入har文件路径:")).replace('"','')
57+
global tmpExportDirPath
58+
tmpDirPath=str(input(u"设置导出目录 绝对路径 (默认为Export):")).replace('"','')
59+
if tmpDirPath!="":
60+
tmpExportDirPath=tmpDirPath
61+
# print(tmpExportDirPath)
62+
63+
with codecs.open(tmpHarFilePath,"r","utf-8",errors='ignore') as tmpHarFile:
64+
harDic=json.load(tmpHarFile)
65+
print(len(harDic["log"]["entries"]))
66+
67+
tmpEntries=harDic["log"]["entries"]
68+
for tmpEntry in tmpEntries:
69+
70+
tmpContentDic=tmpEntry["response"]["content"]
71+
if 'encoding' in tmpContentDic:
72+
tmpEncoding=tmpEntry["response"]["content"]["encoding"]
73+
if tmpEncoding=="base64":
74+
print(tmpEntry["request"]["url"])
75+
# print(tmpEntry["response"]["content"]["text"])
76+
tmpBytes=base64.b64decode(tmpEntry["response"]["content"]["text"])
77+
SaveFileWithUrl(tmpEntry["request"]["url"],tmpBytes)

Tools/HarExport/Helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import codecs
2+
import os
3+
4+
def ShowLogo(varToolTitle):
5+
6+
7+
8+
with codecs.open("./data.bin","r","utf-8",errors='ignore') as tmpLogoFile:
9+
print(tmpLogoFile.read())
10+
print(varToolTitle)
11+
print("\n\n")
12+
13+
def OpenOneToolDir(varDir):
14+
tmpExePath=os.getcwd()+"/Tools/"+varDir
15+
# print(tmpExePath)
16+
os.system('start '+tmpExePath)

Tools/HarExport/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# HarExport
2+
3+
提取Har资源,用来提取H5网页游戏素材资源。
4+
5+
har 是firefox等浏览器用来保存网络访问数据的json文件。
6+
7+
所有访问的网络请求,以request response保存。
8+
9+
图片等文件以Base64保存。
10+
11+
这里的代码功能就是从base64数据还原文件。
12+
13+
首先需要安装 <font color=red>python3</font>
14+
15+
<font color=red>1.保存har文件</font>
16+
17+
![avatar](./image/1.png)
18+
19+
打开游戏页面
20+
21+
F12 打开开发者工具,切换到 <font color=red>网络</font> 一栏
22+
23+
确保选择 <font color=red>所有</font>
24+
25+
玩一段时间游戏
26+
27+
在 HAR 这里点击,选择 <font color=red>所有文件另存为HAR</font>,弹出提示框保存即可。
28+
29+
30+
<font color=red>2.提取图片素材</font>
31+
32+
在当前目录打开命令行,执行命令
33+
34+
python HarExport.py
35+
36+
提示输入har 文件路径,把har 文件拖到 CMD 窗口,回车即可
37+
38+
![avatar](./image/2.png)
39+
40+
文件提取按照url分段 存到指定文件夹。
41+
42+
比如这张图片
43+
44+
"url": "https://res1.t5game.5jli.com/t5game_res/img/bg.jpg?v=1558085555",
45+
46+
就存储在
47+
48+
![avatar](./image/3.png)
49+
50+
51+

Tools/HarExport/README.pdf

1.08 MB
Binary file not shown.

Tools/HarExport/image/1.png

579 KB
Loading

Tools/HarExport/image/2.png

139 KB
Loading

Tools/HarExport/image/3.png

94.5 KB
Loading

Tools/Helper.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: UTF-8 -*-
33
import os
44
import urllib
5+
import codecs
56
from urllib import request
67

78
# 不规范的Url
@@ -41,7 +42,7 @@ def OpenOneToolDir(varDir):
4142

4243
# 检查pip是否安装
4344
def Checkpip():
44-
print("Checkpip")
45+
# print("Checkpip")
4546
try:
4647
import pip
4748
except:
@@ -87,4 +88,11 @@ def getdirpath(varfilepath):
8788
varfilepath=getUnixPath(varfilepath)
8889
tmpStrParts=varfilepath.rpartition('/')
8990
return tmpStrParts[0]+'/'
90-
# Checkpip()
91+
# Checkpip()
92+
93+
# 显示Logo
94+
def ShowLogo(varToolTitle):
95+
with codecs.open("./data.bin","r","utf-8",errors='ignore') as tmpLogoFile:
96+
print(tmpLogoFile.read())
97+
print(varToolTitle)
98+
print("\n\n")
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

data.bin

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
------------------------------------------------------------------------------------------------------------------------
2+
%%
3+
%%%
4+
%%%%%
5+
%%%%%%%%%
6+
%%%%%%%%%%%%%%%%%%%%%
7+
%%%%%%%%%%%%
8+
%%%%%%
9+
%%%%
10+
%%
11+
%%%%%%%%%%%%%%%% %%%%%%% % %%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%% %%%%%% %%%%%%%%%%%%%%%%%
12+
%%%%%%%%%%%%%%%%% %%%%%%%%% %%%%%%%%%%%%%%% %%%%%% %%%%%%%% %%%%%%%%%%%%%%%%%%
13+
%%%% %%%%% %%%%%%%%%%% %%%% %%%% %%%%%%%%%% %%%%% %%%%%
14+
%%%%%%%%%%%%%%%%% %%%%%% %%%%% %%%%%%%%%%%%%%%%% %%%% %%%%% %%%%% %%%%%%%%%%%%%%%%%%
15+
%%%%%%%%%%%%%%%% %%%%%% %%%%% %%%%%%%%%%%%%%%%% %%%% %%%%% %%%%% %%%%%%%%%%%%%%%%%
16+
%%%% %%%%%% %%%%%% %%%%% %%%% %%%% %%%%% %%%%% %%%%% %%%%%%
17+
%%%% %%%%% %%%%%% %%%%% %%%%% %%%% %%%%% %%%%% %%%%% %%%%%
18+
%%%% %%%%%%%%%%%%%%%%%% %%%%% %%%%%%%%%%%%%%%%%% %%%% %%%%%%%%%% %%%%% %%%%% %%%%%%
19+
%%%% %%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%% %%%% %%%%%%%%%%% %%%%%%%%%%% %%%%%
20+
------------------------------------------------------------------------------------------------------------------------
21+

0 commit comments

Comments
 (0)