GP-2941 better defined string iterator

Don't iterate arrays that can't contain a string.
When iterating a struct, only look at defined fields.
Should address issues #8134, #5726, #3498
This commit is contained in:
dev747368 2025-05-15 16:20:27 -04:00
parent a1b6084c88
commit c70de2b590
11 changed files with 442 additions and 81 deletions

View file

@ -4,9 +4,9 @@
* 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.
@ -20,8 +20,7 @@ import ghidra.app.script.GhidraScript;
import ghidra.program.model.data.StringDataInstance;
import ghidra.program.model.data.TranslationSettingsDefinition;
import ghidra.program.model.listing.Data;
import ghidra.program.util.DefinedDataIterator;
import util.CollectionUtils;
import ghidra.program.util.DefinedStringIterator;
public class TranslateStringsScript extends GhidraScript {
@ -40,8 +39,7 @@ public class TranslateStringsScript extends GhidraScript {
int count = 0;
monitor.initialize(currentProgram.getListing().getNumDefinedData());
monitor.setMessage("Translating strings");
for (Data data : CollectionUtils.asIterable(
DefinedDataIterator.definedStrings(currentProgram, currentSelection))) {
for (Data data : DefinedStringIterator.forProgram(currentProgram, currentSelection)) {
if (monitor.isCancelled()) {
break;
}