/* ### * IP: GHIDRA * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // This script condenses all sequences of the current byte in current memory block only // minimum length of 5 // does not condense into new memory blocks // does not overwrite previously defined code or memory // does not condense into newly referenced areas //@category Analysis import ghidra.app.script.GhidraScript; import ghidra.program.model.address.Address; import ghidra.program.model.data.AlignmentDataType; import ghidra.program.model.listing.Listing; import ghidra.program.model.mem.MemoryBlock; import ghidra.program.model.symbol.SymbolTable; /** * Script to condense all undefined sequences matching the current byte (minimum length 5)in the current memory * block into byte arrays */ public class CondenseAllRepeatingBytes extends GhidraScript { @Override public void run() throws Exception { if (currentAddress == null) { println("No Location."); return; } Listing listing = currentProgram.getListing(); Address currentAddr = currentAddress; MemoryBlock memoryBlock = currentProgram.getMemory().getBlock(currentAddr); SymbolTable st = currentProgram.getSymbolTable(); if(memoryBlock.isInitialized()){ byte repeatingByte = currentProgram.getMemory().getByte(currentAddr); String repStringNo0x = Integer.toHexString(repeatingByte & 0xff); println("Condensing all runs of 5 or more " + repStringNo0x + "'s in the " + memoryBlock.getName() + " memory block."); int minRepeatLen = 5; byte[] repeatingBytes = new byte [minRepeatLen]; for(int i=0;i