Example #1
0
int main(int argc, const char* argv[]) {
  printStartMessage();

  std::string target;

  unsigned int port = 2222;
  bool verbose = false;
  bool vverbose = false;
  std::string lf = "";
  std::vector<const char*> commands;

  handleCommandLine(argc, argv, target, port, verbose, vverbose, lf, commands);

  unsigned int loglevel = LOG_ALWAYS;

  if (verbose) {
    loglevel = LOG_VERBOSE;
  } else if (vverbose) {
    loglevel = LOG_ALL;
  }

  initLogger(lf, loglevel);

  msglog->log(LOG_ALWAYS,
              "---------------------------------------------------------");
  msglog->log(LOG_ALWAYS, "Starting new Debugging session");
  msglog->log(LOG_ALWAYS, "Server Port %d", port);

  if (verbose) {
    msglog->log(LOG_ALWAYS, "Verbose mode: ON");
  }

  if (vverbose) {
    msglog->log(LOG_ALWAYS, "Very Verbose mode: ON");
  }

  if (lf != "") {
    msglog->log(LOG_ALWAYS, "Logging to file: %s", lf.c_str());
  }

  for (;;) {
    std::unique_ptr<DebugClient> debugClient;

    if (target == "") {
      msglog->log(LOG_ALWAYS,
                  "No target specified. Target will be chosen later.");

      debugClient = std::unique_ptr<DebugClient>(
          new DebugClient(new CONNECTION_POLICY(port), new SYSTEM_POLICY()));

    } else if (zylib::zycon::isPositiveNumber(target)) {
      msglog->log(LOG_ALWAYS, "Target PID: %s", target.c_str());

      unsigned int processId = zylib::zycon::parseString<unsigned int>(target);

      debugClient = std::unique_ptr<DebugClient>(
          new DebugClient(new CONNECTION_POLICY(port),
          new SYSTEM_POLICY(processId)));
    } else {
      msglog->log(LOG_ALWAYS, "Target executable: %s", target.c_str());

      if (!fexists(target.c_str())) {
        msglog->log(LOG_ALWAYS, "Error: Target executable '%s' does not exist",
                    target.c_str());

        return 1;
      }

      debugClient = std::unique_ptr<DebugClient>(new DebugClient(
          new CONNECTION_POLICY(port),
          new SYSTEM_POLICY(target.c_str(), commands)));
    }

    std::string arguments = "";

    if (commands.size() == 0) {
      arguments = "-";
    }

    for (std::vector<const char*>::iterator Iter = commands.begin();
        Iter != commands.end(); ++Iter) {
      arguments += *Iter;
      arguments += " ";
    }

    msglog->log(LOG_ALWAYS, "Commandline arguments: %s", arguments.c_str());

    msglog->log(LOG_ALWAYS,
                "---------------------------------------------------------");

    msglog->log(LOG_ALWAYS, "Waiting for connection from BinNavi...");

    unsigned int init = debugClient->initializeConnection();

    if (init) {
      msglog->log(LOG_ALWAYS,
                  "Error: Couldn't initialize connection (Code: %d)", init);
      return 1;
    }

    unsigned int connected = debugClient->waitForConnection();

    if (connected) {
      msglog->log(LOG_ALWAYS, "Error: Didn't receive a connection (Code %d)",
                  connected);
      return 1;
    }

    if (debugClient->getSystemPolicy()->hasTarget()) {
      // We do have a system policy at this point. That means that a target
      // process was
      // in some way selected.

      unsigned int attached = debugClient->attachToProcess();

      if (attached) {
        msglog->log(LOG_ALWAYS,
                    "Error: Couldn't attach to the target process (Code %d)",
                    attached);

        debugClient->closeConnection();

        target = "";

        continue;
      } else {
        // Once the debug client attached to the target for the first time, it
        // is necessary
        // to use the PID instead of the target path from now on to support
        // re-attach operations.
        target = zylib::zycon::toString(
            debugClient->getSystemPolicy()->getPID());
      }
    } else {
      debugClient->requestTarget();
    }

    unsigned int procp = debugClient->processPackets();

    if (procp) {
      msglog->log(LOG_ALWAYS,
                  "Error: Error during packet processing. (Code %d)", procp);
    }

    debugClient->closeConnection();
  }
}
Example #2
0
int main(int argc, const char* argv[]) {
  printStartMessage();

  std::string target;

  unsigned int port = 2222;
  bool verbose = false;
  bool vverbose = false;
  std::string lf = "";
  std::vector<const char*> commands;

  handleCommandLine(argc, argv, target, port, verbose, vverbose, lf, commands);

  unsigned int loglevel = LOG_ALWAYS;

  if (verbose) {
    loglevel = LOG_VERBOSE;
  } else if (vverbose) {
    loglevel = LOG_ALL;
  }

  initLogger(lf, loglevel);

  msglog->log(LOG_ALWAYS,
              "---------------------------------------------------------");
  msglog->log(LOG_ALWAYS, "Starting new Debugging session");
  msglog->log(LOG_ALWAYS, "Server Port %d", port);

  if (verbose) {
    msglog->log(LOG_ALWAYS, "Verbose mode: ON");
  }

  if (vverbose) {
    msglog->log(LOG_ALWAYS, "Very Verbose mode: ON");
  }

  if (lf != "") {
    msglog->log(LOG_ALWAYS, "Logging to file: %s", lf.c_str());
  }
  /*
   for (;;)
   {*/
  std::unique_ptr<DebugClient> debugClient;

  msglog->log(LOG_ALWAYS, "Target pipe: %s", target.c_str());

  debugClient = std::unique_ptr<DebugClient>(
      new DebugClient(new CONNECTION_POLICY(port),
                      new SYSTEM_POLICY(target.c_str())));

  msglog->log(LOG_ALWAYS,
              "---------------------------------------------------------");

  msglog->log(LOG_ALWAYS, "Waiting for connection from BinNavi...");

  unsigned int init = debugClient->initializeConnection();

  if (init) {
    msglog->log(LOG_ALWAYS, "Error: Couldn't initialize connection (Code: d)",
                init);
    return 1;
  }

  unsigned int connected = debugClient->waitForConnection();

  if (connected) {
    msglog->log(LOG_ALWAYS, "Error: Didn't receive a connection (Code %d)",
                connected);
    return 1;
  }

  if (debugClient->getSystemPolicy()->hasTarget()) {
    // We do have a system policy at this point. That means that a target
    // process was
    // in some way selected.

    unsigned int attached = debugClient->attachToProcess();

    if (attached) {
      msglog->log(LOG_ALWAYS,
                  "Error: Couldn't attach to the target process (Code %d)",
                  attached);

      debugClient->closeConnection();
      target = "";

      // continue;
    } else {
      // Once the debug client attached to the target for the first time, it is
      // necessary
      // to use the PID instead of the the taregt path from now on to support
      // re-attach operations.
      target = zylib::zycon::toString(debugClient->getSystemPolicy()->getPID());
    }
  } else {
    debugClient->requestTarget();
  }

  unsigned int procp = debugClient->processPackets();

  if (procp) {
    msglog->log(LOG_ALWAYS, "Error: Error during packet processing. (Code %d)",
                procp);
  }

  debugClient->closeConnection();
  //}
}
Example #3
0
int main(int argc, const char* argv[]) {
  printStartMessage();

  if (EXPIRE_YEAR) {
    checkTrial();
  }

  std::vector < std::pair<std::string, std::string> > params =
      zylib::zyline::parseCommandLine(argc, argv);

  if (params.size() < 3) {
    std::cout << szUsage << std::endl;
    return 1;
  }

  std::string gdbhost;
  std::string targetCpu;
  unsigned int clientport = 2222;
  bool verbose = false;
  bool vverbose = false;
  bool testMode = false;
  std::string lf = "";

  handleCommandLine(params, gdbhost, targetCpu, clientport, verbose, vverbose,
                    testMode, lf);

  unsigned int loglevel = LOG_ALWAYS;

  if (verbose) {
    loglevel = LOG_VERBOSE;
  } else if (vverbose) {
    loglevel = LOG_ALL;
  }

  initLogger(lf, loglevel);

  msglog->log(LOG_ALWAYS,
              "---------------------------------------------------------");
  msglog->log(LOG_ALWAYS, "Starting new GDB client session");
  msglog->log(LOG_ALWAYS, "Location of the GDB server: %s", gdbhost.c_str());
  msglog->log(LOG_ALWAYS, "Target CPU: %s", targetCpu.c_str());
  msglog->log(LOG_ALWAYS, "Server Port %d", clientport);

  if (verbose) {
    msglog->log(LOG_ALWAYS, "Verbose mode: ON");
  }

  if (vverbose) {
    msglog->log(LOG_ALWAYS, "Very Verbose mode: ON");
  }

  if (testMode) {
    msglog->log(LOG_ALWAYS, "Test mode: ON");
  }

  if (lf != "") {
    msglog->log(LOG_ALWAYS, "Logging to file: %s", lf.c_str());
  }

  msglog->log(LOG_ALWAYS,
              "---------------------------------------------------------");

  // don't delete it after use, debugClient will do it
  GdbSystem* system = new SYSTEM_POLICY(123);

  std::unique_ptr<DebugClient> debugClient(
      new DebugClient(new CONNECTION_POLICY(clientport), system));

  msglog->log(LOG_ALWAYS, "Connecting to the GDB server ...");

  NaviError initResult = system->initTarget(gdbhost, targetCpu);

  if (initResult) {
    if (initResult == NaviErrors::INVALID_CONNECTION_STRING) {
      msglog->log(LOG_ALWAYS, "Error: Invalid connection string");
    } else if (initResult == NaviErrors::INVALID_CPU_STRING) {
      msglog->log(LOG_ALWAYS, "Error: Invalid CPU string");
    } else if (initResult == NaviErrors::COULDNT_CONNECT_TO_GDBSERVER) {
      msglog->log(LOG_ALWAYS, "Error: Couldn't connect to the gdbserver");
    } else {
      msglog->log(LOG_ALWAYS, "Error: Unexpected error (Code %d)", initResult);
    }

    return initResult;
  }

  msglog->log(LOG_ALWAYS, "Connection to the GDB server open...");

  if (testMode) {
    system->getCpu()->testRun();

    return 0;
  }

  do {
    msglog->log(LOG_VERBOSE, "Creating server for BinNavi to connect ...");

    unsigned int init = debugClient->initializeConnection();

    if (init) {
      msglog->log(LOG_ALWAYS, "Error: Couldn't create server (Code d)", init);
      return 1;
    }

    msglog->log(LOG_VERBOSE, "Waiting for BinNavi to connect ...");

    unsigned int connected = debugClient->waitForConnection();

    if (connected) {
      msglog->log(LOG_ALWAYS, "Error: Didn't receive a connection (Code %d)",
                  connected);
      return 1;
    }

    msglog->log(LOG_VERBOSE, "Attaching to the target process ...");

    unsigned int attached = debugClient->attachToProcess();

    if (attached) {
      msglog->log(LOG_ALWAYS,
                  "Error: Couldn't attach to the target process (Code %d)",
                  attached);
      return 1;
    }

    msglog->log(LOG_VERBOSE, "Processing communication packets ...");

    unsigned int procp = debugClient->processPackets();

    if (procp) {
      msglog->log(LOG_ALWAYS,
                  "Error: Error during packet processing. (Code %d)", procp);
    }

    msglog->log(LOG_VERBOSE, "Closing the connection to BinNavi ...");

    debugClient->closeConnection();
  } while (true);
}
Example #4
0
int main(int ac, char *av[])
{
	int	       	i, c, quitFlag, twoPlayer;		
	pthread_t	collisionThread;
	pthread_t	destCollisionThread;
	pthread_t	gameMonitor;
	void	      	*animate();	
	
	quitFlag = 0;

	setup();
	
	/*
	 * Display start screen, have the user press 'S' to start
	 * the game.
	 */
	printStartMessage();
	while (1) {
		c = getch();
		if (c == '1') {
			twoPlayer = 0;
			clear();
			refresh();
			break;
		} else if (c == '2') {
			twoPlayer = 1;
			clear();
			refresh();
			break;
		} else if (c == 'Q') {
			quitFlag = 1;
			break;
		}
	}	
		

	if (twoPlayer) {
		setupCannon(2);	
		displayCannon(2);
	} else {
		setupCannon(1);
	}
	
	setRocketsToDead(rockets);
	displayCannon(1);
	displayInfo();

	if (pthread_create(&saucerSetup, NULL, setupSaucer, NULL)) {
		endwin();
		exit(0);
	} 	
	pthread_create(&destroyerThread, NULL, sendDestroyer, &destShip); 
	pthread_create(&collisionThread, NULL, collisionDetection, NULL);
	pthread_create(&destCollisionThread, NULL, checkDestRocketCollision, NULL);
	pthread_create(&gameMonitor, NULL, checkEndConditions, NULL);

	/* process user input */
	while(!quitFlag) {
		c = getch();

		if ( c == 'Q' || quitFlag){
			 quitFlag = 1;
			 break;
		} else if (c == 'j' && !endGame) {
			moveCannon(-1, 1);
		} else if (c == 'l' && !endGame) {
			moveCannon(1, 1);
		} else if (c == 'a' && !endGame) {
			moveCannon(-1, 2);
		} else if (c == 'd' && !endGame) {
			moveCannon(1, 2);
		} else if (c == 'w' && !endGame) {
			shootRocket(2);
		} else if (c == 'i' && !endGame) {
			shootRocket(1);	
		}	
	}

	/* cancel all the threads */
	pthread_mutex_lock(&mx);
	for (i=0; i < MAX_ROCKETS; i++) {
		pthread_cancel(rocketThreads[i]);
	}
	pthread_cancel(collisionThread);
	pthread_cancel(destCollisionThread);
	pthread_cancel(gameMonitor);
	endwin();
	return 0;
}