Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4621572
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:43:14+00:00 2026-05-22T02:43:14+00:00

This is for a homework assignment. I am supposed to change the contents of

  • 0

This is for a homework assignment.

I am supposed to change the contents of a dll function and put an error in it (0xCC). After loading the dll function and changing its protection to PAGE_EXECUTE_READWRITE.

I am having a trouble planting the error code in it. I tried the following (I removed the non interesting things):

typedef BOOL (*pfn)();

HMODULE hModule=LoadLibrary("somedll");

pfn somefunc=(pfn)GetProcAddress(hModule,"somefunction");

VirtualProtect (somefunc,dwSize,PAGE_EXECUTE_READWRITE,&dwOldProtect);

BYTE *p = (BYTE*)somefunc;

*p = 0xCC;

When I execute somefunc, instead of getting an exception, it is running without any problems. Why is that and am I doing wrong?

How do I overwrite the function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:43:14+00:00Added an answer on May 22, 2026 at 2:43 am

    Probably VirtualProtect returned an error. Check its (BOOL) return value and, if false, use GetLastError to check what was the cause.

    Notice that VirtualProtect must be compatible with the access given at the call to VirtualAlloc that allocated the memory. Now, that’s something you can’t control, since VirtualAlloc is called internally in LoadLibrary.

    Another thing is that the pointer provided to VirtualProtect must be the starting address to that memory page, and the function pointer you provided most probably is not. Your function can be anywhere inside the page, you’ll have to adjust it to the nearest page start before.

    Of interest:

    http://support.microsoft.com/kb/127904
    (basically what you’re doing, but a few more steps required)

    http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/
    (may be helpful for details on DLL loading mechanism)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on this homework assignment and I am stuck on what I
This is part of a homework assignment. I've got several questions asking find the
Disclaimer: This is for a homework assignment, but the question is not regarding the
I'm doing a basic homework assignment which looks like this: While input <> -1
I know this sounds like a homework assignment, but it isn't. Lately I've been
(this is indirectly a part of a much larger homework assignment) I have something
Full disclosure : This is for a homework assignment. This is driving me nuts.
I have a homework assignment to sort an array in ascending order. Obviously, this
This was a homework assignment for my students (I am a teaching assistant) in
This is for a homework assignment, so I don't want the exact code, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.