Xbox 360 Dump Game Memory to file

Discussion in 'MW3 Modding' started by NITRAM, Oct 3, 2012 with 1 replies and 1,048 views.

  1. NITRAM

    NITRAM Getting There

    Messages:
    981
    Likes Received:
    411
    Here is a little cli app I made to dump game memory to a dump.dmp file, it works on mw2 and mw3 enjoy. To use this have the sdk installed and the default console set correctly also worked with xbdm plugin for dashlaunch.

    [​IMG]

    Anyone who whats a GUI of this **** off and make your own, CLI apps are not hard to use.

    Download Link: https://dl.dropbox.com/u/87733846/CODTOOL.exe

    https://www.virustotal.com/file/767...f6dd2b6c2f5a3eb1b50efa80/analysis/1349313336/

    Source
    Code (Text):
    // CODTOOL.cpp : Defines the entry point for the console application.
    //
     
    #pragma once
     
    #include <windows.h>
    #include "xbdm.h"
    #include "XDevkit.h"
    #define _WIN32_DCOM
    #include <wbemidl.h>
    #include <fstream>
    # pragma comment(lib, "wbemuuid.lib")
     
    #ifndef myFunc
    #define myFunc
    DWORD DumpGameMem( IXboxDebugTarget *DebugTarget, DWORD Addr, DWORD Size );
    #endif
     
    using namespace std;
     
    //----------------------------------------------------------------------------
    // Prototypes
    //----------------------------------------------------------------------------
    BOOL LoadXBDM();
     
     
    //----------------------------------------------------------------------------
    // Name: Main
    // Desc: Entry point for program
    //----------------------------------------------------------------------------
     
    int main(int argc, char* argv[])
    {
        IXboxManager *Manager;
        IXboxConsole *Console;
        IXboxDebugTarget *DebugTarget;
     
        BSTR DefaultXbox;
        HRESULT hr;
     
        if(argc == 1)
        {
            printf("--------------------------------\n\n%s GAME\n\nGAME: MW2, MW3\n\nPress enter to exit!\n\n--------------------------------\n\n", argv[0] );
            getchar();
            return 0;
        }
        else
        {
            hr = CoInitializeEx(0, COINIT_MULTITHREADED);
     
            if (FAILED(hr)) {
                printf("Failed to initialize COM library. Error code = 0x%x",hr);
                return hr;
            }
     
            hr = CoCreateInstance(__uuidof(XboxManager),NULL,CLSCTX_INPROC_SERVER,__uuidof(IXboxManager),&(void*&)Manager );
     
            // Attempt to load XBDM.DLL.  The project settings specify to delay load
            // it so as to not break the linker.  So long as we load it manually
            // before we try to use it, all will be well.  Exit main on failure.
     
            if (!LoadXBDM())
                return 0;
     
            hr = Manager->get_DefaultConsole(&DefaultXbox);
            hr = Manager->OpenConsole(DefaultXbox, &Console);
     
     
            if( FAILED(hr) )
                printf("\nERROR:\n\nCould not connect to default Xenon devkit or no devkit name set.\n %x",  hr);
            else
                printf("\nConnection succeeded to xbox!");
     
            hr = Console->get_DebugTarget(&DebugTarget);
            char mw3[] = "MW3";
            char mw2[] = "MW2";
            if(!strcmp(argv[1], mw2))
            {
                printf("\n\nDumping game memory [0x82000000-->0x83DE0000] size: 0x1DE0000...");
                DWORD re = DumpGameMem( DebugTarget, 0x82000000, 0x1DE0000 );
            }
            else if(!strcmp(argv[1], mw3))
            {
                printf("\n\nDumping game memory [0x82000000-->0x84080000] size: 0x2080000...");
                DWORD re = DumpGameMem( DebugTarget, 0x82000000, 0x2080000 );
            }
            else
            {
                printf("--------------------------------\n\n%s GAME\n\nGAME: MW2, MW3\n\nPress enter to exit!\n\n--------------------------------\n\n", argv[0] );
                getchar();
                return 0;
            }
            return 0;
        }
    }
     
    DWORD DumpGameMem( IXboxDebugTarget *DebugTarget, DWORD Addr, DWORD Size )
    {
        byte *buf = new byte[Size];
        DWORD num;
        HRESULT hr = DebugTarget->GetMemory_cpp(Addr, Size, buf, &num);
        printf("Done!\n\nWriting to file...");
        ofstream outfile ("dump.dmp",ofstream::binary);
        outfile.write ((char *)buf,num);
        printf("Done!");
        return num;
    }
     
    //----------------------------------------------------------------------------
    // Name: LoadXBDM
    // Desc: Adds %xedk%\bin\win32 to the path and loads XBDM.DLL.
    //----------------------------------------------------------------------------
    BOOL LoadXBDM()
    {
        char* path;
        char* xedkDir;
        size_t pathSize;
        size_t xedkDirSize;
     
        errno_t err;
     
        err = _dupenv_s(&path, &pathSize, "path");
        if (err)
            return 0;
     
        err = _dupenv_s(&xedkDir, &xedkDirSize, "xedk");
        if (err)
            return 0;
     
        // Build a new path with the %xedk%\bin\win32 directory added.
        // Allocate enough memory for the newPath string.
        char formatBuffer[] = "path=%s\\bin\\win32;%s";
     
        // Calculate how much extra space is needed--this will actually
        // allocate a few bytes more than necessary.
        int formatSize = sizeof(formatBuffer);
        size_t newPathSize = pathSize + xedkDirSize + formatSize;
        char* newPath = new char[newPathSize];
     
        // _snprintf_s will always zero-terminate the buffer.
        _snprintf_s(newPath, newPathSize, newPathSize, formatBuffer, xedkDir ? xedkDir : "", path);
     
        // Update the system path with the new value.  This is so our LoadLibrary
        // call can find XBDM.DLL.
        _putenv(newPath);
     
        // Delete newPath
        delete [] newPath;
     
        // Free path
        if (path)
            free(path);
     
        // Free xedkDir
        if (xedkDir)
            free(xedkDir);
     
        // Call LoadLibrary on XBDM.DLL.
        HMODULE hXBDM = LoadLibrary("xbdm.dll");
     
        // Print an error message and return zero if XBDM.DLL didn't load.
        if (!hXBDM)
        {
            if ( xedkDir )
                printf("\nERROR:\n\nCouldn't load xbdm.dll.\n");
            else
                printf("\nERROR:\n\nCouldn't load xbdm.dll\nXEDK environment variable not set.\n");
            return 0;
        }
     
        // XBDM.DLL loaded.  Return 1 for success.
        return 1;
    }
     
     
    Last edited: Oct 3, 2012
    Xx jAmes t xX and Xb0x360 like this.
  2. Savage Zombie

    Savage Zombie Enthusiast

    Messages:
    155
    Likes Received:
    35
    Looks cool man. Might come in handy for some of my problems!
    Thanks!