Skip to content

Commit 97dc133

Browse files
committed
GT-3261_emteere code review, changed checkCanceled()
1 parent 48aaa69 commit 97dc133

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
2424
import ghidra.app.util.bin.format.macho.MachConstants;
2525
import ghidra.app.util.bin.format.macho.MachHeader;
26-
import ghidra.app.util.bin.format.macho.dyld.DyldCacheAccelerateInfo;
2726
import ghidra.app.util.importer.MessageLog;
2827
import ghidra.program.flatapi.FlatProgramAPI;
2928
import ghidra.program.model.address.Address;
@@ -75,7 +74,7 @@ private void initSymbolTableCommand(FactoryBundledWithBinaryReader reader, MachH
7574
long index = reader.getPointerIndex();
7675

7776
reader.setPointerIndex(header.getStartIndexInProvider() + symoff);
78-
77+
7978
List<NList> nlistList = new ArrayList<>(nsyms);
8079
long startIndex = header.getStartIndexInProvider();
8180
boolean is32bit = header.is32bit();
@@ -85,16 +84,16 @@ private void initSymbolTableCommand(FactoryBundledWithBinaryReader reader, MachH
8584
nlistList.add(NList.createNList(reader, is32bit));
8685
}
8786
// sort the entries by the index in the string table, so don't jump around reading
88-
List<NList> sortedList = nlistList.stream()
89-
.sorted((o1,o2)-> o1.getStringTableIndex() - o2.getStringTableIndex())
90-
.collect(Collectors.toList());
87+
List<NList> sortedList = nlistList.stream().sorted(
88+
(o1, o2) -> o1.getStringTableIndex() - o2.getStringTableIndex()).collect(
89+
Collectors.toList());
9190

9291
// initialize the NList strings from string table
9392
long stringTableOffset = stroff;
94-
sortedList.forEach(entry -> {
95-
entry.initString(reader, stringTableOffset);
96-
symbols.add(entry);
97-
} );
93+
for (NList nList : sortedList) {
94+
nList.initString(reader, stringTableOffset);
95+
symbols.add(nList);
96+
}
9897

9998
reader.setPointerIndex(index);
10099
}

Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldCacheLocalSymbolsInfo.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121
import java.util.stream.Collectors;
22-
import java.util.stream.Stream;
2322

2423
import generic.continues.RethrowContinuesFactory;
2524
import ghidra.app.util.bin.BinaryReader;
@@ -30,10 +29,7 @@
3029
import ghidra.app.util.bin.format.macho.commands.NList;
3130
import ghidra.app.util.importer.MessageLog;
3231
import ghidra.program.model.address.Address;
33-
import ghidra.program.model.data.CategoryPath;
34-
import ghidra.program.model.data.DataType;
35-
import ghidra.program.model.data.DataUtilities;
36-
import ghidra.program.model.data.StructureDataType;
32+
import ghidra.program.model.data.*;
3733
import ghidra.program.model.listing.Data;
3834
import ghidra.program.model.listing.Program;
3935
import ghidra.program.model.util.CodeUnitInsertionException;
@@ -124,7 +120,7 @@ public void markup(Program program, Address localSymbolsInfoAddr, TaskMonitor mo
124120
public List<NList> getNList() {
125121
return nlistList;
126122
}
127-
123+
128124
/**
129125
* Gets the {@link List} of {@link DyldCacheLocalSymbolsEntry}s.
130126
*
@@ -149,12 +145,11 @@ public DataType toDataType() throws DuplicateNameException, IOException {
149145
return struct;
150146
}
151147

152-
private void parseNList(MessageLog log, TaskMonitor monitor)
153-
throws CancelledException {
148+
private void parseNList(MessageLog log, TaskMonitor monitor) throws CancelledException {
154149
FactoryBundledWithBinaryReader nListReader = new FactoryBundledWithBinaryReader(
155150
RethrowContinuesFactory.INSTANCE, reader.getByteProvider(), reader.isLittleEndian());
156151
monitor.setMessage("Parsing DYLD nlist symbol table...");
157-
monitor.initialize(nlistCount*2);
152+
monitor.initialize(nlistCount * 2);
158153
nListReader.setPointerIndex(startIndex + nlistOffset);
159154
try {
160155

@@ -164,18 +159,17 @@ private void parseNList(MessageLog log, TaskMonitor monitor)
164159
monitor.incrementProgress(1);
165160
}
166161
// sort the entries by the index in the string table, so don't jump around reading
167-
List<NList> sortedList = nlistList.stream()
168-
.sorted((o1,o2)-> o1.getStringTableIndex() - o2.getStringTableIndex())
169-
.collect(Collectors.toList());
162+
List<NList> sortedList = nlistList.stream().sorted(
163+
(o1, o2) -> o1.getStringTableIndex() - o2.getStringTableIndex()).collect(
164+
Collectors.toList());
170165

171166
// initialize the NList strings from string table
172167
long stringTableOffset = startIndex + stringsOffset;
173-
sortedList.forEach(entry -> {
174-
if (!monitor.isCancelled()) {
175-
entry.initString(nListReader, stringTableOffset);
176-
monitor.incrementProgress(1);
177-
}
178-
} );
168+
for (NList nList : sortedList) {
169+
monitor.checkCanceled();
170+
monitor.incrementProgress(1);
171+
nList.initString(nListReader, stringTableOffset);
172+
}
179173
}
180174
catch (IOException e) {
181175
log.appendMsg(DyldCacheAccelerateInfo.class.getSimpleName(), "Failed to parse nlist.");
@@ -206,8 +200,8 @@ private void markupNList(Program program, Address localSymbolsInfoAddr, TaskMoni
206200
try {
207201
Address addr = localSymbolsInfoAddr.add(nlistOffset);
208202
for (NList nlist : nlistList) {
209-
Data d = DataUtilities.createData(program, addr, nlist.toDataType(), -1,
210-
false, DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
203+
Data d = DataUtilities.createData(program, addr, nlist.toDataType(), -1, false,
204+
DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
211205
addr = addr.add(d.getLength());
212206
monitor.checkCanceled();
213207
monitor.incrementProgress(1);

0 commit comments

Comments
 (0)