Exemplo n.º 1
0
static GLboolean
expand_defined (expand_state *e, slang_string *buffer)
{
   GLboolean in_paren = GL_FALSE;
   const char *id;

   /* Parse the optional opening parenthesis. */
   SKIP_WHITE(e->input);
   if (*e->input == '(') {
      e->input++;
      in_paren = GL_TRUE;
      SKIP_WHITE(e->input);
   }

   /* Parse operand. */
   if (!IS_FIRST_ID_CHAR(*e->input)) {
      slang_info_log_error (e->state->elog,
                            "preprocess error: identifier expected after operator 'defined'.");
      return GL_FALSE;
   }
   slang_string_reset (buffer);
   slang_string_pushc (buffer, *e->input++);
   while (IS_NEXT_ID_CHAR(*e->input))
      slang_string_pushc (buffer, *e->input++);
   id = slang_string_cstr (buffer);

   /* Check if the operand is defined. Output 1 if it is defined, output 0 if not. */
   if (pp_symbols_find (&e->state->symbols, id) == NULL)
      slang_string_pushs (e->output, " 0 ", 3);
   else
      slang_string_pushs (e->output, " 1 ", 3);

   /* Parse the closing parentehesis if the opening one was there. */
   if (in_paren) {
      SKIP_WHITE(e->input);
      if (*e->input != ')') {
         slang_info_log_error (e->state->elog, "preprocess error: ')' expected.");
         return GL_FALSE;
      }
      e->input++;
      SKIP_WHITE(e->input);
   }
   return GL_TRUE;
}
Exemplo n.º 2
0
BOOL
CmdListNear(
    LPSTR             CmdBuf,
    HANDLE            hProcess,
    HANDLE            hThread,
    PEXCEPTION_RECORD ExceptionRecord
    )
{
    SKIP_NONWHITE( CmdBuf );
    SKIP_WHITE( CmdBuf );

    ULONG Address;
    GetAddress( CmdBuf, &Address );
    if (Address) {
        ULONG Displacement;
        if (SymGetSymFromAddr( hProcess, Address, &Displacement, sym )) {
            printf( "0x%08x %s\n", sym->Address, sym->Name );
        }
    }
    return TRUE;
}
Exemplo n.º 3
0
BOOL
CmdDisplayCode(
    LPSTR             CmdBuf,
    HANDLE            hProcess,
    HANDLE            hThread,
    PEXCEPTION_RECORD ExceptionRecord
    )
{
    static ULONG Address = 0;
    ULONG   ThisAddress;
    CHAR    DisBuf[512];
    ULONG   i;


    //
    // skip any command modifiers & white space that may follow
    //
    SKIP_NONWHITE( CmdBuf );
    SKIP_WHITE( CmdBuf );

    GetAddress( CmdBuf, &ThisAddress );
    if (ThisAddress) {
        Address = ThisAddress;
    }

    printf( "\n" );

    for (i=0; i<20; i++) {
        if (!disasm( hProcess, &Address, DisBuf, TRUE )) {
            break;
        }
        printf( "%s\n", DisBuf );
    }

    printf( "\n" );

    return TRUE;
}
Exemplo n.º 4
0
static time_t ascdatetotime(char *string, bool heavy)
{
	bool utc = FALSE;
	
	static char *months[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
							"Aug", "Sep", "Oct", "Nov", "Dec", "---", "---", "---"};

	static unsigned msize[] ={ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	struct tm tm, *tm2;

	time_t lsec;
	char am_pm, flg24;
	char *ptr = string;

	char *day="", *month="", *year="";
	char *hour="",*minute="",*second="";

	/* check - does it start with 'UTC'? */
	if ((!strncmp(ptr,"UTC",3))||(!strncmp(ptr,"utc",3))) {
		utc = TRUE;
		ptr+=3;
	}

	/* change default from 0:0:0 to 59:59:59 if heavy */
	if (heavy) {
		hour = "23";
		minute = second = "59";
	} else {
		hour = minute = second = "0";
	}

	/* "dd/mm/yy hh:mm:ss" */

	do
	{
		SKIP_WHITE(ptr);
		day = ptr;    
	
		SKIP_TO_SLASH(ptr);	
		BREAK_ON_END(ptr);
		month = ptr;
	
		SKIP_TO_SLASH(ptr);
		BREAK_ON_END(ptr);
		year = ptr;
	
		SKIP_TO_WHITE(ptr);
		BREAK_ON_END(ptr);
	
		SKIP_WHITE(ptr);
		minute = second = NULL;
	
		hour = ptr;	
	
		SKIP_TO_COLON(ptr);	
		BREAK_ON_END(ptr);
		minute = ptr;
	
		SKIP_TO_COLON(ptr);
		BREAK_ON_END(ptr);
		second = ptr;
		SKIP_TO_WHITE(ptr);
		BREAK_ON_END(ptr);

		break;	
	} while (FALSE);

	#ifdef TDIAG
		fprintf(stderr,"day = '%s'\n",day);
		fprintf(stderr,"month = '%s'\n",month);
		fprintf(stderr,"year = '%s'\n",year);
		fprintf(stderr,"hour = '%s'\n",hour);
		fprintf(stderr,"minute = '%s'\n",minute);
		fprintf(stderr,"second = '%s'\n",second);
	#endif

	if (!utc) {
		/* learn whether we are in daylight savings time or not */
		lsec = time(NULL);
		tm2 = localtime(&lsec);
		tm.tm_isdst = tm2->tm_isdst;
	} else tm.tm_isdst = 0;
	
	tm.tm_min = 0;
	am_pm = 0;
	flg24 = 1;

	tm.tm_sec = ctod(second);
	if(tm.tm_sec > 59)
		terminate("Time - Invalid second\n");

	tm.tm_min = ctod(minute);
	if(tm.tm_min > 59)
		terminate("Time - Invalid minute\n");

	tm.tm_hour = ctod(hour);
	if(tm.tm_hour > 23)
		terminate("Time - Invalid hour\n");

	if(am_pm  &&  !flg24  &&  tm.tm_hour < 12)
		tm.tm_hour += 12;

	if(tm.tm_hour > 11)
		am_pm = 1;

	tm.tm_year = ctod(year);
	if (tm.tm_year>=0 && tm.tm_year<=38) tm.tm_year+=2000;	// 00-38 is 2000-2038
	if(tm.tm_year >= 1970) 		tm.tm_year -= 1900;
	if(tm.tm_year < 70 ||  tm.tm_year > 155)
		terminate("Date - Invalid year\n");

	if(month[0] >= '0'  &&  month[0] <= '9')
	{
			tm.tm_mon = ctod(month) - 1;
	}
	else
	{
		for(tm.tm_mon = 0; tm.tm_mon < 12; ++tm.tm_mon)
			if(comp(months[tm.tm_mon + 1], month)) break;
	}

	if(tm.tm_mon > 11)
		terminate("Date - Invalid month\n");

	if(tm.tm_mon == 1  &&  (tm.tm_year % 4) == 2)
		msize[2] = 29; /* leap years allow feb 29 */

	tm.tm_mday = ctod(day);
	if(tm.tm_mday > msize[tm.tm_mon + 1]  ||  tm.tm_mday == 0)
		terminate("Date - Invalid day\n");

	lsec = mktime(&tm);

	if (utc) 
#if defined(__CYGWIN32__) || defined(__MINGW32__)
		lsec = lsec - _timezone;
#else
		lsec = lsec - timezone;
#endif

	#ifdef TDIAG
		fprintf(stderr,"lsec = %ld\n",lsec);
	#endif

	return(lsec);
}
Exemplo n.º 5
0
static GLboolean
expand_symbol (expand_state *e, pp_symbol *symbol)
{
   expand_state es;

   /* If the macro has some parameters, we need to parse them. */
   if (symbol->parameters.count != 0) {
      GLuint i;

      /* Parse the opening parenthesis. */
      SKIP_WHITE(e->input);
      if (*e->input != '(') {
         slang_info_log_error (e->state->elog, "preprocess error: '(' expected.");
         return GL_FALSE;
      }
      e->input++;
      SKIP_WHITE(e->input);

      /* Parse macro actual parameters. This can be anything, separated by a colon.
       */
      for (i = 0; i < symbol->parameters.count; i++) {
         GLuint nested_paren_count = 0; /* track number of nested parentheses */

         if (*e->input == ')') {
            slang_info_log_error (e->state->elog, "preprocess error: unexpected ')'.");
            return GL_FALSE;
         }

         /* Eat all characters up to the comma or closing parentheses. */
         pp_symbol_reset (&symbol->parameters.symbols[i]);
         while (!IS_NULL(*e->input)) {
            /* Exit loop only when all nested parens have been eaten. */
            if (nested_paren_count == 0 && (*e->input == ',' || *e->input == ')'))
               break;

            /* Actually count nested parens here. */
            if (*e->input == '(')
               nested_paren_count++;
            else if (*e->input == ')')
               nested_paren_count--;

            slang_string_pushc (&symbol->parameters.symbols[i].replacement, *e->input++);
         }

         /* If it was not the last paremeter, skip the comma. Otherwise, skip the
          * closing parentheses. */
         if (i + 1 == symbol->parameters.count) {
            /* This is the last paremeter - skip the closing parentheses. */
            if (*e->input != ')') {
               slang_info_log_error (e->state->elog, "preprocess error: ')' expected.");
               return GL_FALSE;
            }
            e->input++;
            SKIP_WHITE(e->input);
         }
         else {
            /* Skip the separating comma. */
            if (*e->input != ',') {
               slang_info_log_error (e->state->elog, "preprocess error: ',' expected.");
               return GL_FALSE;
            }
            e->input++;
            SKIP_WHITE(e->input);
         }
      }
   }

   /* Expand the macro. Use its parameters as a priority symbol list to expand
    * macro parameters correctly. */
   es.output = e->output;
   es.input = slang_string_cstr (&symbol->replacement);
   es.state = e->state;
   slang_string_pushc (e->output, ' ');
   if (!expand (&es, &symbol->parameters))
      return GL_FALSE;
   slang_string_pushc (e->output, ' ');
   return GL_TRUE;
}
Exemplo n.º 6
0
BOOL
CmdBreakPoint(
    LPSTR             CmdBuf,
    HANDLE            hProcess,
    HANDLE            hThread,
    PEXCEPTION_RECORD ExceptionRecord
    )
{
    CHAR BpCmd = tolower(CmdBuf[1]);
    ULONG Address = 0;
    PBREAKPOINT_INFO bp;
    PPROCESS_INFO ThisProcess;
    ULONG Flags;
    LPSTR p;
    LPSTR SymName;
    ULONG i;
    IMAGEHLP_MODULE mi;


    ThisProcess = GetProcessInfo( hProcess );
    if (!ThisProcess) {
        printf( "could not get process information\n" );
        return FALSE;
    }

    PTHREAD_INFO ThisThread = GetThreadInfo( hProcess, hThread );
    if (!ThisThread) {
        printf( "could not get thread information\n" );
        return FALSE;
    }

    SKIP_NONWHITE( CmdBuf );
    SKIP_WHITE( CmdBuf );
    p = CmdBuf;

    switch ( BpCmd ) {
        case 'p':
            Flags = 0;
            CmdBuf = GetAddress( CmdBuf, &Address );
            SymName = (LPSTR) MemAlloc( CmdBuf - p + 16 );
            if (!SymName) {
                printf( "could not allocate memory for bp command\n" );
                break;
            }
            strncpy( SymName, p, CmdBuf - p );
            if (!Address) {
                Flags = BPF_UNINSTANCIATED;
                printf( "breakpoint not instanciated\n" );
            }
            bp = SetBreakpoint(
                ThisProcess,
                Address,
                Flags,
                SymName,
                UserBpHandler
                );
            MemFree( SymName );
            if (!bp) {
                printf( "could not set breakpoint\n" );
            }
            ThisProcess->UserBpCount += 1;
            bp->Number = ThisProcess->UserBpCount;
            SKIP_WHITE( CmdBuf );
            if (CmdBuf[0]) {
                if (CmdBuf[0] == '/') {
                    switch (tolower(CmdBuf[1])) {
                        case 'c':
                            CmdBuf += 3;
                            if (CmdBuf[0] != '\"') {
                                printf( "invalid syntax\n" );
                                return FALSE;
                            }
                            CmdBuf += 1;
                            p = strchr( CmdBuf, '\"' );
                            if (!p) {
                                printf( "invalid syntax\n" );
                                return FALSE;
                            }
                            p[0] = 0;
                            bp->Command = _strdup( CmdBuf );
                            break;

                        default:
                            break;
                    }
                }
            }
            break;

        case 'l':
            for (i=0; i<MAX_BREAKPOINTS; i++) {
                if (ThisProcess->Breakpoints[i].Number) {
                    ULONG disp = 0;
                    if (ThisProcess->Breakpoints[i].Flags & BPF_WATCH) {
                        printf( "#%d %c%c\t          \tWatch\n",
                            ThisProcess->Breakpoints[i].Number,
                            ThisProcess->Breakpoints[i].Flags & BPF_UNINSTANCIATED ? 'U' : 'I',
                            ThisProcess->Breakpoints[i].Flags & BPF_DISABLED       ? 'D' : 'E'
                            );
                    } else if ((ThisProcess->Breakpoints[i].Address != 0) &&
                        (ThisProcess->Breakpoints[i].Address != 0xffffffff)) {
                        SymGetModuleInfo(
                            ThisProcess->hProcess,
                            ThisProcess->Breakpoints[i].Address,
                            &mi
                            );
                        if (SymGetSymFromAddr(
                            ThisProcess->hProcess,
                            ThisProcess->Breakpoints[i].Address,
                            &disp,
                            sym
                            )) {
                                printf( "#%d %c%c\t0x%08x\t%s!%s\n",
                                    ThisProcess->Breakpoints[i].Number,
                                    ThisProcess->Breakpoints[i].Flags & BPF_UNINSTANCIATED ? 'U' : 'I',
                                    ThisProcess->Breakpoints[i].Flags & BPF_DISABLED       ? 'D' : 'E',
                                    ThisProcess->Breakpoints[i].Address,
                                    mi.ModuleName,
                                    sym ? sym->Name : ""
                                    );
                        }
                    } else {
                        printf( "#%d %c%c\t          \t%s\n",
                            ThisProcess->Breakpoints[i].Number,
                            ThisProcess->Breakpoints[i].Flags & BPF_UNINSTANCIATED ? 'U' : 'I',
                            ThisProcess->Breakpoints[i].Flags & BPF_DISABLED       ? 'D' : 'E',
                            ThisProcess->Breakpoints[i].SymName
                            );
                    }
                }
            }
            break;

        case 'c':
            if (!CmdBuf[0]) {
                printf( "missing breakpoint number\n" );
                return FALSE;
            }
            if (CmdBuf[0] == '*') {
                for (i=0; i<MAX_BREAKPOINTS; i++) {
                    if (ThisProcess->Breakpoints[i].Number) {
                        ClearBreakpoint( ThisProcess, &ThisProcess->Breakpoints[i] );
                    }
                }
                return TRUE;
            }
            if (isdigit(CmdBuf[0])) {
                ULONG BpNum = atoi( CmdBuf );
                for (i=0; i<MAX_BREAKPOINTS; i++) {
                    if (ThisProcess->Breakpoints[i].Number == BpNum) {
                        ClearBreakpoint( ThisProcess, &ThisProcess->Breakpoints[i] );
                        return TRUE;
                    }
                }
            }
            printf( "invalid breakpoint number\n" );
            return FALSE;

        case 'd':
            break;

        case 'e':
            break;

        case 'a':
#if defined(_M_IX86)
            CmdBuf = GetAddress( CmdBuf, &Address );

            bp = GetAvailBreakpoint( ThisProcess );
            if (!bp) {
                printf( "could not set breakpoint\n" );
                return FALSE;
            }

            bp->Address = Address;
            bp->Handler = UserBpHandler;
            bp->Flags   = BPF_WATCH;

            ThisProcess->UserBpCount += 1;
            bp->Number = ThisProcess->UserBpCount;

            CurrContext.Dr0 = Address;
            CurrContext.Dr6 = 0x000d0002;
            SetRegContext( ThisThread->hThread, &CurrContext );
#else
            printf( "only available on x86\n" );
#endif
            break;

        default:
            break;
    }

    return TRUE;
}
Exemplo n.º 7
0
BOOL
CmdDisplayMemory(
    LPSTR             CmdBuf,
    HANDLE            hProcess,
    HANDLE            hThread,
    PEXCEPTION_RECORD ExceptionRecord
    )
{
    static ULONG Address = 0;

    //
    // skip any command modifiers & white space that may follow
    //
    SKIP_NONWHITE( CmdBuf );
    SKIP_WHITE( CmdBuf );

    ULONG ThisAddress;
    GetAddress( CmdBuf, &ThisAddress );
    if (ThisAddress) {
        Address = ThisAddress;
    }

    ULONG DataSize = 20*16;  // 20 lines @ 16 bytes per line
    LPSTR DataBuf = (LPSTR) MemAlloc( DataSize );
    if (!DataBuf) {
        return FALSE;
    }

    ULONG cb;
    if (!ReadMemory( hProcess, (PVOID)Address, DataBuf, DataSize )) {
        printf( "could not read memory\n" );
        MemFree( DataBuf );
        return FALSE;
    }

    ULONG i,j;
    printf( "\n" );
    for( i = 0; i < DataSize/16; i++ ) {
        j = i * 16;
        printf( "%08x  %08x %08x %08x %08x   %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
                  j + Address,
                  *(LPDWORD)&DataBuf[ j + 0 ],
                  *(LPDWORD)&DataBuf[ j + 4 ],
                  *(LPDWORD)&DataBuf[ j + 8 ],
                  *(LPDWORD)&DataBuf[ j + 12 ],
                  isprint( DataBuf[ j +  0 ]) ? DataBuf[ j +  0 ] : '.',
                  isprint( DataBuf[ j +  1 ]) ? DataBuf[ j +  1 ] : '.',
                  isprint( DataBuf[ j +  2 ]) ? DataBuf[ j +  2 ] : '.',
                  isprint( DataBuf[ j +  3 ]) ? DataBuf[ j +  3 ] : '.',
                  isprint( DataBuf[ j +  4 ]) ? DataBuf[ j +  4 ] : '.',
                  isprint( DataBuf[ j +  5 ]) ? DataBuf[ j +  5 ] : '.',
                  isprint( DataBuf[ j +  6 ]) ? DataBuf[ j +  6 ] : '.',
                  isprint( DataBuf[ j +  7 ]) ? DataBuf[ j +  7 ] : '.',
                  isprint( DataBuf[ j +  8 ]) ? DataBuf[ j +  8 ] : '.',
                  isprint( DataBuf[ j +  9 ]) ? DataBuf[ j +  9 ] : '.',
                  isprint( DataBuf[ j + 10 ]) ? DataBuf[ j + 10 ] : '.',
                  isprint( DataBuf[ j + 11 ]) ? DataBuf[ j + 11 ] : '.',
                  isprint( DataBuf[ j + 12 ]) ? DataBuf[ j + 12 ] : '.',
                  isprint( DataBuf[ j + 13 ]) ? DataBuf[ j + 13 ] : '.',
                  isprint( DataBuf[ j + 14 ]) ? DataBuf[ j + 14 ] : '.',
                  isprint( DataBuf[ j + 15 ]) ? DataBuf[ j + 15 ] : '.'
                );
    }
    printf( "\n" );

    Address += DataSize;
    MemFree( DataBuf );

    return TRUE;
}