{"id":13812933,"url":"https://github.com/everettjf/WasmPatch","last_synced_at":"2025-05-14T22:31:19.465Z","repository":{"id":56927285,"uuid":"276706754","full_name":"everettjf/WasmPatch","owner":"everettjf","description":"🧱Yet Another Patch Module for iOS/macOS via WebAssembly","archived":false,"fork":false,"pushed_at":"2021-09-12T01:07:08.000Z","size":402,"stargazers_count":87,"open_issues_count":0,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-03-14T15:49:38.647Z","etag":null,"topics":["libffi","objective-c","patch","wasm","webassembly"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/everettjf.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}},"created_at":"2020-07-02T17:24:43.000Z","updated_at":"2024-03-14T15:49:38.647Z","dependencies_parsed_at":"2022-08-21T04:20:57.296Z","dependency_job_id":null,"html_url":"https://github.com/everettjf/WasmPatch","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everettjf%2FWasmPatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everettjf%2FWasmPatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everettjf%2FWasmPatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everettjf%2FWasmPatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/everettjf","download_url":"https://codeload.github.com/everettjf/WasmPatch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254239540,"owners_count":22037722,"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":["libffi","objective-c","patch","wasm","webassembly"],"created_at":"2024-08-04T04:00:58.204Z","updated_at":"2025-05-14T22:31:14.422Z","avatar_url":"https://github.com/everettjf.png","language":"C","readme":"# WasmPatch\n\n*Yet Another Patch Module for iOS/macOS via WebAssembly* \n\n[![GitHub issues](https://img.shields.io/github/issues-raw/everettjf/WasmPatch?style=flat-square\u0026label=issues\u0026color=success)](https://github.com/everettjf/WasmPatch/issues) \n[![GitHub license](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/everettjf/WasmPatch)\n\n\nWasmPatch bridges `Objective-C and WebAssembly`. We `build C code into WebAssembly`, and have the ability to `call any Objective-C class and method dynamically`. This makes the App obtaining the power of WebAssembly: add features or replacing Objective-C code to fix bugs dynamically.\n\nWasmPatch is a **DEMO** now, and is still in development, welcome to improve the project together.\n\n[![Twitter](https://img.shields.io/twitter/follow/everettjf?style=flat-square\u0026color=1da1f2\u0026label=twitter\u0026logo=twitter)](https://twitter.com/everettjf) \n[![Discord](https://img.shields.io/discord/728632973670219870?style=flat-square\u0026logo=discord\u0026color=7289da\u0026label=discord)](https://discord.gg/7qWjfzj)\n[![Telegram](https://img.shields.io/badge/telegram-chat-0088cc?style=flat-square\u0026logo=telegram)](https://t.me/wasmpatch)\n\n## How it work\n\n![WasmPatch](Image/WasmPatch.png)\n\n\u003cimg align=\"right\" width=\"311\" height=\"118\" src=\"/Image/wechat.png\"\u003e\n\n- 中文介绍: 请关注微信订阅号，搜索「WasmPatch探索之路」文章。\n\n## Example\n\n[View Source Directly](https://github.com/everettjf/WasmPatch/blob/master/TestCase/WasmPatch-TestCase/Assets/script.bundle/objc.c)\n\n### Call Method\n\n```\n// method call - class method\ncall_class_method_0(\"CallMe\", \"sayHi\");\n    \nWAPObject word = new_objc_nsstring(\"I am from c program\");\ncall_class_method_1(\"CallMe\", \"sayWord:\", word);\ndealloc_object(word);\n\n// method call - instance method\nWAPObject call = alloc_objc_class(\"CallMe\");\ncall_instance_method_0(call,\"sayHi\");\ndealloc_object(call);\n\nWAPObject call1 = alloc_objc_class(\"CallMe\");\nword = new_objc_nsstring(\"I am from c program\");\ncall_instance_method_1(call1,\"sayWord:\", word);\ndealloc_object(word);\ndealloc_object(call1);\n```\n\n### Replace Method\n\n```\n\nint my_class_ReplaceMe_request(WAPObject self, const char * cmd) {\n    print_string(\"replaced + ReplaceMe request\");\n    return 0;\n}\n\nint my_class_ReplaceMe_requestfromto(WAPObject self, const char * cmd, WAPArray parameters) {\n    print_string(\"replaced + ReplaceMe requestFrom:Two to:One\");\n    return 0;\n}\nint my_instance_ReplaceMe_request(WAPObject self, const char * cmd) {\n    print_string(\"replaced - ReplaceMe request\");\n    return 0;\n}\n\nint my_instance_ReplaceMe_requestfromto(WAPObject self, const char * cmd, WAPArray parameters) {\n    print_string(\"replaced - ReplaceMe requestFrom:Two to:One\");\n    return 0;\n}\n\nint entry() {\n    // method replace\n    replace_class_method(\"ReplaceMe\", \"request\", \"my_class_ReplaceMe_request\");\n    replace_class_method(\"ReplaceMe\", \"requestFrom:to:\", \"my_class_ReplaceMe_requestfromto\");\n\n    replace_instance_method(\"ReplaceMe\", \"request\", \"my_instance_ReplaceMe_request\");\n    replace_instance_method(\"ReplaceMe\", \"requestFrom:to:\", \"my_instance_ReplaceMe_requestfromto\");\n}\n```\n\n### Call with many arguments\n\n```\n// many arguments\nWAPArray params = alloc_array();\nappend_array(params, alloc_int32(10));\nappend_array(params, alloc_int64(666));\nappend_array(params, alloc_float(7.77));\nappend_array(params, alloc_double(200.2222));\nappend_array(params, new_objc_nsstring(\"excellent\"));\nappend_array(params, alloc_string(\"WebAssembly\"));\ncall_class_method_param(\"CallMe\", \"callWithManyArguments:p1:p2:p3:p4:p5:\", params);\ndealloc_array(params);\n```\n\n### Environment\n\n- iOS/macOS.\n- Tested: arm64/arm64e/x86_64 , Should work: armv7/armv7s/i386.\n- C++17 standard.\n\n## Quick playing with Demo\n\n```\ncd Demo \u0026\u0026 sh podinstall_all.sh\n```\n\n- iOS demo: open `Demo/WasmPatch-iOS/WasmPatch-iOS.xcworkspace`\n- macOS demo: open `Demo/WasmPatch-macOS/WasmPatch-macOS.xcworkspace`\n\n## Usage\n\n### Build C into WebAssembly\n\nTo build c code into WebAssembly, we need to install llvm.\n\n```\nbrew update\nbrew install llvm\n```\n\n### Playing with Demo\n\nDemo c code for patch building:\n\n```\nTestCase/WasmPatch-TestCase/Assets/script.bundle/objc.c\n```\n\nRun `compile-testcase.sh` to build it.\n\n```\ncd TestCase \u0026\u0026 sh compile-testcase.sh\n```\n\nIt will call `Tool/c2wasm.sh` internal.\n\nThen, `Pod install` iOS and macOS demo.\n\n```\ncd Demo \u0026\u0026 sh podinstall_all.sh\n```\n\nOpen `Demo/WasmPatch-iOS/WasmPatch-iOS.xcworkspace` for iOS demo, or open `Demo/WasmPatch-macOS/WasmPatch-macOS.xcworkspace` for macOS demo.\n\n\n### Build Patch\n\n```\n./Tool/c2wasm.sh input.c output.wasm\n```\n\n### Load Patch\n\n```\n// header file\n#import \u003cWasmPatch/WasmPatch.h\u003e\n\n// ...\n\n// call wap_load_file to load wasm file\nNSString *scriptPath = [scriptBundlePath stringByAppendingPathComponent:@\"objc.wasm\"];\nbool result = wap_load_file(scriptPath.UTF8String);\nif (!result) {\n    NSLog(@\"failed load file %@\", scriptPath);\n    return;\n}\n```\n\n\n## Installation\n\n### CocoaPods\n\n```\n// local pod\npod 'WasmPatch', :path =\u003e '../../'\n\n// online pod\npod 'WasmPatch'\n```\n\n### Manual\n\nDrag `WasmPatch` directory into project, and configure `Header Search Path` to `WasmPatch/Classes/wap/depend/libffi/include`\n\n\n\n## Thanks\n\n- wasm3 https://github.com/wasm3/wasm3\n- libffi https://github.com/libffi/libffi\n- JSPatch https://github.com/bang590/JSPatch\n\n\n---\n\nWish you enjoy :)\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverettjf%2FWasmPatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feverettjf%2FWasmPatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverettjf%2FWasmPatch/lists"}