Skip to content

Commit fb4e6d4

Browse files
修复jq转换到stash时会丢失双引号的bug
Shadowrocket已支持 header-rewrite
1 parent edf4a5c commit fb4e6d4

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

Rewrite-Parser.beta.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
524524
}
525525

526526
//#!arguments参数
527-
if (/^#!arguments\s*=\s*.+/.test(x) || /^[^#]=\s*(input|select|switch)\s*,/.test(x)) {
527+
if (/^#!arguments\s*=\s*.+/.test(x) || /^[^#].+?=\s*(input|select|switch)\s*,/.test(x)) {
528528
parseArguments(x)
529529
}
530530

@@ -610,7 +610,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
610610
const jsptn = regex
611611
let args = [[action, newSuffixArray]]
612612

613-
if (jqEnabled && (isSurgeiOS || isStashiOS)) {
613+
if (jqEnabled && (isSurgeiOS || isStashiOS || isShadowrocket)) {
614614
if (action === 'json-add') {
615615
newSuffixArray.forEach(item => {
616616
const paths = parseJsonPath(item[0])
@@ -642,6 +642,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
642642
newSuffixArray = newSuffixArray.map(item => item.join(' '))
643643
rwbodyBox.push({ type: jstype, regex: jsptn, value: newSuffixArray.join(' ') })
644644
}
645+
}else if (jqEnabled && isLooniOS) {
646+
URLRewrite.push(x)
645647
} else {
646648
// console.log(JSON.stringify(args, null, 2))
647649
const index = jsBox.findIndex(i => i.jsurl === jsurl && i.jstype === jstype && i.jsptn === jsptn)
@@ -1064,7 +1066,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
10641066
realBox = pieceHn(realBox)
10651067
if (synMitm) fheBox = hnBox
10661068

1067-
if (isSurgeiOS && sgArg.length > 0) {
1069+
if ((isSurgeiOS || isShadowrocket) && sgArg.length > 0) {
10681070
let sgargArr = []
10691071
for (let i = 0; i < sgArg.length; i++) {
10701072
let key = sgArg[i].key
@@ -1114,13 +1116,13 @@ if (binaryInfo != null && binaryInfo.length > 0) {
11141116
break
11151117
} //模块信息输出结束
11161118

1117-
//[Argument]输出
1119+
//surge模块参数转[Argument]输出
11181120
if (isLooniOS && sgArg.length > 0) {
11191121
for (let i = 0; i < sgArg.length; i++) {
11201122
let key = sgArg[i].key
11211123
let type = sgArg[i].type
11221124
let value = sgArg[i].value
1123-
if (type == 'switch') value = /^true/.test(value) ? 'true,false' : 'false,true'
1125+
if (type == 'switch') value = /^true/.test(value) ? '"true","false"' : '"false","true"'
11241126
let tag = sgArg[i].tag
11251127
loonArg.push(key + '=' + type + ',' + value + ',' + tag)
11261128
}
@@ -1311,6 +1313,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
13111313
const isResponseHeaderRewrite = /^http-response\s/.test(x)
13121314
switch (targetApp) {
13131315
case 'surge-module':
1316+
case 'shadowrocket-module':
1317+
13141318
HeaderRewrite.push(mark + noteK + x)
13151319
break
13161320

@@ -1340,10 +1344,6 @@ if (binaryInfo != null && binaryInfo.length > 0) {
13401344
x = x.replace(/^http-(?:request|response)\s+/, '').replace(/\s+header-/, hdtype)
13411345
HeaderRewrite.push(mark + `${noteK4}- >-${noteKn6}` + x)
13421346
break
1343-
1344-
case 'shadowrocket-module':
1345-
otherRule.push(noteK + x)
1346-
break
13471347
} //headerRewrite输出结束
13481348
} //for
13491349

@@ -1803,9 +1803,10 @@ ${MITM}
18031803
.replace(/^(request|response)$/, '$1-replace-regex')} ${value
18041804
.replace(/^"(.+)"$/, '$1')
18051805
.replace(/^'(.+)'$/, '$1')
1806-
.split(' ')
1807-
.map(i => i.replace(/^"(.+)"$/, '$1').replace(/^'(.+)'$/, '$1'))
1808-
.join(' ')}`
1806+
//.split(' ')
1807+
//.map(i => i.replace(/^"(.+)"$/, '$1').replace(/^'(.+)'$/, '$1'))
1808+
//.join(' ')
1809+
}`
18091810
)
18101811
}
18111812
if (StashBodyRewrite.length > 0) {

Rewrite-Parser.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
524524
}
525525

526526
//#!arguments参数
527-
if (/^#!arguments\s*=\s*.+/.test(x) || /^[^#]=\s*(input|select|switch)\s*,/.test(x)) {
527+
if (/^#!arguments\s*=\s*.+/.test(x) || /^[^#].+?=\s*(input|select|switch)\s*,/.test(x)) {
528528
parseArguments(x)
529529
}
530530

@@ -610,7 +610,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
610610
const jsptn = regex
611611
let args = [[action, newSuffixArray]]
612612

613-
if (jqEnabled && (isSurgeiOS || isStashiOS)) {
613+
if (jqEnabled && (isSurgeiOS || isStashiOS || isShadowrocket)) {
614614
if (action === 'json-add') {
615615
newSuffixArray.forEach(item => {
616616
const paths = parseJsonPath(item[0])
@@ -642,6 +642,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
642642
newSuffixArray = newSuffixArray.map(item => item.join(' '))
643643
rwbodyBox.push({ type: jstype, regex: jsptn, value: newSuffixArray.join(' ') })
644644
}
645+
}else if (jqEnabled && isLooniOS) {
646+
URLRewrite.push(x)
645647
} else {
646648
// console.log(JSON.stringify(args, null, 2))
647649
const index = jsBox.findIndex(i => i.jsurl === jsurl && i.jstype === jstype && i.jsptn === jsptn)
@@ -1064,7 +1066,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
10641066
realBox = pieceHn(realBox)
10651067
if (synMitm) fheBox = hnBox
10661068

1067-
if (isSurgeiOS && sgArg.length > 0) {
1069+
if ((isSurgeiOS || isShadowrocket) && sgArg.length > 0) {
10681070
let sgargArr = []
10691071
for (let i = 0; i < sgArg.length; i++) {
10701072
let key = sgArg[i].key
@@ -1114,13 +1116,13 @@ if (binaryInfo != null && binaryInfo.length > 0) {
11141116
break
11151117
} //模块信息输出结束
11161118

1117-
//[Argument]输出
1119+
//surge模块参数转[Argument]输出
11181120
if (isLooniOS && sgArg.length > 0) {
11191121
for (let i = 0; i < sgArg.length; i++) {
11201122
let key = sgArg[i].key
11211123
let type = sgArg[i].type
11221124
let value = sgArg[i].value
1123-
if (type == 'switch') value = /^true/.test(value) ? 'true,false' : 'false,true'
1125+
if (type == 'switch') value = /^true/.test(value) ? '"true","false"' : '"false","true"'
11241126
let tag = sgArg[i].tag
11251127
loonArg.push(key + '=' + type + ',' + value + ',' + tag)
11261128
}
@@ -1311,6 +1313,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
13111313
const isResponseHeaderRewrite = /^http-response\s/.test(x)
13121314
switch (targetApp) {
13131315
case 'surge-module':
1316+
case 'shadowrocket-module':
1317+
13141318
HeaderRewrite.push(mark + noteK + x)
13151319
break
13161320

@@ -1340,10 +1344,6 @@ if (binaryInfo != null && binaryInfo.length > 0) {
13401344
x = x.replace(/^http-(?:request|response)\s+/, '').replace(/\s+header-/, hdtype)
13411345
HeaderRewrite.push(mark + `${noteK4}- >-${noteKn6}` + x)
13421346
break
1343-
1344-
case 'shadowrocket-module':
1345-
otherRule.push(noteK + x)
1346-
break
13471347
} //headerRewrite输出结束
13481348
} //for
13491349

@@ -1803,9 +1803,10 @@ ${MITM}
18031803
.replace(/^(request|response)$/, '$1-replace-regex')} ${value
18041804
.replace(/^"(.+)"$/, '$1')
18051805
.replace(/^'(.+)'$/, '$1')
1806-
.split(' ')
1807-
.map(i => i.replace(/^"(.+)"$/, '$1').replace(/^'(.+)'$/, '$1'))
1808-
.join(' ')}`
1806+
//.split(' ')
1807+
//.map(i => i.replace(/^"(.+)"$/, '$1').replace(/^'(.+)'$/, '$1'))
1808+
//.join(' ')
1809+
}`
18091810
)
18101811
}
18111812
if (StashBodyRewrite.length > 0) {

0 commit comments

Comments
 (0)