{"id":31053093,"url":"https://github.com/lunar-rf/cdl86","last_synced_at":"2025-09-15T01:52:01.279Z","repository":{"id":154754799,"uuid":"582248748","full_name":"lunar-rf/cdl86","owner":"lunar-rf","description":"Tiny C x86_64 function detouring library.","archived":false,"fork":false,"pushed_at":"2025-09-07T23:16:13.000Z","size":168,"stargazers_count":26,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-08T00:24:15.268Z","etag":null,"topics":["detours","hooking-library","ida-pro","linux","reverse-engineering","windows"],"latest_commit_sha":null,"homepage":"https://journal.lunar.sh/2022/linux-detours.html","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lunar-rf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-12-26T08:04:07.000Z","updated_at":"2025-09-07T23:16:16.000Z","dependencies_parsed_at":"2024-01-27T08:25:10.021Z","dependency_job_id":"67d95545-e6e4-4e53-91e1-4b2d2a68fd91","html_url":"https://github.com/lunar-rf/cdl86","commit_stats":null,"previous_names":["lunarbin/cdl86","lunarjournal/cdl86","lunar-sh/cdl86","lunar-rf/cdl86"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lunar-rf/cdl86","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lunar-rf%2Fcdl86","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lunar-rf%2Fcdl86/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lunar-rf%2Fcdl86/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lunar-rf%2Fcdl86/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lunar-rf","download_url":"https://codeload.github.com/lunar-rf/cdl86/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lunar-rf%2Fcdl86/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275194022,"owners_count":25421441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["detours","hooking-library","ida-pro","linux","reverse-engineering","windows"],"created_at":"2025-09-15T01:52:00.400Z","updated_at":"2025-09-15T01:52:01.263Z","avatar_url":"https://github.com/lunar-rf.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cdl86\r\n\r\n```\r\n  ________  __   ___  ____\r\n / ___/ _ \\/ /  ( _ )/ __/\r\n/ /__/ // / /__/ _  / _ \\ \r\n\\___/____/____/\\___/\\___/ \r\n```\r\n                          \r\n`cdl86` - `Compact Detours Library 86`\r\n\r\n\u003e **Demo Projects** \u003cbr\u003e\r\n\u003e [`gsctool`](https://github.com/lunar-sh/gsctool)\r\n\u003e [`cs2rec`](https://github.com/FASTCUP/cs2rec)\r\n\r\n# Abstract\r\n`cdl86` is a tiny, single file, cross platform `detours` library written in `C` in less than `1K` lines.\r\n\r\n[`https://journal.lunar.sh/2022/linux-detours.html`](https://journal.lunar.sh/2022/linux-detours.html)\r\n\r\nIt allows for the interception of `x86` and `x86_64` `C/C++` binary functions in memory following code injection.\r\n\r\nCurrently the following platforms are supported:\r\n- `Linux`\r\n- `MS Windows`\r\n\r\nThe library currently supports two types of function hooks:\r\n* `JMP` patch - patches origin function with a `JMP` to detour.\r\n* `INT3` patch - places software breakpoint (`SWBP`) at origin address.\u003cbr\u003e\r\nHandles `control flow` to `detour`.\r\n\r\n\u003e Note: This project makes use of an internal `x86` instruction length disassembly engine.\r\n\r\n# API\r\n```\r\nstruct cdl_jmp_patch cdl_jmp_attach(void **target, void *detour);\r\nstruct cdl_swbp_patch cdl_swbp_attach(void **target, void *detour);\r\nvoid cdl_jmp_detach(struct cdl_jmp_patch *jmp_patch);\r\nvoid cdl_swbp_detach(struct cdl_swbp_patch *swbp_patch);\r\nvoid cdl_jmp_dbg(struct cdl_jmp_patch *jmp_patch);\r\nvoid cdl_swbp_dbg(struct cdl_swbp_patch *swbp_patch);\r\n```\r\nThe `API` is documented in more detail in the corresponding `header` and `source`\r\nfiles.\r\n\r\n# Example Usage\r\n\r\nAssuming we have a function `add()` that is defined as follows:\r\n```\r\nint add(\r\n    __in int x,\r\n    __in int y\r\n)\r\n{\r\n    printf(\"Inside original function\\n\");\r\n    return x + y;\r\n}\r\n```\r\n\r\nAssuming we want to hook this function with `cdl86` the first step\r\nis to define a function pointer `typedef` and declare our `detour` function:\r\n\r\n```\r\ntypedef int add_t(\r\n    __in int x,\r\n    __in int y\r\n);\r\nadd_t* addo = NULL;\r\n```\r\n```\r\n// define detour function\r\nint add_detour(\r\n    __in int x,\r\n    __in int y\r\n)\r\n{\r\n    printf(\"Inside detour function\\n\");\r\n    return addo(5,5);\r\n}\r\n\r\n```\r\nThen in our `main()` function we create a `cdl_jmp_patch` struct and assign\r\na value to `addo` (our function pointer to the original function):\r\n```\r\nstruct cdl_jmp_patch jmp_patch = {};\r\naddo = (add_t*)add;\r\n```\r\n\r\nFinally call `cdl_jmp_attach` as follows:\r\n```\r\njmp_patch = cdl_jmp_attach((void**)\u0026addo, add_detour);\r\n```\r\n\r\nThe original function `add` has now been hooked!\r\n\r\nTo dump `debug` info from the `cdl_jmp_patch` struct use `cdl_jmp_dbg`.\r\n\r\n# Info\r\n\r\nThe compiler used for this project is [`tcc`](https://github.com/lunar-sh/tcc).\r\n\r\nFiles:\r\n\u003cbr/\u003e\r\n* `cdl.c` - `C` source file for `CDL`.\r\n* `cdl.h` - `CDL` header file to include.\r\n\r\nFolders:\r\n* `/tests` - `CDL` test suite.\r\n\r\n# Signature\r\n\r\n```\r\n+---------------------------------------+\r\n|     .-.       .-.       .-.           |\r\n|    /   \\     /   \\     /   \\     +    |\r\n|         \\   /     \\   /     \\   /     |\r\n|          \"_\"       \"_\"       \"_\"      |\r\n|                                       |\r\n|  _   _   _ _  _   _   ___   ___ _  _  |\r\n| | | | | | | \\| | /_\\ | _ \\ / __| || | |\r\n| | |_| |_| | .` |/ _ \\|   /_\\__ \\ __ | |\r\n| |____\\___/|_|\\_/_/ \\_\\_|_(_)___/_||_| |\r\n|                                       |\r\n|                                       |\r\n| Lunar RF Labs                         |\r\n| https://lunar.sh                      |\r\n|                                       |\r\n| Research Laboratories                 |\r\n| Copyright (C) 2022-2024               |\r\n|                                       |\r\n+---------------------------------------+\r\n```\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flunar-rf%2Fcdl86","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flunar-rf%2Fcdl86","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flunar-rf%2Fcdl86/lists"}