Saudações aos amantes do python. Uma vez eu acidentalmente enfiei meu dedo em ctypes. E você sabe, eu gostei. Especialmente o bloco de entrada de teclado e mouse. E a primeira coisa que me veio à mente foi: "Por que não escrever um armário para Windows em python, com desbloqueio em uma unidade flash USB, como uma chave" (Não pergunte por quê, eu não me conheço). E então minha imaginação foi embora. Agora vou escrever o que você tem que enfrentar para escrevê-lo.
Bem, vamos começar!
O primeiro passo é criar uma parte gráfica do armário. Não faremos um lençol estupidamente branco: d
Vamos nomeá-lo. ... ... locker.pyw
Por que pyw? Sim, porque quando você inicia o armário, o console vai sair, que um tio malvado em potencial pode fechar, então todo o armário estará coberto, mas não precisamos disso.
import hashlib
import time
import sys
import os
from tkinter import Tk, Entry, Label
import tkinter
import pyautogui
import threading
from lofu import *
Importando bibliotecas para locker.pyw
* hashlib, precisamos salvar a chave em um formato hash, para que haja menos chance de sucata (se você não precisar dela, não precisará importá-la!)
* hora é só para dormir ()
* sys para boa saída exit ()
* os para iniciar a tarefa do sistema () parte do armário
* tkinter esta é a nossa parte do gráfico
* pyautogui para mover o mouse para um canto (deixe-o pensar sobre seu comportamento)
* threading para o segundo thread de deslocamento do mouse (de modo a não interferir com o thread principal)
* lofu. ... ... ... Coloquei algumas funções, só em outro arquivo e pronto, sou um artista, a meu ver!
Vamos fazer a função de mover o mouse para o lado para que o usuário não tenha tempo de clicar em nenhum lugar.
def mouse_trac(screen_width, screen_height):
while True:
pyautogui.moveTo(screen_width, screen_height)
pyautogui.moveTo(screen_width, screen_height) - ( , )
screen_width, screen_height
Tk(), ,
root = Tk()
root.attributes('-fullscreen', True)
pyautogui.FAILSAFE = False
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
root.attributes('-fullscreen', True) - .
pyautogui.FAILSAFE = False - , .
screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() - ,
,
x = threading.Thread(target=mouse_trac, args=(screen_width, screen_height), daemon=True)
x.start()
target=mouse_trac - ,
args=(screen_width, screen_height) -
daemon=True -
label = Label(root, text='Enter flesh drive with code!', font='Courier 15', fg='#C71585')
label.place(relx=.5, rely=.94, anchor="center")
label3 = Label(root, text='USBCODE waiting...', font='Courier 20', fg='#00BFFF')
label3.place(relx=.5, rely=.40, anchor="center")
label4 = Label(root, text='Powered by .... wait....by who?', font='Courier 15', fg='#C71585')
label4.place(relx=.1, rely=.95, anchor="center")
root.update()
label = Label(root, text='Enter flesh drive with code!', font='Courier 15', fg='#C71585') label.place(relx=.5, rely=.94, anchor="center") -
root -
text - :G
font -
fg - HTML ( https://colorscheme.ru/html-colors.html )
relx - X
rely - Y
anchor="center" -
root.update() - ( CTRL+S)
.
.
, . , " " , windows. windows " ". , , . ( , , ).
" "
"" ( )
" "
, ""
""
: " " " (, 1 , )"
""
" "
! ? . . .
. input_block.pyw
from ctypes import *
import time
import sys
from lofu import *
while True:
statusl = status_lock()
if str(statusl) == '0':
windll.user32.BlockInput(False)
elif str(statusl) == '1':
windll.user32.BlockInput(True)
lofu
def status_lock():
filee = open(r' ', 'r')
return filee.read()
filee.close()
def disable_lock():
filee = open(r' ', 'w')
text = 0
filee.write(str(text))
filee.close()
def enable_lock():
filee = open(r' ', 'w')
text = 1
filee.write(str(text))
filee.close()
, : " , ? JSON ! !"
json, sqlite3 . . . !
input_block.pyw >> input_block.exe
pyinstaller
pyinstall input_block.pyw --onefile
? pyinstaller?
pip install pyinstaller
" ".
" " " " .
locker.pyw
os.system('schtasks.exe /run /tn " "')
, ,
while True:
try:
enable_lock()
file = open(r'F:\key.txt','r')
file_t = str(file.read())
file.close()
hash_object = hashlib.sha256(file_t.encode())
hex_dig = hash_object.hexdigest()
if ' -' == str(hex_dig):
label3.configure(text='USBCODE correct. Unlocking...', fg='#00FF00', font="Courier 30")
root.update()
time.sleep(4)
disable_lock()
sys.exit()
else:
label3.configure(text='USBCODE incorrect. Try again!', fg='#FF0000', font="Courier 30")
enable_lock()
root.update()
except SystemExit:
sys.exit()
except:
time.sleep(10)
label3.configure(text='USBCODE not found! Waiting...', fg='#FF1493', font="Courier 20")
enable_lock()
root.update()
, . ,
enable_lock() - lofu
disable_lock() - lofu -
time.sleep(N) -
file = open(r'F:\key.txt','r')
file_t = str(file.read())
file.close() - ,
hash_object = hashlib.sha256(file_t.encode())
hex_dig = hash_object.hexdigest() -
if ' ' == str(hex_dig): - :d
:
* - ( , , , )
* ( )
* ( - locker.pyw)
, locker.pyw.
, shell:startup, " ".
Isso é tudo. Meus parabéns! Acabamos de fazer um locker para Windows em Python 3.xc com bloqueio completo de entrada através do "Agendador de Tarefas" , com desbloqueio através de pen drive USB, com chave hash e interface gráfica!
PS Você também pode inserir o atalho locker.pyw no campo " Atalho " para vincular as teclas e travar rapidamente.