{"id":20183753,"url":"https://github.com/glavo/foreign-hacker","last_synced_at":"2025-10-08T02:50:11.793Z","repository":{"id":134537345,"uuid":"348541025","full_name":"Glavo/foreign-hacker","owner":"Glavo","description":"Foreign Linker API Hack","archived":false,"fork":false,"pushed_at":"2021-09-19T12:34:16.000Z","size":71,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-03T06:27:25.280Z","etag":null,"topics":["ffi","java","jni","panama"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Glavo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-03-17T01:17:33.000Z","updated_at":"2023-08-24T14:58:15.000Z","dependencies_parsed_at":"2023-06-17T15:15:28.846Z","dependency_job_id":null,"html_url":"https://github.com/Glavo/foreign-hacker","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Glavo/foreign-hacker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavo%2Fforeign-hacker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavo%2Fforeign-hacker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavo%2Fforeign-hacker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavo%2Fforeign-hacker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Glavo","download_url":"https://codeload.github.com/Glavo/foreign-hacker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavo%2Fforeign-hacker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278881673,"owners_count":26062176,"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-10-08T02:00:06.501Z","response_time":56,"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":["ffi","java","jni","panama"],"created_at":"2024-11-14T02:47:08.819Z","updated_at":"2025-10-08T02:50:11.764Z","avatar_url":"https://github.com/Glavo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Foreign Linker Hacker\n\n[![](https://jitpack.io/v/Glavo/foreign-hacker.svg)](https://jitpack.io/#Glavo/foreign-hacker)\n\nAllows programmers to enable the [Foreign Linker API](https://openjdk.java.net/jeps/389) without adding JVM parameters `-Dforeign.restricted=permit` or `--ensure-native-access`.\n\nJava 16 or higher is required. \n\nThis library can't avoid other limitations of the incubator module. \nYou still need to add `--add-module jdk.incubator.foreign` and  `--enable-preview` options to JVM for use `jdk.incubator.foreign` module.\n\n## Usage: \n\n```java \nForeignHacker.enableForeignAccess(module);\n```\n\n\u003c!--\nThe effect of calling this method is similar to starting the JVM with the `-Dforeign.restricted=permit` option,\nwill allow programmers to use the [Foreign Linker API](https://openjdk.java.net/jeps/389).\n\nNode: `System.setProperty(\"foreign.restricted\", \"permit\")` doesn't work,\nForeign Linker API only detects the value of property `foreign.restricted` passed in when the JVM is started.\n--\u003e\n\n## Add to your build\n\n### Download jar directly\n\nPlease visit [releases](https://github.com/Glavo/foreign-hacker/releases/latest).\n\n### Gradle\n```groovy\nrepositories {\n    maven { url 'https://jitpack.io' }\n}\n\nimplementation group: 'org.glavo', name: 'foreign-hacker', version: \"0.2.1\"\n```\n\n## Example\n```java\nimport jdk.incubator.foreign.*;\nimport org.glavo.foreign.hacker.ForeignHacker;\n\nimport java.lang.invoke.MethodType;\n\npublic final class Main {\n    public static void main(String[] args) throws Throwable {\n        ForeignHacker.enableForeignAccess(Main.class.getModule());\n\n        LibraryLookup l = LibraryLookup.ofDefault();\n        var handle = CLinker.getInstance().downcallHandle(\n                l.lookup(\"strlen\").orElse(null),\n                MethodType.methodType(int.class, MemoryAddress.class),\n                FunctionDescriptor.of(CLinker.C_INT, CLinker.C_POINTER)\n        );\n        try (MemorySegment str = CLinker.toCString(\"str\")) {\n            System.out.println((int) handle.invokeExact(str.address()));\n        }\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglavo%2Fforeign-hacker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglavo%2Fforeign-hacker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglavo%2Fforeign-hacker/lists"}