{"id":19456724,"url":"https://github.com/x0reaxeax/smol_helloworld","last_synced_at":"2025-07-18T20:32:24.847Z","repository":{"id":134817029,"uuid":"459176486","full_name":"x0reaxeax/smol_helloworld","owner":"x0reaxeax","description":"Shortest Hello World code in C - 0 characters source file! ","archived":false,"fork":false,"pushed_at":"2022-06-04T23:30:15.000Z","size":24,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-03T08:03:17.179Z","etag":null,"topics":["c","hello-world","helloworld","shortest-code"],"latest_commit_sha":null,"homepage":"","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/x0reaxeax.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}},"created_at":"2022-02-14T13:37:24.000Z","updated_at":"2024-12-23T06:14:39.000Z","dependencies_parsed_at":"2023-04-29T07:48:48.509Z","dependency_job_id":null,"html_url":"https://github.com/x0reaxeax/smol_helloworld","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/x0reaxeax/smol_helloworld","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x0reaxeax%2Fsmol_helloworld","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x0reaxeax%2Fsmol_helloworld/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x0reaxeax%2Fsmol_helloworld/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x0reaxeax%2Fsmol_helloworld/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/x0reaxeax","download_url":"https://codeload.github.com/x0reaxeax/smol_helloworld/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x0reaxeax%2Fsmol_helloworld/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265828549,"owners_count":23835078,"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":["c","hello-world","helloworld","shortest-code"],"created_at":"2024-11-10T17:18:17.640Z","updated_at":"2025-07-18T20:32:24.825Z","avatar_url":"https://github.com/x0reaxeax.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Very smol C hello world, 0 characters!\n\n### Challenge rules:\n- [x] No binary modifications  \n- [x] No external libraries or code\n- [x] OS is Linux (3.7 i686)\n- [x] GCC compiler (gcc version 4.7.2)\n- [x] This (preprocessor macros) is not allowed: `$ gcc smoll.c -D\"_=int main() {puts(\\\"hello world\\\");}\"`\n\n### Approach:\n(Ab)Use GCC's `__FILE__` preprocessor macro, which holds source filename string.  \n**Example:**\n```c\n/* file - 'test.c' */\n  ...\n  printf(\"%s\\n\", __FILE__);\n  ...\n```\nOutputs:\n```\ntest.c\n```\nWe could either settle for 27 characters with:\n```c\nint main(){puts(__FILE__);}\n```\n\n...or we could load our source filename with opcodes!  \n**There are 2 things that complicate this:**\n1. Newline character (0x0a) cuts the filename\n2. We can't use nullbyte basically for the exact same reason  \n(might be able to overcome this with a pair of double-quotes..)  \n  \n**Workaround:**\nJust avoid `mov`s and `lea`s with 0s! \n\n```asm\n_start:\n    xor eax, eax\n    xor ebx, ebx\n    xor edx, edx\n    \n    inc ebx\n\n    add al,  0x4        ; sys_write = 4\n    add edx, 0xb        ; strlen = 11 (actually 10, but (int) 10 (0xa) is ASCII newline, which we can't use)\n    \n    mov ecx, 0x8048285  ; __FILE__ magic address (0x804826d) + offset to \"helloworld!\"\n    int 0x80\n    \n    xor eax, eax\n    inc eax            ; sys_exit = 1\n    int 0x80\n```\n\nThis with appended \"helloworld!\" translates to:\n\n```c\nunsigned char bytecode[] = {  \n        0x31, 0xc0,\n        0x31, 0xdb,\n        0x31, 0xd2,\n\n        0x43,\n        0x04, 0x04,\n        0x83, 0xc2, 0x0b,\n\n        0xb9, 0x85, 0x82, 0x04, 0x08,\n        0xcd, 0x80,\n        \n        0x31, 0xc0,\n        0x40,\n        0xcd, 0x80,\n\n        0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21\n};\n```\n\nNow we have to rename our c source file with these bytes:\n```c\n/* craft.c */\n\n#include \u003cstdio.h\u003e\n\nint main(void) {\n  unsigned char bytecode[] { ... };\n  rename(\"test.c\", bytecode);\n  return 0;\n}\n```\n\nLast thing.. just create an empty source file named `test.c`  \nSo yea, 0 characters C \"Hello World\".\n\nGreat, now for the final step - compilation!\n```sh\ngcc -nostdlib -z execstack -e 0x804826d -x c {GARBAGE_NAME}\n```\n\n.. or just run `make`!  \n\n```\n$ ./a.out\nhelloworld!\n```\n\nyaaaaaaaaaaaayyyy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx0reaxeax%2Fsmol_helloworld","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fx0reaxeax%2Fsmol_helloworld","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx0reaxeax%2Fsmol_helloworld/lists"}