コード例 #1
0
ファイル: isense.c プロジェクト: sndae/winter-sense
//==========================================================================================
static DLL *ISD_LoadLib( void )
{
    if(hLib = dll_load( ISD_LIB_NAME ))
    {
        _ISD_OpenTracker            = ( ISD_OPEN_FN )           dll_entrypoint( hLib, "ISD_OpenTracker" );
        _ISD_OpenAllTrackers        = ( ISD_OPEN_ALL_FN )       dll_entrypoint( hLib, "ISD_OpenAllTrackers" );
        _ISD_CloseTracker           = ( ISD_COMMAND_FN )        dll_entrypoint( hLib, "ISD_CloseTracker" );
        _ISD_GetCommInfo            = ( ISD_COMM_INFO_FN )      dll_entrypoint( hLib, "ISD_GetCommInfo" );
        _ISD_GetTrackerConfig       = ( ISD_SYSTEM_CONFIG_FN )  dll_entrypoint( hLib, "ISD_GetTrackerConfig" );
        _ISD_SetTrackerConfig       = ( ISD_SYSTEM_CONFIG_FN )  dll_entrypoint( hLib, "ISD_SetTrackerConfig" );
        _ISD_GetStationConfig       = ( ISD_STATION_CONFIG_FN ) dll_entrypoint( hLib, "ISD_GetStationConfig" );
        _ISD_SetStationConfig       = ( ISD_STATION_CONFIG_FN ) dll_entrypoint( hLib, "ISD_SetStationConfig" );
        _ISD_GetTrackingData        = ( ISD_DATA_FN )           dll_entrypoint( hLib, "ISD_GetTrackingData" );
        _ISD_GetCameraData          = ( ISD_CAMERA_DATA_FN )    dll_entrypoint( hLib, "ISD_GetCameraData" );
        _ISD_SendScript             = ( ISD_SCRIPT_FN )         dll_entrypoint( hLib, "ISD_SendScript" );
        _ISD_NumOpenTrackers        = ( ISD_COUNT_FN )          dll_entrypoint( hLib, "ISD_NumOpenTrackers" );
        _ISD_ResetHeading           = ( ISD_RESET_HEADING_FN )  dll_entrypoint( hLib, "ISD_ResetHeading" );
        _ISD_Boresight              = ( ISD_BORESIGHT_FN )      dll_entrypoint( hLib, "ISD_Boresight" );
        _ISD_BoresightReferenced    = ( ISD_BORESIGHT_REF_FN )  dll_entrypoint( hLib, "ISD_BoresightReferenced" );
        _ISD_GetTime                = ( ISD_GET_TIME )          dll_entrypoint( hLib, "ISD_GetTime" );
        _ISD_ConfigureFromFile      = ( ISD_CONFIG_FILE_FN)     dll_entrypoint( hLib, "ISD_ConfigureFromFile" );
        _ISD_ConfigSave             = ( ISD_COMMAND_FN )        dll_entrypoint( hLib, "ISD_ConfigSave" );
        _ISD_AuxOutput              = ( ISD_AUX_OUTPUT_FN )     dll_entrypoint( hLib, "ISD_AuxOutput" );
        _ISD_UdpBroadcastData       = ( ISD_UDP_BROADCAST_FN )  dll_entrypoint( hLib, "ISD_UdpBroadcastData" );
        _ISD_GetSystemHardwareInfo  = ( ISD_SYS_INFO_FN )       dll_entrypoint( hLib, "ISD_GetSystemHardwareInfo" );
        _ISD_GetStationHardwareInfo = ( ISD_GET_HARDW_INFO_FN ) dll_entrypoint( hLib, "ISD_GetStationHardwareInfo" );
        _ISD_RingBufferSetup        = ( ISD_SET_RBUFFER_FN )    dll_entrypoint( hLib, "ISD_RingBufferSetup" );
        _ISD_RingBufferStart        = ( ISD_RBUFFER_FN )        dll_entrypoint( hLib, "ISD_RingBufferStart" );
        _ISD_RingBufferStop         = ( ISD_RBUFFER_FN )        dll_entrypoint( hLib, "ISD_RingBufferStop" );
        _ISD_RingBufferQuery        = ( ISD_QRY_RBUFFER_FN )    dll_entrypoint( hLib, "ISD_RingBufferQuery" );
    }
    
    if( hLib == NULL )
    {
        printf("Could not load %s\n", ISD_LIB_NAME);
    }
    
    return hLib;
}
コード例 #2
0
int _tmain(int argc, _TCHAR* argv[])
{
	WSADATA wsaData;
	SOCKET hServSock, hClntSock;
	SOCKADDR_IN serv_addr, clnt_addr;
	FILE *fp, *f_size;
	char message[BUF_SIZE];
	int clntAddrSize, len;
	int nx = 0, ny = 0;
	int ret;
	char data[BUF_SIZE];
	HWND hWnd_desktop = GetDesktopWindow();
	HWND hWnd_console = GetConsoleWindow();
	CImage capImage;
	HDC hdc = NULL;
	nx = GetSystemMetrics(SM_CXSCREEN);
	ny = GetSystemMetrics(SM_CYSCREEN);
	if(!hWnd_desktop) return 0;
	if(!hWnd_console) return 0;
	if(!capImage.Create(nx, ny, 32)) return 0;
	DWORD dwError;
	CTime t = CTime::GetCurrentTime();
	char szPath[] = "C:\\SCC";
	char szPath2[] = "C:\\SCC\\ProcessLog";
	//ShowWindow(hWnd_console, SW_HIDE);
	char currentDirectory[BUF_SIZE];
	GetCurrentDirectoryA(BUF_SIZE, currentDirectory);
	char serviceAdd[BUF_SIZE] = "\"";

	dll_load(&wsaData);
	memset(&serv_addr, 0, sizeof(serv_addr));
	conn_init(&hServSock, &serv_addr, 1234);

	if(bind(hServSock, (SOCKADDR*)&serv_addr, sizeof(serv_addr)) == SOCKET_ERROR)
		ErrorHandling("bind() Error");

	if(listen(hServSock, 5) == SOCKET_ERROR)
		ErrorHandling("listen() Error");

	clntAddrSize = sizeof(clnt_addr);

	while(1)
	{
		accept_client(&hClntSock, &hServSock, &clnt_addr, &clntAddrSize);
		
		memset(data, 0, sizeof data);
		ret = recv(hClntSock, data, 1024, 0);

		if(ret = 0 || WSAGetLastError() ==WSAETIMEDOUT) continue;
		
		if(ret == SOCKET_ERROR)
		{
			printf("WSAGETLASTERROR\n", WSAGetLastError());
			WSACleanup(); return 0;
		}
//hello	
		if(strcmp(data, "hello") == 0)
		{
			//printf("hello\n");
			if(shutdown(hClntSock, SD_SEND) == SOCKET_ERROR)
				ErrorHandling("shutdown() Error");
		}
//Shutdown
		if(strcmp(data, "shutdown") == 0)
		{
			//printf("shutdown\n");
			system("shutdown -s -t 1");
		}
//ShutdownTest
		if(strcmp(data, "shutdownTest") == 0)
		{
			//printf("shutdown\n");
			system("shutdown -s -t 100");
		}
//Process_Terminate
		if(data[16] == '|')
		{
			char tmp[100] = {0x0,};
			int cnt = 0;

			for(int i = 17; i < strlen(data); i++)
			{
				tmp[cnt] = data[i];
				cnt++;
			}

			int pid = atoi(tmp);
			char command[1024];

			sprintf(command, "taskkill /pid %d", pid);
			system(command);
		}


//SendMessage
		if(data[11] == '|')
		{
			char tmp[100] = {0x0, };
			int cnt = 0;

			for(int i = 12; i < strlen(data); i++)
			{
				tmp[cnt] = data[i];
				cnt++;
			}

			MessageBoxA(0, tmp, "Sent from Iphone", MB_OK);
		}
//Process_Get
		if(strcmp(data, "getProcess") == 0)
		{
			if (!CreateDirectoryA(szPath2, NULL))
			{
				dwError = GetLastError();
				switch (dwError)
				{
				case ERROR_ALREADY_EXISTS: break;
				default: CreateDirectoryA(szPath, NULL); break;
				}
			}
			EnumWindows(EnumWindowsProc, NULL);
			memset(message, 0, 1024);

			CTime t = CTime::GetCurrentTime();
			char processLog_file[BUF_SIZE];
			char *processLog_file_temp = "abcd";
			char test[BUF_SIZE] = "C:\\SCC\\ProcessLog\\test.txt";
			sprintf(processLog_file, "C:\\SCC\\ProcessLog\\%d%02d%02d%02d%02d%02d.txt", t.GetYear(), t.GetMonth(), t.GetDay(), t.GetHour(), t.GetMinute(), t.GetSecond());
			processLog_file_temp = processLog_file;

			//printf("processLog_file = %s \n", processLog_file);
			//printf("processLog_file_temp = %s \n", processLog_file_temp);

			f_size = fopen(processLog_file_temp, "r");
			if(f_size)
			{
				//printf("f_size\n");
				int size;
				fseek(f_size, 0, SEEK_END);
				size = ftell(f_size);
				char file_size[BUF_SIZE];
				itoa(size, file_size, 10);
				send(hClntSock, file_size, BUF_SIZE, 0);

				fp = fopen(processLog_file_temp, "rb");
				if(fp)
				{
					//printf("Sending\n");
					while(1)
					{
						len = fread(message, sizeof(char), BUF_SIZE, fp);
						send(hClntSock, message, len, 0);

						if(feof(fp)) 
						{
							Sleep(1500);
							send(hClntSock, "0", 2, 0);
							//printf("End Of File\n");
							break;
						}
					}
					//printf("Done ...\n");
					fclose(fp);
				}
				else{printf("No\n");}
			}
			else{printf("N0\n");}

			if(shutdown(hClntSock, SD_SEND) == SOCKET_ERROR)
				ErrorHandling("shutdown() Error");
		}
//ScreenShot
		if(strcmp(data, "getScreenshot") == 0)
		{
			//printf("screenshot\n");
			if (!CreateDirectoryA(szPath, NULL))
			{
				dwError = GetLastError();
				switch (dwError)
				{
				case ERROR_ALREADY_EXISTS: break;
				default: CreateDirectoryA(szPath, NULL); break;
				}
			}
			memset(message, 0, 1024);
			hdc = capImage.GetDC();
			BitBlt(hdc, 0, 0, nx, ny, GetWindowDC(hWnd_desktop), 0, 0, SRCCOPY);
			capImage.Save(_T("C:\\SCC\\temp.jpg"), Gdiplus::ImageFormatJPEG);
			capImage.ReleaseDC();

			f_size = fopen("C:\\SCC\\temp.jpg", "r");
			int size;
			fseek(f_size, 0, SEEK_END);
			size = ftell(f_size);
			char file_size[BUF_SIZE];
			itoa(size, file_size, 10);
			//char *size = file_size;
			send(hClntSock, file_size, BUF_SIZE, 0);

			fp = fopen("C:\\SCC\\temp.jpg", "rb");
			if(fp == NULL)
			{
				ErrorHandling("File Open Error!");
				continue;
			}
			else
			{
				//printf("Sending ...\n");
				while(1)
				{
					len = fread(message, sizeof(char), BUF_SIZE, fp);
					send(hClntSock, message, len, 0);

					if(feof(fp)) 
					{
						Sleep(1500);
						send(hClntSock, "0", 2, 0);
						//printf("End Of File\n");
						break;
					}
				}
				//printf("Done ...\n");
			}
			fclose(fp);
			if(shutdown(hClntSock, SD_SEND) == SOCKET_ERROR)
				ErrorHandling("shutdown() Error");
		}
		puts(data);
	}

	if(shutdown(hClntSock, SD_SEND) == SOCKET_ERROR)
		ErrorHandling("shutdown() Error");

	len = (hClntSock, message, BUF_SIZE-1, 0);
	message[len] = 0;
	fputs(message, stdout);

	conn_finish(&hClntSock);
	
    return 0;
}