Skip to content

Commit

Permalink
modify JimpleStringAnalysisInputLocation instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
sahilagichani14 committed Nov 6, 2024
1 parent 7649be5 commit 58fa5b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class JimpleStringAnalysisInputLocation implements AnalysisInputLocation

@Nonnull final Path path = Paths.get("only-in-memory.jimple");
@Nonnull final List<BodyInterceptor> bodyInterceptors;
@Nonnull private final OverridingClassSource classSource;
@Nonnull final SourceType sourceType;
private String jimpleFileContents;

public JimpleStringAnalysisInputLocation(@Nonnull String jimpleFileContents) {
this(jimpleFileContents, SourceType.Application, Collections.emptyList());
Expand All @@ -59,34 +59,37 @@ public JimpleStringAnalysisInputLocation(
@Nonnull String jimpleFileContents,
@Nonnull SourceType sourceType,
@Nonnull List<BodyInterceptor> bodyInterceptors) {
this.jimpleFileContents = jimpleFileContents;
this.bodyInterceptors = bodyInterceptors;
this.sourceType = sourceType;
}

private OverridingClassSource getOverridingClassSource(
String jimpleFileContents, List<BodyInterceptor> bodyInterceptors, View view) {
final @Nonnull OverridingClassSource classSource;
try {
JimpleConverter jimpleConverter = new JimpleConverter();
classSource =
jimpleConverter.run(
CharStreams.fromString(jimpleFileContents),
this,
path,
bodyInterceptors,
new JimpleView(this));
CharStreams.fromString(jimpleFileContents), this, path, bodyInterceptors, view);
} catch (Exception e) {
throw new IllegalArgumentException("No valid Jimple given.", e);
}
return classSource;
}

@Nonnull
@Override
public Optional<? extends SootClassSource> getClassSource(
@Nonnull ClassType type, @Nonnull View view) {
return Optional.of(classSource);
return Optional.of(getOverridingClassSource(jimpleFileContents, bodyInterceptors, view));
}

@Nonnull
@Override
public Collection<? extends SootClassSource> getClassSources(@Nonnull View view) {
return Collections.singletonList(classSource);
return Collections.singletonList(
getOverridingClassSource(jimpleFileContents, bodyInterceptors, view));
}

@Nonnull
Expand All @@ -101,8 +104,9 @@ public List<BodyInterceptor> getBodyInterceptors() {
return bodyInterceptors;
}

/** This is expensive, don't use in production code. Use it only for test case for convenience. */
@Nonnull
public ClassType getClassType() {
return classSource.getClassType();
public ClassType getClassType(@Nonnull View view) {
return getOverridingClassSource(jimpleFileContents, bodyInterceptors, view).getClassType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public void test() {
new JimpleStringAnalysisInputLocation(methodStr);

View view = new JimpleView(Collections.singletonList(analysisInputLocation));
assertTrue(view.getClass(analysisInputLocation.getClassType()).isPresent());
assertTrue(view.getClass(analysisInputLocation.getClassType(view)).isPresent());

MethodSignature methodSig =
view.getIdentifierFactory()
.getMethodSignature(
analysisInputLocation.getClassType(),
analysisInputLocation.getClassType(view),
"banana",
VoidType.getInstance(),
Collections.emptyList());
Expand Down

0 comments on commit 58fa5b7

Please sign in to comment.