Skip to content

Commit

Permalink
送信データをUTF8と見做す設定追加
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Apr 19, 2022
1 parent b74a73b commit 8f69586
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 1 deletion.
7 changes: 7 additions & 0 deletions 2chAPIProxy/AppSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class AppSetting
private bool enableUTF8Post = false;
private bool addX2chUAHeader = true;
private bool addMsToNonce = true;
private bool assumeReqBodyIsUTF8 = false;
String _HMkey = "hO2QHdapzbqbTFOaJgZTKXgT2gWqYS";
String _Appkey = "JYW2J6wh9z8p8xjGFxO3M2JppGCyjQ";
String _UserAgent0 = "";
Expand Down Expand Up @@ -365,6 +366,12 @@ public bool AddMsToNonce
set { addMsToNonce = value; change = true; }
}

public bool AssumeReqBodyIsUTF8
{
get => assumeReqBodyIsUTF8;
set { assumeReqBodyIsUTF8 = value; change = true; }
}


public String CryptData(String data, bool encrypt = true)
{
Expand Down
3 changes: 2 additions & 1 deletion 2chAPIProxy/DatProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class DatProxy
public bool EnableUTF8Post { get; set; }
public bool AddX2chUAHeader { get; set; }
public bool AddMsToNonce { get; set; }
public bool AssumeReqBodyIsUTF8 { get; set; }


private string[] PostFieldOrederArray;
Expand Down Expand Up @@ -1112,7 +1113,7 @@ private void ResPostv2(Session oSession, bool is2ch)
// 新しい書き込み仕様への対応

// 送信されてきたエンコーディング取得
var src_encoding = oSession.RequestHeaders["Content-Type"].Contains("UTF-8") switch
var src_encoding = (AssumeReqBodyIsUTF8 || oSession.RequestHeaders["Content-Type"].Contains("UTF-8")) switch
{
true => Encoding.UTF8,
false => Encoding.GetEncoding("Shift_JIS")
Expand Down
13 changes: 13 additions & 0 deletions 2chAPIProxy/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,19 @@
</Style>
</CheckBox.Style>
</CheckBox>
<CheckBox x:Name="PostUTF8_Copy" Content="UTF-8エンコーディングを仮定する" VerticalAlignment="Top" Margin="410,267,30,0" Height="20" ToolTip="書き込み時、送られてきたデータがUTF-8エンコーディングであると仮定して処理します。どうしても文字化けする場合に試してみてください" TabIndex="3" IsChecked="{Binding AssumeReqBodyIsUTF8, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<CheckBox.Style>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="FontSize" Value="12px"/>
<Setter Property="IsEnabled" Value="True"/>
<Style.Triggers>
<DataTrigger Binding="{Binding EnablePostv2}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
</Grid>
</TabItem>
</TabControl>
Expand Down
17 changes: 17 additions & 0 deletions 2chAPIProxy/ViewModels/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public ViewModelImpl()
postFieldOrder = Setting.PostFieldOrder;
addX2chUAHeader = Setting.AddX2chUAHeader;
addMsToNonce = Setting.AddMsToNonce;
assumeReqBodyIsUTF8 = Setting.AssumeReqBodyIsUTF8;

//スリープ/休止状態時の処理
Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(PowermodeChanged);
Expand Down Expand Up @@ -203,6 +204,7 @@ public void Init()
DatProxy.PostFieldOrder = PostFieldOrder;
DatProxy.AddX2chUAHeader = AddX2chUAHeader;
DatProxy.AddMsToNonce = AddMsToNonce;
DatProxy.AssumeReqBodyIsUTF8 = AssumeReqBodyIsUTF8;

//設定の適用、APIアクセスクラス
DatProxy.APIMediator.AppKey = this.Appkey;
Expand Down Expand Up @@ -897,6 +899,21 @@ public bool AddMsToNonce
}
}

private bool assumeReqBodyIsUTF8;

public bool AssumeReqBodyIsUTF8
{
get => assumeReqBodyIsUTF8;
set
{
if (assumeReqBodyIsUTF8 != value)
{
Setting.AssumeReqBodyIsUTF8 = DatProxy.AssumeReqBodyIsUTF8 = assumeReqBodyIsUTF8 = value;
NoticePropertyChanged("AssumeReqBodyIsUTF8");
}
}
}

int _PortNumber;
public int PortNumber
{
Expand Down
117 changes: 117 additions & 0 deletions doc/書き込み新仕様関連.md
Original file line number Diff line number Diff line change
Expand Up @@ -996,3 +996,120 @@ Accept-Encoding: gzip
FROM=&mail=&MESSAGE=%E3%81%A6&bbs=news4vip&key=16473****&submit=%E6%9B%B8%E3%81%8D%E8%BE%BC%E3%82%80&time=1647367943
```

# JaneStyleのヘッダ

https://pastebin.com/2nLSwx4N

```
POST /test/bbs.cgi HTTP/1.0
Connection: close
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 142
X-PostSig: ********
X-APIKey: a6kwZ1FHfwlxIKJWCq4XQQnUTqiA1P
X-PostNonce: 1649570744
X-MonaKey: ********
Host: eagle.5ch.net
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, identity
Referer: https://eagle.5ch.net/livejupiter/
User-Agent: Monazilla/1.00 JaneStyle/4.22 Windows/10.0.22000
submit=%E6%9B%B8%E3%81%8D%E8%BE%BC%E3%82%80&FROM=&mail=sage&MESSAGE=%E3%81%95%E3%82%88%E3%81%8B&bbs=livejupiter&key=1649570721&time=1649570744
```

# Beで書いたとき

```
オリジナルリクエストヘッダ
Host:egg.5ch.net
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language:ja,en-US;q=0.7,en;q=0.3
Accept-Encoding:gzip, deflate
Referer:http://egg.5ch.net/test/read.cgi/software/1649493298/
Upgrade-Insecure-Requests:1
Content-Type:application/x-www-form-urlencoded
Content-Length:200
Connection:keep-alive
Cookie:yuki=akari; DMDM=2c3b5b74891e91cf11b69ef5eadd61196b5d8f0f336abf7dfb3da437333c3aa7; MDMD=10cce5498330e0aa2d340e04398ec186493788cc3e9979387436bf32abb9a76e
リクエストヘッダ
Referer:https://egg.5ch.net/test/read.cgi/software/1649493298/
X-PostSig:c411eba4c063c1be186eb8293e0cfcdcf29965cf174df880c41902e99ba72d90
X-APIKey:8yoeAcaLXiEY1FjEuJBKgkPxirkDqn
X-PostNonce:1649611333.180
X-MonaKey:00000000-0000-0000-0000-000000000000
X-2ch-UA:2chMate/0.8.10.153
User-Agent:Monazilla/1.00 2chMate/0.8.10.153 Dalvik/2.1.0 (Linux; U; Android 12; SC-03L Build/SP1A.210812.016)
Accept-Encoding:gzip
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:egg.5ch.net
Cookie:DMDM=2c3b5b74891e91cf11b69ef5eadd61196b5d8f0f336abf7dfb3da437333c3aa7; MDMD=10cce5498330e0aa2d340e04398ec186493788cc3e9979387436bf32abb9a76e
Content-Length:238
Connection:Keep-Alive
レスポンスヘッダ
Connection:close
X-Chx-Error:0001 Confirmation phase;
X-InqID:egg/6f9d2c6ac8e2fccd;
X-PostPlace:software/1649493298
X-RONIN-Stat:NONE
X-MonaKey:07bb65337ef3bdc19e10b7650a31362b464154dd3df70a2d7172869bd15d56f8
Vary:Accept-Encoding
CF-Cache-Status:DYNAMIC
Expect-CT:max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
CF-RAY:6f9d2c6ac8e2fccd-KIX
Content-Encoding:
Content-Type:text/html; charset=Shift_JIS
Date:Sun, 10 Apr 2022 17:24:00 GMT
Server:cloudflare
オリジナルリクエストヘッダ
Host:egg.5ch.net
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language:ja,en-US;q=0.7,en;q=0.3
Accept-Encoding:gzip, deflate
Referer:http://egg.5ch.net/test/bbs.cgi
Upgrade-Insecure-Requests:1
Content-Type:application/x-www-form-urlencoded
Content-Length:252
Connection:keep-alive
Cookie:yuki=akari; DMDM=2c3b5b74891e91cf11b69ef5eadd61196b5d8f0f336abf7dfb3da437333c3aa7; MDMD=10cce5498330e0aa2d340e04398ec186493788cc3e9979387436bf32abb9a76e
リクエストヘッダ
Referer:https://egg.5ch.net/test/read.cgi/software/1649493298/
X-PostSig:38bb2c017218405ee9f5e82139374130c5cf01c3d472fc38748c0ef194b42cf2
X-APIKey:8yoeAcaLXiEY1FjEuJBKgkPxirkDqn
X-PostNonce:1649611333.617
X-MonaKey:07bb65337ef3bdc19e10b7650a31362b464154dd3df70a2d7172869bd15d56f8
X-2ch-UA:2chMate/0.8.10.153
User-Agent:Monazilla/1.00 2chMate/0.8.10.153 Dalvik/2.1.0 (Linux; U; Android 12; SC-03L Build/SP1A.210812.016)
Accept-Encoding:gzip
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:egg.5ch.net
Cookie:DMDM=2c3b5b74891e91cf11b69ef5eadd61196b5d8f0f336abf7dfb3da437333c3aa7; MDMD=10cce5498330e0aa2d340e04398ec186493788cc3e9979387436bf32abb9a76e
Content-Length:337
Connection:Keep-Alive
レスポンスヘッダ
Connection:close
X-PostPlace:software/1649493298
X-Resnum:649
X-PostDate:1649611453.75
X-PosterID:MpwJ7F9s
X-RONIN-Stat:NONE
X-Condition:0/0
X-Proc-Time:0.194596 sec.
X-BBx-Stat:180.60.38.129, NONE
Vary:Accept-Encoding
CF-Cache-Status:DYNAMIC
Expect-CT:max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
CF-RAY:6f9d2cc05f49833e-KIX
Content-Encoding:
Content-Type:text/html; charset=Shift_JIS
Date:Sun, 10 Apr 2022 17:24:14 GMT
Server:cloudflare
```

0 comments on commit 8f69586

Please sign in to comment.