yashsingh1/xdaforums huggingface dataset:
[Android General] rkhat:
Oreo ROMs come compressed by brotili. You can compile from source to get the executable or you can get the binaries directly from the release page (version 1.0). Use it to extract and repack .br.

I added a converter from file_context.bin to a readable format in the new version I just uploaded.

This project only supports Linux as of now. As for using it in Windows, you have 3 options,

Use a linux distro in VirtualBox (I currently use this option)

Install a linux bash shell in Windows 10

Build the project in Cygwin (hopefully someone can make a pull request and share it with the rest)
[Android General] marshharsha:
thanks brother for your kind reply can you give guide for make exe from brotli source? with java or c

thanks again
[Android General] rkhat:
Just use a pre-built brotli from the release page (there is a window version). It doesn't matter that the executable is not the latest version as you only need to extract compress the .br file.

If you really need to build brotli for windows, just open scripts/appveyor.yml in the github repository. Decide which environment you want (I see they support 32-bit/64-bit versions for Visual Studio, Python, MinGW). Download the necessary software (python, mingw ...). Then run the commands in appveyor.yml using cmd in this order.
[Android General] sdeft:
[MENTION=8241686]rkhat[/MENTION]

Hi and thanks for making the tools for us.

I am getting the below error when ./img2simg new-system.img news-system.img. I downloaded version for Nougat.

img2simg: /android-rom-repacker/external/platform/core/src/libsparse/sparse.c:153: int write_all_blocks(struct sparse_file *, struct output_file *): Assertion `pad >= 0' failed.

Aborted

I am running Ubuntu. Do you know what might be the problem ?
[Android General] rkhat:
Just tested a Nougat lineage ROM for Nexus 7 from here. No issues!

Are you sure you used this version for Nougat?

If you still have issues, can you link me the zipped ROM and more importantly the source you got it from so I can test it out? Thank you.
[Android General] sdeft:
I think I found the issue. This is happening only when i perform it on the image created with

./make_ext4fs -s -l 3000M -a system new-system.img tmp/

If I just umount the image and then apply img2simg it works.

Is this strange or what ?
[Android General] rkhat:
Don't use "-s" (lowercase s) option. It only writes sparse headers in new-system.img. The file is only couple MBs instead of 3000MB you specified. I am curious how img2simg even worked.

Also, use "-S file_contexts" (uppercase S) option to apply the security contexts on files. The zipped ROM has file_contexts.bin (binary version) since Android Nougat. You'll need to convert it to text format. You can use the executable sefcontext_decompile included in my tools to convert file_contexts.bin to file_contexts.
[Android General] sdeft:
I am not using a zipped rom with file_contexts.bin, system.new.dat etc.

I am trying to mod a system.img from a fastboot rom for xiaomi. So far only managed to have the userdata.img working but system.img keeps giving me bootloops!. Will try your suggestion above...
[Android General] anggafzkdev99:
build use cygwin window 7 x64

how build use cygwin on w7 x64? or can you make for windows too?

sorry for bad engglish
[Android General] rkhat:
I don't use windows in this project. So you're on your own in building using cygwin :(

Alternatively, you can use Ubuntu on VirtualBox which is what I currently use.
[Android General] marshharsha:
how to convert file context.bin to plain for oreo in windows?
[Android General] rkhat:
I don't know if other developers have a window's version but my project only works on linux :(
[Android General] marshharsha:
guide me please
[Android General] rkhat:
I told you my project doesn't work in windows. You need linux. If you have Windows 10, you can download ubuntu from Microsoft store.

If you don't have Windows 10, then you can get ubuntu desktop and run it inside virtualbox. This might need some extra CPU and RAM.

If your computer is old, your third option is to get

1. an empty usb (at least 2 GB)

2. download ubuntu desktop

3. download Rufus

4. Follow this tutorial. (it needs 9 min!)

5. Restart the pc, get into BIOS and change the boot order to boot from usb first.

6. Click try Ubuntu

Now you have ubuntu running from a usb. Any files you save in this ubuntu will be lost. Your PC's hard disk will look like an external usb or hard disk. You can get files from there and save them there.

Once you get into ubuntu or any other linux distro,

1. Download this archive and extract it anywhere.

2. Put sefcontext_decompile (found in the extracted archive) and file_context.bin in the same folder.

3. Open terminal (this is the linux equivalent of windows command prompt).

4. cd to_the_folder_from_step_2 (This is exactly like how it is done in windows command prompt)

5. type

./sefcontext_decompile -o file_context file_context.bin

6. file_context will be the text file you need.
[Android General] marshharsha:
thanks bro getiing command not found
[Android General] rkhat:
Sorry my bad. Add ./ before the command like this

./sefcontext_decompile -o file_context file_context.bin

Also if you get a permission denied error. Type this command and try again:

chmod +x sefcontext_decompile
[Android General] alecxs:
Have added init.d to stock firmware using the old Android_ROM_IMG_Repacker, now Odin Downloader won't flash because "md5 error! Binary is invalid". Can i use your tool for KitKat, which branch should i use? its a SAMSUNG Galaxy Tab 3 Lite SM-T113 DBT
[Android General] ngochoangimsat:
Please write a guide how to install this tool on Ubuntu? I downloaded android-rom-repacker-20180401-5880079.tar.gz from your link to My computer , but i dont know what to do . The tool from old thead have a file call main-menu to do the job but in now i cant see this file your android-rom-repacker-20180401-5880079.tar.gz
[Android General] rkhat:
Hi, the binaries have multiple purposes so I can't write one guide.

If you need to unpack/modify/repack a ROM that has system.new.dat (like lineageOS) follow the guide here (2nd post) and use make_ext4fs and img2simg from my project. Also if you are using android >= 7, you will need to convert file_contexts.bin binary file to file_contexts text file. You can find out how to do this in my main post (under sefcontext_decompile).

If you need to unpack/modify/repack a ROM that has system.img and boot.img. First unpack boot.img using

./unpackbootimg -i boot.img -o boot

then extract boot.img-ramdisk.gz inside boot folder then boot.img-ramdisk. Now you will find file_contexts text file.

Then follow the exact same guide above but in step 1 run this instead:

./simg2img system.img my_new_system.img

and use my_new_system.img for step 2. Then do steps 2 and 3. The output of step 3 is the new system.img you will need (basically skip step 4).
[Android General] ngochoangimsat:
Could you tell me the way to unpack and repack this ROM , this rom for a head unit with android 6.0, which all of partion is in one file.bin

http://www.mediafire.com/file/byc7t...%E5%8E%BB%E5%BA%95%E5%99%AA%E9%9F%B3.rar/file
[Android General] rkhat:
How do you flash this ROM into your head unit? Do you use any 3rd party tool?
[Android General] ngochoangimsat:
Do you use any 3rd party tool? -> No

How do you flash this ROM into your head unit? -> I coppied 3562f.bin and 3562f.upd to the root folder of USB Storage , plugin to head unit and reboot head unit. That all

Somes years ago, when i cook rom for windows mobile device, i used winhex to manual copy any partion to file by it header or flags. For excam, the system.img may be start at offset with flag AA 0b EC xx yy xx ...

But now , on android rom i dont know
[Android General] rkhat:
The format of the .bin file is most likely proprietary to prevent others from modifying the ROM. Do you have root access in the head unit? Otherwise it is going to be near impossible to modify ROM without some reverse engineering.
[Android General] ngochoangimsat:
yes, i have root access. I can dump all partions by command line as: dd if=/dev/.... of=/sdcard/...

but i cant repack it and i can't creat scatter , scatter for me to use SFT when need

The head unit does not usb ota to connect to computer, i have to solder it, but way is only for unbrick device. I want to pack the rom for other peoples flash via usb storage
[Android General] rkhat:
Oh ok, I see what you need now and using dd was what I was going to suggest.

This is going to be difficult depending on how the .bin was packaged. I suggest trying the following:

1. The bin file is simply a dump of all the partitions. In this case, create a disk image of one of the partitions (like system partition) using dd. Then hex search in the bin file, the first couple of hex values of the disk image. This will let you know where the partition starts in the bin file.

2. Modify a couple of hex values in the bin file and flash the ROM. Then compare the old and new disk images of all the partitions. Be careful that this might brick the headunit.

If these suggestions don't work, then it is going to be outside my field of expertise.
[Android General] ngochoangimsat:
I search some hex value from dump file (by dd command) in the bin file, but nothing found.

By the way, in the MT3561 CPU head unit (my head unit is MT3562 CPU, it may be similar but i dont understand the code to change), the member from 4pda.ru make the script for unpackge an repackge look like:

What exacclty this code do?

1. Splitt.sh

#!/bin/bash
BIN=$1
if [ "$BIN" == "" ]; then
BIN=3561.bin
fi;

get_file_name() {
case $1 in
1) file_name="lk.bin";;
2) file_name="image$1.bin";;
3) file_name="boot.img";;
4) file_name="recovery.img";;
5) file_name="system.img";;
6) file_name="image$1.bin";;
7) file_name="dtb2.img";;
8) file_name="kernel2.img";;
9) file_name="ramdisk2.img";;
10) file_name="tee.img";;
*) echo "Done. Files extracted from $BIN are located in: $PWD/$DIR"; echo; exit;;
esac;
}

DIR=$(basename $BIN)-splitted
mkdir -p $DIR

LIST=$(hexdump -s 8 -v -n 40 -e '1/4 "%d " "\n"' $BIN)
echo $LIST

offset=48
offset1=48
id=0
for length in $LIST; do
let "id = id + 1"
get_file_name $id
let "offset1 = offset"
let "offset = offset + length"
echo $id":" $file_name":" "offset="$offset1 "length="$length
echo "------------"
dd if=$BIN skip=1 ibs=$offset1 obs=$length | dd bs=$length count=1 of=$DIR/$file_name
done

exit 0

2. Make.sh

#!/bin/bash
function getbytes()
{
vh=$(printf "%08x" $1)
vh1=${vh:6:2}
vh2=${vh:4:2}
vh3=${vh:2:2}
vh4=${vh:0:2}
vh1=${vh1^^}
vh2=${vh2^^}
vh3=${vh3^^}
vh4=${vh4^^}
vhu="\x${vh1}\x${vh2}\x${vh3}\x${vh4}"
#	echo -en $vhu > file.tmp
}
BIN=$1
if [ "$BIN" == "" ]; then
BIN=3561.bin
fi
for i in 0 1 2 3 4 5 6 7 8 9; do
rm -f image$i.img
done
#
j=0
for img in lk.bin image1.img boot.img recovery.img system.img image5.img dtb2.img kernel2.img ramdisk2.img tee.img; do
if [ -f $img ]; then
cp $img image$j.img
else
touch image$j.img
fi
let "j = j + 1"
done
#
echo -n "cxj8" > header.bin
echo -en "\x00\x00\x00\x00" >> header.bin
#
for i in 0 1 2 3 4 5 6 7 8 9; do
FS=$(stat -c%s "image$i.img")
getbytes $FS
echo -en $vhu >> header.bin
done
#
cat header.bin > new_$BIN
for i in 0 1 2 3 4 5 6 7 8 9; do
cat image$i.img >> new_$BIN
rm -f image$i.img
done
rm -f header.bin
[Android General] rkhat:
Ok I just tested the scripts and they works. You will run them like this

./splitt.sh 3562f.bin

#modify what you need inside 3562f.bin-splitted directory
#copy make.sh inside the directory and run the following
./make.sh 3562f.bin

#rename file if needed

splitt.sh will split the bin into imgs. You'll have system.img and boot.img. Then follow the guide in my earlier comment to modify system.img. Then use make.sh to combine the imgs back to the bin file.
[Android General] JamFlux:
Awesome help from you

I admire your work [MENTION=8241686]rkhat[/MENTION].

I made a simple bacth tool for unpack and repack system format till android 8.1, here: https://xdaforums.com/chef-central/...ndroid-5-8-t3670763/post73735778#post73735778

Iit automaically find file_contexts.bin and convert to plain text. This under Windows environment. I have some issues with make_ext4fs binary cause is pretty old and wifi is not working on repacked system.img.

I appreciate the most if you can set your github sources into mingw32 or 64 options.

Or if you know some one who can compile make_ext4fs binary for windows.

Thanks u¿in advance.
[Android General] rkhat:
Hi JamFlux,

It is not possible to compile make_ext4fs with mingw because it uses linux exclusive libraries that have not been ported to Windows.

Only option is to compile using cygwin but I don't have time to learn how to do it :( . Looking at the previous developer that was working on this project., there is very minimal changes to the code to get it running on cygwin. You could try your luck and see if you can get my project compiled using cygwin. Or try asking someone with experience in compiling using cygwin.

Sorry I couldn't be of any help. :(
[Android General] Austcool:
Does this work with samsung devices in my case a sm-t380 tablet?
[Android General] rkhat:
The binaries in this repack are from lineageOS source code. They are also exactly the same as AOSP (stock android).

So if you want to modify lineageOS ROM (or most lineageOS-based ROM) for your tablet, then it will work.

If you want to modify the stock ROM or any other ROM, then it might or might not work. It depends on how the ROM was built and whether or not they modified the source code for the binaries from stock android. In case it doesn't work, then you might need to create the binaries from the source code of that ROM.
[Android General] JamFlux:
Hi friend. Thanks for answering.

I found this updated Make_ext4fs source that works on Windows using mingw-64. But it works until android 7.1.2. I tested and 8.1 roms doesn't boot up.

Please, i know you can check the code inside that source and update with Oreo 8.1 changes. I will be expecting to you for testing.
[Android General] rkhat:
This is for linux. If you have gotten it for Windows from this source, then it is done through cygwin not mingw. I am not interested in learning how to compile using cygwin. Maybe in the future when I have a lot of free time.

Also, don't expect anything from me. I do not work for you. You should be familiar with forums rules especially rule 2.3.

I'll give you the benefit of doubt as the sentence is clearly written by a non-English speaker.
[Android General] JamFlux:
[MENTION=8241686]rkhat[/MENTION], thanks for answering me.

I'm not demanding to you. My intentions are not bothering you. Just I think that you know how to build make_ext4fs tool for linux, may be you can find a way to may your knowledge compatible with cygwin. I'm able to be your tester. This repo is working for building make_ext4fs for windows under cygwin. My idea, and sorry if bothering you, is that may be you can fork that repo and add only the changes for oreo, because oreo roms can't boot without updates.

That would be aweosme for this community, a make_ext4fs utility update for windows users.

Thank you so much. And sorry for my english. Lol.
[Android General] rkhat:
That repo you posted does the exact same thing my repo does. Only difference is that he has the sources in the repo and uses make directly. I download the sources in the build process and use cmake before make. So if I were to do what you want, I would have done it on my repo as I already have oreo. The thing is I don't have much interest and little free time which I could use to learn something more useful.

I have a simple question for you. Do you have a windows PC? If so, you can do it yourself. I see from your project you have experience writing batch scripts so you know how to use command prompt. It is not much difficult and probably involves no or minimal programming. It is mostly downloading libraries and using the cygwin terminal (basically command prompt but some commands are slightly different as it uses bash instead of batch). If you get any programming errors or any other errors, post them here and I or someone else will probably be able to assist you.

1. Download cygwin. The terminal (Mintty) should be included with it by default.

2. Find a way to use the clang compiler in cygwin instead of the default gcc compiler. (you'll find an answer using Google)

3. Find a way to get the equivalent of these 6 packages in cygwin build-essential git zlib1g-dev libpcre3-dev libc++-dev libc++abi-dev (you'll find an answer using Google)

4. Find a way to get cmake in cygwin (you'll find an answer using Google)

4. Download my android oreo repo from here and unzip it in your Windows home folder.

5. Run these 4 instructions in the cygwin terminal

cd [I]"folder_you_unzipped"[/I]
mkdir build && cd build
cmake ..
make

6. If you get errors, you might have to download additional packages or fix something. You can try googling the error.

7. If you are still getting error, post them here and I might be able to help you.
[Android General] JamFlux:
Thank you.

I tried differents ways but download functions aren't working. I changed cmake file to 3.6 compatibility because cygwin only is updated with cmake 3.6.

I found an updated repo for oreo, here. Now I'm going to test and tell you. Thanks.
[Android General] rkhat:
Which cmake version are you using? Use cmake --version command.

If it is on 3.8 or 3.9, download cmake 3.10 or higher and try again. I think I might have used code for cmake 3.10 or higher to fix a bug and never tested backward compatibility with 3.8. Please let me know if that resolved the issue.
[Android General] Q9Nap:
I was using cmake 3.8 as that is the required version listed in the readme documentation.

I re setup my chroot from scratch and added buster sources, which is necessary for cmake greater than 3.10. Cmake is now 3.12.1.

It now doesn't make it through the "cmake ..", as this testing version seems to be broken, but at least it is a new error!

user@localhost:~/build/android-rom-repacker-android-7$ ls
CMakeLists.txt ExternalModules src
CMakeModules README.md
user@localhost:~/build/android-rom-repacker-android-7$ export CC=/usr/bin/clang
user@localhost:~/build/android-rom-repacker-android-7$ export CXX=/usr/bin/clang++
user@localhost:~/build/android-rom-repacker-android-7$ mkdir build && cd build
user@localhost:~/build/android-rom-repacker-android-7/build$ cmake ..
-- The C compiler identification is unknown
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- broken
CMake Error at /usr/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler

"/usr/bin/clang"

is not able to compile a simple test program.

It fails with the following output:
Change Dir: /home/user/build/android-rom-repacker-android-7/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_e6b32/fast"
/usr/bin/make -f CMakeFiles/cmTC_e6b32.dir/build.make CMakeFiles/cmTC_e6b32.dir/build
make[1]: Entering directory '/home/user/build/android-rom-repacker-android-7/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_e6b32.dir/testCCompiler.c.o
/usr/bin/clang -o CMakeFiles/cmTC_e6b32.dir/testCCompiler.c.o -c /home/user/build/android-rom-repacker-android-7/build/CMakeFiles/CMakeTmp/testCCompiler.c
make[1]: *** [CMakeFiles/cmTC_e6b32.dir/build.make:66: CMakeFiles/cmTC_e6b32.dir/testCCompiler.c.o] Segmentation fault
make[1]: Leaving directory '/home/user/build/android-rom-repacker-android-7/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_e6b32/fast] Error 2

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!
See also "/home/user/build/android-rom-repacker-android-7/build/CMakeFiles/CMakeOutput.log".
See also "/home/user/build/android-rom-repacker-android-7/build/CMakeFiles/CMakeError.log".
user@localhost:~/build/android-rom-repacker-android-7/build$

Any other suggestions or am I SOL?
[Android General] rkhat:
Thanks for testing it out. I will update the readme to 3.10 and block cmake from working on any version below 3.10 which is the version I actually test on. Sorry for the inconvenience.

Notice this error:

-- The C compiler identification is unknown
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- broken

Did you install the clang compiler? There is a step that says to install the clang compiler which is the following for the debian system

apt-get install clang

Edit: I forgot to write the step in the Readme for android 8 and android 9 but I have it for android 7. I will add it to android 8 and 9.
[Android General] Q9Nap:
No problem regarding testing; I want to get these tools working on armhf.

BTW there is also a typo in the c++ export command in the readme; "bing" should be "bin".

I do have clang installed, but it seems to be broken:

user@localhost:~$ sudo apt install clang
Reading package lists... Done
Building dependency tree
Reading state information... Done
clang is already the newest version (1:6.0-42).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
user@localhost:~$ clang --version
Segmentation fault
user@localhost:~$
[Android General] rkhat:
Fixed. Thanks! :good:

Yes it seems to be broken. The command clang --version should work. I am guessing clang 6 (default for debian buster) is broken for armhf since clang 3.8 was working in the your first log. You should probably try to file a bug report with the clang developers.

Meanwhile, you could try your luck reinstalling clang 6(check this). There is a small chance it wasn't properly installed.

Or try installing clang-3.9 for debian buster. You will have to change the exports to something like this (or whatever the clang-3.9 binary is inside /usr/bin)

export CC=/usr/bin/clang-3.9
export CXX=/usr/bin/clang++-3.9

By the way you can also see the whole execution process on travis. I am using a very base version of ubuntu 18 there and using only the steps from the readme. It uses clang 1:6.0-41 package.
[Android General] Q9Nap:
I tried uninstalling and reinstalling clang, tried clang-3.9, and scrapped the debian chroot altogether. I then installed Ubuntu 18.04 chroot with all the dependencies from the readme.

All return errors due to broken clang.

Oddly, all clang related files in /usr/bin are zero byte files on armhf; iirc it was that way even with clang-3.8 that did partially work.

Guess it's a no go on armhf unless/until they make a working updated version of clang.
[Android General] rkhat:
You could try building clang for your device

Or cross-compile from an x86_64 device targeting arm architecture.
[Android General] Q9Nap:
Thanks for the suggestions!

I really just needed sefcontext_decompile, so compiled it by itself.

I was able to install android-tools-fsutils for the other binaries.
[Android General] dhiet75:
Hi bro.. i wanna ask, how to convert back from system.new.dat to system.new.dat.br using linux?
[Android General] rkhat:
If you have ubuntu or a debian-based distro, install brotli using this command:

sudo apt-get install brotli

Then run this command:

brotli --input system.new.dat --output system.new.dat.br