An Electron application developer tool forced opening method, device, equipment and medium
By intercepting the V8 engine compilation entry point using dynamic binary instrumentation technology in Electron applications, injecting DevTools control code, and combining it with the Electron API, the problem of forcibly enabling and disabling DevTools in Electron applications is solved. This enables continuous operation and user control of DevTools, making it suitable for security auditing and debugging of Electron applications.
Patent Information
- Application Number
- CN202611083181.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-21
- Publication Date
- 2026-11-20
AI Technical Summary
Existing technologies struggle to effectively force the opening of developer tools in Electron applications without modifying files or relying on debugging parameters, and to counteract anti-debugging shutdown behaviors within the application.
By intercepting the V8 engine's script compilation entry point through dynamic binary instrumentation, obtaining the script source code, and injecting developer tool control code into memory, combined with the Electron application interface, DevTools is forcibly enabled and closed requests are blocked. Global shortcut keys are registered to achieve user control.
It enables seamless injection of DevTools into Electron applications, continuously keeping it running and resisting internal application shutdown behavior, thus improving the stability and flexibility of debugging and auditing. It is applicable to different Electron applications and does not affect normal functionality.
Smart Images

Figure CN123138089A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software debugging and security auditing technology, and in particular to a method, apparatus, device and medium for forcibly enabling Electron application developer tools. Background Technology
[0002] Electron is a mainstream desktop application development framework built on Chromium and Node.js, and is widely used for cross-platform desktop application development. Electron applications come with built-in Chrome DevTools, which developers and security researchers typically need to open to observe information such as the application's DOM structure, network requests, and JavaScript execution status when debugging, reverse engineering, and security auditing applications.
[0003] Currently, the main ways to open the DevTools of an Electron application include: (1) opening it through the menu or shortcut key (such as Ctrl+Shift+I) provided by the application itself, but most production environment applications will disable this function; (2) inserting openDevTools calls into the source code by modifying the application's installation file (such as the ASAR package), but this method requires unpacking, modifying and repackaging, which is cumbersome and will destroy the application's digital signature and integrity verification. Some applications will detect file integrity and refuse to run when starting; (3) enabling the debugging port through startup parameters (such as --inspect, --remote-debugging-port), but production environment applications usually filter or ignore debugging-related command line parameters, or even actively exit the process after detecting that the debugging port is open.
[0004] Furthermore, even if DevTools is successfully opened using the methods described above, the application's business logic may still contain logic that periodically checks and calls webContents.closeDevTools() to actively close DevTools, rendering DevTools unusable. Therefore, how to forcibly open DevTools at runtime without modifying application files or relying on debugging parameters, and effectively combat anti-debugging shutdown behavior, has become a pressing technical problem in this field. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a method, apparatus, device and medium for forcibly enabling Electron application developer tools, without modifying application files, effectively resisting anti-debugging behavior, and providing an efficient and reliable technical means for security auditing, vulnerability research and debugging of Electron applications.
[0006] In a first aspect, the present invention provides a method for forcibly enabling Electron application developer tools, comprising the following steps: S1. By using dynamic binary instrumentation technology, intercept the script compilation entry function of the V8 engine during the Electron application runtime to obtain the source code and script identification information of the script to be compiled. S2. Based on the script identification information, determine whether the script to be compiled is the main process entry script of the target application; if yes, proceed to step S3; if no, maintain the original compilation process of the script to be compiled and end the process. S3. In memory, the control code used to force the developer tools to be enabled is appended to the end of the original source code of the script to be compiled, generating the modified script source code, and the modified script source code is written back to the compilation pipeline of the V8 engine to replace the original source code for compilation and execution. S4. In response to the execution of the modified script source code, after the main window of the target application is loaded, the developer tools of the main window are forcibly opened through the Electron application programming interface, and the window is prevented from closing in response to a close request, so as to maintain the open state.
[0007] Secondly, the present invention provides a device for forcibly enabling Electron application developer tools, comprising: The script compilation interception module uses dynamic binary instrumentation technology to intercept the script compilation entry function of the V8 engine during Electron application runtime, and obtain the source code and script identification information of the script to be compiled. The precise injection and positioning module determines whether the script to be compiled is the main process entry script of the target application based on the script identification information; if so, the source code dynamic modification module is executed; if not, the original compilation process of the script to be compiled is maintained and the process ends. The source code dynamic modification module appends the control code used to force the developer tools to be enabled to the end of the original source code of the script to be compiled in memory, generates the modified script source code, and writes the modified script source code back to the compilation pipeline of the V8 engine to replace the original source code for compilation and execution. The developer tools enable and protect module, in response to the execution of the modified script source code, after the main window of the target application is loaded, forcibly opens the developer tools of the main window through the Electron application programming interface and prevents it from closing in response to a close request, so as to maintain the open state.
[0008] Thirdly, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect.
[0009] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0010] One or more technical solutions provided by this invention have at least the following technical effects or advantages: 1. This application uses dynamic binary instrumentation technology to hook at the V8 engine compilation entry point, completing the modification and injection of script source code in memory. It does not require unpacking, modifying or repackaging any disk files of the Electron application, and will not damage the application's digital signature and integrity verification. It effectively avoids the file integrity detection mechanism at application startup and achieves runtime traceless injection.
[0011] 2. This application replaces the webContents.closeDevTools() method of the main window with an empty function through a method overriding mechanism, while saving its original reference. When the application business code calls the close method, it is silently intercepted, effectively resisting the anti-debugging close behavior inside the application. This ensures that the developer tools remain open throughout the entire application lifecycle, significantly improving the stability and continuity of debugging and auditing.
[0012] 3. This application registers a system-level global shortcut key, enabling users to actively control the opening and closing of the developer tools via the shortcut key. Combined with the anti-closing protection mechanism, it forms a dual control strategy of "business code cannot be closed, and users can actively control it", which not only ensures that the developer tools are always open, but also provides users with flexible operation permissions.
[0013] 4. This application uses a precise matching mechanism based on script filenames to inject control code only into the main process entry script of the target application, without making any modifications to third-party libraries, rendering process scripts, or other unrelated scripts. This ensures that the injection behavior is highly accurate, has minimal side effects, and does not affect the normal operation of other functions of the application.
[0014] 5. This application uses a memory reference persistence mechanism to store the memory pointers allocated during the injection process in a global reference array, effectively preventing the V8 engine's garbage collection mechanism from reclaiming critical memory areas before compilation is complete, thus ensuring the integrity of the injected code and the stability of the compilation process.
[0015] 6. This application does not require the application to have its own open debugging interface, does not require pre-modification of files, and does not rely on specific startup parameters. It has a wide range of applications and can be migrated to different Electron applications simply by adjusting the matching identifier according to the actual main entry file name of the target application. It has good versatility and portability, and provides an efficient and reliable technical means for software security auditing, vulnerability research, reverse analysis and application debugging.
[0016] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0017] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0018] Figure 1 This is a flowchart of the method in Embodiment 1 of the present invention; Figure 2 This is a schematic diagram of the device in Embodiment 2 of the present invention. Detailed Implementation
[0019] The overall concept of the technical solution in this application is as follows: This application proposes a method and system for forcibly enabling Electron application developer tools based on V8 engine script compilation hooks. By using dynamic binary instrumentation technology (Frida), the script compilation entry point of the V8 engine is intercepted at the application runtime. Without modifying any application files, DevTools control code is injected into the main process script of the target application, realizing automatic opening, protection against closing, and shortcut key control of DevTools.
[0020] (1) Runtime script injection mechanism based on V8 compilation entry point By using the Frida framework for dynamic binary instrumentation to locate the exported symbol address of `ScriptCompiler::CompileFunction` in the V8 engine, and then using an Interceptor to set a hook at the function entry point, the hook callback is triggered when the V8 engine compiles any JavaScript script. This allows the engine to read the source code and filename of the script to be compiled. The main process entry script of the target application (e.g., `main.index.js`) is identified by matching the filename. Injected code is appended to the end of the original source code, and the modified source code is written back to the V8's `Source` structure. This ensures that V8 actually compiles and executes an enhanced version containing the injected code. The entire process occurs in memory and does not modify any files on disk.
[0021] (2) Cross-language bidirectional conversion of V8 string types To enable reading and writing of string data within the V8 engine, symbol resolution is used to locate V8's string manipulation APIs: `String::Utf8Length` retrieves the UTF-8 byte length of the V8 string, `String::WriteUtf8` exports the internal V8 string as a UTF-8 byte stream, and `String::NewFromUtf8` creates an internal V8 string object from the external UTF-8 byte stream. `Isolate::GetCurrent` retrieves the current V8 isolation instance as the context. This conversion mechanism allows the injection framework to read V8 script source code at the native level, modify its content, and then write it back to the V8 compilation pipeline.
[0022] (3) DevTools automatic opening and anti-closing protection mechanism The injected code ensures execution after the application window is created by using Electron's `app.whenReady()` event. All window instances are obtained via `BrowserWindow.getAllWindows()`, and `webContents.openDevTools({mode:detach})` is executed on the main window to open DevTools in detached window mode. Close protection is implemented through method overriding: after saving the original reference to `webContents.closeDevTools`, it is replaced with a null operation function, silently intercepting any calls to `closeDevTools()` in the application's business logic, keeping DevTools always open.
[0023] (4) Controllable switch mechanism based on global shortcut keys Registering system-level global shortcuts (such as Ctrl+Shift+U) via Electron's globalShortcut.register API provides users with the ability to manually control the display state of DevTools. The actual closing operation is achieved within the shortcut callback by retaining the original closeDevTools reference, forming a dual control strategy: default protection against closing by business logic code plus active user control via shortcuts.
[0024] (5) Precise injection location based on script filename The Hook callback reads the script resource name (resource_name) from the V8 Source structure and performs a string match against the preset target entry file name. The injection logic is executed only if the script name contains the target entry file identifier, without making any modifications to other scripts (such as third-party libraries, rendering process scripts, etc.), ensuring the accuracy of the injection and zero impact on other parts of the application.
[0025] (6) Memory reference persistence anti-garbage mechanism Since the V8 string objects and allocated native memory blocks created during the injection process need to remain valid after the Hook callback returns (the V8 compilation process may asynchronously reference this data), a global array is used to hold all allocated memory pointer references to prevent the garbage collector from reclaiming these memory areas before compilation is complete, thus ensuring the integrity and stability of the injected code.
[0026] Specifically: Step 1: Locate the V8 compilation entry point Electron uses the V8 engine to execute JavaScript. V8 compiles any script before it can be executed.
[0027] We locate the function responsible for compilation in V8 (ScriptCompiler::CompileFunction) and insert an interceptor before it executes: / / Locate the script compilation function for V8 const v8CompileFunction = Module.getGlobalExportByName( "?CompileFunction@ScriptCompiler@v8@@SA..." ); / / Set up interception at function entry point Interceptor.attach(v8CompileFunction, { onEnter(args) { / / Every time V8 needs to compile a script, it comes here first. } }); Step 2: Identify the main process entry script V8 compiles many scripts (third-party libraries, various modules, etc.), but we only care about the application's main process entry point; we leave the others untouched. We determine this by reading the script filenames. / / Read script name const sourceName = v8StringToJsString(isolate, source.readPointer().add(8)); / / Only process the main entry script if (sourceName.includes('main.index.js')) { console.log('[Inject] Hit the main entry point:', sourceName); / / Start Injection } Step 3: Append control code to the end of the source code After confirming it's the main entry script, the original source code is read, and our DevTools control code is appended to the end. The entire process is completed in memory; not a single byte of the file on disk changes.
[0028] / / Read the original source code const sourceContent = v8StringToJsString(isolate, source.readPointer()); / / Append injection code to the end const replaced = sourceContent + " " + injectAfter + " " / / Write the modified source code back const replacedV8 = jsStringToV8String(isolate, Memory.allocUtf8String(replaced)); args[2].writePointer(replacedV8.readPointer()); Step 4: After the application has finished starting, open DevTools. The injected code executes automatically once the application is ready. `setTimeout` is used because the operation waits until the window is actually created; 600ms is generally sufficient, but applications with slow window startup times can increase this value.
[0029] app.whenReady().then(() => { setTimeout(() => { / / Find the main window const mainWindow = BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0]; / / Open DevTools (independent window mode) mainWindow.webContents.openDevTools({ mode: 'detach'}); console.log('[DevTools] has been opened automatically'); }, 600); }); Step 5: Prevent the application from closing DevTools Many applications manually close DevTools in their code; we'll replace this method. After that, no matter how many times the application calls closeDevTools(), DevTools will remain unchanged.
[0030] / / Save the original method (for backup) win._originalCloseDevTools = win.webContents.closeDevTools.bind(win.webContents); / / Replace closeDevTools with an empty function that does nothing. win.webContents.closeDevTools = function () { console.log('[DevTools] intercepted a close request and blocked it'); / / Do nothing }; Step 6: Register the shortcut key and control it manually. Provide users with a shortcut key for manual control (default Ctrl+Shift+U), forming a two-layer control: the application's own code cannot turn it off, but the user can turn it off manually by pressing the shortcut key.
[0031] globalShortcut.register('Control+Shift+U', () => { const win = getMainWindow(); if (win.webContents.isDevToolsOpened()) { win._originalCloseDevTools(); / / Call the original method to actually close } else { win.webContents.openDevTools({ mode: 'detach'}); }}); How to read and write strings in V8: V8 uses its own string format internally, which cannot be used directly as a regular string. You need to use the V8 API to convert it. Plain string → V8 string: UTF-8 bytes → String::NewFromUtf8 → V8 String object V8 string → ordinary string: V8 String object → String::WriteUtf8 → UTF-8 bytes / / V8 string → JS string function v8StringToJsString(isolate, v8String) { const len = call_v8_string_utf8_length(v8String, isolate); const buffer = Memory.alloc(len + 1); call_v8_string_write_utf8(v8String, isolate, buffer, len); return buffer.readUtf8String(len); } / / JS string → V8 string function jsStringToV8String(isolate, utf8Ptr) { const maybeLocalBuffer = Memory.alloc(32); const v8Str = call_v8_new_string_from_utf8(maybeLocalBuffer,isolate, utf8Ptr); globalPtr.push(maybeLocalBuffer); / / Prevent garbage collection return v8Str; } The created memory references must be stored in a global array; otherwise, the V8 garbage collector may clear them before the compilation is complete.
[0032] Migrating to other applications only requires modifying two places: 1. Replace main.index.js with the actual main entry file name of the target application in the entry script file name (print sourceName first to observe).
[0033] 2. In applications where window loading is slow, increase the delay time.
[0034] Example 1 like Figure 1 As shown, this embodiment provides a method for forcibly enabling Electron application developer tools, including the following steps: S1. By using dynamic binary instrumentation technology, intercept the script compilation entry function of the V8 engine during the Electron application runtime to obtain the source code and script identification information of the script to be compiled. S2. Based on the script identification information, determine whether the script to be compiled is the main process entry script of the target application; if yes, proceed to step S3; if no, maintain the original compilation process of the script to be compiled and end the process. S3. In memory, the control code used to force the developer tools to be enabled is appended to the end of the original source code of the script to be compiled, generating the modified script source code, and the modified script source code is written back to the compilation pipeline of the V8 engine to replace the original source code for compilation and execution. S4. In response to the execution of the modified script source code, after the main window of the target application is loaded, the developer tools of the main window are forcibly opened through the Electron application programming interface, and the window is prevented from closing in response to a close request, so as to maintain the open state.
[0035] In this embodiment, preferably, in step S1, the dynamic binary instrumentation technology is implemented based on the Frida framework, and the script compilation entry function of the V8 engine is ScriptCompiler::CompileFunction; The interception is achieved by locating the exported symbol address of the ScriptCompiler::CompileFunction function in memory and setting an interception callback function at the function's entry point. Whenever the V8 engine compiles a script, the interception callback function is triggered and executed.
[0036] In this embodiment, preferably, step S2 specifically includes: Read the resource name field from the script source object of the V8 engine, and match the resource name field with the preset target entry script file name; If the match is successful, the script to be compiled is determined to be the main process entry script of the target application, and step S3 is continued; if the match fails, the script to be compiled is not modified, its original compilation process is maintained, and the process ends.
[0037] In this embodiment, preferably, step S3, which involves writing the modified script source code back to the V8 engine's compilation pipeline, specifically includes: The memory byte stream is converted into a V8 engine internal string object through the string manipulation application programming interface provided by the V8 engine, and written into the script source object, overwriting its original source code. Step S3 further includes: The memory pointers allocated in memory by the modified script source code are stored in a global reference array to prevent the V8 engine's garbage collection mechanism from reclaiming the memory area before compilation is complete.
[0038] In this embodiment, preferably, in step S4, the developer tool for forcibly opening the main window specifically includes: In response to the Electron application's app.whenReady event, all window instances of the target application are obtained through BrowserWindow.getAllWindows, and webContents.openDevTools({mode: 'detach'}) is called on the main window to open the developer tools in detached window mode.
[0039] In this embodiment, preferably, step S4, preventing it from closing in response to a close request, specifically includes: Save the original reference to the webContents.closeDevTools method of the main window, and replace the original method with an empty function; When the business code of the target application calls webContents.closeDevTools, the empty function is triggered, thereby silently intercepting the close request and keeping the developer tools open. It also includes step S5, registering a system-level global shortcut key through Electron's globalShortcut.register application programming interface; In response to the user's triggering of the global shortcut key, detect the current opening status of the developer tools; If the developer tools are open, the original reference is invoked to execute the webContents.closeDevTools method to close the developer tools; if the developer tools are closed, webContents.openDevTools({ mode: 'detach'}) is invoked to reopen the developer tools.
[0040] In this embodiment, preferably, the filename of the main process entry script of the target application is dynamically determined by printing the script resource name information compiled by the V8 engine during pre-run, in order to adapt to the naming differences of the main entry file of different Electron applications.
[0041] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.
[0042] Example 2 like Figure 2 As shown, this embodiment provides a device for forcibly enabling Electron application developer tools, including: The script compilation interception module uses dynamic binary instrumentation technology to intercept the script compilation entry function of the V8 engine during Electron application runtime, and obtain the source code and script identification information of the script to be compiled. The precise injection and positioning module determines whether the script to be compiled is the main process entry script of the target application based on the script identification information; if so, the source code dynamic modification module is executed; if not, the original compilation process of the script to be compiled is maintained and the process ends. The source code dynamic modification module appends the control code used to force the developer tools to be enabled to the end of the original source code of the script to be compiled in memory, generates the modified script source code, and writes the modified script source code back to the compilation pipeline of the V8 engine to replace the original source code for compilation and execution. The developer tools enable and protect module, in response to the execution of the modified script source code, after the main window of the target application is loaded, forcibly opens the developer tools of the main window through the Electron application programming interface and prevents it from closing in response to a close request, so as to maintain the open state.
[0043] In this embodiment, preferably, in the script compilation interception module, the dynamic binary instrumentation technology is implemented based on the Frida framework, and the script compilation entry function of the V8 engine is ScriptCompiler::CompileFunction; The interception is achieved by locating the exported symbol address of the ScriptCompiler::CompileFunction function in memory and setting an interception callback function at the function's entry point. Whenever the V8 engine compiles a script, the interception callback function is triggered and executed.
[0044] In this embodiment, preferably, the precise injection positioning module specifically includes: Read the resource name field from the script source object of the V8 engine, and match the resource name field with the preset target entry script file name; If the match is successful, the script to be compiled is determined to be the main process entry script of the target application, and the source code dynamic modification module continues to be executed; if the match fails, the script to be compiled is not modified, its original compilation process is maintained, and the step ends.
[0045] In this embodiment, preferably, the step of writing the modified script source code back to the V8 engine's compilation pipeline in the source code dynamic modification module specifically includes: The memory byte stream is converted into a V8 engine internal string object through the string manipulation application programming interface provided by the V8 engine, and written into the script source object, overwriting its original source code. The source code dynamic modification module also includes: The memory pointers allocated in memory by the modified script source code are stored in a global reference array to prevent the V8 engine's garbage collection mechanism from reclaiming the memory area before compilation is complete.
[0046] In this embodiment, preferably, in step S4, the developer tool for forcibly opening the main window specifically includes: In response to the Electron application's app.whenReady event, all window instances of the target application are obtained through BrowserWindow.getAllWindows, and webContents.openDevTools({mode: 'detach'}) is called on the main window to open the developer tools in detached window mode.
[0047] In this embodiment, preferably, the step of preventing the developer tools from closing in response to a close request in the developer tools enable and protection module specifically includes: Save the original reference to the webContents.closeDevTools method of the main window, and replace the original method with an empty function; When the business code of the target application calls webContents.closeDevTools, the empty function is triggered, thereby silently intercepting the close request and keeping the developer tools open. It also includes a shortcut key control module, which registers system-level global shortcut keys through Electron's globalShortcut.register application programming interface; In response to the user's triggering of the global shortcut key, detect the current opening status of the developer tools; If the developer tools are open, the original reference is invoked to execute the webContents.closeDevTools method to close the developer tools; if the developer tools are closed, webContents.openDevTools({ mode: 'detach'}) is invoked to reopen the developer tools.
[0048] In this embodiment, preferably, the filename of the main process entry script of the target application is dynamically determined by printing the script resource name information compiled by the V8 engine during pre-run, in order to adapt to the naming differences of the main entry file of different Electron applications.
[0049] Since the apparatus described in Embodiment 2 of the present invention is an apparatus used to implement the method of Embodiment 1 of the present invention, those skilled in the art can understand the specific structure and variations of the apparatus based on the method described in Embodiment 1 of the present invention, and therefore will not be described again here. All apparatuses used in the method of Embodiment 1 of the present invention fall within the scope of protection of the present invention.
[0050] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to Embodiment 1, as detailed in Embodiment 3.
[0051] Example 3 This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it can implement any of the implementation methods in Embodiment 1.
[0052] Since the electronic device described in this embodiment is the device used to implement the method in Embodiment 1 of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in Embodiment 1 of this application. Therefore, how the electronic device implements the method in the embodiment of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiment of this application falls within the scope of protection of this application.
[0053] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, as detailed in Embodiment 4.
[0054] Example 4 This embodiment provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it can implement any of the implementation methods in Embodiment 1.
[0055] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0056] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0057] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0058] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0059] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for forcibly enabling Electron application developer tools, characterized in that, Includes the following steps: S1. By using dynamic binary instrumentation technology, intercept the script compilation entry function of the V8 engine during the Electron application runtime to obtain the source code and script identification information of the script to be compiled. S2. Based on the script identification information, determine whether the script to be compiled is the main process entry script of the target application; if yes, proceed to step S3; if no, maintain the original compilation process of the script to be compiled and end the process. S3. In memory, the control code used to force the developer tools to be enabled is appended to the end of the original source code of the script to be compiled, generating the modified script source code, and the modified script source code is written back to the compilation pipeline of the V8 engine to replace the original source code for compilation and execution. S4. In response to the execution of the modified script source code, after the main window of the target application is loaded, the developer tools of the main window are forcibly opened through the Electron application programming interface, and the window is prevented from closing in response to a close request, so as to maintain the open state.
2. The method according to claim 1, characterized in that, In step S1, the dynamic binary instrumentation technology is implemented based on the Frida framework, and the script compilation entry function of the V8 engine is ScriptCompiler::CompileFunction. The interception is achieved by locating the exported symbol address of the ScriptCompiler::CompileFunction function in memory and setting an interception callback function at the function's entry point. Whenever the V8 engine compiles a script, the interception callback function is triggered and executed.
3. The method according to claim 1, characterized in that, Step S2 specifically includes: Read the resource name field from the script source object of the V8 engine, and perform string matching between the resource name field and the preset target entry script file name; If the match is successful, the script to be compiled is determined to be the main process entry script of the target application, and step S3 is continued; if the match fails, the script to be compiled is not modified, its original compilation process is maintained, and the process ends.
4. The method according to claim 1, characterized in that, In step S3, writing the modified script source code back to the V8 engine's compilation pipeline specifically includes: The memory byte stream is converted into a V8 engine internal string object through the string manipulation application programming interface provided by the V8 engine, and written into the script source object, overwriting its original source code. Step S3 further includes: The memory pointers allocated in memory by the modified script source code are stored in a global reference array to prevent the V8 engine's garbage collection mechanism from reclaiming the memory area before compilation is complete.
5. The method according to claim 1, characterized in that, In step S4, the developer tool for forcibly opening the main window specifically includes: In response to the Electron application's app.whenReady event, all window instances of the target application are obtained through BrowserWindow.getAllWindows, and webContents.openDevTools({ mode:'detach'}) is called on the main window to open the developer tools in detached window mode.
6. The method according to claim 1, characterized in that, In step S4, preventing it from closing in response to a close request specifically includes: Save the original reference to the webContents.closeDevTools method of the main window, and replace the original method with an empty function; When the business code of the target application calls webContents.closeDevTools, the empty function is triggered, thereby silently intercepting the close request and keeping the developer tools open. It also includes step S5, registering a system-level global shortcut key through Electron's globalShortcut.register application programming interface; In response to the user's triggering of the global shortcut key, detect the current opening status of the developer tools; If the developer tools are open, the original reference is invoked to execute the webContents.closeDevTools method to close the developer tools; if the developer tools are closed, webContents.openDevTools({ mode: 'detach'}) is invoked to reopen the developer tools.
7. The method according to claim 1, characterized in that, The filename of the main process entry script of the target application is dynamically determined by printing the script resource name information compiled by the V8 engine during pre-run, in order to adapt to the naming differences of the main entry file of different Electron applications.
8. A device for forcibly enabling Electron application developer tools, characterized in that, include: The script compilation interception module uses dynamic binary instrumentation technology to intercept the script compilation entry function of the V8 engine during the Electron application runtime, and obtains the source code and script identification information of the script to be compiled. The precise injection and positioning module determines whether the script to be compiled is the main process entry script of the target application based on the script identification information; if so, the source code dynamic modification module is executed; if not, the original compilation process of the script to be compiled is maintained and the process ends. The source code dynamic modification module appends the control code used to force the developer tools to be enabled to the end of the original source code of the script to be compiled in memory, generates the modified script source code, and writes the modified script source code back to the compilation pipeline of the V8 engine to replace the original source code for compilation and execution. The developer tools enable and protect module, in response to the execution of the modified script source code, after the main window of the target application is loaded, forcibly opens the developer tools of the main window through the Electron application programming interface and prevents it from closing in response to a close request, so as to maintain the open state.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.
