{"id":19054828,"url":"https://github.com/zhuagenborn/cpp-struct-byte-order-converter","last_synced_at":"2025-10-26T19:17:17.281Z","repository":{"id":251343992,"uuid":"836150870","full_name":"Zhuagenborn/Cpp-Struct-Byte-Order-Converter","owner":"Zhuagenborn","description":"⚒ A script used to generate byte reversing functions for a C/C++ structure.","archived":false,"fork":false,"pushed_at":"2024-10-14T03:35:39.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-02T11:11:51.083Z","etag":null,"topics":["big-endian","byte-order","endianness","little-endian"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","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/Zhuagenborn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-31T08:55:39.000Z","updated_at":"2024-10-14T03:35:43.000Z","dependencies_parsed_at":"2024-08-05T03:07:42.855Z","dependency_job_id":"1e35ebee-68c9-4286-a387-e1e6af266771","html_url":"https://github.com/Zhuagenborn/Cpp-Struct-Byte-Order-Converter","commit_stats":null,"previous_names":["zhuagenborn/cpp-struct-byte-order-converter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zhuagenborn%2FCpp-Struct-Byte-Order-Converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zhuagenborn%2FCpp-Struct-Byte-Order-Converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zhuagenborn%2FCpp-Struct-Byte-Order-Converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zhuagenborn%2FCpp-Struct-Byte-Order-Converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zhuagenborn","download_url":"https://codeload.github.com/Zhuagenborn/Cpp-Struct-Byte-Order-Converter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240110412,"owners_count":19749293,"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":["big-endian","byte-order","endianness","little-endian"],"created_at":"2024-11-08T23:39:53.858Z","updated_at":"2025-10-26T19:17:12.255Z","avatar_url":"https://github.com/Zhuagenborn.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# *C/C++* Structure Byte Order Converter\n\n![PowerShell](badges/PowerShell.svg)\n![GitHub Actions](badges/Made-with-GitHub-Actions.svg)\n![License](badges/License-MIT.svg)\n\n## Introduction\n\nThis script can read a *C/C++* structure definition from the clipboard and generate byte reversing functions for the structure with `ntoh` or `hton` APIs.\n\n## Usage\n\nSuppose we have a structure `Foo`:\n\n```c++\nstruct Foo {\n    unsigned short us;\n    int i8 : 8;\n    int i24 : 24;\n    signed long sl[4];\n    char c[12];\n    long long ll24 : 24;\n    signed int si8 : 8;\n    short s;\n};\n```\n\nCopy the structure definition to the clipboard and run the script. We can get two reversing functions:\n\n```c++\nvoid ReverseFooToLittleEndian(Foo *const data) {\n    data-\u003eus = ntohs(data-\u003eus);\n    *(int*)((unsigned char*)(\u0026data-\u003eus) + sizeof(data-\u003eus) + 0) = ntohl(*(int*)((unsigned char*)(\u0026data-\u003eus) + sizeof(data-\u003eus) + 0));\n    for (size_t i = 0; i \u003c sizeof(data-\u003esl) / sizeof(data-\u003esl[0]); i++) {\n        data-\u003esl[i] = ntohl(data-\u003esl[i]);\n    }\n    *(long long*)((unsigned char*)(\u0026data-\u003ec) + sizeof(data-\u003ec) + 0) = ntohll(*(long long*)((unsigned char*)(\u0026data-\u003ec) + sizeof(data-\u003ec) + 0));\n    *(signed int*)((unsigned char*)(\u0026data-\u003ec) + sizeof(data-\u003ec) + 8) = ntohl(*(signed int*)((unsigned char*)(\u0026data-\u003ec) + sizeof(data-\u003ec) + 8));\n    data-\u003es = ntohs(data-\u003es);\n}\n\nvoid ReverseFooToBigEndian(Foo *const data) {\n    data-\u003eus = htons(data-\u003eus);\n    *(int*)((unsigned char*)(\u0026data-\u003eus) + sizeof(data-\u003eus) + 0) = htonl(*(int*)((unsigned char*)(\u0026data-\u003eus) + sizeof(data-\u003eus) + 0));\n    for (size_t i = 0; i \u003c sizeof(data-\u003esl) / sizeof(data-\u003esl[0]); i++) {\n        data-\u003esl[i] = htonl(data-\u003esl[i]);\n    }\n    *(long long*)((unsigned char*)(\u0026data-\u003ec) + sizeof(data-\u003ec) + 0) = htonll(*(long long*)((unsigned char*)(\u0026data-\u003ec) + sizeof(data-\u003ec) + 0));\n    *(signed int*)((unsigned char*)(\u0026data-\u003ec) + sizeof(data-\u003ec) + 8) = htonl(*(signed int*)((unsigned char*)(\u0026data-\u003ec) + sizeof(data-\u003ec) + 8));\n    data-\u003es = htons(data-\u003es);\n}\n```\n\nThe output can be copied directly to the clipboard:\n\n```console\nPS\u003e .\\Build-ByteReverseFunctions.ps1 | Set-Clipboard\n```\n\n### Warnings\n\n- The structure name can only be extracted from the `struct` statement.\n- The script can only detect single-line comments (`//`).\n- The following settings may differ from the script on some systems and compilers.\n  - Endianness.\n  - The sizes of fundamental *C/C++* types.\n  - The order of bit-fields.\n  - Field alignment.\n\n## License\n\nDistributed under the *MIT License*. See `LICENSE` for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhuagenborn%2Fcpp-struct-byte-order-converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhuagenborn%2Fcpp-struct-byte-order-converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhuagenborn%2Fcpp-struct-byte-order-converter/lists"}