Ejemplo n.º 1
0
def DebugProgram(filepath):
	#Instance a Debug object.
	debug_args = list()
	debug_args.insert(0,PROGRAM_PATH)
	debug_args.insert(len(debug_args),filepath)

	debug = Debug(AccessViolationHandlerWINAPPDBG, bKillOnExit = True)
	#debug.system.load_dbghelp("C:\\Program Files\\Debugging Tools for Windows (x86)\\dbghelp.dll")
	System.fix_symbol_store_path(symbol_store_path = "C:\\ProgramData\\Dbg\\sym",remote = True,force = True) #enter local symbol path here if you have downloaded symbols
	System.set_kill_on_exit_mode(True)
	try:
		 # The execution time limit is 5 seconds.
		maxTime = time() + 5
		# Start a new process for debugging.
		debug.execv(debug_args)

		# Wait for the debugee to finish.
		#debug.loop()
		 # Loop while calc.exe is alive and the time limit wasn't reached.
		while debug and time() < maxTime:
			try:

				# Get the next debug event.
				debug.wait(1000)  # 1 second accuracy

				# Show the current time on screen.
				#print time()

			# If wait() times out just try again.
			# On any other error stop debugging.
			except WindowsError, e:
				if e.winerror in (win32.ERROR_SEM_TIMEOUT,
								  win32.WAIT_TIMEOUT):
					continue
				raise

			# Dispatch the event and continue execution.
			try:
				debug.dispatch()
			finally:
				debug.cont()
		# Stop the debugger.
	finally:
		debug.stop()
Ejemplo n.º 2
0
    def run(self, target_file, save_path=None):
        """
        Run the executable with the provided file, optionally saving all OLEv1
        parts that are encountered.
        """

        # TODO: Ensure target_file is readable

        opts = [self.executable, target_file]
        handler = CustomEventHandler(self._log)
        handler.save_path = save_path

        with Debug(handler, bKillOnExit=True) as debug:

            # Ensure the target application dies if the debugger is killed
            System.set_kill_on_exit_mode(True)
            max_time = time() + self.timeout

            try:
                debug.execv(opts)
            except WindowsError:
                self._log.error("Could not run Office application, check it is 32-bit")

            try:
                while debug.get_debugee_count() > 0 and time() < max_time:
                    try:
                        # Get the next debug event.
                        debug.wait(1000)

                    except WindowsError, exc:
                        if exc.winerror in (win32.ERROR_SEM_TIMEOUT,
                                            win32.WAIT_TIMEOUT):
                            continue
                        raise

                    # Dispatch the event and continue execution.
                    try:
                        debug.dispatch()
                    finally:
                        debug.cont()
            finally:
                debug.stop()

        return handler.objects