#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    16
    Rep Power
    0

    Copying data into an executable by another executable


    How can I create a data storage area in a program
    that another program can put data into. I'm writing an Install program in C. A simple static BYTE Buf[100000]; does not make the compiled program 100000 bytes larger.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    try initializing buf (at least one element will do), while declaring it.

    static BYTE buf[10000] = "x";
    or even
    static BYTE buf[10000] = ""; // since \0 is one byte

    HTH :)
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    16
    Rep Power
    0
    No, that doesn't do it.
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    You do have some reference to buf in your code, right? Otherwise, the optimizer might notice that you're not doing anything with buf and optimize it out.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    16
    Rep Power
    0
    Oh, sure, I'm writing to it and reading from it (as a temporary way to get the data).
  10. #6
  11. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    The compiler only stores the initializers and copies them at startup to dynamically allocated memory. So you would need 10000 explicit initialisers. It will not unnecessarily pad the file. Static data not explicitly initialised is initialised to zero, but the compiler does not need to store 10000 zero bytes to do that.

    It may be possible to use an assembler directive (with in-line assembly), or a modified linker script to reserve space. Since this would be compiler dependant, you'll need to dig deep in the documentation.

    Clifford


    Clifford
  12. #7
  13. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    While this is an interesting problem (technically not quite self-modifying code, but close to it), why not simply use an ini file? Writing into an executable is asking for problems unless you know EXACTLY where the compiler is putting everything. If you are trying to hide some data in the exe, all you are doing it raising the bar on hackers, anyone with an ounce of sense will simply open the exe as a text file and look for the data or run a decompiler on it and see what pops out. If you want to keep others from using the extra data, why not encrypt it and have the exe decrypt it as it is being used? Keep in mind you can't make software that can't be re-engineered, only make it more or less difficult.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    16
    Rep Power
    0
    Does anyone know how to write an _Install_ program, where the compressed data is included in the exe file?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    13
    To write an install program, most of us use an installer. NullSoft's NSIS program is a dream for this.

    Otherwise I'd recommend writing a separate installer program using Microsoft's Installation API, then compressing it with an archive program that can build directly to an exe, like PK-Zip. PK-Zip lets you specify a program to run out of it's payload after extraction.

    Writing your own installer is re-inventing the wheel though. There are already good, free installers out there written by people who understand how such things are done. Use their tools and save yourself the grief.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    16
    Rep Power
    0
    Okay, but how would THEY put files into a installer program?

    My program is complete except for this problem...
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    16
    Rep Power
    0
    ClayDowling:

    Thanks a lot for the intro to NullSoft's NSIS. It looks excellent (and its free (and the source code is included))!
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    One possibility to embed arbitrary binary data into exe files is resource files (.res / .rc - you might be using them for icons and bitmaps already). Read your compilerīs documentation about this.
  24. #13
  25. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    16
    Rep Power
    0
    Oh, yeah! I forgot about that. I've done that before (and forgot)! Thanks!

    (no more suggestions required)

IMN logo majestic logo threadwatch logo seochat tools logo