屏幕锁
hdkghc
·
·
个人记录
ScreenCursorLocker.ini
[SCLpassword]
string = 1到10位密码(不含空格)
[/SCLpassword]
[CursorPosition]
x = 75
y = 55
[/CursorPosition]
[tries]
n = 5
[/tries]
InfLocker.cpp
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#define norm SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x07)
#define undl SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0a)
#define red SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0c)
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
void MyCls (HANDLE) ;
inline void clrscr (void)
{
HANDLE hStdOut = GetStdHandle (STD_OUTPUT_HANDLE);
MyCls (hStdOut);
return;
}
void MyCls (HANDLE hConsole)
{
COORD coordScreen = {0, 0};
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
bSuccess = GetConsoleScreenBufferInfo (hConsole, &csbi);
PERR (bSuccess, "GetConsoleScreenBufferInfo");
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
bSuccess = FillConsoleOutputCharacter (hConsole, (TCHAR)' ', dwConSize, coordScreen, &cCharsWritten);
PERR (bSuccess, "FillConsoleOutputCharacter");
bSuccess = GetConsoleScreenBufferInfo (hConsole, &csbi);
PERR (bSuccess, "ConsoleScreenBufferInfo");
bSuccess = FillConsoleOutputAttribute (hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
PERR (bSuccess, "FillConsoleOutputAttribute");
bSuccess = SetConsoleCursorPosition (hConsole, coordScreen);
PERR (bSuccess, "SetConsoleCursorPosition");
return;
}
int eh, em, et;
string psw;
int x, y, n;
bool flag = false;
HWND m_hWnd = GetConsoleWindow();
void lock()
{
SYSTEMTIME st;
GetLocalTime(&st);
int nt = st.wHour * 60 + st.wMinute;
if(nt >= et) flag = true;
POINT pt;
GetCursorPos (&pt);
if (KEY_DOWN (VK_LBUTTON) || KEY_DOWN (VK_RBUTTON) || KEY_DOWN (VK_MBUTTON))
{
//SetCursorPos (rand() % 1280, rand() * 1024);
SetCursorPos (54, 1023);
}
else if (pt.x != x || pt.y != y)
{
SetCursorPos (x, y);
}
RECT rc;
GetWindowRect (m_hWnd, &rc);
SetWindowLongPtr (m_hWnd, GWL_STYLE, GetWindowLong (m_hWnd, GWL_STYLE) & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX);
SetWindowPos (m_hWnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 0);
norm;
}
void print()
{
norm;
printf (" : input password to unlock cursor\r");
red;
for (int i = 1; i <= psw.length(); i++)
{
printf ("-");
}
norm;
printf ("\r");
}
void Slplk (DWORD millisec)
{
clock_t a = clock();
while (clock() - a < millisec)
{
lock();
}
}
int main(int argc, char **argv)
{
if(argc != 3)
{
throw;
}
eh = atoi(argv[1]);
em = atoi(argv[2]);
et = eh * 60 + em;
srand (time (NULL));
printf("Setting...\n");
::EnableMenuItem (::GetSystemMenu (m_hWnd, false), SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
::SetWindowPos (m_hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
::SetWindowLong (m_hWnd, GWL_STYLE, GetWindowLong (m_hWnd, GWL_STYLE) & ~WS_SIZEBOX);
::SetWindowPos (m_hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
::SetConsoleTitleA ("Screen Cursor Locker (SCL) Ver4.2-Infinity");
system("taskkill /im Explorer.exe /F");
printf("Loading initialize configuration file...\n");
ifstream fin;
fin.open ("./ScreenCursorLocker.ini");
string ig;
printf("Reading initialize configuration file...\n");
fin >> ig >> ig >> ig >> psw >> ig;
// [] str = - []
fin >> ig >> ig >> ig >> x >> ig >> ig >> y >> ig;
// [] x = -y = - []
fin >> ig >> ig >> ig >> n >> ig;
// [] n = - []
fin.close();
int cnt = 0;
printf("Locking...\n");
Sleep(1000);
system("cls");
print();
while (true)
{
lock();
if (kbhit())
{
bool ok = true;
for (int i = 0; i < psw.length(); i++)
{
char c = getch();
undl;
printf ("*");
norm;
if (c != psw[i])
{
ok = false;
}
if (c == ' ') // clear
{
clrscr();
ok = true;
i = -1;
print();
}
while (!kbhit())
{
if (i == psw.length() - 1)
{
Slplk(500);
break;
}
lock();
}
}
clrscr();
Slplk (500);
if (ok)
{
printf ("Unlocking...");
Slplk (500);
Sleep (500);
clrscr();
goto qwer;
}
else
{
++cnt;
printf ("Error!\n\tIncorrect password!");
Slplk (500);
clrscr();
print();
}
if (cnt % n == 0 && cnt != 0)
{
printf ("You must input password after 60 seconds");
printf ("\n\tbecause you try too much passwords.");
Slplk (2000);
clrscr();
clock_t a = clock();
while ((clock() - a) / 1000 < 61)
{
printf ("%d\r", (clock() - a) / 1000);
lock();
}
clrscr();
}
}
if(flag) goto qwer;
}
qwer:
::EnableMenuItem (::GetSystemMenu (m_hWnd, false), SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
system("start explorer");
printf ("Press any key to exit... ");
if(flag)
{
return 0;
}
printf ("\n\tOr press Enter to change password.");
char c = getch();
if (c == 13)
{
clrscr();
printf ("Input password long (1~10, 0 to exit) : ");
int l;
undl;
scanf ("%d", &l);
norm;
if (l < 0 || l > 11)
{
throw;
}
if (l == 0)
{
return 0;
}
if (l == 11)
{
clrscr();
printf ("Input Cursor XY (default 75, 55):\n");
undl;
scanf ("%d%d", &x, &y);
norm;
clrscr();
printf ("Input N (default 5) :\n");
int m;
undl;
scanf ("%d", &m);
norm;
if (m <= 20 && m >= 1) { n = m; }
clrscr();
printf ("Input password long (1~10, 0 to exit) : ");
undl;
scanf ("%d", &l);
norm;
if (l < 0 || l > 10) { throw; }
if (l == 0) { return 0; }
}
psw = "";
while (l--)
{
c = getch();
undl;
printf ("*");
norm;
if (!isdigit (c) && !isalpha (c) && !ispunct (c))
{
clrscr();
printf ("Error 01 : not a visible character.");
Sleep (2000);
throw;
}
psw += c;
}
ofstream fout;
fout.open ("./ScreenCursorLocker.ini");
fout << "[SCLpassword]" << endl;
fout << "string = " << psw << endl;
fout << "[/SCLpassword]" << endl;
fout << "[CursorPosition]" << endl;
fout << "x = " << x << endl;
fout << "y = " << y << endl;
fout << "[/CursorPosition]" << endl;
fout << "[tries]" << endl;
fout << "n = " << n << endl;
fout << "[/tries]" << endl;
fout.close();
}
return 0;
}
timelocker.cpp
// 1. Read File
/* Format:
[Hour1]:[Minute1]~[Hour2]:[Minute2]
[Hour3]:[Minute3]~[Hour4]:[Minute4]
...
*/
#include<Windows.h>
#include<iostream>
#include<stdio.h>
#define Error(str) MessageBoxA(NULL, str, "Error", MB_ICONHAND);
#define exit_0 exit(0)
#define s_fn "timetable.txt"
#define s_lfn "InfLocker.exe"
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
const int _Long = 1024;
struct timelib{
int h1, m1, h2, m2;
bool ok;
}tl[_Long];
string Start = "start \"Locker\" .\\";
FILE *rfile;
int libLong = 0;
struct TIME
{
int h, m, s;
};
void Init()
{
Start += (string)s_lfn;
Start += " ";
}
void ReadLib(const char *filename)
{
if((rfile = fopen(filename, "r")) == NULL) Error("File open error!")
int i = 0;
while(fscanf(rfile, "%02d:%02d~%02d:%02d", &tl[i].h1, &tl[i].m1, &tl[i].h2, &tl[i].m2) != EOF) i++;
libLong = i + 1;
fclose(rfile);
printf("debug: Print the lib:\n");
for(int j = 0; j < libLong; ++j)
{
printf("\t%02d:%02d~%02d:%02d\n", tl[j].h1, tl[j].m1, tl[j].h2, tl[j].m2);
tl[j].ok = false;
}
}
TIME GetTime()
{
SYSTEMTIME res;
GetLocalTime(&res);
return (TIME){res.wHour, res.wMinute, res.wSecond};
}
void RunLocker(int eh, int em)
{
char BUF[4];
printf("Loading...\n");
string __s = Start;
itoa(eh, BUF, 10);
__s += BUF;
itoa(em, BUF, 10);
__s += " ";
__s += BUF;
printf("Running...\n");
printf("Command : %s\n", __s.data());
system(__s.data());
}
void ScanAndResult()
{
TIME t(GetTime());
for(int i = 0; i < libLong; i++)
{
int a = tl[i].h1 * 60 + tl[i].m1;
int b = tl[i].h2 * 60 + tl[i].m2;
int c = t.h * 60 + t.m;
if(c >= a && c <= b && !tl[i].ok)
{
tl[i].ok = true;
printf("Running locker program...\n");
RunLocker(tl[i].h2, tl[i].m2);
}
}
}
int main()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x70);
printf(" F5 ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x07);
printf(" to FLASH.\n");
Sleep(2000);
Init();
printf("Reading...\n");
ReadLib(s_fn);
printf("Scanning...\n");
while(true)
{
if(KEY_DOWN(VK_F5))
{
system("start timelocker.exe");
return 0;
}
printf("Scanning...\t Time: %02d:%02d:%02d\n", GetTime().h, GetTime().m, GetTime().s);
ScanAndResult();
Sleep(50);
}
}