mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-01 02:59:00 +08:00
GP-0: Fix some tests (mock.slaspec, register count)
This commit is contained in:
+2
-1
@@ -53,7 +53,8 @@ public enum TraceObjectInterfaceUtils {
|
||||
List<TraceObjectInterfaceFactory> instances =
|
||||
ClassSearcher.getInstances(TraceObjectInterfaceFactory.class);
|
||||
if (instances.isEmpty()) {
|
||||
Msg.warn(this, "ClassSearcher not active, yet. Falling back to built-ins");
|
||||
Msg.warn(this, "ClassSearcher not active, yet. " +
|
||||
"Falling back to built-in TraceObjectInterfaces.");
|
||||
instances = List.of(new BuiltinTraceObjectInterfaceFactory());
|
||||
}
|
||||
mapByClass = instances
|
||||
|
||||
+19
-8
@@ -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.
|
||||
@@ -32,16 +32,24 @@ import ghidra.util.Msg;
|
||||
import resources.ResourceManager;
|
||||
|
||||
public class SleighLanguageHelper {
|
||||
|
||||
private static SleighLanguage MOCK_BE_64_LANGUAGE;
|
||||
|
||||
private static ResourceFile getResourceFile(String name) {
|
||||
URL url = ResourceManager.getResource(name);
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
return new ResourceFile(url.getPath());
|
||||
ResourceFile maybeInJar = new ResourceFile(url.toExternalForm());
|
||||
ResourceFile notInJar = new ResourceFile(maybeInJar.getFile(true));
|
||||
return notInJar;
|
||||
}
|
||||
|
||||
public static SleighLanguage getMockBE64Language()
|
||||
public synchronized static SleighLanguage getMockBE64Language()
|
||||
throws DecoderException, UnknownInstructionException, SAXException, IOException {
|
||||
if (MOCK_BE_64_LANGUAGE != null) {
|
||||
return MOCK_BE_64_LANGUAGE;
|
||||
}
|
||||
|
||||
ResourceFile cSpecFile = getResourceFile("mock.cpsec");
|
||||
CompilerSpecDescription cSpecDesc =
|
||||
@@ -50,6 +58,7 @@ public class SleighLanguageHelper {
|
||||
ResourceFile pSpecFile = getResourceFile("mock.pspec");
|
||||
ResourceFile slaSpecFile = getResourceFile("mock.slaspec");
|
||||
ResourceFile slaFile = getResourceFile("mock.sla");
|
||||
|
||||
if (slaFile == null || !slaFile.exists() ||
|
||||
(slaSpecFile.lastModified() > slaFile.lastModified())) {
|
||||
assertNotNull("Cannot find mock.slaspec", slaSpecFile);
|
||||
@@ -61,8 +70,8 @@ public class SleighLanguageHelper {
|
||||
catch (IOException | RecognitionException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
slaFile = getResourceFile("mock.sla");
|
||||
assertNotNull("Cannot find mock.sla (after compilation)");
|
||||
slaFile = new ResourceFile(slaSpecFile.getParentFile(), "mock.sla");
|
||||
assertTrue("Cannot find mock.sla (after compilation)", slaFile.exists());
|
||||
}
|
||||
|
||||
SleighLanguageDescription langDesc = new SleighLanguageDescription(
|
||||
@@ -74,12 +83,14 @@ public class SleighLanguageHelper {
|
||||
0, // minor version
|
||||
false, // deprecated
|
||||
new HashMap<>(), // truncatedSpaceMap
|
||||
new ArrayList<>(List.of(cSpecDesc)), new HashMap<>() // externalNames
|
||||
new ArrayList<>(List.of(cSpecDesc)), // compiler specs
|
||||
new HashMap<>() // externalNames
|
||||
);
|
||||
langDesc.setDefsFile(lDefsFile);
|
||||
langDesc.setSpecFile(pSpecFile);
|
||||
langDesc.setSlaFile(slaFile);
|
||||
|
||||
return new SleighLanguage(langDesc);
|
||||
MOCK_BE_64_LANGUAGE = new SleighLanguage(langDesc);
|
||||
return MOCK_BE_64_LANGUAGE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -30,9 +30,10 @@ import utilities.util.FileUtilities;
|
||||
*/
|
||||
|
||||
public class ResourceFile implements Comparable<ResourceFile> {
|
||||
private static final String JAR_FILE_PREFIX = "jar:file:";
|
||||
private Resource resource;
|
||||
private static Map<String, JarResource> jarRootsMap = new HashMap<>();
|
||||
private static final String FILE_PREFIX = "file:";
|
||||
private static final String JAR_FILE_PREFIX = "jar:" + FILE_PREFIX;
|
||||
private final Resource resource;
|
||||
private static final Map<String, JarResource> jarRootsMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Construct a ResourceFile that represents a normal file in the file system.
|
||||
@@ -93,7 +94,13 @@ public class ResourceFile implements Comparable<ResourceFile> {
|
||||
throw new IllegalArgumentException("Failed to open jar: " + filePath, e);
|
||||
}
|
||||
}
|
||||
resource = new FileResource(new File(absolutePath));
|
||||
else if (absolutePath.startsWith(FILE_PREFIX)) {
|
||||
String filePath = absolutePath.substring(FILE_PREFIX.length());
|
||||
resource = new FileResource(new File(filePath));
|
||||
}
|
||||
else {
|
||||
resource = new FileResource(new File(absolutePath));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -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.
|
||||
@@ -563,7 +563,7 @@ public class DebuggerTraceRegistersProviderTest extends AbstractDebuggerRegister
|
||||
waitForDialogComponent(DebuggerAvailableRegistersDialog.class);
|
||||
|
||||
List<AvailableRegisterRow> modelData = dialog.availableTableModel.getModelData();
|
||||
assertEquals(52, modelData.size());
|
||||
assertEquals(getPlatform().getLanguage().getRegisters().size(), modelData.size());
|
||||
AvailableRegisterRow pcAvail =
|
||||
modelData.stream().filter(r -> r.getRegister() == pc).findFirst().orElse(null);
|
||||
assertNotNull(pcAvail);
|
||||
|
||||
Reference in New Issue
Block a user