Quantcast
Channel: Delphi Forum - Delphi Programming Kings of Code - Delphi Android And IOS
Viewing all articles
Browse latest Browse all 54

Touching the root

$
0
0
Probably for the most of situations your application will not require root access to the system. But, who knows why, sometimes you maybe need it. When developing my new application someone asked for a special feature: save the WiFi password which you are connected to. Well, you can get some of the wireless SSID infomation by calling the correct API functions, but not the password. The password is, so far,  storaged into the wpa_supplicant.conf file and to have access to it you will need root privileges. Of course someone can simple type in the password and it’s done.So, for this case, more than run away from the solution I was curious in how could I get root access from my application. After dinging a while I got a solution by watching a You can't view the links! Click here to register video from “Marijsoft sviluppo software”, that he was kind for provide new links for the source code, that I tested on XE8 and DX Seattle and worked as expected.By reading the files (Androidapi.JNI.Runtime, Androidapi.JNI.Stream2and FMX.Android.Runtime) we will discover that source belongs to 天轶_黄金 SmileI needed to do a little fix on it (?) so I was able to make it work as I expected. I guess someone else can really improve this code, but for my purpose it is enough now. You can download the required files You can't view the links! Click here to register (fixed by me), and the original one You can't view the links! Click here to register (while it exists there). Basically you will find 2 functions:
  • HaveRoot():boolean
  • RunAndroidCmd(string, boolean, TStrings)
The first will invoke an internal attempt to run “su” and returning true if success. The second one you could use to reboot the device, if you want, example: RunAndroidCmd(‘su’ + sLineBreak + ‘reboot’, true). This command function will allow you run any Android linux compatible commands, such chmod, rm, kill applications etc., so you can use it to make a party on your device, so be careful.İmage
You can't view the links! Click here to register. Once allowed by SuperSu, my application can have root access. Here I made a simple program to read the wpa_supplicant.conf(Memo1.Lines.ReadFromFile(<fullfilename> was enough) and voilà!

İmage
At this point you application can handle the device with root privileges and now can manipulate whatever you want. Does I told you to be careful already?

 

 

Viewing all articles
Browse latest Browse all 54

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>