{"id":17358154,"url":"https://github.com/dadadel/binmake","last_synced_at":"2025-04-15T00:31:26.017Z","repository":{"id":54184109,"uuid":"61349289","full_name":"dadadel/binmake","owner":"dadadel","description":"Create binary files described by human readable text files","archived":false,"fork":false,"pushed_at":"2021-03-04T16:45:50.000Z","size":187,"stargazers_count":24,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T12:37:32.249Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dadadel.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":"2016-06-17T05:59:27.000Z","updated_at":"2024-10-30T12:18:41.000Z","dependencies_parsed_at":"2022-08-13T08:40:22.588Z","dependency_job_id":null,"html_url":"https://github.com/dadadel/binmake","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadadel%2Fbinmake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadadel%2Fbinmake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadadel%2Fbinmake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadadel%2Fbinmake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dadadel","download_url":"https://codeload.github.com/dadadel/binmake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248984231,"owners_count":21193712,"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":"2024-10-15T19:04:37.488Z","updated_at":"2025-04-15T00:31:24.608Z","avatar_url":"https://github.com/dadadel.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BinMake\n\nThis is an open source tool for generating a binary file described by a human\nreadable text file.\nIt manages endianess, several numbers representations, raw strings.\nIt ignores comments lines, empty lines, leading and ending spaces.\n\nIt is written in C++11 standard.\n\nIt can be used as a standalone binary or as a C++ library (static or dynamic)\nto include to you programs.\n\n\n- [BinMake](#binmake)\n  * [How to install](#how-to-install)\n  * [How to use the binary](#how-to-use-the-binary)\n  * [How to include in C++ code](#how-to-include-in-c-code)\n  * [Brief formatting documentation](#brief-formatting-documentation)\n  * [Offer a coffee or a beer](#offer-a-coffee-or-a-beer)\n  * [TODO](#todo)\n\n## How to install\n\nA Makefile allow to compile the binary and the libs.\n\nThe library provides the class BS::BinStream allowing to manipulate streams.\n\n```bash\n$ git clone https://github.com/dadadel/binmake\n$ cd binmake\n$ make\n```\n\nThis will compile and generate the binary `binmake` in `bin/`, the static lib\n`libbinstream.a` and the dynamic library `libbinstream.so` in `lib/`.\nThe headers are in `include/`.\n\nAfter compiling, the folder tree looks like:\n\n```\n|-- src/ \u003csource code\u003e\n|\n|-- include/\n|     |-- bs_exception.h\n|     |-- bs_data.h\n|     |-- BinStream.h\n|\n|-- lib/\n|     |-- libbinstream.so\n|     |-- libbinstream.a\n|\n|-- bin/\n|     |-- binmake\n|\n|-- test/ \u003cunit tests\u003e\n```\n\n### Tests\n\nNote that `BinStream` (and low-level functions) is well covered by unit tests.\nThe used framework is [Catch](https://github.com/philsquared/Catch).\n\nTo run the tests, just launch:\n\n```bash\n$ make run-tests\n```\n\n## How to use the binary\n\n```bash\n$ mv bin/binmake .\n\n$ ./binmake example.txt example.bin\n\n$ ./binmake example.txt \u003e example.bin\n\n$ cat example.txt | ./binmake \u003e example.bin\n\n$ cat example.txt | ./binmake -o example.bin\n\n$ echo '32 decimal 32 %x61 61' | ./binmake | hexdump -C\n00000000  32 20 61 3d                                       |2 a=|\n00000004\n\n$ echo 'big-endian %f1.2345' | ./bin/binmake | hexdump -C\n00000000  3f 9e 04 19                                       |?...|\n00000004\n```\n\n- Input file `example.txt`:\n\n```bash\n# an example of file description of binary data to generate\n\n# set endianess to big-endian\nbig-endian\n\n# default number is hexadecimal\n00112233\n\n# man can explicit a number type: %b means binary number\n%b0100110111100000\n\n# change endianess to little-endian\nlittle-endian\n\n# if no explicit, use default\n44556677\n\n# bytes are not concerned by endianess\n88 99 aa bb\n\n# change default to decimal\ndecimal\n\n# following number is now decimal on one byte due to its value\n0123\n\n# following number is now decimal forced to 4 bytes\n0123[4]\n\n# strings are delimited by \" or '\n\"this is some raw string\"\n\n# explicit hexa number starts with %x\n%xff\n```\n\n- Output file`example.bin`:\n\n```\n00000000  00 11 22 33 4d e0 77 66  55 44 88 99 aa bb 7b 7b  |..\"3M.wfUD....{{|\n00000010  00 00 00 74 68 69 73 20  69 73 20 73 6f 6d 65 20  |...this is some |\n00000020  72 61 77 20 73 74 72 69  6e 67 ff                 |raw string.|\n0000002b\n```\n\n## How to include in C++ code\n\nYou can either link with the static library or the dynamic library.\n\nThe header to include is `BinStream.h`. It needs `bs_exception.h`.\n\nThe class to use is `BS::BinStream`. You can obviously use the namespace `BS`\nto deal with merely `BinStream`.\n\nYou can stream the text description of you binary from: `istream`, `ifstream`,\n`string` and `stringstream`.\n\nYou can stream the output binary to: `vector\u003cchar\u003e`, `ostream` and `ofstream`.\n\nThere follow some examples.\n\n- Create a binary file from strings\n\n```c++\n#include \u003cfstream\u003e\n#include \"BinStream.h\"\n\nusing namespace std;\nusing namespace BS;\n\nint main()\n{\n    BinStream bin;\n    bin \u003c\u003c \"'hello world!'\"\n            \u003c\u003c \"00112233\"\n            \u003c\u003c \"big-endian\"\n            \u003c\u003c \"00112233\";\n    ofstream f(\"test.bin\");\n    bin \u003e\u003e f;\n    return 0;\n}\n```\n\n- Create a binary file from a text file\n\n```c++\n#include \u003cfstream\u003e\n#include \"BinStream.h\"\n\nusing namespace std;\nusing namespace BS;\n\nint main()\n{\n    BinStream bin;\n    ifstream inf(\"example.txt\");\n    ofstream ouf(\"example.bin\");\n    bin \u003c\u003c inf \u003e\u003e ouf;\n    return 0;\n}\n```\n\n- Read from stdin and write to stdout\n\n```c++\n#include \u003ciostream\u003e\n#include \"BinStream.h\"\n\nusing namespace std;\nusing namespace BS;\n\nint main()\n{\n    BinStream bin;\n    cin \u003e\u003e bin;\n    cout \u003c\u003c bin;\n    return 0;\n}\n```\n\nOr\n\n```c++\n#include \u003ciostream\u003e\n#include \"BinStream.h\"\n\nusing namespace std;\nusing namespace BS;\n\nint main()\n{\n    BinStream bin;\n    bin \u003c\u003c cin;\n    for (size_t i = 0; i \u003c bin.size(); ++i)\n    {\n        cout \u003c\u003c bin[i];\n    }\n    return 0;\n}\n```\n\n- Get the output in a char vector\n\n```c++\n#include \u003ciostream\u003e\n#include \"BinStream.h\"\n\nusing namespace std;\nusing namespace BS;\n\nint main()\n{\n    BinStream bin;\n    vector\u003cchar\u003e output;\n    bin \u003c\u003c \"'hello world!'\" \u003c\u003c \"00112233\";\n    bin \u003e\u003e output;\n    for (size_t i = 0; i \u003c output.size(); ++i)\n    {\n        cout \u003c\u003c output.data()[i];\n    }\n    return 0;\n}\n```\n\n## Brief formatting documentation\n\n### Comments\n\nA comment is in a single line and starts with a #. It should be the first\ncharacter other than space characters.\n\n### String\n\nA string should start and end by either `\"` (double quotes) or `'`\n(single quote) on the same line.\n\n### Numbers\n\nIt is possible to set on the same line several numbers separated by spaces.\nThere is several way to represent a number. By default a number is expected to\nbe in hexadecimal representation unless the default representation is changed.\n\nTo force interpretation of a number representation, it should start with one of\nthe following prefix:\n- `%x` represents hexadecimal number (digits in [0-9a-fA-F])\n- `%d` represents decimal number (digits in [0-9] starting optionnaly by[+-])\n- `%f` represents float number (chars in [+-eE.0-9])\n- `%o` represents octal number (digits in [0-7])\n- `%b` represents binary number (digits in [0-1])\n\nA number will be then represented as a 8 bits, 16 bits, 32 bits or 64 bits\nnumber in the binary output depending on the value of the number. If exceeding\none of the above bits size it will use the next available size (max 64 bits).\n\nAs exception, if a hexadecimal number is provided with non-significant zeros,\nthe size of the string representation will determine the output binary number\nsize. Thus, \"%x0000\" (or \"0000\" if default is hexa) will generate a 16 bits\nnumber instead of 8 bits.\n\nAn other exception is that float numbers can only be represented on 32 bits for\nfloat or 64 bits for double (thus 4 or 8 bytes). Default float representation\nused if not specified is 4 bytes.\n\nFurthermore, it is possible to force a size for a number of any type by adding\nthe size in bytes between brackets (2, 4 or 8). For instance, the decimal number\n`0123` will be encoded on one byte while `0123[4]` will be encoded on 4 bytes.\n\nFor the numbers represented on 16, 32 and 64 bits, the default endianess is\nlittle-endian unless it was changed (see Keywords).\n\n### Keywords\n\nSome special keywords can be used to change default endianess output usage or\ninput not explicit number interpretation.\n\nNote that a keyword should be on a single line without any character other than\nspace characters.\n\n- `little-endian`, `big-endian`\n\nFor the number represented on 16, 32 and 64 bits, the default endianess is\nlittle-endian. The default endianess can be changed by using the keyword\n\"little-endian\" or \"big-endian\".\nOnce the default is changed, all further numbers will be represented in the\nnew default endianess.\n\nAs a reminder, big-endian representation of `%x00112233` is in\nmemory `00 11 22 33`, that is the less significant byte in the lower memory\naddress.\nConversly, in little-endian, the number will be represented like `33 22 11 00`,\nthat is the more significant bytes in lower addresses.\n\n\n- `hexadecimal`, `hexa`, `hex`\n\nIf one of these keywords is found, then all furthur found number without an\nexplicit interpretation will be interpreted as a **hexadecimal number**.\n\n- `decimal`, `dec`\n\nIf one of these keywords is found, then all furthur found number without an\nexplicit interpretation will be interpreted as a **decimal number**.\n\n- `octal`, `oct`\n\nIf one of these keywords is found, then all furthur found number without an\nexplicit interpretation will be interpreted as a **octal number**.\n\n- `binary`, `bin`\n\nIf one of these keywords is found, then all furthur found number without an\nexplicit interpretation will be interpreted as a **binary number**.\n\n- `float`\n\nIf this keyword is found all further numbers without and explicit interpretation\nwill be interpreted as a **float number**.\n\n## Offer a coffee or a beer\n\nIf you enjoyed this free software, and want to thank me, you can offer me some\nbitcoins for a coffee, a beer, or more, I would be happy :)\n\nHere's my address for bitcoins : 1PbzmiF9o46HXZWz3TkXrpafPg4x5uS686\n\n\n## TODO\n\n- Manage several string lines\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdadadel%2Fbinmake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdadadel%2Fbinmake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdadadel%2Fbinmake/lists"}