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

📄 main.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 3 页
字号:
            {
                printf("LOADER: Error on loading debugger! (exitstatus = %u)\n",WEXITSTATUS(status));
                err = WEXITSTATUS(status);
            }
            break;
    }

    return err;
}

///////////////////////////////////////////////////////////////////////////////////
// tryuninstall()
//
///////////////////////////////////////////////////////////////////////////////////
int tryuninstall(void)
{
    char *argv[]={"/sbin/rmmod","pice",NULL};
    int err = 0;
    int pid,status;

    banner();
    printf("LOADER: trying to remove debugger...\n");

    // check for loaded debugger
    if(open_debugger() == INVALID_HANDLE_VALUE)
    {
        return -1;
    }
    // don't to close, else we'll have a reference count != 0
    close_debugger();

    // create a separate thread
    pid = fork();
    switch(pid)
    {
        case -1:
            // error when forking, i.e. out E_NOMEM
            err = errno;
            printf("LOADER: fork failed for execution of '%s' (errno=%u).\n",argv[0],err);
            break;
        case 0:
            // child process handler
            execve(argv[0],argv,NULL);
            // returns only on error, with return value -1, errno is set
            printf("LOADER: couldn't execute '%s' (errno = %u)\n",argv[0],errno);
            exit(255);
            break;
        default:
            // parent process handler
            printf("LOADER: waiting for debugger to unload...\n");
            pid = waitpid(pid, &status, 0); // suspend until child is done

            if( (pid>0) && WIFEXITED(status) && (WEXITSTATUS(status) == 0) )
                printf("LOADER: debugger removed!\n");
            else if( pid<=0 )
            {
                printf("LOADER: Error on removing debugger! (waitpid() = %i)\n",pid);
                err = -1;
            }
            else if( !WIFEXITED(status) )
            {
                printf("LOADER: Error on removing debugger! (ifexited = %i)\n",WIFEXITED(status));
                err = -1;
            }
            else
            {
                printf("LOADER: Error on removing debugger! (exitstatus = %u)\n",WEXITSTATUS(status));
                err = WEXITSTATUS(status);
            }
            break;
    }
    return err;
}
#endif

///////////////////////////////////////////////////////////////////////////////////
// showstatus()
//
///////////////////////////////////////////////////////////////////////////////////
void showstatus(void)
{
    DEBUGGER_STATUS_BLOCK sb;
    int iRetVal;

	if(open_debugger() != INVALID_HANDLE_VALUE)
	{
		iRetVal = ioctl(debugger_file,PICE_IOCTL_STATUS,&sb);

        //printf("LOADER: Test = %X\n",sb.Test);
		close_debugger();
	}
}

///////////////////////////////////////////////////////////////////////////////////
// dobreak()
//
///////////////////////////////////////////////////////////////////////////////////
void dobreak(void)
{
    int iRetVal;

	if(open_debugger() != INVALID_HANDLE_VALUE)
	{
		iRetVal = ioctl(debugger_file,PICE_IOCTL_BREAK,NULL);
		close_debugger();
	}
}

///////////////////////////////////////////////////////////////////////////////////
// doterminal()
//
///////////////////////////////////////////////////////////////////////////////////
#if 0
void doterminal(void)
{
    if(SetupSerial(2,B115200))
    {
        DebuggerShell();
        CloseSerial();
    }
}
#endif

///////////////////////////////////////////////////////////////////////////////////
// process_switches()
//
// returns !=0 in case of a commandline error
//
///////////////////////////////////////////////////////////////////////////////////
int process_switches(int argc,char* argv[])
{
	int i;
	char* parg,*pfilename = NULL;
	int action = ACTION_NONE;
	int error = 0;

    // parse commandline arguments
	for(i=1;i<argc;i++)
	{
		parg = argv[i];
		if(*parg == '-')
		{
		    int new_action=ACTION_NONE;

			parg++;
			if(strcmp(parg,"load")==0 || strcmp(parg,"l")==0)
			{
				new_action = ACTION_LOAD;
			}
			else if(strcmp(parg,"unload")==0 || strcmp(parg,"u")==0)
			{
				new_action = ACTION_UNLOAD;
			}
			else if(strcmp(parg,"trans")==0 || strcmp(parg,"t")==0)
            {
                new_action = ACTION_TRANS;
            }
			else if(strcmp(parg,"reload")==0 || strcmp(parg,"r")==0)
            {
                new_action = ACTION_RELOAD;
            }
			else if(strcmp(parg,"verbose")==0 || strcmp(parg,"v")==0)
            {
			    if( ulGlobalVerbose+1 > ulGlobalVerbose )
				    ulGlobalVerbose++;
            }
			else if(strcmp(parg,"install")==0 || strcmp(parg,"i")==0)
            {
                new_action = ACTION_INSTALL;
            }
			else if(strcmp(parg,"uninstall")==0 || strcmp(parg,"x")==0)
            {
                new_action = ACTION_UNINSTALL;
            }
			else if(strcmp(parg,"status")==0 || strcmp(parg,"s")==0)
            {
                new_action = ACTION_STATUS;
            }
			else if(strcmp(parg,"break")==0 || strcmp(parg,"b")==0)
            {
                new_action = ACTION_BREAK;
            }
			else if(strcmp(parg,"serial")==0 || strcmp(parg,"ser")==0)
            {
                new_action = ACTION_TERMINAL;
            }
			else
			{
				printf("LOADER: error: unknown switch %s", argv[i]);
				error = 1;
			}

            if( new_action != ACTION_NONE )
            {
                if( action == ACTION_NONE )
                    action = new_action;
                else
                if( action == new_action )
                {
                    // identical, just ignore
                }
                else
                {
                    printf("LOADER: error: conflicting switch %s", argv[i]);
                    error = 1;
                }
            }
		}
		else
		{
            if( pfilename )
            {
                printf("LOADER: error: additional filename %s", parg);
                error = 1;
            }
			pfilename = parg;
		}
	}

    // check number of required parameters
    switch( action )
    {
        case ACTION_TRANS :
        case ACTION_LOAD :
        case ACTION_UNLOAD :
            if( !pfilename )
            {
                printf("LOADER: error: missing filename\n");
                error = 1;
            }
            break;
        case ACTION_RELOAD :
            /* filename parameter is optional */
            break;
#if 0
        case ACTION_UNINSTALL:
            close_debugger();
            tryuninstall();
            break;
        case ACTION_INSTALL:
            tryinstall();
            break;
#endif
        case ACTION_STATUS:
            showstatus();
            break;
        case ACTION_BREAK:
            dobreak();
            break;
#if 0
        case ACTION_TERMINAL:
            doterminal();
            break;
#endif
        case ACTION_NONE :
            printf("LOADER: no action specified specifed on commandline\n");
            error = 1;

            break;
        default :
            printf("LOADER: an internal error has occurred at commandline parsing\n");
            error = 1;
    }

    if( !error )    // commandline was fine, now start processing
    {
        switch( action )
        {
            case ACTION_TRANS :
                printf("LOADER: trying to translate file %s...\n",pfilename);
                if( process_file(pfilename)==0 )
                    printf("LOADER: file %s has been translated\n",pfilename);
                else
                    printf("LOADER: error while translating file %s\n",pfilename);
                break;
            case ACTION_LOAD :
            case ACTION_UNLOAD :
            case ACTION_RELOAD :
                change_symbols(action,pfilename);
                break;
        }
    }

    return error;
}


///////////////////////////////////////////////////////////////////////////////////
// showhelp()
//
///////////////////////////////////////////////////////////////////////////////////
void showhelp(void)
{
    banner();
    printf("LOADER: Syntax:\n");
    printf("LOADER:         loader [switches] [executable/object file path]\n");
    printf("LOADER: Switches:\n");
    printf("LOADER:         -trans      (-t):   translate from exe to sym\n");
    printf("LOADER:         -load       (-l):   load symbols\n");
    printf("LOADER:         -unload     (-u):   unload symbols\n");
    printf("LOADER:         -reload     (-r):   reload some/all symbols\n");
    printf("LOADER:         -verbose    (-v):   be a bit more verbose\n");
    printf("LOADER:         -install    (-i):   install pICE debugger\n");
    printf("LOADER:         -uninstall  (-x):   uninstall pICE debugger\n");
    printf("LOADER:         -break      (-b):   break into debugger\n");
    printf("LOADER:         -serial     (-ser): start serial line terminal\n");
}

///////////////////////////////////////////////////////////////////////////////////
// showpermission()
//
///////////////////////////////////////////////////////////////////////////////////
void showpermission(void)
{
    banner();
    printf("LOADER: You must be superuser!\n");
}

///////////////////////////////////////////////////////////////////////////////////
// main()
//
///////////////////////////////////////////////////////////////////////////////////
int main(int argc,char* argv[])
{
    if(argc==1 || argc>3)
    {
		showhelp();

		return 1;
    }

	return process_switches(argc,argv);
}

⌨️ 快捷键说明

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