├── .DS_Store ├── .github └── workflows │ ├── docker-publish.yml │ └── svf-teaching.yml ├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── Assignment-1 ├── Assignment-1.cpp ├── Assignment-1.h ├── CMakeLists.txt └── Test1.cpp ├── Assignment-2 ├── Assignment-2.cpp ├── Assignment-2.h ├── CMakeLists.txt ├── Test2.cpp └── testcase │ ├── bc │ ├── test1.ll │ ├── test2.ll │ └── test3.ll │ ├── dot │ ├── test1.ll.icfg.dot │ ├── test2.ll.icfg.dot │ └── test3.ll.icfg.dot │ └── src │ ├── test1.c │ ├── test2.c │ └── test3.c ├── Assignment-3 ├── Assignment-3.cpp ├── Assignment-3.h ├── CMakeLists.txt ├── Test3.cpp └── testcase │ ├── .DS_Store │ ├── bc │ ├── CI-global.ll │ ├── CI-local.ll │ └── no_alias.ll │ ├── dot │ ├── CI-global_final.dot │ ├── CI-local_final.dot │ └── no_alias_final.dot │ └── src │ ├── CI-global.c │ ├── CI-local.c │ └── no_alias.c ├── Assignment-4 ├── Assignment-4.cpp ├── Assignment-4.h ├── CMakeLists.txt ├── SrcSnk.txt ├── Test4.cpp └── testcase │ ├── bc │ ├── test1.ll │ ├── test2.ll │ ├── test3.ll │ └── test4.ll │ └── src │ ├── test1.c │ ├── test2.c │ ├── test3.c │ └── test4.c ├── CMakeLists.txt ├── CodeGraph ├── CMakeLists.txt ├── CodeGraph.cpp ├── compile.sh └── src │ ├── example.c │ └── swap.c ├── Dockerfile ├── HelloWorld ├── CMakeLists.txt └── hello.cpp ├── LICENSE ├── README.md ├── build.sh └── env.sh /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SVF-tools/Teaching-Software-Analysis/41226d0a09aa64947e735fadea56492d8296436a/.DS_Store -------------------------------------------------------------------------------- /.github/workflows/docker-publish.yml: -------------------------------------------------------------------------------- 1 | name: Docker 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | repository_dispatch: 7 | types: [ new-commit-from-SVF ] 8 | 9 | jobs: 10 | docker-image: 11 | if: github.repository == 'SVF-tools/Teaching-Software-Analysis' 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | 18 | - name: Login to Docker Hub 19 | uses: docker/login-action@v1 20 | with: 21 | username: ${{secrets.DOCKER_USER}} 22 | password: ${{secrets.DOCKER_PASSWD}} 23 | 24 | - name: Set up QEMU (Support ARM64) 25 | uses: docker/setup-qemu-action@v2 26 | 27 | - name: Set up Docker Buildx 28 | uses: docker/setup-buildx-action@v2 29 | 30 | - name: Build and push x86 and ARM64 images 31 | uses: docker/build-push-action@v2 32 | with: 33 | context: . 34 | file: ./Dockerfile 35 | push: true 36 | platforms: linux/amd64,linux/arm64 37 | tags: | 38 | ${{secrets.DOCKER_USER}}/teaching-software-analysis:latest 39 | ${{secrets.DOCKER_USER}}/teaching-software-analysis:latest-arm64 40 | -------------------------------------------------------------------------------- /.github/workflows/svf-teaching.yml: -------------------------------------------------------------------------------- 1 | name: svf-teaching 2 | 3 | # Triggers the workflow on push or pull request events 4 | on: [push, pull_request] 5 | 6 | jobs: 7 | build: 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest, macos-latest] 12 | env: 13 | XCODE_VERSION: '15.3.0' 14 | steps: 15 | # checkout the repo 16 | - uses: actions/checkout@v2 17 | - uses: actions/setup-node@v3 18 | with: 19 | node-version: 18 20 | 21 | # setup the mac/ubuntu environment 22 | - name: mac-setup 23 | if: runner.os == 'macOS' 24 | uses: maxim-lobanov/setup-xcode@v1 25 | with: 26 | xcode-version: ${{ env.XCODE_VERSION }} 27 | - name: mac-setup-workaround 28 | if: runner.os == 'macOS' 29 | run: ln -sfn /Applications/Xcode_${{ env.XCODE_VERSION }}.app /Applications/Xcode.app 30 | - name: ubuntu-setup 31 | if: runner.os == 'Linux' 32 | run: | 33 | sudo apt-get update 34 | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 35 | sudo apt-get update 36 | sudo apt-get install cmake gcc g++ nodejs doxygen graphviz lcov libncurses5-dev libtinfo6 libzstd-dev 37 | 38 | # install llvm and svf 39 | - name: env-setup 40 | run: | 41 | npm install svf-lib 42 | # set SVF_DIR, LLVM_DIR and Z3_DIR and build 43 | - name: build 44 | run: | 45 | export SVF_DIR=$(npm root)/SVF 46 | export LLVM_DIR=$(npm root)/llvm-16.0.0.obj 47 | export Z3_DIR=$(npm root)/z3.obj 48 | echo "SVF_DIR="$SVF_DIR 49 | echo "LLVM_DIR="$LLVM_DIR 50 | echo "Z3_DIR="$Z3_DIR 51 | cmake . 52 | make 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | BUILD/ 2 | build/ -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "/usr/local/include/**", 7 | "${workspaceFolder}/**", 8 | "../SVF/**" 9 | ], 10 | "defines": [], 11 | "compilerPath": "/usr/bin/g++", 12 | "cStandard": "gnu11", 13 | "cppStandard": "gnu++17", 14 | "intelliSenseMode": "linux-gcc-x64" 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(debug) Launch", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Please change to the executable of your current lab or assignment 9 | "program": "${workspaceFolder}/bin/hello", 10 | "args": [], // may input the test llvm bc file or other options and flags the program may use 11 | "cwd": "${workspaceFolder}", 12 | "preLaunchTask": "C/C++: cpp build active file", 13 | "MIMode": "lldb", 14 | "setupCommands": [ 15 | { 16 | "description": "Enable pretty-printing for gdb", 17 | "text": "-enable-pretty-printing", 18 | "ignoreFailures": true 19 | } 20 | ] 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.intelliSenseEngine": "Default" 3 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "label": "C/C++: cpp build active file", 5 | "type": "shell", 6 | // if you run SVF-Teaching not in docker container, you need to change the LLVM_DIR and SVF_DIR 7 | "command": "cmake -DCMAKE_BUILD_TYPE=Debug -DSVF_DIR=../SVF -DLLVM_DIR=../SVF/llvm-16.0.0.obj -DZ3_DIR=../SVF/z3.obj . && make", 8 | "options": { 9 | "cwd": "${workspaceFolder}" 10 | }, 11 | "group": { 12 | "kind": "build", 13 | "isDefault": true 14 | }, 15 | "detail": "Task generated by Debugger." 16 | } 17 | ], 18 | "version": "2.0.0" 19 | } -------------------------------------------------------------------------------- /Assignment-1/Assignment-1.cpp: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 1-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 1 : Graph Traversal 25 | // 26 | // 27 | */ 28 | 29 | 30 | #include "Assignment-1.h" 31 | using namespace std; 32 | 33 | /// TODO: print each path once this method is called, and 34 | /// add each path as a string into std::set paths 35 | /// Print the path in the format "START: 1->2->4->5->END", where -> indicate an edge connecting two node IDs 36 | void GraphTraversal::printPath(std::vector &path) 37 | { 38 | 39 | }; 40 | 41 | /// TODO: Implement your depth first search here to traverse each program path (once for any loop) from src to dst 42 | void GraphTraversal::DFS(set &visited, vector &path, const Node *src, const Node *dst) 43 | { 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Assignment-1/Assignment-1.h: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 1-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 1 : Graph Traversal 25 | // 26 | // 27 | */ 28 | 29 | #ifndef ASSIGNMENT_1_H_ 30 | #define ASSIGNMENT_1_H_ 31 | #include 32 | #include 33 | #include 34 | //declare 35 | class Node; 36 | class Edge; 37 | 38 | class Node 39 | { 40 | private: 41 | int nodeID; 42 | std::set outEdges; // outgoing edges of this node 43 | 44 | public: 45 | // constructor 46 | Node(int i) { 47 | nodeID = i; 48 | } 49 | 50 | // Get the private attribute nodeID 51 | int getNodeID() const { 52 | return nodeID; 53 | } 54 | 55 | // Get the private attribute outEdges 56 | std::set getOutEdges() const { 57 | return outEdges; 58 | } 59 | 60 | // Add an edge into outEdges 61 | void addOutEdge(const Edge *edge) { 62 | outEdges.insert(edge); 63 | } 64 | }; 65 | 66 | class Edge 67 | { 68 | private: 69 | Node *src; // source node of the edge 70 | Node *dst; // target node of the edge 71 | 72 | public: 73 | // Constructor 74 | Edge(Node *s, Node *d) : src(s), dst(d){ 75 | } 76 | // Get the source node 77 | Node *getSrc() const { 78 | return src; 79 | } 80 | 81 | // Get the target node 82 | Node *getDst() const { 83 | return dst; 84 | } 85 | }; 86 | 87 | class Graph 88 | { 89 | private: 90 | std::set nodes; // a set of nodes on the graph 91 | 92 | public: 93 | Graph(){}; 94 | // Get all the nodes of the graph 95 | std::set &getNodes() { 96 | return nodes; 97 | } 98 | // Add a node into the graph 99 | void addNode(const Node *node) { 100 | nodes.insert(node); 101 | } 102 | }; 103 | 104 | 105 | class GraphTraversal 106 | { 107 | public: 108 | // Constructor 109 | GraphTraversal(){}; 110 | // Destructor 111 | ~GraphTraversal(){}; 112 | 113 | /// To be implemented 114 | void printPath(std::vector &path); 115 | 116 | /// To be implemented 117 | void DFS(std::set &visited, std::vector &path, const Node *src, const Node *dst); 118 | 119 | // Retrieve all paths (a set of strings) during graph traversal 120 | std::set& getPaths(){ 121 | return paths; 122 | } 123 | 124 | private: 125 | std::set paths; 126 | }; 127 | 128 | #endif -------------------------------------------------------------------------------- /Assignment-1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(assign-1 Assignment-1.cpp Test1.cpp) 2 | set_target_properties( assign-1 PROPERTIES 3 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) -------------------------------------------------------------------------------- /Assignment-1/Test1.cpp: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 1-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 1 : Graph Traversal 25 | // 26 | // 27 | */ 28 | 29 | #include "Assignment-1.h" 30 | #include 31 | 32 | void Test1() 33 | { 34 | /* 35 | 36 | 37 | 1 38 | / \ 39 | 2 3 40 | \ / 41 | 4 42 | | 43 | 5 44 | 45 | */ 46 | // init nodes 47 | Node *node1 = new Node(1); 48 | Node *node2 = new Node(2); 49 | Node *node3 = new Node(3); 50 | Node *node4 = new Node(4); 51 | Node *node5 = new Node(5); 52 | 53 | // init edges 54 | Edge *edge1 = new Edge(node1, node2); 55 | Edge *edge2 = new Edge(node1, node3); 56 | node1->addOutEdge(edge1); 57 | node1->addOutEdge(edge2); 58 | Edge *edge3 = new Edge(node2, node4); 59 | Edge *edge4 = new Edge(node3, node4); 60 | node2->addOutEdge(edge3); 61 | node3->addOutEdge(edge4); 62 | Edge *edge5 = new Edge(node4, node5); 63 | node4->addOutEdge(edge5); 64 | 65 | // init Graph 66 | Graph *g = new Graph(); 67 | g->addNode(node1); 68 | g->addNode(node2); 69 | g->addNode(node3); 70 | g->addNode(node4); 71 | g->addNode(node5); 72 | // test 73 | std::set expected_answer{"START: 1->2->4->5->END", "START: 1->3->4->5->END"}; 74 | std::set visited; 75 | std::vector path; 76 | GraphTraversal *dfs = new GraphTraversal(); 77 | dfs->DFS(visited, path, node1, node5); 78 | assert(dfs->getPaths() == expected_answer && "Test case 1 failed!"); 79 | std::cout << "Test case 1 passed!\n"; 80 | } 81 | 82 | /// Entry of the program 83 | int main() 84 | { 85 | Test1(); 86 | return 0; 87 | } -------------------------------------------------------------------------------- /Assignment-2/Assignment-2.cpp: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 2-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | /* 23 | // Software-Analysis-Teaching Assignment 2 : Source Sink ICFG DFS Traversal 24 | // 25 | // 26 | */ 27 | 28 | #include 29 | #include "Assignment-2.h" 30 | #include 31 | using namespace SVF; 32 | using namespace std; 33 | 34 | /// TODO: print each path once this method is called, and 35 | /// add each path as a string into std::set paths 36 | /// Print the path in the format "START->1->2->4->5->END", where -> indicate an ICFGEdge connects two ICFGNode IDs 37 | 38 | void ICFGTraversal::collectICFGPath(std::vector &path){ 39 | 40 | } 41 | 42 | 43 | /// TODO: Implement your context-sensitive ICFG traversal here to traverse each program path (once for any loop) from src to dst 44 | void ICFGTraversal::reachability(const ICFGNode *src, const ICFGNode *dst) 45 | { 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Assignment-2/Assignment-2.h: -------------------------------------------------------------------------------- 1 | //===- SVF-Teaching Assignment 2-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | /* 23 | // Software-Analysis-Teaching Assignment 2 : Source Sink ICFG DFS Traversal 24 | // 25 | // 26 | */ 27 | #ifndef ASSIGNMENT_2_H_ 28 | #define ASSIGNMENT_2_H_ 29 | 30 | #include "SVF-LLVM/LLVMUtil.h" 31 | #include "SVF-LLVM/SVFIRBuilder.h" 32 | using namespace SVF; 33 | 34 | class ICFGTraversal 35 | { 36 | public: 37 | typedef std::vector CallStack; 38 | 39 | public: 40 | 41 | ICFGTraversal(SVFIR *p) : pag(p) {} 42 | 43 | /// TODO: to be implemented 44 | virtual void collectICFGPath(std::vector &path); 45 | 46 | /// TODO: to be implemented context sensitive DFS 47 | void reachability(const ICFGNode *src, const ICFGNode *dst); 48 | 49 | // Identify source nodes on ICFG (i.e., call instruction with its callee function named 'src') 50 | virtual std::set &identifySources() 51 | { 52 | for (const CallICFGNode *cs : pag->getCallSiteSet()) 53 | { 54 | const FunObjVar *fun = cs->getCalledFunction(); 55 | if (fun->getName() == "source") 56 | { 57 | sources.insert(cs); 58 | } 59 | } 60 | return sources; 61 | } 62 | 63 | // Identify sink nodes on ICFG (i.e., call instruction with its callee function named 'sink') 64 | virtual std::set &identifySinks() 65 | { 66 | for (const CallICFGNode *cs : pag->getCallSiteSet()) 67 | { 68 | const FunObjVar *fun = cs->getCalledFunction(); 69 | if (fun->getName() == "sink") 70 | { 71 | sinks.insert(cs); 72 | } 73 | } 74 | return sinks; 75 | } 76 | std::set& getPaths(){ 77 | return paths; 78 | } 79 | 80 | protected: 81 | std::set sources; 82 | std::set sinks; 83 | Set> visited; 84 | CallStack callstack; 85 | 86 | SVFIR* pag; 87 | std::set paths; 88 | std::vector path; 89 | 90 | }; 91 | 92 | #endif -------------------------------------------------------------------------------- /Assignment-2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES 2 | *.cpp 3 | ) 4 | add_executable(assign-2 ${SOURCES}) 5 | 6 | target_link_libraries(assign-2 ${SVF_LIB} ${llvm_libs}) 7 | 8 | set_target_properties(assign-2 PROPERTIES 9 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) 10 | -------------------------------------------------------------------------------- /Assignment-2/Test2.cpp: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 2-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 2 : Source Sink ICFG DFS Traversal 25 | // 26 | // 27 | */ 28 | 29 | #include 30 | #include "Assignment-2.h" 31 | 32 | void Test1() 33 | { 34 | 35 | std::vector moduleNameVec = {"./Assignment-2/testcase/bc/test1.ll"}; 36 | 37 | LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec); 38 | 39 | /// Build Program Assignment Graph (SVFIR) 40 | SVFIRBuilder builder; 41 | SVFIR *pag = builder.build(); 42 | ICFG *icfg = pag->getICFG(); 43 | // If you want to test your own case, plase change the dump name 44 | icfg->dump("./Assignment-2/testcase/dot/test1.ll.icfg"); 45 | ICFGTraversal *gt = new ICFGTraversal(pag); 46 | for (const CallICFGNode *src : gt->identifySources()) 47 | { 48 | for (const CallICFGNode *snk : gt->identifySinks()) 49 | { 50 | gt->reachability(src, snk); 51 | } 52 | } 53 | std::set expected = {"START->17->1->7->END"}; 54 | assert(expected == gt->getPaths() && "test1 failed!"); 55 | std::cout << "test1 passed!" << "\n"; 56 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 57 | SVF::SVFIR::releaseSVFIR(); 58 | NodeIDAllocator::unset(); 59 | delete gt; 60 | } 61 | 62 | void Test2() 63 | { 64 | // Your current workingspace dir}/Assignment-2/testCase/ 65 | std::vector moduleNameVec = {"./Assignment-2/testcase/bc/test2.ll"}; 66 | 67 | LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec); 68 | 69 | /// Build Program Assignment Graph (SVFIR) 70 | SVFIRBuilder builder; 71 | SVFIR *pag = builder.build(); 72 | ICFG *icfg = pag->getICFG(); 73 | // If you want to test your own case, plase change the dump name 74 | icfg->dump("./Assignment-2/testcase/dot/test2.ll.icfg"); 75 | ICFGTraversal *gt = new ICFGTraversal(pag); 76 | for (const CallICFGNode *src : gt->identifySources()) 77 | { 78 | for (const CallICFGNode *snk : gt->identifySinks()) 79 | { 80 | gt->reachability(src, snk); 81 | } 82 | } 83 | 84 | std::set expected = {"START->6->7->8->9->10->1->5->2->11->14->END", "START->6->7->8->9->12->1->5->2->13->16->END"}; 85 | assert(expected == gt->getPaths() && "test2 failed!"); 86 | std::cout << "test2 passed!" << "\n"; 87 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 88 | SVF::SVFIR::releaseSVFIR(); 89 | NodeIDAllocator::unset(); 90 | delete gt; 91 | } 92 | 93 | void Test3() 94 | { 95 | // Your current workingspace dir}/Assignment-2/testCase/ 96 | std::vector moduleNameVec = {"./Assignment-2/testcase/bc/test3.ll"}; 97 | 98 | LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec); 99 | 100 | /// Build Program Assignment Graph (SVFIR) 101 | SVFIRBuilder builder; 102 | SVFIR *pag = builder.build(); 103 | ICFG *icfg = pag->getICFG(); 104 | // If you want to test your own case, plase change the dump name 105 | icfg->dump("./Assignment-2/testcase/dot/test3.ll.icfg"); 106 | ICFGTraversal *gt = new ICFGTraversal(pag); 107 | for (const CallICFGNode *src : gt->identifySources()) 108 | { 109 | for (const CallICFGNode *snk : gt->identifySinks()) 110 | { 111 | gt->reachability(src, snk); 112 | } 113 | } 114 | 115 | std::set expected = {"START->11->12->13->14->3->8->9->4->15->16->3->8->9->4->17->18->19->END"}; 116 | assert(expected == gt->getPaths() && "test3 failed!"); 117 | std::cout << "test3 passed!" << "\n"; 118 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 119 | SVF::SVFIR::releaseSVFIR(); 120 | NodeIDAllocator::unset(); 121 | delete gt; 122 | } 123 | 124 | void Test() 125 | { 126 | Test1(); 127 | Test2(); 128 | Test3(); 129 | } 130 | 131 | int main() 132 | { 133 | Test(); 134 | return 0; 135 | } 136 | -------------------------------------------------------------------------------- /Assignment-2/testcase/bc/test1.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'test1.ll' 2 | source_filename = "test1.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind uwtable 7 | define dso_local void @source(ptr noundef %s) #0 { 8 | entry: 9 | call void @sink() 10 | ret void 11 | } 12 | 13 | ; Function Attrs: noinline nounwind uwtable 14 | define dso_local void @sink() #0 { 15 | entry: 16 | ret void 17 | } 18 | 19 | ; Function Attrs: noinline nounwind uwtable 20 | define dso_local i32 @main() #0 { 21 | entry: 22 | %a = alloca i32, align 4 23 | store i32 1, ptr %a, align 4 24 | br label %while.cond 25 | 26 | while.cond: ; preds = %while.body, %entry 27 | %0 = load i32, ptr %a, align 4 28 | %cmp = icmp sle i32 %0, 1 29 | br i1 %cmp, label %while.body, label %while.end 30 | 31 | while.body: ; preds = %while.cond 32 | call void @source(ptr noundef %a) 33 | %1 = load i32, ptr %a, align 4 34 | %inc = add nsw i32 %1, 1 35 | store i32 %inc, ptr %a, align 4 36 | br label %while.cond, !llvm.loop !6 37 | 38 | while.end: ; preds = %while.cond 39 | ret i32 0 40 | } 41 | 42 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 43 | 44 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 45 | !llvm.ident = !{!5} 46 | 47 | !0 = !{i32 1, !"wchar_size", i32 4} 48 | !1 = !{i32 8, !"PIC Level", i32 2} 49 | !2 = !{i32 7, !"PIE Level", i32 2} 50 | !3 = !{i32 7, !"uwtable", i32 2} 51 | !4 = !{i32 7, !"frame-pointer", i32 2} 52 | !5 = !{!"clang version 16.0.0"} 53 | !6 = distinct !{!6, !7} 54 | !7 = !{!"llvm.loop.mustprogress"} 55 | -------------------------------------------------------------------------------- /Assignment-2/testcase/bc/test2.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'test2.ll' 2 | source_filename = "test2.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind uwtable 7 | define dso_local i32 @bar(i32 noundef %s) #0 { 8 | entry: 9 | ret i32 %s 10 | } 11 | 12 | ; Function Attrs: noinline nounwind uwtable 13 | define dso_local i32 @main() #0 { 14 | entry: 15 | %call = call i32 (...) @source() 16 | %cmp = icmp sgt i32 %call, 0 17 | br i1 %cmp, label %if.then, label %if.else 18 | 19 | if.then: ; preds = %entry 20 | %call1 = call i32 @bar(i32 noundef %call) 21 | call void @sink(i32 noundef %call1) 22 | br label %if.end 23 | 24 | if.else: ; preds = %entry 25 | %call2 = call i32 @bar(i32 noundef %call) 26 | call void @sink(i32 noundef %call2) 27 | br label %if.end 28 | 29 | if.end: ; preds = %if.else, %if.then 30 | ret i32 0 31 | } 32 | 33 | declare i32 @source(...) #1 34 | 35 | declare void @sink(i32 noundef) #1 36 | 37 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 38 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 39 | 40 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 41 | !llvm.ident = !{!5} 42 | 43 | !0 = !{i32 1, !"wchar_size", i32 4} 44 | !1 = !{i32 8, !"PIC Level", i32 2} 45 | !2 = !{i32 7, !"PIE Level", i32 2} 46 | !3 = !{i32 7, !"uwtable", i32 2} 47 | !4 = !{i32 7, !"frame-pointer", i32 2} 48 | !5 = !{!"clang version 16.0.0"} 49 | -------------------------------------------------------------------------------- /Assignment-2/testcase/bc/test3.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'test3.ll' 2 | source_filename = "Assignment-2/testcase/src/test3.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind uwtable 7 | define dso_local i32 @bar(i32 noundef %s) #0 { 8 | entry: 9 | ret i32 %s 10 | } 11 | 12 | ; Function Attrs: noinline nounwind uwtable 13 | define dso_local void @foo(ptr noundef %p) #0 { 14 | entry: 15 | store i32 1, ptr %p, align 4 16 | ret void 17 | } 18 | 19 | ; Function Attrs: noinline nounwind uwtable 20 | define dso_local i32 @main() #0 { 21 | entry: 22 | %a = alloca i32, align 4 23 | %call = call i32 (...) @source() 24 | store i32 %call, ptr %a, align 4 25 | call void @foo(ptr noundef %a) 26 | call void @foo(ptr noundef %a) 27 | %0 = load i32, ptr %a, align 4 28 | call void @sink(i32 noundef %0) 29 | ret i32 0 30 | } 31 | 32 | declare i32 @source(...) #1 33 | 34 | declare void @sink(i32 noundef) #1 35 | 36 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 37 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 38 | 39 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 40 | !llvm.ident = !{!5} 41 | 42 | !0 = !{i32 1, !"wchar_size", i32 4} 43 | !1 = !{i32 8, !"PIC Level", i32 2} 44 | !2 = !{i32 7, !"PIE Level", i32 2} 45 | !3 = !{i32 7, !"uwtable", i32 2} 46 | !4 = !{i32 7, !"frame-pointer", i32 2} 47 | !5 = !{!"clang version 16.0.4 (https://github.com/llvm/llvm-project ae42196bc493ffe877a7e3dff8be32035dea4d07)"} 48 | -------------------------------------------------------------------------------- /Assignment-2/testcase/dot/test1.ll.icfg.dot: -------------------------------------------------------------------------------- 1 | digraph "ICFG" { 2 | label="ICFG"; 3 | 4 | Node0x557d0caf48b0 [shape=record,color=purple,label="{GlobalICFGNode0\nCopyStmt: [Var1 \<-- Var0] \n ptr null \{ constant data \}\nAddrStmt: [Var32 \<-- Var3] \n i32 0 \{ constant data \}\nAddrStmt: [Var19 \<-- Var3] \n i32 1 \{ constant data \}\nAddrStmt: [Var4 \<-- Var5] \nFunction: source \nAddrStmt: [Var9 \<-- Var10] \nFunction: sink \nAddrStmt: [Var14 \<-- Var15] \nFunction: main }"]; 5 | Node0x557d0caf48b0 -> Node0x557d0cad53d0[style=solid]; 6 | Node0x557d0cae4520 [shape=record,color=yellow,label="{FunEntryICFGNode1 \{fun: source\}}"]; 7 | Node0x557d0cae4520 -> Node0x557d0cae7de0[style=solid]; 8 | Node0x557d0cae7de0 [shape=record,color=red,label="{CallICFGNode2 \{fun: source\}\n call void @sink() |{0x557d0cae7de0}}"]; 9 | Node0x557d0cae7de0:s0 -> Node0x557d0cadab90[style=solid,color=red]; 10 | Node0x557d0cae24c0 [shape=record,color=blue,label="{RetICFGNode3 \{fun: source\}\n call void @sink() }"]; 11 | Node0x557d0cae24c0 -> Node0x557d0cb5be60[style=solid]; 12 | Node0x557d0cadab90 [shape=record,color=yellow,label="{FunEntryICFGNode4 \{fun: sink\}}"]; 13 | Node0x557d0cadab90 -> Node0x557d0cb4d7c0[style=solid]; 14 | Node0x557d0cb5bab0 [shape=record,color=green,label="{FunExitICFGNode5 \{fun: sink\}|{0x557d0cae7de0}}"]; 15 | Node0x557d0cb5bab0:s0 -> Node0x557d0cae24c0[style=solid,color=blue]; 16 | Node0x557d0cb5be60 [shape=record,color=black,label="{IntraICFGNode6 \{fun: source\}\n ret void }"]; 17 | Node0x557d0cb5be60 -> Node0x557d0cb23ea0[style=solid]; 18 | Node0x557d0cb23ea0 [shape=record,color=green,label="{FunExitICFGNode7 \{fun: source\}|{0x557d0cb24d30}}"]; 19 | Node0x557d0cb23ea0:s0 -> Node0x557d0cae80c0[style=solid,color=blue]; 20 | Node0x557d0cb4d7c0 [shape=record,color=black,label="{IntraICFGNode8 \{fun: sink\}\n ret void }"]; 21 | Node0x557d0cb4d7c0 -> Node0x557d0cb5bab0[style=solid]; 22 | Node0x557d0cad53d0 [shape=record,color=yellow,label="{FunEntryICFGNode9 \{fun: main\}}"]; 23 | Node0x557d0cad53d0 -> Node0x557d0cb6d9e0[style=solid]; 24 | Node0x557d0cb6d9e0 [shape=record,color=black,label="{IntraICFGNode10 \{fun: main\}\nAddrStmt: [Var17 \<-- Var18] \n %a = alloca i32, align 4 }"]; 25 | Node0x557d0cb6d9e0 -> Node0x557d0cb6d6d0[style=solid]; 26 | Node0x557d0cb6d6d0 [shape=record,color=black,label="{IntraICFGNode11 \{fun: main\}\nStoreStmt: [Var17 \<-- Var19] \n store i32 1, ptr %a, align 4 }"]; 27 | Node0x557d0cb6d6d0 -> Node0x557d0cb5b2a0[style=solid]; 28 | Node0x557d0cb5b2a0 [shape=record,color=black,label="{IntraICFGNode12 \{fun: main\}\nBranchStmt: [ Unconditional branch]\nSuccessor 0 ICFGNode13 \n br label %while.cond }"]; 29 | Node0x557d0cb5b2a0 -> Node0x557d0cb3d4a0[style=solid]; 30 | Node0x557d0cb3d4a0 [shape=record,color=black,label="{IntraICFGNode13 \{fun: main\}\nLoadStmt: [Var23 \<-- Var17] \n %0 = load i32, ptr %a, align 4 }"]; 31 | Node0x557d0cb3d4a0 -> Node0x557d0caff780[style=solid]; 32 | Node0x557d0caff780 [shape=record,color=black,label="{IntraICFGNode14 \{fun: main\}\nCmpStmt: [Var24 \<-- (Var23 predicate41 Var19)] \n %cmp = icmp sle i32 %0, 1 }"]; 33 | Node0x557d0caff780 -> Node0x557d0cafa290[style=solid]; 34 | Node0x557d0cafa290 [shape=record,color=black,label="{IntraICFGNode15 \{fun: main\}\nBranchStmt: [Condition Var24]\nSuccessor 0 ICFGNode16 Successor 1 ICFGNode18 \n br i1 %cmp, label %while.body, label %while.end }"]; 35 | Node0x557d0cafa290 -> Node0x557d0cb24d30[style=solid]; 36 | Node0x557d0cafa290 -> Node0x557d0cb44070[style=solid]; 37 | Node0x557d0cb24d30 [shape=record,color=red,label="{CallICFGNode16 \{fun: main\}\nCallPE: [Var7 \<-- Var17] \n call void @source(ptr noundef %a) |{0x557d0cb24d30}}"]; 38 | Node0x557d0cb24d30:s0 -> Node0x557d0cae4520[style=solid,color=red]; 39 | Node0x557d0cae80c0 [shape=record,color=blue,label="{RetICFGNode17 \{fun: main\}\n call void @source(ptr noundef %a) }"]; 40 | Node0x557d0cae80c0 -> Node0x557d0cb69c80[style=solid]; 41 | Node0x557d0cb44070 [shape=record,color=black,label="{IntraICFGNode18 \{fun: main\}\n ret i32 0 }"]; 42 | Node0x557d0cb44070 -> Node0x557d0cb013e0[style=solid]; 43 | Node0x557d0cb69c80 [shape=record,color=black,label="{IntraICFGNode19 \{fun: main\}\nLoadStmt: [Var27 \<-- Var17] \n %1 = load i32, ptr %a, align 4 }"]; 44 | Node0x557d0cb69c80 -> Node0x557d0cb24bb0[style=solid]; 45 | Node0x557d0cb013e0 [shape=record,color=green,label="{FunExitICFGNode20 \{fun: main\}\nPhiStmt: [Var16 \<-- ([Var32, ICFGNode18],)] \n ret i32 0 }"]; 46 | Node0x557d0cb24bb0 [shape=record,color=black,label="{IntraICFGNode21 \{fun: main\}\nBinaryOPStmt: [Var28 \<-- (Var27 opcode13 Var19)] \n %inc = add nsw i32 %1, 1 }"]; 47 | Node0x557d0cb24bb0 -> Node0x557d0cb711f0[style=solid]; 48 | Node0x557d0cb711f0 [shape=record,color=black,label="{IntraICFGNode22 \{fun: main\}\nStoreStmt: [Var17 \<-- Var28] \n store i32 %inc, ptr %a, align 4 }"]; 49 | Node0x557d0cb711f0 -> Node0x557d0cb6d390[style=solid]; 50 | Node0x557d0cb6d390 [shape=record,color=black,label="{IntraICFGNode23 \{fun: main\}\nBranchStmt: [ Unconditional branch]\nSuccessor 0 ICFGNode13 \n br label %while.cond, !llvm.loop !6 }"]; 51 | Node0x557d0cb6d390 -> Node0x557d0cb3d4a0[style=solid]; 52 | } 53 | -------------------------------------------------------------------------------- /Assignment-2/testcase/dot/test2.ll.icfg.dot: -------------------------------------------------------------------------------- 1 | digraph "ICFG" { 2 | label="ICFG"; 3 | 4 | Node0x557d0cb41a00 [shape=record,color=purple,label="{GlobalICFGNode0\nCopyStmt: [Var1 \<-- Var0] \n ptr null \{ constant data \}\nAddrStmt: [Var16 \<-- Var3] \n i32 0 \{ constant data \}\nAddrStmt: [Var4 \<-- Var5] \nFunction: bar \nAddrStmt: [Var9 \<-- Var10] \nFunction: main \nAddrStmt: [Var13 \<-- Var14] \nFunction: source \nAddrStmt: [Var20 \<-- Var21] \nFunction: sink }"]; 5 | Node0x557d0cb41a00 -> Node0x557d0cae4520[style=solid]; 6 | Node0x557d0cae24c0 [shape=record,color=yellow,label="{FunEntryICFGNode1 \{fun: bar\}}"]; 7 | Node0x557d0cae24c0 -> Node0x557d0caf5e30[style=solid]; 8 | Node0x557d0caf5e30 [shape=record,color=black,label="{IntraICFGNode2 \{fun: bar\}\n ret i32 %s }"]; 9 | Node0x557d0caf5e30 -> Node0x557d0cb01730[style=solid]; 10 | Node0x557d0cb01730 [shape=record,color=green,label="{FunExitICFGNode3 \{fun: bar\}\nPhiStmt: [Var6 \<-- ([Var7, ICFGNode2],)] \n ret i32 %s |{0x557d0cb2da50|0x557d0cb24d30}}"]; 11 | Node0x557d0cb01730:s0 -> Node0x557d0cb37ef0[style=solid,color=blue]; 12 | Node0x557d0cb01730:s1 -> Node0x557d0caea7d0[style=solid,color=blue]; 13 | Node0x557d0cae4520 [shape=record,color=yellow,label="{FunEntryICFGNode4 \{fun: main\}}"]; 14 | Node0x557d0cae4520 -> Node0x557d0cafa1a0[style=solid]; 15 | Node0x557d0cafa1a0 [shape=record,color=red,label="{CallICFGNode5 \{fun: main\}\n %call = call i32 (...) @source() }"]; 16 | Node0x557d0cafa1a0 -> Node0x557d0cb03760[style=solid]; 17 | Node0x557d0cb03760 [shape=record,color=blue,label="{RetICFGNode6 \{fun: main\}\n %call = call i32 (...) @source() }"]; 18 | Node0x557d0cb03760 -> Node0x557d0caeb050[style=solid]; 19 | Node0x557d0caeb050 [shape=record,color=black,label="{IntraICFGNode7 \{fun: main\}\nCmpStmt: [Var15 \<-- (Var12 predicate38 Var16)] \n %cmp = icmp sgt i32 %call, 0 }"]; 20 | Node0x557d0caeb050 -> Node0x557d0caeac00[style=solid]; 21 | Node0x557d0caeac00 [shape=record,color=black,label="{IntraICFGNode8 \{fun: main\}\nBranchStmt: [Condition Var15]\nSuccessor 0 ICFGNode9 Successor 1 ICFGNode11 \n br i1 %cmp, label %if.then, label %if.else }"]; 22 | Node0x557d0caeac00 -> Node0x557d0cb2da50[style=solid]; 23 | Node0x557d0caeac00 -> Node0x557d0cb24d30[style=solid]; 24 | Node0x557d0cb2da50 [shape=record,color=red,label="{CallICFGNode9 \{fun: main\}\nCallPE: [Var7 \<-- Var12] \n %call1 = call i32 @bar(i32 noundef %call) |{0x557d0cb2da50}}"]; 25 | Node0x557d0cb2da50:s0 -> Node0x557d0cae24c0[style=solid,color=red]; 26 | Node0x557d0cb37ef0 [shape=record,color=blue,label="{RetICFGNode10 \{fun: main\}\nRetPE: [Var18 \<-- Var6] \n %call1 = call i32 @bar(i32 noundef %call) }"]; 27 | Node0x557d0cb37ef0 -> Node0x557d0cae7de0[style=solid]; 28 | Node0x557d0cb24d30 [shape=record,color=red,label="{CallICFGNode11 \{fun: main\}\nCallPE: [Var7 \<-- Var12] \n %call2 = call i32 @bar(i32 noundef %call) |{0x557d0cb24d30}}"]; 29 | Node0x557d0cb24d30:s0 -> Node0x557d0cae24c0[style=solid,color=red]; 30 | Node0x557d0caea7d0 [shape=record,color=blue,label="{RetICFGNode12 \{fun: main\}\nRetPE: [Var24 \<-- Var6] \n %call2 = call i32 @bar(i32 noundef %call) }"]; 31 | Node0x557d0caea7d0 -> Node0x557d0cb46ea0[style=solid]; 32 | Node0x557d0cae7de0 [shape=record,color=red,label="{CallICFGNode13 \{fun: main\}\n call void @sink(i32 noundef %call1) }"]; 33 | Node0x557d0cae7de0 -> Node0x557d0cae9ae0[style=solid]; 34 | Node0x557d0cae9ae0 [shape=record,color=blue,label="{RetICFGNode14 \{fun: main\}\n call void @sink(i32 noundef %call1) }"]; 35 | Node0x557d0cae9ae0 -> Node0x557d0cb5be60[style=solid]; 36 | Node0x557d0cb46ea0 [shape=record,color=red,label="{CallICFGNode15 \{fun: main\}\n call void @sink(i32 noundef %call2) }"]; 37 | Node0x557d0cb46ea0 -> Node0x557d0cb50e60[style=solid]; 38 | Node0x557d0cb50e60 [shape=record,color=blue,label="{RetICFGNode16 \{fun: main\}\n call void @sink(i32 noundef %call2) }"]; 39 | Node0x557d0cb50e60 -> Node0x557d0cb5bab0[style=solid]; 40 | Node0x557d0cb5be60 [shape=record,color=black,label="{IntraICFGNode17 \{fun: main\}\nBranchStmt: [ Unconditional branch]\nSuccessor 0 ICFGNode19 \n br label %if.end }"]; 41 | Node0x557d0cb5be60 -> Node0x557d0cb0d230[style=solid]; 42 | Node0x557d0cb5bab0 [shape=record,color=black,label="{IntraICFGNode18 \{fun: main\}\nBranchStmt: [ Unconditional branch]\nSuccessor 0 ICFGNode19 \n br label %if.end }"]; 43 | Node0x557d0cb5bab0 -> Node0x557d0cb0d230[style=solid]; 44 | Node0x557d0cb0d230 [shape=record,color=black,label="{IntraICFGNode19 \{fun: main\}\n ret i32 0 }"]; 45 | Node0x557d0cb0d230 -> Node0x557d0cb3ac20[style=solid]; 46 | Node0x557d0cb3ac20 [shape=record,color=green,label="{FunExitICFGNode20 \{fun: main\}\nPhiStmt: [Var11 \<-- ([Var16, ICFGNode19],)] \n ret i32 0 }"]; 47 | } 48 | -------------------------------------------------------------------------------- /Assignment-2/testcase/dot/test3.ll.icfg.dot: -------------------------------------------------------------------------------- 1 | digraph "ICFG" { 2 | label="ICFG"; 3 | 4 | Node0x557d0cae6390 [shape=record,color=purple,label="{GlobalICFGNode0\nCopyStmt: [Var1 \<-- Var0] \n ptr null \{ constant data \}\nAddrStmt: [Var14 \<-- Var3] \n i32 1 \{ constant data \}\nAddrStmt: [Var32 \<-- Var3] \n i32 0 \{ constant data \}\nAddrStmt: [Var4 \<-- Var5] \nFunction: bar \nAddrStmt: [Var9 \<-- Var10] \nFunction: foo \nAddrStmt: [Var16 \<-- Var17] \nFunction: main \nAddrStmt: [Var22 \<-- Var23] \nFunction: source \nAddrStmt: [Var29 \<-- Var30] \nFunction: sink }"]; 5 | Node0x557d0cae6390 -> Node0x557d0cb5bb80[style=solid]; 6 | Node0x557d0cb51550 [shape=record,color=yellow,label="{FunEntryICFGNode1 \{fun: bar\}}"]; 7 | Node0x557d0cb51550 -> Node0x557d0caeab30[style=solid]; 8 | Node0x557d0caeab30 [shape=record,color=black,label="{IntraICFGNode2 \{fun: bar\}\n ret i32 %s }"]; 9 | Node0x557d0caeab30 -> Node0x557d0cb5be60[style=solid]; 10 | Node0x557d0cb5be60 [shape=record,color=green,label="{FunExitICFGNode3 \{fun: bar\}\nPhiStmt: [Var6 \<-- ([Var7, ICFGNode2],)] \n ret i32 %s }"]; 11 | Node0x557d0cb35aa0 [shape=record,color=yellow,label="{FunEntryICFGNode4 \{fun: foo\}}"]; 12 | Node0x557d0cb35aa0 -> Node0x557d0cb5bab0[style=solid]; 13 | Node0x557d0cb5bab0 [shape=record,color=black,label="{IntraICFGNode5 \{fun: foo\}\nStoreStmt: [Var12 \<-- Var14] \n store i32 1, ptr %p, align 4 }"]; 14 | Node0x557d0cb5bab0 -> Node0x557d0cb3e150[style=solid]; 15 | Node0x557d0cb3e150 [shape=record,color=black,label="{IntraICFGNode6 \{fun: foo\}\n ret void }"]; 16 | Node0x557d0cb3e150 -> Node0x557d0cb01730[style=solid]; 17 | Node0x557d0cb01730 [shape=record,color=green,label="{FunExitICFGNode7 \{fun: foo\}|{0x557d0cb2da50|0x557d0cb58370}}"]; 18 | Node0x557d0cb01730:s0 -> Node0x557d0cafa370[style=solid,color=blue]; 19 | Node0x557d0cb01730:s1 -> Node0x557d0cb723b0[style=solid,color=blue]; 20 | Node0x557d0cb5bb80 [shape=record,color=yellow,label="{FunEntryICFGNode8 \{fun: main\}}"]; 21 | Node0x557d0cb5bb80 -> Node0x557d0caf5e30[style=solid]; 22 | Node0x557d0caf5e30 [shape=record,color=black,label="{IntraICFGNode9 \{fun: main\}\nAddrStmt: [Var19 \<-- Var20] \n %a = alloca i32, align 4 }"]; 23 | Node0x557d0caf5e30 -> Node0x557d0cb24d30[style=solid]; 24 | Node0x557d0cb24d30 [shape=record,color=red,label="{CallICFGNode10 \{fun: main\}\n %call = call i32 (...) @source() }"]; 25 | Node0x557d0cb24d30 -> Node0x557d0cb26480[style=solid]; 26 | Node0x557d0cb26480 [shape=record,color=blue,label="{RetICFGNode11 \{fun: main\}\n %call = call i32 (...) @source() }"]; 27 | Node0x557d0cb26480 -> Node0x557d0cb496b0[style=solid]; 28 | Node0x557d0cb496b0 [shape=record,color=black,label="{IntraICFGNode12 \{fun: main\}\nStoreStmt: [Var19 \<-- Var21] \n store i32 %call, ptr %a, align 4 }"]; 29 | Node0x557d0cb496b0 -> Node0x557d0cb2da50[style=solid]; 30 | Node0x557d0cb2da50 [shape=record,color=red,label="{CallICFGNode13 \{fun: main\}\nCallPE: [Var12 \<-- Var19] \n call void @foo(ptr noundef %a) |{0x557d0cb2da50}}"]; 31 | Node0x557d0cb2da50:s0 -> Node0x557d0cb35aa0[style=solid,color=red]; 32 | Node0x557d0cafa370 [shape=record,color=blue,label="{RetICFGNode14 \{fun: main\}\n call void @foo(ptr noundef %a) }"]; 33 | Node0x557d0cafa370 -> Node0x557d0cb58370[style=solid]; 34 | Node0x557d0cb58370 [shape=record,color=red,label="{CallICFGNode15 \{fun: main\}\nCallPE: [Var12 \<-- Var19] \n call void @foo(ptr noundef %a) |{0x557d0cb58370}}"]; 35 | Node0x557d0cb58370:s0 -> Node0x557d0cb35aa0[style=solid,color=red]; 36 | Node0x557d0cb723b0 [shape=record,color=blue,label="{RetICFGNode16 \{fun: main\}\n call void @foo(ptr noundef %a) }"]; 37 | Node0x557d0cb723b0 -> Node0x557d0cb54ae0[style=solid]; 38 | Node0x557d0cb54ae0 [shape=record,color=black,label="{IntraICFGNode17 \{fun: main\}\nLoadStmt: [Var27 \<-- Var19] \n %0 = load i32, ptr %a, align 4 }"]; 39 | Node0x557d0cb54ae0 -> Node0x557d0caec5d0[style=solid]; 40 | Node0x557d0caec5d0 [shape=record,color=red,label="{CallICFGNode18 \{fun: main\}\n call void @sink(i32 noundef %0) }"]; 41 | Node0x557d0caec5d0 -> Node0x557d0caf6920[style=solid]; 42 | Node0x557d0caf6920 [shape=record,color=blue,label="{RetICFGNode19 \{fun: main\}\n call void @sink(i32 noundef %0) }"]; 43 | Node0x557d0caf6920 -> Node0x557d0cb73ac0[style=solid]; 44 | Node0x557d0cb73ac0 [shape=record,color=black,label="{IntraICFGNode20 \{fun: main\}\n ret i32 0 }"]; 45 | Node0x557d0cb73ac0 -> Node0x557d0cb51320[style=solid]; 46 | Node0x557d0cb51320 [shape=record,color=green,label="{FunExitICFGNode21 \{fun: main\}\nPhiStmt: [Var18 \<-- ([Var32, ICFGNode20],)] \n ret i32 0 }"]; 47 | } 48 | -------------------------------------------------------------------------------- /Assignment-2/testcase/src/test1.c: -------------------------------------------------------------------------------- 1 | #include 2 | void sink(); 3 | void source(int *s){ 4 | sink(); 5 | }; 6 | void sink(){ 7 | }; 8 | 9 | int main(){ 10 | int a = 1; 11 | while ( a <=1){ 12 | source(&a); 13 | a++; 14 | } 15 | return 0; 16 | }; -------------------------------------------------------------------------------- /Assignment-2/testcase/src/test2.c: -------------------------------------------------------------------------------- 1 | extern int source(); 2 | extern void sink(int s); 3 | int bar(int s){ 4 | return s; 5 | } 6 | int main(){ 7 | int a = source(); 8 | if (a > 0){ 9 | int p = bar(a); 10 | sink(p); 11 | }else{ 12 | int q = bar(a); 13 | sink(q); 14 | } 15 | } -------------------------------------------------------------------------------- /Assignment-2/testcase/src/test3.c: -------------------------------------------------------------------------------- 1 | #include 2 | extern int source(); 3 | extern void sink(int s); 4 | int bar(int s){ 5 | return s; 6 | } 7 | void foo(int* p) { 8 | *p = 1; 9 | } 10 | 11 | int main() { 12 | int a = source(); 13 | foo(&a); 14 | foo(&a); 15 | sink(a); 16 | } -------------------------------------------------------------------------------- /Assignment-3/Assignment-3.cpp: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 3-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 3 : Andersen's pointer analysis 25 | // 26 | // 27 | */ 28 | 29 | #include "SVF-LLVM/LLVMUtil.h" 30 | #include "SVF-LLVM/SVFIRBuilder.h" 31 | #include "WPA/Andersen.h" 32 | #include "Assignment-3.h" 33 | using namespace SVF; 34 | using namespace llvm; 35 | using namespace std; 36 | 37 | 38 | // TODO: Implement your Andersen's Algorithm here 39 | void AndersenPTA::solveWorklist(){ 40 | processAllAddr(); 41 | 42 | // Keep solving until workList is empty. 43 | while (!isWorklistEmpty()) { 44 | 45 | } 46 | 47 | } 48 | 49 | // Process all address constraints to initialize pointers' points-to sets 50 | void AndersenPTA::processAllAddr(){ 51 | for (ConstraintGraph::const_iterator nodeIt = consCG->begin(), nodeEit = consCG->end(); nodeIt != nodeEit; nodeIt++) 52 | { 53 | ConstraintNode *cgNode = nodeIt->second; 54 | for (ConstraintEdge* edge : cgNode->getAddrInEdges()) { 55 | const AddrCGEdge *addr = SVFUtil::cast(edge); 56 | NodeID dst = addr->getDstID(); 57 | NodeID src = addr->getSrcID(); 58 | if (addPts(dst, src)) 59 | pushIntoWorklist(dst); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Assignment-3/Assignment-3.h: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 3-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 3 : Andersen's pointer analysis 25 | // 26 | // 27 | */ 28 | #ifndef ASSIGNMENT_3_H_ 29 | #define ASSIGNMENT_3_H_ 30 | #include "SVF-LLVM/LLVMUtil.h" 31 | #include "WPA/Andersen.h" 32 | 33 | class AndersenPTA: public SVF::AndersenBase 34 | { 35 | public: 36 | // Constructor 37 | AndersenPTA(SVF::SVFIR* _pag) : AndersenBase(_pag){}; 38 | 39 | //dump constraint graph 40 | void dump_consCG(std::string name) 41 | { 42 | consCG->dump(name); 43 | }; 44 | 45 | private: 46 | 47 | // Process all the address constraint edges 48 | void processAllAddr(); 49 | 50 | // To be implemented 51 | virtual void solveWorklist() override; 52 | 53 | /// Add copy edge on constraint graph 54 | virtual bool addCopyEdge(SVF::NodeID src, SVF::NodeID dst) override 55 | { 56 | if (consCG->addCopyCGEdge(src, dst)) 57 | return true; 58 | else 59 | return false; 60 | } 61 | 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Assignment-3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES 2 | *.cpp 3 | ) 4 | add_executable(assign-3 ${SOURCES}) 5 | 6 | target_link_libraries(assign-3 ${SVF_LIB} ${llvm_libs}) 7 | 8 | set_target_properties( assign-3 PROPERTIES 9 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) 10 | -------------------------------------------------------------------------------- /Assignment-3/Test3.cpp: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 3-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 3 : Andersen's pointer analysis 25 | // 26 | // 27 | */ 28 | 29 | #include "Assignment-3.h" 30 | 31 | #include "SVF-LLVM/LLVMUtil.h" 32 | #include "SVF-LLVM/SVFIRBuilder.h" 33 | #include "WPA/Andersen.h" 34 | #include "Util/Options.h" 35 | #include "Util/CommandLine.h" 36 | 37 | 38 | void Test1() 39 | { 40 | 41 | SVF::LLVMModuleSet::getLLVMModuleSet()->buildSVFModule({"./Assignment-3/testcase/bc/no_alias.ll"}); 42 | /// Build Program Assignment Graph (SVFIR) 43 | SVF::SVFIRBuilder builder; 44 | SVF::SVFIR *pag = builder.build(); 45 | pag->dump ("./Assignment-3/testcase/dot/no_alias_init"); 46 | AndersenPTA *andersenPTA = new AndersenPTA(pag); 47 | andersenPTA->analyze(); 48 | andersenPTA->dump_consCG("./Assignment-3/testcase/dot/no_alias_final"); 49 | delete andersenPTA; 50 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 51 | SVF::SVFIR::releaseSVFIR(); 52 | SVF::NodeIDAllocator::unset(); 53 | } 54 | 55 | void Test2() 56 | { 57 | 58 | SVF::LLVMModuleSet::getLLVMModuleSet()->buildSVFModule({"./Assignment-3/testcase/bc/CI-global.ll"}); 59 | /// Build Program Assignment Graph (SVFIR) 60 | SVF::SVFIRBuilder builder; 61 | SVF::SVFIR *pag = builder.build(); 62 | pag->dump ("./Assignment-3/testcase/dot/CI-global_init"); 63 | AndersenPTA *andersenPTA = new AndersenPTA(pag); 64 | andersenPTA->analyze(); 65 | andersenPTA->dump_consCG("./Assignment-3/testcase/dot/CI-global_final"); 66 | delete andersenPTA; 67 | SVF::SVFIR::releaseSVFIR(); 68 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 69 | SVF::NodeIDAllocator::unset(); 70 | } 71 | 72 | void Test3() 73 | { 74 | SVF::LLVMModuleSet::getLLVMModuleSet()->buildSVFModule({"./Assignment-3/testcase/bc/CI-local.ll"}); 75 | /// Build Program Assignment Graph (SVFIR) 76 | SVF::SVFIRBuilder builder; 77 | SVF::SVFIR *pag = builder.build(); 78 | pag->dump ("./Assignment-3/testcase/dot/CI-local_init"); 79 | AndersenPTA *andersenPTA = new AndersenPTA(pag); 80 | andersenPTA->analyze(); 81 | andersenPTA->dump_consCG("./Assignment-3/testcase/dot/CI-local_final"); 82 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 83 | SVF::SVFIR::releaseSVFIR(); 84 | delete andersenPTA; 85 | SVF::NodeIDAllocator::unset(); 86 | } 87 | void Test() 88 | { 89 | Test1(); 90 | Test2(); 91 | Test3(); 92 | } 93 | 94 | 95 | int main(int argc, char ** argv) 96 | { 97 | 98 | int arg_num = 0; 99 | int extraArgc = 1; 100 | char **arg_value = new char *[argc + extraArgc]; 101 | for (; arg_num < argc; ++arg_num) { 102 | arg_value[arg_num] = argv[arg_num]; 103 | } 104 | 105 | // You may comment it to see the details of the analysis 106 | arg_value[arg_num++] = (char*) "-stat=false"; 107 | 108 | std::vector moduleNameVec; 109 | moduleNameVec = OptionBase::parseOptions( 110 | arg_num, arg_value, "Teaching-Software-Analysis Assignment 3", "[options]" 111 | ); 112 | Test(); 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /Assignment-3/testcase/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SVF-tools/Teaching-Software-Analysis/41226d0a09aa64947e735fadea56492d8296436a/Assignment-3/testcase/.DS_Store -------------------------------------------------------------------------------- /Assignment-3/testcase/bc/CI-global.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'CI-global.ll' 2 | source_filename = "CI-global.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | @global = dso_local global i32 0, align 4 7 | @p_global = dso_local global ptr null, align 8 8 | 9 | ; Function Attrs: noinline nounwind uwtable 10 | define dso_local void @foo() #0 { 11 | entry: 12 | store ptr @global, ptr @p_global, align 8 13 | ret void 14 | } 15 | 16 | ; Function Attrs: noinline nounwind uwtable 17 | define dso_local i32 @main() #0 { 18 | entry: 19 | call void @foo() 20 | %0 = load ptr, ptr @p_global, align 8 21 | call void @MAYALIAS(ptr noundef @global, ptr noundef %0) 22 | ret i32 0 23 | } 24 | 25 | declare void @MAYALIAS(ptr noundef, ptr noundef) #1 26 | 27 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 28 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 29 | 30 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 31 | !llvm.ident = !{!5} 32 | 33 | !0 = !{i32 1, !"wchar_size", i32 4} 34 | !1 = !{i32 8, !"PIC Level", i32 2} 35 | !2 = !{i32 7, !"PIE Level", i32 2} 36 | !3 = !{i32 7, !"uwtable", i32 2} 37 | !4 = !{i32 7, !"frame-pointer", i32 2} 38 | !5 = !{!"clang version 16.0.0"} 39 | -------------------------------------------------------------------------------- /Assignment-3/testcase/bc/CI-local.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'CI-local.ll' 2 | source_filename = "CI-local.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind uwtable 7 | define dso_local void @foo(ptr noundef %m, ptr noundef %n) #0 { 8 | entry: 9 | call void @MAYALIAS(ptr noundef %m, ptr noundef %n) 10 | ret void 11 | } 12 | 13 | declare void @MAYALIAS(ptr noundef, ptr noundef) #1 14 | 15 | ; Function Attrs: noinline nounwind uwtable 16 | define dso_local i32 @main() #0 { 17 | entry: 18 | %a = alloca i32, align 4 19 | %b = alloca i32, align 4 20 | %0 = load i32, ptr %a, align 4 21 | %tobool = icmp ne i32 %0, 0 22 | br i1 %tobool, label %if.then, label %if.else 23 | 24 | if.then: ; preds = %entry 25 | call void @foo(ptr noundef %a, ptr noundef %b) 26 | br label %if.end 27 | 28 | if.else: ; preds = %entry 29 | call void @foo(ptr noundef %b, ptr noundef %a) 30 | br label %if.end 31 | 32 | if.end: ; preds = %if.else, %if.then 33 | ret i32 0 34 | } 35 | 36 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 37 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 38 | 39 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 40 | !llvm.ident = !{!5} 41 | 42 | !0 = !{i32 1, !"wchar_size", i32 4} 43 | !1 = !{i32 8, !"PIC Level", i32 2} 44 | !2 = !{i32 7, !"PIE Level", i32 2} 45 | !3 = !{i32 7, !"uwtable", i32 2} 46 | !4 = !{i32 7, !"frame-pointer", i32 2} 47 | !5 = !{!"clang version 16.0.0"} 48 | -------------------------------------------------------------------------------- /Assignment-3/testcase/bc/no_alias.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'no_alias.ll' 2 | source_filename = "no_alias.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | @global_obj_f = dso_local global i32 0, align 4 7 | @global_ptr_f = dso_local global ptr @global_obj_f, align 8 8 | 9 | ; Function Attrs: noinline nounwind uwtable 10 | define dso_local i32 @main() #0 { 11 | entry: 12 | %a = alloca i32, align 4 13 | store i32 5, ptr %a, align 4 14 | %0 = load ptr, ptr @global_ptr_f, align 8 15 | call void @NOALIAS(ptr noundef %0, ptr noundef %a) 16 | ret i32 0 17 | } 18 | 19 | declare void @NOALIAS(ptr noundef, ptr noundef) #1 20 | 21 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 22 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 23 | 24 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 25 | !llvm.ident = !{!5} 26 | 27 | !0 = !{i32 1, !"wchar_size", i32 4} 28 | !1 = !{i32 8, !"PIC Level", i32 2} 29 | !2 = !{i32 7, !"PIE Level", i32 2} 30 | !3 = !{i32 7, !"uwtable", i32 2} 31 | !4 = !{i32 7, !"frame-pointer", i32 2} 32 | !5 = !{!"clang version 16.0.0"} 33 | -------------------------------------------------------------------------------- /Assignment-3/testcase/dot/CI-global_final.dot: -------------------------------------------------------------------------------- 1 | digraph "ConstraintG" { 2 | label="ConstraintG"; 3 | 4 | Node0x1d2afb0 [shape=record,shape=box,label="{0:}"]; 5 | Node0x1d2afb0 -> Node0x1cf7680[color=black]; 6 | Node0x1d2afb0 -> Node0x1cd7b40[color=black]; 7 | Node0x1d2afb0 -> Node0x1d17890[color=blue]; 8 | Node0x1cf7680 [shape=record,shape=diamond,label="{1:dummyVal}"]; 9 | Node0x1ce0580 [shape=record,shape=box,label="{4:global}"]; 10 | Node0x1ce0580 -> Node0x1cd7b40[color=black]; 11 | Node0x1ce0580 -> Node0x1d17890[color=blue]; 12 | Node0x1d5b290 [shape=record,shape=box3d,label="{6}"]; 13 | Node0x1d5b290 -> Node0x1ce0580[color=green]; 14 | Node0x1d17890 [shape=record,shape=box,label="{7:p_global}"]; 15 | Node0x1d17890 -> Node0x1ce77f0[color=red]; 16 | Node0x1cd7b40 [shape=record,shape=box3d,label="{8}"]; 17 | Node0x1cd7b40 -> Node0x1d17890[color=green]; 18 | Node0x1cd7b40 -> Node0x1ce77f0[color=black]; 19 | Node0x1d1bd00 [shape=record,shape=box,label="{9:foo}"]; 20 | Node0x1cffd70 [shape=record,shape=box3d,label="{10}"]; 21 | Node0x1cffd70 -> Node0x1d1bd00[color=green]; 22 | Node0x1d4c6e0 [shape=record,shape=box,label="{14:main}"]; 23 | Node0x1d37150 [shape=record,shape=box3d,label="{15}"]; 24 | Node0x1d37150 -> Node0x1d4c6e0[color=green]; 25 | Node0x1ce77f0 [shape=record,shape=box,label="{18:}"]; 26 | Node0x1d304c0 [shape=record,shape=box,label="{20:MAYALIAS}"]; 27 | Node0x1d4a9c0 [shape=record,shape=box3d,label="{21}"]; 28 | Node0x1d4a9c0 -> Node0x1d304c0[color=green]; 29 | } 30 | -------------------------------------------------------------------------------- /Assignment-3/testcase/dot/CI-local_final.dot: -------------------------------------------------------------------------------- 1 | digraph "ConstraintG" { 2 | label="ConstraintG"; 3 | 4 | Node0x1d004d0 [shape=record,shape=box,label="{0:}"]; 5 | Node0x1d004d0 -> Node0x1cdaeb0[color=black]; 6 | Node0x1cdaeb0 [shape=record,shape=diamond,label="{1:dummyVal}"]; 7 | Node0x1d48cf0 [shape=record,shape=box,label="{4:foo}"]; 8 | Node0x1d036a0 [shape=record,shape=box3d,label="{5}"]; 9 | Node0x1d036a0 -> Node0x1d48cf0[color=green]; 10 | Node0x1d5d8f0 [shape=record,shape=box,label="{7:m}"]; 11 | Node0x1d03c70 [shape=record,shape=box,label="{8:n}"]; 12 | Node0x1ce7860 [shape=record,shape=box,label="{10:MAYALIAS}"]; 13 | Node0x1cf7e70 [shape=record,shape=box3d,label="{11}"]; 14 | Node0x1cf7e70 -> Node0x1ce7860[color=green]; 15 | Node0x1d12f20 [shape=record,shape=box,label="{16:main}"]; 16 | Node0x1d09f40 [shape=record,shape=box3d,label="{17}"]; 17 | Node0x1d09f40 -> Node0x1d12f20[color=green]; 18 | Node0x1d115d0 [shape=record,shape=box,label="{19:}"]; 19 | Node0x1d115d0 -> Node0x1d5d8f0[color=black]; 20 | Node0x1d115d0 -> Node0x1d03c70[color=black]; 21 | Node0x1d35e80 [shape=record,shape=box3d,label="{20}"]; 22 | Node0x1d35e80 -> Node0x1d115d0[color=green]; 23 | Node0x1d52750 [shape=record,shape=box,label="{22:}"]; 24 | Node0x1d52750 -> Node0x1d5d8f0[color=black]; 25 | Node0x1d52750 -> Node0x1d03c70[color=black]; 26 | Node0x1d5f860 [shape=record,shape=box3d,label="{23}"]; 27 | Node0x1d5f860 -> Node0x1d52750[color=green]; 28 | } 29 | -------------------------------------------------------------------------------- /Assignment-3/testcase/dot/no_alias_final.dot: -------------------------------------------------------------------------------- 1 | digraph "ConstraintG" { 2 | label="ConstraintG"; 3 | 4 | Node0x1d08ed0 [shape=record,shape=box,label="{0:}"]; 5 | Node0x1d08ed0 -> Node0x1d29660[color=black]; 6 | Node0x1d29660 [shape=record,shape=diamond,label="{1:dummyVal}"]; 7 | Node0x1ce4210 [shape=record,shape=box,label="{4:global_obj_f}"]; 8 | Node0x1ce4210 -> Node0x1d5a900[color=black]; 9 | Node0x1ce4210 -> Node0x1d57430[color=blue]; 10 | Node0x1d48fe0 [shape=record,shape=box3d,label="{6}"]; 11 | Node0x1d48fe0 -> Node0x1ce4210[color=green]; 12 | Node0x1d57430 [shape=record,shape=box,label="{7:global_ptr_f}"]; 13 | Node0x1d57430 -> Node0x1cdd9a0[color=red]; 14 | Node0x1d5a900 [shape=record,shape=box3d,label="{8}"]; 15 | Node0x1d5a900 -> Node0x1d57430[color=green]; 16 | Node0x1d5a900 -> Node0x1cdd9a0[color=black]; 17 | Node0x1d227b0 [shape=record,shape=box,label="{9:main}"]; 18 | Node0x1d2c620 [shape=record,shape=box3d,label="{10}"]; 19 | Node0x1d2c620 -> Node0x1d227b0[color=green]; 20 | Node0x1d44ae0 [shape=record,shape=box,label="{12:}"]; 21 | Node0x1ceccf0 [shape=record,shape=box3d,label="{13}"]; 22 | Node0x1ceccf0 -> Node0x1d44ae0[color=green]; 23 | Node0x1cdd9a0 [shape=record,shape=box,label="{17:}"]; 24 | Node0x1d0c6e0 [shape=record,shape=box,label="{19:NOALIAS}"]; 25 | Node0x1d2fdf0 [shape=record,shape=box3d,label="{20}"]; 26 | Node0x1d2fdf0 -> Node0x1d0c6e0[color=green]; 27 | } 28 | -------------------------------------------------------------------------------- /Assignment-3/testcase/src/CI-global.c: -------------------------------------------------------------------------------- 1 | extern void MAYALIAS(void* p, void* q); 2 | 3 | int global; 4 | int *p_global; 5 | 6 | void foo() { 7 | p_global = &global; 8 | } 9 | 10 | int main() { 11 | int *p_local; 12 | p_local = &global; 13 | foo(); 14 | MAYALIAS(p_local, p_global); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Assignment-3/testcase/src/CI-local.c: -------------------------------------------------------------------------------- 1 | extern void MAYALIAS(void* p, void* q); 2 | 3 | 4 | void foo(int *m, int *n) 5 | { 6 | MAYALIAS(m,n); 7 | } 8 | 9 | int main() 10 | { 11 | int *p, *q; 12 | int a,b; 13 | if (a) { 14 | p = &a; 15 | q = &b; 16 | foo(p,q); 17 | } 18 | else { 19 | p = &b; 20 | q = &a; 21 | foo(p,q); 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Assignment-3/testcase/src/no_alias.c: -------------------------------------------------------------------------------- 1 | extern void NOALIAS(void* p, void* q); 2 | 3 | 4 | int global_obj_f; 5 | int *global_ptr_f = &global_obj_f; 6 | int main(){ 7 | 8 | int a = 5; 9 | NOALIAS(global_ptr_f,&a); 10 | return 0; 11 | 12 | } -------------------------------------------------------------------------------- /Assignment-4/Assignment-4.cpp: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 4-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 4: Information Flow Tracking 25 | // 26 | // 27 | */ 28 | #include "Assignment-4.h" 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace SVF; 35 | using namespace llvm; 36 | using namespace std; 37 | 38 | 39 | // Get sources function names read from checker_source_api collected from a text file 40 | std::set& TaintGraphTraversal::identifySources() 41 | { 42 | for (const CallICFGNode *cs : pag->getCallSiteSet()) 43 | { 44 | const FunObjVar *fun = cs->getCalledFunction(); 45 | if (checker_source_api.find(fun->getName()) != checker_source_api.end()) 46 | { 47 | sources.insert(cs); 48 | } 49 | } 50 | return sources; 51 | } 52 | // Get sinks function names read from checker_sink_api collected from a text file 53 | std::set& TaintGraphTraversal::identifySinks() 54 | { 55 | for (const CallICFGNode *cs : pag->getCallSiteSet()) 56 | { 57 | const FunObjVar *fun = cs->getCalledFunction(); 58 | if (checker_sink_api.find(fun->getName()) != checker_sink_api.end()) 59 | { 60 | sinks.insert(cs); 61 | } 62 | } 63 | return sinks; 64 | } 65 | 66 | // Start taint checking. 67 | // There is a tainted flow from p@source to q@sink 68 | // if (1) alias(p,q)==true and (2) source reaches sink on ICFG. 69 | void TaintGraphTraversal::taintChecking(){ 70 | // configure sources and sinks for taint analysis 71 | readSrcSnkFromFile("./Assignment-4/SrcSnk.txt"); 72 | ander = new AndersenPTA(pag); 73 | ander->analyze(); 74 | for(const CallICFGNode* src : identifySources()){ 75 | for(const CallICFGNode* snk : identifySinks()){ 76 | if(aliasCheck(src,snk)) 77 | reachability(src, snk); 78 | } 79 | } 80 | } 81 | 82 | /// TODO: print each path once this method is called, and 83 | /// (1) add each path (a sequence of node IDs) as a string into std::set paths 84 | /// in the format "START: 1->2->4->5->END", where -> indicate an ICFGEdge connects two ICFGNode IDs 85 | /// bonus: dump and append each program path to a `ICFGPaths.txt` in the form of 86 | /// ‘{ln: number cl: number, fl:name} -> {ln: number, cl: number, fl: name} -> {ln:number, cl: number, fl: name} 87 | /// ln : line number cl: column number fl:file name for further learning, you can review the code in SVF, SVFUtil 88 | void TaintGraphTraversal::collectICFGPath(std::vector &path){ 89 | 90 | } 91 | 92 | 93 | // TODO: Implement your code to parse the two lines from `SrcSnk.txt` in the form of 94 | // line 1 for sources "{ api1 api2 api3 }" 95 | // line 2 for sinks "{ api1 api2 api3 }" 96 | void TaintGraphTraversal::readSrcSnkFromFile(const string& filename){ 97 | 98 | } 99 | 100 | /// TODO: Checking aliases of the two variables at source and sink. For example: 101 | /// src instruction: actualRet = source(); 102 | /// snk instruction: sink(actualParm,...); 103 | /// return true if actualRet is aliased with any parameter at the snk node (e.g., via ander->alias(..,..)) 104 | bool TaintGraphTraversal::aliasCheck(const CallICFGNode *src, const CallICFGNode *snk) 105 | { 106 | return true; 107 | } 108 | -------------------------------------------------------------------------------- /Assignment-4/Assignment-4.h: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 4-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 4: Information Flow Tracking 25 | // 26 | // 27 | */ 28 | #ifndef ASSIGNMENT_4_H_ 29 | #define ASSIGNMENT_4_H_ 30 | #include "Assignment-2.h" 31 | #include "Assignment-3.h" 32 | 33 | class TaintGraphTraversal : public ICFGTraversal{ 34 | 35 | public: 36 | // mapping a type to its corresponding APIs, e.g., source -> {getenv, ...} 37 | TaintGraphTraversal(SVFIR* pag): ICFGTraversal(pag){} 38 | 39 | // Return true if two pointers are aliases 40 | bool aliasCheck(const CallICFGNode *src, const CallICFGNode *snk); 41 | 42 | // Identify source nodes on ICFG (i.e., call instruction with its callee function named 'src') 43 | std::set& identifySources(); 44 | 45 | // Identify sink nodes on ICFG (i.e., call instruction with its callee function named 'sink') 46 | std::set& identifySinks(); 47 | 48 | // TODO: implement the path printing 49 | void collectICFGPath(std::vector &path); 50 | 51 | // TODO: Source and sink function names read from SrcSnk.txt 52 | void readSrcSnkFromFile(const std::string& filename); 53 | 54 | // The driver method for taint checking 55 | void taintChecking(); 56 | 57 | private: 58 | AndersenPTA* ander; 59 | 60 | // default source and sink function name API if SrcSnk.txt is not added 61 | std::set checker_source_api; 62 | std::set checker_sink_api; 63 | 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /Assignment-4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(../Assignment-2) 2 | include_directories(../Assignment-3) 3 | file (GLOB SOURCES 4 | *.cpp 5 | ../Assignment-2/Assignment-2.cpp 6 | ../Assignment-3/Assignment-3.cpp 7 | ) 8 | 9 | add_executable(assign-4 ${SOURCES}) 10 | 11 | target_link_libraries(assign-4 ${SVF_LIB} ${llvm_libs}) 12 | 13 | set_target_properties(assign-4 PROPERTIES 14 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) 15 | -------------------------------------------------------------------------------- /Assignment-4/SrcSnk.txt: -------------------------------------------------------------------------------- 1 | source -> { source src set getname update getchar tgetstr } 2 | sink -> { sink mysql_query system require chmod broadcast } -------------------------------------------------------------------------------- /Assignment-4/Test4.cpp: -------------------------------------------------------------------------------- 1 | //===- Software-Analysis-Teaching Assignment 4-------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis Framework for Source Code 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // Software-Analysis-Teaching Assignment 4: Information Flow Tracking 25 | // 26 | // 27 | */ 28 | #include "Assignment-4.h" 29 | 30 | #include "SVF-LLVM/LLVMUtil.h" 31 | #include "SVF-LLVM/SVFIRBuilder.h" 32 | #include "Graphs/CallGraph.h" 33 | #include "Util/Options.h" 34 | #include "Util/CommandLine.h" 35 | 36 | 37 | using namespace std; 38 | 39 | void Test1() 40 | { 41 | cout << "\n running test1: " << endl; 42 | LLVMModuleSet::getLLVMModuleSet()->buildSVFModule({"./Assignment-4/testcase/bc/test1.ll"}); 43 | /// Build Program Assignment Graph (SVFIR) 44 | SVF::SVFIRBuilder builder; 45 | SVF::SVFIR *pag = builder.build(); 46 | TaintGraphTraversal* taint = new TaintGraphTraversal(pag); 47 | taint->taintChecking(); 48 | set expected = {"START->6->1->5->2->7->8->9->10->END"}; 49 | assert(taint->getPaths() == expected && " \n wrong paths generated - test1 failed !"); 50 | cout << "\n test1 passed !" << endl; 51 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 52 | SVF::SVFIR::releaseSVFIR(); 53 | NodeIDAllocator::unset(); 54 | } 55 | void Test2() 56 | { 57 | cout << "\n running test2 :" << endl; 58 | LLVMModuleSet::getLLVMModuleSet()->buildSVFModule({"./Assignment-4/testcase/bc/test2.ll"}); 59 | /// Build Program Assignment Graph (SVFIR) 60 | SVF::SVFIRBuilder builder; 61 | SVF::SVFIR *pag = builder.build(); 62 | 63 | TaintGraphTraversal* taint = new TaintGraphTraversal(pag); 64 | 65 | taint->taintChecking(); 66 | assert(taint->getPaths().size() == 0 && " \n should not exist tainted path - test2 failed !"); 67 | cout << "\n test2 passed !" << endl; 68 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 69 | SVF::SVFIR::releaseSVFIR(); 70 | NodeIDAllocator::unset(); 71 | } 72 | 73 | void Test3() 74 | { 75 | cout << "\n running test3 :" << endl; 76 | LLVMModuleSet::getLLVMModuleSet()->buildSVFModule({"./Assignment-4/testcase/bc/test3.ll"}); 77 | /// Build Program Assignment Graph (SVFIR) 78 | SVF::SVFIRBuilder builder; 79 | SVF::SVFIR *pag = builder.build(); 80 | 81 | TaintGraphTraversal* taint = new TaintGraphTraversal(pag); 82 | 83 | taint->taintChecking(); 84 | assert(taint->getPaths().size() == 0 && " \n should not exist tainted path - test3 failed !"); 85 | cout << "\n test3 passed !" << endl; 86 | SVF::SVFIR::releaseSVFIR(); 87 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 88 | NodeIDAllocator::unset(); 89 | } 90 | 91 | void Test4() 92 | { 93 | cout << "\n running test4 :" << endl; 94 | LLVMModuleSet::getLLVMModuleSet()->buildSVFModule({"./Assignment-4/testcase/bc/test4.ll"}); 95 | /// Build Program Assignment Graph (SVFIR) 96 | SVF::SVFIRBuilder builder; 97 | SVF::SVFIR *pag = builder.build(); 98 | 99 | TaintGraphTraversal* taint = new TaintGraphTraversal(pag); 100 | 101 | taint->taintChecking(); 102 | set expected = {"START->6->1->5->2->7->8->9->10->11->13->14->END"}; 103 | assert(taint->getPaths() == expected && " \n wrong paths generated - test4 failed !"); 104 | cout << "\n test4 passed !" << endl; 105 | SVF::LLVMModuleSet::releaseLLVMModuleSet(); 106 | SVF::SVFIR::releaseSVFIR(); 107 | NodeIDAllocator::unset(); 108 | } 109 | int main(int argc, char ** argv) 110 | { 111 | int arg_num = 0; 112 | int extraArgc = 1; 113 | char **arg_value = new char *[argc + extraArgc]; 114 | for (; arg_num < argc; ++arg_num) { 115 | arg_value[arg_num] = argv[arg_num]; 116 | } 117 | 118 | // You may comment it to see the details of the analysis 119 | arg_value[arg_num++] = (char*) "-stat=false"; 120 | 121 | std::vector moduleNameVec; 122 | moduleNameVec = OptionBase::parseOptions( 123 | arg_num, arg_value, "Teaching-Software-Analysis Assignment 4", "[options]" 124 | ); 125 | Test1(); 126 | Test2(); 127 | Test3(); 128 | Test4(); 129 | return 0; 130 | } 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /Assignment-4/testcase/bc/test1.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'test1.ll' 2 | source_filename = "test1.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | @tgetstr.initstr = internal global [25 x i8] c"select* From City ..\00\00\00\00\00", align 16 7 | 8 | ; Function Attrs: noinline nounwind uwtable 9 | define dso_local ptr @tgetstr() #0 { 10 | entry: 11 | ret ptr @tgetstr.initstr 12 | } 13 | 14 | ; Function Attrs: noinline nounwind uwtable 15 | define dso_local i32 @main() #0 { 16 | entry: 17 | %call = call ptr @tgetstr() 18 | call void @MAYALIAS(ptr noundef %call, ptr noundef %call) 19 | call void @broadcast(ptr noundef %call) 20 | ret i32 0 21 | } 22 | 23 | declare void @MAYALIAS(ptr noundef, ptr noundef) #1 24 | 25 | declare void @broadcast(ptr noundef) #1 26 | 27 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 28 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 29 | 30 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 31 | !llvm.ident = !{!5} 32 | 33 | !0 = !{i32 1, !"wchar_size", i32 4} 34 | !1 = !{i32 8, !"PIC Level", i32 2} 35 | !2 = !{i32 7, !"PIE Level", i32 2} 36 | !3 = !{i32 7, !"uwtable", i32 2} 37 | !4 = !{i32 7, !"frame-pointer", i32 2} 38 | !5 = !{!"clang version 16.0.0"} 39 | -------------------------------------------------------------------------------- /Assignment-4/testcase/bc/test2.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'test2.ll' 2 | source_filename = "test2.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | @tgetstr.initstr = internal global [25 x i8] c"select* From City ..\00\00\00\00\00", align 16 7 | @.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1 8 | 9 | ; Function Attrs: noinline nounwind uwtable 10 | define dso_local ptr @tgetstr() #0 { 11 | entry: 12 | ret ptr @tgetstr.initstr 13 | } 14 | 15 | ; Function Attrs: noinline nounwind uwtable 16 | define dso_local i32 @main() #0 { 17 | entry: 18 | %call = call ptr @tgetstr() 19 | call void @broadcast(ptr noundef @.str) 20 | call void @NOALIAS(ptr noundef @.str, ptr noundef %call) 21 | ret i32 0 22 | } 23 | 24 | declare void @broadcast(ptr noundef) #1 25 | 26 | declare void @NOALIAS(ptr noundef, ptr noundef) #1 27 | 28 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 29 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 30 | 31 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 32 | !llvm.ident = !{!5} 33 | 34 | !0 = !{i32 1, !"wchar_size", i32 4} 35 | !1 = !{i32 8, !"PIC Level", i32 2} 36 | !2 = !{i32 7, !"PIE Level", i32 2} 37 | !3 = !{i32 7, !"uwtable", i32 2} 38 | !4 = !{i32 7, !"frame-pointer", i32 2} 39 | !5 = !{!"clang version 16.0.0"} 40 | -------------------------------------------------------------------------------- /Assignment-4/testcase/bc/test3.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'test3.ll' 2 | source_filename = "test3.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1 7 | 8 | ; Function Attrs: noinline nounwind uwtable 9 | define dso_local ptr @foo(ptr noundef %token) #0 { 10 | entry: 11 | ret ptr %token 12 | } 13 | 14 | ; Function Attrs: noinline nounwind uwtable 15 | define dso_local i32 @main() #0 { 16 | entry: 17 | %call = call ptr (...) @getchar() 18 | br label %while.cond 19 | 20 | while.cond: ; preds = %if.end, %entry 21 | %tobool = trunc i8 1 to i1 22 | br i1 %tobool, label %while.body, label %while.end 23 | 24 | while.body: ; preds = %while.cond 25 | %tobool1 = trunc i8 0 to i1 26 | br i1 %tobool1, label %if.then, label %if.else 27 | 28 | if.then: ; preds = %while.body 29 | %call2 = call ptr @foo(ptr noundef %call) 30 | br label %if.end 31 | 32 | if.else: ; preds = %while.body 33 | %call3 = call ptr @foo(ptr noundef @.str) 34 | call void (ptr, ...) @broadcast(ptr noundef %call3) 35 | call void @NOALIAS(ptr noundef %call, ptr noundef %call3) 36 | br label %if.end 37 | 38 | if.end: ; preds = %if.else, %if.then 39 | br label %while.cond, !llvm.loop !6 40 | 41 | while.end: ; preds = %while.cond 42 | ret i32 0 43 | } 44 | 45 | declare ptr @getchar(...) #1 46 | 47 | declare void @broadcast(...) #1 48 | 49 | declare void @NOALIAS(ptr noundef, ptr noundef) #1 50 | 51 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 52 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 53 | 54 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 55 | !llvm.ident = !{!5} 56 | 57 | !0 = !{i32 1, !"wchar_size", i32 4} 58 | !1 = !{i32 8, !"PIC Level", i32 2} 59 | !2 = !{i32 7, !"PIE Level", i32 2} 60 | !3 = !{i32 7, !"uwtable", i32 2} 61 | !4 = !{i32 7, !"frame-pointer", i32 2} 62 | !5 = !{!"clang version 16.0.0"} 63 | !6 = distinct !{!6, !7} 64 | !7 = !{!"llvm.loop.mustprogress"} 65 | -------------------------------------------------------------------------------- /Assignment-4/testcase/bc/test4.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'test4.ll' 2 | source_filename = "test4.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-unknown-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [4 x i8] c"/0 \00", align 1 7 | @.str.1 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 8 | 9 | ; Function Attrs: noinline nounwind uwtable 10 | define dso_local ptr @getchar() #0 { 11 | entry: 12 | ret ptr @.str 13 | } 14 | 15 | ; Function Attrs: noinline nounwind uwtable 16 | define dso_local i32 @main() #0 { 17 | entry: 18 | %call = call ptr @getchar() 19 | br label %while.cond 20 | 21 | while.cond: ; preds = %if.end, %entry 22 | %tobool = trunc i8 1 to i1 23 | br i1 %tobool, label %while.body, label %while.end 24 | 25 | while.body: ; preds = %while.cond 26 | %tobool1 = trunc i8 1 to i1 27 | br i1 %tobool1, label %if.then, label %if.else 28 | 29 | if.then: ; preds = %while.body 30 | call void (ptr, ...) @broadcast(ptr noundef %call) 31 | call void @MAYALIAS(ptr noundef %call, ptr noundef %call) 32 | br label %if.end 33 | 34 | if.else: ; preds = %while.body 35 | br label %if.end 36 | 37 | if.end: ; preds = %if.else, %if.then 38 | br label %while.cond, !llvm.loop !6 39 | 40 | while.end: ; preds = %while.cond 41 | ret i32 0 42 | } 43 | 44 | declare void @broadcast(...) #1 45 | 46 | declare void @MAYALIAS(ptr noundef, ptr noundef) #1 47 | 48 | attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 49 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 50 | 51 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 52 | !llvm.ident = !{!5} 53 | 54 | !0 = !{i32 1, !"wchar_size", i32 4} 55 | !1 = !{i32 8, !"PIC Level", i32 2} 56 | !2 = !{i32 7, !"PIE Level", i32 2} 57 | !3 = !{i32 7, !"uwtable", i32 2} 58 | !4 = !{i32 7, !"frame-pointer", i32 2} 59 | !5 = !{!"clang version 16.0.0"} 60 | !6 = distinct !{!6, !7} 61 | !7 = !{!"llvm.loop.mustprogress"} 62 | -------------------------------------------------------------------------------- /Assignment-4/testcase/src/test1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | extern void MAYALIAS(void* p, void* q); 4 | extern void broadcast(char* num); 5 | char *tgetstr(){ 6 | // e.g. sql injection init 7 | static char initstr[25] = "select* From City .."; 8 | return initstr; 9 | } 10 | 11 | 12 | int main(){ 13 | char *injection = tgetstr(); 14 | char* s = injection; 15 | char* b = s; 16 | MAYALIAS(injection, s); 17 | broadcast(b); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Assignment-4/testcase/src/test2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | extern void NOALIAS(void* p, void* q); 4 | extern void MAYALIAS(void* p, void* q); 5 | extern void broadcast(char* num); 6 | char *tgetstr(){ 7 | // e.g. sql injection init 8 | static char initstr[25] = "select* From City .."; 9 | return initstr; 10 | } 11 | 12 | 13 | int main(){ 14 | char *injection = tgetstr(); 15 | char* s = injection; 16 | char* b = s; 17 | char* safe_token = "hello"; 18 | broadcast(safe_token); 19 | NOALIAS(safe_token,b); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Assignment-4/testcase/src/test3.c: -------------------------------------------------------------------------------- 1 | #include 2 | extern char* getchar(); 3 | extern void broadcast(); 4 | char* foo(char* token){ return token; } 5 | extern void NOALIAS(void* p, void* q); 6 | int main(){ 7 | bool loopCondition = true; 8 | bool BranchCondition = false; 9 | char* secretToken = getchar(); // source 10 | char* publicToken = "hello"; 11 | while(loopCondition){ 12 | if(BranchCondition){ 13 | char* b =foo(secretToken); 14 | } 15 | else{ 16 | char* a = foo(publicToken); 17 | broadcast(a); // sink 18 | NOALIAS(secretToken,a); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Assignment-4/testcase/src/test4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern void broadcast(); 4 | char* getchar(){ return "/0 "; }; //init a char number 5 | extern void MAYALIAS(void* p, void* q); 6 | int main(){ 7 | bool loopCondition = true; 8 | bool BranchCondition = true; 9 | char* secretToken = getchar(); // source 10 | while(loopCondition){ 11 | if(BranchCondition){ 12 | char* a = secretToken; 13 | broadcast(a); // sink 14 | MAYALIAS(a,secretToken); 15 | } 16 | else{ 17 | char* b = "hello"; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.23) 2 | 3 | project(Teaching-Software-Analysis 4 | VERSION 1.0 5 | DESCRIPTION "Teaching-Software-Analysis is an open course for learning software analysis" 6 | HOMEPAGE_URL "https://github.com/SVF-tools/Teaching-Software-Analysis" 7 | LANGUAGES C CXX 8 | ) 9 | 10 | # Check if the LLVM_DIR environment variable is defined and set it accordingly 11 | if (DEFINED LLVM_DIR) 12 | set(ENV{LLVM_DIR} "${LLVM_DIR}") 13 | elseif (DEFINED ENV{LLVM_DIR}) 14 | set(LLVM_DIR $ENV{LLVM_DIR}) 15 | else() 16 | message(FATAL_ERROR "\ 17 | WARNING: The LLVM_DIR var was not set !\n\ 18 | Please set this to environment variable to point to the LLVM_DIR directory or set this variable to cmake configuration\n(e.g. on linux: export LLVM_DIR=/path/to/LLVM/dir) \n or \n \n(make the project via: cmake -DLLVM_DIR=your_path_to_LLVM) ") 19 | endif() 20 | 21 | # If the LLVM_DIR environment variable is set, configure CMake build flags and standards for C++ and C 22 | if (DEFINED ENV{LLVM_DIR}) 23 | # Set the C++ standard to C++17 and configure compiler flags based on the build type 24 | set(CMAKE_CXX_STANDARD 17) 25 | if(CMAKE_BUILD_TYPE MATCHES "Debug") 26 | set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++17 -O0 -fno-rtti -Wno-deprecated -Werror") 27 | else() 28 | set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++17 -O3 -fno-rtti -Wno-deprecated -Werror") 29 | endif() 30 | set(CMAKE_C_FLAGS "-fPIC") 31 | # Check if compiler is GNU and version is less than 9 32 | if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9) 33 | # Link filesystem library globally 34 | link_libraries(stdc++fs) 35 | endif() 36 | endif() 37 | 38 | 39 | # Locate and use the LLVM package for the project 40 | find_package(LLVM REQUIRED CONFIG) 41 | message(STATUS "LLVM STATUS: 42 | Version: ${LLVM_VERSION} 43 | Includes: ${LLVM_INCLUDE_DIRS} 44 | Libraries: ${LLVM_LIBRARY_DIRS} 45 | Build type: ${LLVM_BUILD_TYPE} 46 | RTTI enabled: ${LLVM_ENABLE_RTTI} 47 | Exceptions enabled: ${LLVM_ENABLE_EH} 48 | Dynamic lib: ${LLVM_LINK_LLVM_DYLIB}" 49 | ) 50 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") 51 | include(AddLLVM) 52 | 53 | # Add LLVM definitions to the compile options 54 | add_definitions(${LLVM_DEFINITIONS}) 55 | include_directories(${LLVM_INCLUDE_DIRS}) 56 | 57 | # Abort configuration if LLVM is not found 58 | if(NOT "${LLVM_FOUND}") 59 | message(FATAL_ERROR "Failed to find supported LLVM version") 60 | endif() 61 | 62 | # Add the LLVM include and library directories for all subsequent targets 63 | separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS}) 64 | include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) 65 | link_directories(${LLVM_LIBRARY_DIRS}) 66 | add_definitions(${LLVM_DEFINITIONS}) 67 | 68 | # Determine how to link with LLVM (dynamically with a single shared library or statically with multiple libraries) 69 | if(LLVM_LINK_LLVM_DYLIB) 70 | message(STATUS "Linking to LLVM dynamic shared library object") 71 | set(llvm_libs LLVM) 72 | else() 73 | message(STATUS "Linking to separate LLVM static libraries") 74 | llvm_map_components_to_libnames(llvm_libs bitwriter core ipo irreader instcombine instrumentation target linker analysis scalaropts support) 75 | endif() 76 | 77 | # Re-include AddLLVM module and configure LLVM/CMake settings 78 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") 79 | include(AddLLVM) 80 | 81 | # Configure additional compile options for RTTI and exception handling based on LLVM settings 82 | if(NOT LLVM_ENABLE_RTTI) 83 | add_compile_options("-fno-rtti") 84 | endif() 85 | if(NOT LLVM_ENABLE_EH) 86 | add_compile_options("-fno-exceptions") 87 | endif() 88 | 89 | 90 | # If SVF_DIR is not set while ENV{SVF_DIR} is set, sync. 91 | if(NOT DEFINED SVF_DIR AND DEFINED ENV{SVF_DIR}) 92 | set(SVF_DIR $ENV{SVF_DIR}) 93 | endif() 94 | # Find the SVF CMake package (pass $SVF_DIR as a (prioritised) hint) Set 95 | # $SVF_DIR to the installation prefix used to install SVF 96 | find_package(SVF REQUIRED CONFIG HINTS ${SVF_DIR} ${SVF_DIR}/Debug-build ${SVF_DIR}/Release-build) 97 | 98 | message(STATUS "SVF STATUS: 99 | Found: ${SVF_FOUND} 100 | Version: ${SVF_VERSION} 101 | Build mode: ${SVF_BUILD_TYPE} 102 | C++ standard: ${SVF_CXX_STANDARD} 103 | RTTI enabled: ${SVF_ENABLE_RTTI} 104 | Exceptions enabled: ${SVF_ENABLE_EXCEPTIONS} 105 | Install root directory: ${SVF_INSTALL_ROOT} 106 | Install binary directory: ${SVF_INSTALL_BIN_DIR} 107 | Install library directory: ${SVF_INSTALL_LIB_DIR} 108 | Install include directory: ${SVF_INSTALL_INCLUDE_DIR} 109 | Install 'extapi.bc' file path: ${SVF_INSTALL_EXTAPI_FILE}") 110 | 111 | # Set default build type to Release if not set 112 | if(NOT CMAKE_BUILD_TYPE) 113 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) 114 | endif() 115 | 116 | # Assert if CMAKE_BUILD_TYPE is Debug but SVF_BUILD_TYPE is Release 117 | if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND SVF_BUILD_TYPE STREQUAL "Release") 118 | message(FATAL_ERROR "CMAKE_BUILD_TYPE=Debug but SVF_BUILD_TYPE=Release is not allowed!") 119 | endif() 120 | 121 | # Check if SVF is found and handle importing with modern CMake methods or legacy methods 122 | if("${SVF_FOUND}") 123 | message(STATUS "Found installed SVF instance; importing using modern CMake methods") 124 | 125 | # Ensure compatibility between SVF and LLVM in terms of RTTI and exception handling 126 | if(NOT (${SVF_ENABLE_RTTI} STREQUAL ${LLVM_ENABLE_RTTI})) 127 | message(FATAL_ERROR "SVF & LLVM RTTI support mismatch (SVF: ${SVF_ENABLE_RTTI}, LLVM: ${LLVM_ENABLE_RTTI})! This indicates that the version of LLVM used by your SVF dependency does not match the version of LLVM used by your current project. You need to check and ensure both are using the same LLVM version.") 128 | endif() 129 | if(NOT (${SVF_ENABLE_EXCEPTIONS} STREQUAL ${LLVM_ENABLE_EH})) 130 | message(WARNING "SVF & LLVM exceptions support mismatch (SVF: ${SVF_ENABLE_EXCEPTIONS}, LLVM: ${LLVM_ENABLE_EH}). You may not be able to catch exceptions across modules between SVF and LLVM.") 131 | endif() 132 | 133 | # Include SVF include directories and link the library directories 134 | include_directories(SYSTEM ${SVF_INSTALL_INCLUDE_DIR}) 135 | link_directories(${SVF_INSTALL_LIB_DIR}) 136 | else() 137 | message(STATUS "Failed to find installed SVF instance; using legacy import method") 138 | message(FATAL_ERROR "SVF & LLVM RTTI support mismatch (SVF: ${SVF_ENABLE_RTTI}, LLVM: ${LLVM_ENABLE_RTTI})!") 139 | endif() 140 | 141 | # Set the SVF library components 142 | set(SVF_LIB SvfLLVM SvfCore) 143 | 144 | # Find and configure Z3 package, first trying the system Z3 with CMake, then fallback to SVF's Z3 instance 145 | # Find Z3 and its include directory from the top-level include file 146 | find_library(Z3_LIBRARIES REQUIRED NAMES z3 HINTS ${Z3_DIR} ENV Z3_DIR PATH_SUFFIXES bin lib) 147 | find_path(Z3_INCLUDES REQUIRED NAMES z3++.h HINTS ${Z3_DIR} ENV Z3_DIR PATH_SUFFIXES include z3) 148 | message(STATUS "Z3 STATUS: 149 | Z3 library file: ${Z3_LIBRARIES} 150 | Z3 include directory: ${Z3_INCLUDES}" 151 | ) 152 | 153 | # Add the Z3 include directory and link the Z3 library to all targets of SVF 154 | set(CMAKE_INSTALL_RPATH ${Z3_INCLUDES}) 155 | link_libraries(${Z3_LIBRARIES}) 156 | include_directories(SYSTEM ${Z3_INCLUDES}) 157 | 158 | # ============================================================================== 159 | # SVF Ecosystem CMake Template 160 | # ============================================================================== 161 | # ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 162 | # Everything above this line is a general CMake template for SVF ecosystem projects. 163 | # Everything below this line is specific to this project (user/application code). 164 | # ============================================================================== 165 | 166 | 167 | add_subdirectory(HelloWorld) 168 | add_subdirectory(CodeGraph) 169 | add_subdirectory(Assignment-1) 170 | add_subdirectory(Assignment-2) 171 | add_subdirectory(Assignment-3) 172 | add_subdirectory(Assignment-4) 173 | -------------------------------------------------------------------------------- /CodeGraph/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES 2 | *.cpp 3 | ) 4 | add_executable(codegraph ${SOURCES}) 5 | 6 | target_link_libraries(codegraph ${SVF_LIB} ${llvm_libs}) 7 | 8 | set_target_properties( codegraph PROPERTIES 9 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) 10 | -------------------------------------------------------------------------------- /CodeGraph/CodeGraph.cpp: -------------------------------------------------------------------------------- 1 | //=== Software-Analysis-Teaching CodeGraph.cpp -- -------------------------------------// 2 | // 3 | // SVF: Static Value-Flow Analysis 4 | // 5 | // Copyright (C) <2013-> 6 | // 7 | 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | //===-----------------------------------------------------------------------===// 22 | 23 | /* 24 | // SVFIR ICFG Generation 25 | // 26 | // Author: Guanqin Zhang email: 152585@uts.edu.au 27 | */ 28 | 29 | #include "SVF-LLVM/LLVMUtil.h" 30 | #include "Graphs/SVFG.h" 31 | #include "WPA/Andersen.h" 32 | #include "SABER/LeakChecker.h" 33 | #include "SVF-LLVM/SVFIRBuilder.h" 34 | 35 | 36 | using namespace SVF; 37 | using namespace llvm; 38 | using namespace std; 39 | 40 | 41 | int main(int argc, char ** argv) { 42 | 43 | int arg_num = 0; 44 | int extraArgc = 1; 45 | char **arg_value = new char *[argc + extraArgc]; 46 | for (; arg_num < argc; ++arg_num) { 47 | arg_value[arg_num] = argv[arg_num]; 48 | } 49 | 50 | // You may comment it to see the details of the analysis 51 | arg_value[arg_num++] = (char*) "-stat=false"; 52 | 53 | std::vector moduleNameVec; 54 | moduleNameVec = OptionBase::parseOptions( 55 | arg_num, arg_value, "Teaching-Software-Analysis Assignment 4", "[options]" 56 | ); 57 | 58 | LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec); 59 | 60 | /// Build Program Assignment Graph (SVFIR or PAG) 61 | SVFIRBuilder builder; 62 | SVFIR *pag = builder.build(); 63 | //dump pag 64 | pag->dump(PAG::getPAG()->getModuleIdentifier() + ".pag"); 65 | /// ICFG 66 | ICFG *icfg = pag->getICFG(); 67 | //dump icfg 68 | icfg->dump(PAG::getPAG()->getModuleIdentifier() + ".icfg"); 69 | 70 | // iterate each ICFGNode on ICFG 71 | for(ICFG::iterator i = icfg->begin(); i != icfg->end(); i++) 72 | { 73 | ICFGNode *n = i->second; 74 | // SVFUtil::outs() << n->toString() << "\n"; 75 | // for(ICFGEdge* edge : n->getOutEdges()){ 76 | // SVFUtil::outs() << edge->toString() << "\n"; 77 | // } 78 | } 79 | 80 | // iterate each SVFVar on SVFIR 81 | for(SVFIR::iterator p = pag->begin(); p != pag->end();p++) 82 | { 83 | SVFVar *n = p->second; 84 | // SVFUtil::outs() << n->toString() << "\n"; 85 | // for(SVFStmt* edge : n->getOutEdges()){ 86 | // SVFUtil::outs() << edge->toString() << "\n"; 87 | // } 88 | } 89 | 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /CodeGraph/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -n $1 ]; then 3 | file=$(basename $1 .c) 4 | clang -S -c -Xclang -disable-O0-optnone -fno-discard-value-names -emit-llvm $1 -o $file.ll 5 | opt -S -p=mem2reg $file.ll -o $file.ll 6 | else 7 | echo "please give the .c file" 8 | fi 9 | -------------------------------------------------------------------------------- /CodeGraph/src/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | void sink(); 3 | void source(int *s){ 4 | sink(); 5 | }; 6 | void sink(){ 7 | }; 8 | 9 | int main(){ 10 | int a = 1; 11 | while ( a <=1){ 12 | source(&a); 13 | a++; 14 | } 15 | return 0; 16 | }; 17 | -------------------------------------------------------------------------------- /CodeGraph/src/swap.c: -------------------------------------------------------------------------------- 1 | void swap(char **p, char **q){ 2 | char* t = *p; 3 | *p = *q; 4 | *q = t; 5 | } 6 | int main(){ 7 | char a1, b1; 8 | char *a = &a1; 9 | char *b = &b1; 10 | swap(&a,&b); 11 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:24.04 2 | 3 | # Stop ubuntu-20 interactive options. 4 | ENV DEBIAN_FRONTEND noninteractive 5 | ARG TARGETPLATFORM 6 | 7 | # Stop script if any individual command fails. 8 | RUN set -e 9 | 10 | # Define LLVM version. 11 | ENV llvm_version=16.0.0 12 | 13 | # Define home directory 14 | ENV HOME=/home/SVF-tools 15 | 16 | # Define dependencies. 17 | ENV lib_deps="cmake g++ gcc git zlib1g-dev libncurses5-dev libtinfo6 build-essential libssl-dev libpcre2-dev zip libzstd-dev" 18 | ENV build_deps="wget xz-utils git gdb tcl software-properties-common" 19 | 20 | # Fetch dependencies. 21 | RUN apt-get update --fix-missing 22 | RUN apt-get install -y $build_deps $lib_deps 23 | 24 | # Add deadsnakes PPA for multiple Python versions 25 | RUN add-apt-repository ppa:deadsnakes/ppa 26 | RUN apt-get update 27 | RUN set -ex; \ 28 | if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ 29 | apt-get update && apt-get install -y python3.10-dev \ 30 | && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1; \ 31 | elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ 32 | apt-get update && apt-get install -y python3.8-dev \ 33 | && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1; \ 34 | else \ 35 | echo "Unsupported platform: $TARGETPLATFORM" && exit 1; \ 36 | fi 37 | 38 | # Fetch and build SVF source. 39 | RUN echo "Downloading LLVM and building SVF to " ${HOME} 40 | WORKDIR ${HOME} 41 | RUN git clone "https://github.com/SVF-tools/SVF.git" 42 | WORKDIR ${HOME}/SVF 43 | RUN echo "Building SVF ..." 44 | RUN bash ./build.sh 45 | 46 | # Export SVF, llvm, z3 paths 47 | ENV PATH=${HOME}/SVF/Release-build/bin:$PATH 48 | ENV PATH=${HOME}/SVF/llvm-$llvm_version.obj/bin:$PATH 49 | ENV SVF_DIR=${HOME}/SVF 50 | ENV LLVM_DIR=${HOME}/SVF/llvm-$llvm_version.obj 51 | ENV Z3_DIR=${HOME}/SVF/z3.obj 52 | RUN ln -s ${Z3_DIR}/bin/libz3.so ${Z3_DIR}/bin/libz3.so.4 53 | 54 | # Fetch and build 55 | WORKDIR ${HOME} 56 | RUN git clone "https://github.com/SVF-tools/Teaching-Software-Analysis.git" 57 | WORKDIR ${HOME}/Teaching-Software-Analysis 58 | RUN echo "Building ..." 59 | RUN sed -i 's/lldb/gdb/g' ${HOME}/Teaching-Software-Analysis/.vscode/launch.json 60 | RUN cmake -DCMAKE_BUILD_TYPE=MinSizeRel . 61 | RUN make -j8 62 | -------------------------------------------------------------------------------- /HelloWorld/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello hello.cpp) 2 | set_target_properties( hello PROPERTIES 3 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) -------------------------------------------------------------------------------- /HelloWorld/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | cout << "Hello World!\n"; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Software-Analysis-Teaching Contents](https://github.com/SVF-tools/Teaching-Software-Analysis/wiki) 2 | 3 | If you fork this repository, please make it as private and do not disclose your solutions. 4 | 5 | For more courses, refer to [SVF-Teaching](https://github.com/SVF-tools/SVF-Teaching). 6 | 7 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | npm i --silent svf-lib --prefix ${HOME} 3 | source ./env.sh 4 | cmake -DCMAKE_BUILD_TYPE=Debug . 5 | make 6 | -------------------------------------------------------------------------------- /env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Get the current working directory and store it in PROJECTHOME 4 | PROJECTHOME=$(pwd) 5 | 6 | # Detect the operating system type and store it in sysOS 7 | sysOS=`uname -s` 8 | 9 | # Set the major version of LLVM 10 | MajorLLVMVer=16 11 | 12 | # Define the full LLVM version 13 | LLVMVer=${MajorLLVMVer}.0.0 14 | 15 | # Set the home directories for LLVM and Z3 16 | LLVMHome="llvm-${LLVMVer}.obj" 17 | Z3Home="z3.obj" 18 | 19 | # Change this to your SVF root directory 20 | svf_root=`pwd`/../SVF 21 | 22 | # Export the paths for the LLVM, Z3, and SVF directories 23 | export LLVM_DIR=$svf_root/$LLVMHome 24 | export Z3_DIR=$svf_root/$Z3Home 25 | export SVF_DIR=$svf_root 26 | 27 | # Update the PATH to include the binary directories for SVF, LLVM, and the project 28 | export PATH=$SVF_DIR/Release-build/bin:$PATH 29 | export PATH=$LLVM_DIR/bin:$PATH 30 | export PATH=$PROJECTHOME/bin:$PATH 31 | 32 | # Print the paths to the terminal for verification 33 | echo "SVF_DIR="$SVF_DIR 34 | echo "LLVM_DIR="$LLVM_DIR 35 | echo "Z3_DIR="$Z3_DIR --------------------------------------------------------------------------------