New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have dummySpace / inject / injectFile take an additional magic string #7

Closed
mgsloan opened this Issue Jan 17, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@mgsloan
Contributor

mgsloan commented Jan 17, 2015

It looks to me like an executable can only have one injected bytestring, because the magic string is always the same for dummySpace.

I can make a pull request adding this, if you want me to!

@snoyberg

This comment has been minimized.

Owner

snoyberg commented Jan 17, 2015

Would the PR add a new function that allows customizing the magic string?

On Sat Jan 17 2015 at 5:22:28 AM Michael Sloan notifications@github.com
wrote:

It looks to me like an executable can only have one injected bytestring,
because the magic string is always the same for dummySpace.

I can make a pull request adding this, if you want me to!


Reply to this email directly or view it on GitHub
#7.

@mgsloan

This comment has been minimized.

Contributor

mgsloan commented Jan 19, 2015

Yes, but we'd need new versions of dummySpace / inject / injectFile. Alternatively, it might be reasonable to break the API, in order to encourage users to provide a magic string (so that different uses of this injection don't interfere with eachother). While API changes should be avoided, are there many users of this? I see file-embed has lots of reverse dependencies, but I figure most of them are using the normal file embedding stuff. http://packdeps.haskellers.com/reverse/file-embed

@snoyberg

This comment has been minimized.

Owner

snoyberg commented Jan 20, 2015

Then we need new versions of those three functions. Not breaking API on a whim.

mgsloan added a commit to mgsloan/file-embed that referenced this issue Jan 27, 2015

mgsloan added a commit to mgsloan/file-embed that referenced this issue Jan 28, 2015

@gregwebs

This comment has been minimized.

gregwebs commented Jan 28, 2015

does anyone have some example usage of the injection stuff? I am not sure how to use it. My use case is I want to use embed-file but not invoke Template Haskell.

@mgsloan

This comment has been minimized.

Contributor

mgsloan commented Jan 29, 2015

@gregwebs, I've been using this as a reference for the injection stuff: http://www.yesodweb.com/blog/2011/06/building-better-chm

It would probably good to add more haddocks to this module, as well. You ought to be able to use injection without TH, but I'm not sure how to write a StringPrimL in code. Something like this might work, though (untested):

{-# LANGAUGE OverloadedStrings #-}

import qualified Data.ByteString as BS

-- magic string ++ padded size ++ payload space
-- "feMS" ++ (replicate 19 '0' ++ "4") ++ replicate 4 '0'
bs :: BS.ByteString
bs = "feMS000000000000000000040000"

injected :: BS.ByteString
injected = BS.drop 24 bs

Then, use injectFile on the compiled binary to inject your own ByteString (up to 4 bytes).

snoyberg added a commit that referenced this issue Jan 29, 2015

Merge pull request #8 from mgsloan/magic-postfixes
Allow custom postfix for the magic string #7
@gregwebs

This comment has been minimized.

gregwebs commented Jan 29, 2015

I don't see how we can efficiently reserve the dummy space without StringPrimL from template-haskell. Perhaps it is possible with some pointer tricks.

@snoyberg

This comment has been minimized.

Owner

snoyberg commented Mar 1, 2015

@gregwebs I just updated the documentation:

http://hackage.haskell.org/package/file-embed-0.0.8.2/docs/Data-FileEmbed.html#g:2

Closing this issue, as the original topic has been addressed. Greg: if you have questions about how to use it, let's follow up in the mailing list or a different issue.

@snoyberg snoyberg closed this Mar 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment