From 93039d3958792f69b1a19ca3bf3908cd6bfc9290 Mon Sep 17 00:00:00 2001 From: caheckman <48068198+caheckman@users.noreply.github.com> Date: Wed, 29 Jul 2020 17:03:46 -0400 Subject: [PATCH] Synchronize access to ClassFileAnalysisState --- .../util/pcodeInject/InjectPayloadJava.java | 12 ++++---- .../app/util/pcodeInject/PcodeOpEmitter.java | 15 ++++++++++ .../format/ClassFileAnalysisState.java | 30 +++++++------------ 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/Ghidra/Processors/JVM/src/main/java/ghidra/app/util/pcodeInject/InjectPayloadJava.java b/Ghidra/Processors/JVM/src/main/java/ghidra/app/util/pcodeInject/InjectPayloadJava.java index d057962b08..5072d501c6 100644 --- a/Ghidra/Processors/JVM/src/main/java/ghidra/app/util/pcodeInject/InjectPayloadJava.java +++ b/Ghidra/Processors/JVM/src/main/java/ghidra/app/util/pcodeInject/InjectPayloadJava.java @@ -19,6 +19,8 @@ import java.io.IOException; import ghidra.app.plugin.processors.sleigh.PcodeEmit; import ghidra.app.plugin.processors.sleigh.SleighLanguage; +import ghidra.javaclass.format.ClassFileAnalysisState; +import ghidra.javaclass.format.ClassFileJava; import ghidra.javaclass.format.constantpool.AbstractConstantPoolInfoJava; import ghidra.program.model.lang.InjectContext; import ghidra.program.model.lang.InjectPayload; @@ -42,15 +44,15 @@ public abstract class InjectPayloadJava implements InjectPayload { } protected static AbstractConstantPoolInfoJava[] getConstantPool(Program program) { - ConstantPoolJava cPool = null; + ClassFileAnalysisState analysisState; try { - cPool = new ConstantPoolJava(program); + analysisState = ClassFileAnalysisState.getState(program); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + return null; } - return cPool.getConstantPool(); + ClassFileJava classFile = analysisState.getClassFile(); + return classFile.getConstantPool(); } @Override diff --git a/Ghidra/Processors/JVM/src/main/java/ghidra/app/util/pcodeInject/PcodeOpEmitter.java b/Ghidra/Processors/JVM/src/main/java/ghidra/app/util/pcodeInject/PcodeOpEmitter.java index 92abc2ec9d..d62c351815 100644 --- a/Ghidra/Processors/JVM/src/main/java/ghidra/app/util/pcodeInject/PcodeOpEmitter.java +++ b/Ghidra/Processors/JVM/src/main/java/ghidra/app/util/pcodeInject/PcodeOpEmitter.java @@ -1,3 +1,18 @@ +/* ### + * IP: GHIDRA + * + * 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. + */ package ghidra.app.util.pcodeInject; import java.util.ArrayList; diff --git a/Ghidra/Processors/JVM/src/main/java/ghidra/javaclass/format/ClassFileAnalysisState.java b/Ghidra/Processors/JVM/src/main/java/ghidra/javaclass/format/ClassFileAnalysisState.java index 57496e0368..a9420e794f 100644 --- a/Ghidra/Processors/JVM/src/main/java/ghidra/javaclass/format/ClassFileAnalysisState.java +++ b/Ghidra/Processors/JVM/src/main/java/ghidra/javaclass/format/ClassFileAnalysisState.java @@ -39,7 +39,6 @@ public class ClassFileAnalysisState implements AnalysisState { private Program program; private ClassFileJava classFile; // Constant-pool and method descriptions - private UniqueAddressFactory uniqueFactory; // Produces temporary registers during p-code generation private HashMap
methodMap; // Map from address to method description public ClassFileAnalysisState(Program program) throws IOException { @@ -53,8 +52,6 @@ public class ClassFileAnalysisState implements AnalysisState { MemoryByteProvider provider = new MemoryByteProvider(memory, space); BinaryReader reader = new BinaryReader(provider, false); classFile = new ClassFileJava(reader); - uniqueFactory = - new UniqueAddressFactory(program.getAddressFactory(), program.getLanguage()); } /** @@ -70,27 +67,20 @@ public class ClassFileAnalysisState implements AnalysisState { * @return the MethodInfoJava describing the method, or null if no method is found at the address */ public MethodInfoJava getMethodInfo(Address addr) { - if (methodMap == null) { - try { - buildMethodMap(); - } - catch (MemoryAccessException e) { - Msg.error(this, e.getMessage(), e); - // methodMap will be non-null but empty + synchronized (this) { + if (methodMap == null) { + try { + buildMethodMap(); + } + catch (MemoryAccessException e) { + Msg.error(this, e.getMessage(), e); + // methodMap will be non-null but empty + } } } return methodMap.get(addr); } - /** - * Generate (the address of) a new temporary register, for use when resolving injections - * during p-code generation for a Java instruction - * @return the address of the next available temporary register - */ - public Address getNextUniqueAddress() { - return uniqueFactory.getNextUniqueAddress(); - } - /** * Walk through the {@link MethodInfoJava} objects in {@link ClassFileJava} and * create a map from Address to the corresponding object @@ -114,7 +104,7 @@ public class ClassFileAnalysisState implements AnalysisState { * @param program * @returnClassFileAnalysisState for specified program instance
*/
- public static ClassFileAnalysisState getState(Program program) throws IOException {
+ public static synchronized ClassFileAnalysisState getState(Program program) throws IOException {
ClassFileAnalysisState analysisState =
AnalysisStateInfo.getAnalysisState(program, ClassFileAnalysisState.class);
if (analysisState == null) {