Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization #1376

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/soot_options.htm
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ <H2><A name="section_2">Input Options</A></H2>
</tt><br><tt>apk&nbsp;
</tt><br><tt>apk-class-jimple&nbsp;
</tt><tt>apk-c-j&nbsp;
</tt><br><tt>binary&nbsp;
</tt><tt>bin&nbsp;
</tt><br></td>
<td colspan="1">Sets source precedence to
<var>format</var>
Expand Down Expand Up @@ -678,6 +680,8 @@ <H2><A name="section_3">Output Options</A></H2>
</tt><tt>template&nbsp;
</tt><br><tt>a&nbsp;
</tt><tt>asm&nbsp;
</tt><br><tt>bin&nbsp;
</tt><tt>binary&nbsp;
</tt><br></td>
<td colspan="1">Set output format for Soot</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8751,6 +8751,10 @@ private Composite Input_OptionsCreate(Composite parent) {
"apk-class-jimple apk-c-j",
"\nTry to resolve classes first from .apk (Android Package) files \nfound in the Soot classpath. Fall back to .class, or .jimple \nfiles only when unable to find a class in .apk files. Never load \na .java file.",
false),
new OptionData("Binary",
"binary bin",
"\n...",
false),
};


Expand Down Expand Up @@ -9036,6 +9040,10 @@ private Composite Output_OptionsCreate(Composite parent) {
"a asm",
"\nProduce .asm files as textual bytecode representation generated \nwith the ASM back end.",
false),
new OptionData("Binary",
"bin binary",
"\n...",
false),
};


Expand Down
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
<licence-check.failOnMissingHeader>true</licence-check.failOnMissingHeader>
<asm.version>7.1</asm.version>
<kryo.version>5.0.0-RC5-SNAPSHOT</kryo.version>
<kryo-serializers.version>0.45</kryo-serializers.version>
</properties>
<build>
<finalName>sootclasses-trunk</finalName>
Expand Down Expand Up @@ -420,7 +422,16 @@
<artifactId>asm-commons</artifactId>
<version>${asm.version}</version>
</dependency>

<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>${kryo.version}</version>
</dependency>
<dependency>
<groupId>de.javakaffee</groupId>
<artifactId>kryo-serializers</artifactId>
<version>${kryo-serializers.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions src/main/generated/options/soot/AntTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ public void setsrc_prec(String arg) {
|| arg.equals( "apk" )
|| arg.equals( "apk-class-jimple" )
|| arg.equals( "apk-c-j" )
|| arg.equals( "binary" )
|| arg.equals( "bin" )
) {
addArg("-src-prec");
addArg(arg);
Expand Down Expand Up @@ -336,6 +338,8 @@ public void setoutput_format(String arg) {
|| arg.equals( "template" )
|| arg.equals( "a" )
|| arg.equals( "asm" )
|| arg.equals( "bin" )
|| arg.equals( "binary" )
) {
addArg("-output-format");
addArg(arg);
Expand Down
26 changes: 26 additions & 0 deletions src/main/generated/options/soot/options/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public static Options v() {
public static final int src_prec_apk = 5;
public static final int src_prec_apk_class_jimple = 6;
public static final int src_prec_apk_c_j = 6;
public static final int src_prec_binary = 7;
public static final int src_prec_bin = 7;
public static final int output_format_J = 1;
public static final int output_format_jimple = 1;
public static final int output_format_j = 2;
Expand Down Expand Up @@ -81,6 +83,8 @@ public static Options v() {
public static final int output_format_template = 16;
public static final int output_format_a = 17;
public static final int output_format_asm = 17;
public static final int output_format_bin = 18;
public static final int output_format_binary = 18;
public static final int java_version_default = 1;
public static final int java_version_1_1 = 2;
public static final int java_version_1 = 2;
Expand Down Expand Up @@ -398,6 +402,16 @@ else if (false
}
src_prec = src_prec_apk_c_j;
}
else if (false
|| value.equals("binary")
|| value.equals("bin")
) {
if (src_prec != 0 && src_prec != src_prec_bin) {
G.v().out.println("Multiple values given for option " + option);
return false;
}
src_prec = src_prec_bin;
}
else {
G.v().out.println(String.format("Invalid value %s given for option -%s", option, value));
return false;
Expand Down Expand Up @@ -646,6 +660,16 @@ else if (false
}
output_format = output_format_asm;
}
else if (false
|| value.equals("bin")
|| value.equals("binary")
) {
if (output_format != 0 && output_format != output_format_binary) {
G.v().out.println("Multiple values given for option " + option);
return false;
}
output_format = output_format_binary;
}
else {
G.v().out.println(String.format("Invalid value %s given for option -%s", option, value));
return false;
Expand Down Expand Up @@ -1672,6 +1696,7 @@ public String getUsage() {
+ padVal("java", "Favour Java files as Soot source")
+ padVal("apk", "Favour APK files as Soot source")
+ padVal("apk-class-jimple apk-c-j", "Favour APK files as Soot source, disregard Java files")
+ padVal("binary bin", "Favour binary serialization files as Soot source.")
+ padOpt("-full-resolver", "Force transitive resolving of referenced classes")
+ padOpt("-allow-phantom-refs", "Allow unresolved classes; may cause errors")
+ padOpt("-allow-phantom-elms", "Allow phantom methods and fields in non-phantom classes")
Expand Down Expand Up @@ -1701,6 +1726,7 @@ public String getUsage() {
+ padVal("d dava", "Produce dava-decompiled .java files")
+ padVal("t template", "Produce .java files with Jimple templates.")
+ padVal("a asm", "Produce .asm files as textual bytecode representation generated with the ASM back end.")
+ padVal("bin binary", "Produce .bin files as binary serialized representation of the current Scene.")
+ padOpt("-java-version ARG", "Force Java version of bytecode generated by Soot.")
+ padVal("default", "Let Soot determine Java version of generated bytecode.")
+ padVal("1.1 1", "Force Java 1.1 as output version.")
Expand Down
14 changes: 14 additions & 0 deletions src/main/generated/singletons/soot/Singletons.java
Original file line number Diff line number Diff line change
Expand Up @@ -2427,4 +2427,18 @@ public soot.jbco.jimpleTransformations.FieldRenamer soot_jbco_jimpleTransformati
protected void release_soot_jbco_jimpleTransformations_FieldRenamer() {
instance_soot_jbco_jimpleTransformations_FieldRenamer = null;
}

private soot.serialization.SootSerializer instance_soot_serialization_SootSerializer;
public soot.serialization.SootSerializer soot_serialization_SootSerializer() {
if (instance_soot_serialization_SootSerializer == null) {
synchronized (this) {
if (instance_soot_serialization_SootSerializer == null)
instance_soot_serialization_SootSerializer = new soot.serialization.SootSerializer(g);
}
}
return instance_soot_serialization_SootSerializer;
}
protected void release_soot_serialization_SootSerializer() {
instance_soot_serialization_SootSerializer = null;
}
}
14 changes: 7 additions & 7 deletions src/main/java/soot/AbstractSootFieldRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class AbstractSootFieldRef implements SootFieldRef {
private static final Logger logger = LoggerFactory.getLogger(AbstractSootFieldRef.class);

public AbstractSootFieldRef(SootClass declaringClass, String name, Type type, boolean isStatic) {
this.declaringClass = declaringClass;
this.declaringClass = declaringClass.getType();
this.name = name;
this.type = type;
this.isStatic = isStatic;
Expand All @@ -54,14 +54,14 @@ public AbstractSootFieldRef(SootClass declaringClass, String name, Type type, bo
}
}

private final SootClass declaringClass;
private final RefType declaringClass;
private final String name;
private final Type type;
private final boolean isStatic;

@Override
public SootClass declaringClass() {
return declaringClass;
return declaringClass.getSootClass();
}

@Override
Expand All @@ -81,7 +81,7 @@ public boolean isStatic() {

@Override
public String getSignature() {
return SootField.getSignature(declaringClass, name, type);
return SootField.getSignature(declaringClass.getSootClass(), name, type);
}

public class FieldResolutionFailedException extends ResolutionFailedException {
Expand Down Expand Up @@ -119,7 +119,7 @@ private SootField checkStatic(SootField ret) {
}

private SootField resolve(StringBuffer trace) {
SootClass cl = declaringClass;
SootClass cl = declaringClass.getSootClass();
while (true) {
if (trace != null) {
trace.append("Looking in " + cl + " which has fields " + cl.getFields() + "\n");
Expand Down Expand Up @@ -190,7 +190,7 @@ else if (Scene.v().allowsPhantomRefs() && cl.isPhantom()) {
synchronized (declaringClass) {
// Be careful: Another thread may have already created this
// field in the meantime, so better check twice.
SootField clField = declaringClass.getFieldByNameUnsafe(name);
SootField clField = declaringClass.getSootClass().getFieldByNameUnsafe(name);
if (clField != null) {
if (clField.getType().equals(type)) {
return checkStatic(clField);
Expand All @@ -199,7 +199,7 @@ else if (Scene.v().allowsPhantomRefs() && cl.isPhantom()) {
}
} else {
// Add the new phantom field
declaringClass.addField(sf);
declaringClass.getSootClass().addField(sf);
return sf;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/soot/Body.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
public abstract class Body extends AbstractHost implements Serializable {
private static final Logger logger = LoggerFactory.getLogger(Body.class);
/** The method associated with this Body. */
protected transient SootMethod method = null;
protected SootMethod method = null;

/** The chain of locals for this Body. */
protected Chain<Local> localChain = new HashChain<Local>();
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/soot/PackManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* #L%
*/

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;

import heros.solver.CountingThreadPoolExecutor;

import java.io.File;
Expand Down Expand Up @@ -119,6 +122,7 @@
import soot.jimple.toolkits.thread.synchronization.LockAllocator;
import soot.jimple.toolkits.typing.TypeAssigner;
import soot.options.Options;
import soot.serialization.BinaryBackend;
import soot.shimple.Shimple;
import soot.shimple.ShimpleBody;
import soot.shimple.ShimpleTransformer;
Expand Down Expand Up @@ -152,6 +156,8 @@ public class PackManager {
private JarOutputStream jarFile = null;
protected DexPrinter dexPrinter = null;

private Supplier<BinaryBackend> binaryBackend = Suppliers.memoize(() -> new BinaryBackend());

public PackManager(Singletons.Global g) {
PhaseOptions.v().setPackManager(this);
init();
Expand Down Expand Up @@ -939,6 +945,8 @@ private void runBodyPacks(SootClass c) {
produceGrimp = Options.v().via_grimp();
produceBaf = !produceGrimp;
break;
case Options.output_format_binary:
break;
default:
throw new RuntimeException();
}
Expand Down Expand Up @@ -1169,6 +1177,9 @@ protected void writeClass(SootClass c) {
case Options.output_format_asm:
createASMBackend(c).generateTextualRepresentation(writerOut);
break;
case Options.output_format_binary:
binaryBackend.get().write(c,streamOut);
break;
default:
throw new RuntimeException();
}
Expand All @@ -1182,7 +1193,7 @@ protected void writeClass(SootClass c) {
jarFile.closeEntry();
}
} catch (IOException e) {
throw new CompilationDeathException("Cannot close output file " + fileName);
throw new CompilationDeathException("Cannot close output file " + fileName, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/soot/RefType.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String getClassName() {
return className;
}

private volatile SootClass sootClass;
private volatile transient SootClass sootClass;
private AnySubType anySubType;

private RefType(String className) {
Expand Down
Loading