Exemplo n.º 1
0
int main(int ac,char *av[])
{
    int rc = 0;

    SET_THREAD_NAME("bootstrap");

    // Disable default invalid crt parameter handling

    DISABLE_CRT_INVALID_PARAMETER_HANDLER();

    // Request the highest possible time-interval accuracy...

    timeBeginPeriod( 1 );   // (one millisecond time interval accuracy)

    // If we're being debugged, then let the debugger
    // catch the exception. Otherwise, let our exception
    // handler catch it...

    if (!IsDebuggerPresent())
    {
        if (!sysblk.daemon_mode)    // (normal panel mode?)
        {
            EnableMenuItem( GetSystemMenu( FindConsoleHandle(), FALSE ),
                            SC_CLOSE, MF_BYCOMMAND | MF_GRAYED );
        }

        if (1
            && (g_hDbgHelpDll = LoadLibrary(_T("DbgHelp.dll")))
            && (g_pfnMiniDumpWriteDumpFunc = (MINIDUMPWRITEDUMPFUNC*)
                GetProcAddress( g_hDbgHelpDll, _T("MiniDumpWriteDump")))
        )
        {
            GetModuleFileNameW( NULL, g_wszHercPath, _countof( g_wszHercPath ) );
            _wsplitpath( g_wszHercPath, g_wszHercDrive, g_wszHercDir, NULL, NULL );
        }

        SetUnhandledExceptionFilter( HerculesUnhandledExceptionFilter );
        SetErrorMode( SEM_NOGPFAULTERRORBOX );
    }

    rc = impl(ac,av);       // (Hercules, do your thing!)

    // Each call to "timeBeginPeriod" must be matched with a call to "timeEndPeriod"

    timeEndPeriod( 1 );     // (no longer care about accurate time intervals)

    if (!IsDebuggerPresent())
    {
        if (!sysblk.daemon_mode)    // (normal panel mode?)
        {
            EnableMenuItem( GetSystemMenu( FindConsoleHandle(), FALSE ),
                        SC_CLOSE, MF_BYCOMMAND | MF_ENABLED );
        }
    }

    return rc;
}
Exemplo n.º 2
0
int main(int argc, char* argv[]) {
  Arguments args;
  GlobalState state;
  state.num_locking_processes = 0;
  state.p_locking_processes = NULL;

  state.appHWnd = FindConsoleHandle();

  kExitCode exit_code = ParseArguments(argc, argv, &args);
  if (exit_code == kUserNoFiles) {
    PrintHelp();
    fprintf(stderr, "\nError: No filename(s) specified.");
    return (exit_code);
  } else if (exit_code == kUserTooManyFiles) {
    fprintf(stderr, "\nError: Too many filenames specified, max is 32.\n");
    return (exit_code);
  } else if (exit_code != kSuccess) {
    return (exit_code);
  }

  exit_code = InterfaceStateInit(&args, &state.if_state);
  if (exit_code != kSuccess) {
    CleanupAndExit(&args, &state, exit_code);
  }

  if (args.action == kActionHelpOnly) {
    PrintHelp();
    return (kSuccess);
  }

  do {
    kExitCode update_result = UpdateState(&args, &state);
    if (update_result == kFailEnumProc) {
      fprintf(stderr, "\nError: Failed to enumerate processes.\n");
      return (kFailEnumProc);
    } else if (update_result == kSuccessNoReplacements) {
      dbg_printf("Success: No replacement files found.\n");
      return (kSuccess);
    }

  } while (1);

  return (kSuccess);
}
Exemplo n.º 3
0
static void ProcessException( EXCEPTION_POINTERS* pExceptionPtrs )
{
    int rc;
    UINT uiMBFlags =
        0
        | MB_SYSTEMMODAL
        | MB_TOPMOST
        | MB_SETFOREGROUND
        ;

    HWND hwndMBOwner = FindConsoleHandle();

    if (!hwndMBOwner || !IsWindowVisible(hwndMBOwner))
        hwndMBOwner = GetDesktopWindow();

    if ( !g_pfnMiniDumpWriteDumpFunc )
    {
        MsgBox
        (
            hwndMBOwner,
            _T("The creation of a crash dump for analysis by the Hercules ")
            _T("development team is NOT possible\nbecause the required 'DbgHelp.dll' ")
            _T("is missing or is not installed or was otherwise not located.")
            ,_T("OOPS!  Hercules has crashed!"),
            uiMBFlags
                | MB_ICONERROR
                | MB_OK
            ,0                  // (default/neutral language)
            ,(15 * 1000)        // (timeout == 15 seconds)
        );

        return;
    }

    if ( IDYES == ( rc = MsgBox
    (
        hwndMBOwner,
        _T("The creation of a crash dump for further analysis by ")
        _T("the Hercules development team is strongly suggested.\n\n")
        _T("Would you like to create a crash dump for ")
        _T("the Hercules development team to analyze?")
        ,_T("OOPS!  Hercules has crashed!"),
        uiMBFlags
            | MB_ICONERROR
            | MB_YESNO
        ,0                      // (default/neutral language)
        ,(10 * 1000)            // (timeout == 10 seconds)
    ))
        || MB_TIMEDOUT == rc
    )
    {
        if ( CreateMiniDump( pExceptionPtrs ) && MB_TIMEDOUT != rc )
        {
            MsgBox
            (
                hwndMBOwner,
                _T("Please send the dump to the Hercules development team for analysis.")
                ,_T("Dump Complete"),
                uiMBFlags
                    | MB_ICONEXCLAMATION
                    | MB_OK
                ,0              // (default/neutral language)
                ,(5 * 1000)     // (timeout == 5 seconds)
            );
        }
    }
}
Exemplo n.º 4
0
static LONG WINAPI HerculesUnhandledExceptionFilter( EXCEPTION_POINTERS* pExceptionPtrs )
{
    static BOOL bDidThis = FALSE;               // (if we did this once already)
    if (bDidThis)
        return EXCEPTION_EXECUTE_HANDLER;       // (quick exit to prevent loop)
    bDidThis = TRUE;
    SetErrorMode( 0 );                          // (reset back to default handling)

    if (sysblk.daemon_mode)                     // (is an external GUI in control?)
    {
        fflush( stdout );
        fflush( stderr );

        _ftprintf( stderr, _T("]!OOPS!\n") );   // (external GUI pre-processing...)

        fflush( stdout );
        fflush( stderr );
        Sleep( 10 );
    }
    else
    {
        // Normal panel mode: reset console mode and clear the screen...

        DWORD                       dwCellsWritten;
        CONSOLE_SCREEN_BUFFER_INFO  csbi;
        HANDLE                      hStdIn, hStdErr;
        COORD                       ptConsole = { 0, 0 };

        EnableMenuItem( GetSystemMenu( FindConsoleHandle(), FALSE ),
                    SC_CLOSE, MF_BYCOMMAND | MF_ENABLED );

        hStdIn  = GetStdHandle( STD_INPUT_HANDLE );
        hStdErr = GetStdHandle( STD_ERROR_HANDLE );

#define DEFAULT_CONSOLE_ATTRIBUTES     (0   \
        | FOREGROUND_RED                    \
        | FOREGROUND_GREEN                  \
        | FOREGROUND_BLUE                   \
        )

/* FIXME these are defined in SDK V6+ */
#ifndef ENABLE_INSERT_MODE
#define ENABLE_INSERT_MODE 0
#endif
#ifndef ENABLE_QUICK_EDIT_MODE
#define ENABLE_QUICK_EDIT_MODE 0
#endif

#define DEFAULT_CONSOLE_INPUT_MODE     (0   \
        | ENABLE_ECHO_INPUT                 \
        | ENABLE_INSERT_MODE                \
        | ENABLE_LINE_INPUT                 \
        | ENABLE_MOUSE_INPUT                \
        | ENABLE_PROCESSED_INPUT            \
        | ENABLE_QUICK_EDIT_MODE            \
        )

#define DEFAULT_CONSOLE_OUTPUT_MODE    (0   \
        | ENABLE_PROCESSED_OUTPUT           \
        | ENABLE_WRAP_AT_EOL_OUTPUT         \
        )

        SetConsoleTextAttribute( hStdErr, DEFAULT_CONSOLE_ATTRIBUTES  );
        SetConsoleMode         ( hStdIn,  DEFAULT_CONSOLE_INPUT_MODE  );
        SetConsoleMode         ( hStdErr, DEFAULT_CONSOLE_OUTPUT_MODE );

        GetConsoleScreenBufferInfo( hStdErr, &csbi );
        FillConsoleOutputCharacter( hStdErr, ' ', csbi.dwSize.X * csbi.dwSize.Y, ptConsole, &dwCellsWritten );
        GetConsoleScreenBufferInfo( hStdErr, &csbi );
        FillConsoleOutputAttribute( hStdErr, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, ptConsole, &dwCellsWritten );
        SetConsoleCursorPosition  ( hStdErr, ptConsole );

        fflush( stdout );
        fflush( stderr );
        Sleep( 10 );
    }

    _tprintf( _T("\n\n") );
    _tprintf( _T("                      ***************\n") );
    _tprintf( _T("                      *    OOPS!    *\n") );
    _tprintf( _T("                      ***************\n") );
    _tprintf( _T("\n") );
    _tprintf( _T("                    Hercules has crashed!\n") );
    _tprintf( _T("\n") );
    _tprintf( _T("(you may or may not need to press ENTER if no 'oops!' dialog-box appears)\n") );
    _tprintf( _T("\n") );

    fflush( stdout );
    fflush( stderr );
    Sleep( 10 );

    ProcessException( pExceptionPtrs );     // (create a minidump, if possible)

    fflush( stdout );
    fflush( stderr );
    Sleep( 10 );

    timeEndPeriod( 1 );                     // (reset to default time interval)

    return EXCEPTION_EXECUTE_HANDLER;       // (quite likely exits the process)
}