Skip to content

Commit 8f244b7

Browse files
committed
Notify user when types are missing in the assembler which can result in VerifyError on execution
1 parent d181f28 commit 8f244b7

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ image-io-ext-ico = "3.0.2"
2121
instrument-server = "1.6.0"
2222
jackson = "2.18.2"
2323
jakarta-annotation = "3.0.0"
24-
jasm = "77c67f6ceb"
24+
jasm = "63513d7e4e"
2525
jelf = "0.11.0"
2626
jlinker = "3.0.1"
2727
junit = "5.13.4"

recaf-core/src/main/java/software/coley/recaf/services/assembler/AbstractAssemblerPipeline.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import me.darknet.assembler.compiler.Compiler;
99
import me.darknet.assembler.compiler.CompilerOptions;
1010
import me.darknet.assembler.compiler.InheritanceChecker;
11+
import me.darknet.assembler.compiler.TypeAwareness;
1112
import me.darknet.assembler.error.Error;
1213
import me.darknet.assembler.error.Result;
1314
import me.darknet.assembler.printer.AnnotationHolder;
@@ -80,6 +81,26 @@ private void refreshContext() {
8081
@Nonnull
8182
protected abstract Compiler getCompiler();
8283

84+
@Nonnull
85+
protected TypeAwareness getTypeAwareness() {
86+
return new TypeAwareness() {
87+
@Override
88+
public boolean isAwareOf(String type) {
89+
return inheritanceGraph.getVertex(type) != null;
90+
}
91+
92+
@Override
93+
public String notifyUnknownType(String type) {
94+
// TODO: We should have 'assembler.missingtypewarning' in the lang files, but we're not in the UI module
95+
// so we can't reference it here...
96+
return "Type '" + type + "' is not present in the workspace. StackMapTable references to it will degrade to 'java/lang/Object'\n" +
97+
"Consider either:\n" +
98+
"- Adding a dependency containing the class to the workspace.\n" +
99+
"- Enabling workspace phantom generation under 'All Services > Analysis > Phantom generator'.";
100+
}
101+
};
102+
}
103+
83104
@Nonnull
84105
protected InheritanceChecker getInheritanceChecker() {
85106
return new InheritanceChecker() {
@@ -145,6 +166,7 @@ protected Result<R> compile(@Nonnull List<ASTElement> elements, @Nonnull PathNod
145166

146167
CompilerOptions<? extends CompilerOptions<?>> options = getCompilerOptions();
147168
options.version(getClassVersion(info))
169+
.awareness(getTypeAwareness())
148170
.inheritanceChecker(getInheritanceChecker());
149171

150172
if (element.type() != ElementType.CLASS) {

0 commit comments

Comments
 (0)