├── .github └── workflows │ ├── docker-image.yml │ └── gradle.yml ├── .gitignore ├── .gitmodules ├── Dockerfile ├── LICENSE ├── LicenseHeadTemplate.txt ├── README.md ├── artifact ├── Qilin-0.9.7-SNAPSHOT.jar ├── __init__.py ├── qilin.py ├── run.py ├── runbach.py └── util │ ├── TerminalColor.py │ ├── Tex.py │ ├── Util.py │ ├── __init__.py │ ├── benchmark.py │ ├── common.py │ ├── dacapobach.py │ ├── generalCSFacts.py │ ├── generalClient.py │ ├── opt.py │ └── ptaout.py ├── build.gradle ├── docs ├── QilinArchitecture.png ├── QilinCodeStructure.html ├── QilinCodeStructure.html_files │ ├── freeplane2html.css │ ├── hide.png │ ├── icons │ │ ├── clock2.svg │ │ ├── knotes.svg │ │ ├── links │ │ │ └── link │ │ │ │ └── web_ssl.svg │ │ └── yes.svg │ ├── ilink.png │ ├── image.png │ ├── leaf.png │ └── show.png ├── QilinCodeStructure.mm ├── QilinCodeStructure.pdf ├── example │ └── example01 │ │ ├── example.jar │ │ └── src │ │ └── Main.java ├── index.html └── stylesheets │ ├── github-light.css │ ├── normalize.css │ └── stylesheet.css ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── qilin.core ├── build.gradle └── src │ └── qilin │ ├── CoreConfig.java │ ├── core │ ├── ArtificialMethod.java │ ├── CorePTA.java │ ├── PTA.java │ ├── PTAScene.java │ ├── PointsToAnalysis.java │ ├── VirtualCalls.java │ ├── builder │ │ ├── CallGraphBuilder.java │ │ ├── ExceptionHandler.java │ │ ├── FakeMainFactory.java │ │ └── MethodNodeFactory.java │ ├── context │ │ ├── ContextElement.java │ │ ├── ContextElements.java │ │ └── TypeContextElement.java │ ├── natives │ │ ├── JavaIoFileSystemGetFileSystemNative.java │ │ ├── JavaIoFileSystemListNative.java │ │ ├── JavaLangObjectCloneNative.java │ │ ├── JavaLangRefFinalizerInvokeFinalizeMethodNative.java │ │ ├── JavaLangReflectArrayGet.java │ │ ├── JavaLangReflectArraySet.java │ │ ├── JavaLangSystemArraycopyNative.java │ │ ├── JavaLangSystemSetErr0Native.java │ │ ├── JavaLangSystemSetIn0Native.java │ │ ├── JavaLangSystemSetOut0Native.java │ │ ├── JavaLangThreadCurrentThread.java │ │ ├── JavaLangThreadStart0Native.java │ │ ├── JavaSecurityAccessControllerDoPrivilegedNative.java │ │ ├── JavaSecurityAccessControllerDoPrivileged_ExceptionNative.java │ │ ├── NativeMethod.java │ │ ├── NativeMethodDriver.java │ │ └── package-info.java │ ├── pag │ │ ├── AllocNode.java │ │ ├── ArrayElement.java │ │ ├── CallSite.java │ │ ├── ClassConstantNode.java │ │ ├── ConstantNode.java │ │ ├── ContextAllocNode.java │ │ ├── ContextField.java │ │ ├── ContextMethod.java │ │ ├── ContextVarNode.java │ │ ├── ExceptionThrowSite.java │ │ ├── FieldRefNode.java │ │ ├── FieldValNode.java │ │ ├── GlobalVarNode.java │ │ ├── LocalVarNode.java │ │ ├── MergedNewExpr.java │ │ ├── MethodPAG.java │ │ ├── Node.java │ │ ├── PAG.java │ │ ├── Parm.java │ │ ├── StringConstantNode.java │ │ ├── ValNode.java │ │ ├── VarNode.java │ │ ├── VirtualCallSite.java │ │ └── package-info.java │ ├── reflection │ │ ├── NopReflectionModel.java │ │ ├── ReflectionKind.java │ │ ├── ReflectionModel.java │ │ └── TamiflexModel.java │ ├── sets │ │ ├── DoublePointsToSet.java │ │ ├── HybridPointsToSet.java │ │ ├── P2SetVisitor.java │ │ ├── PointsToSet.java │ │ ├── PointsToSetInternal.java │ │ ├── UnmodifiablePointsToSet.java │ │ └── package-info.java │ └── solver │ │ ├── Propagator.java │ │ └── Solver.java │ ├── parm │ ├── ctxcons │ │ ├── CallsiteCtxConstructor.java │ │ ├── CtxConstructor.java │ │ ├── HybObjCtxConstructor.java │ │ ├── HybTypeCtxConstructor.java │ │ ├── InsensCtxConstructor.java │ │ ├── ObjCtxConstructor.java │ │ └── TypeCtxConstructor.java │ ├── heapabst │ │ ├── AllocSiteAbstractor.java │ │ ├── HeapAbstractor.java │ │ ├── HeuristicAbstractor.java │ │ └── MahjongAbstractor.java │ └── select │ │ ├── BeanSelector.java │ │ ├── CtxSelector.java │ │ ├── DebloatingSelector.java │ │ ├── FullMethodLvSelector.java │ │ ├── HeuristicSelector.java │ │ ├── InsenSelector.java │ │ ├── PartialMethodLvSelector.java │ │ ├── PartialVarSelector.java │ │ ├── PipelineSelector.java │ │ ├── UniformSelector.java │ │ └── VarLvSelector.java │ ├── stat │ ├── AbstractStat.java │ ├── AliasStat.java │ ├── BenchmarkStat.java │ ├── CallGraphStat.java │ ├── Exporter.java │ ├── IEvaluator.java │ ├── PAGStat.java │ ├── PTAEvaluator.java │ ├── PointsToStat.java │ ├── RuntimeStat.java │ ├── SimplifiedEvaluator.java │ ├── TypeClientStat.java │ └── YummyStat.java │ └── util │ └── PTAUtils.java ├── qilin.pta ├── build.gradle ├── src │ ├── driver │ │ ├── ContextKind.java │ │ ├── Main.java │ │ ├── PTAComparator.java │ │ ├── PTAFactory.java │ │ ├── PTAOption.java │ │ └── PTAPattern.java │ └── qilin │ │ └── pta │ │ ├── PTAConfig.java │ │ ├── toolkits │ │ ├── bean │ │ │ ├── Bean.java │ │ │ ├── ContextSelector.java │ │ │ ├── RepresentativeContextSelector.java │ │ │ └── gpl-3.0.txt │ │ ├── common │ │ │ ├── DebloatedOAG.java │ │ │ ├── FieldPointstoGraph.java │ │ │ ├── OAG.java │ │ │ └── ToolUtil.java │ │ ├── conch │ │ │ ├── AbstractConch.java │ │ │ ├── AbstractPAG.java │ │ │ ├── CSDG.java │ │ │ ├── Conch.java │ │ │ ├── DFA.java │ │ │ ├── DepOnParamAnalysis.java │ │ │ ├── LeakAnalysis.java │ │ │ ├── PathEdge.java │ │ │ ├── SMPAG.java │ │ │ ├── TranEdge.java │ │ │ └── Trilean.java │ │ ├── dd │ │ │ ├── CtxTunnelingFeaturesTrueTable.java │ │ │ ├── DataDrivenSelector.java │ │ │ ├── FeaturesTrueTable.java │ │ │ ├── TunnelingConstructor.java │ │ │ ├── data-driven │ │ │ │ └── README.md │ │ │ └── tunneling │ │ │ │ └── README.md │ │ ├── debloaterx │ │ │ ├── CollectionHeuristic.java │ │ │ ├── ContainerFinder.java │ │ │ ├── DebloaterX.java │ │ │ ├── Edge.java │ │ │ ├── EdgeKind.java │ │ │ ├── HeapContainerQuery.java │ │ │ ├── InterFlowAnalysis.java │ │ │ ├── IntraFlowAnalysis.java │ │ │ ├── State.java │ │ │ ├── XPAG.java │ │ │ └── XUtility.java │ │ ├── eagle │ │ │ ├── BNode.java │ │ │ └── Eagle.java │ │ ├── mahjong │ │ │ ├── HeapAbstraction.java │ │ │ ├── Mahjong.java │ │ │ ├── automata │ │ │ │ ├── DFA.java │ │ │ │ ├── DFAEquivalenceChecker.java │ │ │ │ ├── DFAFactory.java │ │ │ │ ├── DFAState.java │ │ │ │ └── NFA.java │ │ │ └── gpl-3.0.txt │ │ ├── selectx │ │ │ ├── BNode.java │ │ │ ├── G.java │ │ │ ├── I.java │ │ │ ├── L.java │ │ │ ├── O.java │ │ │ └── Selectx.java │ │ ├── turner │ │ │ ├── AbstractMVFG.java │ │ │ ├── DFA.java │ │ │ ├── MethodLevelCallGraph.java │ │ │ ├── MethodVFG.java │ │ │ ├── ModularMVFG.java │ │ │ ├── OCG.java │ │ │ ├── TranEdge.java │ │ │ └── Turner.java │ │ └── zipper │ │ │ ├── Global.java │ │ │ ├── Main.java │ │ │ ├── ReadMe.txt │ │ │ ├── analysis │ │ │ ├── PotentialContextElement.java │ │ │ └── Zipper.java │ │ │ ├── cases │ │ │ ├── CaseA.java │ │ │ ├── CaseB.java │ │ │ ├── CaseC.java │ │ │ └── CaseD.java │ │ │ ├── flowgraph │ │ │ ├── Edge.java │ │ │ ├── FlowAnalysis.java │ │ │ ├── IObjectFlowGraph.java │ │ │ ├── Kind.java │ │ │ └── ObjectFlowGraph.java │ │ │ └── mit.txt │ │ └── tools │ │ ├── BasePTA.java │ │ ├── BeanPTA.java │ │ ├── CallSiteSensPTA.java │ │ ├── DataDrivenPTA.java │ │ ├── DebloatedPTA.java │ │ ├── EaglePTA.java │ │ ├── HybridObjectSensPTA.java │ │ ├── HybridTypeSensPTA.java │ │ ├── MahjongPTA.java │ │ ├── ObjectSensPTA.java │ │ ├── PartialCallSiteSensPTA.java │ │ ├── PartialObjSensPTA.java │ │ ├── SelectxPTA.java │ │ ├── Spark.java │ │ ├── StagedPTA.java │ │ ├── TunnelingPTA.java │ │ ├── TurnerPTA.java │ │ ├── TypeSensPTA.java │ │ └── ZipperPTA.java └── test │ └── qilin │ └── test │ ├── FlowSensTests.java │ ├── context │ ├── CFATests.java │ ├── CollectionsTests.java │ ├── HybTests.java │ ├── OBJTests.java │ └── TypeTests.java │ ├── core │ ├── ArrayTests.java │ ├── AssignTests.java │ ├── CallTests.java │ ├── ClinitTests.java │ ├── ExceptionTests.java │ ├── FieldTests.java │ ├── GlobalTests.java │ ├── NativeTests.java │ └── ReflogTests.java │ └── util │ ├── AliasAssertion.java │ ├── AssertionsParser.java │ ├── IAssertion.java │ └── JunitTests.java ├── qilin.util ├── build.gradle └── src │ └── qilin │ └── util │ ├── ANSIColor.java │ ├── DataFactory.java │ ├── MemoryWatcher.java │ ├── Pair.java │ ├── Stopwatch.java │ ├── Triple.java │ ├── UnionFindSet.java │ ├── Util.java │ ├── collect │ └── SetFactory.java │ ├── graph │ ├── ConcurrentDirectedGraphImpl.java │ ├── DirectedGraph.java │ ├── DirectedGraphImpl.java │ ├── MergedNode.java │ ├── Reachability.java │ ├── SCCMergedGraph.java │ ├── StronglyConnectedComponents.java │ ├── TopologicalSorter.java │ ├── Tree.java │ ├── TreeImpl.java │ └── TreeNode.java │ ├── package.html │ └── queue │ ├── UniqueQueue.java │ └── package.html ├── run.sh └── settings.gradle /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Docker CI 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | # branches: [ main ] 8 | 9 | jobs: 10 | 11 | build: 12 | if: github.event.base_ref == 'refs/heads/main' 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v2 18 | with: 19 | submodules: 'true' 20 | - name: Set up Docker Buildx 21 | uses: docker/setup-buildx-action@v1 22 | - name: Login to DockerHub 23 | uses: docker/login-action@v1 24 | with: 25 | username: hdjay2013 26 | password: ${{ secrets.DOCKER }} 27 | - name: Build and push 28 | uses: docker/build-push-action@v2 29 | with: 30 | context: . 31 | push: true 32 | tags: hdjay2013/qilin:latest 33 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time 6 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 7 | 8 | name: Gradle CI 9 | 10 | on: 11 | push: 12 | branches: [ main ] 13 | pull_request: 14 | branches: [ main ] 15 | 16 | jobs: 17 | build: 18 | strategy: 19 | matrix: 20 | os: [ubuntu-latest] 21 | # os: [ ubuntu-latest, macos-latest ] 22 | # os: [ubuntu-latest, macos-latest, windows-latest] 23 | runs-on: ${{ matrix.os }} 24 | 25 | steps: 26 | - uses: actions/checkout@v2 27 | with: 28 | submodules: 'true' 29 | - name: Set up JDK 17 30 | uses: actions/setup-java@v2 31 | with: 32 | java-version: '17' 33 | distribution: 'adopt' 34 | - name: Setup and execute Gradle 'test' task 35 | uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7 36 | with: 37 | arguments: test 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .gradle/ 3 | .classpath 4 | .project 5 | .settings/ 6 | __pycache__/ 7 | build/ 8 | bin/ 9 | benchmark 10 | out/ 11 | artifact/output/ 12 | run/pta/Qilin-all-1.0-SNAPSHOT.jar 13 | *.pyc 14 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "artifact/benchmarks"] 2 | path = artifact/benchmarks 3 | url = https://github.com/QiLinPTA/benchmarks.git 4 | [submodule "qilin.microben"] 5 | path = qilin.microben 6 | url = https://github.com/QilinPTA/microben.git 7 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # compile artifact 2 | FROM amd64/gradle AS buildEnv 3 | RUN apt-get install python3 -y 4 | ADD . /build/ 5 | WORKDIR /build/ 6 | RUN ./gradlew clean fatJar 7 | 8 | # build image 9 | FROM hdjay2013/jupx:v16 10 | ENV workdir /qilin 11 | WORKDIR $workdir 12 | ENV user root 13 | USER $user 14 | COPY artifact/benchmarks $workdir/benchmarks 15 | COPY artifact/util/ $workdir/util/ 16 | COPY artifact/run.py $workdir/ 17 | COPY artifact/qilin.py $workdir/ 18 | COPY artifact/__init__.py $workdir/ 19 | COPY --from=buildEnv /build/artifact/Qilin-0.9.4-SNAPSHOT.jar $workdir/ 20 | CMD /bin/bash 21 | -------------------------------------------------------------------------------- /LicenseHeadTemplate.txt: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ -------------------------------------------------------------------------------- /artifact/Qilin-0.9.7-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/artifact/Qilin-0.9.7-SNAPSHOT.jar -------------------------------------------------------------------------------- /artifact/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/artifact/__init__.py -------------------------------------------------------------------------------- /artifact/util/TerminalColor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # terminal color 4 | RESET = '\033[0m' 5 | BOLD = '\033[1m' 6 | GREEN = '\033[32m' 7 | YELLOW = '\033[33m' 8 | CYAN = '\033[36m' 9 | WHITE = '\033[37m' 10 | RED = '\033[91m' 11 | -------------------------------------------------------------------------------- /artifact/util/Tex.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # latex code before table definition. 4 | def genDocHeadPart(): 5 | headPart = [r"\documentclass{article}", 6 | r"\usepackage{adjustbox}", 7 | r"\usepackage{booktabs}", 8 | r"\setlength\heavyrulewidth{0.3ex}", 9 | r"\usepackage{multirow}", 10 | r"\usepackage{geometry}", 11 | r"\usepackage{xspace}", 12 | r"\geometry{a4paper, top=10mm, left=10mm, right=10mm}", 13 | r"\usepackage[table,xcdraw]{xcolor}", 14 | r"\newcommand{\kobj}{\textsc{$k$obj}\xspace}", 15 | r"\newcommand{\twoobj}{\textsc{$2$obj}\xspace}", 16 | r"\newcommand{\eagleobj}[1]{\textsc{E-#1obj}\xspace}", 17 | r"\newcommand{\zipperobj}[1]{\textsc{Z-#1obj}\xspace}", 18 | r"\newcommand{\toolobj}[1]{\textsc{T-#1obj}\xspace}", 19 | r"\newcommand{\threeobj}{\textsc{$3$obj}\xspace}", 20 | r"\newcommand{\zipper}{\textsc{zipper}\xspace}", 21 | r"\newcommand{\eagle}{\textsc{eagle}\xspace}", 22 | r"\newcommand{\tool}{\textsc{Turner}\xspace}", 23 | r"\definecolor{floralwhite}{rgb}{1.0, 0.98, 0.94}", 24 | r"\definecolor{gainsboro}{rgb}{0.86, 0.86, 0.86}", 25 | r"\definecolor{ghostwhite}{rgb}{0.97, 0.97, 1.0}", 26 | r"\definecolor{deepchampagne}{rgb}{0.98, 0.84, 0.65}", 27 | r"\definecolor{darkgray}{rgb}{0.66, 0.66, 0.66}", 28 | r"\definecolor{cornsilk}{rgb}{1.0, 0.97, 0.86}", 29 | r"\definecolor{antiquewhite}{rgb}{0.98, 0.92, 0.84}", 30 | r"\begin{document}", 31 | r"", 32 | ] 33 | return "\n".join(headPart) 34 | 35 | 36 | # latex code for ending the table. 37 | def genTableTailPart(): 38 | return "\n".join(["\t\end{tabular}", "}", "\end{table}"]) 39 | 40 | 41 | def genDocTailPart(): 42 | return "\n\end{document}\n" 43 | -------------------------------------------------------------------------------- /artifact/util/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/artifact/util/__init__.py -------------------------------------------------------------------------------- /artifact/util/common.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | TOOLNAMEMAP = { 4 | 'M-2o': 'M-2OBJ', 5 | 'E-2o': 'E2objH', 6 | 'T-2o': '\\toolobj{2}', 7 | 'T-3o': '\\toolobj{3}', 8 | 'Z-2o': 'Z2OBJ', 9 | 'Z-3o': 'Z3OBJ', 10 | 'E-3o': 'E3OBJ', 11 | 'P-1c': 'P-1c', 12 | 'P-2c': 'P-2c', 13 | '3o': '3OBJ', 14 | '2o': '2OBJ', 15 | 'Y-2o': 'Y-2o', 16 | '2o+D': '2OBJ+D', 17 | 'Z-2o+D': 'Z2OBJ+D', 18 | 'E-2o+D': 'E2OBJ+D', 19 | '3o+D': '3OBJ+D', 20 | 'Z-3o+D': 'Z3OBJ+D', 21 | 'E-3o+D': 'E3OBJ+D', 22 | 'insens': 'ci', 23 | '1c': '1c', 24 | '2c': '2c', 25 | '1o': '1o', 26 | '2t': '2t', 27 | 's-2h': 's-2h', 28 | 29 | 'T-2o-l': 'T-2o-l', 30 | 'T-2o-s': 'T-2o-s', 31 | 'T-2o-po': 'T-2o-phaseone', 32 | 'T-2o-pt': 'T-2o-phasetwo', 33 | 'T-2o-sl': 'T-2o-sl', 34 | 'T-2o-sv': 'T-2o-sv', 35 | 'T-2o-zt': 'T-2o-zt', 36 | 'T-2o-zb': 'T-2o-zb', 37 | 'T-2o-zb2': 'T-2o-zb2', 38 | 'T-2o-zn': 'T-2o-zn', 39 | 'T-2o-eba': 'T-2o-eba', 40 | 'T-2o-ebb': 'T-2o-ebb', 41 | 'T-2o-eta': 'T-2o-eta', 42 | 'T-2o-etb': 'T-2o-etb', 43 | 'T-2o-ebta': 'T-2o-ebta', 44 | 'T-2o-ebtb': 'T-2o-ebtb', 45 | 'T-2o-xboth': 'T-2o-xboth', 46 | 'T-2o-xtop': 'T-2o-xtop', 47 | 'T-2o-xnone': 'T-2o-xnone', 48 | 'T-2o-ge': 'T-2o-ge', 49 | 'T-2o-zt2': 'T-2o-zt2', 50 | 'T-2o-zt3': 'T-2o-zt3', 51 | 'T-2o-man': 'T-2o-man', 52 | 'ml-e-2o': 'method-level-e-2o', 53 | 'ml-hp-2o': 'method-level-p-2o', 54 | } 55 | -------------------------------------------------------------------------------- /artifact/util/dacapobach.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # ignore eclipse and jython. 4 | BENCHMARKS = ['avrora', 'batik', 'h2', 'luindex', 'lusearch', 'pmd', 'sunflow', 'tradebeans', 'xalan'] 5 | 6 | 7 | def getBachAppJar(app): 8 | return "%s.jar" % (app) 9 | 10 | 11 | def getBachAppDep(app): 12 | return "%s-deps.jar" % (app) 13 | 14 | 15 | def getTamiflexLog(app): 16 | if app == 'tradebeans': 17 | return "%s-tamiflex.log" % (app) 18 | else: 19 | return "%s-tamiflex-default.log" % (app) 20 | -------------------------------------------------------------------------------- /artifact/util/opt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import util.TerminalColor as tc 4 | 5 | 6 | # OPTIONS 7 | def makeup(str): 8 | return ' ' * (30 - len(str)) 9 | 10 | 11 | def bioption(opt, arg, des): 12 | return tc.BOLD + tc.YELLOW + opt + ' ' + tc.GREEN + arg + tc.WHITE + makeup( 13 | opt + arg) + des + tc.RESET + '\n' 14 | 15 | 16 | def option(opt, des): 17 | return bioption(opt, '', des) 18 | -------------------------------------------------------------------------------- /docs/QilinArchitecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/docs/QilinArchitecture.png -------------------------------------------------------------------------------- /docs/QilinCodeStructure.html_files/freeplane2html.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #FFFFFF; 3 | } 4 | 5 | div.node { 6 | padding-bottom: 1ex; 7 | padding-left: 2em; 8 | } 9 | 10 | div.cloud { 11 | padding-bottom: 1ex; 12 | padding-left: 2em; 13 | background-color: #C0C0FF; 14 | border-width: 2px; 15 | border-style: solid; 16 | border-color: #A0A0FF; 17 | } 18 | 19 | div.content { 20 | border-width: 1px; 21 | border-style: dashed; 22 | border-color: #C0C0C0; 23 | } 24 | 25 | img.hideshow { 26 | padding-right: 1ex; 27 | } 28 | 29 | img.ilink { 30 | border-width: 0px; 31 | padding-left: 1ex; 32 | } 33 | 34 | /* for notes and image export, fc, 18.7.2005. */ 35 | .images { 36 | max-width:50%; 37 | } 38 | 39 | .nodecontent {display:inline;} 40 | 41 | .note-and-attributes { 42 | margin-left:10%; 43 | color:#0000FF; 44 | } 45 | 46 | table.attributes { 47 | border-collapse:collapse; 48 | empty-cells:show; 49 | border:thin black solid; 50 | } 51 | table.attributes td,th { 52 | border:thin black solid; 53 | padding-top:2px; 54 | padding-bottom:2px; 55 | padding-left:3px; 56 | padding-right:3px; 57 | } 58 | table.attributes th { 59 | text-align:center; 60 | } 61 | table.attributes caption { 62 | margin-top:1em; 63 | font-style:italic; 64 | text-align:center; 65 | } 66 | -------------------------------------------------------------------------------- /docs/QilinCodeStructure.html_files/hide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/docs/QilinCodeStructure.html_files/hide.png -------------------------------------------------------------------------------- /docs/QilinCodeStructure.html_files/icons/yes.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | image/svg+xml 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /docs/QilinCodeStructure.html_files/ilink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/docs/QilinCodeStructure.html_files/ilink.png -------------------------------------------------------------------------------- /docs/QilinCodeStructure.html_files/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/docs/QilinCodeStructure.html_files/image.png -------------------------------------------------------------------------------- /docs/QilinCodeStructure.html_files/leaf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/docs/QilinCodeStructure.html_files/leaf.png -------------------------------------------------------------------------------- /docs/QilinCodeStructure.html_files/show.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/docs/QilinCodeStructure.html_files/show.png -------------------------------------------------------------------------------- /docs/QilinCodeStructure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/docs/QilinCodeStructure.pdf -------------------------------------------------------------------------------- /docs/example/example01/example.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/docs/example/example01/example.jar -------------------------------------------------------------------------------- /docs/example/example01/src/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main(String[] args) { 3 | C c1 = new C(); // C1 4 | C c2 = c1; 5 | A a1 = c1.wcreate2(); // c1 6 | A a2 = c2.wcreate2(); // c2 7 | Object o1 = new Object(); // O1 8 | Object o2 = new Object(); // O2 9 | a1.f = o1; 10 | a2.f = o2; 11 | Object v1 = a1.f; 12 | Object v2 = a2.f; 13 | } 14 | } 15 | 16 | class A { 17 | Object f; 18 | } 19 | 20 | class B { 21 | A create() { 22 | A r1 = new A(); // A1 23 | return r1; 24 | } 25 | 26 | A wcreate() { 27 | A r2 = this.create(); // c4 28 | return r2; 29 | } 30 | } 31 | 32 | class C { 33 | A wcreate2() { 34 | B b1 = new B(); // B1 35 | A r3 = b1.wcreate(); // c3 36 | return r3; 37 | } 38 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.java.installations.auto-download=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QilinPTA/Qilin/99db19ba8ea1a02239d753941f1cf13af5634211/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jul 12 09:20:26 AEST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip 7 | -------------------------------------------------------------------------------- /qilin.core/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | sourceSets.main { 6 | java.srcDirs = ['src'] 7 | } 8 | 9 | repositories { 10 | maven { url "https://repo.maven.apache.org/maven2/" } 11 | } 12 | 13 | dependencies { 14 | // api files("${rootDir}/libs/sootclasses-4.4.0-jar-with-dependencies.jar") 15 | implementation("org.soot-oss:soot:4.6.0") 16 | api(project(':qilin.util')) 17 | } 18 | 19 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/context/ContextElement.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.context; 20 | 21 | public interface ContextElement { 22 | @Override 23 | int hashCode(); 24 | 25 | @Override 26 | boolean equals(Object obj); 27 | } 28 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaIoFileSystemGetFileSystemNative.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.RefType; 22 | import soot.SootMethod; 23 | import soot.Value; 24 | 25 | public class JavaIoFileSystemGetFileSystemNative extends NativeMethod { 26 | public JavaIoFileSystemGetFileSystemNative(SootMethod method) { 27 | super(method); 28 | } 29 | 30 | /************************ java.io.FileSystem ***********************/ 31 | /** 32 | * Returns a variable pointing to the file system constant 33 | *

34 | * public static native java.io.FileSystem getFileSystem(); 35 | * only exists in old version of JDK(e.g., JDK6). 36 | */ 37 | public void simulate() { 38 | Value newLocal0 = getNew(RefType.v("java.io.UnixFileSystem")); 39 | addInvoke(newLocal0, "()>"); 40 | addReturn(newLocal0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaIoFileSystemListNative.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.RefType; 22 | import soot.SootMethod; 23 | import soot.Value; 24 | 25 | public class JavaIoFileSystemListNative extends NativeMethod { 26 | public JavaIoFileSystemListNative(SootMethod method) { 27 | super(method); 28 | } 29 | 30 | /************************ java.io.FileSystem ***********************/ 31 | /** 32 | * Returns a String[] 33 | * only exists in old JDK(e.g., JDK6). 34 | */ 35 | public void simulate() { 36 | Value arrLocal = getNewArray(RefType.v("java.lang.String")); 37 | Value elem = getNew(RefType.v("java.lang.String")); 38 | // addInvoke(elem, "()>"); 39 | addAssign(getArrayRef(arrLocal), elem); 40 | addReturn(arrLocal); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangObjectCloneNative.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.SootMethod; 22 | import soot.Value; 23 | 24 | public class JavaLangObjectCloneNative extends NativeMethod { 25 | 26 | public JavaLangObjectCloneNative(SootMethod method) { 27 | super(method); 28 | } 29 | 30 | /** 31 | * Implements the abstract method simulateMethod. It distributes the request to 32 | * the corresponding methods by signatures. 33 | */ 34 | public void simulate() { 35 | Value r0 = getThis(); 36 | addReturn(r0); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangRefFinalizerInvokeFinalizeMethodNative.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.SootMethod; 22 | import soot.Value; 23 | 24 | public class JavaLangRefFinalizerInvokeFinalizeMethodNative extends NativeMethod { 25 | public JavaLangRefFinalizerInvokeFinalizeMethodNative(SootMethod method) { 26 | super(method); 27 | } 28 | 29 | /** 30 | * "" 31 | */ 32 | public void simulate() { 33 | Value r0 = getPara(0); 34 | addInvoke(r0, ""); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangReflectArrayGet.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.ArrayType; 22 | import soot.RefType; 23 | import soot.SootMethod; 24 | import soot.Value; 25 | 26 | /* 27 | * 28 | * */ 29 | 30 | public class JavaLangReflectArrayGet extends NativeMethod { 31 | JavaLangReflectArrayGet(SootMethod method) { 32 | super(method); 33 | } 34 | 35 | @Override 36 | void simulate() { 37 | Value arrayBase = getPara(0, ArrayType.v(RefType.v("java.lang.Object"), 1)); 38 | Value arrayRef = getArrayRef(arrayBase); 39 | Value ret = getNextLocal(RefType.v("java.lang.Object")); 40 | addAssign(ret, arrayRef); 41 | addReturn(ret); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangReflectArraySet.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.ArrayType; 22 | import soot.RefType; 23 | import soot.SootMethod; 24 | import soot.Value; 25 | 26 | /* 27 | * handle 28 | * */ 29 | 30 | public class JavaLangReflectArraySet extends NativeMethod { 31 | JavaLangReflectArraySet(SootMethod method) { 32 | super(method); 33 | } 34 | 35 | @Override 36 | void simulate() { 37 | Value arrayBase = getPara(0, ArrayType.v(RefType.v("java.lang.Object"), 1)); 38 | Value rightValue = getPara(2); 39 | Value arrayRef = getArrayRef(arrayBase); 40 | addAssign(arrayRef, rightValue); // a[] = b; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangSystemArraycopyNative.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.ArrayType; 22 | import soot.RefType; 23 | import soot.SootMethod; 24 | import soot.Value; 25 | 26 | /* 27 | * This file will be temporarily discarded. Yes, it is correct but need one more level of context. 28 | * Thus it will make qilin.spark less precise than its counterpart in Doop. 29 | * */ 30 | public class JavaLangSystemArraycopyNative extends NativeMethod { 31 | public JavaLangSystemArraycopyNative(SootMethod method) { 32 | super(method); 33 | } 34 | 35 | /** 36 | * never make a[] = b[], it violates the principle of jimple statement. make a 37 | * temporary variable. 38 | */ 39 | public void simulate() { 40 | // Value srcArr = getPara(0); 41 | // Value dstArr = getPara(2); 42 | Value srcArr = getPara(0, ArrayType.v(RefType.v("java.lang.Object"), 1)); 43 | Value dstArr = getPara(2, ArrayType.v(RefType.v("java.lang.Object"), 1)); 44 | Value src = getArrayRef(srcArr); 45 | Value dst = getArrayRef(dstArr); 46 | Value temp = getNextLocal(RefType.v("java.lang.Object")); 47 | addAssign(temp, src); 48 | addAssign(dst, temp); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangSystemSetErr0Native.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.SootMethod; 22 | import soot.Value; 23 | 24 | public class JavaLangSystemSetErr0Native extends NativeMethod { 25 | public JavaLangSystemSetErr0Native(SootMethod method) { 26 | super(method); 27 | } 28 | 29 | /** 30 | * NOTE: this native method is not documented in JDK API. It should have the 31 | * side effect: System.err = parameter 32 | *

33 | * private static native void setErr0(java.io.PrintStream); 34 | */ 35 | public void simulate() { 36 | Value r1 = getPara(0); 37 | Value systemErr = getStaticFieldRef("java.lang.System", "err"); 38 | addAssign(systemErr, r1); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangSystemSetIn0Native.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.SootMethod; 22 | import soot.Value; 23 | 24 | public class JavaLangSystemSetIn0Native extends NativeMethod { 25 | public JavaLangSystemSetIn0Native(SootMethod method) { 26 | super(method); 27 | } 28 | 29 | /** 30 | * NOTE: this native method is not documented in JDK API. It should have the 31 | * side effect: System.in = parameter 32 | *

33 | * private static native void setIn0(java.io.InputStream); 34 | */ 35 | public void simulate() { 36 | Value r1 = getPara(0); 37 | Value systemIn = getStaticFieldRef("java.lang.System", "in"); 38 | addAssign(systemIn, r1); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangSystemSetOut0Native.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.SootMethod; 22 | import soot.Value; 23 | 24 | public class JavaLangSystemSetOut0Native extends NativeMethod { 25 | public JavaLangSystemSetOut0Native(SootMethod method) { 26 | super(method); 27 | } 28 | 29 | /** 30 | * NOTE: this native method is not documented in JDK API. It should have the 31 | * side effect: System.out = parameter 32 | *

33 | * private static native void setOut0(java.io.PrintStream); 34 | */ 35 | public void simulate() { 36 | Value r1 = getPara(0); 37 | Value systemOut = getStaticFieldRef("java.lang.System", "out"); 38 | addAssign(systemOut, r1); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangThreadCurrentThread.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import qilin.core.PTAScene; 22 | import soot.RefType; 23 | import soot.SootMethod; 24 | import soot.Value; 25 | 26 | public class JavaLangThreadCurrentThread extends NativeMethod { 27 | JavaLangThreadCurrentThread(SootMethod method) { 28 | super(method); 29 | } 30 | 31 | @Override 32 | void simulate() { 33 | Value lv = getNextLocal(RefType.v("java.lang.Thread")); 34 | Value rv = PTAScene.v().getFieldCurrentThread(); 35 | addAssign(lv, rv); 36 | addReturn(lv); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaLangThreadStart0Native.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import qilin.core.PTAScene; 22 | import soot.SootMethod; 23 | import soot.Value; 24 | 25 | public class JavaLangThreadStart0Native extends NativeMethod { 26 | 27 | public JavaLangThreadStart0Native(SootMethod method) { 28 | super(method); 29 | } 30 | 31 | /** 32 | * Calls to Thread.start() get redirected to Thread.run. 33 | *

34 | * In JRE 1.5 and JRE 1.6 Thread.start() is defined in Java 35 | * and there is native method start0. 36 | */ 37 | 38 | @Override 39 | void simulate() { 40 | Value mThis = getThis(); 41 | addInvoke(mThis, ""); 42 | Value lv = PTAScene.v().getFieldCurrentThread(); 43 | addAssign(lv, mThis); // store. 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaSecurityAccessControllerDoPrivilegedNative.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | package qilin.core.natives; 19 | 20 | import soot.SootMethod; 21 | import soot.Value; 22 | 23 | public class JavaSecurityAccessControllerDoPrivilegedNative extends NativeMethod { 24 | public JavaSecurityAccessControllerDoPrivilegedNative(SootMethod method) { 25 | super(method); 26 | } 27 | 28 | /** 29 | * public static native java.lang.Object 30 | * doPrivileged(java.security.PrivilegedAction) public static native 31 | * java.lang.Object 32 | * doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext) 33 | */ 34 | public void simulate() { 35 | Value r0 = getPara(0); 36 | Value r1 = getInvoke(r0, ""); 37 | addReturn(r1); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/JavaSecurityAccessControllerDoPrivileged_ExceptionNative.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import soot.SootMethod; 22 | import soot.Value; 23 | 24 | public class JavaSecurityAccessControllerDoPrivileged_ExceptionNative extends NativeMethod { 25 | public JavaSecurityAccessControllerDoPrivileged_ExceptionNative(SootMethod method) { 26 | super(method); 27 | } 28 | 29 | /** 30 | * public static native java.lang.Object 31 | * doPrivileged(java.security.PrivilegedExceptionAction) public static native 32 | * java.lang.Object 33 | * doPrivileged(java.security.PrivilegedExceptionAction,java.security.AccessControlContext) 34 | */ 35 | public void simulate() { 36 | Value r0 = getPara(0); 37 | Value r1 = getInvoke(r0, ""); 38 | addReturn(r1); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/NativeMethod.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.natives; 20 | 21 | import qilin.core.ArtificialMethod; 22 | import qilin.util.PTAUtils; 23 | import soot.SootMethod; 24 | import soot.Value; 25 | 26 | public abstract class NativeMethod extends ArtificialMethod { 27 | 28 | NativeMethod(SootMethod method) { 29 | this.method = method; 30 | this.body = PTAUtils.getMethodBody(method); 31 | int paraCount = method.getParameterCount(); 32 | paraLocals = new Value[paraCount]; 33 | this.paraStart = method.isStatic() ? 0 : 1; 34 | this.localStart = this.paraStart + paraCount; 35 | } 36 | 37 | abstract void simulate(); 38 | } 39 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/natives/package-info.java: -------------------------------------------------------------------------------- 1 | package qilin.core.natives; 2 | 3 | /* 4 | * In this package, we currently only handle a subset of native methods that are supported in Doop. 5 | * In the future, we will append more simulations to native methods that are frequently used by 6 | * real-world applications. 7 | * */ -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/ArrayElement.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.RefType; 22 | import soot.Type; 23 | import soot.jimple.spark.pag.SparkField; 24 | 25 | /** 26 | * Represents an array element. 27 | * 28 | * @author Ondrej Lhotak 29 | */ 30 | public class ArrayElement implements SparkField { 31 | private static ArrayElement instance = null; 32 | private int number = 0; 33 | 34 | public static ArrayElement v() { 35 | if (instance == null) { 36 | synchronized (ArrayElement.class) { 37 | if (instance == null) { 38 | instance = new ArrayElement(); 39 | } 40 | } 41 | } 42 | return instance; 43 | } 44 | 45 | public final int getNumber() { 46 | return number; 47 | } 48 | 49 | public final void setNumber(int number) { 50 | this.number = number; 51 | } 52 | 53 | public Type getType() { 54 | return RefType.v("java.lang.Object"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/CallSite.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import qilin.core.context.ContextElement; 22 | import soot.Unit; 23 | 24 | /** 25 | * callsite based context element in the points to analysis. 26 | */ 27 | public class CallSite implements ContextElement { 28 | 29 | private final Unit unit; 30 | 31 | public CallSite(Unit unit) { 32 | this.unit = unit; 33 | } 34 | 35 | public Unit getUnit() { 36 | return unit; 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | final int prime = 31; 42 | int result = 1; 43 | result = prime * result + ((unit == null) ? 0 : unit.hashCode()); 44 | return result; 45 | } 46 | 47 | @Override 48 | public boolean equals(Object obj) { 49 | if (this == obj) 50 | return true; 51 | if (obj == null) 52 | return false; 53 | if (getClass() != obj.getClass()) 54 | return false; 55 | CallSite other = (CallSite) obj; 56 | if (unit == null) { 57 | return other.unit == null; 58 | } else if (other.unit == null) { 59 | return false; 60 | } else { 61 | return unit.equals(other.unit); 62 | } 63 | } 64 | 65 | public String toString() { 66 | return "CallSite: " + unit; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/ClassConstantNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.RefType; 22 | import soot.jimple.ClassConstant; 23 | 24 | /** 25 | * Represents an allocation site node the represents a known java.lang.Class object. 26 | * 27 | * @author Ondrej Lhotak 28 | */ 29 | public class ClassConstantNode extends ConstantNode { 30 | public ClassConstantNode(ClassConstant cc) { 31 | super(cc, RefType.v("java.lang.Class"), null); 32 | } 33 | 34 | public String toString() { 35 | return "ClassConstantNode " + getNumber() + " " + newExpr; 36 | } 37 | 38 | public ClassConstant getClassConstant() { 39 | return (ClassConstant) newExpr; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/ConstantNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.SootMethod; 22 | import soot.Type; 23 | 24 | public abstract class ConstantNode extends AllocNode { 25 | protected ConstantNode(Object newExpr, Type t, SootMethod m) { 26 | super(newExpr, t, m); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/ContextAllocNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.Context; 22 | 23 | public class ContextAllocNode extends AllocNode { 24 | private final Context context; 25 | private final AllocNode base; 26 | 27 | public ContextAllocNode(AllocNode base, Context context) { 28 | super(base.getNewExpr(), base.getType(), base.getMethod()); 29 | this.context = context; 30 | this.base = base; 31 | } 32 | 33 | public Context context() { 34 | return context; 35 | } 36 | 37 | @Override 38 | public AllocNode base() { 39 | return base; 40 | } 41 | 42 | public String toString() { 43 | return "ContextAllocNode " + getNumber() + "(" + base + ", " + context + ")"; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/ContextMethod.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.Context; 22 | import soot.MethodOrMethodContext; 23 | import soot.SootMethod; 24 | 25 | public final class ContextMethod implements MethodOrMethodContext { 26 | private final SootMethod method; 27 | private final Context context; 28 | 29 | public SootMethod method() { 30 | return this.method; 31 | } 32 | 33 | public Context context() { 34 | return this.context; 35 | } 36 | 37 | public ContextMethod(SootMethod method, Context context) { 38 | this.method = method; 39 | this.context = context; 40 | } 41 | 42 | public int hashCode() { 43 | return this.method.hashCode() + this.context.hashCode(); 44 | } 45 | 46 | public boolean equals(Object o) { 47 | if (!(o instanceof ContextMethod other)) { 48 | return false; 49 | } else { 50 | return this.method.equals(other.method) && this.context.equals(other.context); 51 | } 52 | } 53 | 54 | public String toString() { 55 | return "Method " + this.method + " in context " + this.context; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/ContextVarNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.Context; 22 | 23 | public class ContextVarNode extends VarNode { 24 | private final Context context; 25 | private final VarNode base; 26 | 27 | public ContextVarNode(VarNode base, Context context) { 28 | super(base.getVariable(), base.getType()); 29 | this.context = context; 30 | this.base = base; 31 | } 32 | 33 | 34 | @Override 35 | public boolean isInterProcTarget() { 36 | return base.isInterProcTarget(); 37 | } 38 | 39 | @Override 40 | public boolean isInterProcSource() { 41 | return base.isInterProcSource(); 42 | } 43 | 44 | @Override 45 | public Context context() { 46 | return context; 47 | } 48 | 49 | @Override 50 | public VarNode base() { 51 | return base; 52 | } 53 | 54 | public String toString() { 55 | return "ContextVarNode " + getNumber() + "(" + base + ", " + context + ")"; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/ExceptionThrowSite.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.MethodOrMethodContext; 22 | import soot.Unit; 23 | 24 | import java.util.Objects; 25 | 26 | public class ExceptionThrowSite { 27 | private final Unit unit; 28 | private final VarNode throwNode; 29 | private final MethodOrMethodContext container; 30 | 31 | public ExceptionThrowSite(VarNode throwNode, Unit unit, MethodOrMethodContext container) { 32 | this.unit = unit; 33 | this.container = container; 34 | this.throwNode = throwNode; 35 | } 36 | 37 | public MethodOrMethodContext container() { 38 | return container; 39 | } 40 | 41 | public VarNode getThrowNode() { 42 | return throwNode; 43 | } 44 | 45 | public Unit getUnit() { 46 | return unit; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object o) { 51 | if (this == o) return true; 52 | if (o == null || getClass() != o.getClass()) return false; 53 | ExceptionThrowSite that = (ExceptionThrowSite) o; 54 | return Objects.equals(unit, that.unit) && Objects.equals(throwNode, that.throwNode) && Objects.equals(container, that.container); 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return Objects.hash(unit, throwNode, container); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/FieldRefNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.jimple.spark.pag.SparkField; 22 | import soot.util.Numberable; 23 | 24 | /** 25 | * Represents a field reference node in the pointer assignment graph. 26 | * 27 | * @author Ondrej Lhotak 28 | */ 29 | public class FieldRefNode extends Node implements Numberable { 30 | protected VarNode base; 31 | protected SparkField field; 32 | 33 | public FieldRefNode(VarNode base, SparkField field) { 34 | super(field.getType()); 35 | this.base = base; 36 | this.field = field; 37 | base.addField(this, field); 38 | } 39 | 40 | /** 41 | * Returns the base of this field reference. 42 | */ 43 | public VarNode getBase() { 44 | return base; 45 | } 46 | 47 | /** 48 | * Returns the field of this field reference. 49 | */ 50 | public SparkField getField() { 51 | return field; 52 | } 53 | 54 | public String toString() { 55 | return "FieldRefNode " + getNumber() + " " + base + "." + field; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/FieldValNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.jimple.spark.pag.SparkField; 22 | 23 | public class FieldValNode extends ValNode { 24 | // note, field could only be ArrayElement or Field type. 25 | // Parm should be a local variable in some methods. 26 | private final SparkField field; 27 | 28 | public FieldValNode(SparkField field) { 29 | super(field.getType()); 30 | this.field = field; 31 | } 32 | 33 | public SparkField getField() { 34 | return field; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/GlobalVarNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.SootClass; 22 | import soot.SootField; 23 | import soot.Type; 24 | 25 | /** 26 | * Represents a simple variable node in the pointer assignment graph that is not associated with any particular 27 | * method invocation. 28 | * 29 | * @author Ondrej Lhotak 30 | */ 31 | public class GlobalVarNode extends VarNode { 32 | public GlobalVarNode(Object variable, Type t) { 33 | super(variable, t); 34 | } 35 | 36 | @Override 37 | public VarNode base() { 38 | return this; 39 | } 40 | 41 | public String toString() { 42 | return "GlobalVarNode " + getNumber() + " " + variable; 43 | } 44 | 45 | public SootClass getDeclaringClass() { 46 | if (variable instanceof SootField) { 47 | return ((SootField) variable).getDeclaringClass(); 48 | } 49 | 50 | return null; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/LocalVarNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.SootMethod; 22 | import soot.Type; 23 | 24 | /** 25 | * @author Ondrej Lhotak 26 | */ 27 | public class LocalVarNode extends VarNode { 28 | protected SootMethod method; 29 | 30 | public LocalVarNode(Object variable, Type t, SootMethod m) { 31 | super(variable, t); 32 | this.method = m; 33 | } 34 | 35 | public SootMethod getMethod() { 36 | return method; 37 | } 38 | 39 | public String toString() { 40 | return "LocalVarNode " + getNumber() + " " + variable + " " + method; 41 | } 42 | 43 | /** 44 | * Returns true if this VarNode represents the THIS pointer 45 | */ 46 | public boolean isThis() { 47 | if (variable instanceof Parm parm) { 48 | return parm.isThis(); 49 | } 50 | return false; 51 | } 52 | 53 | public boolean isReturn() { 54 | if (variable instanceof Parm parm) { 55 | return parm.isReturn(); 56 | } 57 | return false; 58 | } 59 | 60 | @Override 61 | public VarNode base() { 62 | return this; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/MergedNewExpr.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import qilin.util.DataFactory; 22 | import soot.RefLikeType; 23 | 24 | import java.util.Map; 25 | 26 | public class MergedNewExpr { 27 | private final RefLikeType type; 28 | private static final Map map = DataFactory.createMap(); 29 | 30 | private MergedNewExpr(RefLikeType type) { 31 | this.type = type; 32 | } 33 | 34 | public static MergedNewExpr v(RefLikeType type) { 35 | return map.computeIfAbsent(type, k -> new MergedNewExpr(type)); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/Node.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import qilin.core.sets.DoublePointsToSet; 22 | import qilin.util.PTAUtils; 23 | import soot.Type; 24 | import soot.util.Numberable; 25 | 26 | /** 27 | * Represents every node in the pointer assignment graph. 28 | * 29 | * @author Ondrej Lhotak 30 | */ 31 | public class Node implements Numberable { 32 | protected Type type; 33 | protected DoublePointsToSet p2set; 34 | private int number = 0; 35 | 36 | /** 37 | * Creates a new node of pointer assignment graph pag, with type type. 38 | */ 39 | protected Node(Type type) { 40 | if (PTAUtils.isUnresolved(type)) { 41 | throw new RuntimeException("Unresolved type " + type); 42 | } 43 | this.type = type; 44 | } 45 | 46 | @Override 47 | public final int hashCode() { 48 | return number; 49 | } 50 | 51 | public final boolean equals(Object other) { 52 | return this == other; 53 | } 54 | 55 | /** 56 | * Returns the declared type of this node, null for unknown. 57 | */ 58 | public Type getType() { 59 | return type; 60 | } 61 | 62 | public final int getNumber() { 63 | return number; 64 | } 65 | 66 | public final void setNumber(int number) { 67 | this.number = number; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/StringConstantNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import soot.RefType; 22 | import soot.jimple.StringConstant; 23 | 24 | /** 25 | * Represents an allocation site node the represents a constant string. 26 | * 27 | * @author Ondrej Lhotak 28 | */ 29 | public class StringConstantNode extends ConstantNode { 30 | public StringConstantNode(StringConstant sc) { 31 | super(sc, RefType.v("java.lang.String"), null); 32 | } 33 | 34 | public String toString() { 35 | return "StringConstantNode " + getNumber() + " " + newExpr; 36 | } 37 | 38 | public String getString() { 39 | return ((StringConstant) newExpr).value; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/ValNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.pag; 20 | 21 | import qilin.core.sets.DoublePointsToSet; 22 | import soot.Type; 23 | import soot.util.Numberable; 24 | 25 | /** 26 | * Represents a simple of pointer node in the pointer assignment graph. 27 | */ 28 | public class ValNode extends Node implements Comparable, Numberable { 29 | 30 | protected ValNode(Type t) { 31 | super(t); 32 | } 33 | 34 | public int compareTo(Object o) { 35 | ValNode other = (ValNode) o; 36 | return other.getNumber() - this.getNumber(); 37 | } 38 | 39 | /** 40 | * Returns the points-to set for this node. 41 | */ 42 | public DoublePointsToSet getP2Set() { 43 | if (p2set != null) { 44 | return p2set; 45 | } else { 46 | p2set = new DoublePointsToSet(); 47 | return p2set; 48 | } 49 | } 50 | 51 | /** 52 | * Delete current points-to set and make a new one 53 | */ 54 | public void discardP2Set() { 55 | p2set = null; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/pag/package-info.java: -------------------------------------------------------------------------------- 1 | package qilin.core.pag; 2 | 3 | /* 4 | * Most of the class files in this package can be seen in the Soot/jimple/spark/pag. 5 | * We have changed them a lot but (at least) their names are kept the same here. 6 | * We hope our framework could be merged into soot and replace the original Spark one day. 7 | * */ -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/reflection/NopReflectionModel.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.reflection; 20 | 21 | import soot.Unit; 22 | import soot.jimple.Stmt; 23 | 24 | import java.util.Collection; 25 | import java.util.Collections; 26 | 27 | /* 28 | * This is an empty reflection model which does nothing for reflection statements. 29 | * */ 30 | 31 | public class NopReflectionModel extends ReflectionModel { 32 | 33 | @Override 34 | Collection transformClassForName(Stmt s) { 35 | return Collections.emptySet(); 36 | } 37 | 38 | @Override 39 | Collection transformClassNewInstance(Stmt s) { 40 | return Collections.emptySet(); 41 | } 42 | 43 | @Override 44 | Collection transformContructorNewInstance(Stmt s) { 45 | return Collections.emptySet(); 46 | } 47 | 48 | @Override 49 | Collection transformMethodInvoke(Stmt s) { 50 | return Collections.emptySet(); 51 | } 52 | 53 | @Override 54 | Collection transformFieldSet(Stmt s) { 55 | return Collections.emptySet(); 56 | } 57 | 58 | @Override 59 | Collection transformFieldGet(Stmt s) { 60 | return Collections.emptySet(); 61 | } 62 | 63 | @Override 64 | Collection transformArrayNewInstance(Stmt s) { 65 | return Collections.emptySet(); 66 | } 67 | 68 | @Override 69 | Collection transformArrayGet(Stmt s) { 70 | return Collections.emptySet(); 71 | } 72 | 73 | @Override 74 | Collection transformArraySet(Stmt s) { 75 | return Collections.emptySet(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/reflection/ReflectionKind.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.reflection; 20 | 21 | public enum ReflectionKind { 22 | ClassForName, ClassNewInstance, ConstructorNewInstance, MethodInvoke, FieldSet, FieldGet, MethodGet, ArrayNewInstance, 23 | ArrayGet, ArraySet, FieldGetName; 24 | 25 | public static ReflectionKind parse(String kindStr) { 26 | return switch (kindStr) { 27 | case "Class.forName" -> ClassForName; 28 | case "Class.newInstance" -> ClassNewInstance; 29 | case "Constructor.newInstance" -> ConstructorNewInstance; 30 | case "Method.invoke" -> MethodInvoke; 31 | case "Method.getName" -> MethodGet; 32 | case "Field.set*" -> FieldSet; 33 | case "Field.get*" -> FieldGet; 34 | case "Field.getName" -> FieldGetName; 35 | case "Array.newInstance" -> ArrayNewInstance; 36 | default -> null; 37 | }; 38 | } 39 | } -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/sets/P2SetVisitor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.sets; 20 | 21 | import qilin.core.PTA; 22 | import qilin.core.pag.Node; 23 | 24 | /** 25 | * Abstract base class for points-to set visitors used to enumerate points-to sets. 26 | * 27 | * @author Ondrej Lhotak 28 | */ 29 | public abstract class P2SetVisitor { 30 | protected boolean returnValue = false; 31 | protected final PTA pta; 32 | 33 | protected P2SetVisitor(PTA pta) { 34 | this.pta = pta; 35 | } 36 | 37 | 38 | protected abstract void visit(Node n); 39 | 40 | public void visit(long idx) { 41 | Node node = pta.getPag().getAllocNodeNumberer().get(idx); 42 | visit(node); 43 | } 44 | 45 | public boolean getReturnValue() { 46 | return returnValue; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/sets/PointsToSetInternal.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.sets; 20 | 21 | import java.util.Iterator; 22 | 23 | /** 24 | * Abstract base class for implementations of points-to sets. 25 | * 26 | * @author Ondrej Lhotak 27 | */ 28 | public abstract class PointsToSetInternal { 29 | /** 30 | * Calls v's visit method on all nodes in this set. 31 | */ 32 | public abstract boolean forall(P2SetVisitor v); 33 | 34 | public abstract boolean addAll(final PointsToSetInternal other, final PointsToSetInternal exclude); 35 | 36 | /** 37 | * Adds node index idx to this set, returns true if idx was not already in this set. 38 | */ 39 | public abstract boolean add(int idx); 40 | 41 | /** 42 | * Returns true iff the set contains the node number index. 43 | */ 44 | public abstract boolean contains(int idx); 45 | 46 | public abstract Iterator iterator(); 47 | 48 | public abstract void clear(); 49 | 50 | public abstract boolean isEmpty(); 51 | 52 | public boolean hasNonEmptyIntersection(final PointsToSetInternal other) { 53 | Iterator it = iterator(); 54 | while (it.hasNext()) { 55 | int idx = it.next(); 56 | if (other.contains(idx)) { 57 | return true; 58 | } 59 | } 60 | return false; 61 | } 62 | 63 | public abstract int size(); 64 | } 65 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/sets/package-info.java: -------------------------------------------------------------------------------- 1 | package qilin.core.sets; 2 | 3 | /* 4 | * We reuse the data structures of points-to set which are originally designed for Spark in Soot. 5 | * In future, we plan to design more memory-efficient data structures for replacements. 6 | * */ -------------------------------------------------------------------------------- /qilin.core/src/qilin/core/solver/Propagator.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.core.solver; 20 | 21 | /** 22 | * Abstract base class for a propagator that propagates points-to sets along pointer assignment graph. 23 | * 24 | * @author Ondrej Lhotak 25 | */ 26 | 27 | public abstract class Propagator { 28 | /** 29 | * Actually does the propagation. 30 | */ 31 | public abstract void propagate(); 32 | } 33 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/ctxcons/CallsiteCtxConstructor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.ctxcons; 20 | 21 | import qilin.core.context.ContextElement; 22 | import qilin.core.context.ContextElements; 23 | import qilin.core.pag.CallSite; 24 | import qilin.core.pag.ContextAllocNode; 25 | import soot.Context; 26 | import soot.MethodOrMethodContext; 27 | import soot.SootMethod; 28 | 29 | public class CallsiteCtxConstructor implements CtxConstructor { 30 | 31 | @Override 32 | public Context constructCtx(MethodOrMethodContext caller, ContextAllocNode receiverNode, CallSite callSite, SootMethod target) { 33 | Context callerContext = caller.context(); 34 | assert callerContext instanceof ContextElements; 35 | ContextElements ctxElems = (ContextElements) callerContext; 36 | int s = ctxElems.size(); 37 | ContextElement[] cxt = ctxElems.getElements(); 38 | ContextElement[] array = new ContextElement[s + 1]; 39 | array[0] = callSite; 40 | System.arraycopy(cxt, 0, array, 1, s); 41 | return new ContextElements(array, s + 1); 42 | } 43 | } -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/ctxcons/CtxConstructor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.ctxcons; 20 | 21 | import qilin.core.context.ContextElement; 22 | import qilin.core.context.ContextElements; 23 | import qilin.core.pag.CallSite; 24 | import qilin.core.pag.ContextAllocNode; 25 | import soot.Context; 26 | import soot.MethodOrMethodContext; 27 | import soot.SootMethod; 28 | 29 | public interface CtxConstructor { 30 | Context constructCtx(MethodOrMethodContext caller, ContextAllocNode receiverNode, CallSite callSite, SootMethod target); 31 | 32 | Context emptyContext = new ContextElements(new ContextElement[0], 0); 33 | } -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/ctxcons/InsensCtxConstructor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.ctxcons; 20 | 21 | import qilin.core.pag.CallSite; 22 | import qilin.core.pag.ContextAllocNode; 23 | import soot.Context; 24 | import soot.MethodOrMethodContext; 25 | import soot.SootMethod; 26 | 27 | public class InsensCtxConstructor implements CtxConstructor { 28 | 29 | @Override 30 | public Context constructCtx(MethodOrMethodContext caller, ContextAllocNode receiverNode, CallSite callSite, SootMethod target) { 31 | return emptyContext; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/ctxcons/ObjCtxConstructor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.ctxcons; 20 | 21 | import qilin.core.context.ContextElement; 22 | import qilin.core.context.ContextElements; 23 | import qilin.core.pag.CallSite; 24 | import qilin.core.pag.ContextAllocNode; 25 | import soot.Context; 26 | import soot.MethodOrMethodContext; 27 | import soot.SootMethod; 28 | 29 | // implementation of obj context...(Ana Tosem'05) 30 | public class ObjCtxConstructor implements CtxConstructor { 31 | 32 | @Override 33 | public Context constructCtx(MethodOrMethodContext caller, ContextAllocNode receiverNode, CallSite callSite, SootMethod target) { 34 | Context callerContext = caller.context(); 35 | if (receiverNode == null) { // static invoke 36 | return callerContext; 37 | } 38 | Context context = receiverNode.context(); 39 | assert context instanceof ContextElements; 40 | ContextElements ctxElems = (ContextElements) context; 41 | int s = ctxElems.size(); 42 | ContextElement[] cxtAllocs = ctxElems.getElements(); 43 | ContextElement[] array = new ContextElement[s + 1]; 44 | array[0] = receiverNode.base(); 45 | System.arraycopy(cxtAllocs, 0, array, 1, s); 46 | return new ContextElements(array, s + 1); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/ctxcons/TypeCtxConstructor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.ctxcons; 20 | 21 | import qilin.core.context.ContextElement; 22 | import qilin.core.context.ContextElements; 23 | import qilin.core.context.TypeContextElement; 24 | import qilin.core.pag.AllocNode; 25 | import qilin.core.pag.CallSite; 26 | import qilin.core.pag.ContextAllocNode; 27 | import soot.Context; 28 | import soot.MethodOrMethodContext; 29 | import soot.SootMethod; 30 | 31 | // implementation of type context...(Yannis popl'11) 32 | public class TypeCtxConstructor implements CtxConstructor { 33 | 34 | @Override 35 | public Context constructCtx(MethodOrMethodContext caller, ContextAllocNode receiverNode, CallSite callSite, SootMethod target) { 36 | Context callerContext = caller.context(); 37 | if (receiverNode == null) { // static invoke 38 | return callerContext; 39 | } 40 | Context context = receiverNode.context(); 41 | assert context instanceof ContextElements; 42 | ContextElements ctxElems = (ContextElements) context; 43 | int s = ctxElems.size(); 44 | ContextElement[] cxtAllocs = ctxElems.getElements(); 45 | ContextElement[] array = new ContextElement[s + 1]; 46 | AllocNode base = receiverNode.base(); 47 | array[0] = TypeContextElement.getTypeContextElement(base); 48 | System.arraycopy(cxtAllocs, 0, array, 1, s); 49 | return new ContextElements(array, s + 1); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/heapabst/AllocSiteAbstractor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.heapabst; 20 | 21 | import qilin.core.pag.AllocNode; 22 | 23 | public class AllocSiteAbstractor implements HeapAbstractor { 24 | @Override 25 | public AllocNode abstractHeap(AllocNode heap) { 26 | return heap; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/heapabst/HeapAbstractor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.heapabst; 20 | 21 | import qilin.core.pag.AllocNode; 22 | 23 | public interface HeapAbstractor { 24 | AllocNode abstractHeap(AllocNode heap); 25 | } 26 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/heapabst/HeuristicAbstractor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.heapabst; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.core.pag.MergedNewExpr; 23 | import qilin.core.pag.PAG; 24 | import qilin.util.DataFactory; 25 | import qilin.util.PTAUtils; 26 | import soot.RefLikeType; 27 | import soot.RefType; 28 | import soot.SootMethod; 29 | import soot.Type; 30 | 31 | import java.util.Set; 32 | 33 | public class HeuristicAbstractor implements HeapAbstractor { 34 | private final PAG pag; 35 | private final Set mergedTypes = DataFactory.createSet(); 36 | 37 | public HeuristicAbstractor(PAG pag) { 38 | this.pag = pag; 39 | mergedTypes.add(RefType.v("java.lang.StringBuffer")); 40 | mergedTypes.add(RefType.v("java.lang.StringBuilder")); 41 | } 42 | 43 | @Override 44 | public AllocNode abstractHeap(AllocNode heap) { 45 | Type type = heap.getType(); 46 | SootMethod m = heap.getMethod(); 47 | if (mergedTypes.contains(type) || (PTAUtils.isThrowable(type) && mergedTypes.add(type))) { 48 | return pag.makeAllocNode(MergedNewExpr.v((RefLikeType) type), type, null); 49 | } else { 50 | return heap; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/heapabst/MahjongAbstractor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.heapabst; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.core.pag.PAG; 23 | import qilin.util.PTAUtils; 24 | import soot.SootMethod; 25 | import soot.Type; 26 | 27 | import java.util.Map; 28 | import java.util.Set; 29 | 30 | public class MahjongAbstractor implements HeapAbstractor { 31 | private final Set mergedHeap; 32 | private final Map heapModelMap; 33 | private final PAG pag; 34 | 35 | public MahjongAbstractor(PAG pag, Set mergedHeap, Map heapModelMap) { 36 | this.pag = pag; 37 | this.mergedHeap = mergedHeap; 38 | this.heapModelMap = heapModelMap; 39 | } 40 | 41 | @Override 42 | public AllocNode abstractHeap(AllocNode heap) { 43 | Object newExpr = heap.getNewExpr(); 44 | Type type = heap.getType(); 45 | SootMethod m = heap.getMethod(); 46 | Object mergedIr = this.heapModelMap.get(newExpr); 47 | if (this.mergedHeap.contains(mergedIr)) { 48 | return pag.makeAllocNode(mergedIr, type, null); 49 | } else { 50 | if (PTAUtils.isThrowable(type)) { 51 | // Mahjong still needs heuristics to handle throwable types. 52 | return pag.makeAllocNode("Merged " + type, type, null); 53 | } 54 | return pag.makeAllocNode(newExpr, type, m); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/select/CtxSelector.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.select; 20 | 21 | import qilin.core.context.ContextElement; 22 | import qilin.core.context.ContextElements; 23 | import qilin.core.pag.AllocNode; 24 | import qilin.core.pag.FieldValNode; 25 | import qilin.core.pag.LocalVarNode; 26 | import qilin.parm.ctxcons.CtxConstructor; 27 | import soot.Context; 28 | import soot.SootMethod; 29 | 30 | public abstract class CtxSelector { 31 | public abstract Context select(SootMethod m, Context context); 32 | 33 | public abstract Context select(LocalVarNode lvn, Context context); 34 | 35 | public abstract Context select(FieldValNode fvn, Context context); 36 | 37 | public abstract Context select(AllocNode heap, Context context); 38 | 39 | protected Context contextTailor(Context context, int length) { 40 | if (length == 0) { 41 | return CtxConstructor.emptyContext; 42 | } 43 | ContextElements ctx = (ContextElements) context; 44 | ContextElement[] fullContexts = ctx.getElements(); 45 | if (length >= ctx.size()) { 46 | return context; 47 | } 48 | ContextElement[] newContexts = new ContextElement[length]; 49 | System.arraycopy(fullContexts, 0, newContexts, 0, length); 50 | return new ContextElements(newContexts, length); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/select/DebloatingSelector.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.select; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.core.pag.FieldValNode; 23 | import qilin.core.pag.LocalVarNode; 24 | import qilin.parm.ctxcons.CtxConstructor; 25 | import soot.Context; 26 | import soot.SootMethod; 27 | 28 | import java.util.Set; 29 | 30 | public class DebloatingSelector extends CtxSelector { 31 | 32 | protected final Set ctxDepHeaps; 33 | 34 | public DebloatingSelector(Set ctxDepHeaps) { 35 | this.ctxDepHeaps = ctxDepHeaps; 36 | } 37 | 38 | @Override 39 | public Context select(SootMethod m, Context context) { 40 | return context; 41 | } 42 | 43 | @Override 44 | public Context select(LocalVarNode lvn, Context context) { 45 | return context; 46 | } 47 | 48 | @Override 49 | public Context select(FieldValNode fvn, Context context) { 50 | return context; 51 | } 52 | 53 | @Override 54 | public Context select(AllocNode heap, Context context) { 55 | Object ir = heap.getNewExpr(); 56 | if (ctxDepHeaps.contains(ir)) { 57 | return context; 58 | } else { 59 | return CtxConstructor.emptyContext; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/select/FullMethodLvSelector.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.select; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.core.pag.FieldValNode; 23 | import qilin.core.pag.LocalVarNode; 24 | import soot.Context; 25 | import soot.SootMethod; 26 | 27 | import java.util.Map; 28 | 29 | public class FullMethodLvSelector extends CtxSelector { 30 | private final int k; 31 | /* 32 | * Methods and its corresponding context length obtained by Data-driven (OOPSLA 2017). 33 | * */ 34 | private final Map m2len; 35 | 36 | public FullMethodLvSelector(Map m2len, int k) { 37 | this.m2len = m2len; 38 | this.k = k; 39 | } 40 | 41 | @Override 42 | public Context select(SootMethod m, Context context) { 43 | return contextTailor(context, m2len.getOrDefault(m, 0)); 44 | } 45 | 46 | @Override 47 | public Context select(LocalVarNode lvn, Context context) { 48 | SootMethod sm = lvn.getMethod(); 49 | return contextTailor(context, m2len.getOrDefault(sm, 0)); 50 | } 51 | 52 | @Override 53 | public Context select(FieldValNode fvn, Context context) { 54 | return contextTailor(context, k); 55 | } 56 | 57 | @Override 58 | public Context select(AllocNode heap, Context context) { 59 | SootMethod sm = heap.getMethod(); 60 | return contextTailor(context, Math.max(0, m2len.getOrDefault(sm, 0) - 1)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/select/HeuristicSelector.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.select; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.core.pag.FieldValNode; 23 | import qilin.core.pag.LocalVarNode; 24 | import qilin.parm.ctxcons.CtxConstructor; 25 | import qilin.util.PTAUtils; 26 | import soot.Context; 27 | import soot.SootMethod; 28 | 29 | public class HeuristicSelector extends CtxSelector { 30 | 31 | @Override 32 | public Context select(SootMethod m, Context context) { 33 | return context; 34 | } 35 | 36 | @Override 37 | public Context select(LocalVarNode lvn, Context context) { 38 | return context; 39 | } 40 | 41 | @Override 42 | public Context select(FieldValNode fvn, Context context) { 43 | return context; 44 | } 45 | 46 | @Override 47 | public Context select(AllocNode heap, Context context) { 48 | if (PTAUtils.isThrowable(heap.getType()) || PTAUtils.subtypeOfAbstractStringBuilder(heap.getType())) { 49 | return CtxConstructor.emptyContext; 50 | } 51 | return context; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/select/InsenSelector.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.select; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.core.pag.FieldValNode; 23 | import qilin.core.pag.LocalVarNode; 24 | import qilin.parm.ctxcons.CtxConstructor; 25 | import soot.Context; 26 | import soot.SootMethod; 27 | 28 | public class InsenSelector extends CtxSelector { 29 | @Override 30 | public Context select(SootMethod m, Context context) { 31 | return CtxConstructor.emptyContext; 32 | } 33 | 34 | @Override 35 | public Context select(LocalVarNode lvn, Context context) { 36 | return CtxConstructor.emptyContext; 37 | } 38 | 39 | @Override 40 | public Context select(FieldValNode fvn, Context context) { 41 | return contextTailor(context, 1); 42 | } 43 | 44 | @Override 45 | public Context select(AllocNode heap, Context context) { 46 | return CtxConstructor.emptyContext; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/select/PipelineSelector.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.select; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.core.pag.FieldValNode; 23 | import qilin.core.pag.LocalVarNode; 24 | import soot.Context; 25 | import soot.SootMethod; 26 | 27 | /* 28 | * A pipeline context selector which selects context by firstly using ctxSelA and then ctxSelB. 29 | * */ 30 | public class PipelineSelector extends CtxSelector { 31 | private final CtxSelector ctxSelA; 32 | private final CtxSelector ctxSelB; 33 | 34 | public PipelineSelector(CtxSelector lenSelA, CtxSelector lenSelB) { 35 | this.ctxSelA = lenSelA; 36 | this.ctxSelB = lenSelB; 37 | } 38 | 39 | @Override 40 | public Context select(SootMethod m, Context context) { 41 | return ctxSelB.select(m, ctxSelA.select(m, context)); 42 | } 43 | 44 | @Override 45 | public Context select(LocalVarNode lvn, Context context) { 46 | return ctxSelA.select(lvn, ctxSelB.select(lvn, context)); 47 | } 48 | 49 | @Override 50 | public Context select(FieldValNode fvn, Context context) { 51 | return ctxSelA.select(fvn, ctxSelB.select(fvn, context)); 52 | } 53 | 54 | @Override 55 | public Context select(AllocNode heap, Context context) { 56 | return ctxSelA.select(heap, ctxSelB.select(heap, context)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/parm/select/UniformSelector.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.parm.select; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.core.pag.FieldValNode; 23 | import qilin.core.pag.LocalVarNode; 24 | import soot.Context; 25 | import soot.SootMethod; 26 | 27 | public class UniformSelector extends CtxSelector { 28 | private final int k; 29 | private final int hk; 30 | 31 | public UniformSelector(int k, int hk) { 32 | this.k = k; 33 | this.hk = hk; 34 | } 35 | 36 | @Override 37 | public Context select(SootMethod m, Context context) { 38 | return contextTailor(context, k); 39 | } 40 | 41 | @Override 42 | public Context select(LocalVarNode lvn, Context context) { 43 | return contextTailor(context, k); 44 | } 45 | 46 | @Override 47 | public Context select(FieldValNode fvn, Context context) { 48 | return contextTailor(context, k); 49 | } 50 | 51 | @Override 52 | public Context select(AllocNode heap, Context context) { 53 | return contextTailor(context, hk); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/stat/AbstractStat.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.stat; 20 | 21 | public interface AbstractStat { 22 | void export(Exporter exporter); 23 | } 24 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/stat/IEvaluator.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.stat; 20 | 21 | public interface IEvaluator { 22 | int GB = 1024 * 1024 * 1024; 23 | 24 | void begin(); 25 | 26 | void end(); 27 | } 28 | -------------------------------------------------------------------------------- /qilin.core/src/qilin/stat/RuntimeStat.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.stat; 20 | 21 | import java.util.Date; 22 | 23 | public class RuntimeStat implements AbstractStat { 24 | private Date startTime; 25 | private long elapsedTime; 26 | 27 | public void begin() { 28 | startTime = new Date(); 29 | } 30 | 31 | public void end() { 32 | Date endTime = new Date(); 33 | elapsedTime = endTime.getTime() - startTime.getTime(); 34 | } 35 | 36 | @Override 37 | public void export(Exporter exporter) { 38 | exporter.collectMetric("Time (sec):", String.valueOf(((double) elapsedTime) / 1000.0)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /qilin.pta/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | sourceSets.main { 6 | java.srcDirs = ['src'] 7 | } 8 | 9 | sourceSets.test { 10 | java.srcDirs = ['test'] 11 | } 12 | 13 | repositories { 14 | maven { url "https://repo.maven.apache.org/maven2/" } 15 | maven { url "https://repo1.maven.org/maven2/" } 16 | } 17 | 18 | test { 19 | useJUnit() 20 | maxHeapSize = '4096m' 21 | } 22 | 23 | dependencies { 24 | implementation("org.soot-oss:soot:4.6.0") 25 | implementation(project(':qilin.core')) 26 | // https://mvnrepository.com/artifact/commons-cli/commons-cli 27 | implementation group: 'commons-cli', name: 'commons-cli', version: '1.7.0' 28 | implementation group: 'com.google.guava', name: 'guava', version: '33.2.0-jre' 29 | testImplementation group: 'junit', name: 'junit', version: '4.13.2' 30 | } 31 | 32 | -------------------------------------------------------------------------------- /qilin.pta/src/driver/ContextKind.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package driver; 20 | 21 | import qilin.util.Util; 22 | 23 | import java.util.Collection; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | public enum ContextKind { 28 | INSENS, CALLSITE, OBJECT, TYPE, HYBOBJ, HYBTYPE; 29 | static final Map contextKinds = new HashMap<>(); 30 | 31 | static { 32 | Util.add(contextKinds, INSENS, "insensitive", "insens", "ci"); 33 | Util.add(contextKinds, CALLSITE, "callsite", "call", "c"); 34 | Util.add(contextKinds, OBJECT, "object", "obj", "o"); 35 | Util.add(contextKinds, HYBOBJ, "hybobj", "ho", "h"); 36 | Util.add(contextKinds, HYBTYPE, "hybtype", "ht"); 37 | Util.add(contextKinds, TYPE, "type", "t"); 38 | } 39 | 40 | public static Collection contextAliases() { 41 | return contextKinds.keySet(); 42 | } 43 | 44 | public static ContextKind toCtxKind(String name) { 45 | return contextKinds.getOrDefault(name, INSENS); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return switch (this) { 51 | case CALLSITE -> "callsite"; 52 | case OBJECT -> "object"; 53 | case HYBOBJ -> "hybobj"; 54 | case HYBTYPE -> "hybtype"; 55 | case TYPE -> "type"; 56 | default -> "insensitive"; 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/common/DebloatedOAG.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.common; 2 | 3 | import qilin.core.PTA; 4 | import qilin.core.pag.AllocNode; 5 | 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | public class DebloatedOAG extends OAG { 10 | private final Set ctxDepHeaps; 11 | 12 | public DebloatedOAG(PTA prePta, Set ctxDepHeaps) { 13 | super(prePta); 14 | this.ctxDepHeaps = ctxDepHeaps; 15 | } 16 | 17 | @Override 18 | /** 19 | * Add a directed object allocation edge to the OAG. 20 | */ 21 | protected void addEdge(AllocNode src, AllocNode tgt) { 22 | nodes.add(src); 23 | nodes.add(tgt); 24 | if (this.ctxDepHeaps.contains(tgt)) { 25 | this.predecessors.computeIfAbsent(tgt, k -> new HashSet<>()).add(src); 26 | this.successors.computeIfAbsent(src, k -> new HashSet<>()).add(tgt); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/conch/TranEdge.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.conch; 20 | 21 | import qilin.core.pag.Node; 22 | 23 | import java.util.Objects; 24 | 25 | /* 26 | * Transition edges used in define our DFAs. 27 | * */ 28 | public class TranEdge { 29 | private final Node src; 30 | private final Node dst; 31 | private final DFA.TranCond tranCond; 32 | 33 | public TranEdge(Node s, Node d, DFA.TranCond tran) { 34 | this.src = s; 35 | this.dst = d; 36 | this.tranCond = tran; 37 | } 38 | 39 | public Node getSource() { 40 | return src; 41 | } 42 | 43 | public Node getTarget() { 44 | return dst; 45 | } 46 | 47 | public DFA.TranCond getTranCond() { 48 | return tranCond; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (this == o) return true; 54 | if (o == null || getClass() != o.getClass()) return false; 55 | TranEdge tranEdge = (TranEdge) o; 56 | return Objects.equals(src, tranEdge.src) && 57 | Objects.equals(dst, tranEdge.dst) && 58 | tranCond == tranEdge.tranCond; 59 | } 60 | 61 | @Override 62 | public int hashCode() { 63 | return Objects.hash(src, dst, tranCond); 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return src + "\n\t--" + tranCond + "-->\n\t" + dst; 69 | } 70 | } -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/conch/Trilean.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.conch; 20 | 21 | public enum Trilean { 22 | TRUE, FALSE, UNKNOWN; 23 | 24 | public static Trilean OR(Trilean x1, Trilean x2) { 25 | if (x1 == TRUE || x2 == TRUE) { 26 | return TRUE; 27 | } else if (x1 == UNKNOWN || x2 == UNKNOWN) { 28 | return UNKNOWN; 29 | } else { 30 | return FALSE; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/dd/data-driven/README.md: -------------------------------------------------------------------------------- 1 | # References 2 | 3 | 1. [Data-driven context-sensitivity for points-to analysis](https://dl.acm.org/doi/abs/10.1145/3133924) 4 | 5 | 2. [Artifact Link](https://github.com/kupl/Data-Driven-Pointsto-Analysis) -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/dd/tunneling/README.md: -------------------------------------------------------------------------------- 1 | # References 2 | 3 | 1. [Precise and Scalable Points-to Analysis via Data-Driven Context Tunneling](https://dl.acm.org/doi/10.1145/3276510) 4 | 5 | 2. [Artifact Link](https://dl.acm.org/do/10.1145/3276931/full/) -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/debloaterx/Edge.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.debloaterx; 2 | 3 | import qilin.core.pag.Node; 4 | import soot.jimple.spark.pag.SparkField; 5 | 6 | public class Edge { 7 | Node from; 8 | Node to; 9 | SparkField field; 10 | EdgeKind kind; 11 | 12 | Edge(Node from, Node to, SparkField f, EdgeKind kind) { 13 | this.from = from; 14 | this.to = to; 15 | this.field = f; 16 | this.kind = kind; 17 | } 18 | } -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/debloaterx/EdgeKind.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.debloaterx; 2 | 3 | public enum EdgeKind { 4 | // "I" means inverse. 5 | NEW, INEW, 6 | // the following two used for normal assign, cast, and inter-procedural assign for invocations with "this" as the base variable. 7 | // no global assignments are included. 8 | ASSIGN, IASSIGN, 9 | // the following four used only for normal Java store and load. 10 | LOAD, ILOAD, 11 | STORE, ISTORE, 12 | // the following four model parameter passing for non-this invocation. 13 | CLOAD, ICLOAD, 14 | CSTORE, ICSTORE, 15 | // the following three are self-loops. 16 | THIS, ITHIS, 17 | PARAM, 18 | RETURN, 19 | } -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/debloaterx/State.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.debloaterx; 2 | 3 | public enum State { 4 | P, VPlus, VMinus, O, ThisAlias, THIS, End, Error 5 | } 6 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/eagle/BNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.eagle; 20 | 21 | import qilin.core.pag.AllocNode; 22 | import qilin.util.PTAUtils; 23 | 24 | /** 25 | * Original Graph Node(sparkNode) expanded bidirectinally 26 | */ 27 | public class BNode { 28 | public Object sparkNode; 29 | public Boolean forward; 30 | public int level; 31 | public Boolean cs; 32 | 33 | public boolean entryCS() { 34 | if (this.cs) 35 | return false; 36 | return this.cs = true; 37 | } 38 | 39 | public BNode(Object origin, Boolean forward) { 40 | this.sparkNode = origin; 41 | this.forward = forward; 42 | this.cs = false; 43 | this.level = 0; 44 | } 45 | 46 | public Object getIR() { 47 | return PTAUtils.getIR(sparkNode); 48 | } 49 | 50 | boolean isHeapPlus() { 51 | return sparkNode instanceof AllocNode && this.forward; 52 | } 53 | 54 | boolean isHeapMinus() { 55 | return sparkNode instanceof AllocNode && !this.forward; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return sparkNode + "," + forward; 61 | } 62 | } -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/mahjong/automata/DFA.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.mahjong.automata; 2 | 3 | import soot.Type; 4 | 5 | import java.util.HashSet; 6 | import java.util.LinkedList; 7 | import java.util.Queue; 8 | import java.util.Set; 9 | 10 | /** 11 | * @author Tian Tan 12 | * @author Yue Li 13 | *

14 | * refactered by Dongjie He. 15 | */ 16 | public class DFA { 17 | 18 | private Set states, allStates; 19 | private final DFAState q0; 20 | 21 | static final DFAState deadState = new DFAState(); 22 | 23 | public DFA(DFAState q0) { 24 | this.q0 = q0; 25 | } 26 | 27 | /** 28 | * @return Set of states. Does not contains dead state. 29 | */ 30 | public Set getStates() { 31 | if (states == null) { 32 | computeStates(); 33 | } 34 | return states; 35 | } 36 | 37 | /** 38 | * @return Set of all states including dead state. 39 | */ 40 | public Set getAllStates() { 41 | if (allStates == null) { 42 | computeStates(); 43 | } 44 | return allStates; 45 | } 46 | 47 | private void computeStates() { 48 | Queue queue = new LinkedList<>(); 49 | queue.add(q0); 50 | states = new HashSet<>(); 51 | while (!queue.isEmpty()) { 52 | DFAState s = queue.poll(); 53 | if (!states.contains(s)) { 54 | states.add(s); 55 | queue.addAll(s.getNextMap().values()); 56 | } 57 | } 58 | allStates = new HashSet<>(states); 59 | allStates.add(deadState); 60 | } 61 | 62 | public DFAState getStartState() { 63 | return q0; 64 | } 65 | 66 | public static DFAState getDeadState() { 67 | return deadState; 68 | } 69 | 70 | public Set outputOf(DFAState s) { 71 | return s.getOutput(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/selectx/BNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.selectx; 20 | 21 | import qilin.core.pag.Node; 22 | 23 | import java.util.stream.Stream; 24 | 25 | public abstract class BNode { 26 | public Node sparkNode; 27 | /** 28 | * visited is not overrided by para: this represents value flows in *any* contexts, 29 | * this can avoid unmatched exit without missing exit from inner alloc or global 30 | */ 31 | private boolean visited = false; 32 | 33 | BNode(Node origin) { 34 | this.sparkNode = origin; 35 | } 36 | 37 | public void reset() { 38 | visited = false; 39 | } 40 | 41 | public boolean isVisited() { 42 | return this.visited; 43 | } 44 | 45 | public boolean setVisited() { 46 | if (visited) 47 | return false; 48 | return visited = true; 49 | } 50 | 51 | public abstract boolean addOutEdge(BNode to); 52 | 53 | public abstract Stream forwardTargets(); 54 | 55 | @Override 56 | public String toString() { 57 | return this.getClass().toString() + " : " + sparkNode.toString(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/selectx/G.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.selectx; 20 | 21 | import qilin.core.pag.GlobalVarNode; 22 | 23 | import java.util.HashMap; 24 | import java.util.HashSet; 25 | import java.util.Map; 26 | import java.util.Set; 27 | import java.util.stream.Stream; 28 | 29 | public class G extends BNode { 30 | public static Map g2GN = new HashMap<>(); 31 | public static Map g2GP = new HashMap<>(); 32 | 33 | public static G v(GlobalVarNode origin, boolean positive) { 34 | if (positive) { 35 | return g2GP.computeIfAbsent(origin, k -> new G(origin, true)); 36 | } else { 37 | return g2GN.computeIfAbsent(origin, k -> new G(origin, false)); 38 | } 39 | } 40 | 41 | private final Set outLs = new HashSet<>(); 42 | private final boolean positive; 43 | 44 | G(GlobalVarNode origin, boolean positive) { 45 | super(origin); 46 | this.positive = positive; 47 | } 48 | 49 | public boolean addOutEdge(L toE) { 50 | return outLs.add(toE); 51 | } 52 | 53 | @Override 54 | public boolean addOutEdge(BNode toE) { 55 | return addOutEdge((L) toE); 56 | } 57 | 58 | @Override 59 | public Stream forwardTargets() { 60 | return outLs.stream(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/selectx/I.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.selectx; 20 | 21 | import qilin.core.pag.Node; 22 | 23 | import java.util.HashSet; 24 | import java.util.Set; 25 | import java.util.stream.Stream; 26 | 27 | 28 | /** 29 | * local nodes 30 | */ 31 | public abstract class I extends BNode { 32 | private final Set outIs = new HashSet<>(); 33 | protected Set paras = new HashSet<>(); 34 | 35 | I(Node origin) { 36 | super(origin); 37 | } 38 | 39 | public void clearParas() { 40 | this.paras.clear(); 41 | } 42 | 43 | boolean update(I another) { 44 | return this.paras.addAll(another.paras); 45 | } 46 | 47 | public boolean addOutEdge(I to) { 48 | return outIs.add(to); 49 | } 50 | 51 | @Override 52 | public boolean addOutEdge(BNode toE) { 53 | return addOutEdge((I) toE); 54 | } 55 | 56 | @Override 57 | public Stream forwardTargets() { 58 | return outIs.stream(); 59 | } 60 | 61 | public Set getOutTargets() { 62 | return this.outIs; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/selectx/O.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.selectx; 20 | 21 | import qilin.core.pag.AllocNode; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | public class O extends I { 27 | public static Map o2O = new HashMap<>(); 28 | 29 | public static O v(AllocNode origin) { 30 | return o2O.computeIfAbsent(origin, k -> new O(origin)); 31 | } 32 | 33 | public O(AllocNode origin) { 34 | super(origin); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/turner/MethodVFG.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.turner; 20 | 21 | import qilin.core.PTA; 22 | import soot.SootMethod; 23 | 24 | import java.util.Set; 25 | 26 | public class MethodVFG extends AbstractMVFG { 27 | public static AbstractMVFG findOrCreateMethodVFG(PTA prePTA, SootMethod method, OCG hg) { 28 | return method2VFG.computeIfAbsent(method, k -> new MethodVFG(prePTA, method, hg)); 29 | } 30 | 31 | public MethodVFG(PTA prePTA, SootMethod method, OCG hg) { 32 | super(prePTA, hg, method); 33 | buildVFG(); 34 | } 35 | 36 | @Override 37 | protected boolean statisfyAddingLoadCondition(Set targets) { 38 | return true; 39 | } 40 | 41 | @Override 42 | protected boolean satisfyAddingStoreCondition(int paramIndex, Set targets) { 43 | return true; 44 | } 45 | } -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/turner/TranEdge.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.toolkits.turner; 20 | 21 | import java.util.Objects; 22 | 23 | public class TranEdge { 24 | private final Object src; 25 | private final Object dst; 26 | private final DFA.TranCond tranCond; 27 | 28 | public TranEdge(Object s, Object d, DFA.TranCond tran) { 29 | this.src = s; 30 | this.dst = d; 31 | this.tranCond = tran; 32 | } 33 | 34 | public Object getSource() { 35 | return src; 36 | } 37 | 38 | public Object getTarget() { 39 | return dst; 40 | } 41 | 42 | public DFA.TranCond getTranCond() { 43 | return tranCond; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (this == o) return true; 49 | if (o == null || getClass() != o.getClass()) return false; 50 | TranEdge tranEdge = (TranEdge) o; 51 | return Objects.equals(src, tranEdge.src) && 52 | Objects.equals(dst, tranEdge.dst) && 53 | tranCond == tranEdge.tranCond; 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return Objects.hash(src, dst, tranCond); 59 | } 60 | } -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/ReadMe.txt: -------------------------------------------------------------------------------- 1 | Get its source from https://github.com/silverbullettt/zipper.git 2 | Commit: b83b0382580eed3e93e88b9bc07cfe27c2c2af01 3 | Replace original Obj with AllocNode; 4 | Replace original Variable with VarNode; 5 | Replace original Method/InstanceMethod/StaticMethod with SootMethod; 6 | Replace original Field with SparkField; -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/cases/CaseA.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.zipper.cases; 2 | 3 | // NO IN , NO OUT, CASE 4. 4 | public class CaseA { 5 | static class A { 6 | Object f; 7 | } 8 | 9 | A create() { 10 | return new A(); 11 | } 12 | 13 | void foo() { 14 | Object o = new Object(); 15 | A a = create(); 16 | a.f = o; 17 | o = a.f; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/cases/CaseB.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.zipper.cases; 2 | 3 | // No Out, case 2 4 | public class CaseB { 5 | static class A { 6 | Object f; 7 | 8 | void bar(Object q) { 9 | this.f = q; 10 | } 11 | } 12 | 13 | void foo() { 14 | Object oy = new Object(); 15 | Object oz = new Object(); 16 | 17 | A a = new A(); 18 | a.bar(oy); 19 | Object o = a.f; 20 | 21 | // A a1 = new A(); 22 | // a1.bar(oz); 23 | // Object o1 = a1.f; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/cases/CaseC.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.zipper.cases; 2 | 3 | public class CaseC { 4 | static class A { 5 | Object f; 6 | } 7 | 8 | A f; 9 | 10 | // case 2; 11 | CaseC() { 12 | A a = new A(); 13 | this.f = a; 14 | } 15 | 16 | // does not consider this_variable. 17 | A getF() { 18 | A r = this.f; 19 | return r; 20 | } 21 | 22 | void foo() { 23 | Object o1 = new Object(); 24 | CaseC c1 = new CaseC(); 25 | A a1 = c1.getF(); 26 | a1.f = o1; 27 | Object o1x = a1.f; 28 | 29 | // Object o2 = new Object(); 30 | // CaseC c2 = new CaseC(); 31 | // A a2 = c2.getF(); 32 | // a2.f = o2; 33 | // Object o2x = a2.f; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/cases/CaseD.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.zipper.cases; 2 | 3 | public class CaseD { 4 | static class A { 5 | Object f, g; 6 | } 7 | 8 | Object id(Object p) { 9 | A a = new A(); 10 | a.f = p; 11 | Object r = a.f; 12 | return r; 13 | } 14 | 15 | Object fakeId(Object p) { 16 | A a = new A(); 17 | a.f = p; 18 | a.g = new Object(); 19 | return a.g; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/flowgraph/Edge.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.zipper.flowgraph; 2 | 3 | import qilin.core.pag.Node; 4 | 5 | import java.util.Objects; 6 | 7 | public class Edge { 8 | private final Kind kind; 9 | private final Node source; 10 | private final Node target; 11 | private final int hashCode; 12 | 13 | public Edge(final Kind kind, final Node source, final Node target) { 14 | this.kind = kind; 15 | this.source = source; 16 | this.target = target; 17 | this.hashCode = Objects.hash(kind, source, target); 18 | } 19 | 20 | public Kind getKind() { 21 | return this.kind; 22 | } 23 | 24 | public Node getSource() { 25 | return this.source; 26 | } 27 | 28 | public Node getTarget() { 29 | return this.target; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return this.kind + ": " + this.source + " --> " + this.target; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return this.hashCode; 40 | } 41 | 42 | @Override 43 | public boolean equals(final Object other) { 44 | if (this.isOFGEdge()) { 45 | return this == other; 46 | } 47 | if (this == other) { 48 | return true; 49 | } 50 | if (!(other instanceof final Edge otherEdge)) { 51 | return false; 52 | } 53 | return this.kind.equals(otherEdge.kind) && this.source.equals(otherEdge.source) && this.target.equals(otherEdge.target); 54 | } 55 | 56 | private boolean isOFGEdge() { 57 | return this.kind != Kind.WRAPPED_FLOW && this.kind != Kind.UNWRAPPED_FLOW; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/flowgraph/IObjectFlowGraph.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.zipper.flowgraph; 2 | 3 | import qilin.core.pag.Node; 4 | 5 | import java.util.Set; 6 | 7 | public interface IObjectFlowGraph { 8 | Set outEdgesOf(final Node p0); 9 | 10 | Set allNodes(); 11 | } 12 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/flowgraph/Kind.java: -------------------------------------------------------------------------------- 1 | package qilin.pta.toolkits.zipper.flowgraph; 2 | 3 | public enum Kind { 4 | LOCAL_ASSIGN, 5 | INTERPROCEDURAL_ASSIGN, 6 | INSTANCE_LOAD, 7 | INSTANCE_STORE, 8 | WRAPPED_FLOW, 9 | UNWRAPPED_FLOW; 10 | } 11 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/toolkits/zipper/mit.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (C) 2018 Yue Li, Tian Tan, Anders Møller, Yannis Smaragdakis 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/CallSiteSensPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.parm.ctxcons.CallsiteCtxConstructor; 22 | import qilin.parm.heapabst.AllocSiteAbstractor; 23 | import qilin.parm.heapabst.HeuristicAbstractor; 24 | import qilin.parm.select.CtxSelector; 25 | import qilin.parm.select.HeuristicSelector; 26 | import qilin.parm.select.PipelineSelector; 27 | import qilin.parm.select.UniformSelector; 28 | import qilin.pta.PTAConfig; 29 | 30 | /* 31 | * refer to "Two approaches to interprocedural data flow analysis" (PFA 1981) 32 | * */ 33 | 34 | public class CallSiteSensPTA extends BasePTA { 35 | 36 | public CallSiteSensPTA(int k, int hk) { 37 | this.ctxCons = new CallsiteCtxConstructor(); 38 | CtxSelector us = new UniformSelector(k, hk); 39 | if (PTAConfig.v().getPtaConfig().enforceEmptyCtxForIgnoreTypes) { 40 | this.ctxSel = new PipelineSelector(new HeuristicSelector(), us); 41 | } else { 42 | this.ctxSel = us; 43 | } 44 | if (PTAConfig.v().getPtaConfig().mergeHeap) { 45 | this.heapAbst = new HeuristicAbstractor(pag); 46 | } else { 47 | this.heapAbst = new AllocSiteAbstractor(); 48 | } 49 | System.out.println("k-callsite PTA ..."); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/HybridObjectSensPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.parm.ctxcons.HybObjCtxConstructor; 22 | import qilin.parm.heapabst.AllocSiteAbstractor; 23 | import qilin.parm.heapabst.HeuristicAbstractor; 24 | import qilin.parm.select.CtxSelector; 25 | import qilin.parm.select.HeuristicSelector; 26 | import qilin.parm.select.PipelineSelector; 27 | import qilin.parm.select.UniformSelector; 28 | import qilin.pta.PTAConfig; 29 | 30 | /** 31 | * refer to "Hybrid Context-Sensitivity for Points-To Analysis" (PLDI'13) 32 | */ 33 | public class HybridObjectSensPTA extends BasePTA { 34 | 35 | public HybridObjectSensPTA(int k, int hk) { 36 | this.ctxCons = new HybObjCtxConstructor(); 37 | CtxSelector us = new UniformSelector(k + 1, hk); 38 | if (PTAConfig.v().getPtaConfig().enforceEmptyCtxForIgnoreTypes) { 39 | this.ctxSel = new PipelineSelector(new HeuristicSelector(), us); 40 | } else { 41 | this.ctxSel = us; 42 | } 43 | if (PTAConfig.v().getPtaConfig().mergeHeap) { 44 | this.heapAbst = new HeuristicAbstractor(pag); 45 | } else { 46 | this.heapAbst = new AllocSiteAbstractor(); 47 | } 48 | System.out.println("Hybrid k-OBJ ..."); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/HybridTypeSensPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.parm.ctxcons.HybTypeCtxConstructor; 22 | import qilin.parm.heapabst.AllocSiteAbstractor; 23 | import qilin.parm.heapabst.HeuristicAbstractor; 24 | import qilin.parm.select.CtxSelector; 25 | import qilin.parm.select.HeuristicSelector; 26 | import qilin.parm.select.PipelineSelector; 27 | import qilin.parm.select.UniformSelector; 28 | import qilin.pta.PTAConfig; 29 | 30 | /** 31 | * refer to "Hybrid Context-Sensitivity for Points-To Analysis" (PLDI'13) 32 | */ 33 | 34 | public class HybridTypeSensPTA extends BasePTA { 35 | 36 | public HybridTypeSensPTA(int k, int hk) { 37 | this.ctxCons = new HybTypeCtxConstructor(); 38 | CtxSelector us = new UniformSelector(k, hk); 39 | if (PTAConfig.v().getPtaConfig().enforceEmptyCtxForIgnoreTypes) { 40 | this.ctxSel = new PipelineSelector(new HeuristicSelector(), us); 41 | } else { 42 | this.ctxSel = us; 43 | } 44 | if (PTAConfig.v().getPtaConfig().mergeHeap) { 45 | this.heapAbst = new HeuristicAbstractor(pag); 46 | } else { 47 | this.heapAbst = new AllocSiteAbstractor(); 48 | } 49 | System.out.println("Hybrid k-type ..."); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/ObjectSensPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.parm.ctxcons.ObjCtxConstructor; 22 | import qilin.parm.heapabst.AllocSiteAbstractor; 23 | import qilin.parm.heapabst.HeuristicAbstractor; 24 | import qilin.parm.select.CtxSelector; 25 | import qilin.parm.select.HeuristicSelector; 26 | import qilin.parm.select.PipelineSelector; 27 | import qilin.parm.select.UniformSelector; 28 | import qilin.pta.PTAConfig; 29 | 30 | /* 31 | * refer to "Parameterized object sensitivity for points-to analysis for Java" (TSE'05) 32 | * */ 33 | public class ObjectSensPTA extends BasePTA { 34 | public ObjectSensPTA(int k, int hk) { 35 | this.ctxCons = new ObjCtxConstructor(); 36 | CtxSelector us = new UniformSelector(k, hk); 37 | if (PTAConfig.v().getPtaConfig().enforceEmptyCtxForIgnoreTypes) { 38 | this.ctxSel = new PipelineSelector(new HeuristicSelector(), us); 39 | } else { 40 | this.ctxSel = us; 41 | } 42 | if (PTAConfig.v().getPtaConfig().mergeHeap) { 43 | System.out.println(".... Heuristic..."); 44 | this.heapAbst = new HeuristicAbstractor(pag); 45 | } else { 46 | this.heapAbst = new AllocSiteAbstractor(); 47 | } 48 | System.out.println("k-OBJ ..."); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/SelectxPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.pta.toolkits.selectx.Selectx; 22 | 23 | import java.util.Map; 24 | 25 | public class SelectxPTA extends PartialCallSiteSensPTA { 26 | 27 | public SelectxPTA(int ctxLen) { 28 | super(ctxLen); 29 | System.out.println("selectx ... "); 30 | } 31 | 32 | //=========context selector============= 33 | 34 | @Override 35 | protected Map calculatingNode2Length() { 36 | System.out.print("Construct transPAG..."); 37 | long time = System.currentTimeMillis(); 38 | 39 | prePAG = prePTA.getPag(); 40 | Selectx selectx = new Selectx(prePTA); 41 | 42 | System.out.println((System.currentTimeMillis() - time) / 1000 + "s"); 43 | 44 | System.out.println("Propagate.."); 45 | return selectx.process(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/Spark.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.parm.ctxcons.InsensCtxConstructor; 22 | import qilin.parm.heapabst.AllocSiteAbstractor; 23 | import qilin.parm.heapabst.HeuristicAbstractor; 24 | import qilin.parm.select.InsenSelector; 25 | import qilin.pta.PTAConfig; 26 | 27 | /* 28 | * refer to "Scaling Java Points-To Analysis using SPARK" (CC'03) 29 | * */ 30 | public class Spark extends BasePTA { 31 | public Spark() { 32 | this.ctxCons = new InsensCtxConstructor(); 33 | this.ctxSel = new InsenSelector(); 34 | if (PTAConfig.v().getPtaConfig().mergeHeap) { 35 | this.heapAbst = new HeuristicAbstractor(pag); 36 | } else { 37 | this.heapAbst = new AllocSiteAbstractor(); 38 | } 39 | System.out.println("Context-Insensitive ..."); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/StagedPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.pta.PTAConfig; 22 | 23 | /* 24 | * Many recent pointer analyses are two-staged analyses with a preanalysis and a main analysis. 25 | * This class gives a structure for such kinds of analyses. 26 | * */ 27 | public abstract class StagedPTA extends BasePTA { 28 | protected BasePTA prePTA; 29 | 30 | public BasePTA getPrePTA() { 31 | return this.prePTA; 32 | } 33 | 34 | protected abstract void preAnalysis(); 35 | 36 | protected void mainAnalysis() { 37 | if (!PTAConfig.v().getPtaConfig().preAnalysisOnly) { 38 | System.out.println("selective pta starts!"); 39 | super.run(); 40 | } 41 | } 42 | 43 | @Override 44 | public void run() { 45 | preAnalysis(); 46 | prePTA.getPag().resetPointsToSet(); 47 | mainAnalysis(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/TunnelingPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.parm.ctxcons.CtxConstructor; 22 | import qilin.parm.heapabst.AllocSiteAbstractor; 23 | import qilin.parm.heapabst.HeuristicAbstractor; 24 | import qilin.parm.select.CtxSelector; 25 | import qilin.parm.select.HeuristicSelector; 26 | import qilin.parm.select.PipelineSelector; 27 | import qilin.parm.select.UniformSelector; 28 | import qilin.pta.PTAConfig; 29 | import qilin.pta.toolkits.dd.TunnelingConstructor; 30 | 31 | /* 32 | * This class support context tunneling from the paper "Precise and Scalable Points-to Analysis via Data-Driven 33 | * Context Tunneling" (OOPSLA 2018). We reuse the trained formula from the paper. However, our evaluation does 34 | * not show the claimed effectiveness. Maybe we should train the benchmarks to get new formulas? 35 | * */ 36 | public class TunnelingPTA extends BasePTA { 37 | public TunnelingPTA(CtxConstructor ctxCons, int k, int hk) { 38 | this.ctxCons = new TunnelingConstructor(ctxCons); 39 | CtxSelector us = new UniformSelector(k, hk); 40 | if (PTAConfig.v().getPtaConfig().enforceEmptyCtxForIgnoreTypes) { 41 | this.ctxSel = new PipelineSelector(new HeuristicSelector(), us); 42 | } else { 43 | this.ctxSel = us; 44 | } 45 | if (PTAConfig.v().getPtaConfig().mergeHeap) { 46 | this.heapAbst = new HeuristicAbstractor(pag); 47 | } else { 48 | this.heapAbst = new AllocSiteAbstractor(); 49 | } 50 | System.out.println("context-tunneling ..."); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/TurnerPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.pta.toolkits.turner.Turner; 22 | 23 | import java.util.Map; 24 | 25 | /* 26 | * refer to "Accelerating Object-Sensitive Pointer Analysis by Exploiting Object Containment and Reachability" (ECOOP'21) 27 | * */ 28 | public class TurnerPTA extends PartialObjSensPTA { 29 | private final int k; 30 | 31 | public TurnerPTA(int k) { 32 | super(k); 33 | this.k = k; 34 | System.out.println("Turner ..."); 35 | } 36 | 37 | @Override 38 | protected Map calculatingNode2Length() { 39 | Turner turner = new Turner(k, prePTA); 40 | return turner.contxtLengthAnalysis(); 41 | } 42 | } -------------------------------------------------------------------------------- /qilin.pta/src/qilin/pta/tools/TypeSensPTA.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.pta.tools; 20 | 21 | import qilin.parm.ctxcons.TypeCtxConstructor; 22 | import qilin.parm.heapabst.AllocSiteAbstractor; 23 | import qilin.parm.heapabst.HeuristicAbstractor; 24 | import qilin.parm.select.CtxSelector; 25 | import qilin.parm.select.HeuristicSelector; 26 | import qilin.parm.select.PipelineSelector; 27 | import qilin.parm.select.UniformSelector; 28 | import qilin.pta.PTAConfig; 29 | 30 | /* 31 | * refer to "Pick Your Contexts Well: Understanding Object-Sensitivity" (PLDI'11) 32 | * */ 33 | public class TypeSensPTA extends BasePTA { 34 | 35 | public TypeSensPTA(int k, int hk) { 36 | this.ctxCons = new TypeCtxConstructor(); 37 | CtxSelector us = new UniformSelector(k, hk); 38 | if (PTAConfig.v().getPtaConfig().enforceEmptyCtxForIgnoreTypes) { 39 | this.ctxSel = new PipelineSelector(new HeuristicSelector(), us); 40 | } else { 41 | this.ctxSel = us; 42 | } 43 | if (PTAConfig.v().getPtaConfig().mergeHeap) { 44 | this.heapAbst = new HeuristicAbstractor(pag); 45 | } else { 46 | this.heapAbst = new AllocSiteAbstractor(); 47 | } 48 | System.out.println("k-type ..."); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/FlowSensTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test; 20 | 21 | import org.junit.Ignore; 22 | import org.junit.Test; 23 | import qilin.test.util.JunitTests; 24 | 25 | public class FlowSensTests extends JunitTests { 26 | @Test 27 | public void testLoops() { 28 | checkAssertions(run("qilin.microben.flowsens.Loops")); 29 | } 30 | 31 | @Ignore 32 | public void testFlowSens0() { 33 | checkAssertions(run("qilin.microben.flowsens.FlowSens0")); 34 | } 35 | 36 | @Ignore 37 | public void testInstanceOf0() { 38 | checkAssertions(run("qilin.microben.flowsens.InstanceOf0")); 39 | } 40 | 41 | @Ignore 42 | public void testBranching1() { 43 | checkAssertions(run("qilin.microben.flowsens.Branching1")); 44 | } 45 | 46 | @Ignore 47 | public void testStrongUpdate1() { 48 | checkAssertions(run("qilin.microben.flowsens.StrongUpdate1")); 49 | } 50 | 51 | @Ignore 52 | public void testStrongUpdate2() { 53 | checkAssertions(run("qilin.microben.flowsens.StrongUpdate2")); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/context/CFATests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.context; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class CFATests extends JunitTests { 25 | 26 | @Test 27 | public void testCFA1k0() { 28 | checkAssertions(run("qilin.microben.context.cfa.CFA1k0", "1c")); 29 | } 30 | 31 | @Test 32 | public void testCFA1k1() { 33 | checkAssertions(run("qilin.microben.context.cfa.CFA1k1", "1c")); 34 | } 35 | 36 | @Test 37 | public void testCFA1k2() { 38 | checkAssertions(run("qilin.microben.context.cfa.CFA1k2", "1c")); 39 | } 40 | 41 | @Test 42 | public void testCFA2k() { 43 | checkAssertions(run("qilin.microben.context.cfa.CFA2k", "2c")); 44 | } 45 | } -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/context/HybTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.context; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class HybTests extends JunitTests { 25 | @Test 26 | public void testHyb0() { 27 | checkAssertions(run("qilin.microben.context.hyb.Hyb0", "1h")); 28 | } 29 | 30 | @Test 31 | public void testHyb1() { 32 | checkAssertions(run("qilin.microben.context.hyb.Hyb1", "1h")); 33 | } 34 | 35 | @Test 36 | public void testHyb2() { 37 | checkAssertions(run("qilin.microben.context.hyb.Hyb2", "2h")); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/context/OBJTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.context; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class OBJTests extends JunitTests { 25 | @Test 26 | public void testOBJ1k0() { 27 | checkAssertions(run("qilin.microben.context.obj.OBJ1k0", "1o")); 28 | } 29 | 30 | @Test 31 | public void testOBJ1k1() { 32 | checkAssertions(run("qilin.microben.context.obj.OBJ1k1", "1o")); 33 | } 34 | 35 | @Test 36 | public void testOBJ1k2() { 37 | checkAssertions(run("qilin.microben.context.obj.OBJ1k2", "1o")); 38 | } 39 | 40 | @Test 41 | public void testOBJ1k3() { 42 | checkAssertions(run("qilin.microben.context.obj.OBJ1k3", "1o")); 43 | } 44 | 45 | @Test 46 | public void testOBJ1k4() { 47 | checkAssertions(run("qilin.microben.context.obj.OBJ1k4", "1o")); 48 | } 49 | 50 | @Test 51 | public void testOBJ1k5() { 52 | checkAssertions(run("qilin.microben.context.obj.OBJ1k5", "1o")); 53 | } 54 | 55 | @Test 56 | public void testOBJ2k0() { 57 | checkAssertions(run("qilin.microben.context.obj.OBJ2k0", "2o")); 58 | } 59 | 60 | @Test 61 | public void testOBJ2k1() { 62 | checkAssertions(run("qilin.microben.context.obj.OBJ2k1", "2o")); 63 | } 64 | 65 | @Test 66 | public void testOBJ2k2() { 67 | checkAssertions(run("qilin.microben.context.obj.OBJ2k2", "2o")); 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/context/TypeTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.context; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class TypeTests extends JunitTests { 25 | @Test 26 | public void testType1k0() { 27 | checkAssertions(run("qilin.microben.context.type.Type1k0", "1t")); 28 | } 29 | 30 | @Test 31 | public void testType2k0() { 32 | checkAssertions(run("qilin.microben.context.type.Type2k0", "2t")); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/core/ArrayTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.core; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class ArrayTests extends JunitTests { 25 | @Test 26 | public void testArrayIndex() { 27 | checkAssertions(run("qilin.microben.core.array.ArrayIndex")); 28 | } 29 | 30 | @Test 31 | public void testMultiArraySimple() { 32 | checkAssertions(run("qilin.microben.core.array.MultiArraySimple")); 33 | } 34 | 35 | @Test 36 | public void testMultiArrayComplex() { 37 | checkAssertions(run("qilin.microben.core.array.MultiArrayComplex")); 38 | } 39 | 40 | @Test 41 | public void testArrayCopy() { 42 | checkAssertions(run("qilin.microben.core.array.ArrayCopy")); 43 | } 44 | 45 | @Test 46 | public void testArrayElemTypeFiltering() { 47 | checkAssertions(run("qilin.microben.core.array.ArrayElemTypeFiltering")); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/core/CallTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.core; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class CallTests extends JunitTests { 25 | @Test 26 | public void testVirtualCall0() { 27 | checkAssertions(run("qilin.microben.core.call.VirtualCall0")); 28 | } 29 | 30 | @Test 31 | public void testVirtualCall1() { 32 | checkAssertions(run("qilin.microben.core.call.VirtualCall1")); 33 | } 34 | 35 | @Test 36 | public void testStaticCall() { 37 | checkAssertions(run("qilin.microben.core.call.StaticCall")); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/core/ClinitTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.core; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class ClinitTests extends JunitTests { 25 | @Test 26 | public void testClinitNewExpr() { 27 | checkAssertions(run("qilin.microben.core.clinit.ClinitNewExpr")); 28 | } 29 | 30 | @Test 31 | public void testClinitStaticCall() { 32 | checkAssertions(run("qilin.microben.core.clinit.ClinitStaticCall")); 33 | } 34 | 35 | @Test 36 | public void testClinitStaticLoad() { 37 | checkAssertions(run("qilin.microben.core.clinit.ClinitStaticLoad")); 38 | } 39 | 40 | @Test 41 | public void testClinitStaticStore() { 42 | checkAssertions(run("qilin.microben.core.clinit.ClinitStaticStore")); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/core/ExceptionTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.core; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class ExceptionTests extends JunitTests { 25 | @Test 26 | public void testSimpleException() { 27 | checkAssertions(run("qilin.microben.core.exception.SimpleException")); 28 | } 29 | 30 | @Test 31 | public void testExceptionChain() { 32 | checkAssertions(run("qilin.microben.core.exception.ExceptionChain")); 33 | } 34 | 35 | @Test 36 | public void testMethodThrow() { 37 | checkAssertions(run("qilin.microben.core.exception.MethodThrow")); 38 | } 39 | } -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/core/FieldTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.core; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class FieldTests extends JunitTests { 25 | @Test 26 | public void testInstanceLoad() { 27 | checkAssertions(run("qilin.microben.core.field.InstanceLoad")); 28 | } 29 | 30 | @Test 31 | public void testInstanceStore() { 32 | checkAssertions(run("qilin.microben.core.field.InstanceStore")); 33 | } 34 | 35 | @Test 36 | public void testFieldSensitivity1() { 37 | checkAssertions(run("qilin.microben.core.field.FieldSensitivity1")); 38 | } 39 | 40 | @Test 41 | public void testFieldSensitivity2() { 42 | checkAssertions(run("qilin.microben.core.field.FieldSensitivity2")); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/core/GlobalTests.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.core; 20 | 21 | import org.junit.Test; 22 | import qilin.test.util.JunitTests; 23 | 24 | public class GlobalTests extends JunitTests { 25 | @Test 26 | public void testStaticLoad() { 27 | checkAssertions(run("qilin.microben.core.global.StaticLoad")); 28 | } 29 | 30 | @Test 31 | public void testStaticStore() { 32 | checkAssertions(run("qilin.microben.core.global.StaticStore")); 33 | } 34 | 35 | @Test 36 | public void testStringConstant() { 37 | checkAssertions(run("qilin.microben.core.global.StringConstant")); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /qilin.pta/test/qilin/test/util/IAssertion.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.test.util; 20 | 21 | public interface IAssertion { 22 | boolean check(); 23 | } 24 | -------------------------------------------------------------------------------- /qilin.util/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | sourceSets.main { 6 | java.srcDirs = ['src'] 7 | } 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | implementation 'com.github.oshi:oshi-core:6.6.0' 15 | } 16 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/ANSIColor.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util; 20 | 21 | public class ANSIColor { 22 | public static final String RESET = "\u001b[0m"; 23 | public static final String BOLD = "\u001b[1m"; 24 | public static final String BLACK = "\u001b[30m"; 25 | public static final String RED = "\u001b[31m"; 26 | public static final String GREEN = "\u001b[32m"; 27 | public static final String YELLOW = "\u001b[33m"; 28 | public static final String BLUE = "\u001b[34m"; 29 | public static final String PURPLE = "\u001b[35m"; 30 | public static final String CYAN = "\u001b[36m"; 31 | public static final String WHITE = "\u001b[37m"; 32 | public static final String BG_BLACK = "\u001b[40m"; 33 | 34 | public static String color(final String color, final String s) { 35 | return color + s + RESET; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/DataFactory.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util; 20 | 21 | import java.util.ArrayList; 22 | import java.util.HashMap; 23 | import java.util.HashSet; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Set; 27 | 28 | public class DataFactory { 29 | public static List createList() { 30 | return new ArrayList<>(); 31 | // return new CopyOnWriteArrayList<>(); 32 | } 33 | 34 | public static Set createSet() { 35 | return new HashSet<>(); 36 | // return ConcurrentHashMap.newKeySet(); 37 | } 38 | 39 | public static Set createSet(int initCapacity) { 40 | return new HashSet<>(initCapacity); 41 | // return ConcurrentHashMap.newKeySet(initCapacity); 42 | } 43 | 44 | public static Map createMap() { 45 | return new HashMap<>(); 46 | // return new ConcurrentHashMap<>(); 47 | } 48 | 49 | public static Map createMap(int initCapacity) { 50 | return new HashMap<>(initCapacity); 51 | // return new ConcurrentHashMap<>(initCapacity); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/Pair.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util; 20 | 21 | import java.util.Objects; 22 | 23 | public class Pair { 24 | 25 | private final T1 first; 26 | private final T2 second; 27 | 28 | public Pair(T1 first, T2 second) { 29 | this.first = first; 30 | this.second = second; 31 | } 32 | 33 | public T1 getFirst() { 34 | return first; 35 | } 36 | 37 | public T2 getSecond() { 38 | return second; 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return Objects.hash(first, second); 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (o instanceof Pair anoPair) { 49 | return Objects.equals(first, anoPair.first) && Objects.equals(second, anoPair.second); 50 | } 51 | return false; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "<" + first + ", " + second + ">"; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/Stopwatch.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util; 20 | 21 | public class Stopwatch { 22 | private final String name; 23 | private long elapsedTime; 24 | private long startTime; 25 | private boolean inCounting; 26 | 27 | public static Stopwatch newAndStart(final String name) { 28 | Stopwatch stopwatch = new Stopwatch(name); 29 | stopwatch.start(); 30 | return stopwatch; 31 | } 32 | 33 | private Stopwatch(final String name) { 34 | this.elapsedTime = 0L; 35 | this.inCounting = false; 36 | this.name = name; 37 | } 38 | 39 | private void start() { 40 | if (!this.inCounting) { 41 | this.inCounting = true; 42 | this.startTime = System.currentTimeMillis(); 43 | } 44 | } 45 | 46 | public void stop() { 47 | if (this.inCounting) { 48 | this.elapsedTime += System.currentTimeMillis() - this.startTime; 49 | this.inCounting = false; 50 | } 51 | } 52 | 53 | public float elapsed() { 54 | return this.elapsedTime / 1000.0f; 55 | } 56 | 57 | public void reset() { 58 | this.elapsedTime = 0L; 59 | this.inCounting = false; 60 | } 61 | 62 | public void restart() { 63 | reset(); 64 | start(); 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return String.format("%s elapsed time: %.2fs", this.name, this.elapsed()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/Triple.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util; 20 | 21 | import java.util.Objects; 22 | 23 | public class Triple { 24 | private final T1 first; 25 | private final T2 second; 26 | private final T3 third; 27 | 28 | public Triple(final T1 first, final T2 second, final T3 third) { 29 | this.first = first; 30 | this.second = second; 31 | this.third = third; 32 | } 33 | 34 | public T1 getFirst() { 35 | return this.first; 36 | } 37 | 38 | public T2 getSecond() { 39 | return this.second; 40 | } 41 | 42 | public T3 getThird() { 43 | return this.third; 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | return Objects.hash(this.first, this.second, this.third); 49 | } 50 | 51 | @Override 52 | public boolean equals(final Object o) { 53 | if (o instanceof final Triple anoTriple) { 54 | return Objects.equals(this.first, anoTriple.first) && Objects.equals(this.second, anoTriple.second) 55 | && Objects.equals(this.third, anoTriple.third); 56 | } 57 | return false; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "<" + this.first + ", " + this.second + ", " 63 | + this.third + ">"; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/collect/SetFactory.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util.collect; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | import java.util.Set; 24 | 25 | public class SetFactory { 26 | private final Map, Set> sets; 27 | 28 | public SetFactory() { 29 | this.sets = new HashMap<>(); 30 | } 31 | 32 | public Set get(final Set set) { 33 | if (!this.sets.containsKey(set)) { 34 | this.sets.put(set, set); 35 | } 36 | return this.sets.get(set); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/graph/ConcurrentDirectedGraphImpl.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util.graph; 20 | 21 | import java.util.Collection; 22 | import java.util.Collections; 23 | import java.util.Map; 24 | import java.util.Set; 25 | import java.util.concurrent.ConcurrentHashMap; 26 | 27 | public class ConcurrentDirectedGraphImpl implements DirectedGraph { 28 | protected Set nodes; 29 | protected Map> preds; 30 | protected Map> succs; 31 | 32 | public ConcurrentDirectedGraphImpl() { 33 | this.nodes = ConcurrentHashMap.newKeySet(); 34 | this.preds = new ConcurrentHashMap<>(); 35 | this.succs = new ConcurrentHashMap<>(); 36 | } 37 | 38 | public void addNode(final N node) { 39 | this.nodes.add(node); 40 | } 41 | 42 | public void addEdge(final N from, final N to) { 43 | this.addNode(from); 44 | this.addNode(to); 45 | this.preds.computeIfAbsent(to, k -> ConcurrentHashMap.newKeySet()).add(from); 46 | this.succs.computeIfAbsent(from, k -> ConcurrentHashMap.newKeySet()).add(to); 47 | } 48 | 49 | @Override 50 | public Collection allNodes() { 51 | return this.nodes; 52 | } 53 | 54 | @Override 55 | public Collection predsOf(final N n) { 56 | return this.preds.getOrDefault(n, Collections.emptySet()); 57 | } 58 | 59 | @Override 60 | public Collection succsOf(final N n) { 61 | return this.succs.getOrDefault(n, Collections.emptySet()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/graph/DirectedGraph.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util.graph; 20 | 21 | import java.util.Collection; 22 | import java.util.HashSet; 23 | import java.util.Set; 24 | import java.util.Stack; 25 | import java.util.stream.Collectors; 26 | 27 | public interface DirectedGraph { 28 | Collection allNodes(); 29 | 30 | Collection predsOf(final N p); 31 | 32 | Collection succsOf(final N p); 33 | 34 | /* no cache, very slow.*/ 35 | default Collection computeReachableNodes(N source) { 36 | Set reachableNodes = new HashSet<>(); 37 | Stack stack = new Stack<>(); 38 | stack.push(source); 39 | while (!stack.isEmpty()) { 40 | N node = stack.pop(); 41 | if (reachableNodes.add(node)) { 42 | stack.addAll(succsOf(node)); 43 | } 44 | } 45 | return reachableNodes; 46 | } 47 | 48 | default Collection computeRootNodes() { 49 | return allNodes().stream().filter(node -> predsOf(node).size() == 0).collect(Collectors.toSet()); 50 | } 51 | 52 | default Collection computeTailNodes() { 53 | return allNodes().stream().filter(node -> succsOf(node).size() == 0).collect(Collectors.toSet()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/graph/DirectedGraphImpl.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util.graph; 20 | 21 | import java.util.Collection; 22 | import java.util.Collections; 23 | import java.util.HashMap; 24 | import java.util.HashSet; 25 | import java.util.Map; 26 | import java.util.Set; 27 | 28 | public class DirectedGraphImpl implements DirectedGraph { 29 | protected Set nodes; 30 | protected Map> preds; 31 | protected Map> succs; 32 | 33 | public DirectedGraphImpl() { 34 | this.nodes = new HashSet<>(); 35 | this.preds = new HashMap<>(); 36 | this.succs = new HashMap<>(); 37 | } 38 | 39 | public void addNode(final N node) { 40 | this.nodes.add(node); 41 | } 42 | 43 | public void addEdge(final N from, final N to) { 44 | this.addNode(from); 45 | this.addNode(to); 46 | this.preds.computeIfAbsent(to, k -> new HashSet<>()).add(from); 47 | this.succs.computeIfAbsent(from, k -> new HashSet<>()).add(to); 48 | } 49 | 50 | @Override 51 | public Collection allNodes() { 52 | return this.nodes; 53 | } 54 | 55 | @Override 56 | public Collection predsOf(final N n) { 57 | return this.preds.getOrDefault(n, Collections.emptySet()); 58 | } 59 | 60 | @Override 61 | public Collection succsOf(final N n) { 62 | return this.succs.getOrDefault(n, Collections.emptySet()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/graph/MergedNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util.graph; 20 | 21 | import java.util.Collection; 22 | import java.util.Collections; 23 | import java.util.HashSet; 24 | import java.util.Set; 25 | 26 | public class MergedNode { 27 | private Set> preds; 28 | private Set> succs; 29 | private final Set content; 30 | 31 | public MergedNode(final Collection content) { 32 | this.content = new HashSet<>(content); 33 | } 34 | 35 | public void addPred(final MergedNode pred) { 36 | if (this.preds == null) { 37 | this.preds = new HashSet<>(4); 38 | } 39 | this.preds.add(pred); 40 | } 41 | 42 | public Set> getPreds() { 43 | return (this.preds == null) ? Collections.emptySet() : this.preds; 44 | } 45 | 46 | public void addSucc(final MergedNode succ) { 47 | if (this.succs == null) { 48 | this.succs = new HashSet<>(4); 49 | } 50 | this.succs.add(succ); 51 | } 52 | 53 | public Set> getSuccs() { 54 | return (this.succs == null) ? Collections.emptySet() : this.succs; 55 | } 56 | 57 | public Set getContent() { 58 | return this.content; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return this.content.toString(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/graph/TopologicalSorter.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util.graph; 20 | 21 | import java.util.Collections; 22 | import java.util.HashSet; 23 | import java.util.LinkedList; 24 | import java.util.List; 25 | import java.util.Set; 26 | 27 | public class TopologicalSorter { 28 | private DirectedGraph graph; 29 | private List sortedList; 30 | private Set visited; 31 | 32 | public List sort(final DirectedGraph graph) { 33 | return this.sort(graph, false); 34 | } 35 | 36 | public List sort(final DirectedGraph graph, final boolean reverse) { 37 | this.initialize(graph); 38 | graph.allNodes().stream().filter(n -> graph.succsOf(n).isEmpty()).forEach(this::visit); 39 | List result = this.sortedList; 40 | if (reverse) { 41 | Collections.reverse(result); 42 | } 43 | this.clear(); 44 | return result; 45 | } 46 | 47 | private void initialize(final DirectedGraph graph) { 48 | this.graph = graph; 49 | this.sortedList = new LinkedList<>(); 50 | this.visited = new HashSet<>(); 51 | } 52 | 53 | private void visit(final N node) { 54 | if (!this.visited.contains(node)) { 55 | this.visited.add(node); 56 | this.graph.predsOf(node).forEach(this::visit); 57 | this.sortedList.add(node); 58 | } 59 | } 60 | 61 | private void clear() { 62 | this.graph = null; 63 | this.sortedList = null; 64 | this.visited = null; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/graph/Tree.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util.graph; 20 | 21 | import java.util.Collection; 22 | 23 | public interface Tree { 24 | N getRoot(); 25 | 26 | Collection getLeaves(); 27 | 28 | boolean isALeaf(N n); 29 | 30 | Collection getAllNodes(); 31 | 32 | int size(); 33 | 34 | N parentOf(N n); 35 | 36 | Collection childrenOf(N n); 37 | } 38 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/graph/TreeNode.java: -------------------------------------------------------------------------------- 1 | /* Qilin - a Java Pointer Analysis Framework 2 | * Copyright (C) 2021-2030 Qilin developers 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as 6 | * published by the Free Software Foundation, either version 3.0 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Lesser Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Lesser Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | package qilin.util.graph; 20 | 21 | import java.util.HashSet; 22 | import java.util.Set; 23 | 24 | public class TreeNode { 25 | private final D elem; 26 | private TreeNode parent; 27 | private final Set> children; 28 | 29 | public TreeNode(D e) { 30 | this.elem = e; 31 | this.children = new HashSet<>(); 32 | } 33 | 34 | public D getElem() { 35 | return elem; 36 | } 37 | 38 | public TreeNode getParent() { 39 | return parent; 40 | } 41 | 42 | public boolean isLeaf() { 43 | return this.children.isEmpty(); 44 | } 45 | 46 | public boolean isRoot() { 47 | return this.parent == null; 48 | } 49 | 50 | public void setParent(TreeNode parent) { 51 | this.parent = parent; 52 | } 53 | 54 | public Set> getChildren() { 55 | return children; 56 | } 57 | 58 | public boolean addChild(TreeNode child) { 59 | return this.children.add(child); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/package.html: -------------------------------------------------------------------------------- 1 | 22 | 23 | Soot utility classes 24 | 25 | Generally useful utility classes for Soot. 26 | 27 | 28 | -------------------------------------------------------------------------------- /qilin.util/src/qilin/util/queue/package.html: -------------------------------------------------------------------------------- 1 | 22 | 23 | Soot queue classes 24 | 25 | An efficient queue implementation to be used generally within Soot. 26 | 27 | 28 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./gradlew clean fatjar 3 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Qilin' 2 | include 'qilin.util' 3 | include 'qilin.core' 4 | include 'qilin.pta' 5 | 6 | --------------------------------------------------------------------------------