2014-12-03 19:58:56 +01:00
|
|
|
|
/*
|
|
|
|
|
Copyright 2014 Stas'M Corp.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
2014-12-04 21:00:44 +01:00
|
|
|
|
#define MAX_STRING_LEN 255
|
|
|
|
|
|
2014-12-04 15:48:31 +01:00
|
|
|
|
// Out values struсts
|
2014-12-03 19:58:56 +01:00
|
|
|
|
typedef struct _INI_VAR_STRING
|
|
|
|
|
{
|
2014-12-04 21:00:44 +01:00
|
|
|
|
char Name[MAX_STRING_LEN];
|
|
|
|
|
char Value[MAX_STRING_LEN];
|
|
|
|
|
} INI_VAR_STRING, *PINI_VAR_STRING;
|
2014-12-03 19:58:56 +01:00
|
|
|
|
|
|
|
|
|
typedef struct _INI_VAR_DWORD
|
|
|
|
|
{
|
2014-12-04 21:00:44 +01:00
|
|
|
|
char Name[MAX_STRING_LEN];
|
2014-12-03 19:58:56 +01:00
|
|
|
|
#ifndef _WIN64
|
2014-12-04 19:22:57 +01:00
|
|
|
|
DWORD ValueDec;
|
2014-12-03 19:58:56 +01:00
|
|
|
|
DWORD ValueHex;
|
|
|
|
|
#else
|
2014-12-04 19:22:57 +01:00
|
|
|
|
DWORD64 ValueDec;
|
2014-12-03 19:58:56 +01:00
|
|
|
|
DWORD64 ValueHex;
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-12-04 21:00:44 +01:00
|
|
|
|
} INI_VAR_DWORD, *PINI_VAR_DWORD;
|
2014-12-03 19:58:56 +01:00
|
|
|
|
|
|
|
|
|
typedef struct _INI_VAR_BYTEARRAY
|
|
|
|
|
{
|
2014-12-04 21:00:44 +01:00
|
|
|
|
char Name[MAX_STRING_LEN];
|
2014-12-03 19:58:56 +01:00
|
|
|
|
byte ArraySize;
|
2014-12-04 21:00:44 +01:00
|
|
|
|
char Value[MAX_STRING_LEN];
|
|
|
|
|
} INI_VAR_BYTEARRAY, *PINI_VAR_BYTEARRAY;
|
|
|
|
|
|
|
|
|
|
typedef struct _INI_SECTION_VARLIST_ENTRY
|
|
|
|
|
{
|
|
|
|
|
char String[MAX_STRING_LEN];
|
|
|
|
|
} INI_SECTION_VARLIST_ENTRY, *PINI_SECTION_VARLIST_ENTRY;
|
|
|
|
|
|
|
|
|
|
typedef struct _INI_SECTION_VARLIST
|
|
|
|
|
{
|
|
|
|
|
DWORD EntriesCount;
|
|
|
|
|
[length_is(EntriesCount)] INI_SECTION_VARLIST_ENTRY *NamesEntries;
|
|
|
|
|
[length_is(EntriesCount)] INI_SECTION_VARLIST_ENTRY *ValuesEntries;
|
|
|
|
|
} INI_SECTION_VARLIST, *PINI_SECTION_VARLIST;
|
2014-12-03 19:58:56 +01:00
|
|
|
|
|
|
|
|
|
// end
|
|
|
|
|
|
|
|
|
|
typedef struct _INI_SECTION_VARIABLE
|
|
|
|
|
{
|
2014-12-04 21:00:44 +01:00
|
|
|
|
char VariableName[MAX_STRING_LEN];
|
|
|
|
|
char VariableValue[MAX_STRING_LEN];
|
|
|
|
|
} INI_SECTION_VARIABLE, *PINI_SECTION_VARIABLE;
|
2014-12-03 19:58:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _INI_SECTION
|
|
|
|
|
{
|
2014-12-04 21:00:44 +01:00
|
|
|
|
char SectionName[MAX_STRING_LEN];
|
2014-12-03 19:58:56 +01:00
|
|
|
|
DWORD VariablesCount;
|
|
|
|
|
[length_is(SectionCount)] INI_SECTION_VARIABLE *Variables;
|
|
|
|
|
|
2014-12-04 21:00:44 +01:00
|
|
|
|
} INI_SECTION, *PINI_SECTION;
|
2014-12-03 19:58:56 +01:00
|
|
|
|
|
|
|
|
|
typedef struct _INI_DATA
|
|
|
|
|
{
|
|
|
|
|
DWORD SectionCount;
|
|
|
|
|
[length_is(SectionCount)] INI_SECTION *Section;
|
|
|
|
|
} INI_DATA, *PINI_DATA;
|
|
|
|
|
|
|
|
|
|
class INI_FILE
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
INI_FILE(wchar_t*);
|
|
|
|
|
~INI_FILE();
|
|
|
|
|
|
|
|
|
|
bool SectionExists(char *SectionName);
|
2014-12-04 21:00:44 +01:00
|
|
|
|
bool VariableExists(char *SectionName, char *VariableName);
|
2014-12-03 19:58:56 +01:00
|
|
|
|
bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_STRING *Variable);
|
|
|
|
|
bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_DWORD *Variable);
|
2014-12-04 21:00:44 +01:00
|
|
|
|
bool GetVariableInSection(char *SectionName, char *VariableName, bool *Variable);
|
2014-12-03 19:58:56 +01:00
|
|
|
|
bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_BYTEARRAY *Variable);
|
2014-12-04 21:00:44 +01:00
|
|
|
|
bool GetSectionVariablesList(char *SectionName, INI_SECTION_VARLIST *VariablesList);
|
2014-12-03 19:58:56 +01:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
DWORD FileSize; // Ini file size
|
|
|
|
|
char *FileRaw; // Ini file raw dump
|
2014-12-04 19:22:57 +01:00
|
|
|
|
DWORD FileStringsCount; // String-map length
|
2014-12-03 19:58:56 +01:00
|
|
|
|
DWORD *FileStringsMap; // String-map
|
|
|
|
|
INI_DATA IniData; // Parsed data
|
|
|
|
|
|
2014-12-04 15:48:31 +01:00
|
|
|
|
// Common service functions
|
|
|
|
|
int StrTrim(char* Str);
|
|
|
|
|
|
|
|
|
|
// Class service functions
|
2014-12-03 19:58:56 +01:00
|
|
|
|
bool CreateStringsMap(); // Create file string-map
|
|
|
|
|
bool Parse(); // Parse file to class structures
|
2014-12-04 19:22:57 +01:00
|
|
|
|
DWORD GetFileStringFromNum(DWORD StringNumber, char *RetString, DWORD Size); // Get string from string-map
|
2014-12-04 15:48:31 +01:00
|
|
|
|
bool IsVariable(char *Str, DWORD StrSize);
|
|
|
|
|
bool FillVariable(INI_SECTION_VARIABLE *Variable, char *Str, DWORD StrSize); // Fill INI_SECTION_VARIABLE struct (for Parse)
|
2014-12-04 21:00:44 +01:00
|
|
|
|
PINI_SECTION GetSection(char *SectionName);
|
2014-12-04 15:48:31 +01:00
|
|
|
|
bool GetVariableInSectionPrivate(char *SectionName, char *VariableName, INI_SECTION_VARIABLE *RetVariable);
|
2014-12-03 19:58:56 +01:00
|
|
|
|
};
|