How do you patch a program?

This is a discussion on How do you patch a program? within the C++ Programming forums, part of the General Programming Boards category; I've made a simple program and found a couple of bugs in it. Here is my question. 1.) How do ...

  1. #1
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299

    How do you patch a program?

    I've made a simple program and found a couple of bugs in it. Here is my question.
    1.) How do I calculate the patch offset?
    2.) How do I write to that offset?

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    if you're in a linux system, type
    Code:
    man patch
    and follow the directions. i'm not sure on the details of making patches, but to apply them 9 times out of 10 you type:
    Code:
    patch -p0 < patch_goes_here
    don't know what you do for windows. there's probably a utility somewhere

  3. #3
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    I need to know how i would do this in a windows OS.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    just replace the exe with the new one. thats the easiest way. to make it even more easy on you, split up the program in dlls and modules, that way you can update just the file thats has changed. one way i do it for my game is that i have the game logic as binary files of executable code, that i load on runtime and execute. whenever one of the files is changed, i just update that file. and in most cases files are < 10k. this is on the other hand, not as easy to do. the binary fileloader/executer is no simple thing. But I'll go with DLLs for splitting up the program into smaller parts.

    Patching an EXE is tricky, since a change you did to the program might affect more in the exe than just part you changed. Your changes will change the compilers options for optimizing, so the code can change more than you know...

  5. #5
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    Here is the problem.

    Where learning to use the debuger

    My teacher gave the class a program and told us to make a patch to fix an error in it.
    It is using strncpy() to copy one array into another. Just for example
    Code:
    strncpy(aString, sCopyTo, maxLen);
    well maxLen has a simple "off by 1 error" where it writes over the end of the array.
    That is a definite no no.

    I don't have the source, and the only file i/o she when over is storing text files.

    To be more specific, how do you go to a certain place in a file, then write to that location?

    I can look up the hex value of the asm, but she also wanted us to know the page offset, and patch offset. These I have not been able to find any information on.

    So could someone tell me how to do this?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21