⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 psmscrlk.cpp

📁 一款防火墙源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//(C) 2003 PSMKorea
// PSMScrLk.cpp : Defines the initialization routines for the DLL.
//Main module for Screen Lock

#include "stdafx.h"
#include "PSMScrLk.h"
#include "LockForm.h"
#include "cregistry.h"
#include "md5.h"

//#include <WinSock.h>
//#pragma comment(lib, "wsock32.lib")

#include <nb30.h>
#include "hangePwForm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


//
//	Note!
//
//		If this DLL is dynamically linked against the MFC
//		DLLs, any functions exported from this DLL which
//		call into MFC must have the AFX_MANAGE_STATE macro
//		added at the very beginning of the function.
//
//		For example:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// normal function body here
//		}
//
//		It is very important that this macro appear in each
//		function, prior to any calls into MFC.  This means that
//		it must appear as the first statement within the 
//		function, even before any object variable declarations
//		as their constructors may generate calls into the MFC
//		DLL.
//
//		Please see MFC Technical Notes 33 and 58 for additional
//		details.
//

/////////////////////////////////////////////////////////////////////////////
// CPSMScrLkApp

typedef struct _ASTAT_
{
    ADAPTER_STATUS adapt;
    NAME_BUFFER    NameBuff [30];
}ASTAT, * PASTAT;

typedef struct tagKBDLLHOOKSTRUCT {
    DWORD   vkCode;
    DWORD   scanCode;
    DWORD   flags;
    DWORD   time;
    DWORD   dwExtraInfo;
} *PKBDLLHOOKSTRUCT;
#define WH_KEYBOARD_LL     13

//***Global Vars
//For Hook and ScreenLock Form:
LockForm	*pLockForm;//The Screen Lock Form (Will be always on top)
//CWnd		*pDesktopWnd;//Main Window

HINSTANCE	ghDLLInst		=	NULL;//Instance of this DLL
HHOOK		hKeyboardHook	=	NULL;//Handle to Keyboard Hook
HWND		hParent			=	NULL;//Parent Window which will receive keyboard event (CharCode)
BOOL		bFirstRun		=	FALSE;//Detect th first time using this module

//bLock is shared variable of all apps which use this DLL.
//App1 lock Screen -> bLock=TRUE, App2 call lock(), check if bLock -> does not lock second time.
#pragma data_seg(".SharedDataBetweenApps")
BOOL		bLock			=	FALSE;
#pragma data_seg()
#pragma comment(linker, "/section:.SharedDataBetweenApps,RWS")

//For REG: Store common information
#define PSMRegPath "SOFTWARE\\Microsoft\\PSMScrLk"
//***

BEGIN_MESSAGE_MAP(CPSMScrLkApp, CWinApp)
	//{{AFX_MSG_MAP(CPSMScrLkApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPSMScrLkApp construction

CPSMScrLkApp::CPSMScrLkApp()
{
	// TODO: add construction code here,
	//SetDialogBkColor(RGB(58,110,165));
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CPSMScrLkApp object
CPSMScrLkApp theApp;

//**************************************
//Function GetMAC:
//Purpose: Storing Password Purpopse.
//Md5HashValueOf(MAC of Network Card + Passwod) will be store in the Registry.
CString GetMAC()
{
	ASTAT Adapter;
    NCB ncb;
    BYTE bRetCode;
 
    memset( &ncb, 0, sizeof(ncb) );
    ncb.ncb_command = NCBRESET;
    ncb.ncb_lana_num = 0;
 
    bRetCode = Netbios( &ncb );
    //_tprintf( _T("The NCBRESET return code is: 0x%x \n"), bRetCode );
 
    memset( &ncb, 0, sizeof(ncb) );
    ncb.ncb_command = NCBASTAT;
    ncb.ncb_lana_num = 0;
 
    // Must be in non-unicode
    strcpy( (char*) ncb.ncb_callname,  "*               " );
    ncb.ncb_buffer = (unsigned char *) &Adapter;
    ncb.ncb_length = sizeof(Adapter);
 
    bRetCode = Netbios( &ncb );
    //_tprintf( _T("The NCBASTAT return code is: 0x%x \n"), bRetCode );
    if ( bRetCode == 0 )
    {
//        _tprintf( _T("The MAC Address is: %02x%02x%02x%02x%02x%02x\n"),
//                Adapter.adapt.adapter_address[0],
//                Adapter.adapt.adapter_address[1],
//                Adapter.adapt.adapter_address[2],
//                Adapter.adapt.adapter_address[3],
//                Adapter.adapt.adapter_address[4],
//                Adapter.adapt.adapter_address[5] );
		CString tmp;
		tmp.Format("%02x%02x%02x%02x%02x%02x",Adapter.adapt.adapter_address[0],Adapter.adapt.adapter_address[1],Adapter.adapt.adapter_address[2],Adapter.adapt.adapter_address[3],Adapter.adapt.adapter_address[4],Adapter.adapt.adapter_address[5]);
		return tmp;
    }
	else
	{
		return "";
	}
}

/* Function GetIP is No longer being used, use GetMAC instead.
CString GetIP(void)
{
	WORD wVersionRequested;
	WSADATA wsaData;
	char name[255];
	PHOSTENT hostinfo;
	wVersionRequested = MAKEWORD( 1, 1 );
	char *ip;
	CString tmp;
	name[0]='\0';
	
	if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
		if( gethostname ( name, sizeof(name)) == 0)
		{
			if((hostinfo = gethostbyname(name)) != NULL)
			{
				if(hostinfo->h_addr_list[0])
				{
					ip = inet_ntoa (*(struct in_addr *)hostinfo->h_addr_list[0]);
				}
			}
		}
	tmp.Format("%s%s",name,ip);
	return tmp;
}
*/

//Function GetHash
//Purpose: Get the unique Hash value of any string.
CString GetHash(CString str)
{
	CString stHash;
	char* tmp;
	tmp=MD5String((char*)(LPCTSTR)str);
	stHash.Format("%s",tmp);
	free(tmp);//Free the memory from the strdup() function in md5.cpp->PrintMD5
	return stHash;
}

//**************************************
//REG***********************************
//Function SaveSettings
//Purpose: Store information to the regidtry.
unsigned int SaveSettings(HKEY myKey, CString RegPath, CString Key, CString Value)
{
	CRegistry reg;
	try
	{
		if (!reg.CreateKey(myKey,RegPath))
		{
			return 0;
		};
	}
	catch (unsigned int error)
	{
		return error;
	}

	try
	{
		if (!reg.SetStringValue(myKey,RegPath,Key,Value))
		{
			return 0;
		}
	}
	catch (unsigned int error)
	{
		return error;
	}
	return 1;
}

//Function GetSettings.
//Purpose: Getting information form the registry
CString GetSettings(HKEY myKey, CString RegPath, CString Key)
{
	CRegistry reg;
	char str[1024];
	DWORD rS=1024;
	try 
	{
		if (!reg.GetStringValue(myKey,RegPath,Key,str,rS))
		{
			return (CString)"";
		}
	}
	catch(unsigned int error)
	{
		rS=error;//Hide the warning when Debug only
		return (CString)"";
	}

	if (rS>0)
	{
		return (CString)str;
	}
	else
	{
		return "";
	}
}

//Function SaveSettingsDWORD
//Purpose: Same function with SaveSettings, but store DWORD value.
unsigned int SaveSettingsDWORD(HKEY myKey, CString RegPath, CString Key, DWORD Value)
{
	CRegistry reg;
	try
	{
		if (!reg.CreateKey(myKey,RegPath))
		{
			return 0;
		};
	}
	catch (unsigned int error)
	{
		return error;
	}

	try
	{
		if (!reg.SetDWORDValue(myKey,RegPath,Key,Value))
		{
			return 0;
		}
	}
	catch (unsigned int error)
	{
		return error;
	}
	return 1;
}

//***********************************
//Function: HookKeyboardProc
//Purpose: Call back proc for Keyboard routine.
//This function will send the keycode to just only one LockForm Window.
LRESULT	CALLBACK HookKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	BOOL bKeyDown;
	BOOL bCapital;
	BOOL bShift;
	BOOL bUpper;
	DWORD lastCode;
	char lastChar;

	if (_winmajor>4){//WinNT/2000/XP
		bKeyDown=(wParam==WM_KEYDOWN);
	}else{//9x
		bKeyDown=((lParam >= 0x00000000) && (lParam < 0x10000000));
	}
	
	if (nCode==HC_ACTION)
	{
		if(bKeyDown){
			bCapital = (GetKeyState(VK_CAPITAL)!=0);
			bShift = (GetAsyncKeyState(VK_SHIFT)!=0);
			//1^1=0 BUT 129^1!=0!
			bUpper = bCapital ^ bShift;
			
			if (_winmajor>4)//WinNT/2000/XP
			{
				PKBDLLHOOKSTRUCT pStruct = (PKBDLLHOOKSTRUCT)lParam;
				lastCode=(DWORD)pStruct->vkCode;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -