Skip to content

Commit

Permalink
Clean up safe and framework classes
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebFenton committed Dec 13, 2015
1 parent eaa3363 commit 367f4a0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions smalivm/src/main/java/org/cf/smalivm/MethodReflector.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public static boolean isSafe(String typeDescriptor) {
return false;
}

public static boolean isUnsafeMethod(String methodDescriptor) {
return !UnsafeMethods.contains(methodDescriptor);
}

private static void loadSafeClasses() throws IOException {
// Methods from safe classes must not have any side effects, e.g. any IO.
List<String> lines = ConfigurationLoader.loadConfig(SAFE_CLASSES_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.instruction.formats.Instruction22c;
import org.jf.dexlib2.util.ReferenceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NewArrayOpFactory implements OpFactory {

private static final Logger log = LoggerFactory.getLogger(NewArrayOpFactory.class.getSimpleName());

@Override
public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) {
MethodLocation child = Utils.getNextLocation(location, addressToLocation);
Expand All @@ -27,7 +31,11 @@ public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressT
boolean useLocalClass = false;
if (classManager.isFrameworkClass(baseClassName)) {
// Create arrays of LocalInstance
useLocalClass = classManager.isSafeFrameworkClass(baseClassName);
if (classManager.isSafeFrameworkClass(baseClassName)) {
useLocalClass = true;
} else {
log.warn("{} is framework but not safe; will treat as if it doesn't exist.", baseClassName);
}
} else {
useLocalClass = classManager.isLocalClass(baseClassName);
}
Expand Down
7 changes: 5 additions & 2 deletions smalivm/src/main/resources/safe_classes.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Methods of any classes here are considered safe to reflect.

// Numbers + Math
Ljava/lang/Boolean;
Ljava/lang/Byte;
Expand Down Expand Up @@ -27,12 +29,13 @@ Ljava/lang/StringBuilder;
Ljava/util/Comparator;
Ljava/util/Locale;
Ljava/util/Properties;
// It probably wouldn't break anything to reflect this, but it may mean
// not all execution paths are taken.
// It probably wouldn't break anything to reflect this, but it may mean not all execution paths are taken.
//Ljava/util/Random;
Ljava/util/Scanner;
Ljava/util/StringTokenizer;
Ljava/util/UUID;
Ljava/util/concurrent/TimeUnit;
// Network
Expand Down
7 changes: 6 additions & 1 deletion smalivm/src/main/resources/safe_framework_classes.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Framework;
// Methods of these classes are safe to virtual execute. This implies instantiation.
Landroid/security/Credentials;
Landroid/security/IKeyChainAliasCallback;
Landroid/security/IKeyChainAliasCallback$Stub;
Expand Down Expand Up @@ -133,3 +133,8 @@ Landroid/graphics/Paint$Cap;
Landroid/text/TextUtils$TruncateAt;

Ljava/lang/Enum;


Ljava/lang/Object;

Landroid/net/wifi/SupplicantState;
3 changes: 3 additions & 0 deletions smalivm/src/main/resources/unsafe_methods.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// It's unsafe to assume this method will always return the same value.
Ljava/lang/Math;->random()D
// No sleeping on the job please.
Ljava/util/concurrent/TimeUnit;->sleep(J)V

0 comments on commit 367f4a0

Please sign in to comment.