Пример #1
0
/*
=================
idSessionLocal::HandleMsgCommands
=================
*/
void idSessionLocal::HandleMsgCommands( const char *menuCommand ) {
	assert( guiActive == guiMsg );
	// "stop" works even on first frame
	if ( idStr::Icmp( menuCommand, "stop" ) == 0 ) {
		// force hiding the current dialog
		guiActive = guiMsgRestore;
		guiMsgRestore = NULL;
		msgRunning = false;
		msgRetIndex = -1;
	}
	if ( msgIgnoreButtons ) {
		common->DPrintf( "MessageBox HandleMsgCommands 1st frame ignore\n" );
		return;
	}
	if ( idStr::Icmp( menuCommand, "mid" ) == 0 || idStr::Icmp( menuCommand, "left" ) == 0 ) {
		guiActive = guiMsgRestore;
		guiMsgRestore = NULL;
		msgRunning = false;
		msgRetIndex = 0;
		DispatchCommand( guiActive, msgFireBack[ 0 ].c_str() );
	} else if ( idStr::Icmp( menuCommand, "right" ) == 0 ) {
		guiActive = guiMsgRestore;
		guiMsgRestore = NULL;
		msgRunning = false;
		msgRetIndex = 1;
		DispatchCommand( guiActive, msgFireBack[ 1 ].c_str() );
	}
}
Пример #2
0
/*
** Answer whether a breakpoint is actually set at the given address.
*/
int isValidBreakpoint(ULONG addr)
{
Breakpoint *bp;
Breakpoint *tmp;
int	    isValid = 0;
int	    firstDead = 1;

    /*
    ** First, see if this is an expected breakpoint.
    */
    for(bp=Breakpoints; bp; bp=bp->next) {
        if(bp->addr == addr) {
	    isValid = 1;
            debugBuffer.Addr  = addr;
            debugBuffer.Len   = 1;
            debugBuffer.Index = 0;
            debugBuffer.Value = DBG_W_Local | DBG_W_Execute;
	    DispatchCommand(DBG_C_SetWatch);
	    break;
        }
    }

    /*
    ** Now, remove all breakpoints.
    */
    for(bp=Breakpoints; bp;bp=bp->next) {
        debugBuffer.Index = bp->id;
	DispatchCommand(DBG_C_ClearWatch);
    }

    /*
    ** Now, go through the list again, setting only the 'permanent' breakpoints.
    */
    tmp = NULL;
    for(bp=Breakpoints; bp;) {
        if(!bp->oneTimeFlag) {
            debugBuffer.Addr  = bp->addr;
            debugBuffer.Len   = 1;
            debugBuffer.Index = 0;
            debugBuffer.Value = DBG_W_Local | DBG_W_Execute;
	    DispatchCommand(DBG_C_SetWatch);
            if(tmp)
                tmp->next = bp;
            else
                tmp = bp;
            bp = bp->next;
        } else {
            Breakpoint *tmp2;

            tmp2 = bp;
	    bp = bp->next;
	    if(tmp2->desc)
		free(tmp2->desc);
            free(tmp2);
        }
    }
    Breakpoints = tmp;
    return isValid;
}
Пример #3
0
void *newconnection(void *arg)
{
  int sockethandle=(uintptr_t)arg;
  unsigned char command;
  int r;
  //printf("Hello!\n");

  //wait for a command and dispatch it

  r=1;
  while (r>=0)
  {
    r=recvall(sockethandle, &command, 1, MSG_WAITALL);
    if (r==1)
      DispatchCommand(sockethandle, command);
    else
    {
      //printf("Peer has disconnected");
      //if (r==-1)
      //  printf(" due to an error");

      //printf("\n");

      //fflush(stdout);
      close(sockethandle);
    }
  }

  printf("Bye\n");
  return NULL;
}
Пример #4
0
//---------------------------------------------------------------------------
DWORD  WINAPI ProcessDataThread::WorkerThread(LPVOID lParam)
{
    PDATA_BLOCK dataBlock = NULL;
	
    do
    {
        WaitForSingleObject(FrmMain->hEventForPlgData, INFINITE);

        // 不管怎么说,先得将数据处理完毕
        //
        while(true)
        {
            dataBlock = FrmMain->PopPlgDataBlock();
            if (dataBlock)
            {
                DispatchCommand(dataBlock);
                delete dataBlock;
            }
            else
            {
                break;
            }
        }

        if (FrmMain->bClosing)
        {
            break;
        }

    } while(TRUE);
    
    return 0;
}
Пример #5
0
/*
=================
idSessionLocal::GuiFrameEvents
=================
*/
void idSessionLocal::GuiFrameEvents() {
	const char	*cmd;
	sysEvent_t  ev;
	idUserInterface	*gui;

	// stop generating move and button commands when a local console or menu is active
	// running here so SP, async networking and no game all go through it
	if ( console->Active() || guiActive ) {
		usercmdGen->InhibitUsercmd( INHIBIT_SESSION, true );
	} else {
		usercmdGen->InhibitUsercmd( INHIBIT_SESSION, false );
	}

	if ( guiTest ) {
		gui = guiTest;
	} else if ( guiActive ) {
		gui = guiActive;
	} else {
		return;
	}

	memset( &ev, 0, sizeof( ev ) );

	ev.evType = SE_NONE;
	cmd = gui->HandleEvent( &ev, com_frameTime );
	if ( cmd && cmd[0] ) {
		DispatchCommand( guiActive, cmd );
	}
}
Пример #6
0
LRESULT CWidgetButton::OnButtonClick(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
TRY_CATCH

	DispatchCommand(cmd_ButtonClick);
	return TRUE;

CATCH_THROW()
}
Пример #7
0
/*
** Linearize an offset/segment.  This linearization will
** check whether the segment is 16/32 bit.  If 32 bit,
** just return offset.	If 16 bit, convert to linear.
*/
ULONG Linearize(ULONG offset, USHORT segment)
{
    if((offset & 0xffff0000) != 0)
	return offset;

    debugBuffer.Value = segment;
    debugBuffer.Index = offset;
    DispatchCommand(DBG_C_SelToLin);
    return debugBuffer.Addr;
}
int ti1610_ioctl_priv_proc_tl(tiwlan_req_t *req_data)
{
    struct net_device *dev = req_data->drv->netdev;
    tiioctl_req_t *req = (tiioctl_req_t *) req_data->u.req.p1;
    static unsigned int drv_started = 0;
	static UINT8 IoCompleteFlag ;

    ULONG *data = (ULONG *) req_data->u.req.p2;

    int res = -EINVAL;

    print_deb("priv_ioctl_proc(): cmd=%ld, data=%p (user_data=%lx), lenght=%ld\n",
                req->cmd, data, req->user_data_pointer, req->length);
    if( !drv_started && (req->cmd != TIWLN_DRIVER_STATUS_SET)) { /* Dm: Fix */
            return res;
    }
					
    switch( req->cmd ) {
        case TIWLN_DRIVER_STATUS_SET:
            if(*data)
                res = tiwlan_start_drv( (tiwlan_net_dev_t *)dev->priv );
            else
                res = tiwlan_stop_drv( (tiwlan_net_dev_t *)dev->priv );

            if( res == OK )
                    drv_started = !drv_started;
            break;

        case TIWLN_SEND_EAPOL_PACKET:
            res = os_sendPacket(dev, data, req->length);
            break;
#ifdef TI_DBG
        case TIWLN_DRIVER_DEBUG_PRINT:
                res = util_hal_debug_print(dev, data);
                break;
#endif /* TI_DBG */
        default:
		{
            res = DispatchCommand(&req_data->drv->adapter, req->cmd, &req->length, req->length, data,&IoCompleteFlag );
			/* If we do not have to send complete to user back then set the Falg to FALSE 
			The Complete will be sent from another contect of command completion from FW */
			if(IoCompleteFlag == FALSE)
			{
			   req_data->u.req.reply_expected = FALSE;
			   /****** TO DO - This solution will have a problem in case of two async ioctrls (in case of two utility adapters). ******/
			   /* Store the semaphore for later competion */
			   (req_data->drv->adapter).IoctlComp = &(req_data->u.req.comp);
			   /* Store the pointer of the result status for later competion */
			   (req_data->drv->adapter).pCompleteReply = &(req_data->u.reply);
			}

		}
    }
    return res;
}
Пример #9
0
static bool ProcessNextCommand()
{
	cmdtype_t cmdtype;

	if (readaddr >= endaddr)
		return false;

	cmdtype = ReadCommand();

	DispatchCommand(cmdtype);

	return (cmdtype == CMD_END);
}
Пример #10
0
/*
** Take the command pointers and set up the commands.
*/
int CommandGo(char **ptrs)
{
int	i;
ULONG	addr;
char   *desc;
Breakpoint *bp;

    /*
    ** If no parameter, then just go.
    */
    if(ptrs[2] == NULL)
	return DBG_C_Go;

    /*
    ** Find the address of the breakpoint.
    */
    addr = FindExecAddr(ptrs[2], &desc);
    if(addr == 0) {
	fprintf(logFile, "FUNCTION NOT FOUND!\n");
	return -1;
    }

    /*
    ** Set the breakpoint to the address specified.
    */
    debugBuffer.Addr  = addr;
    debugBuffer.Len   = 1;
    debugBuffer.Index = 0;
    debugBuffer.Value = DBG_W_Local | DBG_W_Execute;
    DispatchCommand(DBG_C_SetWatch);

    /*
    ** Add the breakpoint to the list, and tag it as a 'go'
    ** breakpoint which will unconditionally be cleared the
    ** next time we get back from the debuggee.
    */
    if(Breakpoints) {
	for(i=0, bp=Breakpoints; bp->next; i++, bp=bp->next) ;
	bp->next = malloc(sizeof(Breakpoint));
	bp = bp->next;
    } else {
	i = 0;
	Breakpoints = bp = malloc(sizeof(Breakpoint));
    }
    bp->id = debugBuffer.Index;
    bp->addr = addr;
    bp->next = NULL;
    bp->desc = desc;
    bp->oneTimeFlag = 1;
    return DBG_C_Go;
}
Пример #11
0
LRESULT CWidgetTimerLabel::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY_CATCH

	SetText(m_defaultText);

	KillTimer(1);
	
	DispatchCommand(cmd_DefaultTextAppeared);
	
	return 0;

CATCH_THROW()
}
Пример #12
0
int CheckForAndDispatchCommand(int currentsocket)
{
  int r;
  unsigned char command;

  r=recv(currentsocket, &command, 1, MSG_DONTWAIT);
  if (r==1)
  {
    DispatchCommand(currentsocket, command);
    return 1;
  }

  return 0;
}
Пример #13
0
/*
** Free all breakpoints.
*/
void FreeAllBreakpoints()
{
Breakpoint *bp, *next;

    for(bp=Breakpoints; bp; ) {
        debugBuffer.Index = bp->id;
	DispatchCommand(DBG_C_ClearWatch);
	next = bp->next;
	if(bp->desc)
	    free(bp->desc);
        free(bp);
        bp = next;
    }
    Breakpoints = NULL;
}
Пример #14
0
/*
** Convert a string to an address.  Do any necessary linearization.
*/
ULONG StrToAddr(char *str, int type)
{
ULONG val;
char *end;

    val = strtoul(str, &end, 16);
    if((val & 0xffff0000) != 0)
	return val;
    DispatchCommand(DBG_C_ReadReg);
    switch(type) {
	case TOADDR_CODE:   return Linearize(val, debugBuffer.CS);
	case TOADDR_DATA:   return Linearize(val, debugBuffer.DS);
	case TOADDR_STACK:  return Linearize(val, debugBuffer.SS);
    }
    return 0;
}
Пример #15
0
void SystemWrapper::ExecuteString(char *commands)
{
	if (!commands || !commands[0])
		return;

	int size = 0;
	char singleCmd[256] = "";
	bool quotes = false;
	char *p = singleCmd;
	char *c = commands;

	COM_RemoveEvilChars(c);
	while (true)
	{
		*p = *c;

		if (++size >= sizeof(singleCmd))
		{
			DPrintf("WARNING! System::ExecuteString: Command token too long.\n");
			break;
		}

		if (*c == '"')
			quotes = !quotes;

		if ((*c != ';' || quotes) && *c)
		{
			++p;
		}
		else
		{
			*p = '\0';

			char *cmd = singleCmd;
			while (*cmd == ' ') { cmd++; }

			DispatchCommand(cmd);
			p = singleCmd;
			size = 0;
		}

		if (!*c++)
			break;
	}
}
Пример #16
0
void MainObject::ParseCommand(int ch)
{
  char buf[256];
  int c;
  RipcdConnection *conn=ripcd_conns[ch];

  while((c=conn->socket->readBlock(buf,256))>0) {
    buf[c]=0;
    for(int i=0;i<c;i++) {
      if(buf[i]==' ') {
	if(conn->argnum<RD_RML_MAX_ARGS) {
	  conn->args[conn->argnum][conn->argptr]=0;
	  conn->argnum++;
	  conn->argptr=0;
	}
	else {
	  LogLine(RDConfig::LogWarning,QString().
		  sprintf("*** ParseCommand1: argument list truncated.  LocalBuffer: %s ***",buf));
	}
      }
      if(buf[i]=='!') {
	conn->args[conn->argnum++][conn->argptr]=0;
	DispatchCommand(ch);
	conn->argnum=0;
	conn->argptr=0;
	if(conn->socket==NULL) {
	  return;
	}
      }
      if((isgraph(buf[i]))&&(buf[i]!='!')) {
	if(conn->argptr<RIPCD_MAX_LENGTH) {
	  conn->args[conn->argnum][conn->argptr]=buf[i];
	  conn->argptr++;
	}
	else {
	  if(debug) {
	    LogLine(RDConfig::LogWarning,QString().
		    sprintf("*** ParseCommand2: argument list truncated.  LocalBuffer: %s ***",buf));
	  }
	}
      }
    }
  }
}
Пример #17
0
/*
==============
idSessionLocal::MenuEvent

Executes any commands returned by the gui
==============
*/
void idSessionLocal::MenuEvent( const sysEvent_t *event ) {
	const char	*menuCommand;

	if ( guiActive == NULL ) {
		return;
	}

	menuCommand = guiActive->HandleEvent( event, com_frameTime );

	if ( !menuCommand || !menuCommand[0] ) {
		// If the menu didn't handle the event, and it's a key down event for an F key, run the bind
		if ( event->evType == SE_KEY && event->evValue2 == 1 && event->evValue >= K_F1 && event->evValue <= K_F12 ) {
			idKeyInput::ExecKeyBinding( event->evValue );
		}
		return;
	}

	DispatchCommand( guiActive, menuCommand );
}
Пример #18
0
void MainObject::ParseCommand(int ch)
{
  char buf[256];
  int c;

  while((c=socket[ch]->readBlock(buf,256))>0) {
    buf[c]=0;
    for(int i=0;i<c;i++) {
      if(buf[i]==' ') {
	if(argnum[ch]<RD_RML_MAX_ARGS) {
	  args[ch][argnum[ch]][argptr[ch]]=0;
	  argnum[ch]++;
	  argptr[ch]=0;
	}
	else {
	  LogLine(RDConfig::LogWarning,QString().
		  sprintf("*** ParseCommand1: argument list truncated.  LocalBuffer: %s ***",buf));
	}
      }
      if(buf[i]=='!') {
	args[ch][argnum[ch]++][argptr[ch]]=0;
	DispatchCommand(ch);
	argnum[ch]=0;
	argptr[ch]=0;
	if(socket[ch]==NULL) {
	  return;
	}
      }
      if((isgraph(buf[i]))&&(buf[i]!='!')) {
	if(argptr[ch]<RIPCD_MAX_LENGTH) {
	  args[ch][argnum[ch]][argptr[ch]]=buf[i];
	  argptr[ch]++;
	}
	else {
	  if(debug) {
	    LogLine(RDConfig::LogWarning,QString().
		    sprintf("*** ParseCommand2: argument list truncated.  LocalBuffer: %s ***",buf));
	  }
	}
      }
    }
  }
}
Пример #19
0
/*
** Assuming the address is a pointer to a pointer, return the value
** at the pointer.
*/
int HLLGetRegisterValue(DebugModule *module, State *state)
{
HLLTypeData *hllType = state->typeData;

    module;
    if(hllType->registerNum != -1) {
	if(DispatchCommand(DBG_C_ReadReg))
	    return INTERNAL_ERROR;
	switch(hllType->registerNum) {
	    case 0x10: state->value.val.lVal = debugBuffer->EAX; return SUCCESS;
	    case 0x11: state->value.val.lVal = debugBuffer->ECX; return SUCCESS;
	    case 0x12: state->value.val.lVal = debugBuffer->EDX; return SUCCESS;
	    case 0x13: state->value.val.lVal = debugBuffer->EBX; return SUCCESS;
	    case 0x14: state->value.val.lVal = debugBuffer->ESP; return SUCCESS;
	    case 0x15: state->value.val.lVal = debugBuffer->EBP; return SUCCESS;
	    case 0x16: state->value.val.lVal = debugBuffer->ESI; return SUCCESS;
	    case 0x17: state->value.val.lVal = debugBuffer->EDI; return SUCCESS;
	    default: state->value.typeValue = UNKNOWN; return INVALID_NAME;
	}
    }
    return INVALID_NAME;
}
Пример #20
0
/*
** Assuming the address is a pointer to a pointer, return the value
** at the pointer.
*/
int CVGetRegisterValue(DebugModule *module, State *state)
{
CVTypeData *cvType = state->typeData;

    module;
    if(cvType->registerNum != -1) {
	if(DispatchCommand(DBG_C_ReadReg))
	    return INTERNAL_ERROR;
	switch(cvType->registerNum) {
	    case 16: state->value.val.lVal = debugBuffer->EAX; return SUCCESS;
	    case 17: state->value.val.lVal = debugBuffer->ECX; return SUCCESS;
	    case 18: state->value.val.lVal = debugBuffer->EDX; return SUCCESS;
	    case 19: state->value.val.lVal = debugBuffer->EBX; return SUCCESS;
	    case 20: state->value.val.lVal = debugBuffer->ESP; return SUCCESS;
	    case 21: state->value.val.lVal = debugBuffer->EBP; return SUCCESS;
	    case 22: state->value.val.lVal = debugBuffer->ESI; return SUCCESS;
	    case 23: state->value.val.lVal = debugBuffer->EDI; return SUCCESS;
	    default: state->value.typeValue = UNKNOWN_VAL; return INVALID_NAME;
	}
    }
    return INVALID_NAME;
}
Пример #21
0
bool CPoll::ProcessParamsFromBuilder(CTDVString & sRedirectURL)
{
	// Get command
	CTDVString sCmd = "";
	m_InputContext.GetParamString("cmd",sCmd);

	// Dispatch it
	if(!DispatchCommand(sCmd))
	{
		TDVASSERT(false, "CPoll::ProcessParamsFromBuilder() DispatchCommand failed");

		// Add error xml
		CTDVString sXML;
		sXML << "<" << GetRootElement() << "></" << GetRootElement() << ">";
		
		if(!CreateFromXMLText(sXML, 0, true))
		{
			TDVASSERT(false, "CPoll::ProcessParamsFromBuilder() CreateFromXMLText failed");
			return false;
		}

		if(!AddErrorElement(GetRootElement(), ERRORCODE_UNSPECIFIED, "CPoll::ProcessParamsFromBuilder() DispatchCommand failed"))
		{
			TDVASSERT(false, "CPoll::ProcessParamsFromBuilder() AddErrorElement failed");
			return false;
		}

		// Set redirect url
		sRedirectURL = m_sRedirectURL;

		return false;
	}

    // Set redirect url
	sRedirectURL = m_sRedirectURL;

	return true;
}
Пример #22
0
void SoftwareAuthority::readyReadData()
{
  char buffer[256];
  unsigned n;

  while((n=swa_socket->readBlock(buffer,255))>0) {
    buffer[n]=0;
    ///    printf("RECV: %s\n",buffer);
    for(unsigned i=0;i<n;i++) {
      if(buffer[i]==10) {  // End of line
	swa_buffer[--swa_ptr]=0;
	DispatchCommand();
	swa_ptr=0;
      }
      else {
	if(swa_ptr==SWAUTHORITY_MAX_LENGTH) {  // Buffer overflow
	  swa_ptr=0;
	}
	swa_buffer[swa_ptr++]=buffer[i];
      }
    }
  }
}
Пример #23
0
//----------------------------------------------------------------------------
//
void TelnetTCPClient::SocketReadyRead()
{
    //Keep adding to the command buffer
    QByteArray Data = Socket->readAll();
    CommandBuffer.append(Data);

    //Check to see if the CommandBuffer has a command
    if( ! CommandBuffer.endsWith('\n') )
    {
        return;
    }

    //Process the command

    if(!isAuthenticated)
    {
        //Authenticate the client
        if ( Authenticate(CommandBuffer) )
        {
            SendResponse(QString("success to login.") + strCR);
            SendResponse(strShell);
        }
        else
        {
            SendResponse("failed to login. enter password:");
        }

        CommandBuffer.clear();
        return;
    }

    DispatchCommand( CommandBuffer );
    CommandBuffer.clear();

    SendResponse( strShell );
}
Пример #24
0
void RDCae::readyData(int *stream,int *handle,QString name)
{
  char buf[256];
  int c;
  RDCmdCache cmd;

  if(stream==NULL) {
    for(unsigned i=0;i<delayed_cmds.size();i++) {
      DispatchCommand(&delayed_cmds[i]);
    }
    delayed_cmds.clear();
  }

  while((c=cae_socket->readBlock(buf,256))>0) {
    buf[c]=0;
    for(int i=0;i<c;i++) {
      if(buf[i]==' ') {
	if(argnum<CAE_MAX_ARGS) {
	  args[argnum][argptr]=0;
	  argnum++;
	  argptr=0;
	}
	else {
	  if(debug) {
	    printf("Argument list truncated!\n");
	  }
	}
      }
      if(buf[i]=='!') {
	args[argnum++][argptr]=0;
	if(stream==NULL) {
	  cmd.load(args,argnum,argptr);
	  /*
	  // ************************************
	  printf("DISPATCHING: ");
	  for(int z=0;z<cmd.argNum();z++) {
	    printf(" %s",cmd.arg(z));
	  }
	  printf("\n");
	  // ************************************
	  */
	  DispatchCommand(&cmd);
	}
	else {
	  if(!strcmp(args[0],"LP")) {
	    if(QString(args[2])==name) {
	      sscanf(args[3],"%d",stream);
	      sscanf(args[4],"%d",handle);
	    }
	  }
	  else {
	    cmd.load(args,argnum,argptr);
	    delayed_cmds.push_back(cmd);
	  }
	}
	argnum=0;
	argptr=0;
	if(cae_socket==NULL) {
	  return;
	}
      }
      if((isgraph(buf[i]))&&(buf[i]!='!')) {
	if(argptr<CAE_MAX_LENGTH) {
	  args[argnum][argptr]=buf[i];
	  argptr++;
	}
	else {
	  if(debug) {
	    printf("WARNING: argument truncated!\n");
	  }
	}
      }
    }
  }
}
Пример #25
0
/*
** Take the command pointers and set up the commands.
*/
int CommandBreakpoint(char **ptrs)
{
int	i;
ULONG	addr;
char   *dummy;
char   *desc;
Breakpoint *bp;

    /*
    ** Something to do with breakpoints.  Find out what and do it.
    */
    switch(tolower(ptrs[1][1])) {
	/*
	** Set a breakpoint.
	*/
	case 'p': {
	    int err;

	    /*
	    ** Get the address of the breakpoint.
	    */
	    addr = FindExecAddr(ptrs[2], &desc);
	    if(addr == 0) {
		fprintf(logFile, "FUNCTION NOT FOUND!\n");
		free(desc);
		return -1;
	    }

	    /*
	    ** Set the breakpoint
	    */
	    debugBuffer.Addr  = addr;
	    debugBuffer.Len   = 1;
	    debugBuffer.Index = 0;
	    debugBuffer.Value = DBG_W_Local | DBG_W_Execute;
	    err = DispatchCommand(DBG_C_SetWatch);
	    if(debugBuffer.Cmd != DBG_N_Success) {
		fprintf(logFile, "ERROR CREATING BREAKPOINT %d!\n", err);
		free(desc);
		return -1;
	    }

	    /*
	    ** Connect it to the list.
	    */
	    if(Breakpoints) {
		for(i=0, bp=Breakpoints; bp->next; i++, bp=bp->next) ;
		bp->next = malloc(sizeof(Breakpoint));
		bp = bp->next;
	    } else {
		i = 0;
		Breakpoints = bp = malloc(sizeof(Breakpoint));
	    }
	    bp->id = debugBuffer.Index;
	    bp->addr = addr;
	    bp->next = NULL;
	    bp->desc = desc;
	    bp->oneTimeFlag = 0;
	    break;
	}

	/*
	** Clear a breakpoint.
	*/
	case 'c': {
	    Breakpoint *prior;
	    int num;

	    /*
	    ** Find the watch number, and then the watchpoint id.
	    */
	    if(ptrs[2][0] == '*') {
		FreeAllBreakpoints();
		break;
	    } else {
		i = strtol(ptrs[2], &dummy, 0);
		prior = bp = Breakpoints;
		for(i=0; bp && i<num; i++) {
		    prior = bp;
		    bp = bp->next;
		}
	    }

	    /*
	    ** Make sure the breakpoint exists.
	    */
	    if(bp == NULL) {
		fprintf(logFile, "ILLEGAL BREAKPOINT NUMBER!\n");
		return -1;
	    }

	    /*
	    ** Remove the breakpoint from the list and from the debuggee.
	    */
	    if(bp == Breakpoints) {
		Breakpoints = bp->next;
	    }
	    debugBuffer.Index = bp->id;
	    if(bp->desc)
		free(bp->desc);
	    free(bp);
	    DispatchCommand(DBG_C_ClearWatch);
	    break;
	}

	/*
	** List all of the breakpoints.
	*/
	case 'l': {
	    for(i=0, bp=Breakpoints; bp; i++, bp=bp->next) {
		fprintf(logFile, "Breakpoint [%d]:%08x\n\t%s\n",
			i, bp->addr, bp->desc);
	    }
	    break;
	}
    }
    return -1;
}
Пример #26
0
/*
** Do a single step to the next source instruction.
*/
int CommandStep(char **ptrs)
{
int	    i;
ULONG	    addr;
ULONG	    lineNum;
Breakpoint *bp;
DebugModule *module;
char	    funcName[MAX_FUNCNAME];
char	    funcName2[MAX_FUNCNAME];
char	    sourceName[CCHMAXPATH];

    /*
    ** Provide a reference to keep from getting a compile warning.
    */
    ptrs;

    /*
    ** Find the address specified.
    */
    module = FindModule(debugBuffer.MTE, NULL);
    FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS),
	       funcName, sourceName, &lineNum);
    for(i=0; i<100; i++) {
	lineNum++;
	addr = FindSourceLine(module, lineNum, sourceName);
	if(addr != 0) {
	    FindSource(module, addr, funcName2, sourceName, &lineNum);
	    if(strcmp(funcName2, funcName) == 0)
		break;
	    fprintf(logFile, "Unable to find next line.  Next function found!\n");
	    return -1;
	}
    }

    /*
    ** Did we find a line
    */
    if(addr == 0) {
	fprintf(logFile, "Unable to find next line.\n");
	return -1;
    }

    /*
    ** Set the breakpoint at the address specified.
    */
    debugBuffer.Addr  = addr;
    debugBuffer.Len   = 1;
    debugBuffer.Index = 0;
    debugBuffer.Value = DBG_W_Local | DBG_W_Execute;
    DispatchCommand(DBG_C_SetWatch);

    /*
    ** Add the breakpoint to the list, and tag it as a 'go'
    ** breakpoint which will unconditionally be cleared the
    ** next time we get back from the debuggee.
    */
    if(Breakpoints) {
	for(i=0, bp=Breakpoints; bp->next; i++, bp=bp->next) ;
	bp->next = malloc(sizeof(Breakpoint));
	bp = bp->next;
    } else {
	i = 0;
	Breakpoints = bp = malloc(sizeof(Breakpoint));
    }
    bp->id = debugBuffer.Index;
    bp->addr = addr;
    bp->next = NULL;
    bp->desc = NULL;
    bp->oneTimeFlag = 1;
    return DBG_C_Go;
}
Пример #27
0
/*
** Dump the stack frame.
*/
void DumpStack(int threadID)
{
ULONG	lineNum;
struct {
    ULONG   ebp;
    ULONG   eip;
} info;
DebugModule *module;
ULONG	oldTid;
ULONG	objectNum;
ULONG	baseOffset;
USHORT	lastCS;
char	funcName[MAX_FUNCNAME];
char    sourceName[CCHMAXPATH];

    /*
    ** Find the base and then extract out the EIP.  Follow the chain
    ** until EBP == 0
    */
    oldTid = debugBuffer.Tid;
    debugBuffer.Tid = threadID;
    DispatchCommand(DBG_C_ReadReg);
    lastCS   = debugBuffer.CS;
    info.ebp = Linearize(debugBuffer.EBP, debugBuffer.SS);
    info.eip = Linearize(debugBuffer.EIP, debugBuffer.CS);
    while(1) {
	/*
	** End of chain.
	*/
	if((info.ebp == 0) || (info.eip == 0)) {
	    debugBuffer.Tid = oldTid;
	    return;
	}

	/*
	** Find the module.
	*/
	debugBuffer.Addr = info.eip;
	DispatchCommand(DBG_C_AddrToObject);
        module = FindModule(debugBuffer.MTE, NULL);
	if(module == NULL) {
	    fprintf(logFile, "MODULE NOT FOUND!\n");
	    debugBuffer.Tid = oldTid;
	    return;
	}

	/*
	** Dump EBP:EIP of the current stack frame.
	*/
	baseOffset = debugBuffer.Buffer;
	fprintf(logFile, "EBP:\t%08x\tEIP:\t%08x\n", info.ebp, info.eip);
	fprintf(logFile, "  Base:\t%08x\tRel:\t%08x\tLen:\t%08x\n",
		baseOffset, info.eip - baseOffset, debugBuffer.Len);

	/*
	** Find the object number associated with the address.
	*/
	for(objectNum=1;;objectNum++) {
	    debugBuffer.Value = (ULONG) objectNum;
	    debugBuffer.MTE   = module->MTE;
	    if(DispatchCommand(DBG_C_NumToAddr) != DBG_N_Success)
		break;
	    if(debugBuffer.Addr == baseOffset)
		break;
	}
	fprintf(logFile, "  Object: %08x\n", objectNum);

        /*
	** Dump the values.
	*/
	FindSource(module, info.eip,
	       funcName, sourceName, &lineNum);
	if(lineNum != 0)
	    fprintf(logFile, "  Module:   %s\n"
			    "  Size:     %u\n"
			    "  Timestamp:%s\n"
			    "  Function: %s\n"
			    "  Source:   %s\n"
			    "  Line:     %d\n\n",
		    module->name, module->fileSize, ctime(&module->fTimestamp),
		    funcName, sourceName, lineNum);
	else
	    fprintf(logFile, "  Module:   %s\n"
			    "  Size:     %u\n"
			    "  Timestamp:%s\n"
			    "  Lo Function: %s\n"
			    "  Hi Function: %s\n\n",
		    module->name, module->fileSize, ctime(&module->fTimestamp),
		    funcName, sourceName);

#ifdef SHERLOCK
        {
            DebugModule *module;
            char *mod;

	    debugBuffer.Addr = info.eip;
	    DispatchCommand(DBG_C_AddrToObject);
	    if((debugBuffer.Cmd == DBG_N_Success) &&
	       (debugBuffer.Value & 0x10000000)) {
                module = FindModule(debugBuffer.MTE, NULL);
                if(module == NULL)
                    mod = "UNKNOWN";
                else
                    mod = module->name;
		FindSource(module, info.eip,
			funcName, sourceName, &lineNum);
		fprintf(logFile, "EIP: %08x, DLL: %s Func: %s\n",
			info.eip, mod, funcName);
		DisplaySource(module, sourceName, lineNum);
		fprintf(logFile, "\n\n");
	    }
	}
#endif

	/*
	** Get prior EBP, EIP
	*/
	if(module->typeFlags & FAPPTYP_32BIT) {
            debugBuffer.Addr = info.ebp;
            debugBuffer.Len  = 8;
            debugBuffer.Buffer = (ULONG) &info.ebp;
            info.ebp = info.eip = 0;
	    DispatchCommand(DBG_C_ReadMemBuf);
	} else {
	    USHORT  codePtr[2];

	    /* Get the new code pointer. */
	    debugBuffer.Addr = info.ebp+2;
	    debugBuffer.Len  = 4;
	    debugBuffer.Buffer = (ULONG) &codePtr;
	    info.eip = 0;
	    DispatchCommand(DBG_C_ReadMemBuf);

	    /* Now, get the new base pointer. */
	    debugBuffer.Addr = info.ebp;
	    debugBuffer.Len  = 2;
            debugBuffer.Buffer = (ULONG) &info.ebp;
	    info.ebp = 0;
	    DispatchCommand(DBG_C_ReadMemBuf);
	    info.ebp = Linearize(info.ebp, debugBuffer.SS);

	    /*
	    ** Now for real hocus pocus.  Try to find out
	    ** if the pointer is a near or far call!
	    **
	    ** First, check for NULL pointer, Must be end of chain.
	    */
	    if((codePtr[0] == 0) && (codePtr[1] == 0)) {
		info.eip = 0;
	    } else {
		USHORT tmp;

		/*
		** If supposidly ring 0 or ring 1 caller, then
		** that cannot be correct, must be a near call.
		*/
		tmp = codePtr[1] & 0x03;
		if((tmp == 0) || (tmp == 1)) {
		    info.eip = Linearize(codePtr[0], lastCS);
		} else {

		    /*
		    ** Assume that it is a far pointer.
		    */
		    lastCS = codePtr[1];
		    info.eip = Linearize(codePtr[0], lastCS);
		}
	    }
	}
    }
    debugBuffer.Tid = oldTid;
    return;
}
Пример #28
0
void gameStart(int mode)
{

    bool success;//是否下落成功;若失败,则说明沉底
    int i, j, k, t = 0;
    int cmd = 0;
    int timeLeft[TOTAL_PLAYER+1] = {0, 1000, 1000};
    Block tpBlk[TOTAL_PLAYER+1];

    gameInit();//初始化游戏

    while(1)
    {

        for(i = 1; i <= TOTAL_PLAYER; i++)
        {
            t++;//计时器增加
            setorigin(0, 0); //设置原点
            recoverBk(0, g_player[i].preview.y + 4 * BLOCK_SIZE, 160, 30);
            recoverBk(0, 480 - 30, 160, 30); //重绘预览区
            printScore(t);//显示得分
            drawStageLine();//绘制边界线
            FlushBatchDraw();//执行绘图


            if(g_player[i].dropped == true)
            {

                saveState(i, g_player[i].nowBlk);//保存方块的存在状态


                if(mode == CLEAR && g_player[1+(i==1)].score >= 100)gameOver(i);
                if(reachTop(i))
                {
                    gameOver(i);
                    continue;
                }//判断游戏结束

                k = fullColumn(i);
                if(k > 0)
                {
                    g_player[i].score += k * k;
                    if(mode == NORMAL && g_player[i].score % 10 == 0)newColumn(1 + (i == 1));
                }//计分与消行

                tpBlk[i] = g_player[i].preBlk; //备份预览方块
                g_player[i].nowBlk = preToNow(g_player[i].preBlk);//previewBlock变为player[1].nowBlk
                g_player[i].preBlk = createBlk(); //产生新的预览方块
                refreshBlk(i, tpBlk[i], g_player[i].preBlk, PREVIEW); //绘制新的previewBlock

                g_player[i].dropped = false;


            }


            getCmd(&cmd);//获得命令
            timeLeft[i] -= 10;
            for  (j = 1; j <= TOTAL_PLAYER; j++)
            {

                tpBlk[j] = g_player[j].nowBlk;

                success = DispatchCommand(j, cmd);
                if(success)refreshBlk(j, tpBlk[j], g_player[j].nowBlk);
                else continue;

            }//在一个玩家的循环中要同时处理两个玩家

            if(timeLeft[i] <= 0)
            {
                if(mode == NORMAL)timeLeft[i] = INIT_DELAY - (int)(2.5 * g_player[1+(i==1)].score);
                else timeLeft[i] = (int)(INIT_DELAY - (t / 1000.0)); //速度规则
                if(timeLeft[i] < MIN_DELAY)timeLeft[i] = 3 * MIN_DELAY;

                tpBlk[i] = g_player[i].nowBlk;
                if(i == 1)
                    success = DispatchCommand(1, CMD_DOWN);
                else
                    success = DispatchCommand(2, CMD_DOWN2);
                if(success)refreshBlk(i, tpBlk[i], g_player[i].nowBlk);

            }

        }


    }
    getch();
    closegraph();
}
Пример #29
0
/*
** Display the source file and line number.
*/
int DisplaySource(DebugModule *module, char *sourceName, int lineNum)
{
int	i, lastChar, is32Bit;
int	curLine;
FILE   *file = NULL;
View   *viewData = (View *) module->ViewData;
ULONG	addr, addr2;
char	buff[CCHMAXPATH];
char	dummy[CCHMAXPATH];

    /*
    ** Find out whether this is a 32 bit segment.
    */
    DispatchCommand(DBG_C_ReadReg);
    is32Bit = (debugBuffer.CSAtr & 0x80) != 0;

    /*
    ** If the view data does not exist, create and initialize it.
    */
    if(viewData == NULL) {
	viewData = module->ViewData = calloc(sizeof(View), 1);
	viewData->lastSource = strdup("");
	viewData->basePath   = strdup("");
    }

    /*
    ** Find and open the source file.
    */
    if(strlen(sourceName) > 0) {
	strcpy(buff, sourceName);
	_splitpath(sourceName, drive, dir, fname, ext);
	_splitpath(viewData->basePath, drive, dir, dummy, dummy);
	_makepath(buff, drive, dir, fname, ext);
	while((file = fopen(buff, "r")) == NULL) {
#ifdef SHERLOCK
	    buff[0] = 0;
#else
	    fprintf(logFile, "Please enter path for %s\n", sourceName);
	    fgets(buff, sizeof(buff), stdin);
#endif
	    while((strlen(buff) > 0) && isspace(*buff))
		buff[strlen(buff) - 1] = 0;
	    if(strlen(buff) == 0)
		return 0;

	    lastChar = strlen(buff) - 1;
	    while(isspace(buff[lastChar])) {
		buff[lastChar] = 0;
		lastChar--;
	    }
	    if((buff[lastChar] != '\\') && (buff[lastChar] != '/'))
		strcat(buff, "/");
	    _splitpath(buff, drive, dir, dummy, dummy);
	    _makepath(buff, drive, dir, fname, ext);
	}
    }

    /*
    ** Free/show the last source viewed.
    */
    if(viewData->lastSource)
	free(viewData->lastSource);
    viewData->lastSource = strdup(buff);

    /*
    ** Free the previous path spec.
    */
    if(viewData->basePath)
	free(viewData->basePath);
    _splitpath(buff, drive, dir, fname, ext);
    _makepath(buff, drive, dir, "", "");
    viewData->basePath = strdup(buff);

    /*
    ** Go to just before the line specific.
    */
    if(file) {
	curLine = 0;
	for(curLine=1; curLine < lineNum - 5; curLine++) {
	    fgets(buff, sizeof(buff), file);
	}
    }

    /*
    ** Now, display the source.
    */
    if(file) {
	for(i=0; i<10; i++, curLine++) {
	    if(file)
		if(fgets(buff, sizeof(buff), file) == NULL)
		    break;
	    if(ShouldDumpSource) {
		if(curLine == lineNum)
		    fprintf(logFile, "*%5d: %s", curLine, buff);
		else
		    fprintf(logFile, " %5d: %s", curLine, buff);
	    }
	    if((addr = FindSourceLine(module, curLine, sourceName)) != 0) {
		int	j;

		/*
		** Find the next line.
		*/
		for(j=1; j < 10; j++) {
		    if((addr2=FindSourceLine(module,curLine+j,sourceName))!=0)
			break;
		}
	    }
	    if(addr2 == 0)
		addr2 = addr + 0x10;
	    if(ShouldDumpAsm)
		DumpAsm(addr, addr2-addr, is32Bit);
	}
    } else {
	addr = Linearize(debugBuffer.EIP, debugBuffer.CS);
	DumpAsm(addr, 0x20, is32Bit);
	addr2 = addr + 0x20;
    }
    viewData->lastLine = curLine - 1;
    viewData->lastAddr = addr2;
    if(file)
	fclose(file);
    return 1;
}
Пример #30
0
/*
** View the source for the lines specified.
*/
int CommandView(char **ptrs)
{
DebugModule    *module;
char	       *srcEnd;
ULONG		addr;
ULONG		lineNum;
char		funcName[MAX_FUNCNAME];
char		sourceName[CCHMAXPATH];

    /*
    ** Get the common data.
    */
    module = FindModule(debugBuffer.MTE, NULL);
    FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS),
	       funcName, sourceName, &lineNum);

    /*
    ** View the next lines to be displayed.
    */
    if(ptrs[2] == NULL) {
	DisplaySource(module, sourceName, GetLastLine(module) + 5);
	return -1;
    }

    /*
    ** View a line.
    */
    if(ptrs[2][0] == '.') {

	/*
	** Find the line number or the file name/line number
	*/
	if(isdigit(ptrs[2][1])) {
	    lineNum = atol(&ptrs[2][1]);
	} else {
	    strcpy(sourceName, &ptrs[2][1]);
	    *strrchr(sourceName, ':') = 0;
	    lineNum = atol(strrchr(ptrs[2], ':') + 1);
	}
	DisplaySource(module, sourceName, lineNum);
	return -1;
    }

    /*
    ** Get a view at a given offset.
    */
    if(isxdigit(ptrs[2][0])) {
	/*
	** Find the module associated with the address specified.
	*/
	debugBuffer.Addr = addr = StrToAddr(ptrs[2], TOADDR_CODE);
	DispatchCommand(DBG_C_AddrToObject);

	/*
	** Find the module/source associated with the information given.
	*/
	module = FindModule(debugBuffer.MTE, NULL);
	FindSource(NULL, addr, funcName, sourceName, &lineNum);
	DisplaySource(module, sourceName, lineNum);
	return -1;
    }

    /*
    ** ERROR!
    */
    fprintf(logFile, "Invalid syntax\n");
    return -1;
}