js逆向常用代码

[复制链接]
发表于 2025-10-24 17:37:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
js逆向常用代码

加载
  1. const loadingStyle = `
  2.       #loadingDiv {
  3.           position: fixed;
  4.           z-index: 9999;
  5.           top: 0;
  6.           left: 0;
  7.           width: 100%;
  8.           height: 100%;
  9.           background-color: rgba(255, 255, 255, 0.8);
  10.           display: flex;
  11.           align-items: center;
  12.           justify-content: center;
  13.           flex-direction: column;
  14.       }
  15.       .loader {
  16.           border: 16px solid #f3f3f3;
  17.           border-radius: 50%;
  18.           border-top: 16px solid #3498db;
  19.           width: 120px;
  20.           height: 120px;
  21.           animation: spin 2s linear infinite;
  22.       }
  23.       .loading-text {
  24.           margin-top: 20px;
  25.           font-size: 20px;
  26.           color: #333;
  27.       }
  28.       @keyframes spin {
  29.           0% { transform: rotate(0deg); }
  30.           100% { transform: rotate(360deg); }
  31.       }
  32.    `;
  33. const loadingHTML = `
  34.       <div id="loadingDiv">
  35.           <div class="loader"></div>
  36.           <div class="loading-text">正在生成</div>
  37.       </div>
  38.    `;
  39. // 显示加载页面的方法
  40. function showLoadingScreen() {
  41.    // 创建样式元素并插入到head中
  42.    const style = document.createElement("style");
  43.    style.type = "text/css";
  44.    style.id = "loadingStyle";
  45.    style.innerHTML = loadingStyle;
  46.    document.head.appendChild(style);
  47.    // 创建加载层元素并插入到body中
  48.    const loadingDiv = document.createElement("div");
  49.    loadingDiv.innerHTML = loadingHTML;
  50.    document.body.appendChild(loadingDiv);
  51. }
  52. // 隐藏加载页面的方法
  53. function hideLoadingScreen() {
  54.    const loadingDiv = document.getElementById("loadingDiv");
  55.    if (loadingDiv) {
  56.      loadingDiv.style.display = "none";
  57.    }
  58.    const style = document.getElementById("loadingStyle");
  59.    if (style) {
  60.      style.remove();
  61.    }
  62. }
复制代码
拦截图片天生
  1. var originalCreateObjectURL = URL.createObjectURL;
  2. // 重写createObjectURL方法
  3. URL.createObjectURL = function (blob) {
  4.   // 调用原始的createObjectURL方法,并返回其结果
  5.   var originalResult = originalCreateObjectURL(blob);
  6.   // 返回重写后的结果
  7.   return originalResult;
  8. };
复制代码
  1. // 保存原始的 Image 构造函数
  2. const OriginalImage = window.Image;
  3. // 创建一个自定义的 Image 构造函数
  4. function CustomImage() {
  5.   const img = new OriginalImage();
  6.   // 定义一个 setter 拦截 src 属性
  7.   Object.defineProperty(img, "src", {
  8.     set: function (url) {
  9.       // 继续设置 src 属性
  10.       img.setAttribute("src", url);
  11.     },
  12.   });
  13.   return img;
  14. }
  15. window.Image = CustomImage;
复制代码
  1. const originalCreateElement = document.createElement;
  2. // 重写 createElement 方法
  3. document.createElement = function (tagName) {
  4.    const element = originalCreateElement.call(document, tagName);
  5.    if (tagName.toLowerCase() === "img") {
  6.      // 定义一个 setter 拦截 src 属性
  7.      Object.defineProperty(element, "src", {
  8.        set: function (url) {
  9.         
  10.          element.setAttribute("src", url);
  11.        },
  12.        get: function () {
  13.          return element.getAttribute("src");
  14.        },
  15.      });
  16.    }
  17.    return element;
  18. };
复制代码
拦截apply函数
  1. const originalApply = Function.prototype.apply;
  2. Object.defineProperty(Function.prototype, "apply", {
  3.   value: function (target, thisArg, argArray) {
  4.    
  5.     // 调用原始的 apply 方法
  6.     return originalApply.call(this, target, thisArg, argArray);;
  7.   },
  8. });
复制代码
拦截Function的构建函数
  1. Function.prototype.constructor_ = Function.prototype.constructor;
  2. Function.prototype.constructor=function Function(){
  3.   console.log(arguments)
  4.   return this.constructor_(...arguments)
  5. }
复制代码
拦截Vue加载
  1. // 创建一个 MutationObserver 实例
  2.     const observer = new MutationObserver((mutationsList) => {
  3.         for (const mutation of mutationsList) {
  4.             if (mutation.type === "childList") {
  5.                 // 遍历新增的节点
  6.                 for (const addedNode of mutation.addedNodes) {
  7.                     if (addedNode.tagName === "SCRIPT") {
  8.                         const scriptSrc = addedNode.src;
  9.                         // 检查是否为 Vue.js 文件
  10.                         if (scriptSrc && scriptSrc.includes("vue")) {
  11.                             // 监听 script 标签的 load 事件
  12.                             addedNode.addEventListener("load", () => {
  13.                                 console.log("Vue.js 文件加载成功");
  14.                                 // 在这里可以执行你需要的操作
  15.                                 // 例如检查 Vue 是否可用
  16.                                 if (typeof Vue !== "undefined") {
  17.                                     const originalBeforeCreate = Vue.options.beforeCreate || [];
  18.                                     Vue.options.beforeCreate = [
  19.                                         function () {
  20.                                             console.log(
  21.                                                 "Vue instance is about to be created.",
  22.                                                 this
  23.                                             );
  24.                                             debugger
  25.                                             // 在这里添加自定义代码
  26.                                         },
  27.                                         ...originalBeforeCreate,
  28.                                     ];
  29.                                 }
  30.                             });
  31.                         }
  32.                     }
  33.                 }
  34.             }
  35.         }
  36.     });
  37.     // 配置观察选项
  38.     const config = { childList: true, subtree: true };
  39.     // 开始观察 document.body
  40.     observer.observe(document.head, config);
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告
回复

使用道具 举报

×
登录参与点评抽奖,加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表