Some fixes and comments

The final is near, it already compiles :)
This commit is contained in:
binarymaster 2014-12-09 00:59:47 +03:00
parent 87887259b2
commit a449d04619
2 changed files with 41 additions and 53 deletions

View File

@ -400,7 +400,7 @@ bool INI_FILE::GetVariableInSection(char *SectionName, char *VariableName, INI_V
switch(Variable.VariableValue[i+1]) switch(Variable.VariableValue[i+1])
{ {
case '0': break; case '0': break;
case '1': RetVariable->Value[(i/2)] += 1; break; case '1': RetVariable->Value[(i/2)] += 1; break;
case '2': RetVariable->Value[(i/2)] += 2; break; case '2': RetVariable->Value[(i/2)] += 2; break;
case '3': RetVariable->Value[(i/2)] += 3; break; case '3': RetVariable->Value[(i/2)] += 3; break;

View File

@ -21,7 +21,7 @@ typedef struct
{ {
union union
{ {
struct struct
{ {
WORD Minor; WORD Minor;
WORD Major; WORD Major;
@ -68,7 +68,7 @@ bool AlreadyHooked = false;
DWORD INIReadDWordHex(INI_FILE *IniFile, char *Sect, char *VariableName, PLATFORM_DWORD Default) DWORD INIReadDWordHex(INI_FILE *IniFile, char *Sect, char *VariableName, PLATFORM_DWORD Default)
{ {
INI_VAR_DWORD Variable; INI_VAR_DWORD Variable;
if(IniFile->GetVariableInSection(Sect, VariableName, &Variable)) if(IniFile->GetVariableInSection(Sect, VariableName, &Variable))
{ {
return Variable.ValueHex; return Variable.ValueHex;
@ -82,27 +82,17 @@ void INIReadString(INI_FILE *IniFile, char *Sect, char *VariableName, char *Defa
memset(Ret, 0x00, RetSize); memset(Ret, 0x00, RetSize);
if(!IniFile->GetVariableInSection(Sect, VariableName, &Variable)) if(!IniFile->GetVariableInSection(Sect, VariableName, &Variable))
{ {
strcpy_s(Ret, RetSize, Default); strcpy_s(Ret, RetSize, Default);
return; return;
} }
strcpy_s(Ret, RetSize, Variable.Value); strcpy_s(Ret, RetSize, Variable.Value);
} }
int SListFind(INI_SECTION_VARLIST List, char *Name)
{
for (DWORD i = 0; i < List.EntriesCount; i++)
{
if(strcmp(List.NamesEntries[i].String, Name) == 0) return i;
}
return -1;
}
void WriteToLog(LPSTR Text) void WriteToLog(LPSTR Text)
{ {
DWORD dwBytesOfWritten; DWORD dwBytesOfWritten;
// Correct this - LogFile
HANDLE hFile = CreateFile(LogFile, GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hFile = CreateFile(LogFile, GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) return; if (hFile == INVALID_HANDLE_VALUE) return;
@ -114,19 +104,10 @@ void WriteToLog(LPSTR Text)
HMODULE GetCurrentModule() HMODULE GetCurrentModule()
{ {
HMODULE hModule = NULL; HMODULE hModule = NULL;
// Check this
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)GetCurrentModule, &hModule); GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)GetCurrentModule, &hModule);
return hModule; return hModule;
} }
// Correct this
LPCWSTR GetBinaryPath()
{
wchar_t Filename[256];
GetModuleFileName(GetCurrentModule(), &Filename[0], 256);
return &Filename[0];
}
/*PLATFORM_DWORD SearchAddressBySignature(char *StartPosition, PLATFORM_DWORD Size, char *Signature, int SignatureSize) /*PLATFORM_DWORD SearchAddressBySignature(char *StartPosition, PLATFORM_DWORD Size, char *Signature, int SignatureSize)
{ {
PLATFORM_DWORD AddressReturn = -1; PLATFORM_DWORD AddressReturn = -1;
@ -169,7 +150,7 @@ void SetThreadsState(bool Resume)
CurrTh = GetCurrentThreadId(); CurrTh = GetCurrentThreadId();
CurrPr = GetCurrentProcessId(); CurrPr = GetCurrentProcessId();
h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (h != INVALID_HANDLE_VALUE) if (h != INVALID_HANDLE_VALUE)
{ {
@ -187,14 +168,14 @@ void SetThreadsState(bool Resume)
CloseHandle(hThread); CloseHandle(hThread);
} }
} }
} while (Thread32Next(h, &Thread)); } while (Thread32Next(h, &Thread));
CloseHandle(h); CloseHandle(h);
} }
} }
BOOL __stdcall GetModuleVersion(LPCWSTR lptstrModuleName, FILE_VERSION *FileVersion) BOOL __stdcall GetModuleVersion(LPCWSTR lptstrModuleName, FILE_VERSION *FileVersion)
{ {
typedef struct typedef struct
{ {
WORD wLength; WORD wLength;
WORD wValueLength; WORD wValueLength;
@ -211,13 +192,13 @@ BOOL __stdcall GetModuleVersion(LPCWSTR lptstrModuleName, FILE_VERSION *FileVers
{ {
return false; return false;
} }
HRSRC hResourceInfo = FindResourceW(hMod, (LPCWSTR)1, (LPCWSTR)0x10); HRSRC hResourceInfo = FindResourceW(hMod, (LPCWSTR)1, (LPCWSTR)0x10);
if(!hResourceInfo) if(!hResourceInfo)
{ {
return false; return false;
} }
VS_VERSIONINFO *VersionInfo = (VS_VERSIONINFO*)LoadResource(hMod, hResourceInfo); VS_VERSIONINFO *VersionInfo = (VS_VERSIONINFO*)LoadResource(hMod, hResourceInfo);
if(!VersionInfo) if(!VersionInfo)
{ {
@ -233,7 +214,7 @@ BOOL __stdcall GetModuleVersion(LPCWSTR lptstrModuleName, FILE_VERSION *FileVers
BOOL __stdcall GetFileVersion(LPCWSTR lptstrFilename, FILE_VERSION *FileVersion) BOOL __stdcall GetFileVersion(LPCWSTR lptstrFilename, FILE_VERSION *FileVersion)
{ {
typedef struct typedef struct
{ {
WORD wLength; WORD wLength;
WORD wValueLength; WORD wValueLength;
@ -250,13 +231,13 @@ BOOL __stdcall GetFileVersion(LPCWSTR lptstrFilename, FILE_VERSION *FileVersion)
{ {
return false; return false;
} }
HRSRC hResourceInfo = FindResourceW(hFile, (LPCWSTR)1, (LPCWSTR)0x10); HRSRC hResourceInfo = FindResourceW(hFile, (LPCWSTR)1, (LPCWSTR)0x10);
if(!hResourceInfo) if(!hResourceInfo)
{ {
return false; return false;
} }
VS_VERSIONINFO *VersionInfo = (VS_VERSIONINFO*)LoadResource(hFile, hResourceInfo); VS_VERSIONINFO *VersionInfo = (VS_VERSIONINFO*)LoadResource(hFile, hResourceInfo);
if(!VersionInfo) if(!VersionInfo)
{ {
@ -273,7 +254,7 @@ BOOL __stdcall GetFileVersion(LPCWSTR lptstrFilename, FILE_VERSION *FileVersion)
bool OverrideSL(LPWSTR ValueName, DWORD *Value) bool OverrideSL(LPWSTR ValueName, DWORD *Value)
{ {
INI_VAR_DWORD Variable = {0}; INI_VAR_DWORD Variable = {0};
if (IniFile->VariableExists(L"SLPolicy", ValueName)) if (IniFile->VariableExists(L"SLPolicy", ValueName))
{ {
if (!(IniFile->GetVariableInSection(L"SLPolicy", ValueName, &Variable))) *Value = 0; if (!(IniFile->GetVariableInSection(L"SLPolicy", ValueName, &Variable))) *Value = 0;
@ -312,7 +293,7 @@ HRESULT WINAPI New_SLGetWindowsInformationDWORD(PWSTR pwszValueName, DWORD *pdwV
WriteToLog(Log); WriteToLog(Log);
delete[] Log; delete[] Log;
return S_OK; return S_OK;
} }
WriteProcessMemory(GetCurrentProcess(), _SLGetWindowsInformationDWORD, &Old_SLGetWindowsInformationDWORD, sizeof(FARJMP), &bw); WriteProcessMemory(GetCurrentProcess(), _SLGetWindowsInformationDWORD, &Old_SLGetWindowsInformationDWORD, sizeof(FARJMP), &bw);
@ -358,7 +339,7 @@ HRESULT __fastcall New_Win8SL(PWSTR pwszValueName, DWORD *pdwValue)
WriteToLog(Log); WriteToLog(Log);
delete[] Log; delete[] Log;
return S_OK; return S_OK;
} }
Result = _SLGetWindowsInformationDWORD(pwszValueName, pdwValue); Result = _SLGetWindowsInformationDWORD(pwszValueName, pdwValue);
@ -371,7 +352,7 @@ HRESULT __fastcall New_Win8SL(PWSTR pwszValueName, DWORD *pdwValue)
} else { } else {
WriteToLog("Failed\r\n"); WriteToLog("Failed\r\n");
} }
return Result; return Result;
} }
@ -432,7 +413,7 @@ HRESULT WINAPI New_CSLQuery_Initialize()
if (bServerSku) if (bServerSku)
{ {
*bServerSku = INIReadDWordHex(IniFile, "SLInit", "bServerSku", 0); *bServerSku = INIReadDWordHex(IniFile, "SLInit", "bServerSku", 1);
Log = new char[1024]; Log = new char[1024];
wsprintfA(Log, "[0x%p] bServerSku = %d\r\n", bServerSku, *bServerSku); wsprintfA(Log, "[0x%p] bServerSku = %d\r\n", bServerSku, *bServerSku);
@ -441,7 +422,7 @@ HRESULT WINAPI New_CSLQuery_Initialize()
} }
if (bRemoteConnAllowed) if (bRemoteConnAllowed)
{ {
*bRemoteConnAllowed = INIReadDWordHex(IniFile, "SLInit", "bRemoteConnAllowed", 0); *bRemoteConnAllowed = INIReadDWordHex(IniFile, "SLInit", "bRemoteConnAllowed", 1);
Log = new char[1024]; Log = new char[1024];
wsprintfA(Log, "[0x%p] bRemoteConnAllowed = %d\r\n", bRemoteConnAllowed, *bRemoteConnAllowed); wsprintfA(Log, "[0x%p] bRemoteConnAllowed = %d\r\n", bRemoteConnAllowed, *bRemoteConnAllowed);
@ -450,7 +431,7 @@ HRESULT WINAPI New_CSLQuery_Initialize()
} }
if (bFUSEnabled) if (bFUSEnabled)
{ {
*bFUSEnabled = INIReadDWordHex(IniFile, "SLInit", "bFUSEnabled", 0); *bFUSEnabled = INIReadDWordHex(IniFile, "SLInit", "bFUSEnabled", 1);
Log = new char[1024]; Log = new char[1024];
wsprintfA(Log, "[0x%p] bFUSEnabled = %d\r\n", bFUSEnabled, *bFUSEnabled); wsprintfA(Log, "[0x%p] bFUSEnabled = %d\r\n", bFUSEnabled, *bFUSEnabled);
@ -459,7 +440,7 @@ HRESULT WINAPI New_CSLQuery_Initialize()
} }
if (bAppServerAllowed) if (bAppServerAllowed)
{ {
*bAppServerAllowed = INIReadDWordHex(IniFile, "SLInit", "bAppServerAllowed", 0); *bAppServerAllowed = INIReadDWordHex(IniFile, "SLInit", "bAppServerAllowed", 1);
Log = new char[1024]; Log = new char[1024];
wsprintfA(Log, "[0x%p] bAppServerAllowed = %d\r\n", bAppServerAllowed, *bAppServerAllowed); wsprintfA(Log, "[0x%p] bAppServerAllowed = %d\r\n", bAppServerAllowed, *bAppServerAllowed);
@ -468,7 +449,7 @@ HRESULT WINAPI New_CSLQuery_Initialize()
} }
if (bMultimonAllowed) if (bMultimonAllowed)
{ {
*bMultimonAllowed = INIReadDWordHex(IniFile, "SLInit", "bMultimonAllowed", 0); *bMultimonAllowed = INIReadDWordHex(IniFile, "SLInit", "bMultimonAllowed", 1);
Log = new char[1024]; Log = new char[1024];
wsprintfA(Log, "[0x%p] bMultimonAllowed = %d\r\n", bMultimonAllowed, *bMultimonAllowed); wsprintfA(Log, "[0x%p] bMultimonAllowed = %d\r\n", bMultimonAllowed, *bMultimonAllowed);
@ -495,7 +476,7 @@ HRESULT WINAPI New_CSLQuery_Initialize()
} }
if (bInitialized) if (bInitialized)
{ {
*bInitialized = INIReadDWordHex(IniFile, "SLInit", "bInitialized", 0); *bInitialized = INIReadDWordHex(IniFile, "SLInit", "bInitialized", 1);
Log = new char[1024]; Log = new char[1024];
wsprintfA(Log, "[0x%p] bInitialized = %d\r\n", bInitialized, *bInitialized); wsprintfA(Log, "[0x%p] bInitialized = %d\r\n", bInitialized, *bInitialized);
@ -519,8 +500,7 @@ void Hook()
wchar_t ConfigFile[256] = {0x00}; wchar_t ConfigFile[256] = {0x00};
WriteToLog("Loading configuration...\r\n"); WriteToLog("Loading configuration...\r\n");
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>
GetModuleFileName(GetCurrentModule(), ConfigFile, 255); GetModuleFileName(GetCurrentModule(), ConfigFile, 255);
for(DWORD i = wcslen(ConfigFile); i > 0; i--) for(DWORD i = wcslen(ConfigFile); i > 0; i--)
{ {
@ -538,7 +518,7 @@ void Hook()
WriteToLog("Error: Failed to load configuration\r\n"); WriteToLog("Error: Failed to load configuration\r\n");
return; return;
} }
INI_VAR_STRING LogFileVar; INI_VAR_STRING LogFileVar;
if(!(IniFile->GetVariableInSection("Main", "LogFile", &LogFileVar))) if(!(IniFile->GetVariableInSection("Main", "LogFile", &LogFileVar)))
@ -554,6 +534,8 @@ void Hook()
} }
} }
} }
// else...
// LogFileVar => LogFile
char *Log; char *Log;
SIZE_T bw; SIZE_T bw;
@ -739,7 +721,9 @@ void Hook()
SignPtr = (PLATFORM_DWORD)(TermSrvBase + INIReadDWordHex(IniFile, Sect, "LocalOnlyOffset.x86", 0)); SignPtr = (PLATFORM_DWORD)(TermSrvBase + INIReadDWordHex(IniFile, Sect, "LocalOnlyOffset.x86", 0));
IniFile->GetVariableInSection(Sect, "LocalOnlyCode.x86", &Patch); IniFile->GetVariableInSection(Sect, "LocalOnlyCode.x86", &Patch);
#endif #endif
// Patch.Value is char
// WriteProcessMemory uses LPCVOID lpBuffer, so...
// maybe &Patch.Value ?
if (i >= 0) WriteProcessMemory(GetCurrentProcess(), (LPVOID)SignPtr, Patch.Value, Patch.ArraySize, &bw); if (i >= 0) WriteProcessMemory(GetCurrentProcess(), (LPVOID)SignPtr, Patch.Value, Patch.ArraySize, &bw);
} }
#ifdef _WIN64 #ifdef _WIN64
@ -758,7 +742,9 @@ void Hook()
SignPtr = (PLATFORM_DWORD)(TermSrvBase + INIReadDWordHex(IniFile, Sect, "SingleUserOffset.x86", 0)); SignPtr = (PLATFORM_DWORD)(TermSrvBase + INIReadDWordHex(IniFile, Sect, "SingleUserOffset.x86", 0));
IniFile->GetVariableInSection(Sect, "SingleUserCode.x86", &Patch); IniFile->GetVariableInSection(Sect, "SingleUserCode.x86", &Patch);
#endif #endif
// Patch.Value is char
// WriteProcessMemory uses LPCVOID lpBuffer, so...
// maybe &Patch.Value ?
if (i >= 0) WriteProcessMemory(GetCurrentProcess(), (LPVOID)SignPtr, Patch.Value, Patch.ArraySize, &bw); if (i >= 0) WriteProcessMemory(GetCurrentProcess(), (LPVOID)SignPtr, Patch.Value, Patch.ArraySize, &bw);
} }
#ifdef _WIN64 #ifdef _WIN64
@ -777,7 +763,9 @@ void Hook()
SignPtr = (PLATFORM_DWORD)(TermSrvBase + INIReadDWordHex(IniFile, Sect, "DefPolicyOffset.x86", 0)); SignPtr = (PLATFORM_DWORD)(TermSrvBase + INIReadDWordHex(IniFile, Sect, "DefPolicyOffset.x86", 0));
IniFile->GetVariableInSection(Sect, "DefPolicyCode.x86", &Patch); IniFile->GetVariableInSection(Sect, "DefPolicyCode.x86", &Patch);
#endif #endif
// Patch.Value is char
// WriteProcessMemory uses LPCVOID lpBuffer, so...
// maybe &Patch.Value ?
if (i >= 0) WriteProcessMemory(GetCurrentProcess(), (LPVOID)SignPtr, Patch.Value, Patch.ArraySize, &bw); if (i >= 0) WriteProcessMemory(GetCurrentProcess(), (LPVOID)SignPtr, Patch.Value, Patch.ArraySize, &bw);
} }
#ifdef _WIN64 #ifdef _WIN64
@ -809,7 +797,7 @@ void Hook()
Jump.PushOp = 0x68; Jump.PushOp = 0x68;
Jump.PushArg = (PLATFORM_DWORD)New_Win8SL; Jump.PushArg = (PLATFORM_DWORD)New_Win8SL;
Jump.RetOp = 0xC3; Jump.RetOp = 0xC3;
INIReadString(IniFile, Sect, "SLPolicyFunc.x86", "New_Win8SL", FuncName, 1024); INIReadString(IniFile, Sect, "SLPolicyFunc.x86", "New_Win8SL", FuncName, 1024);
if (strcmp(FuncName, "New_Win8SL")) if (strcmp(FuncName, "New_Win8SL"))
@ -853,9 +841,9 @@ void Hook()
Jump.PushOp = 0x68; Jump.PushOp = 0x68;
Jump.PushArg = (PLATFORM_DWORD)New_CSLQuery_Initialize; Jump.PushArg = (PLATFORM_DWORD)New_CSLQuery_Initialize;
Jump.RetOp = 0xC3; Jump.RetOp = 0xC3;
INIReadString(IniFile, Sect, "SLInitFunc.x86", "New_CSLQuery_Initialize", FuncName, 1024); INIReadString(IniFile, Sect, "SLInitFunc.x86", "New_CSLQuery_Initialize", FuncName, 1024);
if (strcmp(FuncName, "New_CSLQuery_Initialize")) if (strcmp(FuncName, "New_CSLQuery_Initialize"))
{ {
Jump.PushArg = (PLATFORM_DWORD)New_CSLQuery_Initialize; Jump.PushArg = (PLATFORM_DWORD)New_CSLQuery_Initialize;
@ -886,5 +874,5 @@ void WINAPI SvchostPushServiceGlobals(void *lpGlobalData)
WriteToLog("> SvchostPushServiceGlobals\r\n"); WriteToLog("> SvchostPushServiceGlobals\r\n");
if (!AlreadyHooked) Hook(); if (!AlreadyHooked) Hook();
if (_SvchostPushServiceGlobals != NULL) _SvchostPushServiceGlobals(lpGlobalData); if (_SvchostPushServiceGlobals != NULL) _SvchostPushServiceGlobals(lpGlobalData);
} }