How to unpack an .asar file?
Asked Answered
G

2

230

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?

Grillage answered 22/7, 2016 at 10:3 Comment(0)
S
381

From the asar documentation

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

Extract the whole archive:

npx @electron/asar extract app.asar <destfolder>

Extract a particular file:

npx @electron/asar extract-file app.asar main.js
Scapula answered 22/7, 2016 at 10:47 Comment(14)
worked fine when run with sudo. Thanks for the answer, you are a life saver :)Grillage
The electron docs 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??Rataplan
@Rataplan 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...Scapula
Side note: you can install the command with npm install -g asar.Ambush
Ok, how do you unpack a asar file without having to install the entire node development environment?Beatrice
@FakeName In theory, you only need node.exe and asar's source code, but npm will install all dependencies neededIncurvate
It is a tool for Node.js written in JS. You will need a JS engine with file access, in other words Node. github.com/electron/asar/tree/master/binScapula
@FakeName - I used the 7Zip plugin found in this thread at the 7Zip project: sourceforge.net/p/sevenzip/discussion/45797/thread/74cf1dec Allows one to open any ASAR file in 7Zip.Convergence
here is the link to the 7zip asar plugin: tc4shell.com/en/7zip/asarMaxim
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 doingRecollect
One just needs to install Node (nodejs.org) in order to be able to run this command. It is light to install (28 MB).Fetial
By the way, as mentioned in the first comment, you will need admin rights, and access to Internet to download asar.Fetial
@Rataplan 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.Halle
This crashes with TypeError: Cannot read properties of undefined (reading 'link').Wenz
E
78

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.

Eosin answered 28/10, 2018 at 11:2 Comment(4)
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.Fetial
Also with 7-Zip 16.04 (2016-10-04). In every attempt, I get an "unspecified error".Fetial
Investigating at github.com/electron/asar/issues/110 as well.Fetial
Asar.64.dll v1.4 (28 Nov 2022, latest from tc4shell.com/en/7zip/asar) works perfectly with 7-Zip 23.01 (x64): just copy Asar.64.dll into the "7-zip\Formats" subfolder as well with the Total7zip pluging of Total Commander (just copy the same dll into totalcmd\plugins\wcx\Total7zip\64\Codecs)Tatiana

© 2022 - 2024 — McMap. All rights reserved.