Skip to content

Instantly share code, notes, and snippets.

@landaire
Created July 25, 2012 22:32
Show Gist options
  • Save landaire/3179120 to your computer and use it in GitHub Desktop.
Save landaire/3179120 to your computer and use it in GitHub Desktop.
Mount game directory
extern "C" char* ExLoadedImageName; // not sure if this actually works or not. If it doesn't do:
// XexGetProcedureAddress(KernelHandle, 431, &LoadedImageName); // ExLoadedImageName
typedef struct _AnsiString {
USHORT Length;
USHORT MaximumLength;
PCHAR Buffer;
} AnsiString;
extern "C"
{
//-------------------------------------------------------------------------------------
// Name: ObCreateSymbolicLink
// Desc: Creates a symbolic link for a device path
//-------------------------------------------------------------------------------------
DWORD WINAPI ObCreateSymbolicLink( AnsiString* LinkName,
AnsiString* DevicePath);
//-------------------------------------------------------------------------------------
// Name: ObDeleteSymbolicLink
// Desc: Destroys a linked path
//-------------------------------------------------------------------------------------
DWORD WINAPI ObDeleteSymbolicLink( AnsiString* LinkName);
//-------------------------------------------------------------------------------------
// Name: XexGetModuleHandle
// Desc: Gets a HANDLE for a module already loaded in memory
//-------------------------------------------------------------------------------------
DWORD XBOXAPI WINAPI XexGetModuleHandle( const char* ModuleName,
HANDLE* outHandle );
//-------------------------------------------------------------------------------------
// Name: XexGetProcdureAddress
// Desc: Gets the address to a function within a module already loaded in memory
//-------------------------------------------------------------------------------------
DWORD XBOXAPI WINAPI XexGetProcedureAddress( HANDLE Module,
DWORD ordinal,
DWORD* OutAddress );
}
AnsiString CreateAnsiString(const char* String)
{
char *Buffer = new char[strlen(String) + 1];
memset(Buffer, 0, strlen(String) + 1);
sprintf(Buffer, String);
AnsiString as =
{
strlen(String), strlen(String), Buffer
};
return as;
}
//-------------------------------------------------------------------------------------
// Name: MountPartition
// Desc: Mounts a partition, making it ready for reading/writing
// Notes: DevicePath parameter should contain preceding backslashes (e.g. \\Device\\Flash)
// and Link should not have trailing backslashes (e.g. flash:)
//-------------------------------------------------------------------------------------
DWORD MountPartition(const char* DevicePath, const char* Link)
{
char mountName[31];
sprintf_s( mountName,"\\??\\%s", Link );
AnsiString deviceOriginal = // Original device path
{ strlen(DevicePath), // Length of string
strlen(DevicePath) + 1, // Length of string + 1 (null terminator)
(char*)DevicePath }; // String
AnsiString deviceMounted = // Mounted link
{ strlen(mountName),
strlen(mountName) + 1,
mountName };
return ObCreateSymbolicLink( &deviceMounted,
&deviceOriginal );
}
//-------------------------------------------------------------------------------------
// Name: UnmountPartition
// Desc: Unmounts a linked partition
//-------------------------------------------------------------------------------------
DWORD UnmountPartition(char* link)
{
char mountName[31];
sprintf_s( mountName,"\\??\\%s", link );
AnsiString deviceMounted = // Mounted link
{ strlen(mountName), // Length of string
strlen(mountName) + 1, // Length of string + 1 (null terminator)
mountName }; // String
return ObDeleteSymbolicLink(&deviceMounted);
}
void MountGameDirectory( void )
{
std::string XexPath((const char*)LoadedImageName);
XexPath = XexPath.substr(0, XexPath.find_last_of("\\"));
GameDirMounted = !MountPartition(XexPath.c_str(), "g:");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment