Tapatalk

Select and cut a block in HEX mode

Select and cut a block in HEX mode

6
NewbieNewbie
6

    Apr 10, 2014#1

    Hi, I've got a (larger) binary file, which i open in HEX mode.

    Now I want to
    a) cut away some block from the beginning of the file down to a byte at a special 1st HEX offset in the file
    b) want to keep the following code area to another 2nd HEX offset
    c) cut away the code from the 2nd HEX offset down to the end of the file

    The problem is:
    I didn't find any dialog to specify the area from offset to offset which I want to cut, like often used in any other HEX editor.
    So I have to mark the area by mouse. This is very timeconsuming until the file is scrolled to its end and the highlighting is complete. Another idea would be to click left at start byte of the area, quickly scroll down via scrollbar, SHIFT+left mouse button. Usually now the whole area should be highlighted, but somehow when using this method the highlighting of many lines below the start offset got lost again, so it is useless.

    So how to reach my goal best with UltraEdit?

    6,685587
    Grand MasterGrand Master
    6,685587

      Apr 11, 2014#2

      Press Ctrl+G to open the Hex Goto dialog and enter the second offset. Start with 0x to enter the offset in hexadecimal. Press RETURN to position the caret at this offset

      Now with caret at second offset, press Ctrl+Shift+End to select everything up to end of file from current position and press Ctrl+X to remove the bytes.

      Press Ctrl+G to open the Hex Goto dialog again, enter the first offset and press RETURN. Press Ctrl+Shift+Home to select all bytes to top of file and Ctrl+X to cut them.

      Alternatively you can use Hex Goto and Edit - HEX Functions - Hex Insert/Delete to delete X bytes from current position in file. The number of bytes must be entered in decimal.
      Best regards from an UC/UE/UES for Windows user from Austria

      6
      NewbieNewbie
      6

        Apr 11, 2014#3

        Thanks Mofi, your method works very good.

        One additional question: How to select an area from offset to offset in the middle of a file?
        As a decribed in my 1st post, when trying to reach this by mouse left click at the 1st offset. Then scroll down by using the scrollbar and SHIFT + mouse left click to the 2nd offset, the exact start of the highlighting at the 1st offset got lost for some unknown reason. (The selected area starts many lines below the 1st offset)

        6,685587
        Grand MasterGrand Master
        6,685587

          Apr 11, 2014#4

          I don't know how to select a large block in hex editing mode. Unfortunately the best method using Hex Goto with holding Shift key while clicking on button OK or hitting Shift+Return does not work.

          And according to your post it looks like UltraEdit v21.00 fails to select a very large block in hex editing mode if an internal memory block of the file is removed from memory and another block from file is loaded to memory. UltraEdit does not load the entire file to memory, it loads it only in blocks.

          However, if you just want to select a large block for deleting the bytes and not to cut to clipboard and to paste the bytes anywhere else, it is better to use the Hex Delete function. As it is not possible to enter 2 offsets in hexadecimal in Hex Insert/Delete dialog to define the range to delete, you can use an UltraEdit script for this task.

          Code: Select all

          function ExtendedHexDelete()
          {
             // Ask user of script for first offset. This is the first byte to delete.
             var sOffset1 = UltraEdit.getString("Offset of first byte to delete (in hex):",1);
          
             // Do not except an empty string or a string with
             // any character not being a hexadecimal character.
             if (sOffset1.search(/^[0-9A-Fa-f]+$/) < 0) return;
          
             // Convert the string into a number. (Supported value range unknown!)
             var nOffset1 = parseInt(sOffset1,16);
             if (isNaN(nOffset1)) return;
          
             // Same as above for second offset. This is the first byte outside the block to keep.
             var sOffset2 = UltraEdit.getString("Offset of first byte to keep outside block (in hex):",1);
             if (sOffset2.search(/^[0-9A-Fa-f]+$/) < 0) return;
          
             var nOffset2 = parseInt(sOffset2,16);
             if (isNaN(nOffset2)) return;
          
             // Determine beginning of block and how many bytes to delete.
             if (nOffset2 > nOffset1)      // Block "selection" in standard direction.
             {
                var nBlockBegin = nOffset1;
                var nBytesToDel = nOffset2 - nOffset1;
             }
             else if (nOffset1 > nOffset2) // Block "selection" in reverse direction.
             {
                var nBlockBegin = nOffset2;
                var nBytesToDel = nOffset1 - nOffset2;
             }
             else return;   // Nothing to delete on equal offsets.
          
             // Go to the begin of the block and delete the bytes.
             UltraEdit.activeDocument.gotoPage(nBlockBegin);
             UltraEdit.activeDocument.hexDelete(nBytesToDel);
          }
          
          if (UltraEdit.document.length > 0)  // Is any file opened?
          {
             // Is active file opened in hex editing mode.
             if (UltraEdit.activeDocument.hexMode == true)
             {
                ExtendedHexDelete();
             }
          }
          This script does most likely not work for offsets or number of bytes to delete greater than 2147483647.
          Best regards from an UC/UE/UES for Windows user from Austria