Last active
February 28, 2022 09:20
-
-
Save Redlnn/1b8ef79313551c677141e2a5c64bebeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
"""将 mirai 的旧版 decice.json 转换为新版(`'deviceInfoVersion': 2`)""" | |
import json | |
with open('device.json') as fp: | |
data = json.load(fp) | |
target = {'deviceInfoVersion': 2, 'data': {}} | |
for key, item in data.items(): | |
if key == 'version': | |
target['data']['version'] = {"incremental": "5891938", "release": "10", "codename": "REL"} | |
elif key == 'imei': | |
target['data']['imei'] = item | |
elif key == 'imsiMd5': | |
target['data']['imsiMd5'] = '' | |
for i in item: | |
if i < 0: | |
target['data']['imsiMd5'] += '0' + hex(i+256)[2:] if int(hex(i+256), 16) < 0xf else hex(i+256)[2:] | |
else: | |
target['data']['imsiMd5'] += '0' + hex(i)[2:] if int(hex(i), 16) < 0xf else hex(i)[2:] | |
else: | |
target['data'][key] = ''.join(chr(i) for i in item) | |
with open('new_device.json', 'w') as fp: | |
json.dump(target, fp, ensure_ascii=False, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment