Skip to content

Instantly share code, notes, and snippets.

@hmmhmmhm
Created May 22, 2020 08:58
Show Gist options
  • Save hmmhmmhm/f7244eeb1a7fb970e321385c76ded62c to your computer and use it in GitHub Desktop.
Save hmmhmmhm/f7244eeb1a7fb970e321385c76ded62c to your computer and use it in GitHub Desktop.
DEEP SEA SCANNER
/**
* @description
*
* 브라우저에서 특정 오브젝트 안에 트리형태로
* 존재하는 객체들과 함수에 접근해서 key 를 찾아냅니다.
*
* In the browser, access objects and functions that exist
* in tree form within a specific object to find the key.
*
* @param targetObject Object
* @param findKey String
*/
const deepScan = (targetObject, findKey, isAlive, recover) => {
let lastTimeCheckedRopeMeter = undefined
let visibleUnder = []
let ropeMeter = 0
let isSearchComplete = false
let visibleSomething = ''
let ropeCM = 0
/**
* @description
* Avoid all routes where the rpo comes from.
* 해당 문구가 오는 경로는 모두 피합니다.
*/
let cutRopes = [
'default_symbols',
'_innerWindow',
'_iFrame',
'setLayout',
'_create',
'_render',
'superclass',
'remove',
'reconnect',
'connect',
'alert',
'open',
'stop',
'confirm',
'prompt',
'print',
'_update',
'update',
'_init',
'subscribeBars',
'removeEventListener',
'layout',
'spawn',
'unsubscribe',
'unsubscribeAll',
'reset',
'resetData',
'_destroy',
'destroy',
'destroyPromise',
'hide',
'show',
'appendChild',
'evaluate',
'close',
'disconnect',
'disable',
'write',
'writeln',
]
/**
* @description
* Avoid all routes specified here.
* 여기 명시된 경로는 모두 피합니다.
*/
let dangerRopes = [
'window.location',
'window.top',
'window.history',
]
const deepSeaSearch = async (option) => {
ropeMeter++
try {
let existKeys = []
for (let proto in option.deepSea) {
if (typeof existKeys[proto] == 'undefined')
existKeys.push(proto)
}
// listCheck.push(existKeys)
console.log('[DEEP SEA] GO', option.keyRope, existKeys)
// BEEP BEEP BEEP!
if (existKeys.indexOf(option.findKey) != -1) {
let foundedKeyRope = (option.keyRope.length == 0) ? option.findKey : `${option.keyRope}.${option.findKey}`
console.warn(`[DEEP SEA] BEEP! BEEP! BEEP!: ${foundedKeyRope}`)
}
// DEEP SEA SCANNING...
for (let existKey of existKeys) {
if (cutRopes.indexOf(existKey) != -1) continue
if (typeof option.deepSea[existKey] != 'object') {
if (typeof option.deepSea[existKey] == 'function') {
let sentKeyRope = (option.keyRope.length == 0) ? existKey : `${option.keyRope}.${existKey}()`
if (dangerRopes.indexOf(sentKeyRope) != -1) continue
console.log(`[DEEP SEA] FUNCTION FOUND ropeCM:${++ropeCM}`, `${sentKeyRope}`)
try {
let reallyDeepSea = await option.deepSea[existKey]()
console.log('[DEEP SEA] FUNCTION ENDED', `${sentKeyRope}`, reallyDeepSea)
if (reallyDeepSea) {
visibleUnder.push({
deepSea: reallyDeepSea,
findKey: option.findKey,
keyRope: sentKeyRope,
})
}
if (!isAlive()) {
console.error(`[DEEP SEA] DAMAGED IN ROPE: ${sentKeyRope}`)
recover()
await delay(3000)
}
} catch (e) { }
}
continue
}
let sentKeyRope = (option.keyRope.length == 0) ? existKey : `${option.keyRope}.${existKey}`
visibleSomething = sentKeyRope
visibleUnder.push({
deepSea: option.deepSea[existKey],
findKey: option.findKey,
keyRope: sentKeyRope,
})
}
} catch (e) {
console.log(e)
}
}
// CHECK LIVE OR NOT
setInterval(() => {
console.log(`[DEEP SEA] SEARCHING... ROPE METER: ${ropeMeter}M... CAN SEE UNDER ${visibleUnder.length}M`)
console.log(`[DEEP SEA] VISIBLE SOMETHING ${visibleSomething}`)
if (lastTimeCheckedRopeMeter == ropeMeter && !isSearchComplete)
console.log(`[DEEP SEA] SEARCHING... IT LOOKS LIKE A DEEP SEA ROPE IS BROKEN...?`)
lastTimeCheckedRopeMeter = ropeMeter
// console.log(listCheck)
}, 2000)
const delay = (t) => {
return new Promise((resolve) => {
setTimeout(resolve, t)
})
}
const cruseSearch = async () => {
console.log(`[DEEP SEA] SEARCHING... ROPE METER: ${ropeMeter}M... CAN SEE UNDER ${visibleUnder.length}M`)
await deepSeaSearch({
deepSea: targetObject,
findKey,
keyRope: ''
})
let sleepCount = 0
while (true) {
if (visibleUnder.length == 0) {
isSearchComplete = true
console.log('[DEEP SEA] SCAN COMPLETE')
return
}
await deepSeaSearch(visibleUnder.shift())
if (++sleepCount == 1000) {
console.log('[DEEP SEA] SLEEP')
sleepCount = 0
await delay(100)
}
}
}
cruseSearch()
}
/**
* @description
* 해당 객체 기능이 탐색도중 손상되었는지를 파악합니다.
* Determine if the object function is
* corrupted during the navigation.
*/
const isAlive = () => {
try {
let check = typeof window.sessionStorage == 'object'
if (!check) throw new Error('')
return true
} catch (e) {
return false
}
}
let _sessionStorage = window.sessionStorage
/**
* @description
* 해당 탐색대상이 손상되었을때 메모리로 다시 불러옵니다.
* Recall into memory when the target is damaged.
*/
const recover = () => {
window.sessionStorage = _sessionStorage
}
deepScan(window, 'target', isAlive, recover)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment