|
Your hex editor is handy, but there are two thing you might consider.
1) Allow the font size in use to be changed (visually friendly);
2) Change the background color to make it less tiring to read the codes;
Besides, it was helpful to my needs. thanks for the effort!
___________________________________
Willian Silva Rodrigues
http://www.williansilva.com.br
http://br.linkedin.com/in/willianbr
--- --- --- ---
Radio(NXTL):55*112*109193
BBM PIN: 238d4349
|
|
|
|
|
All I just want to do is batch open a list of binary files, search for a label and extract 2 numbers from it.. then input 2 numbers at specified binary locations.
How can I go about that really quick 'n' dirty with C/C++?
|
|
|
|
|
Hello Paul Frazee,
my name is Fabian Ganter and I´m from Germany.
First thank´s for your Simple Hex Editor.
I have a important Problem. I had token your Hex-Editor and modify it a little bit.
I would the output change and make an adress line(gap) to it. So that was no problem and it worked. But if I scroll with the mouse the scrollbar up and down, the new adress line redraw it always on top of the window and the hexdataout and the chardatatout are switching. I think it is something to change in the code at "void CHexEditorView::OnVScroll", or?
So I hope you know what I mean and perhaps you can help me.
Thank you very much!
Best regarts Fabian Ganter
Sourcecode from HexEditorView:
// calculate rects
CRect rcCharData, rcHexData, rcNumData;
// hex
rcHexData.left = rcRectClient.left + 120;
rcHexData.top = rcRectClient.top ;
rcHexData.right = rcRectClient.right / 2 + 60;
rcHexData.bottom = rcRectClient.bottom - 10;
if( rcHexData.Width() % 20 != 0 )
rcHexData.right -= rcHexData.Width() % 20;
nMaxX = rcHexData.Width() / 20;
// data
rcCharData.left = rcRectClient.right / 2 + 70;
rcCharData.top = rcRectClient.top ;
rcCharData.right = rcRectClient.right;
rcCharData.bottom = rcRectClient.bottom - 10;
if( rcCharData.Width() % 20 != 0 )
rcCharData.right -= rcCharData.Width() % 20;
//adresse
rcNumData.left = rcRectClient.left+40;
rcNumData.top = rcRectClient.top;
rcNumData.right = rcRectClient.right / 2 + 185;
rcNumData.bottom = rcRectClient.bottom - 10;
if( rcNumData.Width() % 20 !=0)
rcNumData.right -= rcNumData.Width() % 20;
// handle the mouse input
if( m_ptMouse.x != -1 )
{ BOOL fValid = TRUE;
if( rcCharData.PtInRect( m_ptMouse ) )
{
m_ptMouse.x -= rcCharData.left;
m_ptMouse.y -= rcCharData.top;
} else if( rcHexData.PtInRect( m_ptMouse ) )
{
m_ptMouse.x -= rcHexData.left;
m_ptMouse.y -= rcHexData.top;
} else
fValid = FALSE;
if( fValid )
{
int nX = ( m_ptMouse.x - ( m_ptMouse.x % 20 ) ) / 20;
int nY = ( m_ptMouse.y - ( m_ptMouse.y % 20 ) ) / 20;
int nSelAdd = nX + ( nY * m_nLineLength ) + m_nVisStart;
if( !m_fDraggingMouse )
m_nCurSel = nSelAdd;
m_nCurSelEnd = nSelAdd;
}
}
CRect rcOut;
unsigned int nAddX;
//write out the adress buffer
CString szOut;
rcOut = rcNumData;
nAddX= 0;
const int v=100;
int z=0;
int Daten[v];
for(int s=0; s <=v;s++)
{
Daten[s]=z;
z += m_nLineLength-1;
}
for(int j=0; j < v; j++)
{
if( j != 0)
{
rcOut.top += 20;
}
szOut.Format( "%08xh:", Daten[j]);
szOut.MakeUpper();
pMemDC->DrawText( szOut , &rcOut, DT_LEFT | DT_NOCLIP );
}
// write out the data buffer
rcOut = rcCharData;
nAddX = 0;
LPTSTR pData = pDoc->m_szDataBuffer.GetBuffer( pDoc->m_nBufferLength );
for( i=m_nVisStart; i < m_nVisEnd; i++ )
{
//TRACE("m_nVisStart: %d m_nVisEnd: %d\n",m_nVisStart,m_nVisEnd);
// if it is over, increment our y
if( ( i - m_nVisStart ) != 0 && ( i - m_nVisStart ) % nMaxX == 0 )
{
nAddX = 0;
rcOut.top += 20;
}
// make the addition
rcOut.left = rcCharData.left + nAddX;
// fill behind current selection
if( ( i >= m_nCurSel && i <= m_nCurSelEnd ) || ( i >= m_nCurSelEnd && i <= m_nCurSel ) )
{
pMemDC->SetBkColor( RGB( 220, 220, 220 ) );
} else
{
pMemDC->SetBkColor( GetSysColor( COLOR_WINDOW ) );
}
// draw the text
if( pData[i] )
pMemDC->DrawText( pData[i], &rcOut, DT_LEFT | DT_NOCLIP );
// add
nAddX += 17;
}
// write out the data buffer in hex
rcOut = rcHexData;
nAddX = 0;
pData = pDoc->m_szDataBuffer.GetBuffer( pDoc->m_nBufferLength );
for( i=m_nVisStart; i < m_nVisEnd - 1; i++ )
{
// if it is over, increment our y
if( ( i - m_nVisStart ) != 0 && ( ( i - m_nVisStart ) % nMaxX ) == 0 )
{
nAddX = 0;
rcOut.top += 20;
}
// make the addition
rcOut.left = rcHexData.left + nAddX;
// fill behind current selection
if( ( i >= m_nCurSel && i <= m_nCurSelEnd ) || ( i >= m_nCurSelEnd && i <= m_nCurSel ) )
{
pMemDC->SetBkColor( RGB( 220, 220, 220 ) );
} else
{
pMemDC->SetBkColor( GetSysColor( COLOR_WINDOW ) );
}
// draw the text
szOut.Format( "%02x", (unsigned char)pData[i] );
szOut.MakeUpper();
pMemDC->DrawText( szOut, &rcOut, DT_LEFT | DT_NOCLIP );
// add
nAddX += 17;
}
// reset the old object
if( pOldObj )
pMemDC->SelectObject( pOldObj );
// copy to the real device context
pDC->BitBlt( 0, 0, rcRectClient.right, rcRectClient.bottom, pMemDC, 0, 0, SRCCOPY );
// restore dc
if( pOldBitmap )
pMemDC->SelectObject( pOldBitmap );
bMemBMP.DeleteObject();
pDC->RestoreDC( nSavedDC );
}
void CHexEditorView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
UpdateScrollbars();
}
/////////////////////////////////////////////////////////////////////////////
// CHexEditorView printing
BOOL CHexEditorView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
//return DoPreparePrinting(pInfo);
// WILL BE IN NEXT VERSION
MessageBox( "Printing Not Yet Implemented" );
return FALSE;
}
void CHexEditorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHexEditorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHexEditorView diagnostics
#ifdef _DEBUG
void CHexEditorView::AssertValid() const
{
CScrollView::AssertValid();
}
void CHexEditorView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CHexEditorDoc* CHexEditorView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHexEditorDoc)));
return (CHexEditorDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHexEditorView message handlers
void CHexEditorView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
BOOL fInvalidate = FALSE;
BOOL fErase = FALSE;
if( nChar == VK_LEFT )
{
if( m_nCurSel > 0 ) m_nCurSelEnd = --m_nCurSel;
fInvalidate = TRUE;
}
if( nChar == VK_RIGHT )
{
m_nCurSelEnd = ++m_nCurSel;
if( m_nCurSel >= GetDocument()->m_nBufferLength )
m_nCurSel = GetDocument()->m_nBufferLength - 1;
fInvalidate = TRUE;
}
if( nChar == VK_UP )
{
m_nCurSel -= m_nLineLength;
if( m_nCurSel < 0 ) m_nCurSel = 0;
m_nCurSelEnd = m_nCurSel;
fInvalidate = TRUE;
}
if( nChar == VK_DOWN )
{
m_nCurSel += m_nLineLength;
if( m_nCurSel >= GetDocument()->m_nBufferLength )
m_nCurSel = GetDocument()->m_nBufferLength - 1;
m_nCurSelEnd = m_nCurSel;
fInvalidate = TRUE;
}
if( nChar == VK_DELETE || nChar == VK_BACK )
{
// error checking
if( ( nChar == VK_BACK && m_nCurSel <= 0 ) || m_nCurSel >= GetDocument()->m_nBufferLength - 1 )
return;
// delete the data
unsigned int nStart, nEnd;
GetSel( nStart, nEnd );
GetDocument()->DeleteData( nStart, nEnd - nStart + 1 );
// move the cursor
if( nChar == VK_BACK ) m_nCurSel = m_nCurSelEnd = ( nStart - 1 );
else m_nCurSelEnd = m_nCurSel = nStart;
// update scroll bars
UpdateScrollbars();
fErase = fInvalidate = TRUE;
}
if( fInvalidate )
{
MakeCursorVisible();
Invalidate( fErase );
return;
}
CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}
BOOL CHexEditorView::OnEraseBkgnd(CDC* pDC)
{
return FALSE;//CScrollView::OnEraseBkgnd(pDC);
}
void CHexEditorView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// windows doesnt natively use 32 bit data to track the pos
// so if we can, we need to get it
TRACE("VSCROLL event \n");
if( nSBCode == SB_THUMBTRACK || nSBCode == SB_THUMBPOSITION )
{
HWND hWndScroll = pScrollBar ? pScrollBar->m_hWnd : m_hWnd;
SCROLLINFO siInfo;
siInfo.cbSize = sizeof( SCROLLINFO );
siInfo.fMask = SIF_TRACKPOS;
::GetScrollInfo( hWndScroll, SB_VERT, &siInfo );
nPos = siInfo.nTrackPos;
rectpos=nPos;
TRACE("nPos= %d \n",nPos);
}
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
Invalidate( FALSE );
}
void CHexEditorView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
Invalidate( FALSE );
}
void CHexEditorView::OnLButtonDown(UINT nFlags, CPoint point)
{ TRACE("OnLButtonDown event \n");
m_ptMouse = point;
CScrollView::OnLButtonDown(nFlags, point);
Invalidate( FALSE );
}
void CHexEditorView::OnLButtonUp(UINT nFlags, CPoint point)
{
m_fDraggingMouse = FALSE;
m_ptMouse.x = m_ptMouse.y = -1;
Invalidate( FALSE );
CScrollView::OnLButtonUp(nFlags, point);
}
void CHexEditorView::OnMouseMove(UINT nFlags, CPoint point)
{ //TRACE("OnMouseMove event \n");
if( m_ptMouse.x != -1 )
{
m_fDraggingMouse = TRUE;
m_ptMouse = point;
Invalidate( FALSE );
}
CScrollView::OnMouseMove(nFlags, point);
}
void CHexEditorView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
if( cx || cy )
UpdateScrollbars();
}
void CHexEditorView::OnRButtonUp(UINT nFlags, CPoint point)
{
// load the menu
CMenu cMenu;
cMenu.LoadMenu( IDR_CONTEXT );
CMenu* pPopup = cMenu.GetSubMenu( 0 );
// convert point
ClientToScreen( &point );
// track popup menu
DWORD dwSelection = pPopup->TrackPopupMenu( (TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD ),
point.x, point.y, this );
// destroy it
pPopup->DestroyMenu();
// act on selection
if( dwSelection == ID_CONTEXT_INSERTBYTES )
GetDocument()->InsertBytes(); // use document's functionality
if( dwSelection == ID_CONTEXT_EDITINTEGER || dwSelection == ID_CONTEXT_EDITHEX )
{
// get the selection
unsigned int nStart, nEnd;
GetSel( nStart, nEnd );
// make sure they havent selected more than 4 bytes
if( nEnd + 1 - nStart > 4 )
{
MessageBox( "Too many bytes selected - max 4", "Error" );
return;
}
// edit the data
GetDocument()->EditData( nStart, nEnd, ( dwSelection == ID_CONTEXT_EDITHEX ) );
Invalidate( TRUE );
}
if( dwSelection == ID_CONTEXT_EDITSTRING )
{
// get the selection
unsigned int nStart, nEnd;
GetSel( nStart, nEnd );
// edit the data
GetDocument()->EditString( nStart, nEnd );
Invalidate( TRUE );
}
CScrollView::OnRButtonUp(nFlags, point);
}
LONG CHexEditorView :: OnWheel( UINT nFlags, LONG pValue )
{
if( nFlags & 0x0100 ) // rolled up
{//TRACE("OnWheel event \n");
OnVScroll( SB_LINEUP, 0, NULL );
}
else // rolled down
{
OnVScroll( SB_LINEDOWN, 0, NULL );
}
return 0;
}
|
|
|
|
|
I have just released 2.5F as a free version of HexEdit. Please email or see http://www.hexedit.com if you want the source code.
The shareware version is HexEdit 3.2 (but 2.5F contains all bug fixes from 3.2!)
Andrew Phillips
http://www.hexedit.com
andrew @ hexedit.com
|
|
|
|
|
Try my hex editor (http://hexedit.com). The free version includes source code using MFC.
- version 2.0 is free with source code (but requires BCG Control Bar library standard)
- version 1.1 source code compiles with Visual C++ 6 (reuqires no other libraries)
Version 1.0 had all basic features including search, compare, keystroke macros, plus
properties dialog to show value at cursor as int (8/16/32/64, signed/etc), real(IEEE/IBM) etc
edit files up to 2Gb, search/jump tools on toolbar (with history), EBCDIC, etc etc etc.
Version 1.1 added background search (in low priority thread),
Version 2.0 added calculator (integrated with macros), edit values in properties dialog
customization of keyboard, toolbars, menus, context menus etc
(See feature list http://hexedit.com/hex-edit-features.htm)
|
|
|
|
|
Nice program, trumped my little diddy. Use his.
|
|
|
|
|
Editors are supposed to be able to edit a file...
|
|
|
|
|
Eh, it probably has more problems than that. Can you blame a 15 year old? *shrug*
|
|
|
|
|
Your program is good but I think you need to upgrade it. Did you use the binary edit of VC++? it's great if your program like that!
|
|
|
|
|
Paul this was a neat project. Glad you posted it. I've posted a copy of the project that will build for those who want to take a quick look. It includes a hacked resource.h file and I updated the DSW/DSP project files so they would build the project.
http://www.darkmagic.org/mike/projects/
(look at bottom for an updated version that builds)
Michael
|
|
|
|
|
Hey, I am sorry this is taking so long. I will post a fix tomorrow so at least the current version COMPILES, and then worry about an upgraded version when I have time.
|
|
|
|
|
1) No resource.h file in zip archive
2) Executable in zip file is debug version - should be release version
3) Program uses white for background color of text, but uses default windows color for window background. Use one or the other, but not both.
4) Mousewheel scrolling causes window to be redrawn incorrectly under windows xp - background is not erased.
5) Print preview shows printout will occupy tiny area of page. If feature is not implemented, delete menu item.
6) Lots of flickering when scrolling - write to memory DC instead of screen directly.
7) Lots of signed/unsigned comparison warnings during compile. Add casts to remove warnings.
|
|
|
|
|
1, 2 and 3) My mistake
4) I am aware, I had no mousewheel on my dev platform
5) I will remove it
6 and 7) I was lazy
I am working on a new, better version that will actually be a useful tool. Give me some time, though, I am pretty busy these days.
|
|
|
|
|
The scroll method you implemented doesn't work when scrolling with the mouse wheel (at least not on my Win98).
The display routine seems to get confused and displays the lines doubled, halved and overlapping. It looks like the background isn't erased correctly.
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|