{"id":19548770,"url":"https://github.com/xtansia/bin2s","last_synced_at":"2025-04-26T20:30:57.589Z","repository":{"id":145396612,"uuid":"81162616","full_name":"Xtansia/bin2s","owner":"Xtansia","description":"Convert binary files to GCC assembly modules","archived":false,"fork":false,"pushed_at":"2024-04-23T22:56:27.000Z","size":27,"stargazers_count":8,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T17:47:41.204Z","etag":null,"topics":["assembly","binary-data","cmake","converter","cpp11"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Xtansia.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}},"created_at":"2017-02-07T03:34:16.000Z","updated_at":"2024-12-30T17:14:44.000Z","dependencies_parsed_at":"2023-06-03T17:00:11.252Z","dependency_job_id":null,"html_url":"https://github.com/Xtansia/bin2s","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/Xtansia%2Fbin2s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xtansia%2Fbin2s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xtansia%2Fbin2s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xtansia%2Fbin2s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xtansia","download_url":"https://codeload.github.com/Xtansia/bin2s/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251051277,"owners_count":21528786,"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":["assembly","binary-data","cmake","converter","cpp11"],"created_at":"2024-11-11T03:56:51.306Z","updated_at":"2025-04-26T20:30:57.016Z","avatar_url":"https://github.com/Xtansia.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bin2s\nConvert binary files to GCC assembly modules.\n\nA C++17 port of devkitPro's [bin2s](https://github.com/devkitPro/general-tools/blob/master/bin2s.c).\n\n```\nbin2s {OPTIONS} [FILES...]\n\n  Convert binary files to GCC assembly modules.\n\nOPTIONS:\n\n    -h, --help                        Show this help message and exit\n    -a [ALIGNMENT],\n    --alignment=[ALIGNMENT]           Boundary alignment, in bytes [default:\n                                      4]\n    -l [LINE_LENGTH],\n    --line-length=[LINE_LENGTH]       Number of bytes to output per line of\n                                      ASM [default: 16]\n    -o [OUTPUT], --output=[OUTPUT]    Output file, \"-\" represents stdout\n                                      [default: -]\n    FILES...                          Binary file to convert to GCC assembly\n    \"--\" can be used to terminate flag options and force all following\n    arguments to be treated as positional options\n\n\nFor each input file it will output assembly defining:\n\n  * {identifier}:\n      An array of bytes containing the data.\n  * {identifier}_end:\n      Will be at the location directly after the end of the data.\n  * {identifier}_size:\n      An unsigned int containing the length of the data in bytes.\n\nRoughly equivalent to this pseudocode:\n\n  const unsigned int identifier_size = ...\n  const unsigned char identifier[identifier_size] = { ... }\n  const unsigned char identifier_end[] = identifier + identifier_size\n\nWhere {identifier} is the input file's name,\nsanitized to produce a legal C identifier, by doing the following:\n\n  * Stripping all character that are not ASCII letters, digits or one of _-./\n  * Replacing all of -./ with _\n  * Prepending _ if the remaining identifier begins with a digit.\n\ne.g. for gfx/foo.bin {identifier} will be foo_bin,\n     and for 4bit.chr it will be _4bit_chr.\n```\n\n## Example\n\nGiven input file `hello_world.txt`:\n\n```\nHello World\n```\n\nIt will produce the following assembly:\n\n```\n  .section .rodata\n  .balign 4\n  .global hello_world_txt\n  .global hello_world_txt_end\n  .global hello_world_txt_size\n\nhello_world_txt:\n  .byte  72,101,108,108,111, 32, 87,111,114,108,100\n\nhello_world_txt_end:\n\n  .align\nhello_world_txt_size: .int 11\n```\n\nYou can then use it from your program by for example creating a header like so:\n\n```c\nextern const unsigned char hello_world_txt[];\nextern const unsigned char hello_world_txt_end[];\nextern const unsigned int hello_world_txt_size;\n```\n\n## CMake\n\nHere's an example CMake snippet to automatically download \u0026 build bin2s, \nand add a function for creating a library target from binary files.\n\n```cmake\ninclude(ExternalProject)\n\nExternalProject_Add(bin2s_git\n  PREFIX vendor/\n  GIT_REPOSITORY https://github.com/Xtansia/bin2s\n  GIT_TAG master\n  GIT_SUBMODULES\n  UPDATE_COMMAND \"\"\n  PATCH_COMMAND \"\"\n  BUILD_COMMAND \"\"\n  CMAKE_ARGS \n    \"-DCMAKE_BUILD_TYPE=Release\" \n    \"-DCMAKE_INSTALL_PREFIX=\u003cINSTALL_DIR\u003e\"\n  INSTALL_COMMAND\n    \"${CMAKE_COMMAND}\"\n    --build .\n    --target install\n    --config Release)\n\nadd_executable(bin2s IMPORTED GLOBAL)\nset_target_properties(bin2s PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/vendor/bin/bin2s)\nadd_dependencies(bin2s bin2s_git)\n\nfunction(add_binfile_library target_name)\n  if (NOT ${ARGC} GREATER 1)\n    message(FATAL_ERROR \"add_binfile_library : Argument error (no input files)\")\n  endif()\n  \n  get_cmake_property(_enabled_languages ENABLED_LANGUAGES)\n  if (NOT _enabled_languages MATCHES \".*ASM.*\")\n    message(FATAL_ERROR \"add_binfile_library : ASM language needs to be enabled\")\n  endif()\n\n  set(_output_dir ${CMAKE_CURRENT_BINARY_DIR}/binfile_asm)\n  set(_output_file ${_output_dir}/${target_name}.s)\n  \n  file(MAKE_DIRECTORY ${_output_dir})\n\n  add_custom_command(OUTPUT ${_output_file}\n                     COMMAND bin2s -o \"${_output_file}\" ${ARGN}\n                     DEPENDS ${ARGN}\n                     WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})\n  \n  add_library(${target_name} ${_output_file})\nendfunction()\n```\n\nWhich you could then use like so:\n\n```cmake\nadd_binfile_library(resources res/some_picture.png)\n\nadd_executable(myprogram src/main.cpp)\ntarget_link_libraries(myprogram resources)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtansia%2Fbin2s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtansia%2Fbin2s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtansia%2Fbin2s/lists"}