介绍
一个有那么一点功能但是又不太保险的防沉迷工具
我脑子进水了才会写这玩意儿 为了变强,我不择手段(笑出zhu jiao
代码
好像没什么用的设定界面
Python
# -*- coding: utf-8 -*-
# Environment PyCharm
# File_name login |User Pfolg
# 2024/8/3 13:05
""" 想这样的,但是石粒不济,弄了个残废品出来可以用
有加密技术,能持续监管线程,能防止自身被击杀,能防止自身被删除,还能自主关闭
"""
import hashlib
import json
import os
import random
from tkinter import messagebox
from tkinter import ttk
import tkinter as tk
import time
count = 0
flag = False
bol = True
def mainControl(frame):
# 目标程序 这里可以翻任务管理器找程序名
appDict = {
"米哈游启动器": "HYPHelper.exe",
"原神": "YuanShen.exe",
"绝区零": "ZenlessZoneZero.exe",
"Bilibili": "哔哩哔哩.exe",
"网易云音乐": "cloudmusic.exe",
"腾讯视频": "QQLive.exe",
"雷神加速器": "leigod.exe",
"Steam": "steam.exe",
"QQ": "QQ.exe",
"微信": "WeChat.exe",
"Edge": "msedge.exe",
"QQ浏览器": "QQBrowser.exe",
"Chrome": "chrome.exe",
}
appList = list(appDict.keys())
BooleanVars = [tk.BooleanVar() for _ in range(len(appList))]
def selectAllApp(x):
if x:
for obj in BooleanVars:
obj.set(True)
else:
for obj in BooleanVars:
obj.set(False)
selectApp = tk.BooleanVar()
ttk.Checkbutton(
frame, text="全选", variable=selectApp, command=lambda: selectAllApp(selectApp.get())
).place(relx=.02, rely=.05)
for i in range(len(appList)):
ttk.Checkbutton(
frame, text=appList[i], variable=BooleanVars[i]
).place(relx=.02, rely=.05 * i + .12)
# 时间段
starTime, endTime = tk.StringVar(), tk.StringVar()
allTime = tk.BooleanVar()
def selectAllTime(x):
if x:
starTime.set(0.0)
endTime.set(24.0)
else:
starTime.set("")
endTime.set("")
timeList = [i * .5 for i in range(48)]
timeList.append(24.0)
ttk.Label(frame, text="Start").place(relx=.7, rely=.1)
ttk.Label(frame, text="end").place(relx=.7, rely=.2)
ttk.Combobox(frame, values=timeList, textvariable=starTime, width=6).place(relx=.75, rely=.1)
ttk.Combobox(frame, values=timeList, textvariable=endTime, width=6).place(relx=.75, rely=.2)
ttk.Checkbutton(
frame, text="全时段封禁", variable=allTime, command=lambda: selectAllTime(allTime.get())
).place(relx=.72, rely=.3)
try:
readf = open("Cache.txt", "r", encoding="utf-8")
settingList = json.load(readf)
for i in range(len(appList)):
BooleanVars[i].set(settingList[0].get(appList[i])[1])
starTime.set(settingList[1])
endTime.set(settingList[2])
c = settingList[3]
readf.close()
except BaseException:
print(404)
def getvalue():
global bol, b
if bol:
for j in range(len(BooleanVars)):
appDict[appList[j]] = [appDict.get(appList[j]), BooleanVars[j].get()]
bol = False
fileNameKeys = "究竟要不要在这里写上原理啥的呢,写了会怎么样,不写又会有什么结果?额,思来想去,我觉得我这个程序漏洞比较大,于是我决定加强主次程序间关系,废话一段,就这样吧。原理什么的别想了。"
myKeys = ""
for _ in range(3):
a = random.randint(0, len(fileNameKeys) - 1)
myKeys += fileNameKeys[a]
b = hashlib.md5(myKeys.encode()).hexdigest()
savef = open("Cache.txt", "w", encoding="utf-8")
json.dump([appDict, starTime.get(), endTime.get(), b], savef, ensure_ascii=False, indent=4)
messagebox.showinfo(title="message", message="Success")
savef.close()
try:
os.remove(f".\\{c}.txt")
except FileNotFoundError:
pass
lb1 = ttk.Label(frame, text="正在运行")
def startUp():
file = open(f".\\{b}.txt", "w", encoding="utf-8")
file.close()
os.system("start .\\killPID.pyw")
lb1.pack()
def stopAPP():
try:
os.remove(f".\\{b}.txt")
except NameError:
pass
os.remove(f".\\{c}.txt")
lb1.pack_forget()
ttk.Button(frame, text="Start", width=8, command=startUp).place(relx=.7, rely=.7)
ttk.Button(frame, text="Stop", width=8, command=stopAPP).place(relx=.8, rely=.7)
ttk.Button(frame, text="Help", width=8,
command=lambda: messagebox.showinfo(title="message", message="一选二保存三运行四停止")
).place(relx=.9, rely=.8)
ttk.Button(frame, text="保存", command=getvalue, width=8).place(relx=.9, rely=.9)
try:
if os.path.isfile(f".\\{c}.txt"):
lb1.pack()
except UnboundLocalError:
pass
# 判断用户名和密码是否正确,用的sha256
# 这里自己设置,我的用户名和密码就当模板罢,这玩意逆向不出来。(暴力破解、差分攻击......
def judge(x, y):
global count, flag
if (hashlib.sha256(x.encode()).hexdigest()
== "00cfe4cfcd27c0c2f658560a2068b1e7e9ae8ca64a93b8d8cad84c9d2603c18b"
and hashlib.sha256(y.encode()).hexdigest()
== "dc96921b3a27e6a8b257d6e6a2a3b083549e1bcd09b497b7f8cdd5a95867e2e3"):
messagebox.showinfo(title="Success", message="You are successfully logged in!")
frameLogin.place_forget()
window.title("游戏管理系统")
with open("log.txt", "a", encoding="utf-8") as f:
f.write(f"<Success-{count}>{time.strftime('%Y/%m/%d-%H:%M:%S', time.localtime())}\n")
frameControl.place(relx=0, rely=0, width=w, height=h)
return
elif count == 4:
messagebox.showerror(title="Fail", message="Sorry, your opportunity has been exhausted!")
with open("log.txt", "a", encoding="utf-8") as f: # 不管登录成功或失败都要记录日志
f.write(f"<Fail-{count}>{time.strftime('%Y/%m/%d-%H:%M:%S', time.localtime())}\n")
return
else:
messagebox.showerror(title="Fail", message="Something error,please try again!\n"
f"left:{4 - count},all:5")
count += 1
# 登录界面
def pwdAndUser(frame):
user, pwd = tk.StringVar(), tk.StringVar()
ttk.Label(frame, text="WELCOME", font=("msyh.ttc", 30)).place(relx=.38, rely=.2)
ttk.Label(frame, text="UserName").place(relx=.3, rely=.4)
ttk.Label(frame, text="Password").place(relx=.3, rely=.5)
ttk.Entry(frame, width=20, textvariable=user).place(relx=.4, rely=.4)
ttk.Entry(frame, width=20, textvariable=pwd).place(relx=.4, rely=.5)
ttk.Button(frame, text="Login", command=lambda: judge(user.get(), pwd.get())).place(relx=.43, rely=.6)
if __name__ == '__main__':
window = tk.Tk()
window.title("Login")
screen_w, screen_h = window.winfo_screenwidth(), window.winfo_screenheight()
w, h = int(screen_w / 2), int(screen_h / 2)
window.geometry(f'{w}x{h}+{int(screen_w / 4)}+{int(screen_h / 4)}')
window.resizable(False, False)
frameLogin = ttk.Frame(window)
frameLogin.place(relx=0, rely=0, width=w, height=h)
pwdAndUser(frameLogin)
frameControl = ttk.Frame(window)
mainControl(frameControl)
window.mainloop()
主要运行程序
原理嘛,寻找并击杀线程
Python
# -*- coding: utf-8 -*-
# Environment PyCharm
# File_name killPID |User Pfolg
# 2024/8/4 17:46
import json
import psutil
import time
import os
from plyer import notification
flag = True
def find_and_kill_process(process_name):
# 查找所有名为process_name的进程
for proc in psutil.process_iter(['name']):
if proc.info['name'] == process_name:
# 记录优化日志
f = open(".\\log.txt", "a", encoding="utf-8")
f.write(f"{time.strftime('%Y/%m/%d-%H:%M:%S', time.localtime())}\t{process_name}\t{proc.pid}\n")
f.close()
print(f"找到进程: {proc.info['name']} (PID: {proc.pid})")
# 尝试关闭进程
try:
proc.terminate() # 发送终止信号
proc.wait(timeout=10) # 等待进程结束
print(f"进程 {proc.pid} 已被终止。")
# messagebox.showerror(title="Windows", message="未知错误!")
except psutil.NoSuchProcess:
print(f"进程 {proc.pid} 已经不存在。")
except psutil.AccessDenied:
notification.notify(
title='Reminder',
message="No power to end"+str(proc.pid),
timeout=10, # 通知显示时间,单位为秒
)
print(f"没有权限终止进程 {proc.pid}。")
except Exception as e:
print(f"终止进程 {proc.pid} 时发生错误: {e}")
break # 如果只需要关闭一个进程,找到后即可退出循环
def mainProcess():
global flag
file = open(".\\Cache.txt", "r", encoding="utf-8")
setInf = json.load(file)
appInf = setInf[0]
begin = setInf[1]
over = setInf[2]
name = setInf[3]
file.close()
app = []
# 筛选可禁用的应用
for i in appInf.keys():
x = appInf.get(i)
if x[1]:
app.append(x[0])
notification.notify(
title='Reminder',
message="System Start Running",
timeout=3, # 通知显示时间,单位为秒
)
while flag:
may_now = time.strftime("%H:%M", time.localtime()).split(":")
now = int(may_now[0]) + int(may_now[1]) / 60
if float(begin) <= now <= float(over):
for i in app:
find_and_kill_process(i)
time.sleep(.1) # 减速减内存
if os.path.isfile(f".\\{name}.txt"):
pass
else:
flag = False
notification.notify(
title='Reminder',
message="System End Running",
timeout=3, # 通知显示时间,单位为秒
)
if __name__ == '__main__':
mainProcess()
效果
上个视频看看吧>
额,那个弹窗我后面删了,程序就显得比较隐蔽了。
不足
功能不强,想禁的程序只能在代码里添加;
删掉md5码生成的txt文件后程序就退出运行了;
太简陋朴实了。
其他
可以手动设置开机自启动,把程序2放到startup文件夹内就可以了;
可以生成日志,登录啥的、线程击杀啥的;
CPU占用一般在0-10%间,最多时间在1%-2%;
改改代码就能自己用了。