Esempio n. 1
0
void CEException::dumpException(HANDLE file, EXCEPTION_RECORD *exceptionRecord) {
	char tempo[200];
	char exceptionName[50];
	unsigned int i;
#if (_WIN32_WCE >= 300)
	writeBreak(file);
	switch (exceptionRecord->ExceptionCode) {
	case EXCEPTION_ACCESS_VIOLATION :
		strcpy(exceptionName, "Access Violation");
		break;
	case EXCEPTION_ARRAY_BOUNDS_EXCEEDED :
		strcpy(exceptionName, "Array Bounds Exceeded");
		break;
	case EXCEPTION_DATATYPE_MISALIGNMENT :
		strcpy(exceptionName, "Datatype Misalignment");
		break;
	case EXCEPTION_IN_PAGE_ERROR :
		strcpy(exceptionName, "In Page Error");
		break;
	case EXCEPTION_INT_DIVIDE_BY_ZERO :
		strcpy(exceptionName, "Int Divide By Zero");
		break;
	case EXCEPTION_INT_OVERFLOW :
		strcpy(exceptionName, "Int Overflow");
		break;
	case EXCEPTION_STACK_OVERFLOW :
		strcpy(exceptionName, "Stack Overflow");
		break;
	default:
		sprintf(exceptionName, "%.8x", exceptionRecord->ExceptionCode);
		break;
	}
	sprintf(tempo, "Exception %s Flags %.8x Address %.8x", exceptionName, exceptionRecord->ExceptionFlags,
	        exceptionRecord->ExceptionAddress);
	writeString(file, tempo);
	if (exceptionRecord->NumberParameters) {
		for (i = 0; i < exceptionRecord->NumberParameters; i++) {
			sprintf(tempo, "Parameter %d %.8x", i, exceptionRecord->ExceptionInformation[i]);
			writeString(file, tempo);
		}
	}
	if (exceptionRecord->ExceptionRecord)
		dumpException(file, exceptionRecord->ExceptionRecord);
#else
	writeBreak(file);
	writeString(file, "Cannot get exception information on this CE version");
#endif
}
Esempio n. 2
0
void CEException::dumpContext(HANDLE file, HANDLE hProcess, CONTEXT *context) {
	char tempo[200];
	unsigned char memoryDump[100];
	DWORD size;
	unsigned int i;

#ifdef ARM
	writeBreak(file);
	writeString(file, "Context dump");
	sprintf(tempo, "R0=%.8x R1=%.8x R2=%.8x R3=%.8x R4=%.8x", context->R0, context->R1,
	        context->R2, context->R3, context->R4);
	writeString(file, tempo);
	sprintf(tempo, "R5=%.8x R6=%.8x R7=%.8x R8=%.8x R9=%.8x", context->R5, context->R6,
	        context->R7, context->R8, context->R9);
	writeString(file, tempo);
	sprintf(tempo, "R10=%.8x R11=%.8x R12=%.8x", context->R10, context->R11,
	        context->R12);
	writeString(file, tempo);
	sprintf(tempo, "Sp=%.8x Lr=%.8x Pc=%.8x Psr=%.8x", context->Sp, context->Lr,
	        context->Pc, context->Psr);
	writeString(file, tempo);
	writeBreak(file);

	sprintf(tempo, "Memory dump at %.8x", context->Pc - (sizeof(memoryDump) / 2));
	writeString(file, tempo);
	if (ReadProcessMemory(hProcess, (LPCVOID)(context->Pc - (sizeof(memoryDump) / 2)), memoryDump, sizeof(memoryDump), &size)) {
		for (i = 0; i < size; i += 8) {
			int j;
			char digit[4];
			int max;
			max = size - i;
			if (max > 8)
				max = 8;
			tempo[0] = '\0';
			for (j = 0; j < max; j++) {
				sprintf(digit, "%.2x ", memoryDump[i + j]);
				strcat(tempo, digit);
			}
			writeString(file, tempo);
		}
	}
#else
	writeBreak(file);
	writeString(file, "Context dump only available on ARM devices");
#endif
}
Esempio n. 3
0
/*! This function updates .ini file in two stages. It copies original .ini file
  into temporary one line by line, replacing/deleting/adding lines as necessary.
  Then it copies temporary file into original one and deletes temporary file.
*/
bool TEIniFile::update()
{
  close();
	if (!f.open(IO_ReadWrite)) return false;
  QString tempfn=f.name()+".tmp";
  QFile tempf(tempfn);
  if (!tempf.open(IO_ReadWrite | IO_Truncate)) return false;
  QTextStream tsorg;
  bool skipsec=false;

  tsorg.setEncoding(QTextStream::UnicodeUTF8);
  tsorg.setDevice(&f);
	ts.setDevice(&tempf); // writeXXX function hardwired to write into ts. So we set it appropriatedly.
	// prepare
  QMap<QString,bool> secProcd, valueProcd; // processedp flag's maps
  QMapIterator<QString,type_ValueList> it1;
  for(it1=SectionList.begin();it1!=SectionList.end();++it1)
  {
    secProcd[it1.key()]=false;
  }
	// scan form sections
	QString line, sec;
	type_Processing pr = P_NONE;	// nothing done yet
	type_ValueList ValueList;

	while (!((line = tsorg.readLine()).isNull())) {
		if ((pr == P_NONE) || (pr == P_SECTION)) {
			// trim line
			line = line.stripWhiteSpace();
			// skip if empty
			if (line.isEmpty())
      {
        writeBreak();
        continue;
      }
			// skip if comment
			if (line.startsWith("#"))
      {
        writeComment(line.mid(1));
        continue;
      }
			// check if section
			if (line.startsWith("[") && line.endsWith("]")) {
				if (pr == P_SECTION) {
					// update previous section
          // write new values
          type_ValueList::iterator it;
          type_ValueList & curSec=SectionList[sec];
          type_ValueList & curSecDef=SectionListDef[sec];
          for(it=curSec.begin();it!=curSec.end();++it)
          {
            if (!valueProcd[it.key()])
            { // this value was not processed yet, hence it's new or just default.
              if (curSecDef.find(it.key())==curSecDef.end() || curSecDef[it.key()]!=it.data()) // if it equals default value, skip it.
                ts << it.key() << "\t" << it.data() << "\n";
              valueProcd[it.key()]=true; // it is for completeness' sake, so it don't really necessary (yet?).
            }
          }
					secProcd[sec]=true;
				}
				// section found!
        valueProcd.clear(); // get ready for next section
				pr = P_SECTION;
				sec = line.mid(1, line.length()-2).stripWhiteSpace();
        writeSection(sec);
        skipsec=SectionList.find(sec)==SectionList.end() || secProcd[sec]==true; // Skip deleted or already processed section
        type_ValueList & curSec=SectionList[sec];
        type_ValueList::iterator it;
        for(it=curSec.begin();it!=curSec.end();++it)
        {
          valueProcd[it.key()]=false;
        }
				ValueList.clear();
				continue;
			}
			if (pr == P_SECTION) {
				// read name
        if (skipsec)
          continue;
				QString nam;
				int j = 0, l = (int)line.length();
				QChar c;
				while ( (j < l) && !((c = line.ref((uint)j)).isSpace()) ) {
					nam += c;
					j++;
				}
				// read value
        bool rawData=false;
        bool doubleQuotes=false;
				QString val;
				val = line.mid((uint)j).stripWhiteSpace();
				if (val == "data{") {
          rawData=true;
					// read raw data...
					val = "";
					while (!((line = ts.readLine()).isNull())) {
						if (line == "}data") {
							ValueList[nam] = val;
							break;
						}
						val += line + "\n";
					}
				} else {
					// test for ""
					if (val.startsWith("\"") && val.endsWith("\""))
          {
            doubleQuotes=true;
						val = val.mid(1, val.length()-2).stripWhiteSpace();
          }
					ValueList[nam] = val;
				}
        if (SectionList[sec].find(nam)!=SectionList[sec].end() && valueProcd[nam]==false)
        { // write modified value
          if (rawData)
            writeData(nam,SectionList[sec][nam]);
          else if (doubleQuotes)
            writeString(nam,SectionList[sec][nam]);
          else
            ts << nam << "\t" << SectionList[sec][nam] << "\n";
          valueProcd[nam]=true;
        }
			}
      else
        writeComment(line);
		}
	}

	if (pr == P_SECTION) {
		// update last section
    // write new values
    type_ValueList::iterator it;
    type_ValueList & curSec=SectionList[sec];
    type_ValueList & curSecDef=SectionListDef[sec];
    for(it=curSec.begin();it!=curSec.end();++it)
    {
      if (!valueProcd[it.key()])
      { // this value was not processed yet, hence it's new.
        if (curSecDef.find(it.key())==curSecDef.end() || curSecDef[it.key()]!=it.data())
          ts << it.key() << "\t" << it.data() << "\n";
        valueProcd[it.key()]=true; // it is for completeness' sake, so it don't really necessary (yet?).
      }
    }
		secProcd[sec]=true;
	}
  QMapIterator<QString,bool> it;
  for(it=secProcd.begin();it!=secProcd.end();++it)
  {
    QString sec=it.key();
    if (!it.data())
    {
      writeSection(sec);
      type_ValueList & curSec=SectionList[sec];
      type_ValueList & curSecDef=SectionListDef[sec];
      type_ValueList::iterator it1;
      for(it1=curSec.begin();it1!=curSec.end();++it1)
        if (curSecDef.find(it1.key())==curSecDef.end() || curSecDef[it1.key()]!=it1.data())
          ts << it1.key() << "\t" << it1.data() << "\n";
    }
  }
  tempf.flush();
  if (!tempf.reset())
    return false;
  f.close();
  if (!f.open(IO_WriteOnly | IO_Truncate))
    return false;
  const int N=64*1024;
  char * buf=new char[N];
  Q_LONG len;
  while(true)
  {
    len=tempf.readBlock(buf,N);
    if (len<=0)
      break;
    f.writeBlock(buf,(Q_ULONG)len);
  }
  delete [] buf;
  f.close();
  tempf.close();
  tempf.remove();
  ts.setDevice(&f);
	return len>=0;
}