2019-07-25


#!/usr/bin/env python 
 
#coding:utf-8
import sys
import os
import glob
import platform
import re
import random
import string
 
print('''
--------------------------------
TeamViewer ID Changer for MAC OS
--------------------------------
''')
 
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 os.environ.has_key('SUDO_USER'):
    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'.lower() 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.
''')
# Delete config files
else:
    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/TeamViewer_Desktop',
]
 
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%sUUID"
 
    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.digits):
    return ''.join(random.choice(chars) for _ in range(size))
 
RANDOMSERIAL = random_generator()
RANDOMPLATFORM = "IOPlatformExpert" + random_generator(6)
 
 
for file in TMBINARYES:
        try:
            idpatch(file,RANDOMPLATFORM,RANDOMSERIAL)
        except:
            print "Error: can not patch file " + file
            print "Wrong version?"
            sys.exit();
 
print "PlatformDevice: " + RANDOMPLATFORM
print "PlatformSerial: " + RANDOMSERIAL
 
print('''
ID changed sucessfully.
!!! Restart computer before using TeamViewer !!!!
''')

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 想记录点什么东西,但拿起笔又发觉没什么可记录的,连记录枯燥的生活都觉得是一种让人沮丧的事情。吃了两个星期的欣百达和...
    飞翔的小鱼阅读 125评论 0 0
  • 跑步 不得不继续说,天气越来越热。一大早就能够把我热得个半死,然后每跑(跑得还是极慢的)2K就休息一会儿,即使这样...
    areece阅读 209评论 0 0
  • 【190131】 6&7/10000《高倍速阅读法》《如何有效阅读一本书》 推荐星级★★★★ 为了实现19年百读计...
    珠珠在盛开阅读 190评论 0 0
  • 道德绑架这个词在近几年非常火,不管是“坏人变老了”,还是“他只是个孩子”,都让很多人深受其害。但是,我今天要说的不...
    紫霞仙子的剑阅读 746评论 0 0
  • 华大在线讯(记者周健)随着“双一流”建设和新校区建设任务的提出,未来要把学校建成什么样、采取什么措施、保持什么样的...
    佳欣er阅读 113评论 0 0