Skip to content

Instantly share code, notes, and snippets.

@zhenhappy
Last active August 10, 2024 14:06
Show Gist options
  • Save zhenhappy/3c808a198715978a38acf0ba44044ea6 to your computer and use it in GitHub Desktop.
Save zhenhappy/3c808a198715978a38acf0ba44044ea6 to your computer and use it in GitHub Desktop.
TV changer for Mac
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import platform
import random
import re
import string
import sys
print('''
--------------------------------
TeamViewer ID Changer for MAC OS
--------------------------------
''')
if sys.version[0:1] != "2":
print("This script can be run only on Python27.")
sys.exit()
if platform.system() != "Darwin":
print("This script can be run only on MAC OS.")
sys.exit()
if os.geteuid() != 0:
print("This script must be run form root.")
sys.exit()
if "SUDO_USER" in os.environ:
USERNAME = os.environ["SUDO_USER"]
if USERNAME == "root":
print("Can not find user name. Run this script via sudo from regular user")
sys.exit()
else:
print("Can not find user name. Run this script via sudo from regular user")
sys.exit()
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('''
There is no TemViewer configs found.
Maybe you have deleted it manualy or never run TeamViewer after installation.
Nothing to delete.
''')
else:
# Delete config files
print("Configs found:\n")
for file in CONFIGS: print(file)
print('''
This files will be DELETED permanently.
All TeamViewer settings will be lost
''')
raw_input("Press Enter to continue or CTR+C to abort...")
for file in CONFIGS:
try:
os.remove(file)
except:
print("Cannot delete config files. Permission denied?")
sys.exit()
print("Done.")
# Find binaryes
TMBINARYES = [
'/Applications/TeamViewer.app/Contents/MacOS/TeamViewer',
'/Applications/TeamViewer.app/Contents/MacOS/TeamViewer_Service',
'/Applications/TeamViewer.app/Contents/Helpers/Restarter',
'/Applications/TeamViewer.app/Contents/Helpers/TeamViewer_Assignment'
]
for file in TMBINARYES:
if os.path.exists(file):
pass
else:
print("File not found: " + file)
print ("Install TeamViewer correctly")
sys.exit()
# 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("Error: can not patch file " + file)
sys.exit()
print("PlatformDevice: " + RANDOMPLATFORM)
print("PlatformSerial: " + RANDOMSERIAL)
os.system("sudo codesign --force --deep --sign - /Applications/TeamViewer.app/")
print('''
ID changed sucessfully.
!!! Restart computer before using TeamViewer !!!!
''')
@zhenhappy
Copy link
Author

My issue was quite simple:

/Applications/TeamViewer.app/: replacing existing signature
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
/Applications/TeamViewer.app/: the codesign_allocate helper tool cannot be found or used

I have installed CommandLineTools from terminal using
xcode-select --install

You can try this answer https://stackoverflow.com/questions/29848622/codesign-allocate-error-unable-to-find-utility-codesign-allocate-not-a-deve

No need, I explain my issue and how I sorted it. All working fine. Just posted in case other will have simillar.

Thanks

@AlanSachin
Copy link

TV 版本15.1.3937
系统版本:macOS 10.15.3 (19D49f)
使用这个脚本并且系统关闭SIP后,重启后第一次打开TV,可以正常使用。
不过完全退出TV后,再次打开TV,会提示需要提示安装帮助程序,输入密码后闪退,只有重启一次,才可以正常打开。
如果再次完全退出TV的话,也就只能重启一次才能重新打开TV,不过还是非常感谢作者的脚本。
Xnip2020-01-09_01-03-15

@zhenhappy
Copy link
Author

TV 版本15.1.3937
系统版本:macOS 10.15.3 (19D49f)
使用这个脚本并且系统关闭SIP后,重启后第一次打开TV,可以正常使用。
不过完全退出TV后,再次打开TV,会提示需要提示安装帮助程序,输入密码后闪退,只有重启一次,才可以正常打开。
如果再次完全退出TV的话,也就只能重启一次才能重新打开TV,不过还是非常感谢作者的脚本。
Xnip2020-01-09_01-03-15

你这个不太清楚是什么原因, 我版本跟你一样的, 并没有出现这个情况, 你看下是不是试着卸载清理干净重新装下试试

@hungdev
Copy link

hungdev commented Jan 16, 2020

@zhenhappy thank for your support new version 15. I love you <3

@YC-Cheung
Copy link

同样出现退出后提示安装新帮助,然后闪退,重启后能正常使用

@NewHongjayGitHub
Copy link

works for me,thx

@josangmi
Copy link

只能用在2.7版本吗? 我的mac装了3.7 是不是就不能用了? 一直报
can not patch file /Applications/TeamViewer.app/Contents/MacOS/TeamViewer
这个应该怎么处理呢,谢谢。

@zhenhappy
Copy link
Author

只能用在2.7版本吗? 我的mac装了3.7 是不是就不能用了? 一直报
can not patch file /Applications/TeamViewer.app/Contents/MacOS/TeamViewer
这个应该怎么处理呢,谢谢。

原则上Mac默认自带都有自带python27, 为了兼容大多数人嘛, 你运行的时候用/usr/bin/python方式运行就可以, python3也不是不行, 有几句话版本上有差异, 有能力的话自己改下也可以

@kampiamodikuesto
Copy link

kampiamodikuesto commented Aug 16, 2021

Hi, I have a problem, how can I fix it? Teamviewer 15
Last login: Sat Dec 21 11:14:42 on ttys000
vitaliygorsky@MBPVitaiiGorsky ~ % sudo /usr/bin/python TeamViewer-14-id-changer-for-mac.py
Password:
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'TeamViewer-14-id-changer-for-mac.py': [Errno 2] No such file or directory
vitaliygorsky@MBPVitaiiGorsky ~ % cd desktop
vitaliygorsky@MBPVitaiiGorsky desktop % sudo /usr/bin/python TeamViewer-14-id-changer-for-mac.py

TeamViewer ID Changer for MAC OS

Configs found:
/Users/vitaliygorsky/library/preferences/com.teamviewer.TeamViewer.plist
/Users/vitaliygorsky/library/preferences/com.teamviewer.teamviewer.preferences.Machine.plist
This files will be DELETED permanently.
All TeamViewer settings will be lost
Press Enter to continue or CTR+C to abort...
Done.
File not found: /Applications/TeamViewer.app/Contents/Helpers/TeamViewer_Desktop
Install TeamViewer correctly
vitaliygorsky@MBPVitaiiGorsky desktop %

yeah, I update the code, you can download the lastest version and try it again

same problem

$ sudo python ./TeamViewer-id-changer2.py
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file './TeamViewer-id-changer2.py': [Errno 2] No such file or directory
$ ls
TeamViewer-id-changer_2.py 	readme.md

I try also with absolute path but nothing. is it my python configuration the problem?

@TheCrow1137
Copy link

sen this erro:

Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'TeamViewer.py': [Errno 2] No such file or directory

@idarek
Copy link

idarek commented Jun 23, 2022

sen this erro:

Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'TeamViewer.py': [Errno 2] No such file or directory

See this

@STiXzoOR
Copy link

For anyone looking for a python 3 based script: STiXzoOR/ab46bfebcf6644d6f2aebb97d09cd6f9

@idarek
Copy link

idarek commented Nov 18, 2022

For anyone looking for a python 3 based script: STiXzoOR/ab46bfebcf6644d6f2aebb97d09cd6f9

Super!

@changhexingchen
Copy link

我运行程序正常,但是重新开机ID没有变化。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment