mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 12:00:04 +02:00
parent
e835f91e50
commit
05108d5556
1 changed files with 41 additions and 20 deletions
|
@ -15,11 +15,12 @@
|
||||||
*/
|
*/
|
||||||
package pdb.symbolserver;
|
package pdb.symbolserver;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ import pdb.PdbUtils;
|
||||||
*/
|
*/
|
||||||
public class SymbolServerService {
|
public class SymbolServerService {
|
||||||
|
|
||||||
|
private static final int MAX_TRY_COUNT = 3;
|
||||||
private SymbolStore symbolStore; // also the first element of the symbolServers list
|
private SymbolStore symbolStore; // also the first element of the symbolServers list
|
||||||
private List<SymbolServer> symbolServers;
|
private List<SymbolServer> symbolServers;
|
||||||
|
|
||||||
|
@ -233,20 +235,7 @@ public class SymbolServerService {
|
||||||
private SymbolFileLocation ensureLocalUncompressedFile(SymbolFileLocation symbolFileLocation,
|
private SymbolFileLocation ensureLocalUncompressedFile(SymbolFileLocation symbolFileLocation,
|
||||||
TaskMonitor monitor) throws IOException, CancelledException {
|
TaskMonitor monitor) throws IOException, CancelledException {
|
||||||
if (!(symbolFileLocation.getSymbolServer() instanceof SymbolStore)) {
|
if (!(symbolFileLocation.getSymbolServer() instanceof SymbolStore)) {
|
||||||
Msg.debug(this, logPrefix() + ": copying file " + symbolFileLocation.getLocationStr() +
|
symbolFileLocation = copyRemoteToLocal(symbolFileLocation, monitor);
|
||||||
" from remote to local " + symbolStore.getName());
|
|
||||||
|
|
||||||
// copy from remote store to our main local symbol store
|
|
||||||
String remoteFilename = FilenameUtils.getName(symbolFileLocation.getPath());
|
|
||||||
try (SymbolServerInputStream symbolServerInputStream =
|
|
||||||
symbolFileLocation.getSymbolServer()
|
|
||||||
.getFileStream(symbolFileLocation.getPath(), monitor)) {
|
|
||||||
String newPath =
|
|
||||||
symbolStore.putStream(symbolFileLocation.getFileInfo(), symbolServerInputStream,
|
|
||||||
remoteFilename, monitor);
|
|
||||||
symbolFileLocation =
|
|
||||||
new SymbolFileLocation(newPath, symbolStore, symbolFileLocation.getFileInfo());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// symbolFileLocation now must be on a SymbolStore, so safe to cast
|
// symbolFileLocation now must be on a SymbolStore, so safe to cast
|
||||||
|
@ -257,8 +246,8 @@ public class SymbolServerService {
|
||||||
File temporaryExtractFile = new File(symbolStore.getAdminDir(),
|
File temporaryExtractFile = new File(symbolStore.getAdminDir(),
|
||||||
"ghidra_cab_extract_tmp_" + System.currentTimeMillis());
|
"ghidra_cab_extract_tmp_" + System.currentTimeMillis());
|
||||||
|
|
||||||
Msg.debug(this,
|
Msg.debug(this, "%s: decompressing file %s".formatted(logPrefix(),
|
||||||
logPrefix() + ": decompressing file " + symbolFileLocation.getLocationStr());
|
symbolFileLocation.getLocationStr()));
|
||||||
|
|
||||||
String originalName =
|
String originalName =
|
||||||
PdbUtils.extractSingletonCabToFile(cabFile, temporaryExtractFile, monitor);
|
PdbUtils.extractSingletonCabToFile(cabFile, temporaryExtractFile, monitor);
|
||||||
|
@ -269,13 +258,45 @@ public class SymbolServerService {
|
||||||
symbolFileLocation = new SymbolFileLocation(uncompressedPath, symbolStore,
|
symbolFileLocation = new SymbolFileLocation(uncompressedPath, symbolStore,
|
||||||
symbolFileLocation.getFileInfo());
|
symbolFileLocation.getFileInfo());
|
||||||
|
|
||||||
Msg.debug(this,
|
Msg.debug(this, "%s: new decompressed file %s".formatted(logPrefix(),
|
||||||
logPrefix() + ": new decompressed file " + symbolFileLocation.getLocationStr());
|
symbolFileLocation.getLocationStr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return symbolFileLocation;
|
return symbolFileLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SymbolFileLocation copyRemoteToLocal(SymbolFileLocation symbolFileLocation,
|
||||||
|
TaskMonitor monitor) throws CancelledException, IOException {
|
||||||
|
int tryCount = 0;
|
||||||
|
while (true) {
|
||||||
|
Msg.debug(this,
|
||||||
|
"%s try[%d]: copying file %s from remote to local %s".formatted(logPrefix(),
|
||||||
|
tryCount, symbolFileLocation.getLocationStr(), symbolStore.getName()));
|
||||||
|
|
||||||
|
// copy from remote store to our main local symbol store
|
||||||
|
String remoteFilename = FilenameUtils.getName(symbolFileLocation.getPath());
|
||||||
|
try (SymbolServerInputStream symbolServerInputStream =
|
||||||
|
symbolFileLocation.getSymbolServer()
|
||||||
|
.getFileStream(symbolFileLocation.getPath(), monitor)) {
|
||||||
|
String newPath = symbolStore.putStream(symbolFileLocation.getFileInfo(),
|
||||||
|
symbolServerInputStream, remoteFilename, monitor);
|
||||||
|
return new SymbolFileLocation(newPath, symbolStore,
|
||||||
|
symbolFileLocation.getFileInfo());
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
String msg = "%s: error copying file %s to %s: %s".formatted(logPrefix(),
|
||||||
|
symbolFileLocation.getLocationStr(), symbolStore.getName(), e.getMessage());
|
||||||
|
if (++tryCount >= MAX_TRY_COUNT) {
|
||||||
|
Msg.error(this, msg);
|
||||||
|
throw e; // failure
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow retry
|
||||||
|
Msg.warn(this, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String logPrefix() {
|
private String logPrefix() {
|
||||||
return getClass().getSimpleName();
|
return getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue