In today’s tutorial, we’ll show you how to hack a published Ubuntu Core application. This method is especially useful for hacking applications that have already been published in the Ubuntu Core store.

\

Recently, I wanted to port an application called vtop on Ubuntu Desktop to our Ubuntu Core Dragonboard. Vtop is a great application that shows the resources of your application in Ubuntu:

\

We can install it on our Ubuntu Desktop using the following commands:

$ sudo snap install vtop
Copy the code

We do not use any channel options here, indicating that it is installed from our Stable Channel. There are no safety issues. We can directly type the following command in terminal:

$ vtop
Copy the code

You can run the application.

To get the same app, I also tried to create the same app using the following snapcraft. Yaml file:

snapcraft.yaml

name: v-top # you probably want to 'snapcraft register <name>1. 'version: '1' # task This is a snap for vtop # 79 char long summary description: | This is vtop. More info can be found at https://parall.ax/vtop grade: stable # must be 'stable' to release into candidate/stable channels confinement: strict # use 'strict' once you have the right plugs and slots apps: v-top: command: bin/vtop plugs: [home, network, system-observe, process-control,network-bind] parts: vtop: # See 'snapcraft plugins' plugin: Nodejs source: https://github.com/MrRio/vtop source - type: git node - engine: 6.9.2Copy the code

The snapcraft. Yaml file is very simple. After we packed, we found that the application could only be installed in DevMode, otherwise there would be some problems, such as:

\

liuxg@liuxg:~/snappy/desktop/vtop2$ v-top TypeError: Cannot read property 'replace' of undefined at child.exec (/snap/v-top/x1/lib/node_modules/vtop/sensors/memory.js:45:43)  at ChildProcess.exithandler (child_process.js:213:5) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at maybeClose (internal/child_process.js:877:16) at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:498:12)
Copy the code

So where do we go wrong? Apparently it appears in the latest release github.com/MrRio/vtop. This newly released software contains some code that doesn’t allow us to package snap. To solve this problem, I came up with vtop, which is already available in our Ubuntu Core store. I performed the following operations:

\

Create a directory, such as TMP, and go to our directory:

\

$ snap download vtop
Copy the code

To download the vtop app from the store, run the following command:

\

liuxg@liuxg:~/tmp$ ls
vtop_1.snap
Copy the code

\

Obviously we’ve downloaded the VTop app that was released to our store. Next, we use the following command:

\

liuxg@liuxg:~/tmp$ unsquashfs vtop_1.snap 
Parallel unsquashfs: Using 4 processors
2205 inodes (2419 blocks) to write

[=================================================================================/] 2419/2419 100%

created 2202 files
created 483 directories
created 3 symlinks
created 0 devices
created 0 fifos
liuxg@liuxg:~/tmp$ ls
squashfs-root  vtop_1.snap
Copy the code

\

So in our current application, we found a directory created for squashfs-root. All of the files in this directory are the ones we eventually installed on the Ubuntu Core system. We can hack the squashfs-root files any way we want and then re-pack them as follows: If we don’t make any changes at this point, we can repackage the file as a snap file using the following command:

\

Liuxg @ liuxg: ~ / TMP $snapcraft snap squashfs - root/Snapping 'vtop | Snapped vtop_1. 0.1 _amd64. Snap liuxg @ liuxg: $ls ~ / TMP Squashfs - root vtop_1. 0.1 _amd64. Snap vtop_1. The snapCopy the code

\

Of course, this is not our ultimate goal. Our goal is to be able to release the same application to Ubuntu Core. To do this, we go to the folder we have expanded:

\

liuxg@liuxg:~/tmp$ cd squashfs-root/ liuxg@liuxg:~/tmp/squashfs-root$ ls bin CHANGELOG.md command-vtop.wrapper etc include lib LICENSE meta README.md share liuxg@liuxg:~/tmp/squashfs-root$ cd bin/ liuxg@liuxg:~/tmp/squashfs-root/bin$ Ls node NPM vtop liuxg@liuxg:~/ TMP /squashfs-root/bin$./node --version v4.2.2Copy the code

\

First, we found that the nodeJS version in this package is 4.2.2. This information is important. In our Snap package application, we can specify any Python or NodeJS version. In our case, we want the nodeJS version to be the same as the original in the final version so that it doesn’t cause security issues. In addition, we also enter another directory:

\

liuxg@liuxg:~/tmp/squashfs-root/lib/node_modules$ ls
npm  vtop
Copy the code

Here, we can see that all of our code to run our vtop is stored in a directory called vtop:

\

liuxg@liuxg:~/tmp/squashfs-root/lib/node_modules$ ls vtop
app.js  CHANGELOG.md  LICENSE   node_modules  README.md  themes
bin     docs          Makefile  package.json  sensors    upgrade.js
Copy the code

No matter how it was formed in the original application, it was definitely defined as a part called VTOP. We need the software for this part. We can check the files in this directory into our packaged files:

\

liuxg@liuxg:~/snappy/desktop/vtop$ ls
snapcraft.yaml  vtop
Copy the code

For example, in the project we created above, we copied the entire vTOP directory into our project. Meanwhile, the contents of our snapcraft. Yaml are as follows:

\

name: v-top # you probably want to 'snapcraft register <name>1. 'version: '1' # task This is a snap for vtop # 79 char long summary description: | This is vtop. More info can be found at https://parall.ax/vtop grade: stable # must be 'stable' to release into candidate/stable channels confinement: strict # use 'strict' once you have the right plugs and slots apps: v-top: command: bin/vtop plugs: [system-observe] parts: vTOP: # See 'snapcraft plugins' plugin: nodejs source:./vtop node-engine: 4.2.2Copy the code

Here we also specify the same NodeJS version 4.2.2 as before. When we repackage our application, we find that it works exactly as the original application and does not require DevMode when it is installed. We can also check the snap.yaml file in the meta file directory and find the corresponding Plug System-observe required. Of course, in this case, the Plug doesn’t seem to work just fine.

\

So how does such an app install on QualComm’s DragOnboard?

\

We can install the article “How to Install Ubuntu Core for Raspberry PI and Compile it in Snap” to pack our V-Top app on The Dragonboard, and we’ll end up running exactly as we did on Ubuntu Destop, and it doesn’t require DevMode.

\

\

\

As you can see from the image above, the V-Top application is successfully installed and devMode is not required.

\

\

The entire project source at: github.com/liu-xiao-gu…

$sudo snap Install V-top $sudo Snap install V-top $sudo Snap Install V-top

\

\

\

\

\