Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Windows: can't edit EXE's resources with tools like rcedit #149

Closed
jviotti opened this issue Jun 26, 2017 · 8 comments
Closed

Windows: can't edit EXE's resources with tools like rcedit #149

jviotti opened this issue Jun 26, 2017 · 8 comments
Labels

Comments

@jviotti
Copy link

jviotti commented Jun 26, 2017

I wonder if this is related to #128.

Looks like I can't brand pkg generated binaries with rcedit.

For example:

> rcedit.exe etcher.exe --set-version-string "FileDescription" "Foo"
Fatal error: Unable to change version string

> rcedit.exe etcher.exe --set-file-version "1.0.0"
Fatal error: Unable to change file version
jviotti added a commit to balena-io/etcher that referenced this issue Jun 30, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jun 30, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 3, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 4, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 4, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 6, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 6, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 7, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 7, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 7, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 10, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 10, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 11, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit to balena-io/etcher that referenced this issue Jul 11, 2017
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Fixes: #1531
Fixes: #1450
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@dsole
Copy link

dsole commented Aug 31, 2017

I have a working (manual) solution that might help. I've been using this to get the version metadata into the exe that Squirrel/Windows looks for.
I use Resource Hacker but Im sure other tools can do the job.

This is what I do :

1. Compile the executable
pkg --targets node6-win-x86 index.js -o index.exe

2. Compile the VERSION INFO resource definition file to binary format
I then use ResourceHacker to compile a plain-text .rc file to a binary .res format
( You might not need to do this if you already have a .res file )
"C:\Program Files (x86)\Resource Hacker\ResourceHacker.exe" -open version-info.rc -action compile -save version-info.res

3. Import the VERSION INFO resource into the exe
"C:\Program Files (x86)\Resource Hacker\ResourceHacker.exe" -open index.exe -resource version-info.res -action add -save index-output.exe

That creates index-output.exe with the VERSION INFO resource added.

Here's an example of the plain text .rc file used in step 2 ( version-info.rc )

1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x40004
FILETYPE 0x1
{
BLOCK "StringFileInfo"
{
    BLOCK "040904b0"
    {
        VALUE "FileDescription", "Version info test"
        VALUE "FileVersion", "1.0.0"
        VALUE "InternalName", "index.exe"
        VALUE "LegalCopyright", "Copyright (C) 2017"
        VALUE "OriginalFilename", "index.exe"
        VALUE "ProductName", "Version info test"
        VALUE "ProductVersion", "1.0.0"
        VALUE "SquirrelAwareVersion", "1"
    }
}

BLOCK "VarFileInfo"
{
	VALUE "Translation", 0x0409 0x04B0  
}
}

@mmamedel
Copy link

mmamedel commented Apr 7, 2021

I had a similar need to change the EXE's resources and I wanted to use a simple tool like rcedit.
As you will see in the code below a lot can be done in different ways, but the spirit behind this solution is:

  1. Download cache with pkg-fetch
  2. Edit cache with rcedit
  3. Use cache in pkg

Here is my typescript code:

import rcedit from 'rcedit'
import glob from 'glob'
import path from 'path'

process.env.PKG_CACHE_PATH = path.resolve('./.pkg-cache')
build()

async function build() {
  const pkgTarget = 'node14-win-x64'
  const cacheExe = await downloadCache(pkgTarget)

  await rcedit(cacheExe, {
    'product-version': '1,0.0.0',
    'file-version': '1,0.0.0',
    icon: path.resolve('./src/assets/icon.ico'),
    'version-string': {
      FileDescription: 'File description',
      ProductName: 'Program Name',
      LegalCopyright: ${new Date().getFullYear()} My Copyright.`,
      OriginalFilename: 'program.exe',
    },
  })

  const pkg = await import('pkg')
  const outputExe = path.resolve('./dist/output.exe')
  await pkg.exec([path.resolve('./dist/app.js'), ...['--target', pkgTarget], ...['--output', outputExe]])
}

async function downloadCache(pkgTarget: string): Promise<string> {
  const [nodeRange, platform, arch] = pkgTarget.split('-')
  const pkgFetch = await import('pkg-fetch')
  await pkgFetch.need({ nodeRange, platform, arch })
  const cacheExe = glob.sync(`${PKG_CACHE_PATH}/**/fetched*`)
  if (cacheExe.length < 1) throw new Error('Error downloading PKG cache')

  return cacheExe[0]
}

@github-actions
Copy link

github-actions bot commented Jul 7, 2021

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

@github-actions github-actions bot added Stale and removed Stale labels Jul 7, 2021
@jviotti
Copy link
Author

jviotti commented Jul 12, 2021

I haven't tried this myself, but does anybody know if using rc.exe with a corresponding .rc file instead of rcedit.exe works fine? If so, it would indicate a problem with rcedit.exe rather than with this project.

@gcatto
Copy link

gcatto commented Sep 27, 2021

I have been trying to get @mmamedel 's script working for me, but no luck so far as it does not change the exe. I've tried applying https://github.com/vercel/pkg-fetch/issues/188 as well, but either way, the fetched- or built- file still has the original file definitions and then so does the output exe.

I am using CommonJS and require() instead of ES modules for this, but otherwise, but script is basically the same as the @mmamedel one above. Are other folks having issues or success?

I am on pkg@5.3.2 and pkg-fetch@3.2.3

@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

@github-actions github-actions bot added the Stale label Dec 27, 2021
@github-actions
Copy link

github-actions bot commented Jan 2, 2022

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.

@github-actions github-actions bot closed this as completed Jan 2, 2022
@xenois
Copy link

xenois commented Jan 11, 2022

I had a similar need to change the EXE's resources and I wanted to use a simple tool like rcedit. As you will see in the code below a lot can be done in different ways, but the spirit behind this solution is:

  1. Download cache with pkg-fetch
  2. Edit cache with rcedit
  3. Use cache in pkg

Here is my typescript code:

import rcedit from 'rcedit'
import glob from 'glob'
import path from 'path'

process.env.PKG_CACHE_PATH = path.resolve('./.pkg-cache')
build()

async function build() {
  const pkgTarget = 'node14-win-x64'
  const cacheExe = await downloadCache(pkgTarget)

  await rcedit(cacheExe, {
    'product-version': '1,0.0.0',
    'file-version': '1,0.0.0',
    icon: path.resolve('./src/assets/icon.ico'),
    'version-string': {
      FileDescription: 'File description',
      ProductName: 'Program Name',
      LegalCopyright: ${new Date().getFullYear()} My Copyright.`,
      OriginalFilename: 'program.exe',
    },
  })

  const pkg = await import('pkg')
  const outputExe = path.resolve('./dist/output.exe')
  await pkg.exec([path.resolve('./dist/app.js'), ...['--target', pkgTarget], ...['--output', outputExe]])
}

async function downloadCache(pkgTarget: string): Promise<string> {
  const [nodeRange, platform, arch] = pkgTarget.split('-')
  const pkgFetch = await import('pkg-fetch')
  await pkgFetch.need({ nodeRange, platform, arch })
  const cacheExe = glob.sync(`${PKG_CACHE_PATH}/**/fetched*`)
  if (cacheExe.length < 1) throw new Error('Error downloading PKG cache')

  return cacheExe[0]
}

This will not work, as pgk-fetch will check EXPECTED_HASHES and rejects the binary if it does not match the hardcoded hash. You can hack the pgk-fetch in the node_modules, but that sucks as its .gitignored. The only "clean" solution is to work with a custom pkg (instead of npm install pgk) and do there the rcedit magic as explained above.

@jesec jesec mentioned this issue Jun 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants