0
0

More than 1 year has passed since last update.

vaccine_gene感染チェック

Last updated at Posted at 2022-09-14

なにかまた流れてきたので、vacciene_geneの挙動を流用してチェック用のスクリプトを書いてみる。

なにをチェックする?

感染のチェックとしては

  • 所定のフォルダに vaccine.py が存在するか否か
  • userSetup.pyに該当する内容が書き込まれているか否か

とりあえずこの2点に絞ってみる。

優先度が高いのは vaccine.pyの有無。
userSetup.pyが汚染されてても、実行されるvaccine.pyが無ければとりあえずは感染拡大しないはず。

所定のフォルダに vaccine.py が存在するか否か

所定のフォルダの指定は、本家挙動に習ってそのまま流用。

cmds.internalVar(userAppDir=True) + '/scripts'

そのままファイルの有無をチェック

health = True
targetPath = cmds.internalVar(userAppDir=True) + '/scripts'

if os.path.exists(targetPath + "/vaccine.py"):
    health = False

userSetup.pyに該当する内容が書き込まれているか否か

該当する内容っつーのが3行

import vaccine
cmds.evalDeferred('leukocyte = vaccine.phage()')
cmds.evalDeferred('leukocyte.occupation()')

これがuserSetup.pyに書き込まれているか否かをチェックしたい。
userSetup を1行ずつ読み込んでチェック

health = True

targetPath = cmds.internalVar(userAppDir=True) + '/scripts'

if os.path.exists(targetPath + "/userSetup.py"):
    sampleLine = [
                "import vaccine",
                "cmds.evalDeferred('leukocyte = vaccine.phage()')",
                "cmds.evalDeferred('leukocyte.occupation()')"
    ]
    with open(targetPath + "/userSetup.py", "r") as f:
        for line in f:
            line = line.rstrip()

            if line in sampleLine:
                health = False
            
    f.close()     

まとめる

2つのチェック項目をまとめて1個にすると、こんな感じかしら。

import maya.cmds as cmds

def checkVaccineGene():
    health = True
    targetPath = cmds.internalVar(userAppDir=True) + '/scripts'

    if os.path.exists(targetPath + "/vaccine.py"):
        health = False
        
    if os.path.exists(targetPath + "/userSetup.py"):
        sampleLine = [
                    "import vaccine",
                    "cmds.evalDeferred('leukocyte = vaccine.phage()')",
                    "cmds.evalDeferred('leukocyte.occupation()')"
        ]
               
        with open(targetPath + "/userSetup.py", "r") as f:
            for line in f:
                line = line.rstrip()

                if line in sampleLine:
                    health = False
                
        f.close()                

    return health

でも感染してるファイルを野放しにすると意味が無いので、感染元は特定してください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0