[Clam-devel] Embedding files into binaries

David García Garzón dgarcia at iua.upf.edu
Wed Jul 9 11:39:27 PDT 2008


Just for my reference and whoever who is interested, a proof of concept on how 
to embed files into an executable using binutils. I hope to write a blog 
entry soon on this.

SConstruct seems too complex. This is to fix the symbol name that the tool 
generates. It contains the relative path to the file and made the symbol name 
dependant on where do you place it. All that code removes the path but i hope 
i can simplify that.

Being so feasible, this brings also the ladspa-on-click (and the 
Jack-on-click) nearer.

David.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fileembed.cxx
Type: text/x-c++src
Size: 172 bytes
Desc: not available
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20080709/d4d2530b/attachment-0004.cxx>
-------------- next part --------------
Hola Mundo!!
-------------- next part --------------
import os
def renameEmbededFileSymbols(source, target, env) :
	""" Remove the path part of the symbol name for the embeded file"""
	objdumpOutput=os.popen("objdump -x %s | grep _binary'.*'start"%target[0] , "r").read()
	startSymbol=objdumpOutput.split()[-1]
	infix = startSymbol[len('_binary_'):-len("_start")]
	baseName = os.path.split(str(source[0]))[-1]
	newInfix = infix[-len(baseName):]
	return Execute("objcopy %(target)s "
		"--redefine-sym _binary_%(infix)s_start=_binary_%(newInfix)s_start "
		"--redefine-sym _binary_%(infix)s_end=_binary_%(newInfix)s_end "
		"--redefine-sym _binary_%(infix)s_size=_binary_%(newInfix)s_size " % {
			"infix": infix,
			"newInfix": newInfix,
			"target": target[0],
		}
	)

embededFileBuilder = Builder(
	action=Action([
		["ld", "-r", "-b", "binary", "-o", "$TARGET", "$SOURCE"],
		renameEmbededFileSymbols,
		],
		),
	suffix='.o',
	)

env = Environment()
env['BUILDERS']['EmbededFile']=embededFileBuilder


env.Program('testingEmbededFile', [
	'fileembed.cxx', 
	env.EmbededFile('holaMundo.txt')
	])




More information about the clam-devel mailing list