Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. run an executable located in a memory buffer

run an executable located in a memory buffer

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
19 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C cmk

    Never tried it but, it should just be a matter of allocating a block of memory with execute access, casting the address to a function prototype, and calling it. Look at GlobalAlloc() (from MS docs) : "Memory allocated with this function is guaranteed to be aligned on an 8-byte boundary. All memory is created with execute access; no special function is required to execute dynamically generated code." Or, VirtualAlloc( ..., DWORD flProtect ) : flProtect = PAGE_EXECUTE_READWRITE; Enables execute, read, and write access to the committed region of pages. Would probably start with trying to do a simple C function first so you don't need to worry about the 'this' pointer. ...cmk Save the whales - collect the whole set

    B Offline
    B Offline
    Beer26
    wrote on last edited by
    #9

    I'm so sorry, I'm still missing a link here. I can not use the HGLOBAL i get from the GlobalAlloc with CreateProcess. It will only accept a path on the disk. What would you suggest as an alternative to get the HGLOBAL into a process?

    1 Reply Last reply
    0
    • C cmk

      Never tried it but, it should just be a matter of allocating a block of memory with execute access, casting the address to a function prototype, and calling it. Look at GlobalAlloc() (from MS docs) : "Memory allocated with this function is guaranteed to be aligned on an 8-byte boundary. All memory is created with execute access; no special function is required to execute dynamically generated code." Or, VirtualAlloc( ..., DWORD flProtect ) : flProtect = PAGE_EXECUTE_READWRITE; Enables execute, read, and write access to the committed region of pages. Would probably start with trying to do a simple C function first so you don't need to worry about the 'this' pointer. ...cmk Save the whales - collect the whole set

      B Offline
      B Offline
      Beer26
      wrote on last edited by
      #10

      ok, I missed that part about casting the pointer to a function. I'm not sure how that could possibly work though, but Thanks again, I will try that

      R 1 Reply Last reply
      0
      • B Beer26

        I don't want to allow access to the .exe being written, not even for an instant. It is not for a virus. The fact that you have implied that I could be writing a virus, frankly is insulting, and suggesting it, if I may permit myself to say so, was stupid.

        T Offline
        T Offline
        Toni78
        wrote on last edited by
        #11

        Beer26 wrote: if I may permit myself to say so, was stupid. With 9 messages posted, I don't think you can permit yourself to insult other members. For that matter of fact even if you were the guru here, you still cannot call someone's suggestions stupid. Mike's question is very legitimate. I also thought that you were writing a virus. Writing exe packers or decrypters requires certain steps which you could have explained very briefly in your post. Like Mike, I choose not to help you. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

        B 1 Reply Last reply
        0
        • T Toni78

          Beer26 wrote: if I may permit myself to say so, was stupid. With 9 messages posted, I don't think you can permit yourself to insult other members. For that matter of fact even if you were the guru here, you still cannot call someone's suggestions stupid. Mike's question is very legitimate. I also thought that you were writing a virus. Writing exe packers or decrypters requires certain steps which you could have explained very briefly in your post. Like Mike, I choose not to help you. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

          B Offline
          B Offline
          Beer26
          wrote on last edited by
          #12

          "I also thought that you were writing a virus." It is of my opinion that your comments are stupid too. "You cannot insult people!!!!" I wasn't insulting anyone, just stating my own opinion. The germans did not win the 2nd war. I have the right.

          T 1 Reply Last reply
          0
          • B Beer26

            "I also thought that you were writing a virus." It is of my opinion that your comments are stupid too. "You cannot insult people!!!!" I wasn't insulting anyone, just stating my own opinion. The germans did not win the 2nd war. I have the right.

            T Offline
            T Offline
            Toni78
            wrote on last edited by
            #13

            Beer26 wrote: It is of my opinion that your comments are stupid too. You're opinions are very insignificant. Happy 5th birthday! // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

            R 1 Reply Last reply
            0
            • T Toni78

              Beer26 wrote: It is of my opinion that your comments are stupid too. You're opinions are very insignificant. Happy 5th birthday! // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

              R Offline
              R Offline
              Ryan Binns
              wrote on last edited by
              #14

              Toni78 wrote: Happy 5th birthday! That's only making it worse. The best way to treat someone you think is insulting you is to just ignore it. People's opinions are not insignificant, no matter what they are.

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              T 1 Reply Last reply
              0
              • B Beer26

                ok, I missed that part about casting the pointer to a function. I'm not sure how that could possibly work though, but Thanks again, I will try that

                R Offline
                R Offline
                Ryan Binns
                wrote on last edited by
                #15

                Beer26 wrote: I'm not sure how that could possibly work though It should work, but you need to be really careful. Someone asked a very similar question about a week ago, and a few of us cautioned him on the dangers of executing code generated in memory. But if you know what you're doing, it should work no problems :)

                Ryan

                "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                1 Reply Last reply
                0
                • R Ryan Binns

                  Toni78 wrote: Happy 5th birthday! That's only making it worse. The best way to treat someone you think is insulting you is to just ignore it. People's opinions are not insignificant, no matter what they are.

                  Ryan

                  "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                  T Offline
                  T Offline
                  Toni78
                  wrote on last edited by
                  #16

                  Ryan Binns wrote: That's only making it worse. Sorry, you're right.:) // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

                  1 Reply Last reply
                  0
                  • B Beer26

                    is there a way to run an executable located in a memory buffer, that isn't physically on the disk? This isn't real code, but it will give you an idea of what I am trying to do. CRunMyNativeCode foo; foo.run(LPVOID);

                    T Offline
                    T Offline
                    Terry ONolley
                    wrote on last edited by
                    #17

                    point CS:IP at your code

                    I'm going to live forever or die trying!

                    I 1 Reply Last reply
                    0
                    • T Terry ONolley

                      point CS:IP at your code

                      I'm going to live forever or die trying!

                      I Offline
                      I Offline
                      Ilushka
                      wrote on last edited by
                      #18

                      rough :) Sincerely yours, Ilya Kalujny.

                      T 1 Reply Last reply
                      0
                      • I Ilushka

                        rough :) Sincerely yours, Ilya Kalujny.

                        T Offline
                        T Offline
                        Terry ONolley
                        wrote on last edited by
                        #19

                        Well, he asked ;)

                        I'm going to live forever or die trying!

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups