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

📄 shell.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 5 页
字号:
	Args.Count=2;
	DisplayMemory(&Args);

    DPRINT((0,"DebuggerShell(): Unassemble()\n"));

    // disassembly from current address
    PICE_memset(&Args,0,sizeof(ARGS));
	Args.Value[0]=CurrentCS;
	Args.Value[1]=CurrentEIP;
	Args.Count=2;
	Unassemble(&Args);

    // try to find current process's name
    pCurrentProcess = IoGetCurrentProcess();
    CurrentProcess = (ULONG)pCurrentProcess;

    // display status line
    ShowStatusLine();

	// switch on cursor
	ShowCursor();

    // while we are not told to exit
	while(bNotifyToExit==FALSE)
	{
		// emulate graphics cursor
		PrintCursor(FALSE);

		// we have a key press
		if((ucKeyPressedWhileIdle = GetKeyPolled())!=0)
		{
            DPRINT((0,"DebuggerShell(): key = %x control = %u shift = %u\n",ucKeyPressedWhileIdle,bControl,bShift));

            // if cursor reversed, normalize it again (only graphics)
            if(bRev)
            {
			    PrintCursor(TRUE);
            }

			// convert key to ANSI, if success add to command buffer and try to
			// find a command that fits the already entered letters
            ucConverted = AsciiFromScan((UCHAR)(ucKeyPressedWhileIdle&0x7f));

#if 0
            PICE_sprintf(tempShell,"%u -> %u",ucKeyPressedWhileIdle, ucConverted);
            PutChar(tempShell,GLOBAL_SCREEN_WIDTH-32,wWindow[OUTPUT_WINDOW].y-1);
#endif

			if(!bControl && !bAlt && ucConverted)
			{
                DPRINT((0,"DebuggerShell(): normal key\n"));
                if(!(usCurrentPosInInputBuffer==0 && ucConverted==' '))
                {
				    // if we have space in the command buffer
				    // put the character there
				    if(usCurrentPosInInputBuffer<sizeof(ucCommandBuffer)-1)
				    {
					    ucCommandBuffer[usCurrentPosInInputBuffer++]=ucConverted;
					    // output the character
					    PICE_sprintf(tempShell,"%c",ucConverted);
                        wWindow[OUTPUT_WINDOW].usCurX = 1;
					    Print(OUTPUT_WINDOW,tempShell);
				    }
				    // if we have something in command buffer
				    // try to find command help that fits
				    if(usCurrentPosInInputBuffer)
				    {
					    FindCommand(ucCommandBuffer);
				    }
				    else ShowStoppedMsg();
                }
			}
            // normal key while holding down CONTROL
            else if(bControl && !bAlt && !bShift && ucConverted)
            {
                if(ucConverted == 'f')
                    bNotifyToExit = TRUE;
            }
            // normal key while holding down ALT
            else if(!bControl && bAlt && !bShift && ucConverted)
            {
            }
            // normal key while holding down ALT & CONTROL
            else if(bControl && bAlt && !bShift && ucConverted)
            {
            }
			// we didn't get a converted key
			// so this must be a control key
			else
			{
				// RETURN
				if(bNoCtrlKeys() && ucKeyPressedWhileIdle == SCANCODE_ENTER)
				{
                    DPRINT((0,"DebuggerShell(): RETURN\n"));
					ucCommandBuffer[usCurrentPosInInputBuffer]=0;
					if(ucCommandBuffer[0])
					{
                        AddToCommandLineHistory(ucCommandBuffer);
                        ClrLine(wWindow[OUTPUT_WINDOW].y+wWindow[OUTPUT_WINDOW].usCurY);
                        ulLastLineDisplayedOffset = 0;
                        PrintRingBuffer(wWindow[OUTPUT_WINDOW].cy-1);
                        // setup a safe stack for parsing
                        __asm__ __volatile__("\n\t \
                            movl %2,%%eax\n\t \
                            movl %%esp,%%ebx\n\t \
                            mov  %%ebx,%0\n\t \
                            leal _aulNewStack,%%ebx\n\t \
                            addl $0x1FFF0,%%ebx\n\t \
                            movl %%ebx,%%esp\n\t \
                            pushl $0\n\t \
                            pushl %%eax\n\t \
                            call _Parse\n\t \
                            movl %0,%%ebx\n\t \
                            movl %%ebx,%%esp"
                            :"=m" (ulOldStack)
                            :"m" (ulOldStack),"m" (ucCommandBuffer)
                            :"eax","ebx");

                        ShowStoppedMsg();
					}
                    else
                    {
                        if(ulLastLineDisplayedOffset)
                        {
                            ulLastLineDisplayedOffset = 0;
                            PrintRingBuffer(wWindow[OUTPUT_WINDOW].cy-1);
                        }
                    }
					usCurrentPosInInputBuffer=0;
					PICE_memset(&ucCommandBuffer,0,sizeof(ucCommandBuffer));
				}
				// backspace
				else if(bNoCtrlKeys() && ucKeyPressedWhileIdle == SCANCODE_BACKSPACE)
				{
                    DPRINT((0,"DebuggerShell(): BACKSPACE\n"));
					if(usCurrentPosInInputBuffer)
					{
						if(usCurrentPosInInputBuffer)
                            FindCommand(ucCommandBuffer);
						else
                            ShowStoppedMsg();

						usCurrentPosInInputBuffer--;
						ucCommandBuffer[usCurrentPosInInputBuffer]=0;
						Print(OUTPUT_WINDOW,"\b");
					}
				}
				// Tab
				else if(bNoCtrlKeys() && ucKeyPressedWhileIdle==SCANCODE_TAB)
				{
                    DPRINT((0,"DebuggerShell(): TAB\n"));
					if(usCurrentPosInInputBuffer)
					{
						LPSTR pCmd;

						if((pCmd=FindCommand(ucCommandBuffer)) )
						{
							ULONG i;

							// clear the displayed command line
							for(i=0;i<usCurrentPosInInputBuffer;i++)
								Print(OUTPUT_WINDOW,"\b");
							// clear command buffer
							PICE_memset(&ucCommandBuffer,0,sizeof(ucCommandBuffer));
							// copy the found command into command buffer
							PICE_strcpy(ucCommandBuffer,pCmd);
							PICE_strcat(ucCommandBuffer," ");
							usCurrentPosInInputBuffer = PICE_strlen(ucCommandBuffer);
							Print(OUTPUT_WINDOW,ucCommandBuffer);
						}
					}
				}
				else
				{
					// function keys
					if(bNoCtrlKeys() && ucKeyPressedWhileIdle>=59 && ucKeyPressedWhileIdle<69)
					{
                        DPRINT((0,"DebuggerShell(): FUNCTION %u\n",ucKeyPressedWhileIdle-59));
                        PICE_sprintf(tempShell,":");
                        ReplaceRingBufferCurrent(tempShell);
                        PICE_memset(&ucCommandBuffer,0,sizeof(ucCommandBuffer));
            			usCurrentPosInInputBuffer=0;
                        PrintRingBuffer(wWindow[OUTPUT_WINDOW].cy-1);
						PICE_strcpy(ucCommandBuffer,szFunctionKeys[ucKeyPressedWhileIdle-59]);
						usCurrentPosInInputBuffer=PICE_strlen(ucCommandBuffer);
						if(ucCommandBuffer[0])
						{
                            ulLastLineDisplayedOffset = 0;
                            PrintRingBuffer(wWindow[OUTPUT_WINDOW].cy-1);

                            // setup a safe stack for parsing
                            __asm__ __volatile__("\n\t \
                                movl %2,%%eax\n\t \
                                movl %%esp,%%ebx\n\t \
                                mov  %%ebx,%0\n\t \
                                leal _aulNewStack,%%ebx\n\t \
                                addl $0x1FFF0,%%ebx\n\t \
                                movl %%ebx,%%esp\n\t \
                                pushl $1\n\t \
                                pushl %%eax\n\t \
                                call _Parse\n\t \
                                movl %0,%%ebx\n\t \
                                movl %%ebx,%%esp"
                                :"=m" (ulOldStack)
                                :"m" (ulOldStack),"m" (ucCommandBuffer)
                                :"eax","ebx");
							PICE_memset(&ucCommandBuffer,0,sizeof(ucCommandBuffer));
							usCurrentPosInInputBuffer=0;
						}
					}
                    else
                    {
                        switch(ucKeyPressedWhileIdle)
                        {
                            case SCANCODE_ESC:
                                if(usCurrentPosInInputBuffer)
                                {
                                    PICE_sprintf(tempShell,":");
                                    ReplaceRingBufferCurrent(tempShell);
                        		    PICE_memset(&ucCommandBuffer,0,sizeof(ucCommandBuffer));
            					    usCurrentPosInInputBuffer=0;
                                    Print(OUTPUT_WINDOW,"");
                                    ShowStoppedMsg();
                                }
                                break;
                            case SCANCODE_HOME: // home
                                DPRINT((0,"DebuggerShell(): HOME\n"));
                                // memory window
                                if(bAlt)
                                {
                                    DPRINT((0,"DebuggerShell(): data window home\n"));
                                    OldOffset=0x0;
	                                // display data window
	                                Args.Value[0]=OldSelector;
	                                Args.Value[1]=OldOffset;
	                                Args.Count=2;
	                                DisplayMemory(&Args);
                                }
                                // output window
                                else if(bShift)
                                {
                                    DPRINT((0,"DebuggerShell(): output window home\n"));
                                    if(ulLastLineDisplayedOffset != LinesInRingBuffer()-wWindow[OUTPUT_WINDOW].cy)
                                    {
                                        ulLastLineDisplayedOffset = LinesInRingBuffer()-wWindow[OUTPUT_WINDOW].cy+1;
                                        PrintRingBufferHome(wWindow[OUTPUT_WINDOW].cy-1);
                                    }
                                }
                                // source window home
                                else if(bControl)
                                {
                                    if(ulCurrentlyDisplayedLineNumber>0)
                                    {
                                        PICE_SYMBOLFILE_SOURCE* pSrc;

                                        if(ConvertTokenToSrcFile(szCurrentFile,(PULONG)&pSrc) )
                                        {
                                            ulCurrentlyDisplayedLineNumber = 1;

                                            DisplaySourceFile((LPSTR)pSrc+sizeof(PICE_SYMBOLFILE_SOURCE),
                                                              (LPSTR)pSrc+pSrc->ulOffsetToNext,
                                                              1,-1);
                                        }
                                    }
                                }
                                else if(!bShift && !bControl && !bAlt)
                                {
                                }
                                break;
                            case SCANCODE_END: // end
                                DPRINT((0,"DebuggerShell(): END\n"));
                                // memory window
                                if(bAlt)
                                {
                                    DPRINT((0,"DebuggerShell(): data window end\n"));
                                    OldOffset=0xFFFFFFFF-0x10*4;
	                                // display data window
	                                Args.Value[0]=OldSelector;
	                                Args.Value[1]=OldOffset;
	                                Args.Count=2;
	                                DisplayMemory(&Args);
                                }
                                // output window
                                else if(bShift)
                                {
                                    DPRINT((0,"DebuggerShell(): output window end\n"));
                                    if(ulLastLineDisplayedOffset)
                                    {
                                        ulLastLineDisplayedOffset = 0;

                                        PrintRingBuffer(wWindow[OUTPUT_WINDOW].cy-1);
                                    }
                                }
                                else if(!bShift && !bControl && !bAlt)
                                {
                                }
                                break;
                            case SCANCODE_UP: // up
                                DPRINT((0,"DebuggerShell(): UP\n"));
                                // memory window
                                if(bAlt)
                                {
                                    DPRINT((0,"DebuggerShell(): data window up\n"));
                                    OldOffset-=0x10;
	                                // display data window
	                                Args.Value[0]=OldSelector;
	                                Args.Value[1]=OldOffset;
	                                Args.Count=2;
	                                DisplayMemory(&Args);
                                }
                                // output window
                                else if(bShift)
                                {
                                    DPRINT((0,"DebuggerShell(): output window up ulLastLineDisplayedOffset = %u\n",ulLastLineDisplayedOffset));

                                    if(ulLastLineDisplayedOffset+wWindow[OUTPUT_WINDOW].cy < LinesInRingBuffer())
                                    {
                                        ulLastLineDisplayedOffset += 1;

                                        PrintRingBufferOffset(wWindow[OUTPUT_WINDOW].cy-1,ulLastLineDisplayedOffset);
                                    }
                                }
                                // source window up
                                else if(bControl)
                                {
                                    if((ulCurrentlyDisplayedLineNumber-1)>0 && PICE_strlen(szCurrentFile) )
                                    {
                                        PICE_SYMBOLFILE_SOURCE* pSrc;

                                        if(ConvertTokenToSrcFile(szCurrentFile,(PULONG)&pSrc) )
                                        {
                                            ulCurrentlyDisplayedLineNumber--;
                                            DisplaySourceFile((LPSTR)pSrc+sizeof(PICE_SYMBOLFILE_SOURCE),
                                                              (LPSTR)pSrc+pSrc->ulOffsetToNext,
                                                              ulCurrentlyDisplayedLineNumber,-1);
                                        }
                                    }
                                    else
                                    {

⌨️ 快捷键说明

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