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!
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!
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
b) have a .h file for your data, e.g. gfxdata.h
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.
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.
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.
awesome, I will definitely investigate this! :)
Thanks!
Thanks!
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
bin2obj
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!
Thanks again!
here's a slightly updated version of the incbin trick:
gives you the nice feature of having the datasize too.
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.
Gargaj!
Ohoi, Like you were reading my mind. =) Thanks for that!
Ohoi, Like you were reading my mind. =) Thanks for that!
If you want to put a character on your binary you can do something like "static const char x = 'x';"
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 :)
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();
}
}
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.
I guess that will change when files become huge and building becomes tedious because of that.
with source I ment the source of the bin, be it a bmp, mod etc. the binary to be merged to the exe.
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.
I be a fool not to test thee bidding. Must have test both to one slay. Hey?! :p
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)
(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.
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.
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.
That copying method doesn't go well with exe packers.
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.
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/
also,