Ejemplo n.º 1
0
void Init(char *langs, char *dialects, int anamorph)
{
  Starting = 1;
  GenOnAssert = 1;
  LexEntryOff = 0;
  SaveTime = 1;
    /* SaveTime = 1: no spell correction hashing or phrase derivation,
     *               saves memory.
     * SaveTime = 0: uses more time and memory.
     */
  qallocInit();
  DbgInit();
  DbgSet(DBGALL, DBGBAD);
  DbgSetStdoutLevel(DBGOK);
  NoticePrint(stderr);
  NoticePrint(Log);
  EnvInit();
  StringInit();
  RandomInit();
  GridInit();
  ObjInit();
  ObjListInit();
  DbInit();
  ContextInit();
  TsInit();
  TsRangeInit();
  LexEntryInit();
  Lex_WordForm2Init();
  MorphInit(anamorph);
  WordFormInit();
  InferenceInit();
  ReportInit();
  CommentaryInit();
  TranslateInit();
  LearnInit();
  StopAtInit();
  TT_HTML_Init();
  StdDiscourse = DiscourseCreate(langs, dialects);
  DiscourseSetLang(StdDiscourse, F_ENGLISH);
  Starting = 0;
}
Ejemplo n.º 2
0
int main(void)
{
    ADPCFG = 0xFFFF; // Ports as digital, not analog
    #warning "Building for dsPIC33FJ128GP804"

    ETH_CS = 1;
    RF_SPI_CS = 1;
    FLASH_CS1 = 1;
    FLASH_CS2 = 1;

    SysInitGpio();

    RF_POWER = 0;
    SENSOR_PWR = 0;
    CNPU2bits.CN21PUE = 1;

    // Setup UART1 to ICSP pins
    PPSUnLock;
    iPPSOutput(OUT_PIN_PPS_RP0, OUT_FN_PPS_U1TX);
    iPPSInput(IN_FN_PPS_U1RX, IN_PIN_PPS_RP1);
    PPSLock;

    ExtIntInit();
    //spiInit(1);
    UartInit(1, 115200*2);
    printf("Hello world!\r\n");

    // Disable nested ISR
    //INTCON1bits.NSTDIS = 1;

    RtosTaskInit();

    RfInit();
    DbgInit();
    
    RtosTaskRun();

    //while(1);
    return 0;
}
Ejemplo n.º 3
0
void __cdecl ldr_logo()
{
    kboot_info *bi;
	unsigned char ch;
    UINT32 e;

    HeapInit();
	ConsoleInit();
    TxtSetFlags(BGCOLOR_BLACK|FGCOLOR_GREEN);
	TxtClearScreen();
    SerialInit(); 
	PicInit();
	DescriptorsInit();
    InterruptsInit();
    ExceptionsInit();
    DbgInit();
	_enable();
	IrqInit();
	TssInit();
	Vm86Init();
	TimerInit();
	KbdInit();
    //DbgStepEnable();
	StorageProbe();
    e = VolReadFile("A:\\OSLDR.EXE", (VPTR)0x300000);
    DbgPrintf("%s\n", DbgStatusStr(e));
	if(VideoInit())
	{
		DbgPrintf("\nError Initializing Video Subsystem");
	}
	while(1)
	{
		ch=KbdGetKey();
		_Putch(ch);
		if(ch==33) KbdCpuReset();
	}
    while(1);
}
Ejemplo n.º 4
0
int main (void)
#endif
{
    struct mouse_info info;
    struct mouse_box full_box, small_box;
    unsigned char width, height;
    char C;
    bool Invisible = true, Done = false, Jailed = false;

#ifdef __ATARIXL__
    cprintf ("adding heap: $%04X bytes at $%04X\r\n",
             &_HIDDEN_RAM_SIZE__ - (&_HIDDEN_RAM_LAST__ - &_HIDDEN_RAM_START__),
             &_HIDDEN_RAM_LAST__);

    _heapadd (&_HIDDEN_RAM_LAST__, (size_t)(&_HIDDEN_RAM_SIZE__ - (&_HIDDEN_RAM_LAST__ - &_HIDDEN_RAM_START__)));
    cgetc ();
#endif

#ifndef NO_DEBUG
    /* Initialize the debugger */
    DbgInit (0);
#endif

    /* Set dark-on-light colors.  Clear the screen. */
#ifdef __CBM__
    (void) bordercolor (COLOR_GRAY2);
    (void) bgcolor (COLOR_WHITE);
    (void) textcolor (COLOR_GRAY1);
#else
    (void) bordercolor (COLOR_BLUE);
    (void) bgcolor (COLOR_WHITE);
    (void) textcolor (COLOR_BLACK);
#endif
    cursor (0);
    clrscr ();

    /* If a lightpen driver is installed, then it can get a calibration value
    ** from this file (if it exists).  Or, the user can adjust the pen; and,
    ** the value will be put into this file, for the next time.
    ** (Other drivers will ignore this.)
    */
#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
    pen_adjust ("pen.dat");
#endif

#if DYN_DRV
    /* If a dynamically loadable driver is named on the command line,
    ** then use that driver instead of the standard one.
    */
    if (argc > 1) {
        mouse_name = argv[1];
    } else {
#if defined(__ATARI__) || defined(__C64__) || defined(__C128__)
        char selection, flag = 0;
        cprintf ("Select mouse driver:\r\n"
                 "  0 - Joystick\r\n"
#ifdef __ATARI__
                 "  1 - ST Mouse\r\n"
                 "  2 - Amiga Mouse\r\n"
                 "  3 - Atari Trakball\r\n"
                 "  4 - Atari TouchPad\r\n"
#else
                 "  1 - 1351 Mouse\r\n"
                 "  2 - Inkwell Mouse\r\n"
                 "  3 - Paddle\r\n"
#endif
                 "Enter selection: ");
        while (1) {
            switch (selection = cgetc ()) {
            case '0': mouse_name = MSENAME_0; flag = 1; break;
            case '1': mouse_name = MSENAME_1; flag = 1; break;
            case '2': mouse_name = MSENAME_2; flag = 1; break;
            case '3': mouse_name = MSENAME_3; flag = 1; break;
#ifdef __ATARI__
            case '4': mouse_name = MSENAME_4; flag = 1; break;
#endif
            }
            if (flag) break;
        }
        cprintf ("%c\r\nOK, loading \"%s\",\r\nplease wait patiently...\r\n", selection, mouse_name);
#else
        /* Output a warning about the standard driver that is needed. */
        DoWarning ();
        mouse_name = mouse_stddrv;
#endif
    }

    /* Load and install the driver. */
    CheckError ("mouse_load_driver",
                mouse_load_driver (&MOUSE_CALLBACK, mouse_name));
#else  /* not DYN_DRV */
#if !defined(MOUSE_DRIVER) && (defined(__ATARI__) || defined(__C64__) || defined(__C128__))
    {
        char selection, flag = 0;
        cprintf ("Select mouse driver:\r\n"
                 "  0 - Joystick\r\n"
#ifdef __ATARI__
                 "  1 - ST Mouse\r\n"
                 "  2 - Amiga Mouse\r\n"
                 "  3 - Atari Trakball\r\n"
                 "  4 - Atari TouchPad\r\n"
#else
                 "  1 - 1351 Mouse\r\n"
                 "  2 - Inkwell Mouse\r\n"
                 "  3 - Paddle\r\n"
#endif
                 "Enter selection: ");
        while (1) {
            switch (selection = cgetc ()) {
            case '0': mouse_drv_use = MSESTAT_0; flag = 1; break;
            case '1': mouse_drv_use = MSESTAT_1; flag = 1; break;
            case '2': mouse_drv_use = MSESTAT_2; flag = 1; break;
            case '3': mouse_drv_use = MSESTAT_3; flag = 1; break;
#ifdef __ATARI__
            case '4': mouse_drv_use = MSESTAT_4; flag = 1; break;
#endif
            }
            if (flag) break;
        }
    }
#else
    mouse_drv_use = mouse_static_stddrv;
#endif

    /* Install the driver. */
    CheckError ("mouse_install",
                mouse_install (&MOUSE_CALLBACK,
#  ifdef MOUSE_DRIVER
                               MOUSE_DRIVER
#  else
#if defined(__ATARI__) || defined(__C64__) || defined(__C128__)
                               mouse_drv_use
#else
                               mouse_static_stddrv
#endif
#  endif
                               ));
#endif

#ifndef NO_JAIL
    /* Get the initial bounding box. */
    mouse_getbox (&full_box);
#endif

    screensize (&width, &height);

top:
    clrscr ();

    /* Print a help line */
    cputs (" d)ebug  h)ide   q)uit   s)how   j)ail");

    gotoxy (1, 20);
    cprintf ("SP: $%04X", getsp());

    /* Put a cross at the center of the screen. */
    gotoxy (width / 2 - 3, height / 2 - 1);
#if defined(__CBM__)
    cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
             width / 2, "");
#else
    cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
             width / 2, "");
#endif

    /* Test loop */
    ShowState (Jailed, Invisible);
    do {
        /* Get the current co-ordinates and button states; and, print them. */
        mouse_info (&info);
        gotoxy (0, 2);
        cprintf (" X  = %3d\r\n", info.pos.x);
        cprintf (" Y  = %3d\r\n", info.pos.y);
        cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
#ifdef __CBM__
                 0x5F
#else
                 'v'
#endif
                 : '^');
        cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
#ifdef __CBM__
                 0x5F
#else
                 'v'
#endif
                 : '^');

        /* Handle user input */
        if (kbhit ()) {
            cclearxy (1, 9, 23);
            switch (tolower (C = cgetc ())) {
#ifndef NO_DEBUG
                case 'd':
                    BREAK();

                    /* The debugger might have changed the colors.
                    ** Restore them.
                    */
#ifdef __CBM__
                    (void) bordercolor (COLOR_GRAY2);
                    (void) bgcolor (COLOR_WHITE);
                    (void) textcolor (COLOR_GRAY1);
#else
                    (void) bordercolor (COLOR_BLUE);
                    (void) bgcolor (COLOR_WHITE);
                    (void) textcolor (COLOR_BLACK);
#endif

                    /* The debugger changed the screen; restore it. */
                    goto top;
#endif
                case 'h':
                    mouse_hide ();
                    ShowState (Jailed, ++Invisible);
                    break;

#ifndef NO_JAIL
                case 'j':
                    if (Jailed) {
                        mouse_setbox (&full_box);
                        Jailed = false;
                    } else {
                        small_box.minx = max (info.pos.x - 10, full_box.minx);
                        small_box.miny = max (info.pos.y - 10, full_box.miny);
                        small_box.maxx = min (info.pos.x + 10, full_box.maxx);
                        small_box.maxy = min (info.pos.y + 10, full_box.maxy);
                        mouse_setbox (&small_box);
                        Jailed = true;
                    }
                    ShowState (Jailed, Invisible);
                    break;
#endif
                case 's':
                    mouse_show ();
                    if (Invisible) {
                        ShowState (Jailed, --Invisible);
                    }
                    break;

                case 'q':
                    Done = true;
                    break;

                default:
                    gotoxy (1, 9);
                    cprintf ("Spurious character: $%02X", C);
            }
        }
    } while (!Done);

#if DYN_DRV
    /* Uninstall and unload the driver. */
    CheckError ("mouse_unload", mouse_unload ());
#else
    /* Uninstall the static driver. */
    CheckError ("mouse_uninstall", mouse_uninstall ());
#endif

    /* Say goodbye */
    cputsxy (0, height / 2 + 3, "Goodbye!");
    return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
//--------------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{    
    m_hInstance = (HINSTANCE)GetModuleHandle(NULL);

    if (argc >= 3)
    {
        m_lpFontPath = argv[2];
        m_lpFontName = argv[1];
        printf(__FUNCTION__"(): Using external font %ws \"%ws\"\n", m_lpFontName, m_lpFontPath);
    }
    else
    {
        printf("USAGE: MsFontsFuzz.exe <font_name> <font_file> [options]\n");
        goto end;
    }    

    _stprintf_s(m_TmpFontPath, _T("__TMP__%s"), _tGetNameFromFullPath(m_lpFontPath));
    DbgMsg(__FILE__, __LINE__, "[+] Temporary font file is \"%ws\"\n", m_TmpFontPath);

    if (_tcslen(m_TmpFontPath) >= 4)
    {
        _tcslwr(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4);
        if (!_tcscmp(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4, _T(".otf")))
        {
            m_dwFontType = FONT_TYPE_OTF;
            DbgMsg(__FILE__, __LINE__, "[+] Font type is .OTF\n");
        }
        else if (!_tcscmp(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4, _T(".ttf")))
        {
            m_dwFontType = FONT_TYPE_TTF;
            DbgMsg(__FILE__, __LINE__, "[+] Font type is .TTF\n");
        }
    }    

    RemoveFontResource(m_TmpFontPath);

#ifdef USE_BOADCAST_MESSAGES

    SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

#endif

    char ch = 0;
    memset(m_szTable, '.', sizeof(m_szTable) - 1);
    
    for (int i = 0; i < sizeof(m_szTable); i++)
    {
        if (i != 0 && i % 16 == 0)
        {
            m_szTable[i] = '\n';
            continue;
        }

        if (ch >= 0x20)
        {
            m_szTable[i] = ch;
        }

        if (ch == 0x7f)
        {
            m_szTable[i] = 0;
            break;
        }

        ch += 1;
    }

    if (argc > 3)
    {
        // enumerate additional parameters
        for (int i = 3; i < argc; i++)
        {
            if (!_tcscmp(argv[i], _T("--test")))
            {
                // single launch mode
                m_bTest = TRUE;
            }
            else if (!_tcscmp(argv[i], _T("--resume")))
            {
                // resume fuzzing in the new process
                m_bResume = TRUE;
            }
            else if (!_tcscmp(argv[i], _T("--noisy")))
            {
                // show lot of output information
                m_bNoisy = TRUE;
            }
            else if (!_tcscmp(argv[i], _T("--text")) && argc - i > 1)
            {
#ifdef UNICODE
                // use caller-specified text for display
                WideCharToMultiByte(
                    CP_ACP, 0, 
                    argv[i + 1], 
                    -1, 
                    m_szTable,
                    sizeof(m_szTable) - 1, 
                    NULL, NULL
                );
#else
                strcpy_s(m_szTable, argv[i + 1]);
#endif
                i++;
            }
            else if (!_tcscmp(argv[i], _T("--fix-crcs")))
            {
                // fix incorrect checksums for the original font file
                m_bFixCrcs = TRUE;
            }
            else if (argc - i > 1 && argv[i][0] == '-')
            {
                /**
                 * Process data generation options.
                 */

                LPCTSTR lpParam = argv[i] + 1;
                DWORD dwValue = 0;
                BOOL bFound = FALSE;

                if (!StrToIntEx(argv[i + 1], STIF_SUPPORT_HEX, (int *)&dwValue))
                {
                    DbgMsg(__FILE__, __LINE__, "[!] ERROR: Invalid value for parameter \"%ws\"\n", argv[i]);
                    continue;
                }

                for (int i_n = 0; i_n < sizeof(m_Params) / sizeof(ENGINE_PARAM); i_n++)
                {
                    // search parameter by name
                    if (!_tcscmp(m_Params[i_n].lpName, lpParam))
                    {
                        *(m_Params[i_n].pdwValue) = dwValue;
                        bFound = TRUE;
                        break;
                    }
                }

                if (!bFound)
                {
                    DbgMsg(__FILE__, __LINE__, "[!] ERROR: Unknown parameter \"%ws\"\n", argv[i]);
                }

                i++;
            }            
        }
    }

    DbgInit(LOG_FILE_NAME);

    // check block size and range
    if (BLOCK_SIZE == 1)
    {
        if (BLOCK_RANGE_START >= 0xFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFF)\n");
            goto end;
        }

        if (BLOCK_RANGE_END > 0xFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFF)\n");
            goto end;
        }
    }
    else if (BLOCK_SIZE == 2)
    {
        if (BLOCK_RANGE_START >= 0xFFFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFFFF)\n");
            goto end;
        }

        if (BLOCK_RANGE_END > 0xFFFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFFFF)\n");
            goto end;
        }
    }
    else if (BLOCK_SIZE == 4)
    {
        if (BLOCK_RANGE_START >= 0xFFFFFFFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFFFFFFFF)\n");
            goto end;
        }

        if (BLOCK_RANGE_END > 0xFFFFFFFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFFFFFFFF)\n");
            goto end;
        }
    }
    else
    {
        DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_SIZE value (it must be 1, 2 or 4)\n");
        goto end;
    }

    // check step size
    if (BLOCK_RANGE_N > BLOCK_RANGE_END)
    {
        DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_N value (it must be <=BLOCK_RANGE_END)\n");
        goto end;
    }

    WNDCLASSEX wcex;
    ZeroMemory(&wcex, sizeof(wcex));
    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.hInstance = m_hInstance;    
    wcex.lpszClassName = _T(WND_CLASS);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

    m_hWndEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (m_hWndEvent == NULL)
    {
        DbgMsg(__FILE__, __LINE__, "CreateEvent() ERROR %d\n", GetLastError());
        goto end;
    }

    // register window class
    if (RegisterClassEx(&wcex) == NULL)
    {
        DbgMsg(__FILE__, __LINE__, "RegisterClassEx() ERROR %d\n", GetLastError());
        goto end;
    }    
    
    // init random number generator
    init_genrand(GetTickCount());

    SetUnhandledExceptionFilter(UnhandledExceptionError);
        
    // read input file
    if (ReadFromFile(m_lpFontPath, &m_pData, &m_dwDataSize))
    {
        if (FILE_RANGE_START >= m_dwDataSize)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_START value (it must be <=FILE_SIZE)\n");
            M_FREE(m_pData);
            return -1;
        }

        if (FILE_RANGE_END > m_dwDataSize)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_END value (it must be <FILE_SIZE)\n");
            M_FREE(m_pData);
            return -1;
        }        

        if (FILE_RANGE_END == 0)
        {
            FILE_RANGE_END = m_dwDataSize;
        }

        if (FILE_RANGE_START >= FILE_RANGE_END)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_START/FILE_RANGE_END values\n");
            M_FREE(m_pData);
            return -1;
        }

        DbgMsg(__FILE__, __LINE__, "[+] %d bytes readed from \"%ws\"\n", m_dwDataSize, m_lpFontPath);

        if (!m_bResume && (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF))
        {
            OTF_TableByOffset(m_pData, (ULONG)-1);
        }

        if (m_bFixCrcs)
        {
            // write fixed checksums into the original file
            if (DumpToFile(m_lpFontPath, m_pData, m_dwDataSize))
            {
                DbgMsg(__FILE__, __LINE__, "[+] Checksums has been fixed for font file \"%ws\"\n", m_lpFontPath);
            }
        }
        else if (m_bTest)
        {
            // single run with the unchanged font file
            if (DumpToFile(m_TmpFontPath, m_pData, m_dwDataSize))
            {
                FuzzIteration();
            }
        }
        else
        {
            DbgMsg(__FILE__, __LINE__, "[+] Fuzzing params:\n\n");

            // print parameters values
            for (int i_n = 0; i_n < sizeof(m_Params) / sizeof(ENGINE_PARAM); i_n++)
            {            
                DbgMsg(__FILE__, __LINE__, " %20ws = 0x%.8x\n", m_Params[i_n].lpName, *(m_Params[i_n].pdwValue));
            }

            DbgMsg(__FILE__, __LINE__, "\n");
            DbgMsg(__FILE__, __LINE__, "[+] Processing cases...\n\n");

            // align buffer size by block size
            m_dwAlignedDataSize = XALIGN_UP(m_dwDataSize, BLOCK_SIZE);

            // allocate output buffer
            if (m_pAlignedData = M_ALLOC(m_dwAlignedDataSize))
            {         
                char *lpszBigBuff = (char *)M_ALLOC(BIG_BUFFER_LENGTH);
                if (lpszBigBuff)
                {
                    FillMemory(lpszBigBuff, BIG_BUFFER_LENGTH, 'A');
                }

                PVOID pBigData = M_ALLOC(m_dwDataSize + BIG_BUFFER_LENGTH);
                
                // for each byte/word/dword of input file...
                for (DWORD i = FILE_RANGE_START; i < FILE_RANGE_END; i += BLOCK_SIZE)
                {                
                    DbgMsg(__FILE__, __LINE__, "Offset=0x%.8x TotalSize=0x%.8x File=%.8x\n", i, m_dwDataSize, m_dwCasesProcessed);

                    POTF_TABLE_HEADER Table = NULL;
                    if (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF)
                    {
                        Table = OTF_TableByOffset(m_pData, i);
                        if (Table == NULL)
                        {
                            // skip OTF/TTF data outside the tables
                            continue;
                        }
                    }                    

                    if (BLOCK_RANGE_N > 0)
                    {
                        // fuze each value with the step size == BLOCK_RANGE_N
                        for (DWORD n = XALIGN_DOWN(BLOCK_RANGE_START, BLOCK_RANGE_N); 
                             n < XALIGN_DOWN(BLOCK_RANGE_END, BLOCK_RANGE_N); 
                             n += BLOCK_RANGE_N)
                        {                            
                            // write plain value
                            WriteVal(i, BLOCK_SIZE, n, n, n);                

                            if (BLOCK_SIZE > 1)
                            {
                                // write randomized value
                                WriteVal(i, BLOCK_SIZE, 
                                    n, 
                                    n + getrand(0, BLOCK_RANGE_N - 1), 
                                    n + getrand(0, BLOCK_RANGE_N - 1)
                                );                                    
                            }                    
                        }
                    }

                    // zero-bytes stuff
                    WriteVal(i, BLOCK_SIZE, 0x00, 0x0000, 0x00000000);                

                    // integer overflow stuff
                    WriteVal(i, BLOCK_SIZE, 0xFF, 0xFFFF, 0xFFFFFFFF);

                    // invalid user-mode pointers
                    WriteVal(i, BLOCK_SIZE, 0x0D, 0x0D0D, 0x0D0D0D0D);

                    if (lpszBigBuff && pBigData)
                    {
                        /**
                         * Write big ASCI data after the each byte.
                         */

                        memcpy(pBigData, m_pData, i);
                        memcpy((PUCHAR)pBigData + i, lpszBigBuff, BIG_BUFFER_LENGTH);
                        memcpy((PUCHAR)pBigData + i + BIG_BUFFER_LENGTH, (PUCHAR)m_pData + i, m_dwDataSize - i);

                        if (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF)
                        {
                            POTF_FILE_HEADER Hdr = (POTF_FILE_HEADER)pBigData;
                            POTF_TABLE_HEADER Table = (POTF_TABLE_HEADER)((PUCHAR)pBigData + sizeof(OTF_FILE_HEADER));
                            POTF_TABLE_HEADER CurrentTable = NULL;

                            for (USHORT t = 0; t < htons(Hdr->numTables); t++)
                            {
                                ULONG Offset = htonl(Table->offset), Length = htonl(Table->length);

                                if (i >= Offset &&
                                    i < Offset + Length)
                                {
                                    // fix OTF/TTF table checksum and length
                                    ULONG Sum = OTF_CalcTableChecksum((ULONG *)((PUCHAR)pBigData + Offset), Length);
                                    
                                    Table->checkSum = htonl(Sum);
                                    Table->length = htonl(Length);
                                    CurrentTable = Table;

                                    break;
                                }

                                Table += 1;
                            }

                            if (CurrentTable)
                            {
                                Table = (POTF_TABLE_HEADER)((PUCHAR)pBigData + sizeof(OTF_FILE_HEADER));

                                for (USHORT t = 0; t < htons(Hdr->numTables); t++)
                                {
                                    ULONG Offset = htonl(Table->offset), Length = htonl(Table->length);

                                    if (Offset > htonl(CurrentTable->offset))
                                    {
                                        // fix offsets of the other tables
                                        Table->offset = htonl(Offset + BIG_BUFFER_LENGTH);
                                    }

                                    Table += 1;
                                }
                            }
                        }

                        if (DumpToFile(m_TmpFontPath, pBigData, m_dwDataSize + BIG_BUFFER_LENGTH))
                        {
                            FuzzIteration();
                            m_dwCasesProcessed++;
                        }
                    }

                    if (m_dwCasesProcessed > MAX_CASES_PER_PROCESS)
                    {
                        TCHAR szSelf[MAX_PATH], szCmdLine[MAX_PATH];
                        GetModuleFileName(GetModuleHandle(NULL), szSelf, MAX_PATH);

                        _stprintf_s(
                            szCmdLine, MAX_PATH, 
                            _T("\"%s\" \"%s\" \"%s\" -BLOCK_SIZE 0x%x -BLOCK_RANGE_START 0x%x -BLOCK_RANGE_END 0x%x -BLOCK_RANGE_N 0x%x -FILE_RANGE_START 0x%x --resume Y"),
                            szSelf, m_lpFontName, m_lpFontPath, BLOCK_SIZE, BLOCK_RANGE_START, BLOCK_RANGE_END, BLOCK_RANGE_N, i
                        );

                        if (m_bNoisy)
                        {
                            _tcscat(szCmdLine, _T(" --noisy Y"));
                        }

                        STARTUPINFO si;
                        PROCESS_INFORMATION pi;

                        ZeroMemory(&pi, sizeof(pi));
                        ZeroMemory(&si, sizeof(si));
                        si.cb = sizeof(si);                            

                        // create a new fuzzer instance
                        if (!CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
                        {
                            MessageBox(0, _T("CreateProcess() fails"), _T("ERROR"), MB_ICONERROR);
                        }

                        ExitProcess(0);
                    }
                }

                DbgMsg(__FILE__, __LINE__, "Done; %d cases processed\n", m_dwCasesProcessed);

                if (pBigData)
                {
                    M_FREE(pBigData);
                }

                if (lpszBigBuff)
                {
                    M_FREE(lpszBigBuff);
                }

                M_FREE(m_pAlignedData);
            }
        }        

        M_FREE(m_pData);        
    }
    else
    {
        DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Error while reading input file\n");
    }

end:

    if (m_hWndEvent)
    {
        CloseHandle(m_hWndEvent);
    }

    printf("Press any key to quit...\n");
    _getch();

	return 0;
}
Ejemplo n.º 6
0
bool
cOpenHpiDaemon::Initialize()
{
  if ( m_daemon )
     {
       DbgInit( "become a daemon.\n" );

       pid_t pid = fork();

       if ( pid < 0 )
	  {
	    fprintf( stderr, "cannot fork: %s !\n",
		     strerror( errno ) );
	    return false;
	  }

       // parent process
       if ( pid != 0 )
	    exit( 0 );

       // become the session leader
       setsid();

       // second fork to become a real daemon
       pid = fork();

       if ( pid < 0 )
	  {
	    fprintf( stderr, "cannot fork: %s !\n",
		     strerror( errno ) );
	    return false;
	  }

       // parent process
       if ( pid != 0 )
	    exit( 0 );

       chdir( "/" );

       umask( 0 );
     }

  // use config file given by the command line
  if ( m_config )
       setenv( "OPENHPI_CONF", m_config, 1 );

  // initialize openhpi
  DbgInit( "initialize openhpi.\n" );
  SaErrorT rv = saHpiInitialize( &m_version );

  if ( rv != SA_OK )
     {
       fprintf( stderr, "cannot initialize openhpi: %s !\n",
		decode_error( rv ) );
       return false;
     }

  // create a session
  rv = saHpiSessionOpen( SAHPI_DEFAULT_DOMAIN_ID, &m_session, 0 );

  if ( rv != SA_OK )
     {
       fprintf( stderr, "cannot create session: %s !\n", 
		decode_error( rv ) );

       saHpiFinalize();
       return false;
     }

  // subscribe
  rv = saHpiSubscribe( m_session, SAHPI_TRUE );

  if ( rv != SA_OK )
     {
       fprintf( stderr, "cannot subscribe: %s !\n", 
		decode_error( rv ) );

       saHpiSessionClose( m_session );
       saHpiFinalize();
       return false;
     }

  // open daemon socket
  DbgInit( "create daemon connection port %d.\n", m_daemon_port );

  m_main_socket = ServerConnectionMainOpen( m_daemon_port );

  if ( !m_main_socket )
     {
       fprintf( stderr, "cannot create daemon socket: %d, %s !\n",
                errno, strerror( errno ) );

       saHpiUnsubscribe( m_session );
       saHpiSessionClose( m_session );
       saHpiFinalize();
       return false;
     }

  if ( m_interactive )
       DbgInit( "interactive\n" );

  DbgInit( "daemon is up.\n" );

  return true;
}
Ejemplo n.º 7
0
int main (void)
#endif
{
    struct mouse_info info;
    struct mouse_box full_box, small_box;
    unsigned char width, height;
    char C;
    bool Invisible = true, Done = false, Jailed = false;

    /* Initialize the debugger */
    DbgInit (0);

    /* Set dark-on-light colors.  Clear the screen. */
#ifdef __CBM__
    (void) bordercolor (COLOR_GRAY2);
    (void) bgcolor (COLOR_WHITE);
    (void) textcolor (COLOR_GRAY1);
#else
    (void) bordercolor (COLOR_BLUE);
    (void) bgcolor (COLOR_WHITE);
    (void) textcolor (COLOR_BLACK);
#endif
    cursor (0);
    clrscr ();

    /* If a lightpen driver is installed, then it can get a calibration value
    ** from this file (if it exists).  Or, the user can adjust the pen; and,
    ** the value will be put into this file, for the next time.
    ** (Other drivers will ignore this.)
    */
#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
    pen_adjust ("pen.dat");
#endif

#if DYN_DRV
    /* If a dynamically loadable driver is named on the command line,
    ** then use that driver instead of the standard one.
    */
    if (argc > 1) {
        mouse_name = argv[1];
    } else {
        /* Output a warning about the standard driver that is needed. */
        DoWarning ();
        mouse_name = mouse_stddrv;
    }

    /* Load and install the driver. */
    CheckError ("mouse_load_driver",
                mouse_load_driver (&mouse_def_callbacks, mouse_name));
#else
    /* Install the driver. */
    CheckError ("mouse_install",
                mouse_install (&mouse_def_callbacks,
#  ifdef MOUSE_DRIVER
                               MOUSE_DRIVER
#  else
                               mouse_static_stddrv
#  endif
                               ));
#endif

    /* Get the initial bounding box. */
    mouse_getbox (&full_box);

    screensize (&width, &height);

top:
    clrscr ();

    /* Print a help line */
    cputs (" d)ebug  h)ide   q)uit   s)how   j)ail");

    /* Put a cross at the center of the screen. */
    gotoxy (width / 2 - 3, height / 2 - 1);
#if defined(__CBM__)
    cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
             width / 2, "");
#else
    cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
             width / 2, "");
#endif

    /* Test loop */
    ShowState (Jailed, Invisible);
    do {
        /* Get the current co-ordinates and button states; and, print them. */
        mouse_info (&info);
        gotoxy (0, 2);
        cprintf (" X  = %3d\r\n", info.pos.x);
        cprintf (" Y  = %3d\r\n", info.pos.y);
        cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
#ifdef __CBM__
                 0x5F
#else
                 'v'
#endif
                 : '^');
        cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
#ifdef __CBM__
                 0x5F
#else
                 'v'
#endif
                 : '^');

        /* Handle user input */
        if (kbhit ()) {
            cclearxy (1, 9, 23);
            switch (tolower (C = cgetc ())) {
                case 'd':
                    BREAK();

                    /* The debugger might have changed the colors.
                    ** Restore them.
                    */
#ifdef __CBM__
                    (void) bordercolor (COLOR_GRAY2);
                    (void) bgcolor (COLOR_WHITE);
                    (void) textcolor (COLOR_GRAY1);
#else
                    (void) bordercolor (COLOR_BLUE);
                    (void) bgcolor (COLOR_WHITE);
                    (void) textcolor (COLOR_BLACK);
#endif

                    /* The debugger changed the screen; restore it. */
                    goto top;

                case 'h':
                    mouse_hide ();
                    ShowState (Jailed, ++Invisible);
                    break;

                case 'j':
                    if (Jailed) {
                        mouse_setbox (&full_box);
                        Jailed = false;
                    } else {
                        small_box.minx = max (info.pos.x - 10, full_box.minx);
                        small_box.miny = max (info.pos.y - 10, full_box.miny);
                        small_box.maxx = min (info.pos.x + 10, full_box.maxx);
                        small_box.maxy = min (info.pos.y + 10, full_box.maxy);
                        mouse_setbox (&small_box);
                        Jailed = true;
                    }
                    ShowState (Jailed, Invisible);
                    break;

                case 's':
                    mouse_show ();
                    if (Invisible) {
                        ShowState (Jailed, --Invisible);
                    }
                    break;

                case 'q':
                    Done = true;
                    break;

                default:
                    gotoxy (1, 9);
                    cprintf ("Spurious character: $%02X", C);
            }
        }
    } while (!Done);

#if DYN_DRV
    /* Uninstall and unload the driver. */
    CheckError ("mouse_unload", mouse_unload ());
#else
    /* Uninstall the static driver. */
    CheckError ("mouse_uninstall", mouse_uninstall ());
#endif

    /* Say goodbye */
    cputsxy (0, height / 2 + 3, "Goodbye!");
    return EXIT_SUCCESS;
}
Ejemplo n.º 8
0
int main(int argc, char* argv[])
{
    qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
    MyApplication application(argc, argv);
    QFile f(QString("%1/style.css").arg(QCoreApplication::applicationDirPath()));
    if(f.open(QFile::ReadOnly | QFile::Text))
    {
        QTextStream in(&f);
        auto style = in.readAll();
        f.close();
        application.setStyleSheet(style);
    }
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    QAbstractEventDispatcher::instance(application.thread())->setEventFilter(MyApplication::globalEventFilter);
#else
    auto eventFilter = new MyEventFilter();
    application.installNativeEventFilter(eventFilter);
#endif

    // Get the hidden language setting (for testers)
    if(!BridgeSettingGet("Engine", "Language", currentLocale) || !isValidLocale(currentLocale))
    {
        QStringList uiLanguages = QLocale::system().uiLanguages();
        QString sysLocale = uiLanguages.size() ? QLocale(uiLanguages[0]).name() : QLocale::system().name();
        strcpy_s(currentLocale, sysLocale.toUtf8().constData());
        BridgeSettingSet("Engine", "Language", currentLocale);
    }

    // Load translations for Qt
    QTranslator qtTranslator;
    if(qtTranslator.load(QString("qt_%1").arg(currentLocale), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
        application.installTranslator(&qtTranslator);

    //x64dbg and x32dbg can share the same translation
    QTranslator x64dbgTranslator;
    auto path = QString("%1/../translations").arg(QCoreApplication::applicationDirPath());
    if(x64dbgTranslator.load(QString("x64dbg_%1").arg(currentLocale), path))
        application.installTranslator(&x64dbgTranslator);

    TLS_TranslatedStringMap = new std::map<DWORD, TranslatedStringStorage>();

    // initialize capstone
    Capstone::GlobalInitialize();

    // load config file + set config font
    mConfiguration = new Configuration;
    application.setFont(ConfigFont("Application"));

    // Register custom data types
    qRegisterMetaType<dsint>("dsint");
    qRegisterMetaType<duint>("duint");
    qRegisterMetaType<byte_t>("byte_t");
    qRegisterMetaType<DBGSTATE>("DBGSTATE");

    // Set QString codec to UTF-8
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
#endif

    // Init communication with debugger
    Bridge::initBridge();

    // Start GUI
    MainWindow* mainWindow;
    mainWindow = new MainWindow();
    mainWindow->show();

    // Set some data
    Bridge::getBridge()->winId = (void*)mainWindow->winId();

    // Init debugger
    const char* errormsg = DbgInit();
    if(errormsg)
    {
        QMessageBox msg(QMessageBox::Critical, QObject::tr("DbgInit Error!"), QString(errormsg));
        msg.setWindowIcon(DIcon("compile-error.png"));
        msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
        msg.exec();
        exit(1);
    }

    //execute the application
    int result = application.exec();
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    application.removeNativeEventFilter(eventFilter);
#else
    QAbstractEventDispatcher::instance(application.thread())->setEventFilter(nullptr);
#endif
    delete mainWindow;
    mConfiguration->save(); //save config on exit
    {
        //delete tls
        auto temp = TLS_TranslatedStringMap;
        TLS_TranslatedStringMap = nullptr;
        delete temp;
    }

    //TODO free capstone/config/bridge and prevent use after free.

    return result;
}