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. Regarding CreateRemoteThread

Regarding CreateRemoteThread

Scheduled Pinned Locked Moved C / C++ / MFC
jsonperformancequestion
5 Posts 4 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.
  • R Offline
    R Offline
    ramana g
    wrote on last edited by
    #1

    Hi I am trying create a remote thread using ::CreateRemoteThread API. I am able to open the remote process (with PROCESS_ALL_ACCESS), and allocate the memory and write the function code successfully. But, when i try to create remote thread, the remote process is crashing. Pls give some points, where it may go wrong?

    L S 2 Replies Last reply
    0
    • R ramana g

      Hi I am trying create a remote thread using ::CreateRemoteThread API. I am able to open the remote process (with PROCESS_ALL_ACCESS), and allocate the memory and write the function code successfully. But, when i try to create remote thread, the remote process is crashing. Pls give some points, where it may go wrong?

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      ramana.g wrote:

      Pls give some points, where it may go wrong?

      I have no experience with that API, but here is something they hid in the documentation: Note that CreateRemoteThread may succeed even if lpStartAddress points to data, code, or is not accessible. If the start address is invalid when the thread runs, an exception occurs, and the thread terminates. Thread termination due to a invalid start address is handled as an error exit for the thread's process.

      M 1 Reply Last reply
      0
      • L led mike

        ramana.g wrote:

        Pls give some points, where it may go wrong?

        I have no experience with that API, but here is something they hid in the documentation: Note that CreateRemoteThread may succeed even if lpStartAddress points to data, code, or is not accessible. If the start address is invalid when the thread runs, an exception occurs, and the thread terminates. Thread termination due to a invalid start address is handled as an error exit for the thread's process.

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        In other words they do no checking whatsoever on the start address parameter. When the remote thread starts the infrastructure will use a CALL instruction to call the supplied start address, and if you're lucky the processor will generate a page fault hardware exception straight away. The OS will turn that into an access violation exception since there's no suitable page mapping, it'll go looking for an exception handler, not find one, and call the process's unhandled exception filter. Typically that will kill the process. If unlucky your address will point to some data and it'll run for a while before it encounters a bit pattern not matching a valid instruction, or the data being interpreted as code tries to touch invalid memory, or it trashes some other pointer in the real program code which causes a crash. It's very difficult to examine a pointer to determine whether it really points to valid code, simply because the range of valid instructions is so vast. A human might be able to spot that the sequence of instructions doesn't make sense and deduce that it's really data, but building in a complete heuristic engine to work that out is not worthwhile.


        DoEvents: Generating unexpected recursion since 1991

        L 1 Reply Last reply
        0
        • M Mike Dimmick

          In other words they do no checking whatsoever on the start address parameter. When the remote thread starts the infrastructure will use a CALL instruction to call the supplied start address, and if you're lucky the processor will generate a page fault hardware exception straight away. The OS will turn that into an access violation exception since there's no suitable page mapping, it'll go looking for an exception handler, not find one, and call the process's unhandled exception filter. Typically that will kill the process. If unlucky your address will point to some data and it'll run for a while before it encounters a bit pattern not matching a valid instruction, or the data being interpreted as code tries to touch invalid memory, or it trashes some other pointer in the real program code which causes a crash. It's very difficult to examine a pointer to determine whether it really points to valid code, simply because the range of valid instructions is so vast. A human might be able to spot that the sequence of instructions doesn't make sense and deduce that it's really data, but building in a complete heuristic engine to work that out is not worthwhile.


          DoEvents: Generating unexpected recursion since 1991

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Mike Dimmick wrote:

          and if you're lucky

          Well if you don't apply the luck keyword properly what do you expect? Really I'm not sure what your point is. You expect to pass an invalid address as a function pointer and everything will work out just fine?

          1 Reply Last reply
          0
          • R ramana g

            Hi I am trying create a remote thread using ::CreateRemoteThread API. I am able to open the remote process (with PROCESS_ALL_ACCESS), and allocate the memory and write the function code successfully. But, when i try to create remote thread, the remote process is crashing. Pls give some points, where it may go wrong?

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            ramana.g wrote:

            the remote process is crashing

            How? Where? You must provide details of the crash! We're no psychic!

            Steve

            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