js逆向常用代码
加载
const loadingStyle = `
#loadingDiv {
position: fixed;
z-index: 9999;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.8);
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
.loading-text {
margin-top: 20px;
font-size: 20px;
color: #333;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
` ;
const loadingHTML = `
<div id="loadingDiv">
<div class="loader"></div>
<div class="loading-text">正在生成</div>
</div>
` ;
function showLoadingScreen ( ) {
const style = document. createElement ( "style" ) ;
style. type = "text/css" ;
style. id = "loadingStyle" ;
style. innerHTML = loadingStyle;
document. head. appendChild ( style) ;
const loadingDiv = document. createElement ( "div" ) ;
loadingDiv. innerHTML = loadingHTML;
document. body. appendChild ( loadingDiv) ;
}
function hideLoadingScreen ( ) {
const loadingDiv = document. getElementById ( "loadingDiv" ) ;
if ( loadingDiv) {
loadingDiv. style. display = "none" ;
}
const style = document. getElementById ( "loadingStyle" ) ;
if ( style) {
style. remove ( ) ;
}
}
拦截图片生成
var originalCreateObjectURL = URL . createObjectURL;
URL . createObjectURL = function ( blob ) {
var originalResult = originalCreateObjectURL ( blob) ;
return originalResult;
} ;
const OriginalImage = window. Image;
function CustomImage ( ) {
const img = new OriginalImage ( ) ;
Object. defineProperty ( img, "src" , {
set : function ( url ) {
img. setAttribute ( "src" , url) ;
} ,
} ) ;
return img;
}
window. Image = CustomImage;
const originalCreateElement = document. createElement;
document. createElement = function ( tagName ) {
const element = originalCreateElement . call ( document, tagName) ;
if ( tagName. toLowerCase ( ) === "img" ) {
Object. defineProperty ( element, "src" , {
set : function ( url ) {
element. setAttribute ( "src" , url) ;
} ,
get : function ( ) {
return element. getAttribute ( "src" ) ;
} ,
} ) ;
}
return element;
} ;
拦截apply函数
const originalApply = Function . prototype. apply;
Object. defineProperty ( Function . prototype, "apply" , {
value : function ( target, thisArg, argArray ) {
return originalApply . call ( this , target, thisArg, argArray) ; ;
} ,
} ) ;
拦截Function的构建函数
Function . prototype. constructor_ = Function . prototype. constructor;
Function . prototype. constructor = function Function ( ) {
console. log ( arguments)
return this . constructor_ ( ... arguments)
}
拦截Vue加载
const observer = new MutationObserver ( ( mutationsList ) => {
for ( const mutation of mutationsList) {
if ( mutation. type === "childList" ) {
for ( const addedNode of mutation. addedNodes) {
if ( addedNode. tagName === "SCRIPT" ) {
const scriptSrc = addedNode. src;
if ( scriptSrc && scriptSrc. includes ( "vue" ) ) {
addedNode. addEventListener ( "load" , ( ) => {
console. log ( "Vue.js 文件加载成功" ) ;
if ( typeof Vue !== "undefined" ) {
const originalBeforeCreate = Vue. options. beforeCreate || [ ] ;
Vue. options. beforeCreate = [
function ( ) {
console. log (
"Vue instance is about to be created." ,
this
) ;
debugger
} ,
... originalBeforeCreate,
] ;
}
} ) ;
}
}
}
}
}
} ) ;
const config = { childList : true , subtree : true } ;
observer. observe ( document. head, config) ;