Esempio n. 1
0
BOOL ModifyHexViewData(HWND hwndHV, int nOperation, BYTE * operand, size_w nLength, int nType, BOOL fEndian)
{
	size_w start, offset;
	size_w remaining = nLength;
	size_w length	 = nLength;

	BYTE buf[0x100];

	HexView_GetSelStart(hwndHV, &start);
	offset = start;

	// turn off redraw so the cursor/display doesn't update whilst we are
	// writing data to the hexview
	SendMessage(hwndHV, WM_SETREDRAW, FALSE, 0);

	while(nLength > 0)
	{
		ULONG len = (ULONG)min(nLength, 0x100);

		// get data at current cursor position!
		if(HexView_GetData(hwndHV, offset, buf, len))
		{
			// do the operation!
			if(ModifyData(buf, len, nOperation, operand, nType, fEndian))
			{
				// write the data back to the hexview
				HexView_SetData(hwndHV, offset, buf, len);
			}
		}
		else
		{
			return FALSE;
		}

		offset += len;
		nLength -= len;
	}

	HexView_SetSelStart(hwndHV, start);
	HexView_SetSelEnd(hwndHV, start+length);

	SendMessage(hwndHV, WM_SETREDRAW, TRUE, 0);
	
	return TRUE;
}
Esempio n. 2
0
BOOL FindNext()
{
	HWND hwndHV = g_hwndHexView;
	size_w result;
	UINT options = 0;

	if(searchLen == 0 || searchValid == FALSE)
	{
		ShowFindDialog(g_hwndMain, -2);
		return FALSE;
	}

	if(g_fFindInSelection)
		options |= HVFF_SCOPE_SELECTION;

	if(g_fMatchCase == FALSE)
		options |= HVFF_CASE_INSENSITIVE;

	if(HexView_FindNext(hwndHV, &result, options))
	{
		HexView_SetSelStart(hwndHV, result);
		HexView_SetSelEnd(hwndHV, result+searchLen);
		HexView_SetCurPos(hwndHV, result+searchLen);

		ShiftWindow(g_hwndSearch, hwndHV);

		InvalidateRect(hwndHV, 0, 0);
		return TRUE;
	}
	else
	{
		MAINWND *mainWnd = (MAINWND *)GetWindowLongPtr(g_hwndMain, 0);
		UpdateProgress(mainWnd, FALSE, 0, 0);
		MessageBox(g_hwndMain, TEXT("Could not find any more data"), TEXT("HexEdit"), MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}
}
Esempio n. 3
0
LRESULT CALLBACK HighlightViewCommandHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	extern HWND g_hwndMain;

	HWND hwndHV = GetActiveHexView(g_hwndMain);

	if (msg == WM_COMMAND)
	{
		switch (LOWORD(wParam))
		{
		case IDC_HIGHLIGHT_ADD:
			HighlightDlg(NULL, NULL);
			break;
		case IDC_HIGHLIGHT_EDIT:
		{
			HWND hwndGridView = GetDlgItem(hwnd, IDC_HIGHLIGHT_GRIDVIEW);
			ULONG curSelItem = GridView_GetCurSel(hwndGridView);
			HGRIDITEM hgCurSelItem = GridView_GetItemHandle(hwndGridView, curSelItem);
			GVITEM curItem = { GVIF_PARAM, curSelItem, 0 };

			// Get the current item - param contains the HBOOKMARK for this item
			if (GridView_GetItem(hwndGridView, hgCurSelItem, &curItem) && curItem.param)
			{
				HBOOKMARK hbm = (HBOOKMARK)curItem.param;

				// Get the parent item - param contains the HWND for the hexview
				if (GridView_GetParentItem(hwndGridView, hgCurSelItem, &curItem) && curItem.param)
				{
					HWND hwndHexView = (HWND)curItem.param;

					HighlightDlg(hwndHexView, hbm);
				}
			}

			break;
		}
		case IDC_HIGHLIGHT_DELETE:
		{
			TCHAR itemText[100] = { 0 };
			HWND hwndGridView = GetDlgItem(hwnd, IDC_HIGHLIGHT_GRIDVIEW);
			ULONG curSelItem = GridView_GetCurSel(hwndGridView);
			HGRIDITEM hgCurSelItem = GridView_GetItemHandle(hwndGridView, curSelItem);
			GVITEM curItem = { GVIF_PARAM | GVIF_TEXT, curSelItem, 0 };
			curItem.pszText = itemText;
			curItem.cchTextMax = ARRAYSIZE(itemText);

			// Get the current item - param contains the HBOOKMARK for this item
			if (GridView_GetItem(hwndGridView, hgCurSelItem, &curItem))
			{
				if (curItem.param)
				{
					HBOOKMARK hbm = (HBOOKMARK)curItem.param;

					// Get the parent item - param contains the HWND for the hexview
					if (GridView_GetParentItem(hwndGridView, hgCurSelItem, &curItem) && curItem.param)
					{
						HWND hwndHexView = (HWND)curItem.param;

						GridView_DeleteItem(hwndGridView, hgCurSelItem);
						HexView_DelBookmark(hwndHexView, hbm);
						GridView_Update(hwndGridView);
					}
				}
				else
				{
					// This wasn't a live bookmark - it exists in a config file
					TCHAR parentText[100] = { 0 };
					curItem.pszText = parentText;
					if (GridView_GetParentItem(hwndGridView, hgCurSelItem, &curItem))
					{
						DeleteBookmarkFromConfig(parentText, itemText);
						GridView_DeleteAll(hwndGridView);
						UpdateHighlights(TRUE);
					}
				}
			}

			break;
		}
		}
		return 0;
	}

	if(msg == WM_NOTIFY)
	{
		NMGRIDVIEW *nmgv = (NMGRIDVIEW *)lParam;

		if(nmgv->hdr.code == GVN_DBLCLK)
		{
			GVITEM gvi = { GVIF_PARAM, nmgv->iItem, 0 };//nmgv->nColumn };

			if(GridView_GetParent(nmgv->hdr.hwndFrom, nmgv->hItem))
			{
				if(GridView_GetItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi))
				{
					// file is not open yet!
					if(gvi.param == 0)
					{
						TCHAR szFileName[MAX_PATH];
						gvi.mask |= GVIF_TEXT;
						gvi.pszText = szFileName;
						gvi.cchTextMax = MAX_PATH;
						
						if(GridView_GetParentItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi))
						{
							HexOpenFile(g_hwndMain, szFileName, DefaultFileMode());
						}
					}
					else
					{
						HighlightDlg(hwndHV, (HBOOKMARK)gvi.param);
					}
				}
			}
		}
		else if(nmgv->hdr.code == GVN_DELETED)
		{
			GVITEM gvi = { GVIF_PARAM, nmgv->iItem, 0 };//nmgv->nColumn };
			//HIGHLIGHT_PARAM hp;

			// get current item in gridview
			GridView_GetItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi);

			HexView_DelBookmark(hwndHV, (HBOOKMARK)gvi.param);
			return 0;
		}
		else if(nmgv->hdr.code == GVN_SELCHANGED)
		{
			GVITEM gvi = { GVIF_PARAM, nmgv->iItem, 0 };//nmgv->nColumn };
			BOOKMARK bm;

			// get the gvi.param - contains the HBOOKMARK for this bookmark entry
			if(GridView_GetItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi) && gvi.param)
			{
				HBOOKMARK hbm = (HBOOKMARK)gvi.param;

				// get parent item's param - contains HWND to the hexview
				if(GridView_GetParentItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi) && gvi.param)
				{
					// make sure the current file is active
					hwndHV = (HWND)gvi.param;
					HexSetCurFileHwnd(g_hwndMain, hwndHV);

					if(HexView_GetBookmark(hwndHV, hbm, &bm))
					{
						HexView_SetCurPos(hwndHV, bm.offset + bm.length);
						HexView_SetSelStart(hwndHV, bm.offset);
						HexView_SetSelEnd(hwndHV, bm.offset + bm.length);
						HexView_ScrollTo(hwndHV,  bm.offset + bm.length);
						InvalidateRect(hwndHV,0,0);
					}
				}
			}
			return 0;
		}
	}

	return 0;
}