Escribir un casillero de Windows en Python 3.x

Saludos a los amantes de las pitones. Una vez metí accidentalmente mi dedo en ctypes. Y sabes, me gustó. Especialmente el bloque de entrada del teclado y el mouse. Y lo primero que me vino a la mente fue: "¿Por qué no escribir un casillero para Windows en python, con desbloqueo en una unidad flash USB, como una llave?" (No preguntes por qué, yo mismo no lo sé). Y luego mi imaginación se fue. Ahora voy a anotar lo que tienes que afrontar para escribirlo.



Bueno, ¡empecemos!



El primer paso es crear una parte gráfica del casillero. No haremos una sábana estúpidamente blanca: d

Le pondremos un nombre. ... ... locker.pyw





¿Por qué pyw? Sí, porque cuando enciendes el casillero saldrá la consola, que un potencial tío malo puede cerrar, entonces se tapará todo el casillero, pero no lo necesitamos.





import hashlib
import time
import sys
import os
from tkinter import Tk, Entry, Label
import tkinter
import pyautogui
import threading
from lofu import *
      
      



Importación de bibliotecas para locker.pyw





* hashlib, necesitamos guardar la clave en forma de hash, por lo que hay menos posibilidades de que se elimine (si no la necesitas, no tienes que importarla)







* el tiempo es solo para dormir ()







* sys para una salida agradable exit ()







* os para iniciar la tarea del sistema () parte del casillero







* tkinter esta es nuestra parte gráfica







* pyautogui para mover el mouse a una esquina (déjelo pensar en su comportamiento)







* enhebrado para el segundo hilo de desplazamiento del mouse (para no interferir con el hilo principal)







* lofu. ... ... ... Pongo un par de funciones, solo en otro archivo y listo, soy un artista, como lo veo!





Hagamos la función de mover el mouse hacia un lado para que el usuario no tenga tiempo de hacer clic en ningún lado.





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 -





Threading









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)





Tkinter





.

.





, . , " " , 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, " ".





Eso es todo. ¡Mis felicitaciones! ¡Acabamos de hacer un casillero para Windows en Python 3.xc con bloqueo completo de entrada a través del "Programador de tareas" , con desbloqueo a través de una unidad flash USB, con una clave hash y una interfaz gráfica!



PD: también puedes poner el atajo locker.pyw en el campo " Atajo " para enlazar teclas para un bloqueo rápido.








All Articles