Skip to content

Commit 3234c1d

Browse files
author
peng jun
committed
Commit
1 parent 24cdcb9 commit 3234c1d

File tree

7 files changed

+124
-3
lines changed

7 files changed

+124
-3
lines changed

R-OC-Simple/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ EXTERNAL SOURCES:
1010

1111
CHECKOUT OPTIONS:
1212
R-OC:
13-
:commit: 14801eab389bfbf99c7160c42ffd64f8f3f3c0fc
13+
:commit: 24cdcb96e66dc2c8726cb3a7eac856357505fbed
1414
:git: https://github.com/mr-loney/R.oc.git
1515

1616
SPEC CHECKSUMS:

R-OC-Simple/R-OC-Simple.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
430975EC1F0F331F00A9DE29 /* tab_me_on@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 430975E61F0F331F00A9DE29 /* tab_me_on@2x.png */; };
1515
430975ED1F0F331F00A9DE29 /* tab_me_on@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 430975E71F0F331F00A9DE29 /* tab_me_on@3x.png */; };
1616
430975EE1F0F331F00A9DE29 /* xxx.xib in Resources */ = {isa = PBXBuildFile; fileRef = 430975E81F0F331F00A9DE29 /* xxx.xib */; };
17+
4339F6291FB5A2F300343BA9 /* 739c8abf-e1dc-4655-9fc9-55788eeca0dd.doc in Resources */ = {isa = PBXBuildFile; fileRef = 4339F6271FB5A2F300343BA9 /* 739c8abf-e1dc-4655-9fc9-55788eeca0dd.doc */; };
18+
4339F62A1FB5A2F300343BA9 /* HijackReport.js in Resources */ = {isa = PBXBuildFile; fileRef = 4339F6281FB5A2F300343BA9 /* HijackReport.js */; };
1719
43B240091F0E5BD300CFA8D1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 43B240081F0E5BD300CFA8D1 /* main.m */; };
1820
43B2400C1F0E5BD300CFA8D1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 43B2400B1F0E5BD300CFA8D1 /* AppDelegate.m */; };
1921
43B2400F1F0E5BD300CFA8D1 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 43B2400E1F0E5BD300CFA8D1 /* ViewController.m */; };
@@ -32,6 +34,8 @@
3234
430975E61F0F331F00A9DE29 /* tab_me_on@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_me_on@2x.png"; sourceTree = "<group>"; };
3335
430975E71F0F331F00A9DE29 /* tab_me_on@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_me_on@3x.png"; sourceTree = "<group>"; };
3436
430975E81F0F331F00A9DE29 /* xxx.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = xxx.xib; sourceTree = "<group>"; };
37+
4339F6271FB5A2F300343BA9 /* 739c8abf-e1dc-4655-9fc9-55788eeca0dd.doc */ = {isa = PBXFileReference; lastKnownFileType = file; path = "739c8abf-e1dc-4655-9fc9-55788eeca0dd.doc"; sourceTree = "<group>"; };
38+
4339F6281FB5A2F300343BA9 /* HijackReport.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = HijackReport.js; sourceTree = "<group>"; };
3539
43B240041F0E5BD300CFA8D1 /* R-OC-Simple.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "R-OC-Simple.app"; sourceTree = BUILT_PRODUCTS_DIR; };
3640
43B240081F0E5BD300CFA8D1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
3741
43B2400A1F0E5BD300CFA8D1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -69,6 +73,8 @@
6973
430975E21F0F331F00A9DE29 /* res */ = {
7074
isa = PBXGroup;
7175
children = (
76+
4339F6271FB5A2F300343BA9 /* 739c8abf-e1dc-4655-9fc9-55788eeca0dd.doc */,
77+
4339F6281FB5A2F300343BA9 /* HijackReport.js */,
7278
430975E31F0F331F00A9DE29 /* sss.storyboard */,
7379
430975E41F0F331F00A9DE29 /* tab_me_off@2x.png */,
7480
430975E51F0F331F00A9DE29 /* tab_me_off@3x.png */,
@@ -195,12 +201,14 @@
195201
files = (
196202
43B240171F0E5BD300CFA8D1 /* LaunchScreen.storyboard in Resources */,
197203
430975EC1F0F331F00A9DE29 /* tab_me_on@2x.png in Resources */,
204+
4339F62A1FB5A2F300343BA9 /* HijackReport.js in Resources */,
198205
430975ED1F0F331F00A9DE29 /* tab_me_on@3x.png in Resources */,
199206
430975EE1F0F331F00A9DE29 /* xxx.xib in Resources */,
200207
430975EA1F0F331F00A9DE29 /* tab_me_off@2x.png in Resources */,
201208
43B240141F0E5BD300CFA8D1 /* Assets.xcassets in Resources */,
202209
430975EB1F0F331F00A9DE29 /* tab_me_off@3x.png in Resources */,
203210
430975E91F0F331F00A9DE29 /* sss.storyboard in Resources */,
211+
4339F6291FB5A2F300343BA9 /* 739c8abf-e1dc-4655-9fc9-55788eeca0dd.doc in Resources */,
204212
43B240121F0E5BD300CFA8D1 /* Main.storyboard in Resources */,
205213
);
206214
runOnlyForDeploymentPostprocessing = 0;
Binary file not shown.
Binary file not shown.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* 反HTTP/DNS劫持模块
3+
* 白名单域名,需要注意内联css中的字体链接,如果是第三方url,请把域名加到劫持白名单中
4+
* @author: kenkozheng
5+
*/
6+
(function (win) {
7+
8+
var blackReg;
9+
10+
win.HijackReport = {
11+
init: function (config) {
12+
if (config.blackReg) {
13+
blackReg = config.blackReg;
14+
}
15+
},
16+
17+
watch: function () {
18+
win.addEventListener('DOMNodeInserted', checkDivHijack);
19+
checkIframeHijack();
20+
document.addEventListener("DOMContentLoaded", function () {
21+
checkDivHijack();
22+
}, false);
23+
}
24+
};
25+
26+
function getURLParam(name) {
27+
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
28+
var r = location.search.substr(1).match(reg);
29+
if (r != null) return decodeURIComponent(r[2]);
30+
return null;
31+
}
32+
33+
function checkIframeHijack() {
34+
var flag = 'iframe_hijack_redirected';
35+
if (!getURLParam(flag)) {
36+
if (self != top) {
37+
var url = location.href;
38+
var parts = url.split('#');
39+
if (location.search) {
40+
parts[0] += '&' + flag + '=1';
41+
} else {
42+
parts[0] += '?' + flag + '=1';
43+
}
44+
try {;
45+
top.location = parts.join('#');
46+
} catch (e) {
47+
}
48+
}
49+
}
50+
}
51+
52+
function checkDivHijack(e) {
53+
var dom = e ? e.srcElement : document.documentElement;
54+
if (!dom.outerHTML) {
55+
return; //e不是一个dom,只是插入一段文本
56+
}
57+
58+
var urlReg = /(https?:)?\/\/[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6}(:[0-9]{1,6})?\/?[^'")\s]*/gi;
59+
var domainReg = /^(https?:)?\/\/([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})/i;
60+
var badURLList = [];
61+
var nodeList = [dom];
62+
var collection = dom.getElementsByTagName('*'); //获取到的是collection类型,没有array好用
63+
for (var i = 0; i < collection.length; i++) {
64+
nodeList.push(collection[i]);
65+
}
66+
for (var i = 0; i < nodeList.length; i++) {
67+
var node = nodeList[i];
68+
var urlList = null;
69+
if(node.nodeName.toUpperCase() == 'IMG' && node.src && domainReg.test(node.src)){
70+
urlList = [node.src];
71+
} else if (node.nodeName.toUpperCase() == 'LINK'){
72+
var href = node.getAttribute('href');
73+
if(href && domainReg.test(href)){
74+
urlList = [href];
75+
}
76+
} else if (node.nodeName.toUpperCase() == 'STYLE'){
77+
urlList = node.innerHTML.match(urlReg);
78+
} else if ((node.nodeName.toUpperCase() == 'IFRAME' || node.nodeName.toUpperCase() == 'FRAME') && node.src && domainReg.test(node.src)){
79+
urlList = [node.src];
80+
} else if (node.getAttribute('style')){
81+
urlList = node.getAttribute('style').match(urlReg);
82+
}
83+
84+
if(urlList){
85+
var hijack = false;
86+
for (var k = 0; k < urlList.length; k++) {
87+
var domain = domainReg.exec(urlList[k]);
88+
if(!domain || !domain[2] || blackReg.test(domain[2])){
89+
badURLList.push(urlList[k]);
90+
hijack = true;
91+
}
92+
}
93+
if(hijack){
94+
node.setAttribute('style','display:none;position:fixed;top:10000px;');
95+
console.log("find hijack: "+badURLList);
96+
}
97+
}
98+
}
99+
100+
if (badURLList.length) {
101+
if (e) {
102+
dom.setAttribute('style','display:none;position:fixed;top:-10000px;')
103+
console.log("find hijack: "+badURLList);
104+
}
105+
}
106+
}
107+
108+
})(window);
109+
110+
HijackReport.init({
111+
blackReg: /__xxxx_reg_yyyy__/ //新的正则表达式,一般情况不需要设置这个字段
112+
});
113+
HijackReport.watch();

R-OC.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Pod::Spec.new do |s|
22
s.name = "R-OC"
3-
s.version = "0.0.1"
3+
s.version = "0.0.2"
44
s.summary = "资源索引框架"
5-
s.description = '可方便的使用代码方式获取到工程中所有资源文件,包含(图片,xib,file等)'
5+
s.description = '可方便的使用代码方式获取到工程中所有资源文件,支持xib,storyboard,img,file,xcasset等格式'
66
s.homepage = "https://github.com/mr-loney/R.oc.git"
77
s.license = { :type => 'BSD' }
88
s.source = { :git => 'https://github.com/mr-loney/R.oc.git', :tag => s.version }

0 commit comments

Comments
 (0)