Skip to content

Commit f1815ce

Browse files
Merge pull request microDreamSheep#5 from microDreamSheep/code
Code
2 parents d1c4bec + 19dbc85 commit f1815ce

File tree

6 files changed

+180
-14
lines changed

6 files changed

+180
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SWCJ(完成进度25%)
1+
# SWCJ(完成进度25%)(本文档已失效)
22

33
## 什么是SWCJ
44

@@ -12,8 +12,8 @@
1212

1313
我当前提供的:
1414

15-
1. jsoup增强工具(开源)-->整合了jsoup,可以使用jsoup强大的分析工具
16-
2. 高性能编译器(**闭源**)-->每一个部分都由我自研,通过直接生成字节码来优化速度,暂在开发中
15+
1. jsoup增强工具-->整合了jsoup,可以使用jsoup强大的分析工具
16+
2. 高性能编译器-->每一个部分都由我自研,通过直接生成字节码来优化速度,暂在开发中
1717
3. http请求大杂烩(开源)-->暂不完善
1818
4. 敬请期待
1919
## 安全检查

src/main/java/com/midream/sheep/swcj/core/executetool/execute/regularexpression/SWCJregular.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.midream.sheep.swcj.data.XmlSpecialStrings;
88
import com.midream.sheep.swcj.pojo.ExecuteValue;
99
import com.midream.sheep.swcj.util.function.StringUtil;
10+
import org.w3c.dom.Document;
1011
import org.w3c.dom.Node;
1112
import org.w3c.dom.NodeList;
1213
import org.xml.sax.InputSource;
@@ -22,6 +23,8 @@
2223
*/
2324
public class SWCJregular<T> implements SWCJExecute<T> {
2425

26+
27+
private String before = "";
2528
@Override
2629
public List<T> execute(ExecuteValue executeValue, String... args) throws Exception {
2730
for (Map.Entry<String, String> entry : XmlSpecialStrings.map.entrySet()) {
@@ -30,17 +33,20 @@ public List<T> execute(ExecuteValue executeValue, String... args) throws Excepti
3033
String text = getText(executeValue);
3134
Map<String, List<String>> values = new LinkedHashMap<>();
3235
//获取节点对象
33-
NodeList d = DocumentBuilderFactory.newInstance()
36+
Document parse = DocumentBuilderFactory.newInstance()
3437
.newDocumentBuilder()
3538
.parse(
3639
new InputSource(new StringReader(args[0].trim()))
37-
)
38-
.getElementsByTagName(RegConstants.regTag)
39-
.item(0)
40-
.getChildNodes();
40+
);
41+
NodeList reg = parse.getElementsByTagName("REG");
42+
if(reg.getLength()==0){
43+
before="reg:";
44+
reg=parse.getElementsByTagName("reg:REG");
45+
}
46+
NodeList d=reg.item(0).getChildNodes();
4147
for (int i = 0; i < d.getLength(); i++) {
4248
Node item = d.item(i);
43-
if (!item.getNodeName().equals(RegConstants.regTag)) {
49+
if (!item.getNodeName().equals(before+RegConstants.regTag)) {
4450
continue;
4551
}
4652
//放入属性map
@@ -51,7 +57,11 @@ public List<T> execute(ExecuteValue executeValue, String... args) throws Excepti
5157
for (Map.Entry<String, String> entry : XmlSpecialStrings.map.entrySet()) {
5258
trim = trim.replace(entry.getKey(), entry.getValue());
5359
}
54-
String del = item.getAttributes().getNamedItem("del").getTextContent();
60+
Node delNode = item.getAttributes().getNamedItem("del");
61+
String del = null;
62+
if(delNode!=null){
63+
del = delNode.getTextContent();
64+
}
5565
String[] nots = new String[0];
5666
if (del != null && !del.equals("")) {
5767
String[] split = del.trim().split("';");

src/main/java/com/midream/sheep/swcj/core/factory/parse/bystr/BetterXmlParseTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private void parseConfigFile(String configString, ReptileConfig config) {
6060
if(configString.contains("<injections>")){
6161
parseInjections(configString.substring(configString.indexOf("<injections>") + "<injections>".length(), configString.indexOf("</injections>")));
6262
}
63-
config.setCache(configString.contains("<cache/>"));
63+
config.setCache(configString.contains("<cache/>")||configString.contains("<cache></cache>"));
6464
}
6565

6666
private void parseInjections(String substring) {

src/main/resources/Efficient.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
-->
7171
<url>
7272
<name>getit</name>
73-
<inPutName></inPutName>
7473
<!--请求方式-->
7574
<type>GET</type>
7675
<!--请求参数 格式 key=value;key=value......-->
@@ -91,11 +90,11 @@
9190
<!--del删除的字符
9291
格式: '';'';
9392
-->
94-
<reg>
93+
<REG>
9594
<reg name="" del=""></reg>
9695
<reg name=""></reg>
9796
<reg name=""></reg>
98-
</reg>
97+
</REG>
9998
</xml>
10099
</parseProgram>
101100
</url>

src/main/resources/reg/reg.xsd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
elementFormDefault="qualified">
4+
<xsd:element name="REG" type="REG"/>
5+
<xsd:complexType name="REG">
6+
<xsd:sequence>
7+
<xsd:element name="reg" type="reg" maxOccurs="unbounded" minOccurs="1"/>
8+
</xsd:sequence>
9+
</xsd:complexType>
10+
<xsd:complexType name="reg">
11+
<xsd:attribute name="name" type="xsd:string"/>
12+
<xsd:attribute name="del" type="xsd:string"/>
13+
</xsd:complexType>
14+
</xsd:schema>
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?xml version="1.0"?>
2+
<xsd:schema xmlns="http://www.itcast.cn/xml"
3+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4+
targetNamespace="http://www.itcast.cn/xml"
5+
elementFormDefault="qualified">
6+
<!--根标签定义-->
7+
<xsd:element name="SWCJ" type="SWCJType"/>
8+
<xsd:simpleType name="Boolean">
9+
<xsd:restriction base="xsd:string">
10+
<xsd:enumeration value="true"/>
11+
<xsd:enumeration value="false"/>
12+
</xsd:restriction>
13+
</xsd:simpleType>
14+
<!--二级子标签-->
15+
<xsd:complexType name="SWCJType">
16+
<xsd:sequence>
17+
<xsd:element name="config" type="configType" minOccurs="0"/>
18+
<xsd:element name="swc" type="swcType" minOccurs="0" maxOccurs="unbounded"/>
19+
</xsd:sequence>
20+
</xsd:complexType>
21+
22+
23+
<!--配置文件限定-->
24+
<xsd:complexType name="configType">
25+
<xsd:all>
26+
<!--分析策略-->
27+
<xsd:element name="chooseStrategy" type="chooseStrategy" minOccurs="0"/>
28+
<!--超时时间-->
29+
<xsd:element name="timeout" type="timeout" minOccurs="0"/>
30+
<!--userAgent-->
31+
<xsd:element name="userAgent" type="userAgent" minOccurs="0"/>
32+
<!--是否使用缓存-->
33+
<xsd:element name="cache" minOccurs="0"/>
34+
<!--工作空间-->
35+
<xsd:element name="constructionSpace" type="constructionSpace" minOccurs="0"/>
36+
<!--执行器-->
37+
<xsd:element name="executes" type="executes" minOccurs="0"/>
38+
<xsd:element name="injections" type="injections" minOccurs="0"/>
39+
</xsd:all>
40+
</xsd:complexType>
41+
<!--分析策略-->
42+
<xsd:simpleType name="chooseStrategy">
43+
<xsd:restriction base="xsd:string">
44+
<xsd:enumeration value="METHOD_NAME"/>
45+
<xsd:enumeration value="ANNOTATION"/>
46+
</xsd:restriction>
47+
</xsd:simpleType>
48+
<!--超时时间配置-->
49+
<xsd:simpleType name="timeout">
50+
<xsd:restriction base="xsd:integer"/>
51+
</xsd:simpleType>
52+
<!--UserAgent-->
53+
<xsd:complexType name="userAgent">
54+
<xsd:sequence>
55+
<xsd:element name="value" type="xsd:string" maxOccurs="100"/>
56+
</xsd:sequence>
57+
</xsd:complexType>
58+
<!--工作空间复合标签-->
59+
<xsd:complexType name="constructionSpace">
60+
<xsd:sequence>
61+
<!--是否绝对路径-->
62+
<xsd:element name="isAbsolute" type="Boolean" minOccurs="0"/>
63+
<!--工作空间-->
64+
<xsd:element name="workSpace" minOccurs="0"/>
65+
</xsd:sequence>
66+
</xsd:complexType>
67+
<!--执行器-->
68+
<xsd:complexType name="executes">
69+
<xsd:sequence>
70+
<xsd:element name="execute" type="execute"/>
71+
</xsd:sequence>
72+
</xsd:complexType>
73+
<!--单个执行器-->
74+
<xsd:complexType name="execute">
75+
<xsd:all>
76+
<xsd:element name="key" type="xsd:string"/>
77+
<xsd:element name="value" type="xsd:string"/>
78+
<xsd:element name="executeConfig" type="xsd:string" minOccurs="0"/>
79+
</xsd:all>
80+
</xsd:complexType>
81+
<!--injections-->
82+
<xsd:complexType name="injections">
83+
<xsd:sequence>
84+
<xsd:element minOccurs="0" maxOccurs="unbounded" name="injection" type="injection"/>
85+
</xsd:sequence>
86+
</xsd:complexType>
87+
<xsd:complexType name="injection">
88+
<xsd:sequence>
89+
<xsd:element name="key" type="xsd:string"/>
90+
<xsd:element name="value" type="xsd:string"/>
91+
</xsd:sequence>
92+
</xsd:complexType>
93+
94+
<!--执行逻辑-->
95+
<xsd:complexType name="swcType">
96+
<xsd:sequence>
97+
<!--获取id-->
98+
<xsd:element name="id" type="xsd:string"/>
99+
<!--携带cookie-->
100+
<xsd:element name="cookies" type="xsd:string" minOccurs="0"/>
101+
<!--接口-->
102+
<xsd:element name="parentInterface" type="xsd:string"/>
103+
<!--具体的请求方法-->
104+
<xsd:element name="url" type="url" maxOccurs="unbounded"/>
105+
</xsd:sequence>
106+
</xsd:complexType>
107+
<!--url具体配置-->
108+
<xsd:complexType name="url">
109+
<xsd:all>
110+
<!--选择名-->
111+
<xsd:element name="name" type="xsd:string"/>
112+
<!--请求类型-->
113+
<xsd:element name="type" type="type" minOccurs="0"/>
114+
<!--请求参数-->
115+
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
116+
<!--请求路径-->
117+
<xsd:element name="path" type="xsd:string"/>
118+
<!--解析方案-->
119+
<xsd:element name="parseProgram" type="parseProgram"/>
120+
</xsd:all>
121+
</xsd:complexType>
122+
<!--type限制-->
123+
<xsd:simpleType name="type">
124+
<xsd:restriction base="xsd:string">
125+
<xsd:enumeration value="GET"/>
126+
<xsd:enumeration value="POST"/>
127+
<xsd:enumeration value="DELETE"/>
128+
<xsd:enumeration value="HEAD"/>
129+
<xsd:enumeration value="PUT"/>
130+
<xsd:enumeration value="OPTIONS"/>
131+
<xsd:enumeration value="TRACE"/>
132+
<xsd:enumeration value="CONNECT"/>
133+
</xsd:restriction>
134+
</xsd:simpleType>
135+
<!--parseProgram-->
136+
<xsd:complexType name="parseProgram">
137+
<xsd:sequence>
138+
<xsd:element name="isHtml" type="Boolean"/>
139+
<xsd:element name="type" type="xsd:string"/>
140+
<xsd:element name="xml" type="xsd:anyType"/>
141+
</xsd:sequence>
142+
</xsd:complexType>
143+
</xsd:schema>

0 commit comments

Comments
 (0)