Code Monkey home page Code Monkey logo

Comments (2)

attilathedud avatar attilathedud commented on June 15, 2024

Hey man, glad you found some of it useful.

You said you already understand VirtualProtect, but I need to talk briefly about it to explain the VirtualAlloc and VirtualFree. So if we look at the msdn entry for VirtualProtect, we have the following prototype:

BOOL WINAPI VirtualProtect(
  _In_  LPVOID lpAddress,
  _In_  SIZE_T dwSize,
  _In_  DWORD  flNewProtect,
  _Out_ PDWORD lpflOldProtect
);

The last parameter holds the old protection type of the area we are modifying. Normally we would do something like:

DWORD old_prot;
VirtualProtect(0xDEADBEEF, 4, VM_WHATEVER, &old_prot);
//modify section as we wish
VirtualProtect(0xDEADBEEF, 4, old_prot, NULL);

But since we are in another application's memory space with the DLL, we need to request a section of memory to hold our old_prot variable using VirtualAlloc. Most of the VirtualAlloc's in the examples have the following form:

push 40h
push 1000h
push 4h
push 0
call VirtualAlloc
mov ebx,eax

Which translates into the following C code:

ebx = VirtualAlloc(0, 4, MEM_COMMIT, PAGE_EXECUTE_READWRITE)

Now why do this? Technically we don't have to reprotect the memory, but it's good practice, and I've had more than one game crash on me due to me not reprotecting the code segment properly. Same with VirtualFree - technically we could leave that 4 bytes floating around, but that's messy. When messing around in another process, it's typically best to try and change as little as possible.

~

For the w2s, could you explain what is broken? I never implemented the y variable in my w2s function, so text displays on a static y offset of 100, but the x coordinates correspond. It's been a few years, but when I originally wrote the code I tested extensively and ensured it work. If you could point me to the problem, I could look into it more.

from cod4_hacks.

 avatar commented on June 15, 2024

Woah, I didn't expect you to answer and definitely not that quickly!
The information you provided has been really useful and now I understand correctly, thank man!

As of the W2S, you stated it yourself, that missing 'y' offset, I guess it isn't a bug but simply a missing feature, thank for the clarification, it could be a nice learning experience to try and add it myself.

Peace man!

from cod4_hacks.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.