1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import platform
import random
import re
import string
import sys

USERNAME = os.environ["SUDO_USER"]
HOMEDIRLIB = "/Users/" + USERNAME + "/library/preferences/"
GLOBALLIB = "/library/preferences/"

CONFIGS = []


# Find config files

def listdir_fullpath(d):
return [os.path.join(d, f) for f in os.listdir(d)]


for file in listdir_fullpath(HOMEDIRLIB):
if 'teamviewer' in file.lower():
CONFIGS.append(file)

for file in listdir_fullpath(GLOBALLIB):
if 'teamviewer' in file.lower():
CONFIGS.append(file)

if not CONFIGS:
print("")
else:
for file in CONFIGS:
try:
os.remove(file)
except:
print("不能删除配置文件。没有权限")
sys.exit()

# Find binaryes

TMBINARYES = [
'/Applications/TeamViewer.app/Contents/MacOS/TeamViewer',
'/Applications/TeamViewer.app/Contents/MacOS/TeamViewer_Service',
'/Applications/TeamViewer.app/Contents/Helpers/Helper',
'/Applications/TeamViewer.app/Contents/Helpers/TeamViewer_Assignment'
]

for file in TMBINARYES:
if os.path.exists(file):
pass

# Patch files

def idpatch(fpath, platf, serial):
file = open(fpath, 'r+b')
binary = file.read()
PlatformPattern = "IOPlatformExpert.{6}"
SerialPattern = "IOPlatformSerialNumber%s%s%s"

binary = re.sub(PlatformPattern, platf, binary)
binary = re.sub(SerialPattern % (chr(0), "[0-9a-zA-Z]{8,8}", chr(0)), SerialPattern % (chr(0), serial, chr(0)), binary)

file = open(fpath, 'wb').write(binary)
return True


def random_generator(size=8, chars=string.ascii_uppercase + string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))


RANDOMSERIAL = random_generator(8)
RANDOMPLATFORM = "IOPlatformExpert" + random_generator(6)

for file in TMBINARYES:
try:
idpatch(file, RANDOMPLATFORM, RANDOMSERIAL)
except:
print("更换ID失败")
sys.exit()