Pelles C forum

C language => Tips & tricks => Topic started by: TimoVJL on August 20, 2010, 12:36:25 PM

Title: PEStripW and .dbg file
Post by: TimoVJL on August 20, 2010, 12:36:25 PM
PellesC IDE debugger support .dbg files.

With this tool you can take away debug information from exe

Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <imagehlp.h>

#pragma lib "imagehlp.lib"

TCHAR szAppName[] = "PEStripW";
/*
BOOL SplitSymbols(PSTR ImageName, PSTR SymbolsPath, PSTR SymbolFilePath, DWORD Flags);
SPLITSYM_EXTRACT_ALL, SPLITSYM_REMOVE_PRIVATE, SPLITSYM_SYMBOLPATH_IS_SRC
*/

int LastError(HWND hWnd)
{
LPVOID lpMsgBuf;
 
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);

// Display the string.
MessageBox( hWnd, lpMsgBuf, szAppName, MB_OK|MB_ICONERROR );

// Free the buffer.
LocalFree( lpMsgBuf );
return 0;
}

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
{
int nLen;
TCHAR szTmp[260], szDbgFile[260];

if (!*lpCmdLine) {
MessageBox(0, TEXT("usage: PEStrip.exe file"), szAppName, MB_OK);
return 1;
}
//wsprintf(szDbgFile, "%s.dbg", lpCmdLine);
lstrcpy(szDbgFile, lpCmdLine);
nLen = lstrlen(szDbgFile);
lstrcpy(&szDbgFile[nLen-3], TEXT("dbg"));
if (SplitSymbols(lpCmdLine, NULL, szDbgFile, SPLITSYM_EXTRACT_ALL)) {
wsprintf(szTmp, TEXT("%s stripped to %s"), lpCmdLine, szDbgFile);
MessageBox(0, szTmp, szAppName, MB_OK);
} else {
//wsprintf(szTmp, "%s: Error %d", lpCmdLine, GetLastError());
//MessageBox(0, szTmp, szAppName, MB_OK | MB_ICONERROR);
LastError(0);
}
return 0;
}
Title: Re: PEStripW and .dbg file
Post by: saliha on February 26, 2011, 08:59:42 AM
To generate a .DBG file in this format, you can use REBASE.EXE, which is provided with the Win32 SDK.
Please see the Win32 SDK documentation for more details.
Title: Re: PEStripW and .dbg file
Post by: TimoVJL on February 26, 2011, 09:10:44 AM
PellesC have porebase.exe for that too.