215

I have packed my Electron application using the following command:

asar pack app app.asar

Now, I need to unpack it and get the whole code back. Is there any way to do so?

Pang
  • 9,564
  • 146
  • 81
  • 122
Vikas Bansal
  • 10,662
  • 14
  • 58
  • 100

2 Answers2

358

From the asar documentation

(the use of npx here is to avoid to install the asar tool globally with npm install -g asar)

Extract the whole archive:

npx asar extract app.asar <destfolder>

Extract a particular file:

npx asar extract-file app.asar main.js
anurupr
  • 2,294
  • 2
  • 20
  • 28
martpie
  • 5,510
  • 1
  • 21
  • 25
  • 2
    worked fine when run with sudo. Thanks for the answer, you are a life saver :) – Vikas Bansal Jul 22 '16 at 11:06
  • 48
    The [electron docs](https://github.com/electron/electron/blob/master/docs/tutorial/application-distribution.md#packaging-your-app-into-a-file) say: "you can also package your app into an asar archive to avoid exposing your app's source code to users." but it is not true if you are then able to unpack it? right?? – neoDev Dec 10 '16 at 13:21
  • 1
    @neoDev there's no real way to completely avoid exposing your code. But you can obfuscate it as much as you can with Asar, closure tools, etc... – martpie Dec 19 '16 at 09:15
  • 11
    Side note: you can install the command with `npm install -g asar`. – Mike Chamberlain Apr 02 '17 at 09:16
  • 11
    Ok, how do you unpack a asar file *without* having to install the entire node development environment? – Fake Name May 19 '17 at 01:16
  • @FakeName In theory, you only need node.exe and asar's [source code](https://github.com/electron/asar), but npm will install all dependencies needed – Bernardo Dal Corno Aug 15 '17 at 20:04
  • 1
    It is a tool for Node.js written in JS. You will need a JS engine with file access, in other words Node. https://github.com/electron/asar/tree/master/bin – martpie Aug 15 '17 at 20:48
  • 38
    @FakeName - I used the 7Zip plugin found in this thread at the 7Zip project: https://sourceforge.net/p/sevenzip/discussion/45797/thread/74cf1dec/ Allows one to open any ASAR file in 7Zip. – MayaPosch Dec 02 '17 at 13:23
  • 1
    here is the link to the 7zip asar plugin: https://www.tc4shell.com/en/7zip/asar/ – TmTron May 15 '21 at 13:51
  • 1
    Hey this answer literally shows in google, any chance you can change the answer to say `npx asar extract app.asar app.asar.unpacked` as that's probably what users are going to be doing – Alice Feb 12 '22 at 21:14
  • One just needs to install Node (https://nodejs.org/) in order to be able to run this command. It is light to install (28 MB). – Wok Apr 04 '22 at 08:51
  • By the way, as mentioned in the first comment, you will need admin rights, and access to Internet to download `asar`. – Wok Apr 04 '22 at 09:02
  • @neoDev yes, you're right. But it does give an extra level of security to your source code, since not everyone will go to the trouble of going through the unpacking process. – Xavier Mukodi Apr 19 '22 at 13:52
  • This crashes with `TypeError: Cannot read properties of undefined (reading 'link')`. – Coder Guy Aug 23 '22 at 15:26
73

It is possible to upack without node installed using the following 7-Zip plugin:
http://www.tc4shell.com/en/7zip/asar/

Thanks @MayaPosch for mentioning that in this comment.

Pang
  • 9,564
  • 146
  • 81
  • 122
Sebastian Ax
  • 1,240
  • 12
  • 11
  • This does not seem to work for my use case. I have tried the plugin with both 7-Zip 21.07 (2021-12-26) and 7-Zip 19.00 (2019-02-21), as the plugin was last released in version 1.2 on 2020-03-05. Everything in 64-bit. – Wok Apr 04 '22 at 07:43
  • Also with 7-Zip 16.04 (2016-10-04). In every attempt, I get an "unspecified error". – Wok Apr 04 '22 at 07:51
  • Investigating at https://github.com/electron/asar/issues/110 as well. – Wok Apr 04 '22 at 07:57