Some updates

This commit is contained in:
binarymaster 2014-12-10 01:00:20 +03:00
parent 4054ef493b
commit 31cce7a873
5 changed files with 171 additions and 151 deletions

View File

@ -1,17 +1,17 @@
/* /*
Copyright 2014 Stas'M Corp. Copyright 2014 Stas'M Corp.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
#include "stdafx.h" #include "stdafx.h"
@ -24,23 +24,23 @@ INI_FILE::INI_FILE(wchar_t *FilePath)
DWORD Status = 0; DWORD Status = 0;
DWORD NumberOfBytesRead = 0; DWORD NumberOfBytesRead = 0;
HANDLE hFile = CreateFile(FilePath, GENERIC_ALL, FILE_SHARE_READ|FILE_SHARE_WRITE, HANDLE hFile = CreateFile(FilePath, GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
{ {
return; return;
} }
FileSize = GetFileSize(hFile, NULL); FileSize = GetFileSize(hFile, NULL);
if(FileSize == INVALID_FILE_SIZE) if (FileSize == INVALID_FILE_SIZE)
{ {
return; return;
} }
FileRaw = new char[FileSize]; FileRaw = new char[FileSize];
Status = (bool)ReadFile(hFile, FileRaw, FileSize, &NumberOfBytesRead, NULL); Status = ReadFile(hFile, FileRaw, FileSize, &NumberOfBytesRead, NULL);
if(!Status) if (!Status)
{ {
return; return;
} }
@ -52,7 +52,7 @@ INI_FILE::INI_FILE(wchar_t *FilePath)
INI_FILE::~INI_FILE() INI_FILE::~INI_FILE()
{ {
for(DWORD i = 0; i < IniData.SectionCount; i++) for (DWORD i = 0; i < IniData.SectionCount; i++)
{ {
delete[] IniData.Section[i].Variables; delete[] IniData.Section[i].Variables;
} }
@ -65,9 +65,9 @@ bool INI_FILE::CreateStringsMap()
{ {
DWORD StringsCount = 1; DWORD StringsCount = 1;
for(DWORD i = 0; i < FileSize; i++) for (DWORD i = 0; i < FileSize; i++)
{ {
if(FileRaw[i] == '\r' && FileRaw[i+1] == '\n') StringsCount++; if (FileRaw[i] == '\r' && FileRaw[i + 1] == '\n') StringsCount++;
} }
FileStringsCount = StringsCount; FileStringsCount = StringsCount;
@ -77,11 +77,11 @@ bool INI_FILE::CreateStringsMap()
StringsCount = 1; StringsCount = 1;
for(DWORD i = 0; i < FileSize; i++) for (DWORD i = 0; i < FileSize; i++)
{ {
if(FileRaw[i] == '\r' && FileRaw[i+1] == '\n') if (FileRaw[i] == '\r' && FileRaw[i + 1] == '\n')
{ {
FileStringsMap[StringsCount] = i+2; FileStringsMap[StringsCount] = i + 2;
StringsCount++; StringsCount++;
} }
} }
@ -92,27 +92,27 @@ bool INI_FILE::CreateStringsMap()
int INI_FILE::StrTrim(char* Str) int INI_FILE::StrTrim(char* Str)
{ {
int i = 0, j; int i = 0, j;
while((Str[i]==' ')||(Str[i]=='\t')) while ((Str[i] == ' ') || (Str[i] == '\t'))
{ {
i++; i++;
} }
if(i>0) if (i>0)
{ {
for(j=0; j < strlen(Str); j++) for (j = 0; j < strlen(Str); j++)
{ {
Str[j]=Str[j+i]; Str[j] = Str[j + i];
} }
Str[j]='\0'; Str[j] = '\0';
} }
i = strlen(Str)-1; i = strlen(Str) - 1;
while((Str[i] == ' ')||(Str[i]=='\t')) while ((Str[i] == ' ') || (Str[i] == '\t'))
{ {
i--; i--;
} }
if(i < (strlen(Str)-1)) if (i < (strlen(Str) - 1))
{ {
Str[i+1] = '\0'; Str[i + 1] = '\0';
} }
return 0; return 0;
} }
@ -123,20 +123,20 @@ DWORD INI_FILE::GetFileStringFromNum(DWORD StringNumber, char *RetString, DWORD
DWORD EndStringPos = 0; DWORD EndStringPos = 0;
DWORD StringSize = 0; DWORD StringSize = 0;
if(StringNumber > FileStringsCount) return -1; if (StringNumber > FileStringsCount) return -1;
for(DWORD i = FileStringsMap[StringNumber]; i < FileSize; i++) for (DWORD i = FileStringsMap[StringNumber]; i < FileSize; i++)
{ {
if((FileRaw[i] == '\r' && FileRaw[i+1] == '\n') || i == (FileSize-1)) if ((FileRaw[i] == '\r' && FileRaw[i + 1] == '\n') || i == (FileSize - 1))
{ {
EndStringPos = i; EndStringPos = i;
break; break;
} }
} }
StringSize = EndStringPos-FileStringsMap[StringNumber]; StringSize = EndStringPos - FileStringsMap[StringNumber];
if(Size < StringSize) return -1; if (Size < StringSize) return -1;
memset(RetString, 0x00, Size); memset(RetString, 0x00, Size);
memcpy(RetString, &(FileRaw[FileStringsMap[StringNumber]]), StringSize); memcpy(RetString, &(FileRaw[FileStringsMap[StringNumber]]), StringSize);
@ -147,10 +147,10 @@ bool INI_FILE::IsVariable(char *Str, DWORD StrSize)
{ {
bool Quotes = false; bool Quotes = false;
for(DWORD i = 0; i < StrSize; i++) for (DWORD i = 0; i < StrSize; i++)
{ {
if(Str[i] == '"' || Str[i] == '\'') Quotes = !Quotes; if (Str[i] == '"' || Str[i] == '\'') Quotes = !Quotes;
if(Str[i] == '=' && !Quotes) return true; if (Str[i] == '=' && !Quotes) return true;
} }
return false; return false;
} }
@ -159,13 +159,13 @@ bool INI_FILE::FillVariable(INI_SECTION_VARIABLE *Variable, char *Str, DWORD Str
{ {
bool Quotes = false; bool Quotes = false;
for(DWORD i = 0; i < StrSize; i++) for (DWORD i = 0; i < StrSize; i++)
{ {
if(Str[i] == '"' || Str[i] == '\'') Quotes = !Quotes; if (Str[i] == '"' || Str[i] == '\'') Quotes = !Quotes;
if(Str[i] == '=' && !Quotes) if (Str[i] == '=' && !Quotes)
{ {
memcpy(Variable->VariableName, Str, i); memcpy(Variable->VariableName, Str, i);
memcpy(Variable->VariableValue, &(Str[i+1]), StrSize-(i-1)); memcpy(Variable->VariableValue, &(Str[i + 1]), StrSize - (i - 1));
StrTrim(Variable->VariableName); StrTrim(Variable->VariableName);
StrTrim(Variable->VariableValue); StrTrim(Variable->VariableValue);
break; break;
@ -187,13 +187,13 @@ bool INI_FILE::Parse()
DWORD CurrentVariableNum = -1; DWORD CurrentVariableNum = -1;
// Calculate sections count // Calculate sections count
for(DWORD CurrentStringNum = 0; CurrentStringNum < FileStringsCount; CurrentStringNum++) for (DWORD CurrentStringNum = 0; CurrentStringNum < FileStringsCount; CurrentStringNum++)
{ {
CurrentStringSize = GetFileStringFromNum(CurrentStringNum, CurrentString, 512); CurrentStringSize = GetFileStringFromNum(CurrentStringNum, CurrentString, 512);
if(CurrentString[0] == ';') continue; // It's a comment if (CurrentString[0] == ';') continue; // It's a comment
if(CurrentString[0] == '[' && CurrentString[CurrentStringSize-1] == ']') // It's section declaration if (CurrentString[0] == '[' && CurrentString[CurrentStringSize - 1] == ']') // It's section declaration
{ {
SectionsCount++; SectionsCount++;
continue; continue;
@ -203,19 +203,19 @@ bool INI_FILE::Parse()
DWORD *SectionVariableCount = new DWORD[SectionsCount]; DWORD *SectionVariableCount = new DWORD[SectionsCount];
memset(SectionVariableCount, 0x00, sizeof(DWORD)*SectionsCount); memset(SectionVariableCount, 0x00, sizeof(DWORD)*SectionsCount);
for(DWORD CurrentStringNum = 0; CurrentStringNum < FileStringsCount; CurrentStringNum++) for (DWORD CurrentStringNum = 0; CurrentStringNum < FileStringsCount; CurrentStringNum++)
{ {
CurrentStringSize = GetFileStringFromNum(CurrentStringNum, CurrentString, 512); CurrentStringSize = GetFileStringFromNum(CurrentStringNum, CurrentString, 512);
if(CurrentString[0] == ';') continue; // It's a comment if (CurrentString[0] == ';') continue; // It's a comment
if(CurrentString[0] == '[' && CurrentString[CurrentStringSize-1] == ']') // It's section declaration if (CurrentString[0] == '[' && CurrentString[CurrentStringSize - 1] == ']') // It's section declaration
{ {
CurrentSectionNum++; CurrentSectionNum++;
continue; continue;
} }
if(IsVariable(CurrentString, CurrentStringSize)) if (IsVariable(CurrentString, CurrentStringSize))
{ {
VariablesCount++; VariablesCount++;
SectionVariableCount[CurrentSectionNum]++; SectionVariableCount[CurrentSectionNum]++;
@ -227,7 +227,7 @@ bool INI_FILE::Parse()
IniData.Section = new INI_SECTION[SectionsCount]; IniData.Section = new INI_SECTION[SectionsCount];
memset(IniData.Section, 0x00, sizeof(PINI_SECTION)*SectionsCount); memset(IniData.Section, 0x00, sizeof(PINI_SECTION)*SectionsCount);
for(DWORD i = 0; i < SectionsCount; i++) for (DWORD i = 0; i < SectionsCount; i++)
{ {
IniData.Section[i].VariablesCount = SectionVariableCount[i]; IniData.Section[i].VariablesCount = SectionVariableCount[i];
IniData.Section[i].Variables = new INI_SECTION_VARIABLE[SectionVariableCount[i]]; IniData.Section[i].Variables = new INI_SECTION_VARIABLE[SectionVariableCount[i]];
@ -239,24 +239,24 @@ bool INI_FILE::Parse()
CurrentSectionNum = -1; CurrentSectionNum = -1;
CurrentVariableNum = -1; CurrentVariableNum = -1;
for(DWORD CurrentStringNum = 0; CurrentStringNum < FileStringsCount; CurrentStringNum++) for (DWORD CurrentStringNum = 0; CurrentStringNum < FileStringsCount; CurrentStringNum++)
{ {
CurrentStringSize = GetFileStringFromNum(CurrentStringNum, CurrentString, 512); CurrentStringSize = GetFileStringFromNum(CurrentStringNum, CurrentString, 512);
if(CurrentString[0] == ';') // It's a comment if (CurrentString[0] == ';') // It's a comment
{ {
continue; continue;
} }
if(CurrentString[0] == '[' && CurrentString[CurrentStringSize-1] == ']') if (CurrentString[0] == '[' && CurrentString[CurrentStringSize - 1] == ']')
{ {
CurrentSectionNum++; CurrentSectionNum++;
CurrentVariableNum = 0; CurrentVariableNum = 0;
memcpy(IniData.Section[CurrentSectionNum].SectionName, &(CurrentString[1]), (CurrentStringSize-2)); memcpy(IniData.Section[CurrentSectionNum].SectionName, &(CurrentString[1]), (CurrentStringSize - 2));
continue; continue;
} }
if(IsVariable(CurrentString, CurrentStringSize)) if (IsVariable(CurrentString, CurrentStringSize))
{ {
FillVariable(&(IniData.Section[CurrentSectionNum].Variables[CurrentVariableNum]), CurrentString, CurrentStringSize); FillVariable(&(IniData.Section[CurrentSectionNum].Variables[CurrentVariableNum]), CurrentString, CurrentStringSize);
CurrentVariableNum++; CurrentVariableNum++;
@ -269,9 +269,9 @@ bool INI_FILE::Parse()
PINI_SECTION INI_FILE::GetSection(char *SectionName) PINI_SECTION INI_FILE::GetSection(char *SectionName)
{ {
for(DWORD i = 0; i < IniData.SectionCount; i++) for (DWORD i = 0; i < IniData.SectionCount; i++)
{ {
if(memcmp(IniData.Section[i].SectionName, SectionName, strlen(SectionName)) == 0) if (memcmp(IniData.Section[i].SectionName, SectionName, strlen(SectionName)) == 0)
{ {
return &IniData.Section[i]; return &IniData.Section[i];
} }
@ -281,13 +281,13 @@ PINI_SECTION INI_FILE::GetSection(char *SectionName)
bool INI_FILE::SectionExists(char *SectionName) bool INI_FILE::SectionExists(char *SectionName)
{ {
if(GetSection(SectionName) == NULL) return false; if (GetSection(SectionName) == NULL) return false;
return true; return true;
} }
bool INI_FILE::VariableExists(char *SectionName, char *VariableName) bool INI_FILE::VariableExists(char *SectionName, char *VariableName)
{ {
INI_SECTION_VARIABLE Variable = {0}; INI_SECTION_VARIABLE Variable = { 0 };
return GetVariableInSectionPrivate(SectionName, VariableName, &Variable); return GetVariableInSectionPrivate(SectionName, VariableName, &Variable);
} }
@ -298,22 +298,22 @@ bool INI_FILE::GetVariableInSectionPrivate(char *SectionName, char *VariableName
// Find section // Find section
Section = GetSection(SectionName); Section = GetSection(SectionName);
if(Section == NULL) if (Section == NULL)
{ {
SetLastError(318); // This region is not found SetLastError(318); // This region is not found
return false; return false;
} }
// Find variable // Find variable
for(DWORD i = 0; i < Section->VariablesCount; i++) for (DWORD i = 0; i < Section->VariablesCount; i++)
{ {
if(memcmp(Section->Variables[i].VariableName, VariableName, strlen(VariableName)) == 0) if (memcmp(Section->Variables[i].VariableName, VariableName, strlen(VariableName)) == 0)
{ {
Variable = &(Section->Variables[i]); Variable = &(Section->Variables[i]);
break; break;
} }
} }
if(Variable == NULL) if (Variable == NULL)
{ {
SetLastError(1898); // Member of the group is not found SetLastError(1898); // Member of the group is not found
return false; return false;
@ -331,7 +331,7 @@ bool INI_FILE::GetVariableInSection(char *SectionName, char *VariableName, INI_V
INI_SECTION_VARIABLE Variable = {}; INI_SECTION_VARIABLE Variable = {};
Status = GetVariableInSectionPrivate(SectionName, VariableName, &Variable); Status = GetVariableInSectionPrivate(SectionName, VariableName, &Variable);
if(!Status) return Status; if (!Status) return Status;
memset(RetVariable, 0x00, sizeof(*RetVariable)); memset(RetVariable, 0x00, sizeof(*RetVariable));
memcpy(RetVariable->Name, Variable.VariableName, strlen(Variable.VariableName)); memcpy(RetVariable->Name, Variable.VariableName, strlen(Variable.VariableName));
@ -346,7 +346,7 @@ bool INI_FILE::GetVariableInSection(char *SectionName, char *VariableName, INI_V
INI_SECTION_VARIABLE Variable = {}; INI_SECTION_VARIABLE Variable = {};
Status = GetVariableInSectionPrivate(SectionName, VariableName, &Variable); Status = GetVariableInSectionPrivate(SectionName, VariableName, &Variable);
if(!Status) return Status; if (!Status) return Status;
memset(RetVariable, 0x00, sizeof(*RetVariable)); memset(RetVariable, 0x00, sizeof(*RetVariable));
memcpy(RetVariable->Name, Variable.VariableName, strlen(Variable.VariableName)); memcpy(RetVariable->Name, Variable.VariableName, strlen(Variable.VariableName));
@ -367,61 +367,62 @@ bool INI_FILE::GetVariableInSection(char *SectionName, char *VariableName, INI_V
INI_SECTION_VARIABLE Variable = {}; INI_SECTION_VARIABLE Variable = {};
Status = GetVariableInSectionPrivate(SectionName, VariableName, &Variable); Status = GetVariableInSectionPrivate(SectionName, VariableName, &Variable);
if(!Status) return Status; if (!Status) return Status;
DWORD ValueLen = strlen(Variable.VariableValue); DWORD ValueLen = strlen(Variable.VariableValue);
if((ValueLen % 2) != 0) return false; if ((ValueLen % 2) != 0) return false;
// for security reasons not more than 16 bytes // for security reasons not more than 16 bytes
if (ValueLen > 32) ValueLen = 32; // 32 hex digits if (ValueLen > 32) ValueLen = 32; // 32 hex digits
memset(RetVariable, 0x00, sizeof(*RetVariable)); memset(RetVariable, 0x00, sizeof(*RetVariable));
memcpy(RetVariable->Name, Variable.VariableName, ValueLen); memcpy(RetVariable->Name, Variable.VariableName, ValueLen);
for(DWORD i = 0; i <= ValueLen; i++) for (DWORD i = 0; i <= ValueLen; i++)
{ {
if((i % 2) != 0) continue; if ((i % 2) != 0) continue;
switch(Variable.VariableValue[i]) switch (Variable.VariableValue[i])
{ {
case '0': break; case '0': break;
case '1': RetVariable->Value[(i/2)] += (1 << 4); break; case '1': RetVariable->Value[(i / 2)] += (1 << 4); break;
case '2': RetVariable->Value[(i/2)] += (2 << 4); break; case '2': RetVariable->Value[(i / 2)] += (2 << 4); break;
case '3': RetVariable->Value[(i/2)] += (3 << 4); break; case '3': RetVariable->Value[(i / 2)] += (3 << 4); break;
case '4': RetVariable->Value[(i/2)] += (4 << 4); break; case '4': RetVariable->Value[(i / 2)] += (4 << 4); break;
case '5': RetVariable->Value[(i/2)] += (5 << 4); break; case '5': RetVariable->Value[(i / 2)] += (5 << 4); break;
case '6': RetVariable->Value[(i/2)] += (6 << 4); break; case '6': RetVariable->Value[(i / 2)] += (6 << 4); break;
case '7': RetVariable->Value[(i/2)] += (7 << 4); break; case '7': RetVariable->Value[(i / 2)] += (7 << 4); break;
case '8': RetVariable->Value[(i/2)] += (8 << 4); break; case '8': RetVariable->Value[(i / 2)] += (8 << 4); break;
case '9': RetVariable->Value[(i/2)] += (9 << 4); break; case '9': RetVariable->Value[(i / 2)] += (9 << 4); break;
case 'A': RetVariable->Value[(i/2)] += (10 << 4); break; case 'A': RetVariable->Value[(i / 2)] += (10 << 4); break;
case 'B': RetVariable->Value[(i/2)] += (11 << 4); break; case 'B': RetVariable->Value[(i / 2)] += (11 << 4); break;
case 'C': RetVariable->Value[(i/2)] += (12 << 4); break; case 'C': RetVariable->Value[(i / 2)] += (12 << 4); break;
case 'D': RetVariable->Value[(i/2)] += (13 << 4); break; case 'D': RetVariable->Value[(i / 2)] += (13 << 4); break;
case 'E': RetVariable->Value[(i/2)] += (14 << 4); break; case 'E': RetVariable->Value[(i / 2)] += (14 << 4); break;
case 'F': RetVariable->Value[(i/2)] += (15 << 4); break; case 'F': RetVariable->Value[(i / 2)] += (15 << 4); break;
} }
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;
case '4': RetVariable->Value[(i/2)] += 4; break; case '4': RetVariable->Value[(i / 2)] += 4; break;
case '5': RetVariable->Value[(i/2)] += 5; break; case '5': RetVariable->Value[(i / 2)] += 5; break;
case '6': RetVariable->Value[(i/2)] += 6; break; case '6': RetVariable->Value[(i / 2)] += 6; break;
case '7': RetVariable->Value[(i/2)] += 7; break; case '7': RetVariable->Value[(i / 2)] += 7; break;
case '8': RetVariable->Value[(i/2)] += 8; break; case '8': RetVariable->Value[(i / 2)] += 8; break;
case '9': RetVariable->Value[(i/2)] += 9; break; case '9': RetVariable->Value[(i / 2)] += 9; break;
case 'A': RetVariable->Value[(i/2)] += 10; break; case 'A': RetVariable->Value[(i / 2)] += 10; break;
case 'B': RetVariable->Value[(i/2)] += 11; break; case 'B': RetVariable->Value[(i / 2)] += 11; break;
case 'C': RetVariable->Value[(i/2)] += 12; break; case 'C': RetVariable->Value[(i / 2)] += 12; break;
case 'D': RetVariable->Value[(i/2)] += 13; break; case 'D': RetVariable->Value[(i / 2)] += 13; break;
case 'E': RetVariable->Value[(i/2)] += 14; break; case 'E': RetVariable->Value[(i / 2)] += 14; break;
case 'F': RetVariable->Value[(i/2)] += 15; break; case 'F': RetVariable->Value[(i / 2)] += 15; break;
} }
} }
RetVariable->ArraySize = ValueLen/2; RetVariable->ArraySize = ValueLen / 2;
return true; return true;
} }
@ -431,7 +432,7 @@ bool INI_FILE::GetVariableInSection(char *SectionName, char *VariableName, bool
INI_SECTION_VARIABLE Variable = {}; INI_SECTION_VARIABLE Variable = {};
Status = GetVariableInSectionPrivate(SectionName, VariableName, &Variable); Status = GetVariableInSectionPrivate(SectionName, VariableName, &Variable);
if(!Status) return Status; if (!Status) return Status;
*RetVariable = (bool)strtol(Variable.VariableValue, NULL, 10); *RetVariable = (bool)strtol(Variable.VariableValue, NULL, 10);
return true; return true;
@ -442,7 +443,7 @@ bool INI_FILE::GetSectionVariablesList(char *SectionName, INI_SECTION_VARLIST *V
INI_SECTION *Section = NULL; INI_SECTION *Section = NULL;
Section = GetSection(SectionName); Section = GetSection(SectionName);
if(Section == NULL) if (Section == NULL)
{ {
SetLastError(318); // This region is not found SetLastError(318); // This region is not found
return false; return false;
@ -456,7 +457,7 @@ bool INI_FILE::GetSectionVariablesList(char *SectionName, INI_SECTION_VARLIST *V
VariablesList->ValuesEntries = new INI_SECTION_VARLIST_ENTRY[VariablesList->EntriesCount]; VariablesList->ValuesEntries = new INI_SECTION_VARLIST_ENTRY[VariablesList->EntriesCount];
memset(VariablesList->ValuesEntries, 0x00, sizeof(INI_SECTION_VARLIST_ENTRY)*VariablesList->EntriesCount); memset(VariablesList->ValuesEntries, 0x00, sizeof(INI_SECTION_VARLIST_ENTRY)*VariablesList->EntriesCount);
for(DWORD i = 0; i < Section->VariablesCount; i++) for (DWORD i = 0; i < Section->VariablesCount; i++)
{ {
memcpy(VariablesList->NamesEntries[i].String, Section->Variables[i].VariableName, memcpy(VariablesList->NamesEntries[i].String, Section->Variables[i].VariableName,
strlen(Section->Variables[i].VariableName)); strlen(Section->Variables[i].VariableName));
@ -473,7 +474,7 @@ bool INI_FILE::GetSectionVariablesList(char *SectionName, INI_SECTION_VARLIST *V
bool INI_FILE::SectionExists(wchar_t *SectionName) bool INI_FILE::SectionExists(wchar_t *SectionName)
{ {
char cSectionName[MAX_STRING_LEN] = {0x00}; char cSectionName[MAX_STRING_LEN] = { 0x00 };
wcstombs(cSectionName, SectionName, MAX_STRING_LEN); wcstombs(cSectionName, SectionName, MAX_STRING_LEN);
@ -482,10 +483,10 @@ bool INI_FILE::SectionExists(wchar_t *SectionName)
bool INI_FILE::VariableExists(wchar_t *SectionName, wchar_t *VariableName) bool INI_FILE::VariableExists(wchar_t *SectionName, wchar_t *VariableName)
{ {
INI_SECTION_VARIABLE Variable = {0}; INI_SECTION_VARIABLE Variable = { 0 };
char cSectionName[MAX_STRING_LEN] = {0x00}; char cSectionName[MAX_STRING_LEN] = { 0x00 };
char cVariableName[MAX_STRING_LEN] = {0x00}; char cVariableName[MAX_STRING_LEN] = { 0x00 };
wcstombs(cSectionName, SectionName, MAX_STRING_LEN); wcstombs(cSectionName, SectionName, MAX_STRING_LEN);
wcstombs(cVariableName, VariableName, MAX_STRING_LEN); wcstombs(cVariableName, VariableName, MAX_STRING_LEN);
@ -495,8 +496,8 @@ bool INI_FILE::VariableExists(wchar_t *SectionName, wchar_t *VariableName)
bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_STRING *RetVariable) bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_STRING *RetVariable)
{ {
char cSectionName[MAX_STRING_LEN] = {0x00}; char cSectionName[MAX_STRING_LEN] = { 0x00 };
char cVariableName[MAX_STRING_LEN] = {0x00}; char cVariableName[MAX_STRING_LEN] = { 0x00 };
wcstombs(cSectionName, SectionName, MAX_STRING_LEN); wcstombs(cSectionName, SectionName, MAX_STRING_LEN);
wcstombs(cVariableName, VariableName, MAX_STRING_LEN); wcstombs(cVariableName, VariableName, MAX_STRING_LEN);
@ -506,8 +507,8 @@ bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName,
bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_DWORD *RetVariable) bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_DWORD *RetVariable)
{ {
char cSectionName[MAX_STRING_LEN] = {0x00}; char cSectionName[MAX_STRING_LEN] = { 0x00 };
char cVariableName[MAX_STRING_LEN] = {0x00}; char cVariableName[MAX_STRING_LEN] = { 0x00 };
wcstombs(cSectionName, SectionName, MAX_STRING_LEN); wcstombs(cSectionName, SectionName, MAX_STRING_LEN);
wcstombs(cVariableName, VariableName, MAX_STRING_LEN); wcstombs(cVariableName, VariableName, MAX_STRING_LEN);
@ -517,8 +518,8 @@ bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName,
bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_BYTEARRAY *RetVariable) bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_BYTEARRAY *RetVariable)
{ {
char cSectionName[MAX_STRING_LEN] = {0x00}; char cSectionName[MAX_STRING_LEN] = { 0x00 };
char cVariableName[MAX_STRING_LEN] = {0x00}; char cVariableName[MAX_STRING_LEN] = { 0x00 };
wcstombs(cSectionName, SectionName, MAX_STRING_LEN); wcstombs(cSectionName, SectionName, MAX_STRING_LEN);
wcstombs(cVariableName, VariableName, MAX_STRING_LEN); wcstombs(cVariableName, VariableName, MAX_STRING_LEN);
@ -528,8 +529,8 @@ bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName,
bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, bool *RetVariable) bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, bool *RetVariable)
{ {
char cSectionName[MAX_STRING_LEN] = {0x00}; char cSectionName[MAX_STRING_LEN] = { 0x00 };
char cVariableName[MAX_STRING_LEN] = {0x00}; char cVariableName[MAX_STRING_LEN] = { 0x00 };
wcstombs(cSectionName, SectionName, MAX_STRING_LEN); wcstombs(cSectionName, SectionName, MAX_STRING_LEN);
wcstombs(cVariableName, VariableName, MAX_STRING_LEN); wcstombs(cVariableName, VariableName, MAX_STRING_LEN);
@ -539,7 +540,7 @@ bool INI_FILE::GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName,
bool INI_FILE::GetSectionVariablesList(wchar_t *SectionName, INI_SECTION_VARLIST *VariablesList) bool INI_FILE::GetSectionVariablesList(wchar_t *SectionName, INI_SECTION_VARLIST *VariablesList)
{ {
char cSectionName[MAX_STRING_LEN] = {0x00}; char cSectionName[MAX_STRING_LEN] = { 0x00 };
wcstombs(cSectionName, SectionName, MAX_STRING_LEN); wcstombs(cSectionName, SectionName, MAX_STRING_LEN);

View File

@ -1,17 +1,17 @@
/* /*
Copyright 2014 Stas'M Corp. Copyright 2014 Stas'M Corp.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
#include "stdafx.h" #include "stdafx.h"
@ -87,6 +87,7 @@ public:
INI_FILE(wchar_t*); INI_FILE(wchar_t*);
~INI_FILE(); ~INI_FILE();
// char block
bool SectionExists(char *SectionName); bool SectionExists(char *SectionName);
bool VariableExists(char *SectionName, char *VariableName); bool VariableExists(char *SectionName, char *VariableName);
bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_STRING *Variable); bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_STRING *Variable);
@ -95,6 +96,15 @@ public:
bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_BYTEARRAY *Variable); bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_BYTEARRAY *Variable);
bool GetSectionVariablesList(char *SectionName, INI_SECTION_VARLIST *VariablesList); bool GetSectionVariablesList(char *SectionName, INI_SECTION_VARLIST *VariablesList);
// wchar_t tramps
bool SectionExists(wchar_t *SectionName);
bool VariableExists(wchar_t *SectionName, wchar_t *VariableName);
bool GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_STRING *Variable);
bool GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_DWORD *Variable);
bool GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, bool *Variable);
bool GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_BYTEARRAY *Variable);
bool GetSectionVariablesList(wchar_t *SectionName, INI_SECTION_VARLIST *VariablesList);
private: private:
DWORD FileSize; // Ini file size DWORD FileSize; // Ini file size
char *FileRaw; // Ini file raw dump char *FileRaw; // Ini file raw dump

View File

@ -56,7 +56,7 @@ FARJMP Old_SLGetWindowsInformationDWORD, Stub_SLGetWindowsInformationDWORD;
SLGETWINDOWSINFORMATIONDWORD _SLGetWindowsInformationDWORD; SLGETWINDOWSINFORMATIONDWORD _SLGetWindowsInformationDWORD;
INI_FILE *IniFile; INI_FILE *IniFile;
wchar_t LogFile[256] = {0x00}; wchar_t LogFile[256] = L"\\rdpwrap.txt";
HMODULE hTermSrv; HMODULE hTermSrv;
HMODULE hSLC; HMODULE hSLC;
PLATFORM_DWORD TermSrvBase; PLATFORM_DWORD TermSrvBase;
@ -519,7 +519,7 @@ void Hook()
return; return;
} }
INI_VAR_STRING LogFileVar; /*INI_VAR_STRING LogFileVar;
if(!(IniFile->GetVariableInSection("Main", "LogFile", &LogFileVar))) if(!(IniFile->GetVariableInSection("Main", "LogFile", &LogFileVar)))
{ {
@ -533,7 +533,7 @@ void Hook()
} }
} }
} }
else memcpy((void*)LogFile, LogFileVar.Value, strlen(LogFileVar.Value)); else memcpy((void*)LogFile, LogFileVar.Value, strlen(LogFileVar.Value));*/
char *Log; char *Log;
SIZE_T bw; SIZE_T bw;
@ -680,6 +680,7 @@ void Hook()
INI_VAR_STRING PatchName; INI_VAR_STRING PatchName;
INI_VAR_BYTEARRAY Patch; INI_VAR_BYTEARRAY Patch;
Sect = new char[1024]; Sect = new char[1024];
memset(Sect, 0x00, 1024);
wsprintfA(Sect, "%d.%d.%d.%d", FV.wVersion.Major, FV.wVersion.Minor, FV.Release, FV.Build); wsprintfA(Sect, "%d.%d.%d.%d", FV.wVersion.Major, FV.wVersion.Minor, FV.Release, FV.Build);
if (IniFile->SectionExists(Sect)) if (IniFile->SectionExists(Sect))

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
@ -27,26 +27,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
@ -160,6 +160,7 @@
<Text Include="ReadMe.txt" /> <Text Include="ReadMe.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="IniFile.h" />
<ClInclude Include="stdafx.h" /> <ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
</ItemGroup> </ItemGroup>
@ -178,6 +179,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
</PrecompiledHeader> </PrecompiledHeader>
</ClCompile> </ClCompile>
<ClCompile Include="IniFile.cpp" />
<ClCompile Include="RDPWrap.cpp" /> <ClCompile Include="RDPWrap.cpp" />
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

View File

@ -24,6 +24,9 @@
<ClInclude Include="targetver.h"> <ClInclude Include="targetver.h">
<Filter>Заголовочные файлы</Filter> <Filter>Заголовочные файлы</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="IniFile.h">
<Filter>Заголовочные файлы</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">
@ -35,6 +38,9 @@
<ClCompile Include="dllmain.cpp"> <ClCompile Include="dllmain.cpp">
<Filter>Файлы исходного кода</Filter> <Filter>Файлы исходного кода</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="IniFile.cpp">
<Filter>Файлы исходного кода</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Export.def"> <None Include="Export.def">