Announcement

Collapse
No announcement yet.

Exe in resource file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exe in resource file

    Hello,

    I want to use a small freeware exe file in my application. For that I would usually call this file with the SHELL command.

    This exe file expects one parameter (just a file name) like SHELL "C:\Executable.exe C:\File2Convert.mid"

    Rather than calling this exe with SHELL I would like to put it into a resource file to call it from there.

    Question: How to call this from a resource? I expect to get a handle to the resource but I have no glue how to call exe from this handle and how to pass the filename as parameter?

    I appreciate any help!

    Thank you,
    Joerg
    Joerg Koehler

  • #2
    You cannot avoid a second process if you want to run a separate EXE as part of your application.

    User-Defined Resource Demo January 26 2003

    Get the resource as a string (use the deviously-named "ResourceAsString" function in that demo), save the string to a file, CreateProcess/ShellExecute[Ex], or SHELL.

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Another example here:

      http://www.powerbasic.com/support/pb...ad.php?t=23527

      ' MakeFile.Inc - By William Burns 01/15/02
      '
      ' This function will allow you to extract a file saved in your resource file as RCDATA.
      Rgds, Dave

      Comment


      • #4
        You can embed an executable in the resource section of your main executable, but the reason you can't run it directly from there (directly from memory) is because the executable is an on-disk image. In other words it hasn't had its sections loaded to the right addresses, it hasn't had its imports resolved, it hasn't had its relocations adjusted, etc etc.

        So you can either manually build the in-memory image, which can be tricky, or extract the file to disk and run from there.

        Michael,
        You cannot avoid a second process if you want to run a separate EXE as part of your application.
        If you want to run another executable without it running as a second process one trick you can use is to manually set %IMAGE_FILE_DLL in IMAGE_NT_HEADERS.FileHeader.Characteristics. You can then call LoadLibrary on the executable, and it will be loaded and its entrypoint (pbmain for example) will be executed. The second executable is essentially now running as a DLL in the process context of the parent executable.

        I still don't see what's wrong with a second process though *scratches head* ...
        Last edited by Wayne Diamond; 16 Jun 2008, 11:30 PM.
        -

        Comment


        • #5
          If you want to run another executable without it running as a second process one trick you can use is to manually [modify the PE header]
          "Trick" is right.

          Shame on you for suggesting this without some kind of caution that this is totally unsupported by either the operating system or compiler publishers!
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            I disagree, I say it is supported! ... unconventional yes, but still "legal"
            -

            Comment


            • #7
              Both you and I have been around long enough to know that modifying a compiled program file is at best an inferior technique and at worst totally silly.

              We veterans owe it to the newbies to keep these kinds of thoughts to ourselves, at least until they are old enough.
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Michael I couldn't agree more with you that modifying an executable "blindly" is obviously asking for trouble and cannot be recommended under usual circumstances (I can't really think of too many situations where it would be required in the first place), but if I'm reading the original post correctly it seems he actually has full control over the EXE he wants to load, so he can test thoroughly before release that this trick works, and if it's a simple program it probably will because as you know there is very little difference between a DLL and an EXE, and it's trivial to turn an EXE into a DLL and vice versa.

                We veterans owe it to the newbies to keep these kinds of thoughts to ourselves, at least until they are old enough.
                On the contrary I think we owe it to newbies to challenge and inspire their minds, regardless of how experienced they are or old they are. We may not always be able to offer a concrete "this is the best way to do it" solution, but perhaps offering them a possible alternative will get their minds ticking and maybe, just maybe they'll be able to come up with a solution to their challenge.
                -

                Comment


                • #9
                  > think we owe it to newbies to challenge and inspire...

                  Code:
                   truth = ((challenge OR inspire) <> hacking)
                  Michael Mattias
                  Tal Systems Inc. (retired)
                  Racine WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    So modifying one flag in IMAGE_NT_HEADERS.FileHeader.Characteristics is "hacking" ??? Michael you've gotta stop thinking inside the square my friend

                    It's as much "hacking" as #COMPILE EXE is vs #COMPILE DLL ...
                    -

                    Comment


                    • #11
                      Taking a penny that's not yours isn't stealing?

                      This is not a 'degree' thing... it's what engineers would call a 'binary solution set': true or false.

                      Modifying a compiled executable is hacking.
                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Definition of Hacking
                        a person who delights in having an intimate understanding of the internal workings of a system, computers and computer networks in particular
                        So wrongfully twisted into a usage of the word for "Script Kiddies"
                        people breaking into computers using programs written by OTHERS, with very little knowledge about the way they work
                        So I would think...modifying your OWN executable would be more along the lines of a TRUE "Hacker"

                        Engineer's Motto: If it aint broke take it apart and fix it

                        "If at 1st you don't succeed... call it version 1.0"

                        "Half of Programming is coding"....."The other 90% is DEBUGGING"

                        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                        Comment

                        Working...
                        X