pouët.net

Go to bottom

Bundle data into EXE

category: general [glöplog]
Hi guys,
I was just wondering what is the best solution for bundling data eg. image onto a EXE. I am using Visual Studio Express so resource-editor is not there. Is there any other way to go about?

Thanks in advance.

Cheers!
added on the 2010-05-23 13:26:57 by ozoi ozoi
many people including me use the NASM incbin way... no clue if there are more hip ways nowadays, but it works nice and easy.
it goes like that:
a) have an .asm file defining your data, e.g. to include a .raw image file
Code: section .data global _nameyourdata _nameyourdata incbin "path\to\data\image.raw"


b) have a .h file for your data, e.g. gfxdata.h
Code: extern "C" unsigned char nameyourdata[];


c) include the header and just use the defined variable.
d) ???
e) PROFIT!

oh, and of course you need to include NASM into your toolchain to compile the .asm files. but can be nicely done within visual studio.
added on the 2010-05-23 13:34:16 by styx^hcr styx^hcr
just put the data at the end of the file ? or are you looking for tools that does this ? if so just use any merge tool.
added on the 2010-05-23 13:34:33 by pantaloon pantaloon
awesome, I will definitely investigate this! :)

Thanks!

added on the 2010-05-23 13:35:56 by ozoi ozoi
what pantaloon said. otherwise write (not hard nor hard to find/rip source)/use an object file writer to process your data into valid coff object files (nasm is basically a way around this, but you can make this a 1-step thing)

bin2obj
added on the 2010-05-23 14:08:01 by superplek superplek
Wowzers! I actually went with the NASM method and with a little bit of investigation I got it to work. Does just the trick!!!

Thanks again!

added on the 2010-05-23 14:20:51 by ozoi ozoi
here's a slightly updated version of the incbin trick:

Code: global _something _something incbin "file.dat" _something_end: global _something_size _something_size dd _something_end - _something


gives you the nice feature of having the datasize too.
added on the 2010-05-23 14:42:23 by Gargaj Gargaj
Gargaj!
Ohoi, Like you were reading my mind. =) Thanks for that!
added on the 2010-05-23 14:52:28 by ozoi ozoi
If you want to put a character on your binary you can do something like "static const char x = 'x';"
added on the 2010-05-23 17:31:24 by xernobyl xernobyl
I use a tool called EFF, from uFMOD. Take any file and generate a hexdump in C/C++ syntax, then include the .h file in your source :)
added on the 2010-05-23 19:06:37 by pera pera
Code: using System; using System.Resources; public class SampleClass { public static void Main() { // Create a resource writer. IResourceWriter rw = new ResourceWriter("myStrings.resources"); // Add resources to the file. rw.AddResource("color1", "red"); rw.AddResource("color2", "green"); rw.AddResource("color3", "blue"); // Close the ResourceWriter. rw.Close(); } }

added on the 2010-05-23 19:13:25 by the_Ye-Ti the_Ye-Ti
bin2h :)
I guess all those bin2h converters are good, but with the NASM-method I can change the source back and forth without having to re-convert the bin. the NASM directive sits there in the build-pipe once configured. with a clean .asm that more or less works as a resource-file with the header to it.
I guess that will change when files become huge and building becomes tedious because of that.
added on the 2010-05-24 02:40:46 by ozoi ozoi
with source I ment the source of the bin, be it a bmp, mod etc. the binary to be merged to the exe.
added on the 2010-05-24 02:42:03 by ozoi ozoi
It's just not a very good method to incorporate resources into your executable, then again, if you're using strategies like this it's probably not that big a project anyway. However, I say to thee once again: bin2obj as build step.
added on the 2010-05-24 02:45:47 by superplek superplek
I be a fool not to test thee bidding. Must have test both to one slay. Hey?! :p
added on the 2010-05-24 03:09:19 by ozoi ozoi
ozoi, what's the difference? just put the bin2h in your pre-build steps.
you could also look into libs like this: http://sol.gfxile.net/cfl/index.html

(but that'll give you a data file and exe file)
Quote:
you could also look into libs like this: http://sol.gfxile.net/cfl/index.html

(but that'll give you a data file and exe file)

Fear not! You can copy /b the .cfl file after the exe, and then use the executable as the cfl name, and it'll find the data just fine. It was designed for this.
added on the 2010-05-24 08:15:13 by sol_hsa sol_hsa
Just cram in the data at the end of the exe file!
Then you can read the executable binary file size in the EXE header, then jump to that byte in the file, normally the file just ends there.
This is IIRC also how windows resources work - the EXE format/header is a remnant from DOS times which had to be extended to support resources.

Only the length specified in the header will be read by the OS.
added on the 2010-05-24 09:06:53 by jaw jaw
That copying method doesn't go well with exe packers.
added on the 2010-05-24 09:23:47 by Marq Marq
that also doesn't go well with virus scanners, i think. at least i suspect that this is the reason why some of my old programs are detected as infected files sometimes.
tailoring demoscene works to virus scanners is an impossible ordeal anyway.
added on the 2010-05-24 14:40:33 by skrebbel skrebbel
indeed- it's like asking skrebbel to rewrite all his happy hardcore classics so they don't make your neighbours call the police when you play them at max volume \o/
added on the 2010-05-24 14:49:16 by havoc havoc
also,
BB Image
added on the 2010-05-24 14:50:14 by havoc havoc

login

Go to top