How to Overwrite File in /config/misc with Root Bash Script

John_83

Member
May 19, 2018
5
0
0
This script creates a duplicate file, with the same name, in the same directory as the intended target (???). The original system file has an Android icon next to it, while the new one has a text icon (as seen in Total Commander).

#!/bin/bash/sh
su
echo "0123456789ab" > /config/wifi/mac.txt

I am trying to overwrite the system file. I can manually edit the original mac.txt, and then when I turn on wifi I have the new mac address. (The normal methods of changing a mac fail with this device - a rooted Nextbook Ares 8" tablet.) The second max.txt file that this script creates gets deleted on reboot - and it has no effect on the mac address. Edits to the original max.txt survive reboot.

I am trying to develop an app to randomly set a mac address on reboot, and being able to overwrite the mac.txt file is the first step. (All of the existing mac address changing apps I have found are based on ifconfig or ip link, and those methods fail on this device.)

Android 5.1
 
Last edited:
Check the permissions on the original file. rm the original file, echo your random MAC to the file, then chmod the file to what the original was. Or you could just install Pry-Fi - Chainfire already did exactly what you want.
 
I just installed Pry-Fi. It fails to work on my device. It shows Original, Wanted, and Current mac address, and Original = Current <> Wanted after I connected on wifi. MAC spoofing while connected is checked. SuperSU shows Pry-Fi has permanent SU access. Yet another app that's using ifconfig and/or ip link, rather than (or additionally) editing the mac.txt file. I guess my device is different than the average one is this regard.

I find it very odd that Android allows there to be two files with the same name/extension in the same directory. I'm afraid to manually remove this file. Don't you need the same permission to edit and remove the file? (">" in a script is supposed to overwrite an existing file) I'd like to understand what's going on first. Otherwise, I'm going to research how to do a fully recoverable backup on my device first, because this is just too weird. I can probably use TWRP for the backup, which is still on there from the difficult process of getting this thing rooted - although booting into recovery isn't doing what it did while I was rooting the tablet.
 
The command :
ls "mac.txt"
only returns one file. I think there's a hidden character at the end of the original file, and it's not a space. A google search for a hidden character used in Android system files fails.
 
I copied the file into a directory viewable from my Windows PC (USB). The files lists as wifi.txt, but when I open it in Windows, Notepad calls the file wifi[1].txt (and there is only one version open).
 
That's a difference between ls and dir. But no, you can't have to files with the same name and extension in the same folder at the same time.

echo x > filename.ext

deletes the original file (or should, according to Linux' rules). (Not exactly overwrite, but the same effect.)

"Don't you need the same permission to edit and remove the file?" Modify and delete are different, but not to chmod. And the file also needs execute permission, at least for the owner, if it's going to execute (although it looks as if this is just the source of the MAC address).

"I guess my device is different than the average one is this regard." It would appear to be. I can't find /config/wifi/ in a rooted Pixel 2.
 
It appears the two filenames are identical. I executed the following:
ls /config/wifi > chars.txt
I copied chars.txt to my Windows PC with adb pull. I copied the text of chars.txt (a directory listing of two apparently identical filenames) to www.mauvecloud.net/charsets/CharCodeFinder.html
Both of the lines translate the same: "/config/wifi/mac.txt" -> "47, 99, 111, 110, 102, 105, 103, 47, 119, 105, 102, 105, 47, 109, 97, 99, 46, 116, 120, 116, 10"
(The 10 is a newline character.) At this point at least, there are no hidden/special characters in the file name.
 
Last edited: