Posted on

Get signature info

Recently I had to verify the authenticity of digital signatures contained on APK files from system apps and .zip files belonging to OTA firmware updates of a specific android device. On Windows 10, all I had to do is use the unzip command together with the keytool command.

APK files:

Zip files:

As you can see, both commands are the same and can be used in different types of files – although an apk is basically a .zip file.

Posted on

Copy file from device system folder to PC (Windows)

Here’s a simple windows batch script that has the ability of copying a file from the device’s system folder to your desktop:

Just save the above text to a text file and rename the extension to .bat and execute.

Do not end the path to your PC with a back slash, it will not work.

Replace [system app name] with the remaining path to your system app and, replace [your username] with the remaining path to your desktop or, replace with some other path on your PC.

Tested on a rooted phone only.

That’s it!

Posted on

Change specific app internet speed

I developed an app for android with the purpose of controlling the daily internet quota assigned to the user and, for this to succeed, I was asked to slow down the internet speed of some apps like facebook, youtube, etc, while maintaining full speed to other apps critical for the device and business purposes. The main reason for this is that, if the user exceeds his daily quota of internet – about 1GB per day – the system should slow down internet speed for some apps while maintaining it for others. The purpose of slowing down some of the apps, is a way of telling the user to stop using them, at least until a new quota of 1GB is assigned to him – usually on demand or the next day.

All the searches related to traffic control lead me to two well known LINUX components: TC and IPTABLES. This is the “official” description of these components:

TC: Traffic control is the name given to the sets of queuing systems and mechanisms by which packets are received and transmitted on a router. This includes deciding which (and whether) packets to accept at what rate on the input of an interface and determining which packets to transmit in what order at what rate on the output of an interface.

IPTABLES: used to set up, maintain, and inspect the tables of IPv4 packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains. Each chain is a list of rules which can match a set of packets. Each rule specifies what to do with a packet that matches. This is called a `target’, which may be a jump to a user-defined chain in the same table.

In other words, with TC I can create a set of rules that define the “speed” at which bytes (packets) are received on the device and, with iptables I can define which users/processes use the rules defined with TC. This is a rough explanation of my needs and obviously, you can do much more with these components. We’re not event scratching the surface here!

I decided to do a test using the device’s wifi connection and so, this is the TC script I created:

The above script, basically creates a 20kbit limit on the wlan0 interface and, two classes that I will use with iptables. This 20kbit limit will be similar to a GSM data connection speed: slow and annoying.

Next, I had to get the name of the users associated with the running processes and, do a test with YouTube (one of the apps being blocked) so, to get all the details about YouTube’s process was very easy, just ran this adb shell command:

Which returned the following details:


The string with the value u0_a99 is the user android associated with YouTube’s process. Fortunately, android creates a user for each process or you might say, for each running app.

Creating the iptables script was fairly easy:

The above commands are very easy to explain. It appends this rule to the OUTPUT chain, the -o wlan0 defines the output wifi interface, the -m owner defines the module being used and it’s options and, the final -j section specifies the target TC class being used 1:10.

I also used ip6tables here because after doing a netstat on the device, all active connections are ip6, here’e the output:


After doing this proof of concept, it was easy to develop a java solution to apply these shell scripts to the running apps.

If you want to know more about iptables, here’s the man page:

Traffic control:

So…that’s it!


Posted on

Change Android preferred network mode using AT commands

I needed a solution on how to change the preferred network mode on KitKat and Lollipop devices and, I had the “luck” of only having to target two rooted Samsung devices from the Galaxy Grand series.

My initial search lead me to a lot of stack overflow posts that mainly described solutions using code reflection of methods belonging to class. None of these seemed to work on more recent android versions, even if installing the app on the android folder reserved for system apps: /system/priv-app/.

One of the first clues on stack overflow was this post:

Nothing worked either: not the reflection code on the post, the app from TheMasterBaron/Toggle-2G, nothing!

A more useful clue came from this xda post:

The post talked among many things, of a way to execute AT commands from windows to android. I used PuTTY, made a serial COM4 connection to the device and in a few seconds, I was executing all sorts of AT commands and getting all sorts of responses. This was great but, I still had no clue on how to execute these commands on the android device itself.


I started to search about AT commands and one of the first things you learn is that they are different from device to device because different devices use different modems, etc.

A quick query of both devices using the command AT+CLAC showed a different list of supported commands and, event more surprising, in devices from the same company and series. The devices are more or less one year apart from each other in terms of release dates.


I found a lot of documents regarding AT commands but, this one has many practical examples on how to use them:

The first thing I had to know, was how to change the preferred network mode on both devices and, all the documentation found online was really helpful. Using PuTTY, I managed to change the network mode from 4G to GSM by using the following commands:



All the network modes were easy to find by using the query version of the above commands, after changing between different network modes:


One of the first things you got to search about, is what serial port does the modem uses: it’s on this serial port that all AT commands will be executed and all responses will be there also.

The initial search lead me to the ports ttyGS0 and smd0. The port smd0 seemed to work on KitKat and, by using this shell command I received my first OK response from android:

But, the happiness didn’t last long, I still had no clue on what port Lollipop was using so, I decided to use brute force, and executed ls /dev/ which returned a bunch of folders representing block/character devices. More info on this subject, here. I counted more or less 750 folders and, one of these folders, contained my serial port! All I had to do was find it! How? well, simple, just test them all in a simple way by trying to change the network mode, like this:


I did a search by blocks of 40 sequential commands from the 750 and almost at the end, eureka! The network mode changed! I found two serial ports that responded to the AT commands! These were the ones that did it:

The final version of the commands on both android versions, which changed the network mode from the default 4G to GSM:



So, that’s it, I hope this helps someone.