{"id":28984410,"url":"https://github.com/dnakov/r2ai.c","last_synced_at":"2025-06-24T17:10:22.044Z","repository":{"id":296696897,"uuid":"985048236","full_name":"dnakov/r2ai.c","owner":"dnakov","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-31T05:51:47.000Z","size":317,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-19T04:53:14.028Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dnakov.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}},"created_at":"2025-05-17T01:09:36.000Z","updated_at":"2025-05-21T19:11:45.000Z","dependencies_parsed_at":"2025-06-01T20:55:39.104Z","dependency_job_id":"01d82793-57f8-44b6-9b29-4e57c8d578de","html_url":"https://github.com/dnakov/r2ai.c","commit_stats":null,"previous_names":["dnakov/r2ai.c"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dnakov/r2ai.c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnakov%2Fr2ai.c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnakov%2Fr2ai.c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnakov%2Fr2ai.c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnakov%2Fr2ai.c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dnakov","download_url":"https://codeload.github.com/dnakov/r2ai.c/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnakov%2Fr2ai.c/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261721228,"owners_count":23199638,"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","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":[],"created_at":"2025-06-24T17:10:21.159Z","updated_at":"2025-06-24T17:10:22.028Z","avatar_url":"https://github.com/dnakov.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C-R2AI\n\nThis directory contains the C rewrite of the r2ai plugin for radare2.\n\n## Installation\n\nRequires radare2 from git if you want to use the stream HTTP APIs.\n\nOtherwise the only requirement is a C compiler.\n\n```console\nmake\nmake user-install\n```\n\n## Features\n\n* Decompilation into any programming language\n* Explain weaknesses and purpose of a function\n* Function and local variable renaming, type propagation\n* Ollama by default, any other remote AI service as choice\n* Auto mode and function calling with any model\n* Fix and improve function signatures\n* Assistant mode with a REPL chat\n\n## Experimental\n\n* Own vector database for embeddings\n* Custom reasoning engine with any model\n\n## Usage\n\n```console\n[0x100003f58]\u003e r2ai -h\nUsage: r2ai   [-args] [...]\n| r2ai -d                 Decompile current function\n| r2ai -dr                Decompile current function (+ 1 level of recursivity)\n| r2ai -a [query]         Resolve question using auto mode\n| r2ai -e                 Same as '-e r2ai.'\n| r2ai -h                 Show this help message\n| r2ai -i [file] [query]  read file and ask the llm with the given query\n| r2ai -m                 show selected model, list suggested ones, choose one\n| r2ai -M                 show suggested models for each api\n| r2ai -n                 suggest a better name for the current function\n| r2ai -r                 enter the repl\n| r2ai -R ([text])        refresh and query embeddings (see r2ai.data)\n| r2ai -s                 function signature\n| r2ai -x                 explain current function\n| r2ai -v                 suggest better variables names and types\n| r2ai -V[r]              find vulnerabilities in the decompiled code (-Vr uses -dr)\n| r2ai [arg]              send a post request to talk to r2ai and print the output\n[0x100003f58]\u003e \n```\n\n## Example\n\nSee [https://github.com/radareorg/r2ai-examples](https://github.com/radareorg/r2ai-examples)\n\n```c\n[0x100003f58]\u003e r2ai -e api=claude\n[0x100003f58]\u003e r2ai -d\nint main(int argc, char **argv, char **envp) {\n    char buffer[32];\n    int result = 0;\n    if (argv[1] != NULL) {\n        strcpy_chk(buffer, argv[1], 32);\n    }\n    return result;\n}\n[0x100003f58]\u003e \n```\n\n## TODO\n\n* add \"undo\" command to drop the last message\n* dump / restore conversational states (see -L command)\n* Implement `~`, `|` and `\u003e` and other r2shell features\n\n\n## Messages API\n\nThe r2ai project includes a new API for managing messages and tool calls in conversations with AI models. This API is implemented in `messages.c` and `messages.h`.\n\n### Key Functions\n\n- `r2ai_messages_new()`: Create a new messages array\n- `r2ai_messages_free(msgs)`: Free a messages array and all associated data\n- `r2ai_messages_add(msgs, role, content, tool_call_id)`: Add a new message\n- `r2ai_messages_add_tool_call(msgs, name, arguments, id)`: Add a tool call to the last message\n- `r2ai_messages_last(msgs)`: Get the last message in the array\n- `r2ai_messages_parse_json(msgs, json)`: Parse a JSON response into messages\n- `r2ai_messages_clear(msgs)`: Clear all messages\n\n### Example Usage\n\n```c\n// Create a new messages array\nR2AI_Messages *msgs = r2ai_messages_new();\n\n// Add a user message\nr2ai_messages_add(msgs, \"user\", \"What is the disassembly of function main?\", NULL);\n\n// Add an assistant message with a tool call\nR2AI_Message *msg = r2ai_messages_add(msgs, \"assistant\", NULL, NULL);\nr2ai_messages_add_tool_call(msgs, \"r2cmd\", \"{\\\"command\\\":\\\"pdf@main\\\"}\", \"tool-123\");\n\n// Free all resources when done\nr2ai_messages_free(msgs);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnakov%2Fr2ai.c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdnakov%2Fr2ai.c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnakov%2Fr2ai.c/lists"}