Ailyth commited on
Commit
8cc0fc3
1 Parent(s): 7c88222
Files changed (1) hide show
  1. xml_scan.py +46 -0
xml_scan.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import hmac
2
+ import hashlib
3
+ import binascii
4
+ import requests
5
+ import xml.etree.ElementTree as ET
6
+ from tqdm import tqdm
7
+
8
+ # Function to generate URL using HMAC
9
+ def generate_url(GameID):
10
+ byte_key = binascii.unhexlify("AD62E37F905E06BC19593142281C112CEC0E7EC3E97EFDCAEFCDBAAFA6378D84")
11
+ hash = hmac.new(byte_key, ("np_" + GameID).encode('utf-8'), digestmod=hashlib.sha256)
12
+ hash = hash.hexdigest()
13
+ url = f"https://gs-sec.ww.np.dl.playstation.net/plo/np/{GameID}/{hash}/{GameID}-ver.xml"
14
+ return url
15
+
16
+ # 将16进制的密钥转换为字节数组
17
+
18
+
19
+ # 循环遍历CUSA00001到CUSA01000的范围
20
+ for number in tqdm(range(1, 45000)):
21
+ GameID = f"CUSA{number:05}"
22
+ url = generate_url(GameID)
23
+
24
+ try:
25
+ # 发送HTTP请求获取XML内容
26
+ response = requests.get(url,verify=False)
27
+ response.raise_for_status() # 抛出HTTP请求错误
28
+ xml_content = response.content
29
+
30
+ root = ET.fromstring(xml_content)
31
+ # 解析XML内容
32
+ title_id = root.attrib["titleid"]
33
+ title = root.find(".//title").text
34
+ version = root.find(".//package").attrib["version"]
35
+ content_id = root.find(".//package").attrib["content_id"]
36
+
37
+ # 将提取的信息写入文本文件
38
+ with open("extracted_info.txt", "a", encoding="utf-8") as info_file:
39
+ info_file.write(f"{title_id},{title},{version},{content_id}\n")
40
+
41
+ print(f"{GameID} - Extraction completed!")
42
+ except (requests.exceptions.RequestException, ET.ParseError) as e:
43
+ print(f"{GameID} - Error: {e}")
44
+ continue # 出错时继续下一次循环
45
+
46
+ print("Extraction and writing completed!")