Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful

    How to detect when a game calls a certain function, such as Save or Load.

    Hey guys, I'm looking to re-write Grand Theft Auto: San Andreas's Save/Load system, with an asi that will intercept the calls made by the game when a user want's to Save and Load a game file.

    Now, I know how to use Cheat Engine to find the Ammo, heath addresses etc.

    But how do I find out if a player is Saving or Loading a game file?

    I've already written the code that checks for "gta_sa.exe", since an asi loader will load it with the game.

    Any help is extremely appreciated!

  2. #2
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    Find the functions that are called when saving/loading and hook them.

    A common method to find functions like that are to look for common strings that pertain to the function at hand. Such as:
    - The name of the save game files.
    - The name of the folder the save games are made in.

    Another method is tracing back to the function by using API breakpoints. In this case, a file is being edited, so you could try setting breakpoints on:
    - CreateFileA
    - CreateFileW

    Then if those are used in the call to save the file/load the file, you can trace back to the function that invoked the API.
    Last edited by atom0s; 06-11-2013 at 03:05 PM.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  3. #3
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    Quote Originally Posted by atom0s View Post
    Find the functions that are called when saving/loading and hook them.

    A common method to find functions like that are to look for common strings that pertain to the function at hand. Such as:
    - The name of the save game files.
    - The name of the folder the save games are made in.

    Another method is tracing back to the function by using API breakpoints. In this case, a file is being edited, so you could try setting breakpoints on:
    - CreateFileA
    - CreateFileW

    Then if those are used in the call to save the file/load the file, you can trace back to the function that invoked the API.
    Thankyou for your reply.
    So is Cheat Engine useless in this case?
    I'm assuming I can't find this data with Cheat Engine?

  4. #4
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    Quote Originally Posted by K^2 View Post
    Thankyou for your reply.
    So is Cheat Engine useless in this case?
    I'm assuming I can't find this data with Cheat Engine?
    If the software is unpacked, I would honestly just do this:

    Hook the CreateFileA\CreateFileW\(Insert any other low-level File Access APIs here) in a DLL, make it a transparent detour and just log all the return addresses and the arguments to the calls of that particular API. You should find that one of them has their arguments as "MySaveGame" and then follow that return address to the caller. Repeat this until you find yourself inside the game and not a filesystem dll (if you land in one in the first place) - you may have to go up several levels as I imagine GTA has a relatively abstract filesystem.



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  5. #5
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    Quote Originally Posted by Jetamay View Post
    If the software is unpacked, I would honestly just do this:

    Hook the CreateFileA\CreateFileW\(Insert any other low-level File Access APIs here) in a DLL, make it a transparent detour and just log all the return addresses and the arguments to the calls of that particular API. You should find that one of them has their arguments as "MySaveGame" and then follow that return address to the caller. Repeat this until you find yourself inside the game and not a filesystem dll (if you land in one in the first place) - you may have to go up several levels as I imagine GTA has a relatively abstract filesystem.
    I've been using ollydbg to find the addresses of CreateFileA, CreateFileW, ReadFile and OpenFile.

    I think they're stored in a block, since the Address I found was the same for all of them, example:

    Address I found holds:
    - CreateFileA
    - CreateFileW
    - ReadFile
    - OpenFile
    - And some others I don't need

    Now, I'm just guessing, maybe I have to dig deeper into that block to find the actual addresses called.

    Are there any tutorials that're specific to my problem?

    Any further assistance in this to bring me a solution would be great.
    Last edited by K^2; 06-11-2013 at 07:09 PM.

  6. #6
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    In Olly just set a breakpoint at the top of the API calls. Then when the break is hit, look at the stack, the return address should be at the top.
    That'll take you back to where the API was invoked at.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  7. #7
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    Quote Originally Posted by atom0s View Post
    In Olly just set a breakpoint at the top of the API calls. Then when the break is hit, look at the stack, the return address should be at the top.
    That'll take you back to where the API was invoked at.
    So I need to leave olly open then run the game, save a file or load one?

  8. #8
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    Quote Originally Posted by K^2 View Post
    So I need to leave olly open then run the game, save a file or load one?
    Easiest way to test if CreateFile is even going to help:
    - Load the game and get all the way to the point where you are about to load a game.
    - Open Olly and attach to your game.
    - Go to CreateFileA / CreateFileW and place the breakpoints at the top.
    - Go back to the game and cause the load / save to happen.
    - See if Olly hit a breakpoint.

    If it did hit a breakpoint, follow the return address that should be at the top of the stack.

    If it did not break, then they are accessing the file by other means.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  9. #9
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    Thankyou for your help and keeping calm with all the questions I'm asking, + respect.

    EDIT: Tried it and the game crashed when trying to overwrite a save file, when saving.
    Minimized to olly and took this screenshot: https://i.imgur.com/sjfPFbo.png

    The only problem was to get control of my PC again I had to end olly's process?
    Attached Thumbnails Attached Thumbnails
    Image1.png  

    image2.png  

    image3.png  

    Image4.png  

    Last edited by K^2; 06-11-2013 at 07:41 PM.

  10. #10
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    Quote Originally Posted by K^2 View Post


    Those images are the steps I took to toggle the breakpoints, did I find the right address and add the breakpoint correctly?

    Thankyou for your help and keeping calm with all the questions I'm asking, + respect.
    Upload the images to a site instead of attaching them here. Have to wait for mod approval for anything attached to posts.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  11. #11
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    Quote Originally Posted by atom0s View Post
    Upload the images to a site instead of attaching them here. Have to wait for mod approval for anything attached to posts.
    Edited my last post

  12. #12
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    Quote Originally Posted by K^2 View Post
    Edited my last post
    Image is way too small to see anything.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  13. #13
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    Quote Originally Posted by atom0s View Post
    Image is way too small to see anything.
    Can you not zoom in? that's a full screenshot and it's everything I see in olly.

    Okay, I've been so stupid.
    I think CreateFileA is always called weather it be, Saving, Loading or overwriting.

    CreateFileA has different modes for the different events.

    For Loading the mode is: OPEN_EXISTING
    I don't know what the other modes are yet.
    So In my asi I just detour the CreateFileA API, then check what Mode it is in? or Check what mode it is in the detour it?
    Last edited by K^2; 06-11-2013 at 08:39 PM.

  14. #14
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    Quote Originally Posted by K^2 View Post
    Thankyou for your help and keeping calm with all the questions I'm asking, + respect.

    EDIT: Tried it and the game crashed when trying to overwrite a save file, when saving.
    Minimized to olly and took this screenshot: https://i.imgur.com/sjfPFbo.png

    The only problem was to get control of my PC again I had to end olly's process?

    Yes, but that doesn't tell you anything. From what I see in the stack, you are reading a file. This is the wrong call to CreateFileA - hence why you need to log it. There will be a million calls to this API, you need to find the right call (where its opening with write access and is writing to a file with a name that is relevant to your save game.) Alternately, if it works, you can break on every call to the API via OllyDbg. Just a heads up though - live analysis on games never works out well. You're always better dissecting with offline analysis then monitoring with a logger of some sort - and repeating that process.

    If you trace back to this where this is called from (by logging the return addresses) you will find what routine in particular is called when you save a game. CreateFileA is a low-level API and it will be called for a million different reasons (including loading files)
    Last edited by radnomguywfq3; 06-11-2013 at 11:26 PM.



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  15. #15
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    Quote Originally Posted by Jetamay View Post
    Yes, but that doesn't tell you anything. From what I see in the stack, you are reading a file. This is the wrong call to CreateFileA - hence why you need to log it. There will be a million calls to this API, you need to find the right call (where its opening with write access and is writing to a file with a name that is relevant to your save game.) Alternately, if it works, you can break on every call to the API via OllyDbg. Just a heads up though - live analysis on games never works out well. You're always better dissecting with offline analysis then monitoring with a logger of some sort - and repeating that process.

    If you trace back to this where this is called from (by logging the return addresses) you will find what routine in particular is called when you save a game. CreateFileA is a low-level API and it will be called for a million different reasons (including loading files)

    How do I do offline analysis?and where is the return address shown?

Page 1 of 3 123 LastLast

Similar Threads

  1. [Tutorial] HOW TO REMOVE THE SPLASH WHEN THE GAME START
    By andryfero in forum Alliance of Valiant Arms (AVA) Tutorials
    Replies: 11
    Last Post: 07-09-2013, 12:15 PM
  2. [Solved] Every injector is detected when I start the game :( HELP
    By DutchArmenian in forum CrossFire Europe Help
    Replies: 5
    Last Post: 08-02-2012, 12:38 AM
  3. [Help] Detecting when In game
    By aneeshgamer in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 9
    Last Post: 03-13-2011, 10:12 AM
  4. HOW CAN I NOT GET MY HACK DETECTED IN A GAME?
    By taker65432 in forum Anti-Cheat
    Replies: 17
    Last Post: 05-28-2010, 12:46 AM
  5. Wierd lines on borders when playin games???
    By thechewu in forum Hardware & Software Support
    Replies: 2
    Last Post: 08-07-2007, 12:48 PM

Tags for this Thread