如何“雕刻”将数据文件写入最终的可执行文件?
我想知道如何将我的文件作为原始字节存储在最终的可执行文件中,程序可以像常规内存一样读取它。 就像,我不明白为什么在程序运行时从不操作的文件数据必须“动态”加载,而不是仅仅存储在可执行文件的数据部分中。 有点像如何使用链接描述文件(通常是非字节码语言)来映射可执行文件内存中的内容?只是这最好也用 Java 来完成。
I would like to know how I could store my file in the final executable as raw bytes, that can be read by the program just like regular memory.
Like, I don't understand why file data that is NEVER manipulated during the program's runtime, have to be loaded "dynamically" instead of just being stored in the executable's data section.
Kind of like how you would use linkerscripts (typically non-bytecode languages) to map stuff in the executable's memory? Only that this would preferably also be done in Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为将这样的可执行文件加载到内存中需要更长的时间。另外,因为现在是 2011 年,并且您有文件和文件系统。
关于你的第一个问题(也是主要问题),你不需要对这样的事情感到困惑。只需将数据附加到可执行文件的末尾,并添加最终的“偏移”值即可告诉您它有多长。
编辑
我在编译的可执行文件的上下文中写了我原来的答案,就像C一样。既然您提到了 Java,据我所知,您可以将内容放入最终的JAR中并以编程方式访问它(因为它只是一个存档。)
Because it'd take longer to load such an executable into memory. Also because it's 2011, and you have files and a filesystem.
About your first (and primary question), you don't need to muck about with anything as such. Just tack on your data to the end of the executable and add a final "offset" value to tell you how long it is.
EDIT
I wrote my original answer in the context of a compiled executable, as with C. Since you've mentioned Java, afaik, you can put stuff in the final JAR and access it programmatically (since it's just an archive.)