Skip to content

Commit a378e07

Browse files
committed
allow for excluding certain methods and fields
1 parent 3871978 commit a378e07

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/main/java/soot/toDex/DexPrinter.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ private void addAsClassDefItem(SootClass c) {
635635
fields = new ArrayList<Field>();
636636
for (SootField f : c.getFields()) {
637637
// We do not want to write out phantom fields
638-
if (f.isPhantom()) {
638+
if (isIgnored(f)) {
639639
continue;
640640
}
641641

@@ -1077,15 +1077,15 @@ private List<Annotation> buildMemberClassesAttribute(SootClass parentClass, Inne
10771077
return anns;
10781078
}
10791079

1080-
private Collection<Method> toMethods(SootClass clazz) {
1080+
protected Collection<Method> toMethods(SootClass clazz) {
10811081
if (clazz.getMethods().isEmpty()) {
10821082
return null;
10831083
}
10841084

10851085
String classType = SootToDexUtils.getDexTypeDescriptor(clazz.getType());
10861086
List<Method> methods = new ArrayList<Method>();
10871087
for (SootMethod sm : clazz.getMethods()) {
1088-
if (sm.isPhantom()) {
1088+
if (isIgnored(sm)) {
10891089
// Do not print method bodies for inherited methods
10901090
continue;
10911091
}
@@ -1119,7 +1119,29 @@ private Collection<Method> toMethods(SootClass clazz) {
11191119
return methods;
11201120
}
11211121

1122-
private MethodImplementation toMethodImplementation(SootMethod m) {
1122+
/**
1123+
* Checks whether the given method shall be ignored, i.e., not written out to dex
1124+
*
1125+
* @param sm
1126+
* The method to check
1127+
* @return True to ignore the method while writing the dex file, false to write it out as normal
1128+
*/
1129+
protected boolean isIgnored(SootMethod sm) {
1130+
return sm.isPhantom();
1131+
}
1132+
1133+
/**
1134+
* Checks whether the given field shall be ignored, i.e., not written out to dex
1135+
*
1136+
* @param sf
1137+
* The field to check
1138+
* @return True to ignore the field while writing the dex file, false to write it out as normal
1139+
*/
1140+
protected boolean isIgnored(SootField sf) {
1141+
return sf.isPhantom();
1142+
}
1143+
1144+
protected MethodImplementation toMethodImplementation(SootMethod m) {
11231145
if (m.isAbstract() || m.isNative()) {
11241146
return null;
11251147
}
@@ -1257,7 +1279,7 @@ private MethodImplementation toMethodImplementation(SootMethod m) {
12571279
builder.addEndLocal(registersLeft);
12581280
}
12591281

1260-
toTries(activeBody.getTraps(), stmtV, builder, labelAssinger);
1282+
toTries(activeBody.getTraps(), builder, labelAssinger);
12611283

12621284
// Make sure that all labels have been placed by now
12631285
for (Label lbl : labelAssinger.getAllLabels()) {
@@ -1497,7 +1519,7 @@ private void addRegisterAssignmentDebugInfo(LocalRegisterAssignmentInformation r
14971519
seenRegisters.put(local, register);
14981520
}
14991521

1500-
private void toInstructions(Collection<Unit> units, StmtVisitor stmtV, Set<Unit> trapReferences) {
1522+
protected void toInstructions(Collection<Unit> units, StmtVisitor stmtV, Set<Unit> trapReferences) {
15011523
// Collect all constant arguments to monitor instructions and
15021524
// pre-alloocate their registers
15031525
Set<ClassConstant> monitorConsts = new HashSet<ClassConstant>();
@@ -1523,8 +1545,7 @@ private void toInstructions(Collection<Unit> units, StmtVisitor stmtV, Set<Unit>
15231545
stmtV.finalizeInstructions(trapReferences);
15241546
}
15251547

1526-
private void toTries(Collection<Trap> traps, StmtVisitor stmtV, MethodImplementationBuilder builder,
1527-
LabelAssigner labelAssigner) {
1548+
protected void toTries(Collection<Trap> traps, MethodImplementationBuilder builder, LabelAssigner labelAssigner) {
15281549
// Original code: assume that the mapping startCodeAddress -> TryItem is
15291550
// enough for
15301551
// a "code range", ignore different end Units / try lengths

0 commit comments

Comments
 (0)