[
  {
    "path": ".gitignore",
    "content": "output/*.csv\n.DS_Store\n.idea\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "# ByteCodeDL\n\n<div align=\"center\">\n\t<img src=\"./bdl-logo.png\" alt=\"ByteCodeDL\" width=\"200\">\n</div>\n\nA declarative static analysis tool for jvm bytecode based Datalog like CodeQL\n\n## Why ByteCodeDL\n\nByteCodeDL这个名字是从CodeQL演化的，ByteCode对应Code，DL对应QL，是一款声明式静态分析工具，主要是为了弥补CodeQL无法直接分析字节码的遗憾。\n\n本项目主要有两个目的：\n\n1. 教学目的，帮助大家入门静态分析，本项目将演示如何通过datalog实现一些静态分析算法，比起命令式静态分析，这种方式要简洁很多，学习了基本原理之后，也可以自己DIY规则。\n2. 提高挖洞效率，安全研究人员一般拿不到源码，大多数情况只能分析Jar包，然后通过IDEA看反编译之后的代码，效率比较低，希望ByteCodeDL提供的搜索功能、调用图分析功能、污点分析功能，能够提高安全研究人员的挖洞效率。\n\n## Install\n\n1. [download](https://github.com/BytecodeDL/soot-fact-generator/releases/download/v1.0/soot-fact-generator.jar) or [build](https://github.com/BytecodeDL/soot-fact-generator) soot-fact-generator.jar\n2. install [souffle](https://souffle-lang.github.io/install) \n3. install [neo4j](https://neo4j.com/download-center/)\n\n## Docker\n\nyou can use the docker we builded like docker-compose.yml\n\n## Features\n\n- [x] 搜索功能\n- [x] 调用图分析\n  - [x] CHA\n  - [x] SIMPLE-CHA \n  - [x] RTA\n- [ ] 指针分析\n  - [x] 上下文无关指针分析\n  - [x] 一阶上下文调用点敏感指针分析\n  - [x] 一阶上下文对象敏感指针分析\n  - [x] 一阶上下文类型敏感指针分析\n  - [ ] 可选择上下文敏感指针分析\n- [x] 污点分析\n  - [x] 上下文无关ptaint\n  - [x] 上下文敏感ptaint\n- [ ] 输出sarif\n- [ ] 实现JackEE\n- [ ] 性能优化\n\n## Usage\n\n见docs文件夹\n\n## Support\n\n在使用中遇到什么问题，可以通过\n\n- email: help@bytecodedl.com\n- github: issue/discussion\n- telegram: [bytecodedl](https://t.me/bytecodedl)\n\n三种途径向我们反馈\n\n## Plugin\n\n- IDEA\n  - ByteCodeDL helper [BDLH](https://github.com/BytecodeDL/BDLH)\n  - Datalog language plugin [intellij-datalog](https://github.com/BytecodeDL/intellij-datalog)\n\n## Acknowledgement\n\n- 感谢南大的李樾和谭添两位老师，通过他们开设的[程序分析课程](https://pascal-group.bitbucket.io/teaching.html)入门了静态分析这一领域。\n- 感谢[Doop](https://bitbucket.org/yanniss/doop) , 提供了soot-fact-generator.jar 。\n"
  },
  {
    "path": "docker/bytecodedl/Dockerfile",
    "content": "From ubuntu:22.04\n\nLABEL version=\"1.0.2\"\nLABEL maintainer=\"yxxx <yxwuman@gmail.com>\"\n\nRUN apt-get update \\\n    && apt-get install -y vim \\\n    && apt-get install -y wget \\\n    && apt-get install -y git \\\n    && apt-get install -y openjdk-8-jdk\n\nRUN wget https://souffle-lang.github.io/ppa/souffle-key.public -O /usr/share/keyrings/souffle-archive-keyring.gpg \\\n    && echo \"deb [signed-by=/usr/share/keyrings/souffle-archive-keyring.gpg] https://souffle-lang.github.io/ppa/ubuntu/ stable main\" | tee /etc/apt/sources.list.d/souffle.list \\\n    && apt update && apt install -y souffle\n\nRUN wget https://github.com/BytecodeDL/soot-fact-generator/releases/download/v1.4.2/soot-fact-generator-1.4.2.jar"
  },
  {
    "path": "docker/neo4j-server/Dockerfile",
    "content": "From neo4j:5.12.0\n\nLABEL version=\"1.0.1\"\nLABEL maintainer=\"yxxx <yxwuman@gmail.com>\"\n\nRUN wget https://github.com/BytecodeDL/bytecodedl-pathfinder-neo4j-procedure/releases/download/v1.0.1/bytecodedl-pathfinder-1.0.1.jar -O /var/lib/neo4j/plugins/bytecodedl-pathfinder-1.0.1.jar\n\nENV NEO4J_AUTH=neo4j/bytecodedl \\\n    NEO4J_dbms_security_procedures_unrestricted=bytecodedl.*"
  },
  {
    "path": "docker-compose.yml",
    "content": "version: '2.4'\nservices:\n  bytecodedl:\n    image: wuxxxxx/bytecodedl:1.0.2\n    restart: always\n    command: sleep infinity\n    volumes:\n        - ./:/bytecodedl\n  neo:\n    image: wuxxxxx/neo4j-server:5.12.0-bytecodedl-pathfinder-1.0.1 \n    restart: always\n    ports:\n      - \"0.0.0.0:7474:7474\"\n      - \"0.0.0.0:7687:7687\"\n    volumes:\n        - ./:/bytecodedl\n"
  },
  {
    "path": "docs/callgraph.md",
    "content": "# callgraph\n\n这节介绍调用图构造，强烈建议先看这个 [PPT](https://pascal-group.bitbucket.io/lectures/Inter.pdf)\n\nSpeicalMethodInvocation和StaticMethodInvocation的被调用的方法在编译期间就可以确定，VirtualMethodInvocation需要在运行时根据receiver实际类型才能确定被调函数。\n\n如何确定receiver的运行时类型，成为了调用图构造的关键，下面介绍两种调用图的构造算法及其相应的实现。\n\n## Common\n\n先介绍一下公共的部分。\n\n调用图，首先是从一个入口函数开始，然后通过分析入口函数内的函数调用情况，将被调用的函数加入worklist，等待后续的分析。\n\n定义EntryPoint(simplename:symbol, descriptor:symbol, class:Class) 为入口函数，也就是分析的起点，然后把能够调用到的方法加入到Reachable(method:Method, step:number)，把调用关系加入到CallGraph(insn:Insn, caller:Method, callee:Method)。\n\n为了能够分析大的应用，这里限制了调用长度，在Reachable(method, step) 中step 表示从入口函数到method的调用步数。\n\n```dl\n// 先根据Etrypoint解析出具体的method，加入Reachable\nReachable(method, 0) :- \n    EntryPoint(simplename, descriptor, class),\n    Dispatch(simplename, descriptor, class, method).\n\n// special callee可以直接确定，所以可以直接加入到CallGraph\nReachable(callee, n+1),\nCallGraph(insn, caller, callee) :-\n    // 如果caller能够调用到\n    Reachable(caller, n),\n    // 并且caller调用步数未超过最大步数\n    n < MAXSTEP,\n    // 且caller 调用了 callee ，那么这些条件可以推到出callee也能访问到，且步数为n+1 调用图中caller和callee有条边\n    SpecialMethodInvocation(insn, _, callee, _, caller).\n// 同上\nReachable(callee, n+1),\nCallGraph(insn, caller, callee) :-\n    Reachable(caller, n),\n    n < MAXSTEP,\n    StaticMethodInvocation(insn, _, callee, caller).\n```\n\n## Class hierarchy analysis (CHA)\n\nCHA调用图算法认为，receiver在实际运行的过程中的类型可以是其声明类型的任意非abstract子类。\n\n```dl\nReachable(callee, n+1),\nCallGraph(insn, caller, callee) :-\n    Reachable(caller, n),\n    n < MAXSTEP,\n    // caller 中调用了 receiver.method() 需要根据receiver的声明类型解析\n    VirtualMethodInvocation(insn, _, method, receiver, caller),\n    // 找到method 对应的方法签名也就是simplename和descriptor\n    MethodInfo(method, simplename, _, _, _, descriptor, _),\n    // 找到receiver对应的声明类型\n    VarType(receiver, class),\n    // 找到receiver 自身及其所有的子类\n    SubEqClass(subeqclass, class),\n    // 排除被abstract修饰的类\n    !ClassModifier(\"abstract\", subeqclass),\n    // 根据方法签名和类型解析出真正的被调函数callee\n    Dispatch(simplename, descriptor, subeqclass, callee).\n```\n\n完整的实现见[cha.dl](../logic/cha.dl)\n\n在benchmark使用样例见[cha-exmaple-1.dl](../example/cha-example-1.dl)\n\n创建benchmark facts时可以加上--facts-subset 参数，只生成bechmark中的facts不再连依赖库中的一起解析。具体命令如下\n\n```bash\njava8 -jar ~/code/soot-fact-generator/build/libs/soot-fact-generator.jar -i Benchmark-1.0-SNAPSHOT.jar --full -l /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/rt.jar -d callgraphtest --allow-phantom --generate-jimple --facts-subset APP\n```\n\n## Rapid type analysis (RTA)\n\nRTA是CHA的改进版本，RTA调用图算法认为，receiver在实际运行的过程中的类型不仅要满足是声明类型的子类，而且这个子类还要已经创建过实例。\n\n以 https://github.com/BytecodeDL/Benchmark/blob/main/src/main/java/com/bytecodedl/benchmark/demo/VirtualCallDemo1.java 为例介绍 CHA和RTA的区别\n\n```java\npublic static void main(String[] args) {\n    VirtualCallInterface1 vcall2 = new VirtualCallDemo2();\n    VirtualCallDemo1 vcall1 = new VirtualCallDemo1(vcall2);\n    VirtualCallInterface1 varParent = vcall1.getParent();\n    String source = vcall1.source();\n    varParent.foo(source);\n}\n```\n\n在解析`varParent.foo(`时\nCHA认为 receiver `varParent`的变量为其声明类型VirtualCallInterface1的所有子类，也就是VirtualCallDemo1， VirtualCallDemo2， VirtualCallDemo3 所以`varParent.foo(`会被解析成也就是VirtualCallDemo1#foo，VirtualCallDemo2#foo，VirtualCallDemo3#foo，存在两条误报边。\nRTA认为 receiver `varParent`的变量为其声明类型VirtualCallInterface1的所有子类 和 已实例化类型的交集（两条new语句中的类型），\n也就是{VirtualCallDemo1， VirtualCallDemo2， VirtualCallDemo3} 和 {VirtualCallDemo1， VirtualCallDemo2} 的交集，\n即 {VirtualCallDemo1， VirtualCallDemo2}, 所以`varParent.foo(`会被解析成VirtualCallDemo1#foo，VirtualCallDemo2#foo 减少了一条误报。\n\nRTA对应的规则和CHA基本一致，总共有两处改变，\n\n一处是增加个新的 relation `InstantiatedClass(insn:Insn, class:Class)` 表示reachable中方法已经实例化的类\n\n另一处改变是在解析虚拟方法时，对subeqclass增加了限制，要求subeqclass还要在InstantiatedClass中。\n\n具体的规则如下\n\n```dl\n// 如果method可达\n// 且method中创建heap\n// heap 的类型是 class \n// 那么class就是已创建实例的类型\nInstantiatedClass(insn, class) :-\n     Reachable(method, _),\n     AssignHeapAllocation(insn, _, heap, _, method, _),\n     NormalHeap(heap, class).\n\n Reachable(callee, n+1),\n CallGraph(insn, caller, callee) :-\n     Reachable(caller, n),\n     !BanCaller(caller),\n     n < MAXSTEP,\n     VirtualMethodInvocation(insn, _, method, receiver, caller),\n     MethodInfo(method, simplename, _, _, _, descriptor, _),\n     VarType(receiver, class),\n     SubEqClass(subeqclass, class),\n     !ClassModifier(\"abstract\", subeqclass),\n     // 限制subeqclass是已创建实例的类型\n     InstantiatedClass(_, subeqclass),\n     Dispatch(simplename, descriptor, subeqclass, callee).\n```\n\nCHA只会存在误报，但是RTA既可能存在误报也可能存在漏报。\n\n## Visualization\n\n调用图的输出结果是callgraph，是调用图中的节点，如果节点一多，不太容易寻找下一个节点，可以借助图数据库neo4j进行可视化。\n\n经测试，通过`neo4j-admin import` 导入的效率最高。 [参考链接](https://neo4j.com/docs/operations-manual/current/tutorial/neo4j-admin-import/) \n\n导入neo4j docker的步骤为：\n\n1. 执行下面命令将结果输出到output文件夹\n   \n   ```bash\n   souffle -F factsdir -D ~/code/ByteCodeDL/output ~/code/ByteCodeDL/example/cha-example-1.dl\n   ```\n\n2. 执行bash importOutput2Neo4j.sh neoImportCall.sh dbname\n3. 最后访问 http://ip:7474 登录 neo4j/bytecodedl\n\n注意上述方式只能脱机导入，也就是databasname不能是正在使用的，需要指定个新的，由于社区版neo4j的限制，不能进行多数据库链接，需要通过更改配置文件切换数据库。\n\n可以通过\n\n```cypher\nMATCH p=(entry:entrypoint)-[*]->() where entry.method contains \"virtualcall.vc2\"  RETURN p \n```\n\n查询入口函数开始的调用图，效果如下，点击节点可以在右侧看到详情\n\n![cha-vc2](images/cha-vc2.png)\n\n## Reference\n- https://pascal-group.bitbucket.io/lectures/Inter.pdf\n- https://neo4j.com/docs/operations-manual/current/tutorial/neo4j-admin-import/\n- http://web.cs.ucla.edu/~palsberg/paper/oopsla00.pdf\n- https://people.cs.vt.edu/ryder/515/f05/lectures/OOPLs-CallGraphConstr9.pdf"
  },
  {
    "path": "docs/cha-in-ctf.md",
    "content": "# cha in ctf\n\n本文首发于 https://tttang.com/archive/1510/\n\n这篇文章对应的代码分支见 [cha-in-ctf](https://github.com/BytecodeDL/ByteCodeDL/tree/cha-in-ctf/) 最好切换至该分支再进行阅读\n\n这节将分享如何用ByteCodeDL 的 CHA 调用图分析功能，解决两个CTF题目。\n\n## buggyLoader 0ctf-2021-final\n\n这是0ctf 2021 决赛的一道题目，NeSE和r3kapig解出了这个题目。题目地址见 https://github.com/waderwu/My-CTF-Challenges/tree/master/0ctf-2021-final/buggyLoader 。这道题的灵感来自Shiro环境下的CC链构造，准确的说来自zsx的[这篇文章](https://blog.zsxsoft.com/post/35)\n\n难点在于反序列化时无法创建数组类型，导致InvokerTransformer 的字段iArgs只能为null，所以最终只能调用public 无参函数。常见的反序列化最后调用的函数有：\n\n1. JdbcRowSetImpl#getDatabaseMetaData() 和 JdbcRowSetImpl#getParameterMetaData 利用JNDI进行攻击\n2. TemplatesImpl#getOutputProperties()\n\n但是上述两类在这个题目都不能用，由于不出网，第一种方式不能用，由于TemplatesImpl的_bytecodes字段为数组，所以第二种方式也不能用。\n\n[Orange](http://blog.orange.tw/2018/03/pwn-ctf-platform-with-java-jrmp-gadget.html)在做强网杯那题的时候，最后使用了[JRMP Client](https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/payloads/JRMPClient.java) 这个payload，第一次反序列化时，发起RMI请求，然后在RMI处理响应的时候会再次触发反序列化，第二次反序列化就没有任何限制了。这种方式有两种局限，第一种是需要环境能外连，第二种是高版本的JDK下JRMP Client这个payload不能用了（具体的版本我忘了）。\n\n如果这题能够外连，可以先调用JdbcRowSetImpl，利用JNDI发起一次RMI请求，在RMI处理响应时会再次触发反序列化，类似JRMP Client的效果，但是对JDK版本没有限制。\n\n已知的套路都不能用了，这题该怎么做呢？重新找个能够造成危害的public 无参函数：可以直接执行命令/代码或者能够二次反序列化。\n\n第一步我们先筛选出 public 无参函数\n\n```dl\n#include \"inputDeclaration.dl\"\n#include \"utils.dl\"\n\n\n.decl NonParamPublicMethod(method:Method, class:Class)\n.output NonParamPublicMethod\n\nNonParamPublicMethod(method, class) :-\n    MethodInfo(method, simplename, _, class, _, _, arity),\n    // method 需要被pulic修饰\n    MethodModifier(\"public\", method),\n    // 排除构造函数\n    simplename != \"<init>\",\n    // 参数数量为零\n    arity = 0,\n    // 类需要能可序列化\n    SubClass(class, \"java.io.Serializable\").\n```\n\nJDK中满足条件的一共10459条，如果一条条筛选下来还是比较困难的\n\n我们再进一步做个限制，让这10459初步满足条件的函数，作为入口函数，进行调用图分析，看一下5步之内，有没有可能调用到危险函数。\n[example/ctf-buggyLoader.dl](../example/ctf-buggyLoader.dl)\n\n```dl\n#define MAXSTEP 5\n\n#include \"inputDeclaration.dl\"\n#include \"utils.dl\"\n#include \"cha.dl\"\n\n\n.decl NonParamPublicMethod(method:Method, class:Class)\n.output NonParamPublicMethod\n\n// 通过class和函数名定义危险函数\n.decl SinkDesc(simplename:symbol, class:Class)\n\n// 加入常见的危险函数\nSinkDesc(\"exec\", \"java.lang.Runtime\").\nSinkDesc(\"<init>\", \"java.lang.ProcessBuilder\").\nSinkDesc(\"start\", \"java.lang.ProcessImpl\").\nSinkDesc(\"loadClass\", \"java.lang.ClassLoader\").\nSinkDesc(\"defineClass\", \"java.lang.ClassLoader\").\nSinkDesc(\"readObject\", \"java.io.ObjectInputStream\").\nSinkDesc(\"readExternal\", \"java.io.ObjectInputStream\").\n\n// 定义具体的危险函数\n.decl SinkMethod(method:Method)\n.output SinkMethod\n\n// 定义具体的危险函数\n.decl EntryMethod(method:Method)\n\n// 根据方法名和类名解析初具体的危险方法\n// 子类中的同名方法也认为是危险函数\nSinkMethod(method) :-\n    SinkDesc(simplename, class),\n    SubEqClass(subeqclass, class),\n    !ClassModifier(\"abstract\", subeqclass),\n    MethodInfo(method, simplename, _, subeqclass, _, _, _).\n\n// 将满足条件的无参函数作为入口方法\nEntryMethod(method),\nReachable(method, 0),\nNonParamPublicMethod(method, class) :- \n    MethodInfo(method, simplename, _, class, _, _, arity),\n    MethodModifier(\"public\", method),\n    simplename != \"<init>\",\n    arity = 0,\n    SubClass(class, \"java.io.Serializable\").\n\n// 调用图中节点\n.decl CallNode(node:Method, label:symbol)\n.output CallNode\n\n// 不是入口节点和危险节点 标记为method\nCallNode(node, \"method\") :-\n    !EntryMethod(node),\n    !SinkMethod(node),\n    Reachable(node, _).\n\n// 危险节点标记为 sink\nCallNode(node, \"sink\") :-\n    Reachable(node, _),\n    SinkMethod(node).\n\n// 入口节点标记为entry\nCallNode(node, \"entry\") :-\n    EntryMethod(node).\n\n// 调用边\n.decl CallEdge(caller:Method, callee:Method)\n.output CallEdge\n\nCallEdge(caller, callee) :-\n    CallGraph(_, caller, callee).\n```\n\n通过 bash importOutput2Neo4j.sh neoImportCall.sh dbname 导入\n\n执行查询\n\n```cypher\nMATCH p=(e:entry)-[*1..2]->(s:sink) where s.method contains \"readObject\"  RETURN p\n```\n\n长度为1-2的调用到readObject的路径\n\n可以筛选出\n\n```text\n<java.security.SignedObject: java.lang.Object getObject()>\n```\n\n```text\n<java.rmi.MarshalledObject: java.lang.Object get()>\n```\n\n但是这俩还是都需要数组字段，不满足我们的需求\n\n对于排查不满足需求的，可以通过下面的方式删除节点，同时删除和这个节点相连的边\n\n```cypher\nMATCH (m:method) where ID(m)=42186\nDETACH DELETE m\n```\n\n长度为4的查询\n\n```cypher\nMATCH p=(e:entry)-[*4]->(s:sink) where s.method contains \"readObject\"  RETURN p\n```\n\n```cypher\nMATCH p=(e:entry)-[*4]->(s:sink) where s.method contains \"readObject\" and ID(e)=57653  unwind nodes(p) as n return n.method\n```\n\n查询结果\n\n```text\n<javax.management.remote.rmi.RMIConnector: void connect()>\n<javax.management.remote.rmi.RMIConnector: void connect(java.util.Map)>\n<javax.management.remote.rmi.RMIConnector: javax.management.remote.rmi.RMIServer findRMIServer(javax.management.remote.JMXServiceURL,java.util.Map)>\n<javax.management.remote.rmi.RMIConnector: javax.management.remote.rmi.RMIServer findRMIServerJRMP(java.lang.String,java.util.Map,boolean)>\n<java.io.ObjectInputStream: java.lang.Object readObject()>\n```\n\n大致的流程如下\n\nrmiConnector.jmxServiceURL.urlPath -> base64 decode -> ByteArrayInputStream -> ObjectInputStream -> readObject\n\n这个刚好满足我们的要求，最终的解法就是：\nreadOjbect -> ... -> InvokerTransformer -> RMIConnector#connect() -> .. -> readObject -> 传统的 CC 链\n\nCHA的优点一是快，而是不存在漏报，但是这也是他的缺点，存在大量的误报，实际测试下来发现需要排除的东西还挺多，仍有不少工作量，还有很大的提升空间。后面将尝试利用污点分析对该任务的精度进行提升。\n\n## ezchain hfctf2022\n\n这是虎符CTF 2022年的一道题，当时bk和ty1310解出了这个题目。题目的环境见：https://github.com/waderwu/My-CTF-Challenges/tree/master/hfctf-2022/ezchain \n\n这也是道反序列化的题，只不过换成了Hessian反序列化，也是内网环境，无法外连。给了Rome第三方库，Marshalsec中包含了这个链，不过最后调用的是JdbcRowSetImpl ，利用JNDI完成攻击。由于无法外连，所以这条路被堵死了。熟悉反序列化的同学，应该能想到可不可以换成TemplatesImpl ， 经过调试之后发现也不行，因为Hessian在反序列化的时候不会调用readObject ，导致被transient 修饰的字段_tfactory一直为null，后续调用_tfactory.getExternalExtensionsMap()会触发空指针错误。\n\n所以已公开的东西都用不了了，需要重新找链，通过分析之后Rome链一直能用到调用任意无参数的getter函数，所以我们只要再重新找个getter函数即可。和上题差不多，危险函数可以是能够执行命令/代码或者能够造成二次反序列化。\n\n其实在上题中，我们已经找到了一个满足条件的getter函数，那就是\n\n```text\n<java.security.SignedObject: java.lang.Object getObject()>\n```\n\n利用这个然后可以造成二次反序列化，然后就可以使用ysoserial中的rome链了，这个解法是二血ty1310队伍提供的。\n\n只要将ctf-buggyLoader.dl中的入口函数限制改一下，就可以用到这个题上\n\n[example/ctf-ezchain.dl](../example/ctf-ezchain.dl)\n\n```dl\nEntryMethod(method),\nReachable(method, 0),\nNonParamPublicMethod(method, class) :- \n    MethodInfo(method, simplename, _, class, _, _, arity),\n    MethodModifier(\"public\", method),\n    // 方法名包含get\n    contains(\"get\", simplename),\n    // 无参数\n    arity = 0.\n    // hessian反序列化时不要求实现Serializable\n```\n\n如果按照这个版本的[cha.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/75a90a8baf9ebbcee573498d8077f61d2a8b338a/logic/cha.dl) 只能找到下面这个，这个我也已经验证可以用。payload我就不给了，大家可以参考UnixPrintServiceLookup进行构造。\n\n```text\n<com.sun.corba.se.impl.activation.ServerManagerImpl: int[] getActiveServers()>\n<com.sun.corba.se.impl.activation.ServerTableEntry: boolean isValid()>\n<com.sun.corba.se.impl.activation.ServerTableEntry: void activate()>\n<java.lang.Runtime: java.lang.Process exec(java.lang.String)>     \n```\n\n但是并没有找到预期解，这个UnixPrintServiceLookup这个类，这是因为在构造调用图时没有考虑一种间接调用，这种间接调用可以简化成这种\n\n```java\ncaller(){\n    AccessController.doPrivileged(new PrivilegedExceptionAction() {\n        public Object run() throws IOException {\n            callee();\n        }\n    }\n}\n```\n\n由于doPrivileged是native方法，无法进行后续的分析，这里就需要进行个特殊处理，认为caller可以直接调用这个run方法\n\n```dl\nCallGraph(insn, caller, callee) :- \n    Reachable(caller, n),\n    n < MAXSTEP,\n    StaticMethodInvocation(insn, _, method, caller),\n    MethodInfo(method, \"doPrivileged\", _, \"java.security.AccessController\", _, _, _),\n    ActualParam(0, insn, param),\n    VarType(param, type),\n    MethodInfo(callee, \"run\", _, type, _, _, 0).\n```\n\n改进之后的完整版本[cha.dl](../logic/cha.dl)\n\n然后当长度为设置4的时候就可以查到了\n\n![cha-ezchain-len-4-exec](images/cha-ezchain-len-4-exec.png)\n\n```dl\nMATCH p=(e:entry)-[*6]->(s:sink) where s.method contains \"exec\"  RETURN p\n```\n\n长度设置为6，在76880 nodes 1119478 relationships 的情况下就差不来了，不知道建立索引或者啥的会不会好一点\n"
  },
  {
    "path": "docs/cha-optimization.md",
    "content": "# cha-optimization\n\n本文代码对应的分支是 [cha-optimization](https://github.com/BytecodeDL/ByteCodeDL/tree/cha-optimization)\n\n## 实现&分析\n\n在实际测试中发现，如果路径过长会出现neo4j查询不出来的情况，还需要对CHA进行进一步优化。优化方向有两个：\n\n1. 尽可能减少节点的数量\n2. 尽可能减少环路的出现\n\n目前采取的遍历算法，有点类似于从entry出发，进行广度优先遍历(bfs)。实际的节点表现可能是这样的\n\n![callgraph-example](./images/callgraph-entry-bfs.png)\n\n从这张图可以看出，有用的节点其实是标有颜色的那些节点，其中绿色表示entry，红色表示sink。但是在导入的时候其他节点也会被导入。\n\n我们可以通过从sink向上回溯，筛选出那些能够到达sink的节点，就可以把这些有颜色的节点筛选出来。\n\n定义SinkReachable(method:Method, sink:Method, step:number) 表示 method 经过 step步能调用到 sink 。\n\n那么久可以根据CallGraph(insn, caller, callee) 一步步向上回溯了，具体规则见\n\n```dl\n// 初始化 sink 到 sink 为 0\nSinkReachable(sink, sink, 0) :-\n    SinkMethod(sink).\n\n// 如果caller 调用 了 callee\n// 且 callee n 步到 sink\n// 那么能够推导出 caller n+1 步 能到 sink\nSinkReachable(caller, sink, n+1) :-\n    n < MAXSTEP,\n    SinkReachable(callee, sink, n), \n    CallGraph(_, caller, callee).\n```\n\n更近一步我们还可以寻找从entry 到 sink 的最短路径\n\n定义 ShortestPathToSink(caller:Method, sink:Method, step:number) 表示caller 经过最短step步 到达 sink \n\n```dl\n// 筛选出entry 到 sink 的 最短长度 n\nShortestPathToSink(entry, sink, n) :- \n    n = min step : {SinkReachable(entry, sink, step)},\n    SinkMethod(sink),\n    EntryMethod(entry).\n\n// 如果caller 到 sink 最短距离 为 n\n// 且 calle 到 sink 的距离为n-1\n// 且 caller 调用 callee\n// 那么可以推导出 callee 到 sink 的 最短距离为 n-1\nShortestPathToSink(callee, sink, n-1) :-\n    n < MAXSTEP + 1,\n    ShortestPathToSink(caller, sink, n),\n    SinkReachable(callee, sink, n-1),\n    CallGraph(_, caller, callee).\n```\n\n这里稍微解释一下\n\n```dl\nShortestPathToSink(entry, sink, n) :-\n    n = min step : {SinkReachable(entry, sink, step)},\n    SinkMethod(sink),\n    EntryMethod(entry).\n```\n\n大概的执行顺序是\n\n1. 先从EntryMethod 选出一个 entry\n2. 从SinkMethod 选出一个 sink\n3. 然后从SinkReachable 找出第一个值为entry 第二个值为sink的数据，从这些数据中选出最小的step\n\n这种就找到entry到sink的最短距离为n\n\n## 使用方法\n\n通过宏定义 可以配置不同的优化级别\n\n1. `#define CHAO 1` 返回的是所有能到sink的节点\n2. `#define CHAO 2` 返回的是entry到sink最短路径上的节点\n3. 如果没有 CHAO 宏定义 则 返回的是entry在MAXSTEP之内能到达的所有节点\n\n使用样例\n\n[ctf-buggyLoader.dl](../example/ctf-buggyLoader.dl)\n\n```dl\n#define MAXSTEP 5\n#define CHAO 2\n\n#include \"inputDeclaration.dl\"\n#include \"utils.dl\"\n#include \"cha.dl\"\n\n\n.decl NonParamPublicMethod(method:Method, class:Class)\n.output NonParamPublicMethod\n\n// 声明sink\nSinkDesc(\"exec\", \"java.lang.Runtime\").\nSinkDesc(\"<init>\", \"java.lang.ProcessBuilder\").\nSinkDesc(\"start\", \"java.lang.ProcessImpl\").\nSinkDesc(\"loadClass\", \"java.lang.ClassLoader\").\nSinkDesc(\"defineClass\", \"java.lang.ClassLoader\").\nSinkDesc(\"readObject\", \"java.io.ObjectInputStream\").\nSinkDesc(\"readExternal\", \"java.io.ObjectInputStream\").\n\n// 声明入口方法\nEntryMethod(method),\nReachable(method, 0),\nNonParamPublicMethod(method, class) :- \n    MethodInfo(method, simplename, _, class, _, _, arity),\n    MethodModifier(\"public\", method),\n    simplename != \"<init>\",\n    arity = 0,\n    SubClass(class, \"java.io.Serializable\").\n\n.output SinkMethod\n```\n\n## 优化效果\n\n以ctf-buggyLoader为例\n\n1. 无 CHAO 宏定义\n   - Nodes: 68561\n   - Relations: 1080201\n   - Time 1:39.87 s\n2. `#define CHAO 1`\n   - Nodes: 3864\n   - Relations: 55736\n   - Time: 20.859 s\n3. `#define CHAO 2`\n   - Nodes: 722\n   - Relations: 3672\n   - Time: 20.134 s\n\n优化效果还行，之所以优化之后的时间更短，我猜测可能是IO更浪费时间，因为不优化的CallNode.csv 和 CallEdge.csv 都上百M了 。\n"
  },
  {
    "path": "docs/context-insensitive-points-to.md",
    "content": "# context-insensitive-points-to\n\n以防后续更新代码，导致与本文描述的有所冲突，建议切换到 [pt-noctx](https://github.com/BytecodeDL/ByteCodeDL/blob/pt-noctx/docs/context-insensitive-points-to.md) 分支进行阅读\n\n## 介绍\n\n本文主要介绍上下文无关指针分析，建议读本文档之前，先学习\n\n- https://pascal-group.bitbucket.io/lectures/PTA.pdf\n- https://pascal-group.bitbucket.io/lectures/PTA-FD.pdf\n- https://pascal-group.bitbucket.io/lectures/Datalog.pdf\n- https://souffle-lang.github.io/components\n\n最主要的是理解这个图\n![context-insensitive-pt](./images/context-insensitive-pt.png)\n\n指针分析主要是为了计算指针在运行过程中可能指向的对象，java中指针包括普通的变量，实例的字段，静态字段，以及数组元素等。由于Java多态的特性，不能仅根据声明类型解析函数调用，需要根据变量实际运行时的类型解析，通过指针分析可以得到变量在运行时指向的对象，进而可以得到对象的类型，然后根据类型即可解析出正确的被调函数，从而得到相对准确的函数调用图，准确的函数调用图对于过程间的分析至关重要，因此指针分析被视为Java静态分析的基础。\n\n对象的生成通过关键字new，然后通过指令，在指针之间传播对象信息，指令包括\n\n- new\n  - 生成对象\n- Assign\n  - 变量之间赋值\n- Store Instance Field\n  - 写入field 写入的其实是x对应的对象实例相应的字段\n- Load Instance Field\n  - 读取field 读取的其实是x对应的对象实例相应的字段\n- Call\n  - 首先根据x的指向对象的类型以及函数签名解析出具体函数m\n  - 设计到的传播关系有\n    - 实际传参数 到 形式参数\n    - 形式返回值 到 实际返回值\n    - base 到 this\n\n实现的时候还要考虑，类型转换(Cast)，读写静态字段(Static Field)，读写数组(Array)\n\n指针分析有很多影响因素，包括是否上下文敏感(Context-Sensitive)，是否流敏感(Flow-Sensitive)，是否字段敏感(Field-Sensitive)等，这些因素会影响指针分析的精度和效率。\n\n本次实现的是上下文不敏感，流不敏感，数组不敏感，字段敏感的指针分析。\n\n- 上下文不敏感\n  - 也就是对上下调用的上下文不敏感，也可以理解为没有调用的上下文\n- 流不敏感\n  - 指令的顺序不影响最终的分析结果，默认所有的分支都能走到\n- 数组不敏感\n  - 不区分数组中不同索引对应的值\n- 字段敏感\n  - 区分对象的不同字段\n\n## 实现\n\n[pt-noctx.dl](../logic/pt-noctx.dl) 主要就是将上图的规则用datalog表示。\n\n```dl\n// 建立一个Component，主要是为了解决命名冲突\n.comp ContextInsensitivePt{\n    // 表示 var 变量 指向 heap 这个对象\n    .decl VarPointsTo(heap:Heap, var:Var)\n    // 表示 baseHeap 这个对象的 field 指向 heap 这个对象\n    .decl InstanceFieldPointsTo(heap:Heap, baseHeap:Heap, field:Field)\n    // 表示 静态 field 指向 heap 这个对象\n    .decl StaticFieldPointsTo(heap:Heap, field:Field)\n    // 表示 baseHeap数组中，包含了heap对象\n    .decl ArrayIndexPointsTo(heap:Heap, baseHeap:Heap)\n    // 表示 在insn指令中 caller 调用了 callee\n    .decl CallGraph(insn:Insn, caller:Method, callee:Method)\n    // 表示 方法可访问到\n    .decl Reachable(method:Method)\n\n    // new\n    // 如果 method 方法可访问\n    // 且 在method中，将创建号的heap对象赋值给了var变量\n    // 那么能够推导出 var变量指向 heap 对象\n    VarPointsTo(heap, var) :-\n        Reachable(method),\n        AssignHeapAllocation(_, _, heap, var, method, _).\n    \n    // assign\n    // 如果method 方法可访问\n    // 且 form 变量 指向 heap 对象\n    // 且 在method中，将from变量赋值给了to 即 to=form\n    // 那么能够推到出 to变量也指向 heap 对象\n    VarPointsTo(heap, to) :- \n        Reachable(method),\n        VarPointsTo(heap, from),\n        AssignLocal(_, _, from, to, method).\n    \n    // cast\n    // 如果method 方法可访问\n    // 且 form 变量 指向 heap 对象\n    // 且 在method中，将from变量类型转换后赋值给了to 即 to=(T)from\n    // 那么能够推到出 to变量也指向 heap 对象\n    VarPointsTo(heap, to) :- \n        Reachable(method),\n        AssignCast(_, _, from, to, _, method),\n        VarPointsTo(heap, from).\n    \n    // load field\n    // 如果method 方法可访问\n    // 且 在method中，将base变量的field取出赋值给了to 也就是 to=base.field\n    // 且 base 指向 baseHeap 对象\n    // 且 baseHeap对象的field指向 heap 对象\n    // 那么能够推到出 to 也指向 heap 对象\n    VarPointsTo(heap, to) :-\n        Reachable(method),\n        LoadInstanceField(_, _, to, base, field, method),\n        VarPointsTo(baseHeap, base),\n        InstanceFieldPointsTo(heap, baseHeap, field).\n    \n    // store field\n    // 如果method 方法可访问\n    // 且 在method中，将from存到了变量base的field，也就是base.field=from\n    // 且 from 指向 heap 对象\n    // 且 base 指向 baseHeap 对象\n    // 那么 能够推到出baseHeap对象的field也指向 heap 对象\n    InstanceFieldPointsTo(heap, baseHeap, field) :-\n        Reachable(method),\n        StoreInstanceField(_, _, from, base, field, method),\n        VarPointsTo(heap, from),\n        VarPointsTo(baseHeap, base).\n    \n    // load staic field\n    // 如果method 方法可访问\n    // 且 在method中，将静态field取出赋值给了to 即 to = T.field\n    // 且 field 指向 heap 对象\n    // 那么可以推导出 to 也指向 heap 对象\n    VarPointsTo(heap, to) :-\n        Reachable(method),\n        LoadStaticField(_, _, to, field, method),\n        StaticFieldPointsTo(heap, field).\n    \n    // store static field\n    // 如果method 方法可访问\n    // 且在method中，将from存入静态field 即 T.field = from\n    // 且 from 指向 heap 对象\n    // 那么可以推到出 静态field指向 heap 对象\n    StaticFieldPointsTo(heap, field) :-\n        Reachable(method),\n        StoreStaticField(_, _, from, field, method),\n        VarPointsTo(heap, from).\n    \n    // load from array\n    // 如果method可访问\n    // 且 从base数组中取出元素到to to = base[i]\n    // 且 base 指向 baseHeap 数组对象\n    // 且 baseHeap 数组对象中 包含 heap 对象\n    // 那么 to 可能指向 heap \n    // 这里的实现未区分取第几个索引\n    VarPointsTo(heap, to) :-\n        Reachable(method),\n        LoadArrayIndex(_, _, to, base, method),\n        VarPointsTo(baseHeap, base),\n        ArrayIndexPointsTo(heap, baseHeap).\n\n    // store into array\n    // 如果method可访问\n    // 将 form 存到 base 数组中 即 base[i] = from\n    // from 指向 heap 对象 \n    // base 指向 baseHeap 数组对象\n    // 那么能推导出 baseHeap 数组对象 包含 heap 对象\n    ArrayIndexPointsTo(heap, baseHeap) :-\n        Reachable(method),\n        StoreArrayIndex(_, _, from, base, method),\n        VarPointsTo(heap, from),\n        VarPointsTo(baseHeap, base).\n    \n    // 下面开始涉及到过程间的指针分析\n    // 先构造调用图\n    // Special 和 Static 和 CHA 处理方式一样，编译时callee就确定，不需要再进行解析\n    Reachable(callee),\n    CallGraph(insn, caller, callee) :- \n        Reachable(caller),\n        SpecialMethodInvocation(insn, _, callee, _, caller).\n    \n    Reachable(callee),\n    CallGraph(insn, caller, callee) :- \n        Reachable(caller),\n        StaticMethodInvocation(insn, _, callee, caller).\n    \n    // Virtual Call 需要根据 base 指向 对象 的类型 进行 dispatch\n    // caller 要可达\n    // 在caller 中 virtual call 了 method\n    // 调用时 base 指向 baseHeap 对象\n    // baseHeap 对象的类型 为 class\n    // 根据method 解析出 被调函数的签名\n    // 通过 函数签名 和 实际类型 解析出真正的被调函数callee\n    Reachable(callee),\n    CallGraph(insn, caller, callee) :- \n        Reachable(caller),\n        VirtualMethodInvocation(insn, _, method, base, caller),\n        VarPointsTo(baseHeap, base),\n        NormalHeap(baseHeap, class),\n        MethodInfo(method, simplename, _, _, _, descriptor, _),\n        Dispatch(simplename, descriptor, class, callee).\n    \n    // param\n    // 调用图中存在调用 insn\n    // 调用时第n个实际参数传的是 变量 arg\n    // 被调函数 callee 的 第 n 个 形式参数是 param\n    // 如果 arg 指向了heap 对象\n    // 那么 param 也指向heap 对象\n    VarPointsTo(heap, param) :- \n        CallGraph(insn, _, callee),\n        ActualParam(n, insn, arg),\n        FormalParam(n, callee, param),\n        VarPointsTo(heap, arg).\n    \n    // return\n    // 调用图中存在调用 insn\n    // 如果 在callee中，返回语句返回的是var变量\n    // 调用后的返回值赋值给了return变量\n    // var 变量 指向 heap 对象\n    // 那么 return 也指向 heap 对象\n    VarPointsTo(heap, return) :- \n        CallGraph(insn, _, callee),\n        Return(_, _, var, callee),\n        AssignReturnValue(insn, return),\n        VarPointsTo(heap, var).\n    \n    // this\n    // 调用图中存在调用 insn\n    // 调用时 base 指向 heap\n    // 那么调用时callee 的 this 变量 也指向 heap 对象\n    VarPointsTo(heap, this) :- \n        CallGraph(insn, _, callee),\n        (\n            VirtualMethodInvocation(insn, _, _, base, _);\n            SpecialMethodInvocation(insn, _, _, base, _)\n        ),\n        ThisVar(callee, this),\n        VarPointsTo(heap, base).\n}\n```\n\n## 使用样例\n\n[pt-noctx-example-1.dl](../example/pt-noctx-example-1.dl)\n\n```dl\n#include \"inputDeclaration.dl\"\n#include \"utils.dl\"\n#include \"pt-noctx.dl\"\n\n// 实例化 component\n.init cipt = ContextInsensitivePt\n\n// 初始化readchable\ncipt.Reachable(method) :-\n    MethodInfo(method, simplename, _, _, _, descriptor, _),\n    simplename = \"main\",\n    descriptor = \"([Ljava/lang/String;)V\".\n\n.output cipt.VarPointsTo\n```\n\n创建benchmark facts\n\n```bash\n java8 -jar soot-fact-generator/build/libs/soot-fact-generator.jar -i Benchmark-1.0-SNAPSHOT.jar --full -l /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/rt.jar -d pttest --allow-phantom --generate-jimple --facts-subset APP\n```\n\n然后执行\n\n```bash\nsouffle -F factsdir -D ByteCodeDL/output ByteCodeDL/example/pt-noctx-example-1.dl\n```\n\n分析结果保存在 output/cipt.VarPointsTo\n\n如果想学习更完善的指针分析，可以看一下这两个repo\n\n- https://github.com/souffle-lang/java-pts\n- https://bitbucket.org/yanniss/doop/src\n\n搞学术的可以去看看doop\n"
  },
  {
    "path": "docs/ptaint.md",
    "content": "# ptaint\n\n## Introduction\n\n主要是根据ptaint这篇论文的思想，将指针分析和污点分析统一起来进行分析，建议先学习下面三份资料\n\n- https://yanniss.github.io/ptaint-oopsla17-prelim.pdf\n  - https://www.youtube.com/watch?v=IA08d-kiCy8\n- https://pascal-group.bitbucket.io/lectures/Security.pdf\n\n污点分析：which sources can reach which sinks\n\n指针分析：which object sources can reach which variables\n\n指针分析是计算指针在运行过程中可能指向哪些对象，也可以理解为创建之后的对象，会传播到哪些指针。\n\n```java\nA a = new A(\"foo\"); // object created\nif (*)\n   aa = a;          // flows locally\nB b = foo(a);       // flows in/out via stack\nb.parent = a;       // stored/loaded on heap\n```\n\n污点分析是计算sink函数的参数是否是污点，也可以理解为污点源会传播到哪些指针\n\n```java\nString a = source.readLine(); // taint source\nif (*)\n   aa = a;          // flows locally\nB b = foo(a);       // flows in/out via stack\nb.parent = a;       // stored/loaded on heap\n```\n\n两者可以统一成，值在指针之间的传播，也就是在PFG(Pointer Flow Graph)中传播\n\n污点分析和指针分析还多了一些东西，比如污点转移，以及污点消除(净化函数)\n\n```java\nString a = source.readLine(); // taint source\nif (*)\n   aa = a;          // flows locally\nB b = foo(a);       // flows in/out via stack\nb.parent = a;       // stored/loaded on heap\n\nbyte[] aAsbytes = a.getBytes(); // transfer\n\nString aSafe = URLEncoder.encode(a, \"UTF-8\"); // sanitize\n```\n\nPtaint论文中将污点视为独立的对象，而不是给传统的对象打上污点标记，会创建新的污点对象，和传统的对象分开各自独立沿着相同的PFG传播\n\n\n\n按照论文中的给的示例规则得到的实现\n\n[ptaint.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/ptaint/logic/ptaint.dl) \n\n```dl\n.comp PTaint{\n    // 指针分析原有的relation\n    .decl VarPointsTo(heap:Heap, var:Var)\n    .decl InstanceFieldPointsTo(heap:Heap, baseHeap:Heap, field:Field)\n    .decl CallGraph(insn:Insn, caller:Method, callee:Method)\n    .decl Reachable(method:Method)\n    .decl InterProcAssign(from:Var, to:Var)\n\t\t\n\t\t// 污点分析相关的新relation\n\t\t// 表示通过insn指令，创建的新的污点对象heap，包括污点源的生成，以及污点转移时的生成\n    .decl TaintHeap(insn:Insn, heap:Heap)\n    // 表示调用指令insn发生时，危险函数的参数指向了污点对象heap\n    .decl Leak(insn:Insn, heap:Heap)\n    // 表示source函数，其返回值表示污点源\n    .decl SourceMethod(method:Method)\n    // 表示sink函数，其第n个实际参数如果指向污点对象，则表示可能存在安全风险\n    .decl SinkMethod(method:Method, n:number)\n\t\t// 表示sanitize函数，经过其处理的污点，将不再是污点，也就是说污点无法通过sanitize传播，是在实际参数向形式参数传播时阻断的\n    .decl SanitizeMethod(method:Method)\n    // 表示sanitize函数的形式参数\n    .decl SanitizeMethodParam(var:Var)\n\t\t// 筛选出sanitize函数的形式参数\n    SanitizeMethodParam(var) :-\n        FormalParam(_, method, var),\n        SanitizeMethod(method).\n\t\t\n\t\t// 污点转移相关的\n\t\t// base 是 污点 返回值也是污点\n    .decl BaseToRetTransfer(method:Method)\n    // 参数是污点返回也是污点\n    .decl ArgToRetTransfer(method:Method, n:number)\n    // 将上面两个合并成一个，或者将污点转移抽象成from变量污染了to变量\n    .decl IsTaintedFrom(insn:Insn, from:Var, to:Var)\n    // heap 对象 污染了 newHeap对象\n    .decl TransferTaint(heap:Heap, newHeap:Heap)\n    \n\n    // new\n    VarPointsTo(heap, var) :-\n        Reachable(method),\n        AssignHeapAllocation(_, _, heap, var, method, _).\n    \n    // assign\n    VarPointsTo(heap, to) :- \n        Reachable(method),\n        VarPointsTo(heap, from),\n        AssignLocal(_, _, from, to, method).\n    \n    // load field\n    VarPointsTo(heap, to) :-\n        Reachable(method),\n        LoadInstanceField(_, _, to, base, field, method),\n        VarPointsTo(baseHeap, base),\n        InstanceFieldPointsTo(heap, baseHeap, field).\n    \n    // store field\n    InstanceFieldPointsTo(heap, baseHeap, field) :-\n        Reachable(method),\n        StoreInstanceField(_, _, from, base, field, method),\n        VarPointsTo(heap, from),\n        VarPointsTo(baseHeap, base).\n    \n    // virtual call\n    Reachable(callee),\n    CallGraph(insn, caller, callee) :- \n        Reachable(caller),\n        VirtualMethodInvocation(insn, _, method, base, caller),\n        VarPointsTo(baseHeap, base),\n        NormalHeap(baseHeap, class),\n        MethodInfo(method, simplename, _, _, _, descriptor, _),\n        Dispatch(simplename, descriptor, class, callee).\n    \n    // arg -> param\n    InterProcAssign(arg, param) :-\n        CallGraph(insn, _, callee),\n        ActualParam(n, insn, arg),\n        FormalParam(n, callee, param).\n    \n    // var -> return\n    InterProcAssign(var, return) :-\n        CallGraph(insn, _, callee),\n        Return(_, _, var, callee),\n        AssignReturnValue(insn, return).\n\n    // normal heap\n    // 正常对象正常传播\n    VarPointsTo(heap, to) :- \n        InterProcAssign(from, to),\n        VarPointsTo(heap, from),\n        // 比起指针分析多了个这个限制，用于限制heap为正常对象\n        NormalHeap(heap, _).\n    \n    // taint heap\n    // 阻断污点对象传播到净化函数的形式参数\n    VarPointsTo(heap, to) :- \n        InterProcAssign(from, to),\n        VarPointsTo(heap, from),\n        TaintHeap(_, heap),\n        !SanitizeMethodParam(to).\n    \n    // this\n    VarPointsTo(heap, this) :-\n        CallGraph(insn, _, callee),\n        VirtualMethodInvocation(insn, _, _, base, _),\n        VarPointsTo(heap, base),\n        ThisVar(callee, this).\n    \n    // 污点对象的生成\n    TaintHeap(insn, heap),\n    VarPointsTo(heap, to) :-\n        SourceMethod(callee),\n        CallGraph(insn, _, callee),\n        AssignReturnValue(insn, to),\n        heap = cat(\"NewTainted::\", insn).\n    \n    // 判断sink函数的参数是否指向污点对象\n    Leak(insn, heap) :-\n        CallGraph(insn, _, callee),\n        SinkMethod(callee, n),\n        ActualParam(n, insn, arg),\n        VarPointsTo(heap, arg),\n        TaintHeap(_, heap).\n\t\t\n\t\t// base -> ret\n    IsTaintedFrom(insn, base, ret) :-\n        CallGraph(insn, _, callee),\n        BaseToRetTransfer(callee),\n        VirtualMethodInvocation(insn, _, _, base, _),\n        AssignReturnValue(insn, ret).\n    // arg -> ret\n    IsTaintedFrom(insn, arg, ret) :-\n        CallGraph(insn, _, callee),\n        ArgToRetTransfer(callee, n),\n        ActualParam(n, insn, arg),\n        AssignReturnValue(insn, ret).\n\t\t\n\t\t// 污点转移\n\t\t// from 指向了污点对象heap\n\t\t// 且from能污染to\n\t\t// 那么to也是污点对象，也要指向一个污点对象\n\t\t// 这里没有直接让to指向新创建的污点对象\n\t\t// 而是先找到to指向的正常对象oldHeap，oldHeap第一个流向的指针var，然后让newHeap也流向指针var，即var指向newHeap\n\t\t// 由于oldHeap流向var之后，通过PFG可以流到to，那么newHeap也能流到to，这样也把和var alias的指针一并污染了\n    TaintHeap(insn, newHeap),\n    TransferTaint(heap, newHeap),\n    VarPointsTo(newHeap, var) :- \n        IsTaintedFrom(insn, from, to),\n        VarPointsTo(heap, from),\n        TaintHeap(_, heap),\n        newHeap = cat(\"TransferTaint::\", insn),\n        VarPointsTo(oldHeap, to),\n        AssignHeapAllocation(_, _, oldHeap, var, _, _).\n}\n```\n\n[ptaint-example-1.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/ptaint/example/ptaint-example-1.dl)\n\n```\n#include \"inputDeclaration.dl\"\n#include \"utils.dl\"\n#include \"ptaint.dl\"\n\n.init ptaint = PTaint\n\nptaint.Reachable(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void main(java.lang.String[])>\").\n\nptaint.SourceMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Source()>\").\nptaint.SinkMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void Sink(java.lang.String)>\", 0).\n\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\").\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.String toString()>\").\n\nptaint.ArgToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\", 0).\n\nptaint.SanitizeMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Sanitize(java.lang.String)>\").\n\n\n.decl TaintVar(var:Var)\n\nTaintVar(var) :-\n    ptaint.VarPointsTo(heap, var),\n    ptaint.TaintHeap(_, heap).\n\n.output TaintVar\n\n.output ptaint.TaintHeap\n.output ptaint.TransferTaint\n.output ptaint.VarPointsTo\n```\n\n可以看到大部分的规则都是和指针分析一样的，那么我能不能利用之前实现的[pt-noctx.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/pt-noctx/logic/pt-noctx.dl)呢？答案是可以的，但是有一处要稍微改一下就是\n\n```\n// param\nVarPointsTo(heap, param) :- \n    CallGraph(insn, _, callee),\n    ActualParam(n, insn, arg),\n    FormalParam(n, callee, param),\n    VarPointsTo(heap, arg),\n    // 在实际参数向形式参数传播的时候，正常的对象可以任意传播，污点对象还需要考虑被sanitize阻断的问题\n    NormalHeap(heap, _).\n```\n\n更改后的[pt-noctx.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/ptaint-upgrade/logic/pt-noctx.dl)\n\n更新后的[ptaint.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/ptaint-upgrade/logic/ptaint.dl)\n\n```dl\n#include \"pt-noctx.dl\"\n\n.comp PTaint{\n\t\t// 实例上下文无关指针分析\n    .init cipt = ContextInsensitivePt\n\t\t\n\t\t// 定义污点分析相关的\n    .decl TaintHeap(insn:Insn, heap:Heap)\n    .decl SourceMethod(method:Method)\n    .decl SinkMethod(method:Method, n:number)\n\n    .decl SanitizeMethod(method:Method)\n\n    .decl BaseToRetTransfer(method:Method)\n    .decl ArgToRetTransfer(method:Method, n:number)\n    .decl IsTaintedFrom(insn:Insn, from:Var, to:Var)\n    .decl TransferTaint(heap:Heap, newHeap:Heap)\n    \n    // 阻止污点对象传播到sanitize函数的形式参数\n    // taint arg to param\n    cipt.VarPointsTo(heap, param) :- \n        cipt.CallGraph(insn, _, callee),\n        ActualParam(n, insn, arg),\n        FormalParam(n, callee, param),\n        cipt.VarPointsTo(heap, arg),\n        TaintHeap(_, heap),\n        !SanitizeMethod(callee).\n    \n    \n    TaintHeap(insn, heap),\n    cipt.VarPointsTo(heap, to) :-\n        SourceMethod(callee),\n        cipt.CallGraph(insn, _, callee),\n        AssignReturnValue(insn, to),\n        heap = cat(\"NewTainted::\", insn).\n\n    IsTaintedFrom(insn, base, ret) :-\n        cipt.CallGraph(insn, _, callee),\n        BaseToRetTransfer(callee),\n        VirtualMethodInvocation(insn, _, _, base, _),\n        AssignReturnValue(insn, ret).\n    \n    IsTaintedFrom(insn, arg, ret) :-\n        cipt.CallGraph(insn, _, callee),\n        ArgToRetTransfer(callee, n),\n        ActualParam(n, insn, arg),\n        AssignReturnValue(insn, ret).\n\n    TaintHeap(insn, newHeap),\n    TransferTaint(heap, newHeap),\n    cipt.VarPointsTo(newHeap, var) :- \n        IsTaintedFrom(insn, from, to),\n        cipt.VarPointsTo(heap, from),\n        TaintHeap(_, heap),\n        newHeap = cat(\"TransferTaint::\", insn),\n        cipt.VarPointsTo(oldHeap, to),\n        AssignHeapAllocation(_, _, oldHeap, var, _, _).\n}\n```\n\n\n\n## Example 1\n\n我们先分析Benchmark中的[TaintDemo3](https://github.com/BytecodeDL/Benchmark/blob/main/src/main/java/com/bytecodedl/benchmark/demo/TaintDemo3.java)\n\n```java\npublic class TaintDemo3 {\n    public static void main(String[] args) {\n        TaintDemo3 demo = new TaintDemo3();\n        String name = demo.Source();\n        demo.test1(name);\n    }\n\n    public void test1(String name){\n        String sql0= \"select * from user where name='\" + name + \"'\";\n        String sql1 = sql0;\n        String sql = Sanitize(sql1);\n        Sink(sql);\n    }\n\n    public void Sink(String param){\n\n    }\n\n    public String Sanitize(String param){\n        String ret = param.replace('\\'', '`');\n        return ret;\n    }\n\n    public String Source(){\n        return \"tainted name\";\n    }\n}\n```\n\n执行\n\n```bash\n// 代码下载到本地\ngit clone git@github.com:BytecodeDL/Benchmark.git\n// 打包\nmvn clean package\n// 切换目录\ncd target\n// 生成facts\njava8 -jar ~/code/soot-fact-generator/build/libs/soot-fact-generator.jar -i Benchmark-1.0-SNAPSHOT.jar --full -l /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/rt.jar -d tainttest --allow-phantom --generate-jimple\n// 切换目录\ncd tainttest\n// 执行souffle\nsouffle -F . -D output ~/code/ByteCodeDL/example/ptaint-example-1.dl\n```\n\n然后在ouput目录能够看到`grep \"Demo3\" TaintVar.csv`结果\n\n```\n<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>/@parameter0\n<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>/$stack5\n<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>/$stack6\n<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>/$stack7\n<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>/$stack8\n<com.bytecodedl.benchmark.demo.TaintDemo3: void main(java.lang.String[])>/name#_6\n<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>/name#_0\n<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>/sql1#_12\n<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>/sql0#_11\n```\n\n可以看到sql1和sql0都是污点，sql不是污点，比较符合我们的预期。\n\n下面介绍如何编写出[ptaint-example-1.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/ptaint-upgrade/example/ptaint-example-1.dl)\n\n首先要实例化Ptaint 并 初始化污点分析的起始方法，在这里起始方法，也就是分析的入口，为TaintDemo3的main函数\n\n```\n// 实例化ptaint\n.init ptaint = PTaint\n\n// 初始化上下文无关文法的入口函数\nptaint.cipt.Reachable(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void main(java.lang.String[])>\").\n```\n\n然后定义Source，Sink和Sanitize函数\n\n```\n// 定义source函数\nptaint.SourceMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Source()>\").\n// 定义危险函数\nptaint.SinkMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void Sink(java.lang.String)>\", 0).\n// 定义净化函数\nptaint.SanitizeMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Sanitize(java.lang.String)>\").\n```\n\n接下来就是定义污点转移函数了，这时候只看java代码看不出来东西，这时候需要看soot生成的jimple代码，也就是下面的代码\n\n```jimple\n public void test1(java.lang.String)\n    {\n        java.lang.StringBuilder $stack5, $stack6, $stack7, $stack8;\n        java.lang.String name#_0, sql0#_11, sql1#_12, sql#_13;\n        com.bytecodedl.benchmark.demo.TaintDemo3 this#_0;\n\n        this#_0 := @this: com.bytecodedl.benchmark.demo.TaintDemo3;\n\n        name#_0 := @parameter0: java.lang.String;\n\n        $stack5 = new java.lang.StringBuilder;\n\n        specialinvoke $stack5.<java.lang.StringBuilder: void <init>()>();\n\n        $stack6 = virtualinvoke $stack5.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(\"select * from user where name=\\'\");\n\n        $stack7 = virtualinvoke $stack6.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(name#_0);\n\n        $stack8 = virtualinvoke $stack7.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(\"\\'\");\n\n        sql0#_11 = virtualinvoke $stack8.<java.lang.StringBuilder: java.lang.String toString()>();\n\n        sql1#_12 = sql0#_11;\n\n        sql#_13 = virtualinvoke this#_0.<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Sanitize(java.lang.String)>(sql1#_12);\n\n        virtualinvoke this#_0.<com.bytecodedl.benchmark.demo.TaintDemo3: void Sink(java.lang.String)>(sql#_13);\n\n        return;\n    }\n```\n\n也就是将字符串的拼接分成了下面几步\n\n```\n\n$stack5 = new java.lang.StringBuilder;\n\nspecialinvoke $stack5.<java.lang.StringBuilder: void <init>()>();\n\n$stack6 = virtualinvoke $stack5.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(\"select * from user where name=\\'\");\n\n$stack7 = virtualinvoke $stack6.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(name#_0);\n\n$stack8 = virtualinvoke $stack7.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(\"\\'\");\n\nsql0#_11 = virtualinvoke $stack8.<java.lang.StringBuilder: java.lang.String toString()>();\n```\n\n转换成java就是\n\n```\n$stack5 = new StringBuilder();\n$stack6 = $stack5.append(\"select * from user where name=\\'\");\n$stack7 = $stack6.append(name#_0);\n$stack8 = $stack7.append(\"\\'\");\n$sql0#_11 = $stack8.toString();\n```\n\nname#_0 是污点变量，由于`$stack7 = $stack6.append(name#_0);` ，我门希望`$stack7`也是污点变量，所以这里应该添加个arg 向 ret的转移。\n\n```\nptaint.ArgToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\", 0).\n```\n\n由于`$stack7`是污点变量，由于`$stack8 = $stack7.append(\"\\'\");` ，我们希望`$stack8`也是污点变量，所以这里应该添加个base 向 ret的转移。\n\n```\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\").\n```\n\n由于`$stack8`是污点变量，由于`$sql0#_11 = $stack8.toString();`，我们希望`$sql0#_11`也是污点变量，所以这里应该添加个base 向ret的转移。\n\n```\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.String toString()>\").\n```\n\n全部规则如下： [ptaint-example-1.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/ptaint-upgrade/example/ptaint-example-1.dl)\n\n```\n#include \"inputDeclaration.dl\"\n#include \"utils.dl\"\n#include \"ptaint.dl\"\n\n// 实例化ptaint\n.init ptaint = PTaint\n\n// 初始化上下文无关文法的入口函数\nptaint.cipt.Reachable(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void main(java.lang.String[])>\").\n\n// 定义source函数\nptaint.SourceMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Source()>\").\n// 定义危险函数\nptaint.SinkMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void Sink(java.lang.String)>\", 0).\n// 定义净化函数\nptaint.SanitizeMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Sanitize(java.lang.String)>\").\n\n// 定义污点转移函数\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\").\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.String toString()>\").\n\nptaint.ArgToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\", 0).\n\n\n\n\n.decl TaintVar(var:Var)\n\nTaintVar(var) :-\n    ptaint.cipt.VarPointsTo(heap, var),\n    ptaint.TaintHeap(_, heap).\n\n.output TaintVar\n\n.output ptaint.TaintHeap\n.output ptaint.TransferTaint\n.output ptaint.cipt.VarPointsTo\n```\n\n但是在分析[TaintDemo2](https://github.com/BytecodeDL/Benchmark/blob/main/src/main/java/com/bytecodedl/benchmark/demo/TaintDemo2.java)的时候，就会发现遇到问题了\n\n```java\npublic class TaintDemo2 {\n    public static void main(String[] args) {\n        TaintDemo2 demo = new TaintDemo2();\n        String name = demo.Source();\n        demo.test1(name);\n    }\n\n    public void test1(String name){\n        String sql = \"select * from user where name='\" + name + \"'\";\n        sql = Sanitize(sql);\n        Sink(sql);\n    }\n\n    public void Sink(String param){\n\n    }\n\n    public String Sanitize(String param){\n        String ret = param.replace('\\'', '`');\n        return ret;\n    }\n\n    public String Source(){\n        return \"tainted name\";\n    }\n}\n```\n\n对应的jimple为\n\n```\npublic void test1(java.lang.String)\n    {\n        java.lang.StringBuilder $stack3, $stack4, $stack5, $stack6;\n        java.lang.String name#_0, sql#_11;\n        com.bytecodedl.benchmark.demo.TaintDemo2 this#_0;\n\n        this#_0 := @this: com.bytecodedl.benchmark.demo.TaintDemo2;\n\n        name#_0 := @parameter0: java.lang.String;\n\n        $stack3 = new java.lang.StringBuilder;\n\n        specialinvoke $stack3.<java.lang.StringBuilder: void <init>()>();\n\n        $stack4 = virtualinvoke $stack3.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(\"select * from user where name=\\'\");\n\n        $stack5 = virtualinvoke $stack4.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(name#_0);\n\n        $stack6 = virtualinvoke $stack5.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(\"\\'\");\n\n        sql#_11 = virtualinvoke $stack6.<java.lang.StringBuilder: java.lang.String toString()>();\n\n        sql#_11 = virtualinvoke this#_0.<com.bytecodedl.benchmark.demo.TaintDemo2: java.lang.String Sanitize(java.lang.String)>(sql#_11);\n\n        virtualinvoke this#_0.<com.bytecodedl.benchmark.demo.TaintDemo2: void Sink(java.lang.String)>(sql#_11);\n\n        return;\n    }\n```\n\n将ptaint-example-1.dl中的TaintDemo3换成TaintDemo2之后后\n\n```\n<com.bytecodedl.benchmark.demo.TaintDemo2: void test1(java.lang.String)>/@parameter0\n<com.bytecodedl.benchmark.demo.TaintDemo2: void Sink(java.lang.String)>/@parameter0\n<com.bytecodedl.benchmark.demo.TaintDemo2: java.lang.String Sanitize(java.lang.String)>/ret#_21\n<com.bytecodedl.benchmark.demo.TaintDemo2: void test1(java.lang.String)>/$stack3\n<com.bytecodedl.benchmark.demo.TaintDemo2: void test1(java.lang.String)>/$stack4\n<com.bytecodedl.benchmark.demo.TaintDemo2: void test1(java.lang.String)>/$stack5\n<com.bytecodedl.benchmark.demo.TaintDemo2: void test1(java.lang.String)>/$stack6\n<com.bytecodedl.benchmark.demo.TaintDemo2: void main(java.lang.String[])>/name#_6\n<com.bytecodedl.benchmark.demo.TaintDemo2: void test1(java.lang.String)>/name#_0\n<com.bytecodedl.benchmark.demo.TaintDemo2: void test1(java.lang.String)>/sql#_11\n<com.bytecodedl.benchmark.demo.TaintDemo2: void Sink(java.lang.String)>/param#_0\n```\n\n会发现`sql#_11` 虽然经过了Sanitize处理，但是还是被标记为了污点变量，这是为什么呢？这是因为目前的分析都是流不敏感的，有没有什么办法解决呢？有在创建facts时加上`--ssa`参数\n\n```\njava8 -jar ~/code/soot-fact-generator/build/libs/soot-fact-generator.jar -i Benchmark-1.0-SNAPSHOT.jar --full -l /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/rt.jar -d tainttest --allow-phantom --generate-jimple --ssa\n```\n\n加上这个参数之后会生成shimple，保证每个变量只会被赋值一次，就会变成下面这样\n\n```shimple\npublic void test1(java.lang.String)\n    {\n        java.lang.StringBuilder $stack3, $stack4, $stack5, $stack6;\n        java.lang.String name#_0, sql#_11, sql_$$A_1#_12;\n        com.bytecodedl.benchmark.demo.TaintDemo2 this#_0;\n\n        this#_0 := @this: com.bytecodedl.benchmark.demo.TaintDemo2;\n\n        name#_0 := @parameter0: java.lang.String;\n\n        $stack3 = new java.lang.StringBuilder;\n\n        specialinvoke $stack3.<java.lang.StringBuilder: void <init>()>();\n\n        $stack4 = virtualinvoke $stack3.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(\"select * from user where name=\\'\");\n\n        $stack5 = virtualinvoke $stack4.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(name#_0);\n\n        $stack6 = virtualinvoke $stack5.<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>(\"\\'\");\n\n        sql#_11 = virtualinvoke $stack6.<java.lang.StringBuilder: java.lang.String toString()>();\n\n        sql_$$A_1#_12 = virtualinvoke this#_0.<com.bytecodedl.benchmark.demo.TaintDemo2: java.lang.String Sanitize(java.lang.String)>(sql#_11);\n\n        virtualinvoke this#_0.<com.bytecodedl.benchmark.demo.TaintDemo2: void Sink(java.lang.String)>(sql_$$A_1#_12);\n\n        return;\n    }\n```\n\n原本Sanitize返回的也是`sql#_11` 现在变成了`sql_$$A_1#_12`，这样就能区分原本两个同名变量在不同时刻的值了。\n\n## Example 2\n\n在实际的场景中，比如spring开发框架下，污点源不是来自source函数的返回值，可能来自函数的参数，这种情况该怎么处理呢？\n\n我们还以TaintDemo3为例，我们以test1方法为分析的起点，形式参数name作为污点源。这时候我们需要模拟创建对象，包括test1@this 以及name参数\n\n```\n.decl EntryMethod(method:Method)\n\nEntryMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>\").\n\n\nptaint.cipt.Reachable(method) :-\n    EntryMethod(method).\n\nNormalHeap(heap, class),\nptaint.cipt.VarPointsTo(heap, this) :-\n    ThisVar(method, this),\n    EntryMethod(method),\n    VarType(this, class),\n    heap = cat(\"Mock::\", class).\n\nNormalHeap(heap, class),\nptaint.TaintHeap(insn, taintHeap),\nptaint.cipt.VarPointsTo(heap, param),\nptaint.cipt.VarPointsTo(taintHeap, param) :- \n    EntryMethod(method),\n    FormalParam(_, method, param),\n    VarType(param, class),\n    heap = cat(\"Mock::\", class),\n    taintHeap = cat(\"NewTainted::\", class),\n    insn = \"Init::Param\".\n```\n\n其他部分同ptaint-example-1.dl，完整见[ptaint-example-2.dl](https://github.com/BytecodeDL/ByteCodeDL/blob/ptaint-upgrade/example/ptaint-example-2.dl)\n\n```\n#include \"inputDeclaration.dl\"\n#include \"utils.dl\"\n#include \"ptaint.dl\"\n\n.init ptaint = PTaint\n\n// 定义入口函数\n.decl EntryMethod(method:Method)\n\nEntryMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>\").\n\n// 初始化指针分析入口函数\nptaint.cipt.Reachable(method) :-\n    EntryMethod(method).\n\n// test1@this 指向虚拟创建的对象\nNormalHeap(heap, class),\nptaint.cipt.VarPointsTo(heap, this) :-\n    ThisVar(method, this),\n    EntryMethod(method),\n    VarType(this, class),\n    heap = cat(\"Mock::\", class).\n\n// test1的参数，指向虚拟创建的污点对象和正常对象\nNormalHeap(heap, class),\nptaint.TaintHeap(insn, taintHeap),\nptaint.cipt.VarPointsTo(heap, param),\nptaint.cipt.VarPointsTo(taintHeap, param) :- \n    EntryMethod(method),\n    FormalParam(_, method, param),\n    VarType(param, class),\n    heap = cat(\"Mock::\", class),\n    taintHeap = cat(\"NewTainted::\", class),\n    insn = \"Init::Param\".\n\n\nptaint.SourceMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Source()>\").\nptaint.SinkMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void Sink(java.lang.String)>\", 0).\n\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\").\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.String toString()>\").\n\nptaint.ArgToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\", 0).\n\nptaint.SanitizeMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Sanitize(java.lang.String)>\").\n\n\n.decl TaintVar(var:Var)\n\nTaintVar(var) :-\n    ptaint.cipt.VarPointsTo(heap, var),\n    ptaint.TaintHeap(_, heap).\n\n.output TaintVar\n\n.output ptaint.TaintHeap\n.output ptaint.TransferTaint\n.output ptaint.cipt.VarPointsTo\n```\n\n"
  },
  {
    "path": "docs/query.md",
    "content": "# query\n\n有了前面的铺垫，到这节，我们就可以通过ByteCodeDL ，快速筛选出一些class和method。\n\n## 案例一\n\n比如这位群友的需求\n> 有没有啥东西，可以自动找jvm里符合某些要求的类\n\n> 比如 我只想找有两个构造参数的类，其中一个传入的还得是数组参数\n\n> 就这样找，有啥现成的工具么\n\n前置知识，构造函数在jimple中的simplename为`<init>`，souffle中提供了一些[字符串相关的函数](https://souffle-lang.github.io/constraints)，如contains，match等\n\n有了前置知识之后，我们可以将上述的问题翻译成下面的三个条件：\n\n1. 方法是构造函数，simplename=`<init>`\n2. 构造函数有两个构造参数, arity=2\n3. 其中一个构造函数的的参数是数组，contains(`[]`, param)\n\n将上述的条件，翻译成datalog如下\n`query-example1.dl`\n```\n#include \"inputDeclaration.dl\"\n\n.decl QueryResult(class:Class, method:Method)\n.output QueryResult\n\nQueryResult(class, method) :- \n    MethodInfo(method, simplename, param, class, _, _, arity),\n    simplename = \"<init>\",\n    contains(\"[]\", param),\n    arity = 2.\n```\n然后执行`souffle -F facts-dir -D output-dir query-example1.dl -j 8` 需要用soot-fact-generator.jar对要分析的jar提前创建好facts，可参考 https://github.com/BytecodeDL/soot-fact-generator\n\n结果示例\n\n```\njava.math.BigInteger    <java.math.BigInteger: void <init>(int,byte[])>\njava.math.BigInteger    <java.math.BigInteger: void <init>(int,int[])>\njava.math.BigInteger    <java.math.BigInteger: void <init>(int[],int)>\njava.math.BigInteger    <java.math.BigInteger: void <init>(byte[],int)>\n```\n\n## 案例二\n\n待补充"
  },
  {
    "path": "docs/readme.md",
    "content": "# ByteCodeDL\n\n基本需要两部分知识，一部分是程序分析另外一部分是datalog编程。对于程序分析部分的知识，强烈推荐去学习南大的程序分析课程，[视频链接](https://space.bilibili.com/2919428/channel/seriesdetail?sid=1006553) [课程主页](https://pascal-group.bitbucket.io/teaching.html)，datalog编程可以通过[souffle](https://souffle-lang.github.io/)的文档学习。\n\n当然后面的教程和使用案例我也会穿插讲解这两部分知识。\n建议阅读顺序\n\n1. [souffle.md](souffle.md)\n2. [relation.md](relation.md)\n3. [utils.md](utils.md)\n4. [query.md](query.md)\n5. [callgraph.md](callgraph.md)\n6. [cha-optimization.md](cha-optimization.md)\n7. [cha-in-ctf.md](cha-in-ctf.md)\n8. [context-insensitive-points-to.md](context-insensitive-points-to.md)\n9. [ptaint](ptaint.md)\n"
  },
  {
    "path": "docs/relation.md",
    "content": "# relation\n\n## Subtypes\n\n```\n// 指令 可以定位出动作（比如call,load,sotre,assign）发生时的代码位置\n.type Insn <: symbol\n// 变量 \n.type Var <: symbol\n// 堆 也可以理解为内存中的对象\n.type Heap <: symbol\n// 字段\n.type Field <: symbol\n// 方法\n.type Method <: symbol\n// 类\n.type Class <: symbol\n```\n\n## Class\n\n- 类名\n  - 对应的就是Class这个类型，是一个字符串\n- 类的修饰符号\n  - `ClassModifier(mod:symbol, class:Class)`\n  - 表示`class`存在`mod`这种修饰符\n  - `mod`可能是public，private，static等修饰符\n  - `class`是形如java.lang.Object这样的类名\n- 是否是非接口类\n  - `ClassType(class:Class)`\n  - 表示`class`是非接口类\n- 是否是Interface\n  - `InterfaceType(interface:Class)`\n  - 表示`interface`是接口类\n- 是出现在待分析的应用中还是在第三方库中\n  - `ApplicationClass(class:Class)`\n    - 表示`class`是应用类\n- 直接继承了什么类\n  - `DirectSuperclass(child:Class, parent:Class)`\n    - 表示`child`直接extend了`parnet`\n- 直接实现了什么接口\n  - `DirectSuperinterface(child:Class, parent:Class)`\n    - 表示`child`直接implement了`parent`\n\n对于方法中有哪些方法和字段，会通过Method和Field相关信息进行反查。\n\n## Method\n\n- 方法的基本信息\n  - `MethodInfo(method:Method, simplename:symbol, param:symbol, class:Class, return:Class, jvmDescriptor:symbol, arity:number)`\n    - `method` 完整的方法名，如：\n    - `simplename` 简单的方法名\n    - `param` 参数类型\n    - `class` 在哪个class声明的\n    - `return` 返回类型\n    - `jvmDescriptor` jvm描述符\n    - `arity` 参数个数\n- 方法的修饰符\n  - `MethodModifier(mod:symbol, method:Method)`\n- 方法对应的this变量\n  - `ThisVar(method:Method, this:Var)`\n- 方法的形式参数\n  - `FormalParam(n:number, method:Method, param:Var)`\n  - method的第n个形式参数为param变量\n- 方法的返回值\n  - `Return(insn:Insn, index:number, var:Var, method:Method)`\n  - method的函数内返回的变量为var\n  \nJava中方法调用，可以分为三类\n\n- SpecialMethodInvocation\n  - 包括private，super，以及构造函数\n  - `SpecialMethodInvocation(insn:Insn, index:number, callee:Method, receiver:Var, caller:Method)`\n  - 在caller中，通过指令insn，调用了receiver.callee()\n- StaticMethodInvocation\n  - 静态方法调用\n  - `StaticMethodInvocation(insn:Insn, index:number, callee:Method, caller:Method)`\n  - 在caller中，通过指令insn调用了静态方法callee\n- VirtualMethodInvocation\n  - 虚拟方法调用\n  - `VirtualMethodInvocation(insn:Insn, index:number, callee:Method, receiver:Var, caller:Method)`\n  - 在caller中，通过指令insn，调用了receiver.callee()\n\nSpecialMethodInvocation和StaticMethodInvocation在编译时就能确定被调方法，但是VirtualMethodInvocation由于多态的原因，只有在运行时根据receiver变量的实际类型才能确定具体的被调方法。\n\n以及调用时涉及到的\n- 实际参数\n  - `ActualParam(n:number, insn:Insn, var:Var)`\n  - 在调用insn发生时，实际传入的第n个参数为var\n- 函数调用后的返回值赋值\n  - `AssignReturnValue(insn:Insn, var:Var)`\n  - 在调用insn返回时，将返回结果赋值给var变量\n\n## Field\n- 字段的基本信息\n  - `FieldInfo(field:Field, declaringType:Class, simplename:symbol, type:Class)`\n    - `field` 完整的名称\n    - `declaringType` 所属的类\n    - `simplename` 字段名\n    - `type` 类型\n- 字段的修饰符\n  - `FieldModifier(modifier:symbol, field:Field)`\n- 读取字段，也就是load\n  - `LoadInstanceField(insn:Insn, index:number, var:Var, base:Var, field:Field, inMethod:Method)`\n  - 表示在inMethod方法中，var = base.field\n- 写入字段，也就是store\n  - `StoreInstanceField(insn:Insn, index:number, var:Var, base:Var, field:Field, inMethod:Method)`\n  - 表示在inMethod中，base.field = var\n\n## Array\n\n- 从数组中读\n  - `LoadArrayIndex(insn:Insn, index:number, to:Var, array:Var, inMethod:Method)`\n  - 表示在inMethod中，to = array[]\n- 往数组中写\n  - `StoreArrayIndex(insn:Insn, index:number, from:Var, array:Var, inMethod:Method)`\n  - 表示在inMethod中，array[] = from\n- 数组中的元素类型\n  - `ComponentType(arrayType:Class, componentType:Class)`\n  - 表示arrayType中元素的类型为componentType\n\n## Others\n\n- 变量的声明类型\n  - `VarType(var:Var, class:Class)`\n  - 表示变量var的声明类型为class\n- 局部变量赋值\n  - `AssignLocal(insn:Insn, index:number, from:Var, to:Var, inMethod: Method)`\n  - 表示在inMethod中，to = from\n- 类型转换\n  - `AssignCast(insn:Insn, index:number, from:Var, to:Var, type:Class, inMethod:Method)`\n  - 表示在inMethod中，to = (type) from\n- 创建对象赋值\n  - `AssignHeapAllocation(insn:Insn, index:number, heap:Heap, var:Var, inMethod:Method, linenumber:number)`\n  - 表示在inMethod中，var = new heap()\n- 堆中对象对应的类型\n  - `NormalHeap(value:Heap, class:Class)`\n  - 表示heap的类型为class"
  },
  {
    "path": "docs/souffle.md",
    "content": "# Souffle\n\n## example\n\nSouffle是款Datalog推理引擎，也是著名声明式分析框架Doop默认的引擎。\n\nDatalog = data + logic ，也就是现有的事实加上推理逻辑可以推理出新的事实。\ndata可以理解为数据库，其中由一个个relation组成，relation可以理解为数据库中的表，表中一列数据表明满足他们满足某种关系。\n\n```\n.decl edge(x:number, y:number)\n```\n\n上面通过.decl声明了edge这个关系，可以理解为x有条指向y的边,x和y可以理解为变量名称，number理解为变量类型。\n添加已有事实有两种方式，一种是通过\n\n```\n.decl edge(x:number, y:number)\nedge(1, 2).\n```\n\n表明节点1到节点2有条边。也可以通过\n\n```\n.decl edge(x:number, y:number)\n.input edge\n```\n\n通过从edge.facts中获取事实，如果edge.facts的内容如下\n\n```\n1\t2\n```\n\n上面表达的效果就是一致的。\n再接着看一个完整的例子，example.dl文件内容如下\n\n```\n// 声明 edge 表示 节点 x 到 y 有条边\n.decl edge(x:number, y:number)\n// 表示从edge.facts 读事实\n.input edge\n\n// 声明 path 表示 节点 x 到 y 有路径可达\n.decl path(x:number, y:number)\n// 表示将path的结果输出到path.csv\n.output path\n\n// 推理规则，如果x到y有边，那么x到y肯定有长度为1的路径，也就是如果x，y满足关系edge，也一定满足关系path\npath(x, y) :- edge(x, y).\n// 用到了递归推理，如果x到z有条路径，并且z到y有条边，那么就可以推理出x到y也有路径\npath(x, y) :- path(x, z), edge(z, y).\n```\n\n如果edge.facts的内容如下\n\n```\n1\t2\n2\t3\n```\n通过执行\n```\nsouffle -F . -D . example.dl\n```\n- `-F` 指定了facts所在的目录\n- `-D` 指定了输出目录\n- `example.dl` 指定datalog文件名\n\n最终得到的path.csv内容如下\n\n```\n1\t2\n1\t3\n2\t3\n```\n\n表示节点1到节点2有路径，节点1到节点3有路径，节点2到节点3有路径。\n上述内容主要来自 https://souffle-lang.github.io/simple\n\n## Type\n\nSouffle中类型除了number类型（和int类似）以外，还有symbol类型（和string类似），这两种都属于Primitive Type，还可以有\n\n- Equivalence Types\n\n    `.type <new-type> = <other-type>`\n\n    ```\n    .type myNumber = number\n    ```\n  \n- SubTypes\n  \n    `type <new-type> <: <other-type>`\n    ```\n    .type myEvenNumber <: number\n    ```\n具体可参考 https://souffle-lang.github.io/types\n\n## reference\n- https://pascal-group.bitbucket.io/lectures/Datalog.pdf\n- https://souffle-lang.github.io/simple\n- https://souffle-lang.github.io/types"
  },
  {
    "path": "docs/utils.md",
    "content": "# utils\n\n## Class Hierarchy\n\n需要构建一个类型层次图，用于寻找某个类的子类、父类，或者用于判断两个类之间是否有继承关系。\n\n从bytecode中能够解析出直接继承关系，其中extend对应的是DirectSuperclass ， implement对应的是DirectSuperinterface 。\n\n创建个新的relation SubClass(subclass:Class, class:Class) 表示subclass是class的子类。\n那么推理规则可以有：\n\n1. 如果满足class x 和 y DirectSuperclass(x, y) 或者DirectSuperinterface(x, y) 那么 x , y 也一定满足 SubClass(x, y)\n2. 还需要利用递推，判断非直接的层次关系。如果x 和 z 满足SubClass(x, z) 且 z 和 y 满足 DirectSuperclass(z, y) 或者DirectSuperinterface(z, y) 那么能够推导出 SubClass(x, y)\n\n将上面的规则翻译成datalog如下：\n\n```\nSubClass(subclass, class) :- DirectSuperclass(subclass, class).\nSubClass(subclass, class) :- DirectSuperinterface(subclass, class).\nSubClass(subclass, class) :- \n    (\n        DirectSuperclass(subclass, tmp);\n        DirectSuperinterface(subclass, tmp)\n    ),\n    SubClass(tmp, class).\n```\n其中`;` 表示或，`,` 表示逻辑且\n\n## Method Dispatch\n\n针对VirtualMethodInvocation(insn:Insn, index:number, callee:Method, receiver:Var, caller:Method)调用，其中的callee并不是真实调用，需要根据receiver运行时类型rclass和callee的函数签名sig解析出实际调用的方法。\n\n解析过程分为两种情况：\n\n1. 如果rclass中有实现方法method.sig == sig 且method没有被abstract修饰，则直接返回method\n2. 如果rclass没有对应的方法实现，则需要去父类中寻找相同函数签名的方法。\n\n创建新的relation Dispatch(simplename:symbol, descriptor:symbol, class:Class, method:Method) simplename和descriptor 能拼凑成函数签名，class 表示要解析的类型，根据这三个元素能够找到对应的method。\n\n可将上面的规则翻译成如下的datalog\n\n```\nDispatch(simplename, descriptor, class, method) :-\n    MethodInfo(method, simplename, _, class, _, descriptor, _),\n    !MethodModifier(\"abstract\", method).\n\nDispatch(simplename, descriptor, class, method) :-\n    !MethodInfo(_, simplename, _, class, _, descriptor, _),\n    DirectSuperclass(class, superclass),\n    Dispatch(simplename, descriptor, superclass, method),\n    !MethodModifier(\"abstract\", method).\n```\n`_` 表示可以为任意值\n\n这部分对应的代码见 `logic/utils.dl`"
  },
  {
    "path": "example/cha-example-1.dl",
    "content": "#define MAXSTEP 8\n\n#include \"../logic/cha.dl\"\n\n\n// init entrypoint \nEntryPoint(simplename, descriptor, class) :-\n    MethodInfo(_, simplename, _, class, _, descriptor, _),\n    simplename = \"main\",\n    descriptor = \"([Ljava/lang/String;)V\"."
  },
  {
    "path": "example/cha-log4shell.dl",
    "content": "#define MAXSTEP 33\n#define CHAO 1\n\n#include \"../logic/cha.dl\"\n\nBanCaller(method) :-\n    MethodInfo(method, _, _, class, _, _, _),\n    !contains(\"org.apache.logging.log4j\", class).\n\n\nSinkDesc(\"lookup\", \"javax.naming.Context\").\n\n// init entrypoint \nEntryPoint(simplename, descriptor, class) :-\n    MethodInfo(_, simplename, _, class, _, descriptor, _),\n    simplename = \"error\",\n    class = \"org.apache.logging.log4j.spi.AbstractLogger\",\n    descriptor = \"(Ljava/lang/String;)V\"."
  },
  {
    "path": "example/cs-ptaint-example-1.dl",
    "content": "#define MAXSTEP 8\n//#include \"../logic/one-callsite-sensitive-pt.dl\"\n#include \"../logic/cs-ptaint.dl\"\n#include \"../logic/one-object-sensitive-pt.dl\"\n\n//.comp MyCallsitePtaint : CSPTaint<HContext, Context>, OneCallsiteSensitivePT{\n//}\n//.init csptaint = MyCallsitePtaint\n.comp MyObjectPtaint : CSPTaint<HContext, Context>, OneObjectSensitivePT{\n}\n\n\n.init csptaint = MyObjectPtaint\n\n\ncsptaint.Reachable(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void main(java.lang.String[])>\", \"initCtx\", 0).\n\ncsptaint.SourceMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Source()>\").\ncsptaint.SinkMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void Sink(java.lang.String)>\", 0).\n\ncsptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\").\ncsptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.String toString()>\").\n\ncsptaint.ArgToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\", 0).\n\ncsptaint.SanitizeMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Sanitize(java.lang.String)>\").\n\n\n.decl TaintVar(var:Var, vCtx:Context)\n\nTaintVar(var, vCtx) :-\n    csptaint.VarPointsTo(heap, _, var, vCtx),\n    csptaint.TaintHeap(_, heap).\n\n.output TaintVar\n\n.output csptaint.TaintHeap\n.output csptaint.TransferTaint\n.output csptaint.VarPointsTo"
  },
  {
    "path": "example/ctf-buggyLoader.dl",
    "content": "#define MAXSTEP 5\n#define CHAO 2\n\n#include \"../logic/cha.dl\"\n\n\n.decl NonParamPublicMethod(method:Method, class:Class)\n.output NonParamPublicMethod\n\n\nSinkDesc(\"exec\", \"java.lang.Runtime\").\nSinkDesc(\"<init>\", \"java.lang.ProcessBuilder\").\nSinkDesc(\"start\", \"java.lang.ProcessImpl\").\nSinkDesc(\"loadClass\", \"java.lang.ClassLoader\").\nSinkDesc(\"defineClass\", \"java.lang.ClassLoader\").\nSinkDesc(\"readObject\", \"java.io.ObjectInputStream\").\nSinkDesc(\"readExternal\", \"java.io.ObjectInputStream\").\n\n\nEntryMethod(method),\nReachable(method, 0),\nNonParamPublicMethod(method, class) :- \n    MethodInfo(method, simplename, _, class, _, _, arity),\n    MethodModifier(\"public\", method),\n    simplename != \"<init>\",\n    arity = 0,\n    SubClass(class, \"java.io.Serializable\").\n\n.output SinkMethod"
  },
  {
    "path": "example/ctf-ezchain.dl",
    "content": "#define MAXSTEP 5\n#define CHAO 2\n\n#include \"../logic/cha.dl\"\n\n\n.decl NonParamPublicMethod(method:Method, class:Class)\n.output NonParamPublicMethod\n\nSinkDesc(\"exec\", \"java.lang.Runtime\").\nSinkDesc(\"<init>\", \"java.lang.ProcessBuilder\").\nSinkDesc(\"start\", \"java.lang.ProcessImpl\").\nSinkDesc(\"loadClass\", \"java.lang.ClassLoader\").\nSinkDesc(\"defineClass\", \"java.lang.ClassLoader\").\nSinkDesc(\"readObject\", \"java.io.ObjectInputStream\").\nSinkDesc(\"readExternal\", \"java.io.ObjectInputStream\").\n\n\nEntryMethod(method),\nReachable(method, 0),\nNonParamPublicMethod(method, class) :- \n    MethodInfo(method, simplename, _, class, _, _, arity),\n    MethodModifier(\"public\", method),\n    contains(\"get\", simplename),\n    arity = 0.\n\n.output SinkMethod"
  },
  {
    "path": "example/one-callsite-sensitive-pt-example-1.dl",
    "content": "#define MAXSTEP 8\n#include \"../logic/one-callsite-sensitive-pt.dl\"\n\n.init callsitecsDemo1 = OneCallsiteSensitivePT\ncallsitecsDemo1.Reachable(\"<com.bytecodedl.benchmark.demo.ContextSensitiveDemo1: void main(java.lang.String[])>\", \"initCtx\", 0).\n.output callsitecsDemo1.VarPointsTo\n\n.init callsitecsDemo2 = OneCallsiteSensitivePT\ncallsitecsDemo2.Reachable(\"<com.bytecodedl.benchmark.demo.ContextSensitiveDemo2: void main(java.lang.String[])>\", \"initCtx\", 0).\n.output callsitecsDemo2.VarPointsTo"
  },
  {
    "path": "example/one-object-sensitive-pt-example-1.dl",
    "content": "#define MAXSTEP 8\n#include \"../logic/one-object-sensitive-pt.dl\"\n\n.init objectDemo1 = OneObjectSensitivePT\nobjectDemo1.Reachable(\"<com.bytecodedl.benchmark.demo.ContextSensitiveDemo1: void main(java.lang.String[])>\", \"initCtx\", 0).\n.output objectDemo1.VarPointsTo\n\n.init objectDemo2 = OneObjectSensitivePT\nobjectDemo2.Reachable(\"<com.bytecodedl.benchmark.demo.ContextSensitiveDemo2: void main(java.lang.String[])>\", \"initCtx\", 0).\n.output objectDemo2.VarPointsTo"
  },
  {
    "path": "example/one-type-sensitive-pt-example-1.dl",
    "content": "#define MAXSTEP 8\n#include \"../logic/one-type-sensitive-pt.dl\"\n\n.init typeDemo1 = OneTypeSensitivePT\ntypeDemo1.Reachable(\"<com.bytecodedl.benchmark.demo.ContextSensitiveDemo1: void main(java.lang.String[])>\", \"initCtx\", 0).\n.output typeDemo1.VarPointsTo\n\n.init typeDemo2 = OneTypeSensitivePT\ntypeDemo2.Reachable(\"<com.bytecodedl.benchmark.demo.ContextSensitiveDemo2: void main(java.lang.String[])>\", \"initCtx\", 0).\n.output typeDemo2.VarPointsTo"
  },
  {
    "path": "example/pt-noctx-example-1.dl",
    "content": "#include \"../logic/pt-noctx.dl\"\n\n.init cipt = ContextInsensitivePt\n\ncipt.Reachable(method) :-\n    MethodInfo(method, simplename, _, _, _, descriptor, _),\n    simplename = \"main\",\n    descriptor = \"([Ljava/lang/String;)V\".\n\n.output cipt.VarPointsTo\n"
  },
  {
    "path": "example/ptaint-example-1.dl",
    "content": "#include \"../logic/ptaint.dl\"\n\n.init ptaint = PTaint\n\nptaint.Reachable(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void main(java.lang.String[])>\").\n\nptaint.SourceMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Source()>\").\nptaint.SinkMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void Sink(java.lang.String)>\", 0).\n\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\").\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.String toString()>\").\n\nptaint.ArgToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\", 0).\n\nptaint.SanitizeMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Sanitize(java.lang.String)>\").\n\n\n.decl TaintVar(var:Var)\n\nTaintVar(var) :-\n    ptaint.VarPointsTo(heap, var),\n    ptaint.TaintHeap(_, heap).\n\n.output TaintVar\n\n.output ptaint.TaintHeap\n.output ptaint.TransferTaint\n.output ptaint.VarPointsTo"
  },
  {
    "path": "example/ptaint-example-2.dl",
    "content": "#include \"../logic/ptaint.dl\"\n\n.init ptaint = PTaint\n\n.decl EntryMethod(method:Method)\n\nEntryMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void test1(java.lang.String)>\").\n\n\nptaint.Reachable(method) :-\n    EntryMethod(method).\n\nNormalHeap(heap, class),\nptaint.VarPointsTo(heap, this) :-\n    ThisVar(method, this),\n    EntryMethod(method),\n    VarType(this, class),\n    heap = cat(\"Mock::\", class).\n\nNormalHeap(heap, class),\nptaint.TaintHeap(insn, taintHeap),\nptaint.VarPointsTo(heap, param),\nptaint.VarPointsTo(taintHeap, param) :-\n    EntryMethod(method),\n    FormalParam(_, method, param),\n    VarType(param, class),\n    heap = cat(\"Mock::\", class),\n    taintHeap = cat(\"NewTainted::\", class),\n    insn = \"Init::Param\".\n\n\nptaint.SourceMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Source()>\").\nptaint.SinkMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: void Sink(java.lang.String)>\", 0).\n\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\").\nptaint.BaseToRetTransfer(\"<java.lang.StringBuilder: java.lang.String toString()>\").\n\nptaint.ArgToRetTransfer(\"<java.lang.StringBuilder: java.lang.StringBuilder append(java.lang.String)>\", 0).\n\nptaint.SanitizeMethod(\"<com.bytecodedl.benchmark.demo.TaintDemo3: java.lang.String Sanitize(java.lang.String)>\").\n\n\n.decl TaintVar(var:Var)\n\nTaintVar(var) :-\n    ptaint.VarPointsTo(heap, var),\n    ptaint.TaintHeap(_, heap).\n\n.output TaintVar\n\n.output ptaint.TaintHeap\n.output ptaint.TransferTaint\n.output ptaint.VarPointsTo"
  },
  {
    "path": "example/query-example-1.dl",
    "content": "#include \"../logic/inputDeclaration.dl\"\n\n.decl QueryResult(class:Class, method:Method)\n.output QueryResult\n\nQueryResult(class, method) :- \n    MethodInfo(method, simplename, param, class, _, _, arity),\n    //simplename = \"<init>\",\n    contains(\"[]\", param),\n    arity = 1.\n"
  },
  {
    "path": "example/rta-example-1.dl",
    "content": "#define MAXSTEP 8\n\n#include \"../logic/RTA.dl\"\n\n.init rta = RTA\n\nrta.EntryPoint(\"main\", \"([Ljava/lang/String;)V\", \"com.bytecodedl.benchmark.demo.VirtualCallDemo1\")."
  },
  {
    "path": "example/simple-cha-log4shell.dl",
    "content": "#define MAXSTEP 33\n\n#include \"../logic/simple-cha.dl\"\n\n\nSinkDesc(\"lookup\", \"javax.naming.Context\").\n\n// init entrypoint \nEntryPoint(simplename, descriptor, class) :-\n    MethodInfo(_, simplename, _, class, _, descriptor, _),\n    simplename = \"error\",\n    class = \"org.apache.logging.log4j.spi.AbstractLogger\",\n    descriptor = \"(Ljava/lang/String;)V\".\n\n\n.output EntryPoint\n.output EntryMethod\n.output SinkMethod\n.output SimpleCallGraph"
  },
  {
    "path": "importOuput2Neo4j.sh",
    "content": "#!/bin/bash\n\ndocker-compose exec neo bash /bytecodedl/$1 $2\ndocker-compose restart neo"
  },
  {
    "path": "logic/abstract-context-sensitive-pt.dl",
    "content": "#pragma once\n#include \"utils.dl\"\n\n.comp AbstractContextSensitivePT<HContext, Context>{\n    .decl VarPointsTo(heap:Heap, hctx:HContext, var:Var, vCtx:Context)\n    .decl InstanceFieldPointsTo(heap:Heap, hctx:Context, baseHeap:Heap, bhCtx:Context, field:Field)\n    .decl StaticFieldPointsTo(heap:Heap, hctx:Context, field:Field)\n    .decl ArrayIndexPointsTo(heap:Heap, hctx:Context, baseHeap:Heap, bhCtx:Context)\n    .decl Reachable(method:Method, ctx:Context, n:number)\n    .decl CallGraph(insn:Insn, caller:Method, callerCtx:Context, callee:Method, calleeCtx:Context)\n\n    .decl SelectInvocationContext(callerCtx:Context, invocation:Insn, baseHeap:Heap, hctx:HContext, calleeCtx:Context) overridable\n    .decl SelectStaticInvocationContext(callerCtx:Context, invocation:Insn, calleeCtx:Context) overridable\n\n    SelectStaticInvocationContext(callerCtx, insn, calleeCtx) :-\n        Reachable(caller, callerCtx, _),\n        StaticMethodInvocation(insn, _, _, caller),\n        calleeCtx = callerCtx.\n\n    // new\n    VarPointsTo(heap, ctx, var, ctx) :-\n        Reachable(method, ctx, _),\n        AssignHeapAllocation(_, _, heap, var, method, _).\n\n    // assign\n    VarPointsTo(heap, hctx, to, ctx) :-\n        Reachable(method, ctx, _),\n        VarPointsTo(heap, hctx, from, ctx),\n        AssignLocal(_, _, from, to, method).\n\n    // cast\n    VarPointsTo(heap, hctx, to, ctx) :-\n        Reachable(method, ctx, _),\n        AssignCast(_, _, from, to, _, method),\n        VarPointsTo(heap, hctx, from, ctx).\n\n    // load field\n    VarPointsTo(heap, hctx, to, ctx) :-\n        Reachable(method, ctx, _),\n        LoadInstanceField(_, _, to, base, field, method),\n        VarPointsTo(baseHeap, bhCtx, base, ctx),\n        InstanceFieldPointsTo(heap, hctx, baseHeap, bhCtx, field).\n\n    // store field\n    InstanceFieldPointsTo(heap, hctx, baseHeap, bhCtx, field) :-\n        Reachable(method, ctx, _),\n        StoreInstanceField(_, _, from, base, field, method),\n        VarPointsTo(heap, hctx, from, ctx),\n        VarPointsTo(baseHeap, bhCtx, base, ctx).\n\n    // load staic field\n    VarPointsTo(heap, hctx, to, ctx) :-\n        Reachable(method, ctx, _),\n        LoadStaticField(_, _, to, field, method),\n        StaticFieldPointsTo(heap, hctx, field).\n\n    // store static field\n    StaticFieldPointsTo(heap, hctx, field) :-\n        Reachable(method, ctx, _),\n        StoreStaticField(_, _, from, field, method),\n        VarPointsTo(heap, hctx, from, ctx).\n\n    // load from array\n    VarPointsTo(heap, hctx, to, ctx) :-\n        Reachable(method, ctx, _),\n        LoadArrayIndex(_, _, to, base, method),\n        VarPointsTo(baseHeap, bhCtx, base, ctx),\n        ArrayIndexPointsTo(heap, hctx, baseHeap, bhCtx).\n\n    // store into array\n    ArrayIndexPointsTo(heap, hctx, baseHeap, bhCtx) :-\n        Reachable(method, ctx, _),\n        StoreArrayIndex(_, _, from, base, method),\n        VarPointsTo(heap, hctx, from, ctx),\n        VarPointsTo(baseHeap, bhCtx, base, ctx).\n\n    Reachable(callee, calleeCtx, n+1),\n    CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-\n        Reachable(caller, callerCtx, n),\n        n < MAXSTEP,\n        SpecialMethodInvocation(insn, _, callee, base, caller),\n        VarPointsTo(baseHeap, hctx, base, calleeCtx),\n        SelectInvocationContext(callerCtx, insn, baseHeap, hctx, callerCtx).\n\n    Reachable(callee, calleeCtx, n+1),\n    CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-\n        Reachable(caller, callerCtx, n),\n        n < MAXSTEP,\n        StaticMethodInvocation(insn, _, callee, caller),\n        SelectStaticInvocationContext(callerCtx, insn, calleeCtx).\n\n    Reachable(callee, calleeCtx, n+1),\n    CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-\n        Reachable(caller, callerCtx, n),\n        n < MAXSTEP,\n        VirtualMethodInvocation(insn, _, method, base, caller),\n        VarPointsTo(baseHeap, hctx, base, callerCtx),\n        NormalHeap(baseHeap, class),\n        MethodInfo(method, simplename, _, _, _, descriptor, _),\n        Dispatch(simplename, descriptor, class, callee),\n        SelectInvocationContext(callerCtx, insn, baseHeap, hctx, calleeCtx).\n\n    // param\n    VarPointsTo(heap, hctx, param, calleeCtx) :-\n        CallGraph(insn, _, callerCtx, callee, calleeCtx),\n        ActualParam(n, insn, arg),\n        FormalParam(n, callee, param),\n        VarPointsTo(heap, hctx, arg, callerCtx),\n        NormalHeap(heap, _).\n\n    // return\n    VarPointsTo(heap, hctx, return, callerCtx) :-\n        CallGraph(insn, _, callerCtx, callee, calleeCtx),\n        Return(_, _, var, callee),\n        AssignReturnValue(insn, return),\n        VarPointsTo(heap, hctx, var, calleeCtx).\n\n    // this\n    VarPointsTo(heap, hctx, this, calleeCtx) :-\n        CallGraph(insn, _, callerCtx, callee, calleeCtx),\n        (\n            VirtualMethodInvocation(insn, _, _, base, _);\n            SpecialMethodInvocation(insn, _, _, base, _)\n        ),\n        ThisVar(callee, this),\n        VarPointsTo(heap, hctx, base, callerCtx).\n}"
  },
  {
    "path": "logic/cha.dl",
    "content": "#pragma once\n#include \"utils.dl\"\n\n.decl EntryPoint(simplename:symbol, descriptor:symbol, class:Class)\n.decl Reachable(method:Method, step:number)\n.decl SinkDesc(simplename:symbol, class:Class)\n.decl SinkMethod(method:Method)\n.decl EntryMethod(method:Method)\n.decl BanCaller(method:Method)\n\n\n.decl CallGraph(insn:Insn, caller:Method, callee:Method)\n\nSinkMethod(method) :-\n    SinkDesc(simplename, class),\n    SubEqClass(subeqclass, class),\n    !MethodModifier(\"abstract\", method),\n    MethodInfo(method, simplename, _, subeqclass, _, _, _).\n\nEntryMethod(method),\nReachable(method, 0) :- \n    EntryPoint(simplename, descriptor, class),\n    Dispatch(simplename, descriptor, class, method).\n\nReachable(callee, n+1),\nCallGraph(insn, caller, callee) :-\n    Reachable(caller, n),\n    !BanCaller(caller),\n    n < MAXSTEP,\n    SpecialMethodInvocation(insn, _, callee, _, caller).\n\nReachable(callee, n+1),\nCallGraph(insn, caller, callee) :-\n    Reachable(caller, n),\n    !BanCaller(caller),\n    n < MAXSTEP,\n    StaticMethodInvocation(insn, _, callee, caller).\n\nReachable(callee, n+1),\nCallGraph(insn, caller, callee) :-\n    Reachable(caller, n),\n    !BanCaller(caller),\n    n < MAXSTEP,\n    VirtualMethodInvocation(insn, _, method, receiver, caller),\n    MethodInfo(method, simplename, _, _, _, descriptor, _),\n    VarType(receiver, class),\n    SubEqClass(subeqclass, class),\n    !ClassModifier(\"abstract\", subeqclass),\n    Dispatch(simplename, descriptor, subeqclass, callee).\n\nReachable(callee, n+1),\nCallGraph(insn, caller, callee) :- \n    Reachable(caller, n),\n    !BanCaller(caller),\n    n < MAXSTEP,\n    StaticMethodInvocation(insn, _, method, caller),\n    MethodInfo(method, \"doPrivileged\", _, \"java.security.AccessController\", _, _, _),\n    ActualParam(0, insn, param),\n    VarType(param, class),\n    MethodInfo(callee, \"run\", _, class, _, _, 0).\n\n// CHAO is CHA OPTIMIZATION LEVEL\n#if CHAO > 0\n\n.decl SinkReachable(method:Method, sink:Method, step:number)\n\nSinkReachable(sink, sink, 0) :-\n    SinkMethod(sink).\n\nSinkReachable(caller, sink, n+1) :-\n    n < MAXSTEP,\n    SinkReachable(callee, sink, n),\n    CallGraph(_, caller, callee).\n\n#endif\n\n#if CHAO > 1\n\n.decl ShortestPathToSink(caller:Method, sink:Method, step:number)\n\nShortestPathToSink(entry, sink, n) :-\n    n = min step : {SinkReachable(entry, sink, step)},\n    SinkMethod(sink),\n    EntryMethod(entry).\n\nShortestPathToSink(callee, sink, n-1) :-\n    n < MAXSTEP + 1,\n    ShortestPathToSink(caller, sink, n),\n    SinkReachable(callee, sink, n-1),\n    CallGraph(_, caller, callee).\n\n#endif\n\n.decl RefinedReachable(method:Method)\n\n#ifdef CHAO\n    #if CHAO == 1\n        RefinedReachable(method) :-\n            SinkReachable(method, _, _).\n    #endif\n    #if CHAO == 2\n        RefinedReachable(method) :-\n            ShortestPathToSink(method, _, _).\n    #endif\n#else\n    RefinedReachable(method) :-\n        Reachable(method, _).\n#endif\n\n.decl CallNode(node:Method, label:symbol)\n.output CallNode\n\nCallNode(node, \"method\") :-\n    !EntryMethod(node),\n    !SinkMethod(node),\n    RefinedReachable(node).\n\nCallNode(node, \"sink\") :-\n    RefinedReachable(node),\n    SinkMethod(node).\n\nCallNode(node, \"entry\") :-\n    RefinedReachable(node),\n    EntryMethod(node).\n\n.decl CallEdge(caller:Method, insn:Insn, callee:Method)\n.output CallEdge\n\nCallEdge(caller, insn, callee) :-\n    RefinedReachable(caller),\n    RefinedReachable(callee),\n    CallGraph(insn, caller, callee).\n"
  },
  {
    "path": "logic/cs-ptaint.dl",
    "content": "#pragma once\n#include \"utils.dl\"\n#include \"abstract-context-sensitive-pt.dl\"\n\n.comp CSPTaint<HContext, Context>{\n    //.init cspt = AbstractContextSensitivePT\n    //.init cspt = CSPT\n\n    .decl TaintHeap(insn:Insn, heap:Heap)\n    .decl SourceMethod(method:Method)\n    .decl SinkMethod(method:Method, n:number)\n\n    .decl SanitizeMethod(method:Method)\n\n    .decl BaseToRetTransfer(method:Method)\n    .decl ArgToRetTransfer(method:Method, n:number)\n    .decl IsTaintedFrom(insn:Insn, from:Var, fromCtx:Context, to:Var, toCtx:Context)\n    .decl TransferTaint(heap:Heap, newHeap:Heap)\n\n\n    // taint arg to param\n    VarPointsTo(heap, hctx, param, calleeCtx) :-\n        CallGraph(insn, _, callerCtx, callee, calleeCtx),\n        ActualParam(n, insn, arg),\n        FormalParam(n, callee, param),\n        VarPointsTo(heap, hctx, arg, callerCtx),\n        TaintHeap(_, heap), // sensitive?\n        !SanitizeMethod(callee).\n\n\n    TaintHeap(insn, heap),\n    VarPointsTo(heap, hctx, to, callerCtx):-\n        SourceMethod(callee),\n        CallGraph(insn, _, callerCtx, callee, _),\n        AssignReturnValue(insn, to),\n        heap = cat(\"NewTainted::\", insn),\n        hctx = \"Mock::\".\n\n    IsTaintedFrom(insn, base, callerCtx, ret, callerCtx) :-\n        CallGraph(insn, _, callerCtx, callee, _),\n        BaseToRetTransfer(callee),\n        (\n            VirtualMethodInvocation(insn, _, _, base, _);\n            SpecialMethodInvocation(insn, _, _, base, _)\n        ),\n        AssignReturnValue(insn, ret).\n\n    IsTaintedFrom(insn, arg, callerCtx, ret, callerCtx) :-\n        CallGraph(insn, _, callerCtx, callee, _),\n        ArgToRetTransfer(callee, n),\n        ActualParam(n, insn, arg),\n        AssignReturnValue(insn, ret).\n\n    TaintHeap(insn, newHeap),\n    TransferTaint(heap, newHeap),\n    VarPointsTo(heap, hctx, var, vCtx) :-\n        IsTaintedFrom(insn, from, fromCtx, to, toCtx),\n        VarPointsTo(heap, hctx, from, fromCtx),\n        TaintHeap(_, heap),\n        newHeap = cat(\"TransferTaint::\", insn),\n        VarPointsTo(oldHeap, oldHCtx, to, toCtx),\n        VarPointsTo(oldHeap, oldHCtx, var, vCtx),\n        AssignHeapAllocation(_, _, oldHeap, var, _, _).\n}"
  },
  {
    "path": "logic/inputDeclaration.dl",
    "content": "#pragma once\n\n.type Insn <: symbol\n.type Var <: symbol\n.type Heap <: symbol\n.type Field <: symbol\n.type Method <: symbol\n.type Class <: symbol\n\n// load data from facts\n// class\n\n.decl ClassModifier(mod:symbol, class:Class)\n.input ClassModifier\n\n.decl ClassType(class:Class)\n.input ClassType\n\n.decl InterfaceType(interface:Class)\n.input InterfaceType\n\n.decl ApplicationClass(class:Class)\n.input ApplicationClass\n\n.decl DirectSuperclass(child:Class, parent:Class)\n.input DirectSuperclass\n\n.decl DirectSuperinterface(child:Class, parent:Class)\n.input DirectSuperinterface\n\n// method \n\n.decl MethodInfo(method:Method, simplename:symbol, param:symbol, class:Class, return:Class, jvmDescriptor:symbol, arity:number)\n.input MethodInfo(IO=file, filename=\"Method.facts\", delimiter=\"\\t\")\n\n.decl MethodModifier(mod:symbol, method:Method)\n.input MethodModifier(IO=file, filename=\"Method-Modifier.facts\", delimiter=\"\\t\")\n\n.decl ThisVar(method:Method, this:Var)\n.input ThisVar\n\n.decl FormalParam(n:number, method:Method, param:Var)\n.input FormalParam\n\n.decl Return(insn:Insn, index:number, var:Var, method:Method)\n.input Return\n\n.decl VirtualMethodInvocation(insn:Insn, index:number, callee:Method, receiver:Var, caller:Method)\n.input VirtualMethodInvocation\n\n.decl StaticMethodInvocation(insn:Insn, index:number, callee:Method, caller:Method)\n.input StaticMethodInvocation\n\n.decl SpecialMethodInvocation(insn:Insn, index:number, callee:Method, receiver:Var, caller:Method)\n.input SpecialMethodInvocation\n\n.decl ActualParam(n:number, insn:Insn, var:Var)\n.input ActualParam\n\n.decl AssignReturnValue(insn:Insn, var:Var)\n.input AssignReturnValue\n\n// Field\n\n.decl FieldInfo(field:Field, declaringType:Class, simplename:symbol, type:Class)\n.input FieldInfo(IO=file, filename=\"Field.facts\", delimiter=\"\\t\")\n\n.decl FieldModifier(modifier:symbol, field:Field)\n.input FieldModifier(IO=file, filename=\"Field-Modifier.facts\", delimiter=\"\\t\")\n\n.decl LoadInstanceField(insn:Insn, index:number, var:Var, base:Var, field:Field, inMethod:Method)\n.input LoadInstanceField\n\n.decl StoreInstanceField(insn:Insn, index:number, var:Var, base:Var, field:Field, inMethod:Method)\n.input StoreInstanceField\n\n.decl LoadStaticField(insn:Insn, index:number, var:Var, field:Field, inMethod:Method)\n.input LoadStaticField\n\n.decl StoreStaticField(insn:Insn, index:number, var:Var, field:Field, inMethod:Method)\n.input StoreStaticField\n\n// Array\n.decl LoadArrayIndex(insn:Insn, index:number, to:Var, array:Var, inMethod:Method)\n.input LoadArrayIndex\n\n.decl StoreArrayIndex(insn:Insn, index:number, from:Var, array:Var, inMethod:Method)\n.input StoreArrayIndex\n\n.decl ComponentType(arrayType:Class, componentType:Class)\n.input ComponentType\n\n// others\n.decl VarType(var:Var, class:Class)\n.input VarType(IO=file, filename=\"Var-Type.facts\", delimiter=\"\\t\")\n\n.decl AssignLocal(insn:Insn, index:number, from:Var, to:Var, inMethod: Method)\n.input AssignLocal\n\n.decl AssignCast(insn:Insn, index:number, from:Var, to:Var, type:Class, inMethod:Method)\n.input AssignCast(IO=file, filename=\"AssignCast.facts\", delimiter=\"\\t\")\n\n.decl AssignHeapAllocation(insn:Insn, index:number, heap:Heap, var:Var, inMethod:Method, linenumber:number)\n.input AssignHeapAllocation\n\n.decl NormalHeap(value:Heap, class:Class)\n.input NormalHeap"
  },
  {
    "path": "logic/one-callsite-sensitive-pt.dl",
    "content": "#pragma once\n#include \"abstract-context-sensitive-pt.dl\"\n\n.type HContext = Insn\n.type Context = Insn\n\n.comp OneCallsiteSensitivePT: AbstractContextSensitivePT<HContext, Context>{\n    .override SelectInvocationContext\n    SelectInvocationContext(callerCtx, insn, baseHeap, hctx, calleeCtx) :-\n        Reachable(caller, callerCtx, _),\n        (\n            SpecialMethodInvocation(insn, _, _, base, caller);\n            VirtualMethodInvocation(insn, _, _, base, caller)\n        ),\n        VarPointsTo(baseHeap, hctx, base, callerCtx),\n        calleeCtx = insn.\n\n    SelectStaticInvocationContext(callerCtx, insn, calleeCtx) :-\n        Reachable(caller, callerCtx, _),\n        StaticMethodInvocation(insn, _, _, caller),\n        calleeCtx = insn.\n}"
  },
  {
    "path": "logic/one-object-sensitive-pt.dl",
    "content": "#pragma once\n#include \"abstract-context-sensitive-pt.dl\"\n\n.type HContext = Heap\n.type Context = Heap\n\n.comp OneObjectSensitivePT: AbstractContextSensitivePT<HContext, Context>{\n    .override SelectInvocationContext\n    SelectInvocationContext(callerCtx, insn, baseHeap, hctx, calleeCtx) :-\n        Reachable(caller, callerCtx, _),\n        (\n            SpecialMethodInvocation(insn, _, _, base, caller);\n            VirtualMethodInvocation(insn, _, _, base, caller)\n        ),\n        VarPointsTo(baseHeap, hctx, base, callerCtx),\n        calleeCtx = baseHeap.\n}"
  },
  {
    "path": "logic/one-type-sensitive-pt.dl",
    "content": "#pragma once\n#include \"abstract-context-sensitive-pt.dl\"\n\n.type HContext = Class\n.type Context = Class\n\n.comp OneTypeSensitivePT: AbstractContextSensitivePT<HContext, Context>{\n    .override SelectInvocationContext\n    SelectInvocationContext(callerCtx, insn, baseHeap, hctx, calleeCtx) :-\n        Reachable(caller, callerCtx, _),\n        (\n            SpecialMethodInvocation(insn, _, _, base, caller);\n            VirtualMethodInvocation(insn, _, _, base, caller)\n        ),\n        VarPointsTo(baseHeap, hctx, base, callerCtx),\n        AssignHeapAllocation(_, _, baseHeap, _, inmethod, _),\n        MethodInfo(inmethod, _, _, inType, _, _, _),\n        calleeCtx = inType.\n}"
  },
  {
    "path": "logic/pt-noctx.dl",
    "content": "#pragma once\n#include \"utils.dl\"\n\n.comp ContextInsensitivePt{\n    .decl VarPointsTo(heap:Heap, var:Var)\n    .decl InstanceFieldPointsTo(heap:Heap, baseHeap:Heap, field:Field)\n    .decl StaticFieldPointsTo(heap:Heap, field:Field)\n    .decl ArrayIndexPointsTo(heap:Heap, baseHeap:Heap)\n    .decl CallGraph(insn:Insn, caller:Method, callee:Method)\n    .decl Reachable(method:Method)\n\n    // new\n    VarPointsTo(heap, var) :-\n        Reachable(method),\n        AssignHeapAllocation(_, _, heap, var, method, _).\n    \n    // assign\n    VarPointsTo(heap, to) :- \n        Reachable(method),\n        VarPointsTo(heap, from),\n        AssignLocal(_, _, from, to, method).\n    \n    // cast\n    VarPointsTo(heap, to) :- \n        Reachable(method),\n        AssignCast(_, _, from, to, _, method),\n        VarPointsTo(heap, from).\n    \n    // load field\n    VarPointsTo(heap, to) :-\n        Reachable(method),\n        LoadInstanceField(_, _, to, base, field, method),\n        VarPointsTo(baseHeap, base),\n        InstanceFieldPointsTo(heap, baseHeap, field).\n    \n    // store field\n    InstanceFieldPointsTo(heap, baseHeap, field) :-\n        Reachable(method),\n        StoreInstanceField(_, _, from, base, field, method),\n        VarPointsTo(heap, from),\n        VarPointsTo(baseHeap, base).\n    \n    // load staic field\n    VarPointsTo(heap, to) :-\n        Reachable(method),\n        LoadStaticField(_, _, to, field, method),\n        StaticFieldPointsTo(heap, field).\n    \n    // store static field\n    StaticFieldPointsTo(heap, field) :-\n        Reachable(method),\n        StoreStaticField(_, _, from, field, method),\n        VarPointsTo(heap, from).\n    \n    // load from array\n    VarPointsTo(heap, to) :-\n        Reachable(method),\n        LoadArrayIndex(_, _, to, base, method),\n        VarPointsTo(baseHeap, base),\n        ArrayIndexPointsTo(heap, baseHeap).\n\n    // store into array\n    ArrayIndexPointsTo(heap, baseHeap) :-\n        Reachable(method),\n        StoreArrayIndex(_, _, from, base, method),\n        VarPointsTo(heap, from),\n        VarPointsTo(baseHeap, base).\n    \n    Reachable(callee),\n    CallGraph(insn, caller, callee) :- \n        Reachable(caller),\n        SpecialMethodInvocation(insn, _, callee, _, caller).\n    \n    Reachable(callee),\n    CallGraph(insn, caller, callee) :- \n        Reachable(caller),\n        StaticMethodInvocation(insn, _, callee, caller).\n    \n    Reachable(callee),\n    CallGraph(insn, caller, callee) :- \n        Reachable(caller),\n        VirtualMethodInvocation(insn, _, method, base, caller),\n        VarPointsTo(baseHeap, base),\n        NormalHeap(baseHeap, class),\n        MethodInfo(method, simplename, _, _, _, descriptor, _),\n        Dispatch(simplename, descriptor, class, callee).\n    \n    // param\n    VarPointsTo(heap, param) :- \n        CallGraph(insn, _, callee),\n        ActualParam(n, insn, arg),\n        FormalParam(n, callee, param),\n        VarPointsTo(heap, arg),\n        NormalHeap(heap, _).\n    \n    // return\n    VarPointsTo(heap, return) :- \n        CallGraph(insn, _, callee),\n        Return(_, _, var, callee),\n        AssignReturnValue(insn, return),\n        VarPointsTo(heap, var).\n    \n    // this\n    VarPointsTo(heap, this) :- \n        CallGraph(insn, _, callee),\n        (\n            VirtualMethodInvocation(insn, _, _, base, _);\n            SpecialMethodInvocation(insn, _, _, base, _)\n        ),\n        ThisVar(callee, this),\n        VarPointsTo(heap, base).\n}\n"
  },
  {
    "path": "logic/ptaint.dl",
    "content": "#pragma once\n#include \"pt-noctx.dl\"\n\n.comp PTaint : ContextInsensitivePt{\n\n    .decl TaintHeap(insn:Insn, heap:Heap)\n    .decl SourceMethod(method:Method)\n    .decl SinkMethod(method:Method, n:number)\n\n    .decl SanitizeMethod(method:Method)\n\n    .decl BaseToRetTransfer(method:Method)\n    .decl ArgToRetTransfer(method:Method, n:number)\n    .decl IsTaintedFrom(insn:Insn, from:Var, to:Var)\n    .decl TransferTaint(heap:Heap, newHeap:Heap)\n    \n    \n    // taint arg to param\n    VarPointsTo(heap, param) :-\n        CallGraph(insn, _, callee),\n        ActualParam(n, insn, arg),\n        FormalParam(n, callee, param),\n        VarPointsTo(heap, arg),\n        TaintHeap(_, heap),\n        !SanitizeMethod(callee).\n    \n    \n    TaintHeap(insn, heap),\n    VarPointsTo(heap, to) :-\n        SourceMethod(callee),\n        CallGraph(insn, _, callee),\n        AssignReturnValue(insn, to),\n        heap = cat(\"NewTainted::\", insn).\n\n    IsTaintedFrom(insn, base, ret) :-\n        CallGraph(insn, _, callee),\n        BaseToRetTransfer(callee),\n        (\n            VirtualMethodInvocation(insn, _, _, base, _);\n            SpecialMethodInvocation(insn, _, _, base, _)\n        ),\n        AssignReturnValue(insn, ret).\n    \n    IsTaintedFrom(insn, arg, ret) :-\n        CallGraph(insn, _, callee),\n        ArgToRetTransfer(callee, n),\n        ActualParam(n, insn, arg),\n        AssignReturnValue(insn, ret).\n\n    TaintHeap(insn, newHeap),\n    TransferTaint(heap, newHeap),\n    VarPointsTo(newHeap, var) :-\n        IsTaintedFrom(insn, from, to),\n        VarPointsTo(heap, from),\n        TaintHeap(_, heap),\n        newHeap = cat(\"TransferTaint::\", insn),\n        VarPointsTo(oldHeap, to),\n        AssignHeapAllocation(_, _, oldHeap, var, _, _).\n}"
  },
  {
    "path": "logic/rta.dl",
    "content": "#pragma once\n#include \"inputDeclaration.dl\"\n#include \"utils.dl\"\n\n.comp RTA{\n    .decl EntryPoint(simplename:symbol, descriptor:symbol, class:Class)\n    .decl Reachable(method:Method, step:number)\n    .decl SinkDesc(simplename:symbol, class:Class)\n    .decl SinkMethod(method:Method)\n    .decl EntryMethod(method:Method)\n    .decl BanCaller(method:Method)\n\n    .decl CallGraph(insn:Insn, caller:Method, callee:Method)\n    .decl InstantiatedClass(insn:Insn, class:Class)\n\n    SinkMethod(method) :-\n        SinkDesc(simplename, class),\n        SubEqClass(subeqclass, class),\n        !ClassModifier(\"abstract\", subeqclass),\n        MethodInfo(method, simplename, _, subeqclass, _, _, _).\n\n    EntryMethod(method),\n    Reachable(method, 0) :-\n        EntryPoint(simplename, descriptor, class),\n        Dispatch(simplename, descriptor, class, method).\n\n    Reachable(callee, n+1),\n    CallGraph(insn, caller, callee) :-\n        Reachable(caller, n),\n        !BanCaller(caller),\n        n < MAXSTEP,\n        SpecialMethodInvocation(insn, _, callee, _, caller).\n\n    Reachable(callee, n+1),\n    CallGraph(insn, caller, callee) :-\n        Reachable(caller, n),\n        !BanCaller(caller),\n        n < MAXSTEP,\n        StaticMethodInvocation(insn, _, callee, caller).\n\n    InstantiatedClass(insn, class) :-\n        Reachable(method, _),\n        AssignHeapAllocation(insn, _, heap, _, method, _),\n        NormalHeap(heap, class).\n\n    Reachable(callee, n+1),\n    CallGraph(insn, caller, callee) :-\n        Reachable(caller, n),\n        !BanCaller(caller),\n        n < MAXSTEP,\n        VirtualMethodInvocation(insn, _, method, receiver, caller),\n        MethodInfo(method, simplename, _, _, _, descriptor, _),\n        VarType(receiver, class),\n        SubEqClass(subeqclass, class),\n        !ClassModifier(\"abstract\", subeqclass),\n        InstantiatedClass(_, subeqclass),\n        Dispatch(simplename, descriptor, subeqclass, callee).\n\n    Reachable(callee, n+1),\n    CallGraph(insn, caller, callee) :-\n        Reachable(caller, n),\n        !BanCaller(caller),\n        n < MAXSTEP,\n        StaticMethodInvocation(insn, _, method, caller),\n        MethodInfo(method, \"doPrivileged\", _, \"java.security.AccessController\", _, _, _),\n        ActualParam(0, insn, param),\n        VarType(param, class),\n        MethodInfo(callee, \"run\", _, class, _, _, 0).\n    \n    // RTAO is RTA OPTIMIZATION LEVEL\n    #if RTAO > 0\n\n    .decl SinkReachable(method:Method, sink:Method, step:number)\n\n    SinkReachable(sink, sink, 0) :-\n        SinkMethod(sink).\n\n    SinkReachable(caller, sink, n+1) :-\n        n < MAXSTEP,\n        SinkReachable(callee, sink, n),\n        CallGraph(_, caller, callee).\n\n    #endif\n\n    #if RTAO > 1\n\n    .decl ShortestPathToSink(caller:Method, sink:Method, step:number)\n\n    ShortestPathToSink(entry, sink, n) :-\n        n = min step : {SinkReachable(entry, sink, step)},\n        SinkMethod(sink),\n        EntryMethod(entry).\n\n    ShortestPathToSink(callee, sink, n-1) :-\n        n < MAXSTEP + 1,\n        ShortestPathToSink(caller, sink, n),\n        SinkReachable(callee, sink, n-1),\n        CallGraph(_, caller, callee).\n\n    #endif\n\n    .decl RefinedReachable(method:Method)\n\n    #ifdef RTAO\n        #if RTAO == 1\n            RefinedReachable(method) :-\n                SinkReachable(method, _, _).\n        #endif\n        #if RTAO == 2\n            RefinedReachable(method) :-\n                ShortestPathToSink(method, _, _).\n        #endif\n    #else\n        RefinedReachable(method) :-\n            Reachable(method, _).\n    #endif\n\n    .decl CallNode(node:Method, label:symbol)\n    .output CallNode\n\n    CallNode(node, \"method\") :-\n        !EntryMethod(node),\n        !SinkMethod(node),\n        RefinedReachable(node).\n\n    CallNode(node, \"sink\") :-\n        RefinedReachable(node),\n        SinkMethod(node).\n\n    CallNode(node, \"entry\") :-\n        RefinedReachable(node),\n        EntryMethod(node).\n\n    .decl CallEdge(caller:Method, callee:Method)\n    .output CallEdge\n\n    CallEdge(caller, callee) :-\n        RefinedReachable(caller),\n        RefinedReachable(callee),\n        CallGraph(_, caller, callee).\n}"
  },
  {
    "path": "logic/simple-cha.dl",
    "content": "#pragma once\n#include \"utils.dl\"\n\n.decl EntryPoint(simplename:symbol, descriptor:symbol, class:Class)\n.decl Reachable(method:Method, step:number)\n.decl SinkDesc(simplename:symbol, class:Class)\n.decl SinkMethod(method:Method)\n.decl EntryMethod(method:Method)\n.decl BanCaller(method:Method)\n\nBanCaller(method) :-\n    MethodInfo(method, simplename, _, class, _, _, _),\n    contains(\"java.util\", class).\n\n.output BanCaller\n\n\n.decl CallGraph(insn:Insn, caller:Method, callee:Method)\n.decl SimpleCallGraph(insn:Insn, caller:Method, callee:Method)\n.decl ChaGraph(caller:Method, implementation:Method, callee:Method)\n\nSinkMethod(method) :-\n    SinkDesc(simplename, class),\n    SubEqClass(subeqclass, class),\n    !MethodModifier(\"abstract\", method),\n    MethodInfo(method, simplename, _, subeqclass, _, _, _).\n\nEntryMethod(method),\nReachable(method, 0) :- \n    EntryPoint(simplename, descriptor, class),\n    Dispatch(simplename, descriptor, class, method).\n\nReachable(callee, n+1),\nSimpleCallGraph(insn, caller, callee),\nCallGraph(insn, caller, callee) :-\n    Reachable(caller, n),\n    !BanCaller(caller),\n    n < MAXSTEP,\n    SpecialMethodInvocation(insn, _, callee, _, caller).\n\nReachable(callee, n+1),\nSimpleCallGraph(insn, caller, callee),\nCallGraph(insn, caller, callee) :-\n    Reachable(caller, n),\n    !BanCaller(caller),\n    n < MAXSTEP,\n    StaticMethodInvocation(insn, _, callee, caller).\n\nReachable(method, n+1),\nReachable(callee, n+1),\nSimpleCallGraph(insn, caller, method),\nCallGraph(insn, caller, callee) :-\n    Reachable(caller, n),\n    !BanCaller(caller),\n    n < MAXSTEP,\n    VirtualMethodInvocation(insn, _, method, receiver, caller),\n    MethodInfo(method, simplename, _, _, _, descriptor, _),\n    VarType(receiver, class),\n    SubEqClass(subeqclass, class),\n    !ClassModifier(\"abstract\", subeqclass),\n    Dispatch(simplename, descriptor, subeqclass, callee).\n\nReachable(callee, n+1),\nSimpleCallGraph(insn, caller, callee),\nCallGraph(insn, caller, callee) :- \n    Reachable(caller, n),\n    !BanCaller(caller),\n    n < MAXSTEP,\n    StaticMethodInvocation(insn, _, method, caller),\n    MethodInfo(method, \"doPrivileged\", _, \"java.security.AccessController\", _, _, _),\n    ActualParam(0, insn, param),\n    VarType(param, class),\n    MethodInfo(callee, \"run\", _, class, _, _, 0).\n\nChaGraph(caller, implementation, callee) :-\n    Reachable(caller, _),\n    MethodInfo(caller, simplename, _, class, _, descriptor, _),\n    SubClass(subclass, class),\n    Dispatch(simplename, descriptor, subclass, implementation),\n    caller != implementation,\n    SimpleCallGraph(_, implementation, callee).\n\n.output ChaGraph\n\n.decl CallNode(node:Method, label:symbol)\n.output CallNode\n\nCallNode(node, \"method\") :-\n    !EntryMethod(node),\n    !SinkMethod(node),\n    Reachable(node, _).\n\nCallNode(node, \"sink\") :-\n    Reachable(node, _),\n    SinkMethod(node).\n\nCallNode(node, \"entry\") :-\n    Reachable(node, _),\n    EntryMethod(node).\n\n.decl CallEdge(caller:Method, callee:Method)\n.output CallEdge\n\nCallEdge(caller, callee) :-\n    SimpleCallGraph(_, caller, callee).\n"
  },
  {
    "path": "logic/utils.dl",
    "content": "#pragma once\n#include \"inputDeclaration.dl\"\n\n//self define relation\n\n// Utils\n.decl SubClass(subclass:Class, class:Class)\n.decl SubEqClass(subeqclass:Class, class:Class)\n\nSubEqClass(\"byte\", \"byte\").\nSubEqClass(\"byte[]\", \"byte[]\").\n\nSubEqClass(subclass, class) :- SubClass(subclass, class).\nSubEqClass(class, class) :- ClassType(class).\n\nSubClass(subclass, class) :- DirectSuperclass(subclass, class).\nSubClass(subclass, class) :- DirectSuperinterface(subclass, class).\nSubClass(subclass, class) :- \n    (\n        DirectSuperclass(subclass, tmp);\n        DirectSuperinterface(subclass, tmp)\n    ),\n    SubClass(tmp, class).\n\n.decl AbstractType(type:Class)\n\nAbstractType(type) :- \n    ClassModifier(\"abstract\", type).\n\n.decl Dispatch(simplename:symbol, descriptor:symbol, class:Class, method:Method)\n\nDispatch(simplename, descriptor, class, method) :-\n    MethodInfo(method, simplename, _, class, _, descriptor, _),\n    !MethodModifier(\"abstract\", method).\n\nDispatch(simplename, descriptor, class, method) :-\n    !MethodInfo(_, simplename, _, class, _, descriptor, _),\n    DirectSuperclass(class, superclass),\n    Dispatch(simplename, descriptor, superclass, method),\n    !MethodModifier(\"abstract\", method).\n"
  },
  {
    "path": "neo4j/CallEdgeHeader.csv",
    "content": ":START_ID(Method)\tinsn\t:END_ID(Method)"
  },
  {
    "path": "neo4j/CallNodeHeader.csv",
    "content": "method:ID(Method)\t:LABEL"
  },
  {
    "path": "neo4j/ChaEdgeHeader.csv",
    "content": ":START_ID(Method)\tmethod\t:END_ID(Method)"
  },
  {
    "path": "neoImportCall-4.4.sh",
    "content": "#!/bin/bash\n\ndbname=$1$(date \"+%m%d%H%M\")\n\nneo4j-admin database import full --relationships=Call=\"/bytecodedl/neo4j/CallEdgeHeader.csv,/bytecodedl/output/.*CallEdge.csv\" --nodes=\"/bytecodedl/neo4j/CallNodeHeader.csv,/bytecodedl/output/.*CallNode.csv\"  --delimiter=\"\\t\" $dbname\n\nif grep -q \"dbms.active_database\" /var/lib/neo4j/conf/neo4j.conf; then\n    sed -i -E \"s/dbms.active_database=\\w+/dbms.active_database=$dbname/g\" /var/lib/neo4j/conf/neo4j.conf\nelse\n    echo \"dbms.active_database=$dbname\" >> /var/lib/neo4j/conf/neo4j.conf\nfi\n"
  },
  {
    "path": "neoImportCall.sh",
    "content": "#!/bin/bash\n\ndbname=$1$(date \"+%m%d%H%M\")\n\nneo4j-admin database import full --nodes=\"/bytecodedl/neo4j/CallNodeHeader.csv,/bytecodedl/output/.*CallNode.csv\" --relationships=Call=\"/bytecodedl/neo4j/CallEdgeHeader.csv,/bytecodedl/output/CallEdge.csv\" --delimiter=\"\\t\" $dbname\n\nif grep -q \"#initial.dbms.default_database\" /var/lib/neo4j/conf/neo4j.conf; then\n    sed -i -E \"s/#initial.dbms.default_database=\\S+/initial.dbms.default_database=$dbname/g\" /var/lib/neo4j/conf/neo4j.conf\nelse\n    sed -i -E \"s/initial.dbms.default_database=\\S+/initial.dbms.default_database=$dbname/g\" /var/lib/neo4j/conf/neo4j.conf\nfi\n"
  },
  {
    "path": "neoImportChaCall-4.4.sh",
    "content": "#!/bin/bash\n\ndbname=$1$(date \"+%m%d%H%M\")\n\nneo4j-admin database import --nodes=Method=\"/bytecodedl/neo4j/CallNodeHeader.csv,/bytecodedl/output/.*CallNode.csv\" --relationships=Call=\"/bytecodedl/neo4j/CallEdgeHeader.csv,/bytecodedl/output/CallEdge.csv\" --relationships=Cha=\"/bytecodedl/neo4j/ChaEdgeHeader.csv,/bytecodedl/output/ChaGraph.csv\" --database=$dbname --delimiter=\"\\t\"\n\nif grep -q \"dbms.active_database\" /var/lib/neo4j/conf/neo4j.conf; then\n    sed -i -E \"s/dbms.active_database=\\w+/dbms.active_database=$dbname/g\" /var/lib/neo4j/conf/neo4j.conf\nelse\n    echo \"dbms.active_database=$dbname\" >> /var/lib/neo4j/conf/neo4j.conf\nfi\n"
  },
  {
    "path": "neoImportChaCall.sh",
    "content": "#!/bin/bash\n\ndbname=$1$(date \"+%m%d%H%M\")\n\nneo4j-admin database import full --nodes=Method=\"/bytecodedl/neo4j/CallNodeHeader.csv,/bytecodedl/output/.*CallNode.csv\" --relationships=Call=\"/bytecodedl/neo4j/CallEdgeHeader.csv,/bytecodedl/output/CallEdge.csv\" --relationships=Cha=\"/bytecodedl/neo4j/ChaEdgeHeader.csv,/bytecodedl/output/ChaEdge.csv\" --delimiter=\"\\t\" $dbname\n\nif grep -q \"#initial.dbms.default_database\" /var/lib/neo4j/conf/neo4j.conf; then\n    sed -i -E \"s/#initial.dbms.default_database=\\w+/initial.dbms.default_database=$dbname/g\" /var/lib/neo4j/conf/neo4j.conf\nelse\n    sed -i -E \"s/initial.dbms.default_database=\\w+/initial.dbms.default_database=$dbname/g\" /var/lib/neo4j/conf/neo4j.conf\nfi\n"
  },
  {
    "path": "output/readme.md",
    "content": "# output\n\n这个目录用于放置输出结果"
  }
]