Memory Editing/Writing

This is a discussion on Memory Editing/Writing within the C Programming forums, part of the General Programming Boards category; How would I make a program that searches for a number in memory (for example a hiscore in a game) ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    3

    Memory Editing/Writing

    How would I make a program that searches for a number in memory (for example a hiscore in a game) and then displays it memory address and then asks what one you want to edit.

    Then after selecting that one, you enter the new value for which you want it to change to. I have written this so far but I do not know how to use pointers:

    Code:
    #include <stdio.h>
    
    void changemem(int);
    
    int main()
    {
    	int mem;
    	char choice;
    	int newmem;
    	
    	printf("Enter a value you are searching for: ");
    	scanf("%d", &mem);	
    	
    	printf("%d\t%p\n", mem, mem);
    
    	printf("\n\nWould you like to enter a new value for %p? ", mem);
    	fflush(0);
    	choice = getchar();
    	choice = getchar();
    	
    	switch (choice)
    	{
    	case 'y':
    	case 'Y':
    	changemem(mem);	
    	break;
    
    	case 'n':
    	case 'N':
    		break;
    
    	
    	case '\n':
    	case '\b':
    	case '\t':
    		main();
    	
    	default:
    		printf("\nInvalid Choice!\n");
    		main();
    	}
    		
    		
    	return 0;
    }
    
    void changemem(int x)
    {
    	printf("Enter the new value: ");
    	scanf("%p", &x);
    
    	printf("\n\nValue changed!\n");
    	printf("%d\t%p\n", x, x);
    
    	main();
    
    }

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    Why are you recursing main? and fflush(0) will not do a thing.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by sand_man
    and fflush(0) will not do a thing.
    Far from it:
    7.19.5.2 The fflush function

    Synopsis

    1 #include <stdio.h>
    int fflush(FILE *stream);

    Description

    2 If stream points to an output stream or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise, the behavior is undefined.

    3 If stream is a null pointer, the fflush function performs this flushing action on all streams for which the behavior is defined above.

    Returns

    4 The fflush function sets the error indicator for the stream and returns EOF if a write error occurs, otherwise it returns zero.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User joed's Avatar
    Join Date
    Mar 2004
    Posts
    59
    I think you're confusing C's function calls with BASIC's goto command. Put the switch statement in a while loop that tests for a quit condition:

    Code:
    while(!quit) {
            do stuff, set quit = 1 when done
    }
    return 0;
    The called functions should just "return". Never call main! Whenever functions are called, new copies are made in memory, so you're nesting multiple copies of main.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    3
    Quote Originally Posted by joed
    I think you're confusing C's function calls with BASIC's goto command. Put the switch statement in a while loop that tests for a quit condition:

    Code:
    while(!quit) {
            do stuff, set quit = 1 when done
    }
    return 0;
    The called functions should just "return". Never call main! Whenever functions are called, new copies are made in memory, so you're nesting multiple copies of main.
    I don't want it to quit the program though, I want it to go back to the top of main.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    On all but a select few ancient operating systems, what you're trying to do is all but impossible.

    Different programs run in different address spaces, so the actions of one program cannot be affected by the actions of another.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by Dave_Sinkula
    Far from it:
    My bad.

  8. #8
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    the changemem func you r writing does not reflect the changes in mem(callin prog)ssed by value pass it by reference
    Code:
    void changemem(int *x)
    {
    	printf("Enter the new value: ");
    	scanf("%p", x);
    
    	printf("\n\nValue changed!\n");
    	printf("%d\t%p\n", *x, *x);
    
    	main();
    
    }
    when calling a function call it like changemem(&mem).change the prototype also.
    note:- i hv'nt read ur whole code just this part and ur stion how to use pointers in it.

  9. #9
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    If you don't mind using the Microsoft Foundation Classes (and C++, for that matter), take a look at OpenProcess(), ReadProcessMemory(), and WriteProcessMemory().
    Jason Deckard

  10. #10
    Registered User
    Join Date
    Aug 2005
    Posts
    3
    I had it done with rentacoder but in Delphi for like 100 bucks. Thanks anyways guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. available memory from task manager
    By George2 in forum Tech Board
    Replies: 10
    Last Post: 01-18-2008, 01:32 AM
  2. Replies: 4
    Last Post: 01-13-2008, 01:14 AM
  3. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  4. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  5. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 01:15 AM

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