//------------------------------------------------ //--- 010 Editor v13.0.1 Script File // // File: ReverseBytes.1sc // Authors: Leslieyon // Version: 1.0 // Purpose: Reverse the order of bytes in a binary file, // optionally with a specified step size. // If a selection is made only the selected bytes // are modified, otherwise the whole file is modified. // Category: Binary // History: // 1.0 2023-04-28 Leslieyon: Initial release. //------------------------------------------------ RequiresVersion( 4.0 ); RequiresFile(); const int BLOCK_SIZE = 1024; uchar start_buff[BLOCK_SIZE],end_buff[BLOCK_SIZE]; quad size, pos; int i, reverse_step; // Input step value reverse_step = InputNumber( GetScriptName(), "Enter a reverse byte step:", "1" ); if( reverse_step == BAD_VALUE ) { MessageBox( idOk, GetScriptName(), "Reverse step bytes is invalid." ); return -1; } if( reverse_step > BLOCK_SIZE ) { MessageBox( idOk, GetScriptName(), "Reverse step bytes is too large." ); return -1; } // Calculate range if( GetSelSize() > 0 ) { pos = GetSelStart(); size = GetSelSize(); } else { pos = 0; size = FileSize(); } if( size % reverse_step !=0 ) { MessageBox( idOk, GetScriptName(), "Size must be divisible by Reverse step bytes." ); return -1; } // Reverse bytes for( i = 0; i < size / 2; i+=reverse_step ) { ReadBytes( start_buff, pos + i, reverse_step ); ReadBytes( end_buff, pos + size - i - reverse_step , reverse_step ); WriteBytes( start_buff, pos + size - i - reverse_step , reverse_step ); WriteBytes( end_buff, pos + i, reverse_step ); }