Skip to content

Instantly share code, notes, and snippets.

@Redlnn
Last active February 28, 2022 09:20
Show Gist options
  • Save Redlnn/1b8ef79313551c677141e2a5c64bebeb to your computer and use it in GitHub Desktop.
Save Redlnn/1b8ef79313551c677141e2a5c64bebeb to your computer and use it in GitHub Desktop.
# !/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