This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8883dc3
commit e3a2e11
Showing
7 changed files
with
178 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"codeAttributes":[{"clazz":"PartialEvaluatorDummy","method":"test0()I","instructions":[{"offset":0,"instruction":"iconst_0","finalVariablesBefore":["LPartialEvaluatorDummy;!"],"finalStackBefore":[]},{"offset":1,"instruction":"ireturn","finalVariablesBefore":["LPartialEvaluatorDummy;!"],"finalStackBefore":["0"],"finalTargetInstructions":[]}],"parameters":["LPartialEvaluatorDummy;!"],"blockEvaluations":[{"startOffset":0,"evaluations":[{"skipEvaluation":false,"isGeneralization":false,"evaluationCount":0,"instruction":"iconst_0","instructionOffset":0,"variablesBefore":["LPartialEvaluatorDummy;!"],"stackBefore":[]},{"skipEvaluation":false,"isGeneralization":false,"evaluationCount":0,"instruction":"ireturn","instructionOffset":1,"variablesBefore":["LPartialEvaluatorDummy;!"],"stackBefore":["0"]}],"branchEvaluationStack":[],"startVariables":["LPartialEvaluatorDummy;!"],"startStack":[]}]},{"clazz":"PartialEvaluatorDummy","method":"test1()I","instructions":[{"offset":0,"instruction":"iconst_1","finalVariablesBefore":["LPartialEvaluatorDummy;!"],"finalStackBefore":[]},{"offset":1,"instruction":"ireturn","finalVariablesBefore":["LPartialEvaluatorDummy;!"],"finalStackBefore":["1"],"finalTargetInstructions":[]}],"parameters":["LPartialEvaluatorDummy;!"],"blockEvaluations":[{"startOffset":0,"evaluations":[{"skipEvaluation":false,"isGeneralization":false,"evaluationCount":0,"instruction":"iconst_1","instructionOffset":0,"variablesBefore":["LPartialEvaluatorDummy;!"],"stackBefore":[]},{"skipEvaluation":false,"isGeneralization":false,"evaluationCount":0,"instruction":"ireturn","instructionOffset":1,"variablesBefore":["LPartialEvaluatorDummy;!"],"stackBefore":["1"]}],"branchEvaluationStack":[],"startVariables":["LPartialEvaluatorDummy;!"],"startStack":[]}]}]} | ||
{"codeAttributes":[{"clazz":"PartialEvaluatorDummy","method":"test0()I","instructions":[{"offset":0,"instruction":"iconst_0","finalVariablesBefore":["LPartialEvaluatorDummy;!"],"finalStackBefore":[]},{"offset":1,"instruction":"ireturn","finalVariablesBefore":["LPartialEvaluatorDummy;!"],"finalStackBefore":["0"],"finalTargetInstructions":[]}],"parameters":["LPartialEvaluatorDummy;!"],"blockEvaluations":[{"startOffset":0,"evaluations":[{"skipEvaluation":false,"isGeneralization":false,"evaluationCount":0,"instruction":"iconst_0","instructionOffset":0,"variablesBefore":["LPartialEvaluatorDummy;!"],"stackBefore":[]},{"skipEvaluation":false,"isGeneralization":false,"evaluationCount":0,"instruction":"ireturn","instructionOffset":1,"variablesBefore":["LPartialEvaluatorDummy;!"],"stackBefore":["0"]}],"branchEvaluationStack":[],"startVariables":["LPartialEvaluatorDummy;!"],"startStack":[]}]},{"clazz":"PartialEvaluatorDummy","method":"test0()V","instructions":[{"offset":0,"instruction":"iconst_1","finalVariablesBefore":["LPartialEvaluatorDummy;!"],"finalStackBefore":[]},{"offset":1,"instruction":"return","finalVariablesBefore":["LPartialEvaluatorDummy;!"],"finalStackBefore":["1"],"finalTargetInstructions":[]}],"parameters":["LPartialEvaluatorDummy;!"],"blockEvaluations":[{"startOffset":0,"evaluations":[{"skipEvaluation":false,"isGeneralization":false,"evaluationCount":0,"instruction":"iconst_1","instructionOffset":0,"variablesBefore":["LPartialEvaluatorDummy;!"],"stackBefore":[]},{"skipEvaluation":false,"isGeneralization":false,"evaluationCount":0,"instruction":"return","instructionOffset":1,"variablesBefore":["LPartialEvaluatorDummy;!"],"stackBefore":["1"]}],"branchEvaluationStack":[],"startVariables":["LPartialEvaluatorDummy;!"],"startStack":[]}]}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package data | ||
|
||
import proguard.classfile.ClassPool | ||
import proguard.classfile.Clazz | ||
import proguard.classfile.Method | ||
import proguard.classfile.attribute.Attribute | ||
import proguard.classfile.attribute.CodeAttribute | ||
import proguard.classfile.attribute.visitor.AllAttributeVisitor | ||
import proguard.classfile.attribute.visitor.AttributeNameFilter | ||
import proguard.classfile.attribute.visitor.AttributeVisitor | ||
import proguard.classfile.visitor.AllClassVisitor | ||
import proguard.classfile.visitor.AllMethodVisitor | ||
import proguard.classfile.visitor.ClassPoolFiller | ||
import proguard.classfile.visitor.FilteredClassVisitor | ||
import proguard.evaluation.PartialEvaluator | ||
import proguard.evaluation.util.jsonPrinter.JsonPrinter | ||
import proguard.io.ClassFilter | ||
import proguard.io.ClassReader | ||
import proguard.io.DataEntrySource | ||
import proguard.io.FileSource | ||
import proguard.io.JarReader | ||
import viewmodel.CodeAttributeViewModel | ||
import java.nio.file.Path | ||
|
||
class LoadUtil { | ||
companion object { | ||
fun getClassPoolFromJAR(path: Path): ClassPool { | ||
val classPool = ClassPool() | ||
|
||
val source: DataEntrySource = FileSource( | ||
path.toFile(), | ||
) | ||
|
||
source.pumpDataEntries( | ||
JarReader( | ||
false, | ||
ClassFilter( | ||
ClassReader( | ||
false, | ||
false, | ||
false, | ||
false, | ||
null, | ||
ClassPoolFiller(classPool), | ||
), | ||
), | ||
), | ||
) | ||
|
||
return classPool | ||
} | ||
|
||
fun classMethodMap(classPool: ClassPool): Map<String, Map<String, CodeAttributeViewModel?>> { | ||
val classMap: MutableMap<String, MutableMap<String, CodeAttributeViewModel?>> = HashMap() | ||
classPool.accept( | ||
AllClassVisitor( | ||
AllMethodVisitor( | ||
AllAttributeVisitor( | ||
AttributeNameFilter( | ||
Attribute.CODE, | ||
object : AttributeVisitor { | ||
override fun visitCodeAttribute( | ||
clazz: Clazz, | ||
method: Method, | ||
codeAttribute: CodeAttribute, | ||
) { | ||
classMap.getOrPut(clazz.name) { HashMap() }[method.getName(clazz) + method.getDescriptor(clazz)] = null | ||
} | ||
}, | ||
), | ||
), | ||
), | ||
), | ||
) | ||
return classMap | ||
} | ||
|
||
fun evalSingleMethod(classPool: ClassPool, clazz: String, method: String): StateTracker? { | ||
val tracker = JsonPrinter() | ||
val pe = PartialEvaluator.Builder.create() | ||
.setEvaluateAllCode(true).setStateTracker(tracker).build() | ||
classPool.accept( | ||
FilteredClassVisitor( | ||
clazz, | ||
AllMethodVisitor( | ||
AllAttributeVisitor( | ||
AttributeNameFilter( | ||
Attribute.CODE, | ||
object : AttributeVisitor { | ||
override fun visitCodeAttribute( | ||
clazz: Clazz, | ||
visitedMethod: Method, | ||
codeAttribute: CodeAttribute, | ||
) { | ||
if (visitedMethod.getName(clazz) + visitedMethod.getDescriptor(clazz) == method) { | ||
pe.visitCodeAttribute(clazz, visitedMethod, codeAttribute) | ||
} | ||
} | ||
}, | ||
), | ||
), | ||
), | ||
), | ||
) | ||
try { | ||
return StateTracker.fromJson(tracker.json) | ||
} catch (e: Exception) { | ||
println("Error while parsing json file: $e") | ||
} | ||
return null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.