From 04b5259737c052856b198600f5abb489cc165d69 Mon Sep 17 00:00:00 2001 From: "PC1\\PTyTb" Date: Fri, 8 Aug 2025 19:11:31 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=83=D1=82=D0=B5?= =?UTF-8?q?=D1=87=D0=B5=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uGeneral.pas | 161 ++++++++++++++++++++++++--------------------------- 1 file changed, 76 insertions(+), 85 deletions(-) diff --git a/uGeneral.pas b/uGeneral.pas index 13257f3..f5eff86 100644 --- a/uGeneral.pas +++ b/uGeneral.pas @@ -191,52 +191,46 @@ end; procedure TTTW_Bot.ReadDB; - function XorDecryptToStrings(const InputFile, Key: string): TStrings; - var - InStream: TFileStream; - MemStream: TMemoryStream; - KeyBytes: TBytes; - KeyLen, KeyIndex: integer; - B: Byte; - begin - // Преобразуем ключ в байты с использованием ANSI кодировки - KeyBytes := TEncoding.ANSI.GetBytes(Key); - KeyLen := Length(KeyBytes); - if KeyLen = 0 then - raise Exception.Create('Ключ не может быть пустым'); + function XorDecryptToStrings(const InputFile, Key: string): TStrings; +var + InStream: TFileStream; + MemStream: TMemoryStream; + KeyBytes: TBytes; + KeyLen, KeyIndex: integer; + B: Byte; +begin + KeyBytes := TEncoding.ANSI.GetBytes(Key); + KeyLen := Length(KeyBytes); + if KeyLen = 0 then + raise Exception.Create('Ключ не может быть пустым'); - InStream := TFileStream.Create(InputFile, fmOpenRead); + InStream := TFileStream.Create(InputFile, fmOpenRead); + try + MemStream := TMemoryStream.Create; try - MemStream := TMemoryStream.Create; + KeyIndex := 0; + while InStream.Position < InStream.Size do + begin + InStream.ReadBuffer(B, 1); + B := B xor KeyBytes[KeyIndex]; + MemStream.WriteBuffer(B, 1); + KeyIndex := (KeyIndex + 1) mod KeyLen; + end; + MemStream.Position := 0; + Result := TStringList.Create; try - KeyIndex := 0; - // Расшифровываем данные и записываем в поток в памяти - while InStream.Position < InStream.Size do - begin - InStream.ReadBuffer(B, 1); - B := B xor KeyBytes[KeyIndex]; - MemStream.WriteBuffer(B, 1); - KeyIndex := (KeyIndex + 1) mod KeyLen; - end; - // Преобразуем данные из потока в TStrings - MemStream.Position := 0; // Сбрасываем позицию для чтения - Result := TStringList.Create; - try - // Используем ANSI кодировку для преобразования байтов в строку - Result.LoadFromStream(MemStream, TEncoding.ANSI); - except - // В случае ошибки освобождаем ресурсы и пробрасываем исключение - Result.Free; - raise; - end; - finally - MemStream.Free; + Result.LoadFromStream(MemStream, TEncoding.ANSI); + except + Result.Free; // Освобождаем при ошибке загрузки + raise; end; finally - InStream.Free; + MemStream.Free; end; + finally + InStream.Free; end; - +end; // Загрузка компонентов настроек (TEdit, TCheckBox) procedure LoadSettingsComponents; var @@ -274,58 +268,55 @@ procedure TTTW_Bot.ReadDB; end; // Загрузка зашифрованного конфига - procedure LoadEncryptedConfig; - var - sl: TStringList; - I: integer; - begin - if not FileExists(myConst.cfg1) then - Exit; +procedure LoadEncryptedConfig; +var + tempList: TStrings; // Временный список для результата + I: integer; +begin + if not FileExists(myConst.cfg1) then + Exit; - sl := TStringList.Create; - try - sl.Assign(XorDecryptToStrings(myConst.cfg1, 'fgvasrgEFAXFAFAS')); - for I := 0 to sl.Count - 1 do + tempList := nil; // Инициализация + try + tempList := XorDecryptToStrings(myConst.cfg1, 'fgvasrgEFAXFAFAS'); + + for I := 0 to tempList.Count - 1 do + begin + var eqPos := Pos('=', tempList[I]); + if eqPos > 0 then begin - var - eqPos := Pos('=', sl[I]); - if eqPos > 0 then - begin - var - Key := Trim(Copy(sl[I], 1, eqPos - 1)); - var - Value := Trim(Copy(sl[I], eqPos + 1, MaxInt)); + var Key := Trim(Copy(tempList[I], 1, eqPos - 1)); + var Value := Trim(Copy(tempList[I], eqPos + 1, MaxInt)); - if Key = 'k1' then - appconst.TTV_ClientID := Value - else if Key = 'k2' then - appconst.AI_GigaChat_AC := Value - else if Key = 'k3' then - appconst.AI_GigaChat_ClientID := Value - else if Key = 'k4' then - appconst.AI_ChatGPT_Token := Value - else if Key = 'k5' then - appconst.AI_DeepSeec_Token := Value - else if Key = 'k6' then - appconst.DA_ClientID := Value - else if Key = 'k7' then - appconst.DA_Sicret := Value - else if Key = 'k8' then - appconst.DA_URL := Value; - end; + if Key = 'k1' then + appconst.TTV_ClientID := Value + else if Key = 'k2' then + appconst.AI_GigaChat_AC := Value + else if Key = 'k3' then + appconst.AI_GigaChat_ClientID := Value + else if Key = 'k4' then + appconst.AI_ChatGPT_Token := Value + else if Key = 'k5' then + appconst.AI_DeepSeec_Token := Value + else if Key = 'k6' then + appconst.DA_ClientID := Value + else if Key = 'k7' then + appconst.DA_Sicret := Value + else if Key = 'k8' then + appconst.DA_URL := Value; end; - - frSettings1.btnGetClientID.Visible := (appconst.TTV_ClientID <> ''); - frAI1.btnGetAIDef.Visible := ((appconst.AI_GigaChat_AC <> '') and - (appconst.AI_GigaChat_ClientID <> '')) or - (appconst.AI_ChatGPT_Token <> '') or (appconst.AI_DeepSeec_Token <> ''); - frSettings1.btnGetDADef.Visible := (appconst.DA_ClientID <> '') and - (appconst.DA_Sicret <> '') and (appconst.DA_URL <> ''); - finally - sl.Free; end; - end; + frSettings1.btnGetClientID.Visible := (appconst.TTV_ClientID <> ''); + frAI1.btnGetAIDef.Visible := ((appconst.AI_GigaChat_AC <> '') and + (appconst.AI_GigaChat_ClientID <> '')) or + (appconst.AI_ChatGPT_Token <> '') or (appconst.AI_DeepSeec_Token <> ''); + frSettings1.btnGetDADef.Visible := (appconst.DA_ClientID <> '') and + (appconst.DA_Sicret <> '') and (appconst.DA_URL <> ''); + finally + tempList.Free; // Важно: освобождаем временный список! + end; +end; // Загрузка настроек уведомлений procedure LoadNotifySettings; var