//***************************************************************************** // The Record will be added to the pool. The index of the Record in the pool // is returned in *piIndex. If the Record is already in the pool, then the // index will be to the existing copy of the Record. //***************************************************************************** void *RecordPool::AddRecord( // New record or NULL. ULONG *piIndex) // Return 1-based index of Record here. { // Space on heap for new Record? if (m_cbRec > GetCbSegAvailable()) { if (!Grow(m_cbRec)) return 0; } // Records should be aligned on record boundaries. _ASSERTE((GetNextOffset() % m_cbRec) == 0); // Copy the Record to the heap. void *pNewRecord = GetNextLocation(); // Give the 1-based index back to caller. if (piIndex) *piIndex = (GetNextOffset() / m_cbRec) + 1; // Update heap counters. SegAllocate(m_cbRec); SetDirty(); return pNewRecord; } // void *RecordPool::AddRecord()
BOOL CmdStep( LPSTR CmdBuf, HANDLE hProcess, HANDLE hThread, PEXCEPTION_RECORD ExceptionRecord ) { PPROCESS_INFO 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; } SuspendAllThreads( ThisProcess, ThisThread ); ULONG Address = GetNextOffset( ThisProcess->hProcess, (ULONG)ExceptionRecord->ExceptionAddress, TRUE ); if (Address == (ULONG)-1) { #ifdef _M_IX86 CurrContext.EFlags |= 0x100; SetRegContext( ThisThread->hThread, &CurrContext ); PBREAKPOINT_INFO bp = GetAvailBreakpoint( ThisProcess ); if (bp) { bp->Flags |= BPF_TRACE; bp->Address = (ULONG)ExceptionRecord->ExceptionAddress; bp->Handler = TraceBpHandler; } #else printf( "could not trace the instruction\n" ); #endif } else { PBREAKPOINT_INFO bp = SetBreakpoint( ThisProcess, Address, 0, NULL, TraceBpHandler ); if (!bp) { printf( "could not trace the instruction\n" ); return FALSE; } } return TRUE; }
//***************************************************************************** // The Record will be added to the pool. The index of the Record in the pool // is returned in *piIndex. If the Record is already in the pool, then the // index will be to the existing copy of the Record. //***************************************************************************** void *RecordPool::AddRecord( // New record or NULL. ULONG *piIndex) // Return 1-based index of Record here. { #ifdef _DEBUG { // Instrumentation for OOM fault injection testing: make sure we can OOM every call to AddRecord. char *p = new (nothrow) char; if (!p) { return 0; } delete p; } #endif // Space on heap for new Record? if (m_cbRec > GetCbSegAvailable()) { if (!Grow(m_cbRec)) return 0; } // Records should be aligned on record boundaries. _ASSERTE((GetNextOffset() % m_cbRec) == 0); // Copy the Record to the heap. void *pNewRecord = GetNextLocation(); // Give the 1-based index back to caller. if (piIndex) *piIndex = (GetNextOffset() / m_cbRec) + 1; // Update heap counters. SegAllocate(m_cbRec); SetDirty(); return pNewRecord; } // void *RecordPool::AddRecord()
int LookupStringInFixedSet(const unsigned char* graph, size_t length, const char* key, size_t key_length) { const unsigned char* pos = graph; const unsigned char* end = graph + length; const unsigned char* offset = pos; const char* key_end = key + key_length; const char* multibyte_start = 0; while (GetNextOffset(&pos, end, &offset)) { /*char <char>+ end_char offsets * char <char>+ return value * char end_char offsets * char return value * end_char offsets * return_value */ int did_consume = 0; if (key != key_end && !IsEOL(offset, end)) { /* Leading <char> is not a match. Don't dive into this child */ if (!IsMatch(offset, end, key, multibyte_start)) continue; did_consume = 1; NextPos(&offset, &key, &multibyte_start); /* Possible matches at this point: * <char>+ end_char offsets * <char>+ return value * end_char offsets * return value */ /* Remove all remaining <char> nodes possible */ while (!IsEOL(offset, end) && key != key_end) { if (!IsMatch(offset, end, key, multibyte_start)) return -1; NextPos(&offset, &key, &multibyte_start); } } /* Possible matches at this point: * end_char offsets * return_value * If one or more <char> elements were consumed, a failure * to match is terminal. Otherwise, try the next node. */ if (key == key_end) { int return_value; if (GetReturnValue(offset, end, multibyte_start, &return_value)) return return_value; /* The DAFSA guarantees that if the first char is a match, all * remaining char elements MUST match if the key is truly present. */ if (did_consume) return -1; continue; } if (!IsEndCharMatch(offset, end, key, multibyte_start)) { if (did_consume) return -1; /* Unexpected */ continue; } NextPos(&offset, &key, &multibyte_start); pos = offset; /* Dive into child */ } return -1; /* No match */ }
DWORD UserBpHandler( PPROCESS_INFO ThisProcess, PTHREAD_INFO ThisThread, PEXCEPTION_RECORD ExceptionRecord, PBREAKPOINT_INFO BreakpointInfo ) { if (BreakpointInfo->Number) { printf( "Breakpoint #%d hit\n", BreakpointInfo->Number ); } else { printf( "Hardcoded breakpoint hit\n" ); } if (PrintRegistersFlag) PrintRegisters(); PrintOneInstruction( ThisProcess->hProcess, (ULONG)ExceptionRecord->ExceptionAddress ); ULONG ContinueStatus = ConsoleDebugger( ThisThread->hProcess, ThisThread->hThread, ExceptionRecord, FALSE, BreakpointInfo->Command ); if (BreakpointInfo->Address && (!Stepped)) { // // the bp is still present so we must step off it // SuspendAllThreads( ThisProcess, ThisThread ); ULONG Address = GetNextOffset( ThisProcess->hProcess, (ULONG)ExceptionRecord->ExceptionAddress, TRUE ); if (Address != (ULONG)-1) { PBREAKPOINT_INFO bp = SetBreakpoint( ThisProcess, Address, 0, NULL, UserBpStepHandler ); if (bp) { bp->LastBp = BreakpointInfo; } else { printf( "could not set off of the breakpoint\n" ); } } else { #ifdef _M_IX86 CurrContext.EFlags |= 0x100; SetRegContext( ThisThread->hThread, &CurrContext ); PBREAKPOINT_INFO bp = GetAvailBreakpoint( ThisProcess ); if (bp) { bp->Flags |= BPF_TRACE; bp->Address = (ULONG)ExceptionRecord->ExceptionAddress; bp->Handler = TraceBpHandler; bp->LastBp = BreakpointInfo; } else { printf( "could not step off of the breakpoint\n" ); } #else printf( "could not step off of the breakpoint\n" ); #endif } } return ContinueStatus; }