更新: 这个脚本基于teamviewer13. 14.0之后teamviewer更改了校验的机制,可能造成tv无法打开,请各位同学注意甄别~
前言
相信很多同学都用teamviewer的免费版,有线上问题远程解决下。但用一段时间就会莫名被检测为商用,进而被限制使用甚至禁用。重装teamviewer也解决不了。查了一下处理方案,大致过程是删掉旧的认证文件,然后替换证书里的几个字段值。操作稍微复杂,写成了一个python脚本,sudo执行下即可。不想看的同学可以直接拉倒最下面看脚本的代码。
1.删掉原配置文件
删掉以下两个目录所有*teamviewer*的文件
HOMEDIRLIB = '/Users/' + USERNAME + '/Library/preferences/'
GLOBALLIB = '/Library/preferences/'
2.修改原配置文件中生成的id
替换以下三个文件中的几个配置项
'/Applications/TeamViewer.app/Contents/MacOS/TeamViewer',
'/Applications/TeamViewer.app/Contents/MacOS/TeamViewer_Service',
'/Applications/TeamViewer.app/Contents/Helpers/TeamViewer_Desktop'
- 16进制的方式打开文件.
因为这几个文件是16进制的文件,vim打开后需要以16进制文件的方式读取,然后才可以看到内容,进而查询修改.
vim 开启16进制的指令是:%!xxd
- 生成新的id
- IOPlatformSerialNumber + 8位任意字母/数的新id
- IOPlatformExpert + 6位任意字母/数字的心id
- 替换 IOPlatformSerialNumber+后8位为(2)中的第一个id;替换IOPlatformExpert为(2)中的第二个id
注意,这三个文件的id要替换为同一组id,既(2)生成的id要用在每个文件的替换中
脚本如下
就是把上面啰嗦的一大堆改为python执行了.需要用到su权限.
#!/usr/bin/python3
#-*- coding=UTF-8 -*-
import sys
import os
import glob
import platform
import re
import random
import string
print('''
--------------------------------
修改Teamviewer for Mac的ID
--------------------------------
''')
# 如果在root权限,os.environ['SUDO_USER']返回用户名,如lining
USER_HOME = os.environ._data.get(b'HOME').decode()
# 下面两个目录是要搜索包含teamviewer字样的文件
HOMEDIRLIB = USER_HOME + '/Library/preferences/'
GLOBALLIB = '/Library/preferences/'
CONFIGS = []
# 获取配置文件的完全路径
def listdir_fullpath(d):
return [os.path.join(d, f) for f in os.listdir(d)]
for file in listdir_fullpath(HOMEDIRLIB):
if 'teamviewer'.lower() in file.lower():
CONFIGS.append(file)
if not CONFIGS:
print ('''
为发现配置文件,没什么可以删除的
''')
# 删除配置文件
else:
print("发现配置文件:\n")
for file in CONFIGS:
print( file)
print('''
这些配置文件将被永久删除
''')
#raw_input("请按<Enter>键盘删除文件或按<CTR+C>组合键退出程序")
for file in CONFIGS:
try:
os.remove(file) # 删除文件
except:
print("不能删除文件,是否权限不够?")
sys.exit();
print("搞定!")
TMBINARYES = [
'/Applications/TeamViewer.app/Contents/MacOS/TeamViewer',
'/Applications/TeamViewer.app/Contents/MacOS/TeamViewer_Service',
'/Applications/TeamViewer.app/Contents/Helpers/TeamViewer_Desktop',
]
# 这些文件必须存在,否则退出程序
for file in TMBINARYES:
if os.path.exists(file):
pass
else:
print("File not found: " + file)
print ("Install TeamViewer correctly")
sys.exit();
# 开始替换上述文件中的值
def idpatch(fpath,platf,serial):
file = open(fpath, 'rb')
binary = file.read()
# 定义模板
PlatformPattern = b"IOPlatformExpert.{6}"
SerialPattern = ('IOPlatformSerialNumber' + chr(0) +"[0-9a-zA-Z]{8,8}" + chr(0) + 'UUID').encode()
SerialPatternOld = (b'IOPlatformSerialNumber' + chr(0).encode() + serial + chr(0).encode() + 'UUID'.encode())
# 开始替换
binary = re.sub(PlatformPattern, platf, binary)
binary = re.sub(SerialPattern, SerialPatternOld, binary)
# 更新待修改的文件
file = open(fpath,'wb').write(binary)
return True
# 产生随机数,用于生成随机的ID
def random_generator(size=8, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size)).encode()
RANDOMSERIAL = random_generator()
RANDOMPLATFORM = b"IOPlatformExpert" + random_generator(6)
# 开始依次替换前面文件中的内容
for file in TMBINARYES:
try:
idpatch(file,RANDOMPLATFORM,RANDOMSERIAL)
except BaseException as e:
print( "错误:不能修改: " + file)
print(e.__str__())
sys.exit();
print('''
ID需要成功
!!! 必须重启计算机才能生效,good luck !!!!
''')