1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Touching the root

Discussion in 'Delphi Android And IOS' started by AdminDF, Oct 26, 2015.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    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 Youtube 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 天轶_黄金 :)I 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 here (fixed by me), and the original one here (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.[​IMG]
    And so, when I need to read the Wifi password I should check first for root (HaveRoot()) and my SuperSU or equivalent will ask permission for my application gain root access. 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à!

    [​IMG]
    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?

     

     
     
  2. izaquemaciel
    Online

    izaquemaciel DF Junior

    Wonderful!
     
  3. Mpas
    Offline

    Mpas DF Member

    great work
     

Share This Page