Merged in AVJoKe/titanengine (pull request #2)

changed FindEx to use MemoryReadSafe, see #32
This commit is contained in:
Carbon Nobarc 2014-03-14 12:43:32 +01:00
commit fce84f3f33
5 changed files with 84 additions and 36 deletions

View File

@ -62,6 +62,7 @@ __declspec(dllexport) bool TITCALL MatchPatternEx(HANDLE hProcess, void* MemoryT
return true; return true;
} }
__declspec(dllexport) bool TITCALL MatchPattern(void* MemoryToCheck, int SizeOfMemoryToCheck, void* PatternToMatch, int SizeOfPatternToMatch, PBYTE WildCard) __declspec(dllexport) bool TITCALL MatchPattern(void* MemoryToCheck, int SizeOfMemoryToCheck, void* PatternToMatch, int SizeOfPatternToMatch, PBYTE WildCard)
{ {
@ -74,6 +75,7 @@ __declspec(dllexport) bool TITCALL MatchPattern(void* MemoryToCheck, int SizeOfM
return(MatchPatternEx(GetCurrentProcess(), MemoryToCheck, SizeOfMemoryToCheck, PatternToMatch, SizeOfPatternToMatch, WildCard)); return(MatchPatternEx(GetCurrentProcess(), MemoryToCheck, SizeOfMemoryToCheck, PatternToMatch, SizeOfPatternToMatch, WildCard));
} }
} }
__declspec(dllexport) long long TITCALL FindEx(HANDLE hProcess, LPVOID MemoryStart, DWORD MemorySize, LPVOID SearchPattern, DWORD PatternSize, LPBYTE WildCard) __declspec(dllexport) long long TITCALL FindEx(HANDLE hProcess, LPVOID MemoryStart, DWORD MemorySize, LPVOID SearchPattern, DWORD PatternSize, LPBYTE WildCard)
{ {
if(!hProcess || !MemoryStart ||!MemorySize || !SearchPattern || !PatternSize) if(!hProcess || !MemoryStart ||!MemorySize || !SearchPattern || !PatternSize)
@ -98,14 +100,14 @@ __declspec(dllexport) long long TITCALL FindEx(HANDLE hProcess, LPVOID MemorySta
if(hProcess != GetCurrentProcess()) if(hProcess != GetCurrentProcess())
{ {
ueReadBuffer = ueReadBuf.Allocate(MemorySize); ueReadBuffer = ueReadBuf.Allocate(MemorySize);
if(ueReadBuffer && !ReadProcessMemory(hProcess, MemoryStart, ueReadBuffer, MemorySize, &ueNumberOfBytesRead)) if(ueReadBuffer && !MemoryReadSafe(hProcess, MemoryStart, ueReadBuffer, MemorySize, &ueNumberOfBytesRead))
{ {
if(ueNumberOfBytesRead == NULL) if(ueNumberOfBytesRead == NULL)
{ {
if(VirtualQueryEx(hProcess, MemoryStart, &memoryInformation, sizeof memoryInformation) != NULL) if(VirtualQueryEx(hProcess, MemoryStart, &memoryInformation, sizeof memoryInformation) != NULL)
{ {
MemorySize = (DWORD)((ULONG_PTR)memoryInformation.BaseAddress + memoryInformation.RegionSize - (ULONG_PTR)MemoryStart); MemorySize = (DWORD)((ULONG_PTR)memoryInformation.BaseAddress + memoryInformation.RegionSize - (ULONG_PTR)MemoryStart);
if(!ReadProcessMemory(hProcess, MemoryStart, ueReadBuffer, MemorySize, &ueNumberOfBytesRead)) if(!MemoryReadSafe(hProcess, MemoryStart, ueReadBuffer, MemorySize, &ueNumberOfBytesRead))
{ {
return 0; return 0;
} }
@ -186,6 +188,7 @@ __declspec(dllexport) bool TITCALL FillEx(HANDLE hProcess, LPVOID MemoryStart, D
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL Fill(LPVOID MemoryStart, DWORD MemorySize, PBYTE FillByte) __declspec(dllexport) bool TITCALL Fill(LPVOID MemoryStart, DWORD MemorySize, PBYTE FillByte)
{ {
@ -198,6 +201,7 @@ __declspec(dllexport) bool TITCALL Fill(LPVOID MemoryStart, DWORD MemorySize, PB
return(FillEx(GetCurrentProcess(), MemoryStart, MemorySize, FillByte)); return(FillEx(GetCurrentProcess(), MemoryStart, MemorySize, FillByte));
} }
} }
__declspec(dllexport) bool TITCALL PatchEx(HANDLE hProcess, LPVOID MemoryStart, DWORD MemorySize, LPVOID ReplacePattern, DWORD ReplaceSize, bool AppendNOP, bool PrependNOP) __declspec(dllexport) bool TITCALL PatchEx(HANDLE hProcess, LPVOID MemoryStart, DWORD MemorySize, LPVOID ReplacePattern, DWORD ReplaceSize, bool AppendNOP, bool PrependNOP)
{ {
@ -251,6 +255,7 @@ __declspec(dllexport) bool TITCALL PatchEx(HANDLE hProcess, LPVOID MemoryStart,
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL Patch(LPVOID MemoryStart, DWORD MemorySize, LPVOID ReplacePattern, DWORD ReplaceSize, bool AppendNOP, bool PrependNOP) __declspec(dllexport) bool TITCALL Patch(LPVOID MemoryStart, DWORD MemorySize, LPVOID ReplacePattern, DWORD ReplaceSize, bool AppendNOP, bool PrependNOP)
{ {
@ -263,6 +268,7 @@ __declspec(dllexport) bool TITCALL Patch(LPVOID MemoryStart, DWORD MemorySize, L
return(PatchEx(GetCurrentProcess(), MemoryStart, MemorySize, ReplacePattern, ReplaceSize, AppendNOP, PrependNOP)); return(PatchEx(GetCurrentProcess(), MemoryStart, MemorySize, ReplacePattern, ReplaceSize, AppendNOP, PrependNOP));
} }
} }
__declspec(dllexport) bool TITCALL ReplaceEx(HANDLE hProcess, LPVOID MemoryStart, DWORD MemorySize, LPVOID SearchPattern, DWORD PatternSize, DWORD NumberOfRepetitions, LPVOID ReplacePattern, DWORD ReplaceSize, PBYTE WildCard) __declspec(dllexport) bool TITCALL ReplaceEx(HANDLE hProcess, LPVOID MemoryStart, DWORD MemorySize, LPVOID SearchPattern, DWORD PatternSize, DWORD NumberOfRepetitions, LPVOID ReplacePattern, DWORD ReplaceSize, PBYTE WildCard)
{ {
@ -303,6 +309,7 @@ __declspec(dllexport) bool TITCALL ReplaceEx(HANDLE hProcess, LPVOID MemoryStart
return true; return true;
} }
} }
__declspec(dllexport) bool TITCALL Replace(LPVOID MemoryStart, DWORD MemorySize, LPVOID SearchPattern, DWORD PatternSize, DWORD NumberOfRepetitions, LPVOID ReplacePattern, DWORD ReplaceSize, PBYTE WildCard) __declspec(dllexport) bool TITCALL Replace(LPVOID MemoryStart, DWORD MemorySize, LPVOID SearchPattern, DWORD PatternSize, DWORD NumberOfRepetitions, LPVOID ReplacePattern, DWORD ReplaceSize, PBYTE WildCard)
{ {

View File

@ -15,7 +15,6 @@ static void* buffPatchedEntry;
// Internal.Engine.Hook.functions: // Internal.Engine.Hook.functions:
static bool ProcessHookScanAddNewHook(PHOOK_ENTRY HookDetails, void* ptrOriginalInstructions, PLIBRARY_ITEM_DATAW ModuleInformation, DWORD SizeOfImage) static bool ProcessHookScanAddNewHook(PHOOK_ENTRY HookDetails, void* ptrOriginalInstructions, PLIBRARY_ITEM_DATAW ModuleInformation, DWORD SizeOfImage)
{ {
HOOK_ENTRY MyhookEntry = {}; HOOK_ENTRY MyhookEntry = {};
RtlMoveMemory(&MyhookEntry, HookDetails, sizeof HOOK_ENTRY); RtlMoveMemory(&MyhookEntry, HookDetails, sizeof HOOK_ENTRY);
@ -79,17 +78,17 @@ __declspec(dllexport) bool TITCALL HooksSafeTransitionEx(LPVOID HookAddressArray
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL HooksSafeTransition(LPVOID HookAddress, bool TransitionStart) __declspec(dllexport) bool TITCALL HooksSafeTransition(LPVOID HookAddress, bool TransitionStart)
{ {
void* aHookAddress[1]; void* aHookAddress[1];
aHookAddress[0] = HookAddress; aHookAddress[0] = HookAddress;
return(HooksSafeTransitionEx(&aHookAddress[0], sizeof aHookAddress, TransitionStart)); return(HooksSafeTransitionEx(&aHookAddress[0], sizeof aHookAddress, TransitionStart));
} }
__declspec(dllexport) bool TITCALL HooksIsAddressRedirected(LPVOID HookAddress) __declspec(dllexport) bool TITCALL HooksIsAddressRedirected(LPVOID HookAddress)
{ {
for(unsigned int i = 0; i < hookEntry.size(); i++) for(unsigned int i = 0; i < hookEntry.size(); i++)
{ {
if(hookEntry[i].HookAddress == HookAddress && hookEntry[i].IATHook == false && hookEntry[i].HookIsEnabled == true) if(hookEntry[i].HookAddress == HookAddress && hookEntry[i].IATHook == false && hookEntry[i].HookIsEnabled == true)
@ -99,9 +98,9 @@ __declspec(dllexport) bool TITCALL HooksIsAddressRedirected(LPVOID HookAddress)
} }
return false; return false;
} }
__declspec(dllexport) void* TITCALL HooksGetTrampolineAddress(LPVOID HookAddress) __declspec(dllexport) void* TITCALL HooksGetTrampolineAddress(LPVOID HookAddress)
{ {
for(unsigned int i = 0; i < hookEntry.size(); i++) for(unsigned int i = 0; i < hookEntry.size(); i++)
{ {
if(hookEntry[i].HookAddress == HookAddress) if(hookEntry[i].HookAddress == HookAddress)
@ -111,9 +110,9 @@ __declspec(dllexport) void* TITCALL HooksGetTrampolineAddress(LPVOID HookAddress
} }
return(NULL); return(NULL);
} }
__declspec(dllexport) void* TITCALL HooksGetHookEntryDetails(LPVOID HookAddress) __declspec(dllexport) void* TITCALL HooksGetHookEntryDetails(LPVOID HookAddress)
{ {
for(unsigned int i = 0; i < hookEntry.size(); i++) for(unsigned int i = 0; i < hookEntry.size(); i++)
{ {
if(hookEntry[i].HookAddress == HookAddress) if(hookEntry[i].HookAddress == HookAddress)
@ -123,9 +122,9 @@ __declspec(dllexport) void* TITCALL HooksGetHookEntryDetails(LPVOID HookAddress)
} }
return(NULL); return(NULL);
} }
__declspec(dllexport) bool TITCALL HooksInsertNewRedirection(LPVOID HookAddress, LPVOID RedirectTo, int HookType) __declspec(dllexport) bool TITCALL HooksInsertNewRedirection(LPVOID HookAddress, LPVOID RedirectTo, int HookType)
{ {
#if !defined(_WIN64) #if !defined(_WIN64)
int j; int j;
unsigned int i; unsigned int i;
@ -411,6 +410,7 @@ __declspec(dllexport) bool TITCALL HooksInsertNewRedirection(LPVOID HookAddress,
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL HooksInsertNewIATRedirectionEx(ULONG_PTR FileMapVA, ULONG_PTR LoadedModuleBase, char* szHookFunction, LPVOID RedirectTo) __declspec(dllexport) bool TITCALL HooksInsertNewIATRedirectionEx(ULONG_PTR FileMapVA, ULONG_PTR LoadedModuleBase, char* szHookFunction, LPVOID RedirectTo)
{ {
@ -561,9 +561,9 @@ __declspec(dllexport) bool TITCALL HooksInsertNewIATRedirectionEx(ULONG_PTR File
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL HooksInsertNewIATRedirection(char* szModuleName, char* szHookFunction, LPVOID RedirectTo) __declspec(dllexport) bool TITCALL HooksInsertNewIATRedirection(char* szModuleName, char* szHookFunction, LPVOID RedirectTo)
{ {
HANDLE FileHandle; HANDLE FileHandle;
DWORD FileSize; DWORD FileSize;
HANDLE FileMap; HANDLE FileMap;
@ -590,9 +590,9 @@ __declspec(dllexport) bool TITCALL HooksInsertNewIATRedirection(char* szModuleNa
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL HooksRemoveRedirection(LPVOID HookAddress, bool RemoveAll) __declspec(dllexport) bool TITCALL HooksRemoveRedirection(LPVOID HookAddress, bool RemoveAll)
{ {
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
if(!RemoveAll) if(!RemoveAll)
@ -626,9 +626,9 @@ __declspec(dllexport) bool TITCALL HooksRemoveRedirection(LPVOID HookAddress, bo
return true; return true;
} }
} }
__declspec(dllexport) bool TITCALL HooksRemoveRedirectionsForModule(HMODULE ModuleBase) __declspec(dllexport) bool TITCALL HooksRemoveRedirectionsForModule(HMODULE ModuleBase)
{ {
int j = NULL; int j = NULL;
unsigned int i = (unsigned int)hookEntry.size(); unsigned int i = (unsigned int)hookEntry.size();
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
@ -661,9 +661,9 @@ __declspec(dllexport) bool TITCALL HooksRemoveRedirectionsForModule(HMODULE Modu
} }
return true; return true;
} }
__declspec(dllexport) bool TITCALL HooksRemoveIATRedirection(char* szModuleName, char* szHookFunction, bool RemoveAll) __declspec(dllexport) bool TITCALL HooksRemoveIATRedirection(char* szModuleName, char* szHookFunction, bool RemoveAll)
{ {
unsigned int i = (unsigned int)hookEntry.size() - 1; unsigned int i = (unsigned int)hookEntry.size() - 1;
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
HMODULE ModuleBase = GetModuleHandleA(szModuleName); HMODULE ModuleBase = GetModuleHandleA(szModuleName);
@ -687,9 +687,9 @@ __declspec(dllexport) bool TITCALL HooksRemoveIATRedirection(char* szModuleName,
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL HooksDisableRedirection(LPVOID HookAddress, bool DisableAll) __declspec(dllexport) bool TITCALL HooksDisableRedirection(LPVOID HookAddress, bool DisableAll)
{ {
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
if(!DisableAll) if(!DisableAll)
@ -723,9 +723,9 @@ __declspec(dllexport) bool TITCALL HooksDisableRedirection(LPVOID HookAddress, b
return true; return true;
} }
} }
__declspec(dllexport) bool TITCALL HooksDisableRedirectionsForModule(HMODULE ModuleBase) __declspec(dllexport) bool TITCALL HooksDisableRedirectionsForModule(HMODULE ModuleBase)
{ {
int j = NULL; int j = NULL;
unsigned int i = (unsigned int)hookEntry.size(); unsigned int i = (unsigned int)hookEntry.size();
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
@ -758,9 +758,9 @@ __declspec(dllexport) bool TITCALL HooksDisableRedirectionsForModule(HMODULE Mod
} }
return true; return true;
} }
__declspec(dllexport) bool TITCALL HooksDisableIATRedirection(char* szModuleName, char* szHookFunction, bool DisableAll) __declspec(dllexport) bool TITCALL HooksDisableIATRedirection(char* szModuleName, char* szHookFunction, bool DisableAll)
{ {
unsigned int i = (unsigned int)hookEntry.size() - 1; unsigned int i = (unsigned int)hookEntry.size() - 1;
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
HMODULE ModuleBase = GetModuleHandleA(szModuleName); HMODULE ModuleBase = GetModuleHandleA(szModuleName);
@ -787,9 +787,9 @@ __declspec(dllexport) bool TITCALL HooksDisableIATRedirection(char* szModuleName
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL HooksEnableRedirection(LPVOID HookAddress, bool EnableAll) __declspec(dllexport) bool TITCALL HooksEnableRedirection(LPVOID HookAddress, bool EnableAll)
{ {
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
if(!EnableAll) if(!EnableAll)
@ -823,9 +823,9 @@ __declspec(dllexport) bool TITCALL HooksEnableRedirection(LPVOID HookAddress, bo
return true; return true;
} }
} }
__declspec(dllexport) bool TITCALL HooksEnableRedirectionsForModule(HMODULE ModuleBase) __declspec(dllexport) bool TITCALL HooksEnableRedirectionsForModule(HMODULE ModuleBase)
{ {
int j = NULL; int j = NULL;
unsigned int i = (unsigned int)hookEntry.size(); unsigned int i = (unsigned int)hookEntry.size();
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
@ -858,9 +858,9 @@ __declspec(dllexport) bool TITCALL HooksEnableRedirectionsForModule(HMODULE Modu
} }
return true; return true;
} }
__declspec(dllexport) bool TITCALL HooksEnableIATRedirection(char* szModuleName, char* szHookFunction, bool EnableAll) __declspec(dllexport) bool TITCALL HooksEnableIATRedirection(char* szModuleName, char* szHookFunction, bool EnableAll)
{ {
unsigned int i = (unsigned int)hookEntry.size() - 1; unsigned int i = (unsigned int)hookEntry.size() - 1;
DWORD OldProtect = PAGE_READONLY; DWORD OldProtect = PAGE_READONLY;
HMODULE ModuleBase = GetModuleHandleA(szModuleName); HMODULE ModuleBase = GetModuleHandleA(szModuleName);
@ -887,9 +887,9 @@ __declspec(dllexport) bool TITCALL HooksEnableIATRedirection(char* szModuleName,
} }
return false; return false;
} }
__declspec(dllexport) void TITCALL HooksScanModuleMemory(HMODULE ModuleBase, LPVOID CallBack) __declspec(dllexport) void TITCALL HooksScanModuleMemory(HMODULE ModuleBase, LPVOID CallBack)
{ {
unsigned int i; unsigned int i;
bool FileIs64 = false; bool FileIs64 = false;
bool FileError = false; bool FileError = false;
@ -1106,9 +1106,9 @@ __declspec(dllexport) void TITCALL HooksScanModuleMemory(HMODULE ModuleBase, LPV
} }
} }
} }
__declspec(dllexport) void TITCALL HooksScanEntireProcessMemory(LPVOID CallBack) __declspec(dllexport) void TITCALL HooksScanEntireProcessMemory(LPVOID CallBack)
{ {
unsigned int i; unsigned int i;
DWORD cbNeeded = 0; DWORD cbNeeded = 0;
HMODULE EnumeratedModules[1024] = {0}; HMODULE EnumeratedModules[1024] = {0};
@ -1122,6 +1122,7 @@ __declspec(dllexport) void TITCALL HooksScanEntireProcessMemory(LPVOID CallBack)
} }
} }
} }
__declspec(dllexport) void TITCALL HooksScanEntireProcessMemoryEx() __declspec(dllexport) void TITCALL HooksScanEntireProcessMemoryEx()
{ {
HooksScanEntireProcessMemory(&ProcessHookScanAddNewHook); HooksScanEntireProcessMemory(&ProcessHookScanAddNewHook);

View File

@ -14,17 +14,20 @@ __declspec(dllexport) bool TITCALL LibrarianSetBreakPoint(char* szLibraryName, D
NewLibrarianData.bpxSingleShoot = SingleShoot; NewLibrarianData.bpxSingleShoot = SingleShoot;
NewLibrarianData.bpxType = bpxType; NewLibrarianData.bpxType = bpxType;
LibrarianData.push_back(NewLibrarianData); LibrarianData.push_back(NewLibrarianData);
return true; return true;
} }
__declspec(dllexport) bool TITCALL LibrarianRemoveBreakPoint(char* szLibraryName, DWORD bpxType) __declspec(dllexport) bool TITCALL LibrarianRemoveBreakPoint(char* szLibraryName, DWORD bpxType)
{ {
int libbpcount=LibrarianData.size(); for(int i = LibrarianData.size() - 1; i >- 1; i--)
for(int i=libbpcount=1; i>-1; i--) {
if(!lstrcmpiA(szLibraryName, LibrarianData.at(i).szLibraryName) && (LibrarianData.at(i).bpxType == bpxType || bpxType == UE_ON_LIB_ALL)) if(!lstrcmpiA(szLibraryName, LibrarianData.at(i).szLibraryName) && (LibrarianData.at(i).bpxType == bpxType || bpxType == UE_ON_LIB_ALL))
{ {
LibrarianData.erase(LibrarianData.begin()+i); LibrarianData.erase(LibrarianData.begin() + i);
} }
}
return true; return true;
} }
@ -32,6 +35,7 @@ __declspec(dllexport) void* TITCALL LibrarianGetLibraryInfo(char* szLibraryName)
{ {
if(!szLibraryName) if(!szLibraryName)
return NULL; return NULL;
wchar_t uniLibraryName[MAX_PATH] = {}; wchar_t uniLibraryName[MAX_PATH] = {};
PLIBRARY_ITEM_DATAW LibInfo; PLIBRARY_ITEM_DATAW LibInfo;
MultiByteToWideChar(CP_ACP, NULL, szLibraryName, lstrlenA(szLibraryName)+1, uniLibraryName, sizeof(uniLibraryName)/(sizeof(uniLibraryName[0]))); MultiByteToWideChar(CP_ACP, NULL, szLibraryName, lstrlenA(szLibraryName)+1, uniLibraryName, sizeof(uniLibraryName)/(sizeof(uniLibraryName[0])));
@ -45,22 +49,28 @@ __declspec(dllexport) void* TITCALL LibrarianGetLibraryInfo(char* szLibraryName)
LibraryInfoData.hFileMappingView = LibInfo->hFileMappingView; LibraryInfoData.hFileMappingView = LibInfo->hFileMappingView;
WideCharToMultiByte(CP_ACP, NULL, LibInfo->szLibraryName, -1, &LibraryInfoData.szLibraryName[0], sizeof LibraryInfoData.szLibraryName, NULL, NULL); WideCharToMultiByte(CP_ACP, NULL, LibInfo->szLibraryName, -1, &LibraryInfoData.szLibraryName[0], sizeof LibraryInfoData.szLibraryName, NULL, NULL);
WideCharToMultiByte(CP_ACP, NULL, LibInfo->szLibraryPath, -1, &LibraryInfoData.szLibraryPath[0], sizeof LibraryInfoData.szLibraryPath, NULL, NULL); WideCharToMultiByte(CP_ACP, NULL, LibInfo->szLibraryPath, -1, &LibraryInfoData.szLibraryPath[0], sizeof LibraryInfoData.szLibraryPath, NULL, NULL);
return((void*)&LibraryInfoData); return((void*)&LibraryInfoData);
} }
return(NULL);
return NULL;
} }
__declspec(dllexport) void* TITCALL LibrarianGetLibraryInfoW(wchar_t* szLibraryName) __declspec(dllexport) void* TITCALL LibrarianGetLibraryInfoW(wchar_t* szLibraryName)
{ {
static LIBRARY_ITEM_DATAW LibraryInfo; static LIBRARY_ITEM_DATAW LibraryInfo;
memset(&LibraryInfo, 0, sizeof(LIBRARY_ITEM_DATAW)); memset(&LibraryInfo, 0, sizeof(LIBRARY_ITEM_DATAW));
int libcount=hListLibrary.size(); int libcount = hListLibrary.size();
for(int i=0; i<libcount; i++)
for(int i = 0; i < libcount; i++)
{
if(hListLibrary.at(i).hFile != INVALID_HANDLE_VALUE && !lstrcmpiW(hListLibrary.at(i).szLibraryName, szLibraryName)) if(hListLibrary.at(i).hFile != INVALID_HANDLE_VALUE && !lstrcmpiW(hListLibrary.at(i).szLibraryName, szLibraryName))
{ {
memcpy(&LibraryInfo, &hListLibrary.at(i), sizeof(LIBRARY_ITEM_DATAW)); memcpy(&LibraryInfo, &hListLibrary.at(i), sizeof(LIBRARY_ITEM_DATAW));
return &LibraryInfo; return &LibraryInfo;
} }
}
return NULL; return NULL;
} }
@ -77,22 +87,29 @@ __declspec(dllexport) void* TITCALL LibrarianGetLibraryInfoEx(void* BaseOfDll)
LibraryInfoData.hFileMappingView = LibInfo->hFileMappingView; LibraryInfoData.hFileMappingView = LibInfo->hFileMappingView;
WideCharToMultiByte(CP_ACP, NULL, LibInfo->szLibraryName, -1, &LibraryInfoData.szLibraryName[0], sizeof LibraryInfoData.szLibraryName, NULL, NULL); WideCharToMultiByte(CP_ACP, NULL, LibInfo->szLibraryName, -1, &LibraryInfoData.szLibraryName[0], sizeof LibraryInfoData.szLibraryName, NULL, NULL);
WideCharToMultiByte(CP_ACP, NULL, LibInfo->szLibraryPath, -1, &LibraryInfoData.szLibraryPath[0], sizeof LibraryInfoData.szLibraryPath, NULL, NULL); WideCharToMultiByte(CP_ACP, NULL, LibInfo->szLibraryPath, -1, &LibraryInfoData.szLibraryPath[0], sizeof LibraryInfoData.szLibraryPath, NULL, NULL);
return((void*)&LibraryInfoData);
return (void*)&LibraryInfoData;
} }
return(NULL);
return NULL;
} }
__declspec(dllexport) void* TITCALL LibrarianGetLibraryInfoExW(void* BaseOfDll) __declspec(dllexport) void* TITCALL LibrarianGetLibraryInfoExW(void* BaseOfDll)
{ {
static LIBRARY_ITEM_DATAW LibraryData; static LIBRARY_ITEM_DATAW LibraryData;
memset(&LibraryData, 0, sizeof(LIBRARY_ITEM_DATAW)); memset(&LibraryData, 0, sizeof(LIBRARY_ITEM_DATAW));
int libcount=hListLibrary.size(); int libcount = hListLibrary.size();
for(int i=0; i<libcount; i++)
for(int i = 0; i < libcount; i++)
{
if(hListLibrary.at(i).hFile != INVALID_HANDLE_VALUE && hListLibrary.at(i).BaseOfDll == BaseOfDll) if(hListLibrary.at(i).hFile != INVALID_HANDLE_VALUE && hListLibrary.at(i).BaseOfDll == BaseOfDll)
{ {
memcpy(&LibraryData, &hListLibrary.at(i), sizeof(LIBRARY_ITEM_DATAW)); memcpy(&LibraryData, &hListLibrary.at(i), sizeof(LIBRARY_ITEM_DATAW));
return &LibraryData; return &LibraryData;
} }
}
return NULL; return NULL;
} }
@ -100,10 +117,13 @@ __declspec(dllexport) void TITCALL LibrarianEnumLibraryInfo(void* EnumCallBack)
{ {
if(!EnumCallBack) if(!EnumCallBack)
return; return;
typedef void(TITCALL *fEnumCallBack)(LPVOID fLibraryDetail); typedef void(TITCALL *fEnumCallBack)(LPVOID fLibraryDetail);
fEnumCallBack myEnumCallBack = (fEnumCallBack)EnumCallBack; fEnumCallBack myEnumCallBack = (fEnumCallBack)EnumCallBack;
int libcount=hListLibrary.size(); int libcount = hListLibrary.size();
for(int i=0; i<libcount; i++)
for(int i = 0; i < libcount; i++)
{
if(hListLibrary.at(i).hFile != INVALID_HANDLE_VALUE) if(hListLibrary.at(i).hFile != INVALID_HANDLE_VALUE)
{ {
__try __try
@ -123,16 +143,20 @@ __declspec(dllexport) void TITCALL LibrarianEnumLibraryInfo(void* EnumCallBack)
break; break;
} }
} }
}
} }
__declspec(dllexport) void TITCALL LibrarianEnumLibraryInfoW(void* EnumCallBack) __declspec(dllexport) void TITCALL LibrarianEnumLibraryInfoW(void* EnumCallBack)
{ {
if(!EnumCallBack) if(!EnumCallBack)
return; return;
typedef void(TITCALL *fEnumCallBack)(LPVOID fLibraryDetail); typedef void(TITCALL *fEnumCallBack)(LPVOID fLibraryDetail);
fEnumCallBack myEnumCallBack = (fEnumCallBack)EnumCallBack; fEnumCallBack myEnumCallBack = (fEnumCallBack)EnumCallBack;
int libcount=hListLibrary.size(); int libcount = hListLibrary.size();
for(int i=0; i<libcount; i++)
for(int i = 0; i < libcount; i++)
{
if(hListLibrary.at(i).hFile != INVALID_HANDLE_VALUE) if(hListLibrary.at(i).hFile != INVALID_HANDLE_VALUE)
{ {
__try __try
@ -144,4 +168,5 @@ __declspec(dllexport) void TITCALL LibrarianEnumLibraryInfoW(void* EnumCallBack)
break; break;
} }
} }
}
} }

View File

@ -25,6 +25,7 @@ __declspec(dllexport) void TITCALL RelocaterCleanup()
RelocationNewImageBase = NULL; RelocationNewImageBase = NULL;
} }
} }
__declspec(dllexport) void TITCALL RelocaterInit(DWORD MemorySize, ULONG_PTR OldImageBase, ULONG_PTR NewImageBase) __declspec(dllexport) void TITCALL RelocaterInit(DWORD MemorySize, ULONG_PTR OldImageBase, ULONG_PTR NewImageBase)
{ {
@ -39,6 +40,7 @@ __declspec(dllexport) void TITCALL RelocaterInit(DWORD MemorySize, ULONG_PTR Old
RelocationOldImageBase = OldImageBase; RelocationOldImageBase = OldImageBase;
RelocationNewImageBase = NewImageBase; RelocationNewImageBase = NewImageBase;
} }
__declspec(dllexport) void TITCALL RelocaterAddNewRelocation(HANDLE hProcess, ULONG_PTR RelocateAddress, DWORD RelocateState) __declspec(dllexport) void TITCALL RelocaterAddNewRelocation(HANDLE hProcess, ULONG_PTR RelocateAddress, DWORD RelocateState)
{ {
@ -91,10 +93,12 @@ __declspec(dllexport) void TITCALL RelocaterAddNewRelocation(HANDLE hProcess, UL
RtlMoveMemory(RelocationWritePosition, &CopyDummy, 2); RtlMoveMemory(RelocationWritePosition, &CopyDummy, 2);
RelocationWritePosition = (LPVOID)((ULONG_PTR)RelocationWritePosition + 2); RelocationWritePosition = (LPVOID)((ULONG_PTR)RelocationWritePosition + 2);
} }
__declspec(dllexport) long TITCALL RelocaterEstimatedSize() __declspec(dllexport) long TITCALL RelocaterEstimatedSize()
{ {
return((DWORD)((ULONG_PTR)RelocationWritePosition - (ULONG_PTR)RelocationData + 8)); return((DWORD)((ULONG_PTR)RelocationWritePosition - (ULONG_PTR)RelocationData + 8));
} }
__declspec(dllexport) bool TITCALL RelocaterExportRelocation(ULONG_PTR StorePlace, DWORD StorePlaceRVA, ULONG_PTR FileMapVA) __declspec(dllexport) bool TITCALL RelocaterExportRelocation(ULONG_PTR StorePlace, DWORD StorePlaceRVA, ULONG_PTR FileMapVA)
{ {
@ -173,6 +177,7 @@ __declspec(dllexport) bool TITCALL RelocaterExportRelocation(ULONG_PTR StorePlac
RelocationData = NULL; RelocationData = NULL;
return false; return false;
} }
__declspec(dllexport) bool TITCALL RelocaterExportRelocationEx(char* szFileName, char* szSectionName) __declspec(dllexport) bool TITCALL RelocaterExportRelocationEx(char* szFileName, char* szSectionName)
{ {
@ -188,6 +193,7 @@ __declspec(dllexport) bool TITCALL RelocaterExportRelocationEx(char* szFileName,
return false; return false;
} }
} }
__declspec(dllexport) bool TITCALL RelocaterExportRelocationExW(wchar_t* szFileName, char* szSectionName) __declspec(dllexport) bool TITCALL RelocaterExportRelocationExW(wchar_t* szFileName, char* szSectionName)
{ {
@ -226,6 +232,7 @@ __declspec(dllexport) bool TITCALL RelocaterExportRelocationExW(wchar_t* szFileN
return false; return false;
} }
} }
__declspec(dllexport) bool TITCALL RelocaterGrabRelocationTable(HANDLE hProcess, ULONG_PTR MemoryStart, DWORD MemorySize) __declspec(dllexport) bool TITCALL RelocaterGrabRelocationTable(HANDLE hProcess, ULONG_PTR MemoryStart, DWORD MemorySize)
{ {
@ -247,6 +254,7 @@ __declspec(dllexport) bool TITCALL RelocaterGrabRelocationTable(HANDLE hProcess,
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL RelocaterGrabRelocationTableEx(HANDLE hProcess, ULONG_PTR MemoryStart, ULONG_PTR MemorySize, DWORD NtSizeOfImage) __declspec(dllexport) bool TITCALL RelocaterGrabRelocationTableEx(HANDLE hProcess, ULONG_PTR MemoryStart, ULONG_PTR MemorySize, DWORD NtSizeOfImage)
{ {
@ -296,10 +304,12 @@ __declspec(dllexport) bool TITCALL RelocaterMakeSnapshot(HANDLE hProcess, char*
{ {
return(DumpMemory(hProcess, MemoryStart, MemorySize, szSaveFileName)); return(DumpMemory(hProcess, MemoryStart, MemorySize, szSaveFileName));
} }
__declspec(dllexport) bool TITCALL RelocaterMakeSnapshotW(HANDLE hProcess, wchar_t* szSaveFileName, LPVOID MemoryStart, ULONG_PTR MemorySize) __declspec(dllexport) bool TITCALL RelocaterMakeSnapshotW(HANDLE hProcess, wchar_t* szSaveFileName, LPVOID MemoryStart, ULONG_PTR MemorySize)
{ {
return(DumpMemoryW(hProcess, MemoryStart, MemorySize, szSaveFileName)); return(DumpMemoryW(hProcess, MemoryStart, MemorySize, szSaveFileName));
} }
__declspec(dllexport) bool TITCALL RelocaterCompareTwoSnapshots(HANDLE hProcess, ULONG_PTR LoadedImageBase, ULONG_PTR NtSizeOfImage, char* szDumpFile1, char* szDumpFile2, ULONG_PTR MemStart) __declspec(dllexport) bool TITCALL RelocaterCompareTwoSnapshots(HANDLE hProcess, ULONG_PTR LoadedImageBase, ULONG_PTR NtSizeOfImage, char* szDumpFile1, char* szDumpFile2, ULONG_PTR MemStart)
{ {
@ -317,6 +327,7 @@ __declspec(dllexport) bool TITCALL RelocaterCompareTwoSnapshots(HANDLE hProcess,
return false; return false;
} }
} }
__declspec(dllexport) bool TITCALL RelocaterCompareTwoSnapshotsW(HANDLE hProcess, ULONG_PTR LoadedImageBase, ULONG_PTR NtSizeOfImage, wchar_t* szDumpFile1, wchar_t* szDumpFile2, ULONG_PTR MemStart) __declspec(dllexport) bool TITCALL RelocaterCompareTwoSnapshotsW(HANDLE hProcess, ULONG_PTR LoadedImageBase, ULONG_PTR NtSizeOfImage, wchar_t* szDumpFile1, wchar_t* szDumpFile2, ULONG_PTR MemStart)
{ {
@ -430,6 +441,7 @@ __declspec(dllexport) bool TITCALL RelocaterCompareTwoSnapshotsW(HANDLE hProcess
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL RelocaterChangeFileBase(char* szFileName, ULONG_PTR NewImageBase) __declspec(dllexport) bool TITCALL RelocaterChangeFileBase(char* szFileName, ULONG_PTR NewImageBase)
{ {
@ -445,6 +457,7 @@ __declspec(dllexport) bool TITCALL RelocaterChangeFileBase(char* szFileName, ULO
return false; return false;
} }
} }
__declspec(dllexport) bool TITCALL RelocaterChangeFileBaseW(wchar_t* szFileName, ULONG_PTR NewImageBase) __declspec(dllexport) bool TITCALL RelocaterChangeFileBaseW(wchar_t* szFileName, ULONG_PTR NewImageBase)
{ {
@ -604,6 +617,7 @@ __declspec(dllexport) bool TITCALL RelocaterChangeFileBaseW(wchar_t* szFileName,
RemoveGarbageItem(szBackupItem, true); RemoveGarbageItem(szBackupItem, true);
return false; return false;
} }
__declspec(dllexport) bool TITCALL RelocaterRelocateMemoryBlock(ULONG_PTR FileMapVA, ULONG_PTR MemoryLocation, void* RelocateMemory, DWORD RelocateMemorySize, ULONG_PTR CurrentLoadedBase, ULONG_PTR RelocateBase) __declspec(dllexport) bool TITCALL RelocaterRelocateMemoryBlock(ULONG_PTR FileMapVA, ULONG_PTR MemoryLocation, void* RelocateMemory, DWORD RelocateMemorySize, ULONG_PTR CurrentLoadedBase, ULONG_PTR RelocateBase)
{ {
@ -710,6 +724,7 @@ __declspec(dllexport) bool TITCALL RelocaterRelocateMemoryBlock(ULONG_PTR FileMa
} }
return false; return false;
} }
__declspec(dllexport) bool TITCALL RelocaterWipeRelocationTable(char* szFileName) __declspec(dllexport) bool TITCALL RelocaterWipeRelocationTable(char* szFileName)
{ {
@ -725,6 +740,7 @@ __declspec(dllexport) bool TITCALL RelocaterWipeRelocationTable(char* szFileName
return false; return false;
} }
} }
__declspec(dllexport) bool TITCALL RelocaterWipeRelocationTableW(wchar_t* szFileName) __declspec(dllexport) bool TITCALL RelocaterWipeRelocationTableW(wchar_t* szFileName)
{ {

View File

@ -4,7 +4,6 @@
// TitanEngine.TranslateName.functions: // TitanEngine.TranslateName.functions:
__declspec(dllexport) void* TITCALL TranslateNativeName(char* szNativeName) __declspec(dllexport) void* TITCALL TranslateNativeName(char* szNativeName)
{ {
void* TranslatedName = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE); //pointer is returned void* TranslatedName = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE); //pointer is returned
char szDeviceName[3] = "A:"; char szDeviceName[3] = "A:";
char szDeviceCOMName[5] = "COM0"; char szDeviceCOMName[5] = "COM0";
@ -47,9 +46,9 @@ __declspec(dllexport) void* TITCALL TranslateNativeName(char* szNativeName)
VirtualFree(TranslatedName, NULL, MEM_RELEASE); VirtualFree(TranslatedName, NULL, MEM_RELEASE);
return(NULL); return(NULL);
} }
__declspec(dllexport) void* TITCALL TranslateNativeNameW(wchar_t* szNativeName) __declspec(dllexport) void* TITCALL TranslateNativeNameW(wchar_t* szNativeName)
{ {
void* TranslatedName = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE); //pointer is returned void* TranslatedName = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE); //pointer is returned
wchar_t szDeviceName[3] = L"A:"; wchar_t szDeviceName[3] = L"A:";
wchar_t szDeviceCOMName[5] = L"COM0"; wchar_t szDeviceCOMName[5] = L"COM0";