Removing a part of an address

Removing a part of an address

5
NewbieNewbie
5

    Nov 30, 2021#1

    Hello!

    Is there a script that, for example, jumps to the address 0x400 and removes 0x20 and so in the entire file? Is there anyone able to code such a script?

    6,602548
    Grand MasterGrand Master
    6,602548

      Nov 30, 2021#2

      It is quite easy to code an UltraEdit script to delete a byte at a specific offset in file in hex edit mode.

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Turn on hex editing mode.
         UltraEdit.activeDocument.hexOn();
         // Go to hexadecimal offset 400.
         UltraEdit.activeDocument.gotoPos(0x400);
         // Delete one byte at this offset.
         UltraEdit.activeDocument.hexDelete(1);
      }
      
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Nov 30, 2021#3

        Hello, thank you for the quick response, the script was very simple, but that was not what it was about the point is that the script would jump over the address 0x400 and remove 0x20 and so that is adrest 0x0000400 0x0000800 etc. this script only removes 1 entry and I have over 20,000 to remove.

        6,602548
        Grand MasterGrand Master
        6,602548

          Nov 30, 2021#4

          That was just an example based on the poor information provided by you. It is of course possible to embed the last two commands in a loop and use a variable for the offset incremented on each loop iteration by 0x400 with taking into account that the file offset changes on deleting a byte for all the following bytes.

          Is the file to modify a binary file at all? Or is it a text file on which a simple regular expression replace all could be also used to remove one character (not byte) after every character stream of 1023 characters?

          Well, a Perl regular expression replace all can be executed even on a binary file on using Replace in Files command.

          So to avoid wasting our time, yours and mine, it would be really good to take the time and describe as detailed as possible the byte/character deletion task. Best would be providing a small input example file with five bytes/characters to delete and an appropriate output example file on which the five bytes/characters are deleted by you manually. These two files are packed together into an 7-Zip, RAR or ZIP archive file which is attached by you to your next post. Then every person who wants to help you cannot only suggest the Perl regular expression to use or the script for the task, but can even try it out on the input example file and verify the result with the output example file.
          Best regards from an UC/UE/UES for Windows user from Austria

          5
          NewbieNewbie
          5

            Dec 01, 2021#5

            Example it is just a different offset but the principle is the same offset 0x00000800 length 0x40 next offset 0x00001040 length 0x40 next offset 0x00001880 length 0x40 e.t.c
            https://mega.nz/file/Wzp1CQBS#ZlLWJ1sUD6dBZ4d9zacDHa40t6bt7kIgxRGquzONhGI

            6,602548
            Grand MasterGrand Master
            6,602548

              Dec 01, 2021#6

              The task is still unclear for me. The RAR archive file test.rar contains just one file test.bin, there is no second file with the expected result, i.e. the first three to five deletions applied manually. I know at least now that the file is indeed a binary file. But I really need also an expected output example to really understand the task and be able to test the script. What is still unclear for me is what is the correct offset after going to offset 0x0800 and deleting 0x40 bytes. Is the next offset really 0x1040 or is it 0x1000 because of 0x40 bytes were deleted before and so the offset for the remaining bytes in the file changes by minus 0x40.

              Please note that there is the button Full Editor & Preview at bottom of a forum page which can be pressed at any time to get a preview of currently type post displayed and below the edit field with the currently typed post an area to drop files for attaching them to the post with an additional button Add files which can be used also to attach files to a post.
              Best regards from an UC/UE/UES for Windows user from Austria

              5
              NewbieNewbie
              5

                Dec 01, 2021#7

                Hello, maybe this is tricky but the script's principle is to jump to an address example 0x800 and removing 0x40 and so on in the loop until the very end of the binary file ready in the attachment
                ready1.rar (7.93 MiB)   0

                6,602548
                Grand MasterGrand Master
                6,602548

                  Dec 01, 2021#8

                  Okay, now it was clear although it looks like ready1.bin missed a deletion of 64 bytes at offset 0x3030.

                  The slow scripting solution for deleting bytes in an opened binary file resulting in lots of window updates and recording the changes on binary file opened with usage of a temporary file.

                  Code: Select all

                  if (UltraEdit.document.length > 0)  // Is any file opened?
                  {
                     // Turn on hex editing mode.
                     UltraEdit.activeDocument.hexOn();
                  
                     // Define the parameter for byte deletion in a loop.
                     var nBaseFileOffset = 0x800;
                     var nOffsetIncrement = 0x800;
                     var nBytesToDelete = 0x40;
                     var nNextFileOffset = nBaseFileOffset;
                  
                     // Go to base file offset.
                     UltraEdit.activeDocument.gotoPos(nBaseFileOffset);
                     while (UltraEdit.activeDocument.currentPos == nNextFileOffset)
                     {
                        // Delete bytes at this offset in file.
                        UltraEdit.activeDocument.hexDelete(nBytesToDelete);
                        // Increment the file offset.
                        nNextFileOffset += nOffsetIncrement;
                        // Go to next offset in file.
                        UltraEdit.activeDocument.gotoPos(nNextFileOffset);
                     }
                  }
                  
                  The fast scripting solution using a Perl regular expression replace all which is possible here because of base file offset and offset increment are identical.

                  Code: Select all

                  var sFullFileName = "";
                  if (UltraEdit.document.length > 0)  // Is any file opened?
                  {
                     if (UltraEdit.activeDocument.isExt("bin"))
                     {
                        sFullFileName = UltraEdit.activeDocument.path;
                     }
                  }
                  if (!sFullFileName.length)
                  {
                     sFullFileName = "C:\\Temp\\test.bin";
                  }
                  UltraEdit.perlReOn();
                  UltraEdit.frInFiles.regExp=true;
                  UltraEdit.frInFiles.filesToSearch=0;
                  UltraEdit.frInFiles.directoryStart="";
                  UltraEdit.frInFiles.searchInFilesTypes=sFullFileName;
                  UltraEdit.frInFiles.matchCase=true;
                  UltraEdit.frInFiles.matchWord=false;
                  UltraEdit.frInFiles.useEncoding=false;
                  UltraEdit.frInFiles.unicodeSearch=false;
                  UltraEdit.frInFiles.searchSubs=false;
                  UltraEdit.frInFiles.preserveCase=false;
                  UltraEdit.frInFiles.ignoreHiddenSubs=false;
                  UltraEdit.frInFiles.openMatchingFiles=false;
                  UltraEdit.frInFiles.logChanges=true;
                  UltraEdit.frInFiles.replace("(?s).{2048}\\K.{64}","");
                  
                  If this script should be used on active file, it must be opened with usage of a temporary file as otherwise the replace in files cannot modify the opened file. This script can be simplified with an always fixed file name with full path defined in the script to:

                  Code: Select all

                  UltraEdit.perlReOn();
                  UltraEdit.frInFiles.regExp=true;
                  UltraEdit.frInFiles.filesToSearch=0;
                  UltraEdit.frInFiles.directoryStart="";
                  UltraEdit.frInFiles.searchInFilesTypes="C:\\Temp\\test.bin";
                  UltraEdit.frInFiles.matchCase=true;
                  UltraEdit.frInFiles.matchWord=false;
                  UltraEdit.frInFiles.useEncoding=false;
                  UltraEdit.frInFiles.unicodeSearch=false;
                  UltraEdit.frInFiles.searchSubs=false;
                  UltraEdit.frInFiles.preserveCase=false;
                  UltraEdit.frInFiles.ignoreHiddenSubs=false;
                  UltraEdit.frInFiles.openMatchingFiles=false;
                  UltraEdit.frInFiles.logChanges=true;
                  UltraEdit.frInFiles.replace("(?s).{2048}\\K.{64}","");
                  
                  Best regards from an UC/UE/UES for Windows user from Austria

                  5
                  NewbieNewbie
                  5

                    Dec 01, 2021#9

                    Thank you very much for your help, I will test .