Safe Haskell | None |
---|---|
Language | Haskell98 |
- dummySpace :: Int -> Q Exp
- dummySpaceWith :: ByteString -> Int -> Q Exp
- inject :: ByteString -> ByteString -> Maybe ByteString
- injectFile :: ByteString -> FilePath -> FilePath -> IO ()
- injectWith :: ByteString -> ByteString -> ByteString -> Maybe ByteString
- injectFileWith :: ByteString -> ByteString -> FilePath -> FilePath -> IO ()
Inject into an executable
The inject system allows arbitrary content to be embedded inside a Haskell executable, post compilation. Typically, file-embed allows you to read some contents from the file system at compile time and embed them inside your executable. Consider a case, instead, where you would want to embed these contents after compilation. Two real-world examples are:
- You would like to embed a hash of the executable itself, for sanity checking in a network protocol. (Obviously the hash will change after you embed the hash.)
- You want to create a self-contained web server that has a set of content, but will need to update the content on machines that do not have access to GHC.
The typical workflow use:
- Use
dummySpace
ordummySpaceWith
to create some empty space in your executable - Use
injectFile
orinjectFileWith
from a separate utility to modify that executable to have the updated content.
The reason for the With
-variant of the functions is for cases where you wish
to inject multiple different kinds of content, and therefore need control over
the magic key. If you know for certain that there will only be one dummy space
available, you can use the non-With
variants.
dummySpace :: Int -> Q Exp Source #
Allocate the given number of bytes in the generate executable. That space
can be filled up with the inject
and injectFile
functions.
dummySpaceWith :: ByteString -> Int -> Q Exp Source #
Like dummySpace
, but takes a postfix for the magic string. In
order for this to work, the same postfix must be used by inject
/
injectFile
. This allows an executable to have multiple
ByteString
s injected into it, without encountering collisions.
Since 0.0.8
:: ByteString | bs to inject |
-> ByteString | original BS containing dummy |
-> Maybe ByteString | new BS, or Nothing if there is insufficient dummy space |
Inject some raw data inside a ByteString
containing empty, dummy space
(allocated with dummySpace
). Typically, the original ByteString
is an
executable read from the filesystem.
:: ByteString | bs to inject |
-> FilePath | template file |
-> FilePath | output file |
-> IO () |
Same as inject
, but instead of performing the injecting in memory, read
the contents from the filesystem and write back to a different file on the
filesystem.
:: ByteString | postfix of magic string |
-> ByteString | bs to inject |
-> ByteString | original BS containing dummy |
-> Maybe ByteString | new BS, or Nothing if there is insufficient dummy space |
Like inject
, but takes a postfix for the magic string.
Since 0.0.8
:: ByteString | postfix of magic string |
-> ByteString | bs to inject |
-> FilePath | template file |
-> FilePath | output file |
-> IO () |
Like injectFile
, but takes a postfix for the magic string.
Since 0.0.8