Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DnyaneshwarWagh/0ea5c556449443df247f5aaa2395d6f3 to your computer and use it in GitHub Desktop.
Save DnyaneshwarWagh/0ea5c556449443df247f5aaa2395d6f3 to your computer and use it in GitHub Desktop.
Change the ID of Teamviewer for macOS to circumvent "commercial use detected"
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import sys
import platform
import re
from pathlib import Path
from uuid import uuid4
print('Change ID of Teamviewer for macOS')
if platform.system() != 'Darwin':
print('You are not running macOS. Aborting.')
sys.exit();
if os.geteuid() != 0:
print('The script has to be run as root. Aborting.')
sys.exit();
if ('SUDO_USER' in os.environ):
USERNAME = os.environ['SUDO_USER']
if USERNAME == 'root':
print('Use sudo to run as root.')
sys.exit();
else:
print('Use sudo to run as root.')
sys.exit();
HOMEDIRLIB = '/Users/' + USERNAME + '/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 ('There is nothing to be deleted.')
else:
print("Configuration files found:\n")
for file in CONFIGS:
print(file)
print('These files are going to be permanently deleted.')
input("<Enter> Proceed, <Ctrl-C> Abort.")
for file in CONFIGS:
try:
os.remove(file)
except:
print("The file could not be deleted. Do you have the permissions?")
sys.exit();
print("Done.")
APP_DIR = Path('/Applications/TeamViewer.app/Contents/')
TMBINARYES = [
'MacOS/TeamViewer',
'MacOS/TeamViewer_Service',
'Helpers/TeamViewer_Desktop',
'Helpers/TeamViewer_Assignment',
]
TMBINARYES = [f for f in [APP_DIR / tgt for tgt in TMBINARYES] if f.exists()]
def idpatch(target: Path, platform: bytes, serial: bytes):
with target.open('rb') as f:
data = f.read()
data = re.sub(rb'(IOPlatformExpert)\w{6}', rb'\g<1>%s' % platform, data)
data = re.sub(rb'(IOPlatformSerialNumber\x00)\w{8}(\x00)', rb'\g<1>%s\g<2>' % serial, data)
with target.open('wb') as f:
f.write(data)
# Ad-hoc codesign the modified binary to fix `Code Signature Invalid` error.
os.system('codesign -f -s - "%s" 2> /dev/null' % str(target))
return True
def random_generator(size: int):
random = uuid4().hex[:size]
return random.upper().encode()
RANDOMPLATFORM, RANDOMSERIAL = map(random_generator, [6, 8])
for file in TMBINARYES:
try:
idpatch(file,RANDOMPLATFORM,RANDOMSERIAL)
except:
print("Error: " + file + " could not be modified.")
sys.exit();
print('\nUsing platform "%s" and serial "%s".' % (RANDOMPLATFORM.decode(), RANDOMSERIAL.decode()))
print('The ID was successfully changed. A reboot is required to apply the changes.')
@DnyaneshwarWagh
Copy link
Author

Note:

  • This script is from https://zhuanlan.zhihu.com/p/46180174. I fixed some bugs and translated it into English.
  • Both the client and server has to be Teamviewer 13. Above version will not work.

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