fix: allow to regenerate class code (#791)

This commit is contained in:
Skylot
2019-12-13 18:19:12 +00:00
parent ef5da49bc0
commit 1c6e51f8b2
4 changed files with 70 additions and 14 deletions
@@ -40,7 +40,7 @@ import jadx.core.utils.exceptions.DecodeException;
import jadx.core.utils.exceptions.JadxRuntimeException;
import static jadx.core.dex.nodes.ProcessState.LOADED;
import static jadx.core.dex.nodes.ProcessState.UNLOADED;
import static jadx.core.dex.nodes.ProcessState.NOT_LOADED;
public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
private static final Logger LOG = LoggerFactory.getLogger(ClassNode.class);
@@ -262,23 +262,33 @@ public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
}
}
public synchronized ICodeInfo decompile() {
public ICodeInfo decompile() {
return decompile(true);
}
public ICodeInfo getCode() {
return decompile(true);
}
public ICodeInfo reloadCode() {
return decompile(false);
}
private synchronized ICodeInfo decompile(boolean searchInCache) {
ICodeCache codeCache = root().getCodeCache();
ClassNode topParentClass = getTopParentClass();
String clsRawName = topParentClass.getRawName();
ICodeInfo code = codeCache.get(clsRawName);
if (code != null) {
return code;
if (searchInCache) {
ICodeInfo code = codeCache.get(clsRawName);
if (code != null) {
return code;
}
}
ICodeInfo codeInfo = ProcessClass.generateCode(topParentClass);
codeCache.add(clsRawName, codeInfo);
return codeInfo;
}
public ICodeInfo getCode() {
return decompile();
}
@Override
public void load() {
for (MethodNode mth : getMethods()) {
@@ -300,7 +310,7 @@ public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
innerClasses.forEach(ClassNode::unload);
fields.forEach(FieldNode::unloadAttributes);
unloadAttributes();
setState(UNLOADED);
setState(NOT_LOADED);
}
private void buildCache() {
@@ -4,15 +4,13 @@ public enum ProcessState {
NOT_LOADED,
LOADED,
PROCESS_STARTED,
PROCESS_COMPLETE,
GENERATED,
UNLOADED;
PROCESS_COMPLETE;
public boolean isLoaded() {
return this != NOT_LOADED;
}
public boolean isProcessed() {
return this == PROCESS_COMPLETE || this == GENERATED || this == UNLOADED;
return this == PROCESS_COMPLETE;
}
}