Skip to content

Commit

Permalink
Parse parameters if class manager doesn't have
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebFenton committed Dec 12, 2015
1 parent 12d3fca commit ff5f4a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions smalivm/src/main/java/org/cf/smalivm/ClassManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public List<BuilderTryBlock> getTryBlocks(String methodDescriptor) {
return methodDescriptorToTryBlocks.get(methodDescriptor);
}

public boolean isFramework(String typeName) {
public boolean isFrameworkClass(String typeName) {
String className = typeName.split("->")[0];

return smaliFileFactory.isFrameworkClass(className);
Expand Down Expand Up @@ -296,7 +296,7 @@ public boolean isNativeMethod(String methodDescriptor) {
return Modifier.isNative(method.getAccessFlags());
}

public boolean isSafeFramework(String typeName) {
public boolean isSafeFrameworkClass(String typeName) {
String className = typeName.split("->")[0];

return smaliFileFactory.isSafeFrameworkClass(className);
Expand Down Expand Up @@ -344,7 +344,7 @@ private void addParameterTypes(BuilderMethod method) {
int accessFlags = method.getAccessFlags();
boolean isStatic = Modifier.isStatic(accessFlags);
if (!isStatic) {
// First "parameter" for non-static methods is instance ref
// First "parameter" for non-static methods is instance reference
parameterTypes.add(0, method.getDefiningClass());
}

Expand Down
2 changes: 1 addition & 1 deletion smalivm/src/main/java/org/cf/smalivm/opcode/InvokeOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void execute(ExecutionNode node, ExecutionContext ectx) {
// This assumes if reflection or emulation fails, not worth it to try possibly cached framework classes.
ClassManager classManager = vm.getClassManager();
if (classManager.isLocalMethod(targetMethod)) {
if (classManager.isFramework(targetMethod) && !classManager.isSafeFramework(targetMethod)) {
if (classManager.isFrameworkClass(targetMethod) && !classManager.isSafeFrameworkClass(targetMethod)) {
if (log.isDebugEnabled()) {
log.debug("Not executing unsafe local method: {}. Assuming maxiumum ambiguity.", targetMethod);
}
Expand Down
11 changes: 7 additions & 4 deletions smalivm/src/main/java/org/cf/smalivm/opcode/InvokeOpFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ private int[] buildParameterRegisters(List<String> parameterTypes, int[] registe
}

private static List<String> getParameterTypes(String methodDescriptor, boolean isStatic, ClassManager classManager) {
List<String> parameterTypes;
if (classManager.isLocalMethod(methodDescriptor) && !classManager.isFramework(methodDescriptor) || classManager
.isSafeFramework(methodDescriptor)) {
List<String> parameterTypes = null;
if (classManager.isLocalMethod(methodDescriptor) && !classManager.isFrameworkClass(methodDescriptor) || classManager
.isSafeFrameworkClass(methodDescriptor)) {
parameterTypes = classManager.getParameterTypes(methodDescriptor);
} else {
}

if (parameterTypes == null) {
// Possibly a framework class, but the method was not found.
parameterTypes = Utils.getParameterTypes(methodDescriptor);
if (!isStatic) {
parameterTypes.add(0, methodDescriptor.split("->")[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressT
String baseClassName = SmaliClassUtils.getBaseClass(arrayType);
ClassManager classManager = vm.getClassManager();
boolean useLocalClass = false;
if (classManager.isFramework(baseClassName)) {
if (classManager.isFrameworkClass(baseClassName)) {
// Create arrays of LocalInstance
useLocalClass = classManager.isSafeFramework(baseClassName);
useLocalClass = classManager.isSafeFrameworkClass(baseClassName);
} else {
useLocalClass = classManager.isLocalClass(baseClassName);
}
Expand Down
4 changes: 2 additions & 2 deletions smalivm/src/test/java/org/cf/smalivm/opcode/TestInvokeOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void setUp() {
classManager = mock(ClassManager.class);
when(vm.getClassManager()).thenReturn(classManager);
when(classManager.isLocalClass(METHOD_CLASS)).thenReturn(true);
when(classManager.isFramework(METHOD_DESCRIPTOR)).thenReturn(false);
when(classManager.isSafeFramework(METHOD_DESCRIPTOR)).thenReturn(false);
when(classManager.isFrameworkClass(METHOD_DESCRIPTOR)).thenReturn(false);
when(classManager.isSafeFrameworkClass(METHOD_DESCRIPTOR)).thenReturn(false);

methodRef = mock(MethodReference.class);
when(methodRef.getDefiningClass()).thenReturn(METHOD_CLASS);
Expand Down

0 comments on commit ff5f4a7

Please sign in to comment.