question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hook for after electron.exe has completely finished being modified

See original GitHub issue
  • Version: 20.22.0

  • Target: Windows

Description: Once Electron builder has finished modifying electron.exe into its final form I would like to apply some changes to the exe manually myself before it is code signed.

Currently I am carrying out these changes in the afterPack hook, however I think further changes to the exe are taking place by (or a dependency of) electron-builder after this hook has been triggered. I am assuming this because the final .exe file is corrupt and crashes with an Access Violation error.

If I move my .exe modifications a bit later in the build process (e.g. either by dumping them in the custom Windows code signing override/delegate function; or by running them manually after electron builder has completely finished) the .exe works as expected which points to electron-builder doing something to the .exe after the afterPack hook and before the code signing takes place. I have tried looking through the code but I cannot work out what changes take place in this timeframe.

As I would like to make use of the electron-builder code-signing functionality, I do not want to override the custom sign function and also cannot make my modifications after electron-builder has finished and the code has been signed. This means I need to try find (or implement) an alternative hook to carry out my tasks after the exe has been completely finished, but before the code signing takes place.

To help me with this, I have a few questions if anyone can give some guidance that would be fantastic:

  • Does something happen to the .exe after afterPack or am I going down a rabbit hole? I had assumed at this stage the binary was completely finished but it doesn’t seem that way.
  • Is there any other kind of hook I could hook into that represents “after the .exe is completely finished and won’t be touched again until code-signing”? I have obviously looked at the docs and not found one, but just wanted to ask incase anyone had any ideas or if I have missed something!
  • If there isn’t such a hook, would you consider accepting a PR to implement one? E.g. maybe preCodeSign or afterPackFinalised? Obviously once I find out what (if anything) is happening to the exe after afterPack it would be easier to come up with a afterX hook name.

Just for the sake of completeness, I am making similar modifications to the Electron framework binary for OSX, however it doesn’t seem to suffer from this same issue and executing the changes from the afterPack hook is working.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
amfiocommented, Jul 23, 2019

afterSign unfortunately does not meet my needs, I need to carry out a task after the exe is in its final form but before code signing takes place. Effectively my hacked solution to this problem was to override the signing functionality but to then invoke the original signing function, e.g:

import * as windowsCodeSign from '../node_modules/electron-builder-lib/out/windowsCodeSign';
const originalSignFunction = windowsCodeSign.sign;

windowsCodeSign.sign = function(options) {
    const signFunctionContext = this;
    const signFunctionArgs = arguments;

    return doMyPostExeFunction().then(() => {
        return originalSignFunction.apply(signFunctionContext, signFunctionArgs);
    });
};

There is no longer active development on the app I required the functionally for, but I still think a hook for preSign to carry out tasks immediately before the signing process makes sense - or at least making it so that afterPack is truly after everything is done (e.g. after the .exe has been modified using rcedit). Obviously I am happy to submit a PR for this, I was just originally looking for clarification as to why additional modifications were taking place between the afterPack and the code signing process.

0reactions
develarcommented, Nov 27, 2018

@amfio Please use afterSign hook.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Electron Compiled EXE Not working as expected
I've been trying to "package" my Electron Application, using the below script, however when the .exe is created and I try to run...
Read more >
Common Configuration - electron-builder
Type is specified after property name: Array<String> | String . ... The function (or path to file or module id) to be run...
Read more >
app | Electron
Emitted when the application has finished basic startup. On Windows and Linux, the will-finish-launching event is the same as the ready event; on...
Read more >
Decompiling and repacking Electron Apps | by Cristian Deleon
Usually Electron apps are glorified web front ends that are… ... root App component where an “Ad” component was being imported and just...
Read more >
Build an Electron App in Under 60 Minutes - YouTube
In this video we will build a desktop application using Electron.js which allows us to build desktop apps using only JavaScript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found