How to modify the oscilloscope application.
This application is a standard application for Android, so all the methods of working with it are no different from the methods of working with any other application for Android. I will describe the process under Windows, but under Linux everything will be almost the same, all tools are available for Linux.
What programs will you need:
apktool -
https://github.com/iBotPeaches/Apktool - a utility for unpacking and packing an .apk application. It unpacks the application into the individual files that make up the application. Requires Java (JRE) installed on the system.
zipalign - a utility included in Android build-tools (
https://developer.android.com/tools). Aligns the contents of the .apk after it has been packaged. I didn’t find how to download build-tools separately, so I downloaded and installed the full Android Studio, which also includes build-tools.
keytool - a utility from the Java SDK (
https://www.oracle.com/cis/java/technologies/downloads/) for creating a key storage with which you will sign the application.
jarsigner a utility from the Java SDK (
https://www.oracle.com/cis/java/technologies/downloads/) for signing applications with keys from the key store, which was created by the keytool utility.
adb a utility included in the Android platform-tools (
https://developer.android.com/tools/releases/platform-tools) for working with Android devices connected via a local network or USB.
jadx -
https://github.com/skylot/jadx - a utility for decompiling an application into Java source codes. Select and download the "jadx-gui with bundled JRE" option.
apktool and
jadx are downloaded from github, they do not need installation.
If you download and install
Android Studio (
https://developer.android.com/studio), then all other utilities (except
apktool and
jadx) will already be included. After downloading and installing, make sure that the path to Java is specified in the environment variables - try typing in the command line
java
and press Enter. You should see java help with a description of the parameters and commands.
In the same way, check the availability of
keytool and
jarsigner.
So, everything has been downloaded and installed, you can start unpacking the application.
Create a separate directory for working with the application. For example, the path would be the "
SparrowWork" directory. Copy the application file (Sparrow.apk),
apktool (apktool_2.9.3.jar in the current version), and
zipalign (zipalign.exe from the Android SDK, it should be located in the Android SDK installation directory, in one of the subdirectories) to this directory ). It is better to rename the original application file, for example to
Sparrow_orig.apk.
Go to this directory and open a command prompt in it.
First you need to create a key store, with which you will then sign the application after assembly. This is done only once before the first assembly; there is no need to repeat this in the future. The key store is created with the command:
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Here “
my-release-key” is the name of the key store being created; you can substitute any other name, which you will then put in the signing command. "
alias_name" is the name of the key, you can also replace it with any other, which you can then substitute in the signing command.
After launching, the program will ask you for various data - name, organization, city, etc. - you can write whatever you want. In addition, it will ask for a password for the vault, you will need to come up with it and remember it, it will be needed for the signing command.
Now extract the application into a separate directory using the command:
java -jar apktool_2.9.3.jar d Sparrow_orig.apk -o Sparrow_unpack
You should have a subdirectory "Sparrow_unpack" in your directory, which will contain all the contents of the application in its original form. In principle, here you can already start editing application files. For example, the "Sparrow_unpack/res" directory will contain all application resources - images, .xml files with texts, parameters, screen layout, etc. In the directory "Sparrow_unpack/smali" and "Sparrow_unpack/smali_classes2" there will be .smali files with source codes in the DALVIK language - this is something like an assembler for Java.
If you want to get source codes in Java, then run the downloaded and unpacked jadx utility (jadx-gui-1.4.7.exe for the current version). In it, open the application file Sparrow_orig.apk and wait until the analysis and decompilation is completed. Now you can view all source codes directly in this program - it has a fairly convenient source viewer. You can save the result as a project - File -> Save as gradle project in a separate subdirectory, then all source java files will be available at any time in this directory, you can open them in your favorite editor.
Warning: You will not be able to compile the application back from the decompiled java files, they are only intended to help you understand the contents of the .smali files. Each .java file will correspond to a .smali file with the same name and in the same subdirectory.
All changes are made to files in the directory into which the application was unpacked using the
apktool utility. In the example, this is the
Sparrow_unpack directory. The application will be built from this directory after all changes.
Okay, you've changed what you wanted, now you need to put the application back together.
The assembly is done with the command:
java -jar apktool_2.9.3.jar b -o Sparrow_unalign.apk Sparrow_unpak
Here
Sparrow_unalign.apk is the name of the application that will be created,
Sparrow_unpack is the directory from which the files for the build are taken.
If no errors are found after the changes, the
Sparrow_unalign.apk file will appear in the current directory. Now you need to align the contents of the application with the command:
zipalign.exe 4 Sparrow_unalign.apk Sparrow.apk
As a result, a
Sparrow.apk file will be created, with all its contents aligned and almost ready for installation. All that remains is to sign it with the command:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore -storepass 123456 Sparrow.apk alias_name
Here you specify "
my-release-key" - the name of the key store you created, "
123456" - the password and "
alias_name" - the password and key name that you specified when creating the key store.
That's it, now the
Sparrow.apk application is completely ready for installation.
About the installation. From the factory, the oscilloscope application is installed as a system application, so simply replacing it with your own modified one will not work. You must first remove the original version. Don't worry - you can always install the original application back. You made a copy of it just in case, didn’t you?
If on your system the path to the directory with the
adb utility is included in the environment variables and the
adb command can be executed from anywhere, then you can continue working in the current directory. Otherwise, copy the resulting
Sparrow.apk application to the directory with adb and launch the command line there.
On the command line, type the command:
adb connect 192.168.1.171:55555
Where
192.168.1.171 replace with the IP address of your oscilloscope. The oscilloscope must be turned on and accessible via the local network.
After that, type the command:
adb uninstall com.rigol.scope
After a second or two, the application should disappear from the oscilloscope screen and the message “
Success” will appear in the terminal.
Install your application:
adb install -g -r Sparrow.apk
The process takes quite a long time, almost a minute, so don't worry about everything getting stuck. When finished, a “
Success” message should appear and within a few seconds the oscilloscope application should automatically launch.
If your modified application is already installed on the oscilloscope and you reinstall it after the next modification, then there is no need for a separate command to remove the old application. You can immediately issue the installation command:
adb install -g -r Sparrow.apk
That's it, your modified application is installed
There is only one point: your application cannot be a system one, because it is signed with the wrong key. One of the noticed negative consequences of this is the inability to take screenshots directly on the oscilloscope. But they can be done via web control. It is possible to make a modified application a system one, but there will be a separate post about this later.
P.S. I'm not a real Android app modder, and I've described here what I've learned and tried over the past few days, so there may be inaccuracies in my description. Maybe someone more experienced will correct me at some points