Trying to create a magisk module to edit rootfs - Magisk

I am attempting to create a magisk module that will "replace" a file in /system/etc. I have created the module and successfully installed it but the changes are not reflected upon booting multiple times. I can 'adb shell cat $MAGISK/system/etc/file.xml' and see the changes have not been made by magisk and I can adb shell cat system/etc/audio_policy_configuration.xml and see the files have not been altered in any way.
I just want to copy a fuggin file to system/etc. I have spent hours trying to research how to copy files to system with magisk modules but they are dead end roads.
I need someone to finally answer the question of how to copy a file using magisks built in module function. I can create and install the module but I am not understanding the process of actually copying the file. I thought anything you put in the system folder in the module template, that it would get used instead of the one in the actual read only system/etc. But I made the directories and file with changes I want, installed it but it doesn't show up in magisk manager and the changes arent made by the module.
Any and all help is appreciated

I've already replied here:
https://forum.xda-developers.com/t/...agisk-module-developers.3846678/post-84749791
But, in your post in that thread (please don't double post) you didn't mention anything about already having created a module.
If you have the module installed already but don't see any changes, provide the Magisk log. But, make sure you're on the latest Magisk Canary release first so that the log is more detailed.
Providing your module could also be a good idea, to see if it's built correctly.

Related

Magisk Module development help

This is my first attempt at a Magisk Module (to fix a issue with a few poorly coded legacy apps and not trip safety net) inject or replace a font and set proper permission on the file
My super simple experiment is here (based on the template from Git)
https://drive.google.com/file/d/1PHdRjzefpSMg51KUOffo4FtqlfoxshOM
Magisk gives me a error when I try to install
I probably did something wrong, hopefully someone can point me in the correct direction (error one, not a valid Magisk Module, error two Magisk is not activated)
I appreciate any insight - please move this post to the correct location if needed
If you want someone to look at the module you'll have to enable sharing for the file first...
But, your errors are usually:
1 - the zip has been packaged wrongly (not the proper file/directory structure
2 - using an old template
Take a look in the official docs on how to work with the current module and module installation setup:
https://topjohnwu.github.io/Magisk/guides.html
Let's try this link:
https://drive.google.com/file/d/1PHdRjzefpSMg51KUOffo4FtqlfoxshOM/view?usp=sharing
I started on Git, but I may have inadvertently been in the wrong place / pulled the wrong file -- I will go back through that link you provided tomorrow and see if something jumps out at me
Yeah, you have a whole host of mixed issues there...
First, all the module files have to be in the root of the module zip, not in the magisk-module-DroidSansFallback you have them in now (this is the "not a Magisk module").
Second, your update-binary is a webpage... That ain't gonna work very well. When you download the module_installer.sh script, save it from the raw view (there's a button above the code when you open the file on GitHub).
Last (but this is only cosmetical really, since it won't affect anything) you found some really old module to base your work on, because the config.sh file hasn't been used for ages, and the readme file is ancient.
Fix the above and follow the instructions in the docs and you should be good to go.
Is there a current template on Git for the blank files?
I am here:
https://topjohnwu.github.io/Magisk/guides.html
Made the updates, going to try it now - but I would like to get a proper template setup
There is no longer an official template provided.
The current module installation setup is so simple that it really doesn't need it. Put whatever files you want to mount in /system, whatever boot script or prop files (as described in the docs) you want to run in the root of the zip, create the module.prop (again, described in the docs) so that you'll have some info about the module in the Manager, zip it up and flash it.
If you want to customise things more you do that with the customize.sh script (described in the docs).
If you really need a template there's always @Zackptg5's MMT-Ext...
So I downloaded a current module and looked through the files / structure and then the docs -- and now I have this
https://drive.google.com/file/d/1z4tlH6wGDpq0UnkxPF0f6i-DohcKnux-/view?usp=sharing
When I go to /system/fonts I now see DroidSansFallback.ttf (it was not present before installing the module)
and no error messages!!
I think I need to read a little more, on Android 5-8 adding this font into /system/fonts (manually) fixed my problem - now I am on Android 9 (OnePlus 6t TMO variant) and I do not see any changes from adding the file (fonts.xml issue?)
I really wanted to try this as a learning experience, and because the old method trips CTSProfile to false
I appreciate your patience - at least now I have a better starting point
All you need for the font file to be mounted is the /system/fonts/DroidSansFallback.ttf file in the module society directory. The REPLACE variable you've set in customize.sh is only for replacing directories with empty ones, not files (so you can remove it since it might be causing a conflict). Details in the docs:
https://topjohnwu.github.io/Magisk/guides.html#remove-folders
updated (linked file updated as well) no change.. .. ..
I did double check that the module places the file in the correct location, and when the module is disabled the file is removed
I found this on a random Google search (ASE) from a unrelated topic (Chinese character support)
On Android 9 it's Noto CJK, e. g. "Noto Sans CJK JP" font family (located in /system/fonts/NotoSansCJK-Regular.ttc). There is no DroidSansFallback.ttf anymore.
Could that explain why adding the file did not work?
Very possible. As you say, the module looks fine and works as intended (places the file where you want it), so the issue likely lies elsewhere.
I will take a stab at injecting a modified fonts.xml and see if that changes anything - thanks!
I experimented with adding a line into the fallback section of the fonts.xml (to reference the new font), and replacing the fonts.xml with a older version from Android 8 --- neither had any effect that I could discern

[Help] Creating Module for vendor partition changes

Hello Fellow Users,
Let me start with the fact that I have zero experience of making flash modules (TWRP/Magisk) and am just dabbling around.
Some background, I found a TWRP flash zip file which makes changes to vendor partition of Redmi Note 7 Pro (violet) running MIUI OS (Android Q) - this is a sound mod.
Now, with TWRP file the issue is that if it doesn't work or has any issues, we need to dirty flash ROM all times (or atleast dirty flash the vendor partition). There is no one-click remove option.
Hence I thought why can't the same be done via Magisk systemless and dabbled around a bit. Below is my experience of the last 2 days.
Now, coming to the original TWRP file - it copies/replaces three folders with included files to vendor partition. Path of folders is following
Code:
/vendor/etc
/vendor/lib/soundfx
/vendor/lib64/soundfx
These 3 folders and similarly named files within them already exist by default in the phone prior to flashing.
Now basis the Magisk guides I saw around and wiki from @Zackptg5 I did the following changes to the default template:
1) Edited customize.sh to define folders to be replaced
Code:
REPLACE="
/vendor/etc
/vendor/lib/soundfx
/vendor/lib64/soundfx"
2) Since Magisk will always look for the vendor under the system folder and so I moved the vendor folder under system folder
Basis same, created attached module and flashed and it installed.
But then three queries in my mind:
1) Are the new files actually replaced systemless and in-use? My concerns as don't see any intended change in sound
2) Is there a way to check if new files are being used o available to system?
3) Is this method of putting replace under customize.sh file the way out? While studying some similar modules making changes to vendor partition, I found that they have default (no change) customize.sh but rather make changes to common/post-fs-data.sh etc
So, looking forward to feedback from users experienced in making Magisk module. Thanks in advance for your time and efforts!
PS: attached is the WIP module which I wrote and also got installed in Magisk Manager
TLDR: How to make a Magisk Module using TWRP files to ensure systemless modification of folder/files in the vendor partition
1 - The REPLACE variable is used to replace the directories you specify with empty folders, not with what you want to add systemlessly. You might want to follow the advice written in the customize.sh file and read the documentation (@topjohnwu has everything explained there):
https://topjohnwu.github.io/Magisk/guides.html
Edit: If you do want to first "remove" (systemlessly, of course) everything in those folders, then keep them in the REPLACE variable. I just realised that it's a little unclear if that's what you want to do or not...
2 - That's the correct procedure. If all you want to do is to add or replace some files to your device, the only thing you need is to put those files in the /system directory of your module. That's it. The customize.sh file is used if you want to customise the installation logic of your module (not necessary if you're just adding files to your device) and post-fs-data.sh and service.sh are boot scripts to run code at boot (again not necessary if you're just adding files systemlessly to your device, see the linked docs for details).
Right now your module isn't adding anything, since the directories in the module's system folder are all empty. There's nothing to add. All it does is to replace those directories with empty ones (see #1 above). I'd say that using MMT is way overkill for such a simple module...
One you've installed a module Magisk will mount that modules files over your existing ones at boot. If the file under the real system path matches the one found in the module directory (under /data/adb/modules) everything is working as it should.
@Didgeridoohan Thanks for taking our time to give detailed reply and guidance
Finally was able to successfully install the module (named AudioEngine) and I do see files under /data/adb/modules but I have the following issue:
All these new files are under:
/data/adb/modules/AudioEngine/system/vendor folder and not under
/data/adb/modules/AudioEngine/vendor folder
Is that ok? If yes, why do we see /data/adb/modules/AudioEngine/vendor separately too?
Attached is final module as well as the screenshot of /data/adb/modules/AudioEngine/ as seen in file manager.
The /vendor folder is a symlink to /system/vendor, created by Magisk. That's just how Magisk works...
From your screenshot it looks like things are working as they should.
That uninstall script looks unnecessary though. The module isn't placing or altering anything outside the module folder, so when uninstalled there won't be any leftovers anyway.
im also try to do something similar with some audio libs in vendor partition for poco f2 with miui12 however if i add any libs to go into vendor/lib, for some strange reason, i lose wifi. theres no issues if vendor/lib/soundfx or vendor/lib64 is occupied with files just the lib directory only. the actual files that are going into lib are not replacing anything but are new files

How to properly compress Magisk module .zip

Hello,
I'm trying to create my own Magisk module based on working modules and referencing the module instructions. Before getting too far, I wanted to make sure that the compression process worked correctly.
So, I downloaded a .zip module from the Magisk app (e.g. Wifi5ghzdisabler), moved .zip to my Ubuntu 20.04 PC using Google Drive, extracted the .zip (using Extract Here in Files context menu), compressed the module folder back to a .zip file (using Compress... in Files context menu) and then moved the new .zip back to the phone using Google Drive. No changes to any files were made. Then, I tried to install it from storage in the Magisk app (v23.0) on a OnePlus Nord N100 running Android 10, but I encountered the following error.
Installation Failed!
- Copying zip to temp directory
! Unzip error
Is this a compression issue or a permissions issue on the phone? I'm probably missing something simple. Thanks in advance.
DanHoliday said:
Hello,
I'm trying to create my own Magisk module based on working modules and referencing the module instructions. Before getting too far, I wanted to make sure that the compression process worked correctly.
So, I downloaded a .zip module from the Magisk app (e.g. Wifi5ghzdisabler), moved .zip to my Ubuntu 20.04 PC using Google Drive, extracted the .zip (using Extract Here in Files context menu), compressed the module folder back to a .zip file (using Compress... in Files context menu) and then moved the new .zip back to the phone using Google Drive. No changes to any files were made. Then, I tried to install it from storage in the Magisk app (v23.0) on a OnePlus Nord N100 running Android 10, but I encountered the following error.
Installation Failed!
- Copying zip to temp directory
! Unzip error
Is this a compression issue or a permissions issue on the phone? I'm probably missing something simple. Thanks in advance.
Click to expand...
Click to collapse
You should upload your zip.
Thanks for the reply.
I've attached the original WiFi5GhzDisabler-v1(1).zip module downloaded from inside the Magisk app.
I've also attached WiFi5GhzDisabler-v1(1)-re-compressed.zip after downloading, extracting and re-compressing the original module it as described in my first post. I didn't make any changes to the files/folders themselves. I did notice they are different sizes (6.1KB original versus 8.6KB re-compressed).
I'm trying to learn more about the correct compression process/tool for these modules. I searched the forum and found a thread with a similar issue. Basically, the OP shared a .zip file that didn't work and another member did something and uploaded a "fixed" version with minimal insight into how it was done.
[HELP] This zip is not a Magisk Module
I would assume there isn't anything wrong with the files in the original module since it was probably reviewed before it was hosted in the Magisk app. It is also strange that the .zip file downloaded from the github repos for various modules don't work for me either, but that may be a separate issue.
Any ideas? The instructions do not include how to compress the module.
Take a close look at the original zip again, and compare it to the one you recompressed. You've put all the files in a directory inside the zip, in comparison to putting them directly in the root of the zip...
There's your problem.
Didgeridoohan said:
You've put all the files in a directory inside the zip, in comparison to putting them directly in the root of the zip...
There's your problem.
Click to expand...
Click to collapse
You're exactly right. I was incorrectly zipping the module folder itself rather than the files inside the folder. As you correctly pointed out, this creates a folder inside the zip that adds an extra layer between the files and the root of the zip.
Wow, what a simple mistake. With your help, the recompressed module installs fine now. I was able to install my own module too!
Thank you so much for your help. My issue has been resolved.

Cannot mount file to system

I've created a module to edit /system/vendor/etc/mixer_paths_tavil.xml but it doesn't work, it used to work but since I got the "Audio Modification Library" module installed it won't change that file. I've attacehed the module down below in case if anything's wrong with it that I couldn't see, my phone is LG G7, thanks in advance.
If you have several modules that replaces the same file, only one module will get their file mounted. In your case it sounds like AML takes precedence. I can't quite remember now how that's decided (maybe installation order)...
One solution would be to edit the xml file in AML instead of in your module, but that would get overwritten whenever there's a change/update to AML.
Another way, that remedies the problem if the above solution, is to create a boot script that edits the AML file on each boot. That way you don't have to worry about the AML xml file being altered by a change/update to AML.
Of course, AML was created to help with just this situation. Having several audio mods trying to replace the same file (and failing). You might want to look into the docs for AML on how to utilise that part natively in your module.
There are limits to the systemless mask, so you'll have to be a little creative. As you can see above, there are options...

[REQUEST] Module to replace a file in vendor/etc

I have an LG V60 phone and I would like to put the phone in "high impedance mode" all the the time for more power to the earphones even if they are less than 50 ohm impedance.
In LG V40/50, it was very simple by rooting the phone and making some modifications in the one of the files that was in the "vendor/etc" directory. The problem with LG V60 is it does not allow any write access to the vendor folder at all.
So the only feasible option that I can think of is to create a Magisk module that replaces the original file with the modified one. My biggest disadvantage is not knowing anything about writing codes including Magisk module ones. So I was wondering if anyone could create a Magisk module that would replace the original file through Magisk?
ADDTIONAL INOFRMATION:
I am running Magisk 25 on a fully rooted LG V60.
The file that needs to be changed is mixer_paths.xml and it resides in the "vendor/etc" folder. I have created the modified file.
So if someone is able to develop a module to accomplish this, I will place the modified file in the "system/vendor/etc" folder of the Magisk module, as I understand it.
Many thanks for your support!
You can use this template system in future as its super easy
The template itself is here
GitHub - Zackptg5/MMT-Extended: Magisk Module Template Extended
Magisk Module Template Extended. Contribute to Zackptg5/MMT-Extended development by creating an account on GitHub.
github.com
click the Code button, then download zip
then extract the zip into a folder and rename the folder "MMT-Extended-master" to the something more meaningful, like the name of your module
Read the wiki and docs here to go step by step to create your first module:
Home
Magisk Module Template Extended. Contribute to Zackptg5/MMT-Extended development by creating an account on GitHub.
github.com
Notably the heading:
How do I make a MMT Extended mod?​
The steps for a simple file addition/replacement module, which are simple, should be steps 1-4, then 8. Then zip up the modules (as a zip) and test.
For you, if you read along (in Step 3) you will need to create a folder vendor, under the existing system one, and then a further etc folder under vendor, and put the necessary file (mixer_paths.xml in there.
If you try and fail, post back and someone will assist. But we prefer people to at least read the documentation and try first, ideally...this is the way the great didgeridoohan mentored myself and many others, he was not big on spoonfeeding
Imagine the satisfaction you might get finding out youre capable of such feats...i promise its not rocket surgery
Feel free to PM even, if you get stuck and think you have a silly question - of course knowing me, and i do, you'll probably get an even sillier, and off topic answer as well...
hint: you can knock out this basic module in far far less time than it took me to write all this
Thank you!
So my changes look like this:
1. Put the modified file in the system/vendor/etc folder of the Magisk module.
2. Made the needed changes to the customize.sh as attached.
Royaltiger said:
Thank you!
So my changes look like this:
1. Put the modified file in the system/vendor/etc folder of the Magisk module.
2. Made the needed changes to the customize.sh as attached.
Click to expand...
Click to collapse
Yes, though you'll need to uncomment (remove the leading #) from the set_perm lines to make them active, also you only really need the 2nd one
Royaltiger said:
Thank you
73sydney said:
Yes, though you'll need to uncomment (remove the leading #) from the set_perm lines to make them active, also you only really need the 2nd one
Click to expand...
Click to collapse
Click to expand...
Click to collapse
So I made the module with the suggested changes in customize.sh and put the modified mixer_path.xml file in the system/vendor/etc folder of the module. Module installs fine with Magisk but when it reboots, the device hangs on the initial LG screen and does not go anywhere from there.
I am attaching the customize.sh snapshot. Also, attached is the module file.
See here under "Disabling/uninstalling modules manually" if youre not able to boot
Module Issues:Magisk and MagiskHide Installation and Troubleshooting guide
www.didgeridoohan.com
I am assuming that it is not possible to accomplish what I wanted to achieve.
Royaltiger said:
I am assuming that it is not possible to accomplish what I wanted to achieve.
Click to expand...
Click to collapse
mixer_paths files have been replaced for years, long before magisk even...i did it back as far as the Galaxy S2 from memory, so im not sure why this didnt work for you, was the mxer_paths file specifically for your device? i have no clear idea why it hasnt worked for you
this thread has a guide to making /system RW, so you could manually copy the file and overwrite it, but id really consider how much you want to replace mixer_paths before i set out to do that
V60 Bootloader Unlock and Magisk Root
Earlier today I was alerted to https://www.cnblogs.com/yanhua-tj/p/15525593.html which has the actual firehose and steps to unlock! However it seems to be in Simplified Chinese so I'll translate it here for you. The firehose is attached below...
forum.xda-developers.com
73sydney said:
mixer_paths files have been replaced for years, long before magisk even...i did it back as far as the Galaxy S2 from memory, so im not sure why this didnt work for you, was the mxer_paths file specifically for your device? i have no clear idea why it hasnt worked for you
this thread has a guide to making /system RW, so you could manually copy the file and overwrite it, but id really consider how much you want to replace mixer_paths before i set out to do that
V60 Bootloader Unlock and Magisk Root
Earlier today I was alerted to https://www.cnblogs.com/yanhua-tj/p/15525593.html which has the actual firehose and steps to unlock! However it seems to be in Simplified Chinese so I'll translate it here for you. The firehose is attached below...
forum.xda-developers.com
Click to expand...
Click to collapse
Actually I had no problem in editing the mixer_tavil.xml file in LG V40/50. But when it comes to LG V60, the file is read-only. There is no way to edit it due to dynamic partition. Hence, I was seeking the only option available i.e., via Magisk module.
Royaltiger said:
Actually I had no problem in editing the mixer_tavil.xml file in LG V40/50. But when it comes to LG V60, the file is read-only. There is no way to edit it due to dynamic partition. Hence, I was seeking the only option available i.e., via Magisk module.
Click to expand...
Click to collapse
So, I encountered the same problem and found what you did wrong. I was able to write my own Magisk module and it works wonderfully. It took so much time to understand how to do it because there is no proper tutorial.
If you are still active and trying to know how to do it the right way, here comes the explanation:
The Replace = " /system/vendor/etc/ " must not be written as it completely wipes the actual folder from your phone. This is why you were not able to turn the phone on. It should be like this:
Replace = " " (That part must be blank)
The rest of the code is good. If you try it like this now, you will see it will work, just like mine did.
Cheers
Does not work. May I see your module? Please upload it here as attachment.
I even put my edited file under /data/adb/modules/<my directory>/system/vendor/etc. It shows up in Magisk as a module and the file loads (as it is not visible in file explorer) but there is no change in volume. So the thing is not working.

Categories

Resources