Skip to content

Commit 94ec6bb

Browse files
ウイルス検知対策
1 parent 75863e3 commit 94ec6bb

File tree

4 files changed

+18
-72
lines changed

4 files changed

+18
-72
lines changed

BrowserCookieImplementations/Buildin.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.IO;
55
using System.Linq;
66
using System.Net;
7-
using System.Security.Cryptography;
87
using System.Text;
98
using System.Text.Json;
109

@@ -70,20 +69,19 @@ public List<Cookie> GetCookieCollection(string domain)
7069

7170
private List<Cookie> LoadAllCookies(string file)
7271
{
73-
var cookieList = new List<Cookie>();
72+
var List = new List<Cookie>();
7473

7574
var path1 = System.IO.Path.Combine(Path, file);
7675

7776
if (!File.Exists(path1))
7877
{
79-
return cookieList;
78+
return List;
8079
}
8180

8281
try
8382
{
84-
// 暗号化されたファイルを読み込み
85-
var encrypted = File.ReadAllBytes(path1);
86-
var json = Encoding.UTF8.GetString(encrypted);
83+
// 暗号化なしでテキストとして読み込む
84+
var json = File.ReadAllText(path1, Encoding.UTF8);
8785

8886
// JSON を CookieDto のリストにデシリアライズ
8987
var cookieDtos = JsonSerializer.Deserialize<List<CookieDto>>(json);
@@ -106,7 +104,7 @@ private List<Cookie> LoadAllCookies(string file)
106104
cookie.HttpOnly = dto.IsHttpOnly;
107105
cookie.Secure = dto.IsSecure;
108106

109-
cookieList.Add(cookie);
107+
List.Add(cookie);
110108
}
111109
catch (Exception)
112110
{
@@ -120,7 +118,7 @@ private List<Cookie> LoadAllCookies(string file)
120118
// 復号化エラーまたはJSONパースエラーの場合は空のリストを返す
121119
}
122120

123-
return cookieList;
121+
return List;
124122
}
125123

126124
private bool IsHostMatch(string cookieDomain, string requestDomain)
@@ -163,7 +161,7 @@ private string GetCookieFilePath(string siteName)
163161
{
164162
var exeDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
165163
?? AppDomain.CurrentDomain.BaseDirectory;
166-
var folder = System.IO.Path.Combine(exeDir, "Cookies");
164+
var folder = System.IO.Path.Combine(exeDir, "LocalCache");
167165
Directory.CreateDirectory(folder);
168166
return folder;
169167
}

MultiCommentViewer/CookieStorage.cs renamed to MultiCommentViewer/LocalCache.cs

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@
77
namespace MultiCommentViewer
88
{
99
using Microsoft.Web.WebView2.Core;
10-
using Newtonsoft.Json;
1110
// 必要な using
1211
using System;
1312
using System.Collections.Generic;
1413
using System.IO;
15-
using System.Net;
16-
using System.Security.Cryptography;
1714
using System.Text;
18-
using System.Text.Json;
1915
using System.Threading.Tasks;
20-
using System.Security;
2116

2217
// Cookie DTO(保存フォーマット)
2318
public class CookieDto
@@ -32,23 +27,23 @@ public class CookieDto
3227
}
3328

3429
// ユーティリティ/保存ロジック
35-
public static class CookieStorage
30+
public static class LocalCache
3631
{
3732
// exe フォルダの Cookies サブフォルダを返す
38-
public static string GetCookieFolder()
33+
public static string GetCacheFolders()
3934
{
4035
var exeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
4136
?? AppDomain.CurrentDomain.BaseDirectory;
42-
var folder = Path.Combine(exeDir, "Cookies");
37+
var folder = Path.Combine(exeDir, "LocalCache");
4338
Directory.CreateDirectory(folder);
4439
return folder;
4540
}
4641

4742
// 保存先パス(サイト名で分ける)
48-
public static string GetCookieFilePath(string siteName)
43+
public static string GetCachePath(string siteName)
4944
{
5045
var safeName = string.IsNullOrWhiteSpace(siteName) ? "default" : MakeFileSystemSafe(siteName);
51-
return Path.Combine(GetCookieFolder(), safeName + ".bin");
46+
return Path.Combine(GetCacheFolders(), safeName + ".bin");
5247
}
5348

5449
// ファイル名に使える安全文字列に変換(簡易)
@@ -60,7 +55,7 @@ private static string MakeFileSystemSafe(string name)
6055
}
6156

6257
// CoreWebView2 の Cookie リストを DTO に変換して暗号化してファイルに保存
63-
public static async Task SaveCookiesEncryptedAsync(IEnumerable<CoreWebView2Cookie> cookies, string siteName)
58+
public static async Task WriteAsync(IEnumerable<CoreWebView2Cookie> cookies, string siteName)
6459
{
6560
var list = new List<CookieDto>();
6661
foreach (var c in cookies)
@@ -97,50 +92,8 @@ public static async Task SaveCookiesEncryptedAsync(IEnumerable<CoreWebView2Cooki
9792
}
9893

9994
var json = System.Text.Json.JsonSerializer.Serialize(list);
100-
var bytes = Encoding.UTF8.GetBytes(json);
101-
102-
var path = GetCookieFilePath(siteName);
103-
File.WriteAllBytes(path, bytes);
95+
var path = GetCachePath(siteName);
96+
File.WriteAllText(path, json, Encoding.UTF8);
10497
}
105-
106-
// // 暗号化ファイルを復号して CookieContainer を返す
107-
// public static CookieContainer LoadCookiesFromEncryptedFile(string siteName)
108-
// {
109-
// var path = GetCookieFilePath(siteName);
110-
// if (!File.Exists(path)) return new CookieContainer();
111-
112-
// var encrypted = File.ReadAllBytes(path);
113-
114-
// // 復号
115-
// var bytes = ProtectedData.Unprotect(encrypted, optionalEntropy: null, scope: DataProtectionScope.LocalMachine);
116-
// var json = Encoding.UTF8.GetString(bytes);
117-
118-
// var list = System.Text.Json.JsonSerializer.Deserialize<List<CookieDto>>(json);
119-
// var container = new CookieContainer();
120-
121-
// if (list != null)
122-
// {
123-
// foreach (var dto in list)
124-
// {
125-
// try
126-
// {
127-
// var cookie = new Cookie(dto.Name, dto.Value, dto.Path ?? "/", dto.Domain ?? "");
128-
// if (dto.Expires.HasValue) cookie.Expires = dto.Expires.Value;
129-
// cookie.HttpOnly = dto.IsHttpOnly;
130-
// cookie.Secure = dto.IsSecure;
131-
132-
// // CookieContainer.Add のドメイン取り扱いに注意:
133-
// // domain は先頭にドットが必要な場合があるためそのまま渡す
134-
// container.Add(cookie);
135-
// }
136-
// catch
137-
// {
138-
// // 無効な cookie があれば無視して続行
139-
// }
140-
// }
141-
// }
142-
143-
// return container;
144-
// }
14598
}
146-
}
99+
}

MultiCommentViewer/MultiCommentViewer.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
<PackageReference Include="System.ComponentModel.Composition" Version="5.0.0" />
5858
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.114.3" />
5959
<PackageReference Include="System.Text.Json" Version="9.0.8" />
60-
<PackageReference Include="WebView2.Runtime.X86" Version="139.0.3405.125" />
6160
</ItemGroup>
6261
<ItemGroup>
6362
<ProjectReference Include="..\BigoIF\BigoIF.csproj" />

MultiCommentViewer/ViewModels/LoginWindow.xaml.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,14 @@ private async void CompleteButton_Click(object sender, RoutedEventArgs e)
171171
{
172172
var cookieManager = WebView.CoreWebView2.CookieManager;
173173
var cookies = await cookieManager.GetCookiesAsync(null);
174-
175-
// 保存(暗号化)
176-
await CookieStorage.SaveCookiesEncryptedAsync(cookies, _siteName);
174+
await LocalCache.WriteAsync(cookies, _siteName);
177175

178176
// Cookie 文字列を既存のロジックと互換させたい場合は組み替え
179177
var cookieString = string.Join("; ", System.Linq.Enumerable.Select(cookies, c => $"{c.Name}={c.Value}"));
180178

181179
var result = new LoginResult
182180
{
183-
IsCompleted = true,
184-
Cookies = cookieString
181+
IsCompleted = true
185182
};
186183

187184
_completionSource.SetResult(result);
@@ -230,7 +227,6 @@ protected override void OnClosed(EventArgs e)
230227
public class LoginResult
231228
{
232229
public bool IsCompleted { get; set; }
233-
public string Cookies { get; set; }
234230
public string ErrorMessage { get; set; }
235231
}
236232
}

0 commit comments

Comments
 (0)