How to unpack an .asar file?

197,933

Solution 1

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

Solution 2

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.

Share:
197,933

Related videos on Youtube

Vikas Bansal
Author by

Vikas Bansal

javascript, typescript, ReactJs, Angularjs, Nodejs, Electronjs.... waiting for the next :) :P :D

Updated on May 01, 2021

Comments

  • Vikas Bansal
    Vikas Bansal over 1 year

    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?

  • Vikas Bansal
    Vikas Bansal over 6 years
    worked fine when run with sudo. Thanks for the answer, you are a life saver :)
  • neoDev almost 6 years
    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??
  • martpie
    martpie almost 6 years
    @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...
  • Mike Chamberlain
    Mike Chamberlain over 5 years
    Side note: you can install the command with npm install -g asar.
  • Fake Name
    Fake Name over 5 years
    Ok, how do you unpack a asar file without having to install the entire node development environment?
  • Bernardo Dal Corno
    Bernardo Dal Corno over 5 years
    @FakeName In theory, you only need node.exe and asar's source code, but npm will install all dependencies needed
  • martpie
    martpie over 5 years
    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/bin
  • MayaPosch almost 5 years
    @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.
  • TmTron
    TmTron over 1 year
    here is the link to the 7zip asar plugin: tc4shell.com/en/7zip/asar
  • Alice
    Alice 10 months
    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
  • Wok
    Wok 8 months
    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
    Wok 8 months
    Also with 7-Zip 16.04 (2016-10-04). In every attempt, I get an "unspecified error".
  • Wok
    Wok 8 months
    Investigating at github.com/electron/asar/issues/110 as well.
  • Wok
    Wok 8 months
    One just needs to install Node (nodejs.org) in order to be able to run this command. It is light to install (28 MB).
  • Wok
    Wok 8 months
    By the way, as mentioned in the first comment, you will need admin rights, and access to Internet to download asar.
  • Xavier Mukodi
    Xavier Mukodi 8 months
    @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.