示例#1
0
char *PrintFlowSize(struct fileentry *fe)
{
   static char buf[50];
   char fullfile[200],line[200];
   osFile os;
   struct osFileEntry *osfe;
   uint32_t files,bytes;

   files=0;
   bytes=0;

   MakeFullPath(cfg_Dir,fe->file,fullfile,200);

   if(!(os=osOpen(fullfile,MODE_OLDFILE)))
   {
      sprintf(buf,"?/?");
      return(buf);
   }

   while(osFGets(os,line,200))
   {
      strip(line);

      if(line[0])
      {
         if(line[0] == '#' || line[0] == '^' || line[0] == '-')
            strcpy(line,&line[1]);
      
         if(stricmp(GetFilePart(line),line) == 0)
         {
            /* No path specified */

            MakeFullPath(fe->dir,line,fullfile,200);
            osfe=osGetFileEntry(fullfile);
         }
         else
         {
            osfe=osGetFileEntry(line);
         }

         if(osfe)
         {
            files++;
            bytes+=osfe->Size;

            TotalFiles++;
            TotalBytes+=osfe->Size;

            osFree(osfe);
         }
      }
   }

   osClose(os);

   sprintf(buf,"%s/%u",unit(bytes),files);
   
   return(buf);
}
示例#2
0
std::wstring GetFileExt(const std::wstring& path)
{
	std::wstring filePart = GetFilePart(path);
	const wchar_t* pLastPeriod = wcsrchr(filePart.c_str(), '.');
	if (pLastPeriod)
		return pLastPeriod;
	return L"";
}
示例#3
0
PROTECTED int EditorWinProc(int nWinId, UINT msg, WPARAM wParam, LPARAM lParam)
{
	char buff[MAXCHARBUFF]={0};

	switch(msg)
	{
	case WM_LBUTTONUP:
		break;
	case WM_LBUTTONDOWN:
		switch(HIWORD(wParam))
		{
		case MID_EDITOR_LFTBTN:
			if(g_gameMaps.curMap > 0)
				g_gameMaps.curMap--;

			sprintf(buff, "%d. %s", g_gameMaps.curMap, GetFilePart(g_gameMaps.maps[g_gameMaps.curMap].mapFile));
				TextBoxChangeText((HTEXTBOX)MenuGetItem(MID_EDITOR_TXTBOX), buff);
			break;
		case MID_EDITOR_RGTBTN:
			if(g_gameMaps.curMap < g_gameMaps.numMap-1)
				g_gameMaps.curMap++;
			
			sprintf(buff, "%d. %s", g_gameMaps.curMap, GetFilePart(g_gameMaps.maps[g_gameMaps.curMap].mapFile));
				TextBoxChangeText((HTEXTBOX)MenuGetItem(MID_EDITOR_TXTBOX), buff);
			break;
		case MID_EDITOR_EDIT:
			g_exit=eEXIT_EDIT;
			break;
		case MID_EDITOR_DELETE:
			GUTDeleteCurrentMap();
			GUTSaveMapList(MAPLIST);
			sprintf(buff, "%d. %s", g_gameMaps.curMap, GetFilePart(g_gameMaps.maps[g_gameMaps.curMap].mapFile));
				TextBoxChangeText((HTEXTBOX)MenuGetItem(MID_EDITOR_TXTBOX), buff);
			break;
		case MID_EDITOR_ADD:
			g_exit=eEXIT_NEW;
			break;
		case MID_EDITOR_CANCEL:
			g_exit=eEXIT_CANCEL;
			break;
		}
		break;
	}

	return 1;
}
示例#4
0
void DisplayFlowContents(struct fileentry *fe)
{
   char size[40],*todo;
   char fullfile[200],line[200];
   osFile os;
   struct osFileEntry *osfe;

   MakeFullPath(cfg_Dir,fe->file,fullfile,200);

   if(!(os=osOpen(fullfile,MODE_OLDFILE)))
   {
      printf("Failed to open file\n");
   }
   else
   {
      while(osFGets(os,line,200))
      {
         strip(line);

         if(line[0])
         {
            todo="";

            if(line[0] == '#' || line[0] == '^') todo="(To be truncated)";
            if(line[0] == '-')                   todo="(To be deleted)";

            if(line[0] == '#' || line[0] == '^' || line[0] == '-')
               strcpy(line,&line[1]);
      
            if(stricmp(GetFilePart(line),line) == 0)
            {
               /* No path specified */

               MakeFullPath(fe->dir,line,fullfile,200);
               osfe=osGetFileEntry(fullfile);
            }
            else
            {
               osfe=osGetFileEntry(line);
            }

            strcpy(size,"Not found");

            if(osfe)
            {
               sprintf(size, "%s", unit(osfe->Size));
               osFree(osfe);
            }

            printf(" %-39.39s %10s   %s\n",line,size,todo);
         }
      }

      osClose(os);
   }

   printf("\n");
}
示例#5
0
std::wstring CrackFilePart(const std::wstring& path)
{
	const std::wstring filePart = GetFilePart(path);
	const std::wstring extension = GetFileExt(filePart);
	UIETWASSERT(filePart.size() >= extension.size());
	if (!extension.empty())
		return filePart.substr(0, filePart.size() - extension.size());
	return filePart;
}
示例#6
0
std::wstring GetFileExt(const std::wstring& path)
{
	const std::wstring filePart = GetFilePart(path);
	const size_t lastPeriod = filePart.find_last_of(L'.');
	if (lastPeriod != std::wstring::npos)
		return filePart.substr(lastPeriod);
	// If there's no period then there's no extension.
	return L"";
}
示例#7
0
PUBLIC char *GetExtension(const char *PathName)
{
	assert(PathName);
	char* FilePart = GetFilePart(PathName);
	assert(FilePart);
	char* LastPeriod = strrchr(FilePart, '.');
	if (LastPeriod)
		return LastPeriod;
	return FilePart + strlen(FilePart);
}
示例#8
0
文件: gdb.cpp 项目: stievie/Martis
const char * FileMap::InitMapFileByParts(HANDLE _hFileMapping, DWORD _dwFileSize, DWORD _dwFileSizeHi)
{
    m_pFilePart          = NULL;
    m_hFileMapping       = _hFileMapping;
    m_dwFileSize         = _dwFileSize;
    m_dwFileSizeHi       = _dwFileSizeHi;
    m_ullFileOffsetBegin = 0;
    m_ullFileOffsetEnd   = 0;

    return GetFilePart(0, 1);
}
示例#9
0
std::wstring CrackFilePart(const std::wstring& path)
{
	std::wstring filePart = GetFilePart(path);
	const std::wstring extension = GetFileExt(filePart);
	if (!extension.empty())
	{
		filePart = filePart.substr(0, filePart.size() - extension.size());
	}

	return filePart;
}
示例#10
0
PUBLIC void GetFilename(const char *PathName, char *str, int strLen)
{
	char *filePart=GetFilePart(PathName);

	//copy till we see a period, or string ends
	for(int i = 0; i < strLen; i++)
	{
		if(filePart[i] == '.')
			break;

		str[i]=filePart[i];
	}
}
示例#11
0
// ChangePath():
//  Changes the path of the input path.  If a path
//  already exists, it is removed.  In either event, the
//  new path will be at the begining of the buffer.
//  Note that this assumes that the new path is indeed a
//  valid path, and will not add a :, /, \  or :\ to it's
//  end.  Note also that the drive part is considered to
//  be part of the path, and will be replaced along with
//  the rest of the path.
char * DirStrings::ChangePath( char *output, const char *new_path ) {
  if( !new_path )
    return output;

  char buffer[ MAX_PATH_LENGTH ];

  GetFilePart( buffer, output );
  strcpy( output, new_path );

  if( !IsEmpty( buffer ) )
    strcat( output, buffer );

  return output;
}
// Entry point into the main exception handling routine.  This routine is put into an except()
// statment at the beginning of a thread and is called anytime that there is a program exception
// The data is stored in a file called ErrorLog.txt in the data directory.
//
// data:			pointer to the exception data
// Message:		Any message	that should be printed out in the error log file
//
// returns: 
//
int __cdecl RecordExceptionInfo(PEXCEPTION_POINTERS data, const char *Message)
{
	static bool BeenHere = false;

	// Going recursive! That must mean this routine crashed!
	if (BeenHere) {
		return EXCEPTION_CONTINUE_SEARCH;
	}

	BeenHere = true;

	char	ModuleName[MAX_PATH];
	char	FileName[MAX_PATH] = "Unknown";
	// Create a filename to record the error information to.
	// Storing it in the executable directory works well.
	if (GetModuleFileName(0, ModuleName, sizeof(ModuleName)) <= 0) {
		ModuleName[0] = 0;
	}

	char *FilePart = GetFilePart(ModuleName);

	// Extract the file name portion and remove it's file extension. We'll
	// use that name shortly.
	lstrcpy(FileName, FilePart);
	char *lastperiod = strrchr(FileName, '.');
	if (lastperiod) {
		lastperiod[0] = 0;
	}

	// Replace the executable filename with our error log file name.
	lstrcpy(FilePart, "errorlog.txt");
	HANDLE LogFile = CreateFile(ModuleName, GENERIC_WRITE, 0, 0,
				OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, 0);
	if (LogFile == INVALID_HANDLE_VALUE) {
		OutputDebugString("Error creating exception report");
		return EXCEPTION_CONTINUE_SEARCH;
	}

	// Append to the error log.
	SetFilePointer(LogFile, 0, 0, FILE_END);
	// Print out some blank lines to separate this error log from any previous ones.
	hprintf(LogFile, "\r\n\r\n\r\n\r\n");
	PEXCEPTION_RECORD	Exception = data->ExceptionRecord;
	PCONTEXT			Context = data->ContextRecord;

	char	CrashModulePathName[MAX_PATH];
	char	*CrashModuleFileName = "Unknown";
	MEMORY_BASIC_INFORMATION	MemInfo;
	// VirtualQuery can be used to get the allocation base associated with a
	// code address, which is the same as the ModuleHandle. This can be used
	// to get the filename of the module that the crash happened in.
	if (VirtualQuery((void*)Context->Eip, &MemInfo, sizeof(MemInfo)) && GetModuleFileName((HINSTANCE)MemInfo.AllocationBase, CrashModulePathName, sizeof(CrashModulePathName)) > 0) {
		CrashModuleFileName = GetFilePart(CrashModulePathName);
	}

	// Print out the beginning of the error log in a Win95 error window
	// compatible format.
	hprintf(LogFile, "%s caused %s in module %s at %04x:%08x.\r\n",
				FileName, GetExceptionDescription(Exception->ExceptionCode),
				CrashModuleFileName, Context->SegCs, Context->Eip);
	hprintf(LogFile, "Exception handler called in %s.\r\n", Message);
	RecordSystemInformation(LogFile);
	// If the exception was an access violation, print out some additional
	// information, to the error log and the debugger.
	if (Exception->ExceptionCode == STATUS_ACCESS_VIOLATION && Exception->NumberParameters >= 2) {
		char DebugMessage[1000];
		const char* readwrite = "Read from";
		if (Exception->ExceptionInformation[0]) {
			readwrite = "Write to";
		}

		wsprintf(DebugMessage, "%s location %08x caused an access violation.\r\n", readwrite, Exception->ExceptionInformation[1]);

#ifdef	_DEBUG
		// The VisualC++ debugger doesn't actually tell you whether a read
		// or a write caused the access violation, nor does it tell what
		// address was being read or written. So I fixed that.
		OutputDebugString("Exception handler: ");
		OutputDebugString(DebugMessage);
#endif

		hprintf(LogFile, "%s", DebugMessage);
	}

	// Print out the register values in a Win95 error window compatible format.
	hprintf(LogFile, "\r\n");
	hprintf(LogFile, "Registers:\r\n");
	hprintf(LogFile, "EAX=%08x CS=%04x EIP=%08x EFLGS=%08x\r\n",
				Context->Eax, Context->SegCs, Context->Eip, Context->EFlags);
	hprintf(LogFile, "EBX=%08x SS=%04x ESP=%08x EBP=%08x\r\n",
				Context->Ebx, Context->SegSs, Context->Esp, Context->Ebp);
	hprintf(LogFile, "ECX=%08x DS=%04x ESI=%08x FS=%04x\r\n",
				Context->Ecx, Context->SegDs, Context->Esi, Context->SegFs);
	hprintf(LogFile, "EDX=%08x ES=%04x EDI=%08x GS=%04x\r\n",
				Context->Edx, Context->SegEs, Context->Edi, Context->SegGs);
	hprintf(LogFile, "Bytes at CS:EIP:\r\n");

	// Print out the bytes of code at the instruction pointer. Since the
	// crash may have been caused by an instruction pointer that was bad,
	// this code needs to be wrapped in an exception handler, in case there
	// is no memory to read. If the dereferencing of code[] fails, the
	// exception handler will print '??'.
	unsigned char *code = (unsigned char*)Context->Eip;
	for (int codebyte = 0; codebyte < NumCodeBytes; codebyte++) {
#ifdef _MSC_VER
		__try {
#endif
			hprintf(LogFile, "%02x ", code[codebyte]);
#ifdef _MSC_VER
		}
		__except(EXCEPTION_EXECUTE_HANDLER) {
			hprintf(LogFile, "?? ");
		}
#endif
	}

#ifdef _MSC_VER
	// Time to print part or all of the stack to the error log. This allows
	// us to figure out the call stack, parameters, local variables, etc.
	hprintf(LogFile, "\r\n"
					 "Stack dump:\r\n");
	__try {
		// Esp contains the bottom of the stack, or at least the bottom of
		// the currently used area.
		DWORD* pStack = (DWORD *)Context->Esp;
		DWORD* pStackTop;
		__asm
		{
			// Load the top (highest address) of the stack from the
			// thread information block. It will be found there in
			// Win9x and Windows NT.
			mov	eax, fs:[4]
			mov pStackTop, eax
		}
		if (pStackTop > pStack + MaxStackDump) {
			pStackTop = pStack + MaxStackDump;
		}

		int Count = 0;
		// Too many calls to WriteFile can take a long time, causing
		// confusing delays when programs crash. Therefore I implemented
		// simple buffering for the stack dumping code instead of calling
		// hprintf directly.
		char	buffer[1000] = "";
		const int safetyzone = 50;
		char*	nearend = buffer + sizeof(buffer) - safetyzone;
		char*	output = buffer;
		while (pStack + 1 <= pStackTop) 	{
			if ((Count % StackColumns) == 0) {
				output += wsprintf(output, "%08x: ", pStack);
			}

			char *Suffix = " ";
			if ((++Count % StackColumns) == 0 || pStack + 2 > pStackTop) {
				Suffix = "\r\n";
			}

			output += wsprintf(output, "%08x%s", *pStack, Suffix);
			pStack++;
			// Check for when the buffer is almost full, and flush it to disk.
			if (output > nearend) {
				hprintf(LogFile, "%s", buffer);
				buffer[0] = 0;
				output = buffer;
			}
		}
		// Print out any final characters from the cache.
		hprintf(LogFile, "%s", buffer);
	}
	__except(EXCEPTION_EXECUTE_HANDLER) {
		hprintf(LogFile, "Exception encountered during stack dump.\r\n");
	}
#endif

#ifndef NDEBUG
	if (safe_string[0])
		hprintf(LogFile, "Last safe point: %s\r\n", safe_string);
#endif

	RecordModuleList(LogFile);

	CloseHandle(LogFile);
	// Return the magic value which tells Win32 that this handler didn't
	// actually handle the exception - so that things will proceed as per
	// normal.

	return EXCEPTION_CONTINUE_SEARCH;
}
示例#13
0
文件: gdb.cpp 项目: stievie/Martis
LoadStatus_t GdbLoader::Load(void)
{
    m_cOrdinal = 0;
    SetProgress(g_hExp, "Loading...", 0);

    size_t cOffset = sizeof(g_pGdbSignature);
    size_t cFileSize = (size_t)GetFileSize();
    do {
        const size_t cEndOffset_tmp = __min(cOffset + sizeof(CGdbRecordHdr), cFileSize);
        const char * const pRecord_tmp = GetFilePart(cOffset, cEndOffset_tmp);
        if (pRecord_tmp == NULL)
            return lsFailed;
        const CGdbRecordHdr * const pHdr_tmp = reinterpret_cast<const CGdbRecordHdr *>(pRecord_tmp);
        size_t cNextOffset = __min(cOffset + sizeof(CGdbRecordHdr) + pHdr_tmp->dwLen, cFileSize);
        const char * const pRecord = GetFilePart (cOffset, cNextOffset);
        if (pRecord == NULL)
            return lsFailed;
        const CGdbRecordHdr * const pHdr = reinterpret_cast<const CGdbRecordHdr *>(pRecord);

        switch (pHdr->btType) {
        case 'D': { // GDB format version.
            const CGdbFormatVersion * const pVer = static_cast<const CGdbFormatVersion *>(pHdr);
            switch (pVer->wdVersion) {
            case 0x6B:
            case 0x6C:
            case 0x6D:
//						AddLog(g_hExp, "GDB Format version %d.", pVer->wdVersion - 0x6B + 1);
                break;
            default:
//						ReportText ("Format version: 0x%02X.", pVer->wdVersion);
                break;
            }
            m_b2ndVersion = pVer->wdVersion == 0x6C;
            m_b3rdVersion = pVer->wdVersion == 0x6D;
            if (pVer->wdVersion > 0x6D)
                AddLog(g_hExp, "File was created with an untested version of MapSource.", NULL);
            break;
        }
        case 'A': { // MapSource version.
            const CGdbMSVersion * const pVer = static_cast<const CGdbMSVersion *> (pHdr);

            const char * const pRecord = GetFilePart (cOffset, cNextOffset + 10);
            if (pRecord == NULL)
                return lsFailed;
            if (::_strnicmp (pRecord + (cNextOffset - cOffset), "MapSource", 10) == 0)
                cNextOffset += 10;
            break;
        }

        case 'W': { // Waypoint.
            const CGdbWaypointHdr * const pWP = static_cast<const CGdbWaypointHdr *> (pHdr);
            ParseWaypoint (pWP, cOffset, cNextOffset);
            break;
        }

        case 'T': { // Track.
            const CGdbTrackHdr * const pTrack = static_cast<const CGdbTrackHdr *> (pHdr);
            ParseTrack (pTrack, cOffset, cNextOffset, cFileSize, false);
            break;
        }

        case 'R': { // Route.
            const CGdbRouteHdr * const pRoute = static_cast<const CGdbRouteHdr *> (pHdr);
            ParseRoute (pRoute, cOffset, cNextOffset);
            break;
        }

        case 'L': { // Map reference.
            const CGdbMapHdr * const pMap = static_cast<const CGdbMapHdr *> (pHdr);
            break;
        }

        case 'V': {	// Tail mark and map set info.
            break;
        }
        }

        cOffset = cNextOffset;

        SetProgress(g_hExp, NULL, ::MulDiv(100, cOffset, cFileSize));
    } while (cOffset < cFileSize);

    return lsOK;
}
void DumpStackStak(HANDLE hLogFile, PEXCEPTION_POINTERS lpExcetion)
{
	STACKFRAME stackFrame;
#ifdef _X86_
	stackFrame.AddrPC.Offset = lpExcetion->ContextRecord->Eip;
	stackFrame.AddrPC.Mode = AddrModeFlat;
	stackFrame.AddrStack.Offset = lpExcetion->ContextRecord->Esp;
	stackFrame.AddrStack.Mode = AddrModeFlat;
	stackFrame.AddrFrame.Offset = lpExcetion->ContextRecord->Ebp;
	stackFrame.AddrFrame.Mode = AddrModeFlat;
#else
	stackFrame.AddrPC.Offset       = (DWORD)lpExcetion->ContextRecord->Fir ;
	stackFrame.AddrPC.Mode         = AddrModeFlat ;
	stackFrame.AddrReturn.Offset   = (DWORD)lpExcetion->ContextRecord->IntRa;
	stackFrame.AddrReturn.Mode     = AddrModeFlat ;
	stackFrame.AddrStack.Offset    = (DWORD)lpExcetion->ContextRecord->IntSp;
	stackFrame.AddrStack.Mode      = AddrModeFlat ;
	stackFrame.AddrFrame.Offset    = (DWORD)lpExcetion->ContextRecord->IntFp;
	stackFrame.AddrFrame.Mode      = AddrModeFlat ;
#endif

	//set up symbol engine
	DWORD dwOpts = SymGetOptions();
	SymSetOptions(dwOpts|SYMOPT_DEFERRED_LOADS|SYMOPT_LOAD_LINES);
	SymInitialize(GetCurrentProcess(), NULL, TRUE);

#ifdef _WIN64
#define CH_MACHINE IMAGE_FILE_MACHINE_IA64
#else
#define CH_MACHINE IMAGE_FILE_MACHINE_I386
#endif

	WriteLogFile(hLogFile, "\r\n\r\nStack trace list:\r\n");
	do 
	{
		BOOL bRet = StackWalk(CH_MACHINE, GetCurrentProcess(), GetCurrentThread(), &stackFrame, lpExcetion->ContextRecord,
			(PREAD_PROCESS_MEMORY_ROUTINE)ReadProcessMemory, SymFunctionTableAccess, SymGetModuleBase, NULL);
		if (bRet == FALSE || stackFrame.AddrFrame.Offset == 0)
			break;

		DWORD dwModuleBase = SymGetModuleBase(GetCurrentProcess(), stackFrame.AddrPC.Offset);
		if (dwModuleBase == 0)
			break;

		//module name of call
		TCHAR szModuleName[MAX_PATH] = {0};
		GetModuleFileName((HMODULE)dwModuleBase, szModuleName, MAX_PATH);

		//funtion name
		DWORD dwDisp = 0;
		TCHAR szFuntionName[MAX_PATH+sizeof(IMAGEHLP_SYMBOL)] = {0};
		PIMAGEHLP_SYMBOL lpSymb = (PIMAGEHLP_SYMBOL)szFuntionName;
		lpSymb->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
		lpSymb->MaxNameLength = MAX_PATH;
		SymGetSymFromAddr(GetCurrentProcess(), stackFrame.AddrPC.Offset, &dwDisp, lpSymb);

		//line number and filename
		IMAGEHLP_LINE hlpLine;
		SymGetLineFromAddr(GetCurrentProcess(), (DWORD)stackFrame.AddrPC.Offset, &dwDisp, &hlpLine);
		WriteLogFile(hLogFile, "%s-%s %s::%d\r\n", lpSymb->Name, GetFilePart(szModuleName), hlpLine.FileName, hlpLine.LineNumber);
	} while (1);
}
void ExceptionHandler(unsigned int, PEXCEPTION_POINTERS lpCeption)
{
	//Get time
	SYSTEMTIME st;
	GetLocalTime(&st);
	TCHAR szTime[120] = {0};
	sprintf_s(szTime, 120, "%d-%d-%d-%d-%d-%d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

	//Get current module name
	TCHAR* lpCurModuleName = _T("Current Module name");
	TCHAR szModuleName[MAX_PATH] = {0};
	if (GetModuleFileName(NULL, szModuleName, MAX_PATH) > 0)
		lpCurModuleName = GetFilePart(szModuleName);

	//Create log file
	TCHAR szFilePath[MAX_PATH] = {0};
	TCHAR szLogPath[MAX_PATH] = {0};
	GetCurrentDirectory(MAX_PATH, szFilePath);
	sprintf_s(szLogPath, MAX_PATH, "%s\\Exception-%s.log", szFilePath, szTime);

	HANDLE hLogFile = CreateFile(szLogPath, GENERIC_WRITE, 0, 0, 
		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, 0);
	if (hLogFile == INVALID_HANDLE_VALUE)
		return;// EXCEPTION_CONTINUE_SEARCH;

	PEXCEPTION_RECORD Exception = lpCeption->ExceptionRecord;
	PCONTEXT          Context   = lpCeption->ContextRecord;
	TCHAR szCrashModuleName[MAX_PATH] = {0};
	TCHAR* lpCrashName = _T("Exception Process Name");
	MEMORY_BASIC_INFORMATION memInfo;
	// VirtualQuery can be used to get the allocation base associated with a
	// code address, which is the same as the ModuleHandle. This can be used
	// to get the filename of the module that the crash happened in.
	if (VirtualQuery((LPCVOID)Context->Eip, &memInfo, sizeof(memInfo)) && (GetModuleFileName((HMODULE)memInfo.AllocationBase, szCrashModuleName, MAX_PATH) > 0))
		lpCrashName = GetFilePart(szCrashModuleName);
	WriteLogFile(hLogFile, "%s caused %s(0x%08x) in module %s at %04x:%08x.\r\n",
		lpCurModuleName, GetExceptionDescription(Exception->ExceptionCode), Exception->ExceptionCode, lpCrashName, Context->SegCs, Context->Eip);

	//Write system info to logfile
	DumpSystemInformation(hLogFile, lpCurModuleName);

	// Print out the bytes of code at the instruction pointer. Since the
	// crash may have been caused by an instruction pointer that was bad,
	// this code needs to be wrapped in an exception handler, in case there
	// is no memory to read. If the dereferencing of code[] fails, the
	// exception handler will print '??'.
	WriteLogFile(hLogFile, _T("\r\n\r\nCode Start CS:EIP:\r\n"));
	BYTE * code = (BYTE *)Context->Eip;
	for (int codebyte = 0; codebyte < 16; codebyte++)
	{
		__try
		{
			WriteLogFile(hLogFile, _T("%02x "), code[codebyte]);
		}
		__except(EXCEPTION_EXECUTE_HANDLER)
		{
			WriteLogFile(hLogFile, _T("?? "));
		}
	}
	//Write Stack information to logfile
	DumpStackStak(hLogFile, lpCeption);
	//Write module of process information to logfile
	DumpModuleList(hLogFile);
	CloseHandle(hLogFile);
	
	//Create dump file
	sprintf_s(szLogPath, MAX_PATH, "%s\\Exception-%s.dmp", szFilePath, szTime);
	HANDLE hDumpFile = CreateFile(szLogPath, GENERIC_WRITE, 0, 0, 
		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, 0);
	if (hDumpFile == INVALID_HANDLE_VALUE)
		return;// EXCEPTION_CONTINUE_SEARCH;
	
	MINIDUMP_EXCEPTION_INFORMATION eInfo;
	eInfo.ThreadId = GetCurrentThreadId();
	eInfo.ExceptionPointers = lpCeption;
	eInfo.ClientPointers = FALSE;
	MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &eInfo, NULL, NULL);
	CloseHandle(hDumpFile);
}
示例#16
0
PROTECTED RETCODE EditorProc(DWORD msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case GMSG_INIT:
		g_exit=eEXIT_NO;

		_GUTBKFXEnterProc(eBKFX_FADEINOUT,0);

		g_win = MenuGetItem(MID_EDITOR);

		if(!g_win)
		{
			char path[MAXCHARBUFF];

			//load up the menu
			strcpy(path, WINDOWDIR);
			strcat(path, EDITORFILE);

			FILE *fp = fopen(path, "rt");
			MenuLoadFromFile (fp);
			fclose(fp);

			g_win = MenuGetItem(MID_EDITOR);

			WindowChangeSize((HWINDOW)g_win, GFXGetScrnSize().cx, GFXGetScrnSize().cy);
			WindowNewProc((HWINDOW)g_win, EditorWinProc);
		}
		else
			MenuShowItem(g_win, HMC_ACTIVE, 1);

		char buff[MAXCHARBUFF];
		sprintf(buff, "%d. %s", g_gameMaps.curMap, GetFilePart(g_gameMaps.maps[g_gameMaps.curMap].mapFile));
		TextBoxChangeText((HTEXTBOX)MenuGetItem(MID_EDITOR_TXTBOX), buff);

		break;

	case GMSG_UPDATE:
		if(g_exit==eEXIT_NO)
		{
			MenuProc();			 //update the windows

			if(g_exit!=eEXIT_NO)
				_GUTBKFXExitProc(eBKFX_FADEINOUT,0);
		}
		break;

	case GMSG_DISPLAY:
		GFXClear(0, 0, 0);   //clears screen within rects with given color

		GFXBltModeEnable(false);
		MenuDraw();			 //draw all menus
		GFXBltModeDisable();

		if(_GUTBKFXUpdate() == RETCODE_BREAK && g_exit != eEXIT_NO)
		{
			SENDPROCMSG(GMSG_DESTROY, 0, 0);

			mapEditInfo mapEdit={0};

			switch(g_exit)
			{
			case eEXIT_EDIT:
				SETPROCTYPE(eEditMap);

				//hardcoded for now...
				strcpy(mapEdit.mapName, GetFilePart(g_gameMaps.maps[g_gameMaps.curMap].mapFile));

				SENDPROCMSG(GMSG_INIT, (WPARAM)&mapEdit, 0);
				break;
			case eEXIT_NEW:
				SETPROCTYPE(eEditNew);
				SENDPROCMSG(GMSG_INIT, 0, 0);
				break;
			case eEXIT_CANCEL:
				SETPROCTYPE(eMainMenu);
				SENDPROCMSG(GMSG_INIT, 0, 0);
				break;
			}
		}
		
		GFXUpdate(0, 0, 0);  //update frame on display
		break;

	case GMSG_LOAD:
		break;

	case GMSG_DESTROY:
		if(g_win)
			MenuShowItem(g_win, HMC_INVIS, 1);
		break;
	}

	return RETCODE_SUCCESS;
}
示例#17
0
文件: filecopy.c 项目: aib/filecopy
int main(int argc, char *argv[])
{
	HANDLE src, dest;
	char destName[MAX_PATH];
	LARGE_INTEGER pos;
	LARGE_INTEGER srcSize;
	DISK_GEOMETRY_EX diskgeo;
	DWORD readbytes;
	DWORD writtenbytes;
	unsigned long blocksize = 0;
	unsigned long skipcount = 0;
	char *buffer;
	WIN32_FILE_ATTRIBUTE_DATA fileAttr;
	int dest_exists;


	clock_t dstart, dend;
	DWORD bytespertick;

	double in_percent;
	double in_speed;

	printf("*** aib's filecopy v" VERSION " ***\n\n");

	if ((argc != 3) && (argc != 4) && (argc != 5)) {
		printf("Usage:\n\t%s <source file> <destination file or dir> [<blocksize>[ <blocks to skip>]]\n", argv[0]);
		return 0;
	}

	if (argc >= 4) {
		blocksize = strtoul(argv[3], (char **) NULL, 10);
	}

	if (argc >= 5) {
		skipcount = strtoul(argv[4], (char **) NULL, 10);
	}

	if (blocksize == 0) blocksize = 512;

	if ((buffer = malloc(blocksize)) == NULL) {
		printf("Unable to allocate memory for read/write buffer.\n");
		return -10;
	}

	dest_exists = 1;
	if (GetFileAttributesEx(argv[2], GetFileExInfoStandard, &fileAttr) == 0) {
		if (GetLastError() == ERROR_FILE_NOT_FOUND) {
			dest_exists = 0;
		} else {
			printf("GetFileAttributesEx() failed on destination file.\n");
			return -11;
		}
	}

	if (dest_exists && (fileAttr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
		strncpy(destName, argv[2], MAX_PATH);
		strncat(destName, "\\", MAX_PATH-strlen(destName)-1);
		strncat(destName, GetFilePart(argv[1]), MAX_PATH-strlen(destName)-1);
//		printf("Creating \"%s\" in \"%s\"...\n", GetFilePart(argv[1]), argv[2]);
	} else {
		strncpy(destName, argv[2], MAX_PATH);
	}

	if ((dest = CreateFile(destName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) {
		printf("Unable to create or open destination file: \"%s\".\n", destName);
		return -1;
	}

	if ((src = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) {
		printf("Unable to open source file.\n");
		return -2;
	}

	if (GetFileSizeEx(src, &srcSize) == 0) {
		printf("GetFileSizeEx() failed on source file, trying ioctl...\n");

		if ((DeviceIoControl(src, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, (LPVOID) &diskgeo, sizeof(diskgeo), &writtenbytes, NULL) == 0) || (writtenbytes == 0)) {
			printf("ioctl failed as well.\n");
			return -5;
		} else {
			srcSize.QuadPart = diskgeo.DiskSize.QuadPart;
		}
	}

	xprintf("SRC file:       %s\n", argv[1]);
	xprintf("DST file:       %s\n", destName);
	xprintf("SRC size:       %llu bytes\n", srcSize.QuadPart);
	xprintf("Block size:     %u bytes\n", blocksize);
	xprintf("Blocks to skip: %u (%llu bytes)\n", skipcount, ((unsigned long long) (skipcount))*blocksize);

	pos.QuadPart = 0;

	if (SetFilePointerEx(dest, pos, &pos, FILE_END) == 0) {
		printf("Unable to seek destination file.\n");
		return -3;
	}

//	original = pos;

	if (pos.QuadPart)
		xprintf("Destination file is at %llu bytes, resuming...\n", pos.QuadPart);

	if (SetFilePointerEx(src, pos, NULL, FILE_BEGIN) == 0) {
		printf("Unable to seek source file.\n");
		return -4;
	}

	dstart = dend = clock();
	bytespertick = 0;
	in_speed = 0;

	while (1) {
		if (skipcount) {
			ZeroMemory(buffer, blocksize);
			readbytes = blocksize;
			skipcount--;
		} else {
			if (ReadFile(src, buffer, blocksize, &readbytes, NULL) == 0) {
				xprintf("\nError reading file at %llu bytes.\n", pos.QuadPart);
				goto end;
			}
		}

		pos.QuadPart += readbytes;

		if ((WriteFile(dest, buffer, readbytes, &writtenbytes, NULL) == 0) || (readbytes != writtenbytes)) {
			printf("\nError writing file.\n");
			goto end;
		}

		bytespertick += readbytes;
		dend = clock();

		if ((dend - dstart) >= CLOCKS_PER_SEC) {
			in_speed = (((double) bytespertick)) * (((double) CLOCKS_PER_SEC) / 1024.0) / ((double) (dend - dstart));
			dstart = clock();
			bytespertick = 0;
		}

		in_percent = (((double) pos.QuadPart) * 100) / ((double) srcSize.QuadPart);

		xprintf("Position:       %llu bytes [%5.2f%%] Speed: %.3f kb/s          \r", pos.QuadPart, in_percent, in_speed);

		if (readbytes != blocksize) {
			xprintf("\nFinished reading at %llu bytes.\n", pos.QuadPart);
			break;
		}
	}

end:
//	printf("\nBytes this session: %u\n", pos-original);

	free(buffer);
	CloseHandle(src);
	CloseHandle(dest);

	return 0;
}
示例#18
0
TEST(USystemTest,GetFilePart_EmptyPath_ReturnsEmptyString)
{
  ASSERT_EQ(L"",GetFilePart(L""));
}
示例#19
0
TEST(USystemTest,GetFilePart_ValidPath_ReturnsFilePart)
{
  ASSERT_EQ(L"a.txt",GetFilePart(L"C:\\temp\\a.txt"));
}