|
@ -5,6 +5,7 @@ import re |
|
|
import json |
|
|
import json |
|
|
from ProxyDecoder import baseFunc |
|
|
from ProxyDecoder import baseFunc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __vmessV2raynDecode(url: str) -> dict: |
|
|
def __vmessV2raynDecode(url: str) -> dict: |
|
|
""" |
|
|
""" |
|
|
v2rayN / v2rayNG分享链接解码 |
|
|
v2rayN / v2rayNG分享链接解码 |
|
@ -27,6 +28,7 @@ def __vmessV2raynDecode(url: str) -> dict: |
|
|
"sni": "...", |
|
|
"sni": "...", |
|
|
"alpn": "..." |
|
|
"alpn": "..." |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
content = json.loads( |
|
|
content = json.loads( |
|
|
baseFunc.base64Decode( |
|
|
baseFunc.base64Decode( |
|
@ -36,7 +38,7 @@ def __vmessV2raynDecode(url: str) -> dict: |
|
|
if int(content['v']) != 2: # version => 2 |
|
|
if int(content['v']) != 2: # version => 2 |
|
|
raise Exception('Unknown version field') |
|
|
raise Exception('Unknown version field') |
|
|
info = { |
|
|
info = { |
|
|
'server': content['add'], |
|
|
'server': baseFunc.formatHost(content['add']), |
|
|
'port': int(content['port']), |
|
|
'port': int(content['port']), |
|
|
'id': content['id'], |
|
|
'id': content['id'], |
|
|
'aid': int(content['aid']), |
|
|
'aid': int(content['aid']), |
|
@ -102,6 +104,7 @@ def __vmessV2raynDecode(url: str) -> dict: |
|
|
info['stream'] = stream |
|
|
info['stream'] = stream |
|
|
return info |
|
|
return info |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __vmessCommonDecode(url: str) -> dict: |
|
|
def __vmessCommonDecode(url: str) -> dict: |
|
|
""" |
|
|
""" |
|
|
VMess标准分享链接解码 (only VMessAEAD) |
|
|
VMess标准分享链接解码 (only VMessAEAD) |
|
@ -153,7 +156,7 @@ def __vmessCommonDecode(url: str) -> dict: |
|
|
if 'encryption' in params: |
|
|
if 'encryption' in params: |
|
|
info['method'] = params['encryption'] |
|
|
info['method'] = params['encryption'] |
|
|
stream = { |
|
|
stream = { |
|
|
'type': params['type'] |
|
|
'type': params['type'] if params['type'] != 'http' else 'h2' |
|
|
} |
|
|
} |
|
|
if params['type'] == 'tcp': |
|
|
if params['type'] == 'tcp': |
|
|
if 'headerType' in params and params['headerType'] == 'http': |
|
|
if 'headerType' in params and params['headerType'] == 'http': |
|
@ -207,27 +210,18 @@ def __vmessCommonDecode(url: str) -> dict: |
|
|
info['stream'] = stream |
|
|
info['stream'] = stream |
|
|
return info |
|
|
return info |
|
|
|
|
|
|
|
|
def vmessDecode(url: str) -> dict or None: |
|
|
|
|
|
""" |
|
|
|
|
|
VMess分享链接解码 |
|
|
|
|
|
|
|
|
|
|
|
链接合法: |
|
|
|
|
|
return { |
|
|
|
|
|
'type': 'vmess', |
|
|
|
|
|
... |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
链接不合法: |
|
|
def decode(url: str) -> dict: |
|
|
return None |
|
|
if url.split('://')[0] != 'vmess': |
|
|
""" |
|
|
raise Exception('Unexpected scheme') |
|
|
if url[0:8] != 'vmess://': |
|
|
|
|
|
return None |
|
|
|
|
|
try: |
|
|
try: |
|
|
result = __vmessV2raynDecode(url) # try v2rayN decode |
|
|
vmessInfo = __vmessV2raynDecode(url) # try v2rayN decode |
|
|
except: |
|
|
except: |
|
|
try: |
|
|
try: |
|
|
result = __vmessCommonDecode(url) # try VMess common decode |
|
|
vmessInfo = __vmessCommonDecode(url) # try VMess common decode |
|
|
except: |
|
|
except: |
|
|
return None |
|
|
raise Exception('Url could not be parsed') |
|
|
result['type'] = 'vmess' |
|
|
return { |
|
|
return result |
|
|
**{'type': 'vmess'}, |
|
|
|
|
|
**vmessInfo |
|
|
|
|
|
} |
|
|