Skip to content

Commit f93f096

Browse files
committed
add json escape by esdeathlove
1 parent cd41434 commit f93f096

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class ShadowsocksNatService extends BaseService {
5656
val conf = if (profile.kcp) {
5757
ConfigUtils
5858
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, "127.0.0.1", profile.localPort + 90, profile.localPort,
59-
profile.password, profile.method, 600, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
59+
ConfigUtils.EscapedJson(profile.password), profile.method, 600, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
6060
} else {
6161
ConfigUtils
6262
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort,
63-
profile.password, profile.method, 600, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
63+
ConfigUtils.EscapedJson(profile.password), profile.method, 600, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
6464
}
6565
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-local-nat.conf"))(p => {
6666
p.println(conf)
@@ -109,7 +109,7 @@ class ShadowsocksNatService extends BaseService {
109109
if (profile.udpdns) {
110110
val conf = ConfigUtils
111111
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort + 53,
112-
profile.password, profile.method, 10, profile.protocol, profile.obfs, profile.obfs_param)
112+
ConfigUtils.EscapedJson(profile.password), profile.method, 600, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
113113
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-tunnel-nat.conf"))(p => {
114114
p.println(conf)
115115
})
@@ -135,11 +135,11 @@ class ShadowsocksNatService extends BaseService {
135135
val conf = if (profile.kcp) {
136136
ConfigUtils
137137
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, "127.0.0.1", profile.localPort + 90,
138-
profile.localPort + 63, profile.password, profile.method, 10, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
138+
profile.localPort + 63, ConfigUtils.EscapedJson(profile.password), profile.method, 10, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
139139
} else {
140140
ConfigUtils
141141
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort + 63,
142-
profile.password, profile.method, 10, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
142+
ConfigUtils.EscapedJson(profile.password), profile.method, 600, profile.protocol, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
143143
}
144144
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-tunnel-nat.conf"))(p => {
145145
p.println(conf)

src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
199199
def startShadowsocksUDPDaemon() {
200200
val conf = ConfigUtils
201201
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort,
202-
profile.password, profile.method, 600, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
202+
ConfigUtils.EscapedJson(profile.password), profile.method, 600, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
203203
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-local-udp-vpn.conf"))(p => {
204204
p.println(conf)
205205
})
@@ -220,11 +220,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {
220220
val conf = if (profile.kcp) {
221221
ConfigUtils
222222
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, "127.0.0.1", profile.localPort + 90, profile.localPort,
223-
profile.password, profile.method, 600, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
223+
ConfigUtils.EscapedJson(profile.password), profile.method, 600, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
224224
} else {
225225
ConfigUtils
226226
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort,
227-
profile.password, profile.method, 600, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
227+
ConfigUtils.EscapedJson(profile.password), profile.method, 600, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
228228
}
229229
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-local-vpn.conf"))(p => {
230230
p.println(conf)
@@ -255,11 +255,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {
255255
val conf = if (profile.kcp) {
256256
ConfigUtils
257257
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, "127.0.0.1", profile.localPort + 90, profile.localPort + 63,
258-
profile.password, profile.method, 10, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
258+
ConfigUtils.EscapedJson(profile.password), profile.method, 10, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
259259
} else {
260260
ConfigUtils
261261
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort + 63,
262-
profile.password, profile.method, 10, profile.protocol, profile.obfs, profile.obfs_param, profile.protocol_param)
262+
ConfigUtils.EscapedJson(profile.password), profile.method, 600, profile.protocol, profile.obfs, ConfigUtils.EscapedJson(profile.obfs_param), ConfigUtils.EscapedJson(profile.protocol_param))
263263
}
264264
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-tunnel-vpn.conf"))(p => {
265265
p.println(conf)

src/main/scala/com/github/shadowsocks/utils/Constants.scala

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ object Executable {
3232
}
3333

3434
object ConfigUtils {
35+
36+
def EscapedJson(OriginString:String):String = {
37+
val ProcessString = OriginString.replaceAll("\\\\","\\\\\\\\").replaceAll("\"","\\\\\"")
38+
39+
ProcessString
40+
}
41+
3542
val SHADOWSOCKS = "{\"server\": \"%s\", \"server_port\": %d, \"local_port\": %d, \"password\": \"%s\", \"method\":\"%s\", \"timeout\": %d, \"protocol\": \"%s\", \"obfs\": \"%s\", \"obfs_param\": \"%s\", \"protocol_param\": \"%s\"}"
3643
val REDSOCKS = "base {\n" +
3744
" log_debug = off;\n" +

0 commit comments

Comments
 (0)