2015-07-29 14:56 阅读 14


Is it possible to append/remove a ressource file to a binary at execution time?

I have an application written with go, which saves/searches data from a database file, and i would like this database file to be embedded to the binary, and updated by the application itself.

This way the application would be self contained with its database.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    doudai3012 doudai3012 2015-07-29 15:51

    Modifying the executable, this is generally a very bad idea.

    Several issues pop right into my head, such as:

    1. Does the current user have sufficient permissions?
    2. Is the file locked during execution?
    3. What about multiple running instances of the application?

    Even if you manage to do just that, think of what anti-virus and firewall applications will say to it: most when they detect the change will flag the executable and/or contain it, or deny running it, or some may even delete it. Rightfully, as this is what many viruses do: modify existing executables.

    Also virus scanner databases maintain reports where files (their contents) are identified based on the hash of their content. Modifying the executable will naturally change the file content hash, thus render the file unknown / suspicious to these databases.

    As mentioned, just write / cache data in separate file(s), preferably in user's home folder or in the application folder (next to the executable, optionally in sub-folders). Or make the cache file / folder a changeable option (command line flags).

    点赞 评论 复制链接分享
  • drhgzx4727 drhgzx4727 2015-07-29 15:05

    Technically, this is possible, but this is a bad idea. Your application could be run by users not having write permissions to your binary.

    If you're talking about a portable app, your best option might be using a file in the same directory the binary is located, otherwise - use the user's home directory according to the conventions of the OS you're running on. You can use the os/user package to find the home directory.

    点赞 评论 复制链接分享