Results 1 to 7 of 7

Thread: RtlMoveMemory ByVal 0, ByVal 1, 1

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    RtlMoveMemory ByVal 0, ByVal 1, 1

    Code:
    Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal Length As LongPtr)
    
    Sub RaiseException()
        RtlMoveMemory ByVal 1, ByVal 1, 1
    End Sub
    The above call to RtlMoveMemory will cause an exception causing an entire crash of the application.

    From what I understand, the SetUnhandledExceptionFilter API can be used in such situation to redirect the exception to the filter function to be handled hence preventing the application crash.

    Is my understanding about setunhandledexceptionfilter correct and could it be used to prevent the crashing that occurs when calling RtlMoveMemory as shown in the code above?

    If so, can anybody provide a small example ? (BTW, I am using this in vba if that makes a difference)

    Regards.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: RtlMoveMemory ByVal 0, ByVal 1, 1

    I played with that exception filter API decades ago. I managed to get it work most of the time, but not always. It definitely reduced the crashes even with CopyMemory/RtlMoveMemory blunders. However, for me to get it somewhat reliable, I needed to have it external to the application as an ActiveX DLL and its use was in the context of safer-subclassing without thunks.

    edited: above not exactly correct. after reading the code comments (see next reply), the filter was included in a bas module within the project. The dll was external and designed for safer subclassing.

    I can't point you to a working example, because it only existed on planetsourcecode & that's its own problem being worked by some on this site. I don't even know if I have the original source on my harddrives any longer (maybe, but not positive). When I was trying to figure that API out, I couldn't find any good examples either. But it's been so long ago, maybe googling might bring you more luck now?

    Honestly, if you are going to use low-level memory peeking & poking, you should ensure your addresses are valid.
    Last edited by LaVolpe; Sep 17th, 2020 at 01:51 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: RtlMoveMemory ByVal 0, ByVal 1, 1

    Quote Originally Posted by LaVolpe View Post
    I played with that exception filter API decades ago. I managed to get it work most of the time, but not always. It definitely reduced the crashes even with CopyMemory/RtlMoveMemory blunders. However, for me to get it somewhat reliable, I needed to have it external to the application as an ActiveX DLL and its use was in the context of safer-subclassing without thunks.

    I can't point you to a working example, because it only existed on planetsourcecode & that's its own problem being worked by some on this site. I don't even know if I have the original source on my harddrives any longer (maybe, but not positive). When I was trying to figure that API out, I couldn't find any good examples either. But it's been so long ago, maybe googling might bring you more luck now?

    Honestly, if you are going to use low-level memory peeking & poking, you should ensure your addresses are valid.
    Thanks.

    I actually have googled the SetUnhandledExceptionFilter API already before asking here and found very few examples none of which worked for me.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: RtlMoveMemory ByVal 0, ByVal 1, 1

    If you google using these terms, your first hit should get you the bas-module I created: lavolpe SetUnhandledExceptionFilter

    You can look over the module comments. Looks like I wrote that back in 2006-ish.

    Worse case, may be helpful in trying to understand how to use the API. I couldn't honestly tell you without reviewing all that code I wrote so long ago.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: RtlMoveMemory ByVal 0, ByVal 1, 1

    Quote Originally Posted by LaVolpe View Post
    If you google using these terms, your first hit should get you the bas-module I created: lavolpe SetUnhandledExceptionFilter

    You can look over the module comments. Looks like I wrote that back in 2006-ish.

    Worse case, may be helpful in trying to understand how to use the API. I couldn't honestly tell you without reviewing all that code I wrote so long ago.
    Thanks LaVolpe.

    I found the bas module... I'll look into it later and see if I can make it work.

  6. #6
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,163

    Re: RtlMoveMemory ByVal 0, ByVal 1, 1

    The trouble with reliable SetUnhandledExceptionFilter in VB6 comes from late-bound calls as implemented by the helpers in the runtime. When you have Dim o As Object: o.DoSomething the method invokation is wrapped in __try/__catch i.e. SEH so that if the DoSomething fails with AV (or any other exception) you get the dreaded "Method ~ of object ~ failed" error message :-))

    Anyway, the point is that your exception filter might be deactivated after an innocuous o.DoSomething call and so your CopyMemory will bring down the whole process again despite your best efforts.

    cheers,
    </wqw>

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: RtlMoveMemory ByVal 0, ByVal 1, 1

    Quote Originally Posted by wqweto View Post
    The trouble with reliable SetUnhandledExceptionFilter in VB6 comes from late-bound calls as implemented by the helpers in the runtime. When you have Dim o As Object: o.DoSomething the method invokation is wrapped in __try/__catch i.e. SEH so that if the DoSomething fails with AV (or any other exception) you get the dreaded "Method ~ of object ~ failed" error message :-))

    Anyway, the point is that your exception filter might be deactivated after an innocuous o.DoSomething call and so your CopyMemory will bring down the whole process again despite your best efforts.

    cheers,
    </wqw>
    Thanks for the explanation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width