198 Commits
1.4.0 ... 2.1.0

Author SHA1 Message Date
1f191dcce9 Update install-termux.sh 2024-07-04 15:22:37 +03:00
96706ada96 Update install-termux.sh 2024-07-04 15:22:16 +03:00
fc02df6583 pmt: Fix FORTIFY problems 2024-06-17 11:41:55 +03:00
deb42c9ff5 Update README.md 2024-06-17 10:57:12 +03:00
60904a4b2f Update install-termux.sh 2024-06-17 00:37:35 +03:00
ad6115f51b Update install-termux.sh 2024-06-17 00:30:59 +03:00
6cc59d92f8 Update install-termux.sh 2024-06-17 00:28:42 +03:00
fe69408eb5 Update install-termux.sh 2024-06-17 00:26:37 +03:00
cd386ac6f9 Update install-termux.sh 2024-06-17 00:22:37 +03:00
268aa8ac77 Update install-termux.sh 2024-06-17 00:21:57 +03:00
c5746fe14b Update install-termux.sh 2024-06-17 00:17:11 +03:00
d2cb68df5e Update install-termux.sh 2024-06-17 00:13:30 +03:00
3976e0fb39 Update install-termux.sh 2024-06-17 00:08:01 +03:00
0a9e164b9c Update install-termux.sh 2024-06-17 00:07:00 +03:00
ecada5f076 Update install-termux.sh 2024-06-17 00:06:28 +03:00
ca09bb94e1 Update install-termux.sh 2024-06-17 00:03:18 +03:00
52ffe99d4b Update install-termux.sh 2024-06-17 00:00:54 +03:00
416939634a pmt: fix syntax 2024-06-17 00:00:24 +03:00
cbbd36899e Update README.md 2024-06-16 23:58:10 +03:00
9dc79ae923 Update install-termux.sh 2024-06-16 23:57:15 +03:00
b522dcc62b Update install-termux.sh 2024-06-16 23:56:35 +03:00
7aeea39e41 Update README.md 2024-06-16 23:56:01 +03:00
974774eb3e pmt: add quick installer 2024-06-16 23:51:02 +03:00
70ce307e50 readme: create a general file alignment table 2024-06-16 08:44:01 +03:00
99ecb9daf3 Make some corrections. 2024-06-10 06:28:01 +03:00
d0a7b2d16f Update CHANGELOG.md 2024-06-04 18:07:35 +03:00
96336bcd0b Update README.md 2024-06-04 17:59:20 +03:00
545376afb2 Initial 2.1.0 update 2024-06-04 17:55:15 +03:00
62b24d5705 Update docs.c 2024-05-26 17:08:18 +03:00
0fca319b29 Update README.md 2024-05-26 17:07:56 +03:00
929150e034 pmt: delete unnecessary files 2024-05-26 11:31:46 +03:00
93843a511d fix typo 2024-05-26 11:30:57 +03:00
0981e70268 pmt: edit changelog 2024-05-26 11:30:03 +03:00
b214da3cd6 pmt: fix missing explanation 2024-05-26 11:24:41 +03:00
464bfe6e56 pmt: Update build guide 2024-05-26 11:23:54 +03:00
f5531fde32 pmt: initial 2.0.0 update 2024-05-26 10:49:33 +03:00
f771fb7c68 Update env.mk 2024-05-14 00:07:19 +03:00
4bc5235952 Update vars.mk 2024-05-14 00:04:29 +03:00
d4b4c91ff4 pmt; use target arch macro 2024-05-14 00:00:15 +03:00
6fc38eb01d Update vars.mk 2024-05-13 23:58:04 +03:00
42e5d132e7 Update vars.mk 2024-05-13 23:52:55 +03:00
39d1411b11 pmt; include stdint lib 2024-05-13 23:47:16 +03:00
04d6471c86 Update tools.c 2024-05-13 23:46:54 +03:00
f7d2f313de Update pmt.c 2024-05-13 23:46:37 +03:00
49a87b0387 pmt; include stdint lib 2024-05-13 23:46:15 +03:00
5a104e5b22 pmt; include stdint lib 2024-05-13 23:45:56 +03:00
055213f2f6 pmt; include stdint lib 2024-05-13 23:45:37 +03:00
7f270e319c pmt; include stdint lib 2024-05-13 23:45:17 +03:00
6a035f8f41 Update pmt.h 2024-05-13 23:43:35 +03:00
1b2dda655a Update vars.mk 2024-05-13 23:43:11 +03:00
07d63944c1 Update pmt.h 2024-05-13 23:36:54 +03:00
36b7bcf246 Update pmt.h 2024-05-13 23:35:30 +03:00
cd3f65a145 Update pmt.h 2024-05-13 23:34:56 +03:00
9dd29f96b8 Update pmt.h 2024-05-13 23:31:41 +03:00
7254637caf Update pmt.h 2024-05-13 23:30:54 +03:00
2af00a8028 Update pmt.h 2024-05-13 23:26:39 +03:00
b5790af803 pmt: change macro name 2024-05-13 23:23:02 +03:00
8fe1548796 Update vars.mk 2024-05-13 23:20:12 +03:00
04d8ccdd81 Update vars.mk 2024-05-13 23:14:59 +03:00
1a790d1d89 Update vars.mk 2024-05-13 23:13:43 +03:00
1296e488f1 Update vars.mk 2024-05-13 23:09:35 +03:00
3fea6c73cc Update vars.mk 2024-05-13 23:06:56 +03:00
cf4b590130 Update vars.mk 2024-05-13 23:05:28 +03:00
352ef6e68a Update vars.mk 2024-05-13 23:04:36 +03:00
754ebaade2 Update vars.mk 2024-05-13 23:03:37 +03:00
8a28a8f1ef Update ndk.sh 2024-05-13 23:01:43 +03:00
086a2dd93d Update vars.mk 2024-05-13 23:00:17 +03:00
383a1efe55 Create ndk.sh 2024-05-13 22:59:21 +03:00
b96977a5fc Update vars.mk 2024-05-13 22:58:17 +03:00
976c10593c Update vars.mk 2024-05-13 22:53:23 +03:00
d45dd67cbe Update vars.mk 2024-05-13 22:46:55 +03:00
0fa5a546aa Update vars.mk 2024-05-13 22:44:59 +03:00
0c487c62fe pmt: fix syntax 2024-05-13 22:43:15 +03:00
105d92e0ca Update vars.mk 2024-05-13 22:40:15 +03:00
850d104a1a Update README.md 2024-05-13 22:28:51 +03:00
6d24fb9eae pmt: adapt NDK 2024-05-13 22:28:10 +03:00
ae8c73c4f5 pmt: adapt NDK 2024-05-13 22:26:46 +03:00
890d93131c pmt: include env first 2024-05-13 22:24:57 +03:00
a33d4e3f16 Update README.md 2024-05-13 22:12:29 +03:00
f344d62d4c Update README.md 2024-05-13 22:10:44 +03:00
40c5b155dc Update README.md 2024-05-13 22:08:51 +03:00
0547e18639 Update README.md 2024-05-13 22:05:57 +03:00
f34a47889e Update README.md 2024-05-13 22:00:47 +03:00
a9fac9e661 pmt: just report compiling with android NDK 2024-05-13 21:57:15 +03:00
e8040de436 pmt: header: make compatible with android NDK 2024-05-13 21:53:54 +03:00
ff6e82c556 pmt: versioner: add 32-bit or 64-bit build information to version information 2024-05-13 21:51:20 +03:00
0c7da875b2 pmt: listpart: include string library 2024-05-13 21:43:21 +03:00
41565d221f pmt: update version 2024-05-08 06:58:40 +03:00
5ba78d860e pmt: update version 2024-05-07 20:58:37 +03:00
181125dfca pmt: initial 1.9.0 update 2024-05-05 21:06:14 +03:00
4464c203fd pmt: initial 1.9.0 update 2024-05-05 21:05:21 +03:00
b9e58df98f pmt: initial 1.9.0 update 2024-05-05 21:04:48 +03:00
e2f8cf4ca3 pmt: initial 1.9.0 update 2024-05-05 21:03:51 +03:00
07e2249ef1 pmt: initial 1.9.0 update 2024-05-05 21:03:01 +03:00
fd970be822 pmt: initial 1.9.0 update 2024-05-05 21:02:26 +03:00
45c964997c Delete src/format.c 2024-05-05 21:02:15 +03:00
31b7f16a29 pmt: initial 1.9.0 update 2024-05-05 21:02:04 +03:00
5f83a4476f pmt: initial 1.9.0 update 2024-05-05 21:01:43 +03:00
5438f5210f pmt: initial 1.9.0 update 2024-05-05 21:00:53 +03:00
cb7904cd5a pmt: initial 1.9.0 update 2024-05-05 20:57:20 +03:00
9c570d5b02 pmt: initial 1.9.0 update 2024-05-05 20:56:34 +03:00
c9736863fe pmt: initial 1.9.0 update 2024-05-05 20:55:59 +03:00
d5ce065e8b pmt: initial 1.9.0 update 2024-05-05 20:55:19 +03:00
a4bc9e3834 pmt: initial 1.9.0 update 2024-05-05 20:54:15 +03:00
ce017e2cbc pmt: move source in to src 2024-04-25 22:35:32 +03:00
b5daf8a44c pmt: move source in to src 2024-04-25 22:35:01 +03:00
f125ae760c pmt: move source in to src 2024-04-25 22:34:31 +03:00
f68f92ade1 pmt: move source in to src 2024-04-25 22:34:04 +03:00
3a723446cc pmt: move source in to src 2024-04-25 22:33:40 +03:00
1d66a3c21f pmt: move source in to src 2024-04-25 22:32:34 +03:00
13e31df7c6 pmt: move source in to src 2024-04-25 22:31:52 +03:00
4922ed5a35 pmt: move source in to src 2024-04-25 22:31:12 +03:00
3220aace91 pmt: move source in to src 2024-04-25 22:30:40 +03:00
7f85d63088 pmt: initial 1.8.0 update 2024-04-25 22:09:03 +03:00
412b697b9c pmt: initial 1.8.0 update 2024-04-25 22:08:30 +03:00
afc958aeb4 pmt: initial 1.8.0 update 2024-04-25 22:07:45 +03:00
fbd45e0936 pmt: initial 1.8.0 update 2024-04-25 22:07:05 +03:00
0ef8767eb5 pmt: initial 1.8.0 update 2024-04-25 22:06:31 +03:00
9bc871573e pmt: initial 1.8.0 update 2024-04-25 22:05:58 +03:00
adad63bbbd pmt: initial 1.8.0 update 2024-04-25 22:05:12 +03:00
0157c886ae pmt: initial 1.8.0 update 2024-04-25 22:04:33 +03:00
076774d9f4 pmt: initial 1.8.0 update 2024-04-25 22:04:00 +03:00
25642cc6f2 pmt: initial 1.8.0 update 2024-04-25 22:02:58 +03:00
16c8654fa2 pmt: initial 1.8.0 update 2024-04-25 22:02:04 +03:00
1fb592a94f pmt: initial 1.8.0 update 2024-04-25 22:01:14 +03:00
5bb26c9eea pmt: initial 1.8.0 update 2024-04-25 21:59:54 +03:00
540dd4fe35 pmt: initial 1.8.0 update 2024-04-25 21:59:06 +03:00
22ef985925 pmt: initial 1.8.0 update 2024-04-25 21:58:42 +03:00
2e81ab9541 pmt: initial 1.8.0 update 2024-04-25 21:57:50 +03:00
112a2986b5 pmt: initial 1.8.0 update 2024-04-25 21:56:59 +03:00
65fd480ba2 pmt: initial 1.8.0 update 2024-04-25 21:56:37 +03:00
d31bccd8f6 pmt: initial 1.8.0 update 2024-04-25 21:56:05 +03:00
6c574e9536 pmt: initial 1.8.0 update 2024-04-25 21:55:09 +03:00
a4838b24e1 pmt: initial 1.8.0 update 2024-04-25 21:54:10 +03:00
908060219e pmt: initial 1.8.0 update 2024-04-25 21:50:04 +03:00
ac06203a2c pmt: initial 1.8.0 update 2024-04-25 21:49:07 +03:00
56976b2bd0 pmt: initial 1.8.0 update 2024-04-25 21:48:43 +03:00
b7ebb92fcd Update CHANGELOG.md 2024-04-25 21:44:08 +03:00
3b36e1309d pmt: Specify that bugs should be reported by email 2024-04-17 17:59:31 +03:00
8dbc54f9fc pmt: build system: update help message 2024-04-13 22:30:29 +03:00
4b4b53a080 pmt: update explanation 2024-04-13 22:29:36 +03:00
09d9aa1ee6 pmt: exclude unnecessary library 2024-04-13 22:26:21 +03:00
171de34710 pmt: exclude unnecessary library 2024-04-13 22:25:54 +03:00
5e39fdcdc9 pmt: add arm defination controller 2024-04-10 01:02:06 +03:00
fbb4822872 Update pmt.h 2024-04-10 00:53:45 +03:00
711319cce0 Update pmt.h 2024-04-10 00:51:39 +03:00
6dbf7acf3c Update pmt.h 2024-04-10 00:48:11 +03:00
287c75aa67 Rename env.mk to env.mk 2024-04-10 00:41:29 +03:00
1835ecc1e0 pmt: apply version 1.7.0 changes 2024-04-09 23:55:55 +03:00
8afbb2314c pmt: apply version 1.7.0 changes 2024-04-09 23:54:53 +03:00
283346f522 Delete binary/include/documentation.h 2024-04-09 23:54:15 +03:00
c46a65607b pmt: apply version 1.7.0 changes 2024-04-09 23:54:01 +03:00
dd6c1c9faf pmt: apply version 1.7.0 changes 2024-04-09 23:53:27 +03:00
6ab211c1b3 pmt: apply version 1.7.0 changes 2024-04-09 23:47:19 +03:00
372563fceb pmt: apply version 1.7.0 changes 2024-04-09 23:46:45 +03:00
0b34fdbfd9 pmt: apply version 1.7.0 changes 2024-04-09 23:46:15 +03:00
a2aee5c5e8 pmt: apply version 1.7.0 changes 2024-04-09 23:45:38 +03:00
d3d6bfd244 pmt: apply version 1.7.0 changes 2024-04-09 23:32:06 +03:00
97edfbc133 pmt: apply version 1.7.0 changes 2024-04-09 23:31:14 +03:00
b5d4c76b2d pmt: apply version 1.7.0 changes 2024-04-09 23:30:35 +03:00
39b1e67f8e Delete mka/apply-config.mk 2024-04-09 23:29:28 +03:00
1ffd0f90be pmt: apply version 1.7.0 changes 2024-04-09 23:28:21 +03:00
b8a8b7ff8f pmt: apply version 1.7.0 changes 2024-04-09 23:26:20 +03:00
848412e1cd pmt: apply version 1.7.0 changes 2024-04-09 23:24:53 +03:00
8034ed897c Fix changelog link 2024-03-12 20:03:43 +03:00
c8c0687519 pmt: improve build system 2024-03-11 22:34:21 +03:00
c82a127e43 pmt: update err message 2024-03-06 22:50:42 +03:00
6378f8300b Update README.md 2024-03-06 20:47:07 +03:00
80b22ee9c7 pmt: initial 1.5.0 update 2024-03-06 20:39:48 +03:00
e770a80d2a pmt: initial 1.5.0 update 2024-03-06 20:39:18 +03:00
9cd749708d pmt: initial 1.5.0 update 2024-03-06 20:31:17 +03:00
39a5098f71 pmt: initial 1.5.0 update 2024-03-06 20:30:50 +03:00
d7c4ec5236 pmt: initial 1.5.0 update 2024-03-06 20:29:49 +03:00
651c49c3d9 pmt: initial 1.5.0 update 2024-03-06 20:29:15 +03:00
c88c529d2c pmt: initial 1.5.0 update 2024-03-06 20:28:11 +03:00
2d23f45387 pmt: initial 1.5.0 update 2024-03-06 20:26:56 +03:00
67d4c86dfd pmt: initial 1.5.0 update 2024-03-06 20:26:25 +03:00
682e7657fd pmt: initial 1.5.0 update 2024-03-06 20:26:05 +03:00
c91cb25c65 pmt: initial 1.5.0 update 2024-03-06 20:25:30 +03:00
d91f9279cc pmt: initial 1.5.0 update 2024-03-06 20:23:44 +03:00
099e9d2ba6 pmt: initial 1.5.0 update 2024-03-06 20:23:09 +03:00
56638ab00e pmt: initial 1.5.0 update 2024-03-06 20:22:35 +03:00
7fd5e1768e pmt: initial 1.5.0 update 2024-03-06 20:21:50 +03:00
b045bf9b87 Add headers 2024-03-04 23:57:56 +03:00
a5ded6a26e pbt: upgrade to 1.5.0 2024-03-04 23:54:36 +03:00
48bc47c1e2 Clean 2024-03-04 23:36:27 +03:00
bbf4ff76cb pbt: add some funcs 2024-03-04 23:32:02 +03:00
9260b35ae6 Update common.h 2024-03-04 23:28:25 +03:00
6064ba2ee1 pbt: update binary 2024-03-04 23:23:27 +03:00
21e7daac0f pbt: add global variables, macros 2024-03-04 23:17:13 +03:00
ddbbffff6b pbt: Let's make a change... 2024-03-04 23:01:50 +03:00
aaf0bc6660 pbt: add banner 2024-03-04 22:51:31 +03:00
d536844f1c pbt: add banner 2024-03-04 22:51:13 +03:00
7dd8694da1 pbt: add banner 2024-03-04 22:49:40 +03:00
ac6d22e58d tb8765ap1_bsp: add banner 2024-03-04 22:49:06 +03:00
189f3078ae tb8765ap1_bsp: change syntax and add banner 2024-03-04 22:48:26 +03:00
9acb17bd10 pbt: update the version and add a new feature 2024-03-04 22:43:54 +03:00
a7da00190f pbt: upgrade version info 2024-03-04 22:41:54 +03:00
29 changed files with 1568 additions and 580 deletions

11
CHANGELOG.md Executable file
View File

@@ -0,0 +1,11 @@
### Version 2.1.0 (code 210) changelog
- The main usage structure has been changed.
- A more organized and functional code was provided. For example, separate values were not used for the same type of control all the time. Everything was done with a single function.
- Smoother error processing was performed.
- There were a lot of arguments, it was cleared up. So the usage change I mentioned above has occurred.
- The exit codes were organized according to the sysexits library.
- Better deb builder script.
- In short, a lot of missing and errors that happened in 2.0.0 have been fixed
| END OF VERSION 2.1.0 CHANGELOG |
|------------------------------------|

4
DISCLAIMER Normal file → Executable file
View File

@@ -1,6 +1,6 @@
WARNING:
Disclaimer of Liability Regarding the Use of the C Library
- This library is intended for the user to backup the C android partitions. However, we do not accept responsibility for any problems or losses that may arise during its use.
- This library is intended for the user to manage the C android partitions. However, we do not accept responsibility for any problems or losses that may arise during its use.
- Users should carefully test the library functions and, if necessary, implement their own error management mechanisms.
- The authors reserve the right to make any changes or updates related to the library.
- This library is intended for backing up android partitions and its suitability for any specific project or application is not guaranteed. It is important for users to evaluate the suitability of their own projects.
- This library is intended for management android partitions and its suitability for any specific project or application is not guaranteed. It is important for users to evaluate the suitability of their own projects.

0
LICENSE Normal file → Executable file
View File

113
Makefile
View File

@@ -1,113 +0,0 @@
include mka/config.mk
# By YZBruh
# Copyright 2024 YZBruh - Partition Backupper
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# speficy
VERSION := 1.4.0
VERSION_CODE := 140
SOURCE_DIR := binary
TARGET := pbt
ARCH := $(shell uname -m)
# code list
OBJS= $(SOURCE_DIR)/pbt.o
SRCS := $(SOURCE_DIR)/pbt.c
# gcc flags
LDFLAGS :=
LDLIBS := -lm
# display
all:
@printf " --- Building Partition Backupper --- \n"; \
printf "Version: $(VERSION)\n"; \
printf "Version code: $(VERSION_CODE)\n"; \
printf " \n"; \
printf " ------------------------------------- \n"; \
printf " \n"; \
printf "Starting build... Please waith.\n"; \
sleep 2; \
printf "Make running with silent mode...\n"; \
make -s pbt;
# build progress
.PHONY: $(TARGET)
$(TARGET): $(OBJS)
$(LD) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
@mkdir -p out; \
mkdir -p out/binary; \
mkdir -p out/package; \
mv pbt out/binary; \
printf "Generating gzip package...\n"; \
cp out/binary/pbt out/package; \
gzip -f out/package/pbt; \
mv out/package/pbt.gz out/package/pbt_$(ARCH).gz; \
printf " \n"; \
printf " ------------------------------------- \n";
# cleaner functions
.PHONY: clean
clean:
@printf "Cleaning (builded files [.o extended])...\n"; \
sleep 2; \
rm -rf $(OBJS); \
printf "Success\n";
.PHONY: clean-all
clean-all:
@printf "Cleaning (builded files [.o extended] and binary)...\n"; \
sleep 2; \
rm -rf $(OBJS) out; \
printf "Success\n";
# helper function
.PHONY: help
help:
@printf " --------- Partition Backupper help ---------\n"; \
printf " \n"; \
printf " Commands;\n"; \
printf " make ==> Build Partition Backupper\n"; \
printf " make clean ==> Clear files (Builded binaries are not deleted)\n"; \
printf " make clean-all ==> Clear files (Builded binaries are deleted)\n"; \
printf " make install-termux ==> If you are using termux, it installs the compiled pbt into termux. So it allows you to use it like a normal command.\n"; \
printf " make help ==> Display help message\n"; \
printf " \n";
.PHONY: install-termux
install-termux:
@arch=$$(uname -m); \
if [ "$$arch" = "aarch64" ]; then \
printf " ------------------------------------- \n"; \
printf " pbt installer \n"; \
printf " ------------------------------------- \n"; \
cp out/binary/pbt /data/data/com.termux/files/usr/bin/pbt; \
chmod 777 /data/data/com.termux/files/usr/bin/pbt; \
printf " \n"; \
printf "Success.\n"; \
printf " \n"; \
elif [ "$$arch" = "armv7l" ]; then \
printf " ------------------------------------- \n"; \
printf " ptb installer \n"; \
printf " ------------------------------------- \n"; \
cp out/pbt /data/data/com.termux/files/usr/bin/pbt; \
chmod 777 /data/data/com.termux/files/usr/bin/pbt; \
printf " \n"; \
printf "Success.\n"; \
printf " \n"; \
else \
printf "This function is only available on Termux Android devices using aarch64 (64-bit) and armv7l (32-bit)\n"; \
fi

2
NOTICE Normal file → Executable file
View File

@@ -1,4 +1,4 @@
Copyright 2024 YZBruh - Partition Backupper
Copyright 2024 Partition Manager
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

125
README.md Normal file → Executable file
View File

@@ -1,68 +1,97 @@
## Partition Backupper (pbt)
## Partition Manager (pmt)
This binary static C library is for backing up partitions of android devices.
This binary C is for manage partitions of android devices.
It offers a lot of options. I will place these below. But first let me talk about the operation...
```
1. The partition name is obtained (with the -p or --partition argument)
2. Other arguments (if used) are processed.
3. It is backed up using DD. If the progress is not a problem, it is not given (DD)
```
#### Presented arguments (options)
```
Usage (arguments):
-p, --partition name of the partition to be backed up
-l, --logical know that the partition that will be backed up is logical
-o, --out the output name of the backed-up partition (default: partition name)
-d, --outdir directory where the backup partition will be saved (default: /storage/emulated/0)
-c, --context it is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name)
-D, --list list partitions
-v, --version see version
-h, --help see help message
-L, --license see license
Usage:
pmt backup PARTITION [OUTPUT] [OPTIONS]...
pmt flash FILE PARTITION [OPTIONS]...
pmt format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...
Example 1:
-p boot_a -o boot_slot_a_image -d /sdcard/backup -c /dev/block/platform/bootdevice/by-name
Options:
-l | --logical it is meant to determine whether the target partition is logical
-c | --context it is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name)
-p | --list list partitions
-s | --silent information and warning messages are silenced in normal work.
-f | --force force mode. Error messages are silenced and some things are ignored.
-v | --version see version
--help see help message
-L | --license see license
Example 2:
-c /dev/block/platform/bootdevice/by-name --list
Examples:
pmt backup boot_a -c /dev/block/platform/bootdevice/by-name
pmt flash /sdcard/twrp/boot.img boot_a -c /dev/block/platform/bootdevice/by-name
pmt format ext4 system_a --logical
pmt -c /dev/block/platform/bootdevice/by-name --list
Report bugs to <xda-@YZBruh>
Report bugs to <t.me/YZBruh>
```
For example, if we want to back up the `boot_a` partition: `pbt -p boot_a` (edit the command if it has a different name).
#### Some notes
- Feel free to ask any questions you want.
- Packages are available in publications.
- it is mandatory to use the `-p` | `--partition` argument. After all, a partition name is required to be backed up.
- If the logical partition flag is not used, a classic partition is tried to be backed up by default.
- If the logical partition flag is not used, a classic partition is tried to be processing by default.
- [Click to see special version changes](https://github.com/YZBruh/pbt/blob/2.1.0-en/CHANGELOG.md)
- Let me know your suggestions!
### How is it built?
Even termux is enough to build the pbt. Or you can compile it with linux if you want. NOTE: Use a custom gcc according to the architecture you want to compile.
Android NDK is required to build.
- [Download](https://developer.android.com/ndk/downloads) and extract the NDK package.
- Clone this repository. And get access to it.
```
git clone https://github.com/YZBruh/pbt -b 2.1.0 ./pmt
cd pmt
```
- Set the NDK working directory variable.
```
export NDK_PROJECT_PATH=$(pwd)
```
- Go to the NDK directory and start the construction
```
./ndk-build
```
- The output files will be inside the `pmt` folder. Binaries are available in two architectures within the `libs` folder. `arm64-v8a` (64-bit) and `armeabi-v7a` (32-bit).
```
pmt/
|
________________|________________
| | | |
jni/ debutils/ obj/ libs/
|
__________|__________
| |
arm64-v8a/ armeabi-v7a/
| |
pmt pmt
```
- For the make installable debian package make-deb.sh use the script. It can be created within two architectures. Use the script flags correctly: arm64-v8a, armeabi-v7a. If you want to process with root, add sudo as the second argument. If you don't want, use no-sudo or leave it blank
```
--Usage--
./make-deb.sh [arm64-v8a, armeabi-v7a] [sudo, no-sudo, <blank>]
```
```
chmod 777 make-deb.sh
# for making 64-bit package
./make-deb.sh arm64-v8a
# for making 32-bit package
./make-deb.sh armeabi-v7a
```
### Easy install on termux
- Just execute this command in termux:
```shell
curl -LSs "https://raw.githubusercontent.com/YZBruh/pbt/2.1.0/install-termux.sh" | bash -
```
### Notes
If you want to change something, take a look at the configuration. You can change him.
it is located in the `mka` folder. His name is `config.mk`. I gave the information in the file. You can ask more.
To build;
```
make
```
Special `make` commands (pbt offers :) ;
```
--------- Partition Backupper help ---------
Commands;
make ==> Build Partition Backupper
make clean ==> Clear files (Builded binaries are not deleted)
make clean-all ==> Clear files (Builded binaries are deleted)
make install-termux ==> If you are using termux, it installs the compiled pbt into termux. So it allows you to use it like a normal command.
make help ==> Display help message
```
I compiled it with termux :D. Why should I bother... I compiled it with `GCC 17.0.6`. You can look at the version with the viewing option :)
it is located in the `jni/config` folder. His name is `env.mk`. I gave the information in the file. You can ask more.

View File

@@ -1,54 +0,0 @@
#ifndef _DOCUMENTATION_H_
#define _DOCUMENTATION_H_
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Backupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
void licenses() {
printf("Copyright 2024 YZBruh - Partition Backupper\n");
printf("Licensed under the Apache License, Version 2.0 (the \"License\");\n");
printf("you may not use this file except in compliance with the License.\n");
printf("You may obtain a copy of the License at\n\n");
printf(" http://www.apache.org/licenses/LICENSE-2.0\n\n");
printf("Unless required by applicable law or agreed to in writing, software\n");
printf("distributed under the License is distributed on an \"AS IS\" BASIS,\n");
printf("WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
printf("See the License for the specific language governing permissions and limitations under the License.\n");
}
void help() {
printf("Usage (arguments): \n");
printf(" -p, --partition name of the partition to be backed up\n");
printf(" -l, --logical know that the partition that will be backed up is logical\n");
printf(" -o, --out the output name of the backed-up partition (default: partition name)\n");
printf(" -d, --outdir directory where the backup partition will be saved (default: /storage/emulated/0)\n");
printf(" -c, --context it is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name)\n");
printf(" -D, --list list partitions\n");
printf(" -v, --version see version\n");
printf(" -h, --help see help message\n");
printf(" -L, --license see license\n\n");
printf("Example 1:\n");
printf(" -p boot_a -o boot_slot_a_image -d /sdcard/backup -c /dev/block/platform/bootdevice/by-name\n\n");
printf("Example 2:\n");
printf(" -c /dev/block/platform/bootdevice/by-name --list\n\n");
printf("Report bugs to <xda-@YZBruh>\n");
}
/* end of code */
#endif

View File

@@ -1,166 +0,0 @@
#ifndef _PBT_H_
#define _PBT_H_
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Packupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* add pre-function important */
char *out;
char *outdir;
char *my_out;
char *cust_cxt;
bool use_cust_cxt = false;
bool pbt_ab = false;
bool pbt_logical = false;
/* shorter error messages will be functional xd */
void error(const char *err_msg) {
fprintf(stderr, ANSI_RED "%s" ANSI_RESET, err_msg);
exit(EXIT_FAILURE);
}
/* check if the device is ab partitioned */
void check_psf() {
/* true = ab | false = a */
if (use_cust_cxt) {
char cust_cxt_ckpath[150];
sprintf(cust_cxt_ckpath, "%s/boot_a", cust_cxt);
if (access(cust_cxt_ckpath, F_OK) != 0) {
pbt_ab = false;
} else {
pbt_ab = true;
}
} else {
if (access("/dev/block/by-name/boot_a", F_OK) != 0) {
pbt_ab = false;
} else {
pbt_ab = true;
}
}
/* true = logical | false = classic */
if (use_cust_cxt) {
char cust_cxt_cklpath[150];
sprintf(cust_cxt_cklpath, "%s/super", cust_cxt);
if (access(cust_cxt_cklpath, F_OK) != 0) {
pbt_logical = false;
} else {
pbt_logical = true;
}
} else {
if (access("/dev/block/by-name/super", F_OK) != 0) {
pbt_logical = false;
} else {
pbt_logical = true;
}
}
}
/* list existing partitions */
void listpart() {
if (use_cust_cxt) {
printf("List of classic partitions (%s): \n", cust_cxt);
char cust_cxt_path[150];
sprintf(cust_cxt_path, "ls %s", cust_cxt);
if (system(cust_cxt_path) != 0) {
error("An error occurred when the partition list appears!\n");
}
} else {
printf("List of classic partitions (/dev/block/by-name): \n");
if (system("ls /dev/block/by-name") != 0) {
error("An error occurred when the classic partition list appears!\n");
}
}
if (pbt_logical) {
printf("List of logical partitions (/dev/block/mapper): \n");
if (system("ls /dev/block/mapper") != 0) {
error("An error occurred when the logical partition list appears!\n");
}
}
if (pbt_ab) {
printf("%sWarning: device using A/B partition style.%s\n", ANSI_YELLOW, ANSI_RESET);
}
if (pbt_logical) {
printf("%sWarning: device using logical partition type.%s\n", ANSI_YELLOW, ANSI_RESET);
}
}
/* additional function to perform backup */
void backup(char *target_pt, char *pst) {
char path[200];
if (strstr(pst, "classic") != NULL) {
if (use_cust_cxt) {
sprintf(path, "%s/%s", cust_cxt, target_pt);
} else {
sprintf(path, "/dev/block/by-name/%s", target_pt);
}
} else if (strstr(pst, "logical") != NULL) {
sprintf(path, "/dev/block/mapper/%s", target_pt);
} else {
error("İnvalid partition type!\n");
}
if (access(path, F_OK) == -1) {
error("Partition not found!\n");
} else {
printf("Target partition: %s\nBackupping...\n", target_pt);
}
char cmd[256];
if (my_out != NULL) {
if (out != NULL) {
sprintf(cmd, "dd if=%s of=%s/%s.img status=none", path, my_out, out);
} else {
sprintf(cmd, "dd if=%s of=%s/%s.img status=none", path, my_out, target_pt);
}
} else {
if (out != NULL) {
sprintf(cmd, "dd if=%s of=/storage/emulated/0/%s.img status=none", path, out);
} else {
sprintf(cmd, "dd if=%s of=/storage/emulated/0/%s.img status=none", path, target_pt);
}
}
if (system(cmd) != 0) {
error("Failed!\n");
} else {
if (my_out != NULL) {
if (out != NULL) {
printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, my_out, out, ANSI_RESET);
} else {
printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, my_out, target_pt, ANSI_RESET);
}
} else {
if (out != NULL) {
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, out, ANSI_RESET);
} else {
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, target_pt, ANSI_RESET);
}
}
}
}
/* root checker function */
void verify_root() {
// a quick, easy method to verify root :D
if (chdir("/dev/block") != 0) {
error("Root privileges could not be detected! Please run this binary with root.\n");
}
}
/* end of code */
#endif

View File

@@ -1,173 +0,0 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <stdbool.h>
#include <getopt.h>
#include <stdint.h>
#include <stddef.h>
#define ANSI_RED "\033[31m"
#define ANSI_YELLOW "\033[33m"
#define ANSI_GREEN "\033[32m"
#define ANSI_RESET "\033[0m"
#define PACK_VER "1.4.0"
#define PACK_VER_CODE "140"
#define PACK_NAME "Partition Backupper"
#define PACK_LANG "en"
#include "include/pbt.h"
#include "include/documentation.h"
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Backupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* classic main function (C binary here xd) */
int main(int argc, char *argv[]) {
# ifdef __aarch64__
/* empty */
# elif __armv8l__
/* empty */
# elif __aarch32__
/* empty */
# elif __armv7l__
/* empty */
# else
error("Incompatible architecture was detected. This binary works with only arm (32-bit or 64-bit).\n");
# endif
/* a structure for long arguments... */
struct option long_options[] = {
{"partition", required_argument, 0, 'p'},
{"logical", no_argument, 0, 'l'},
{"out", required_argument, 0, 'o'},
{"outdir", required_argument, 0, 'd'},
{"context", required_argument, 0, 'c'},
{"list", no_argument, 0, 'D'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"license", no_argument, 0, 'L'},
{0, 0, 0, 0}
};
char *argx_target_p;
bool use_argx_p = false;
bool use_logical = false;
int opt;
/* control for each argument */
while ((opt = getopt_long(argc, argv, "p:lo:d:c:DvhL", long_options, NULL)) != -1) {
/* process arguments */
switch (opt) {
case 'p':
argx_target_p = strdup(optarg);
use_argx_p = true;
break;
case 'l':
verify_root();
check_psf();
if (pbt_logical) {
use_logical = true;
} else {
error("This device does not have logical partitions!\n");
}
break;
case 'o':
out = strdup(optarg);
break;
case 'd':
verify_root();
check_psf();
outdir = strdup(optarg);
struct stat out_info;
if (stat(outdir, &out_info) != 0) {
fprintf(stderr, "%s: %s: no such file or directory.\n", argv[0], outdir);
exit(EXIT_FAILURE);
} else {
if (S_ISDIR(out_info.st_mode)) {
my_out = outdir;
} else {
fprintf(stderr, "%s: %s: is a not directory.\n", argv[0], outdir);
exit(EXIT_FAILURE);
}
}
break;
case 'c':
use_cust_cxt = true;
cust_cxt = strdup(optarg);
break;
case 'D':
listpart();
exit(EXIT_SUCCESS);
break;
case 'v':
printf("Version: %s (code %s)\n", PACK_VER, PACK_VER_CODE);
# ifdef __clang__
printf("Compiled by clang version %s\n", __clang_version__);
# endif
printf("See licenses with -L argument.\n");
exit(EXIT_SUCCESS);
break;
case 'h':
help();
exit(EXIT_SUCCESS);
break;
case 'L':
licenses();
exit(EXIT_SUCCESS);
break;
case '?':
printf("Try `%s --help' for more information.\n", argv[0]);
exit(EXIT_FAILURE);
break;
default:
printf("Usage: %s -p, --partition PARTITION [-l, --logical] [-o, --out] [-d, --outdir] [-D, --list] [-v, --version] [-h, --help] [-L, --license]\n", argv[0]);
}
}
verify_root();
check_psf();
/* custom context checker */
if (use_cust_cxt) {
struct stat cxtinfo;
printf("Checking custom context path...\n");
if (stat(cust_cxt, &cxtinfo) == 0) {
if (S_ISDIR(cxtinfo.st_mode)) {
/* empty */
} else {
fprintf(stderr, "%s: %s: is a not directory.\n", argv[0], cust_cxt);
exit(EXIT_FAILURE);
}
} else {
error("The specified context was not found!\n");
}
if (strstr(cust_cxt, "/dev") != 0) {
printf("%sThis custom context is strange...%s", ANSI_YELLOW, ANSI_RESET);
}
}
if (use_argx_p) {
if (use_logical) {
backup(argx_target_p, "logical");
} else {
backup(argx_target_p, "classic");
}
} else {
fprintf(stderr, "%s: required partition name.\nTry `%s --help' for more information.\n", argv[0], argv[0]);
exit(EXIT_FAILURE);
}
}
/* end of code */

9
debutils/DEBIAN/control_32 Executable file
View File

@@ -0,0 +1,9 @@
Source: pmt
Package: pmt
Version: 2.1.0
Architecture: arm
Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc
Priority: optional
Maintainer: YZBruh <yagizzengin73@gmail.com>
Standards-Version: 4.5.0

9
debutils/DEBIAN/control_64 Executable file
View File

@@ -0,0 +1,9 @@
Source: pmt
Package: pmt
Version: 2.1.0
Architecture: aarch64
Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc
Priority: optional
Maintainer: YZBruh <yagizzengin73@gmail.com>
Standards-Version: 4.5.0

BIN
debutils/mandoc/pmt.8.gz Executable file

Binary file not shown.

62
install-termux.sh Normal file
View File

@@ -0,0 +1,62 @@
#!/data/data/com.termux/files/usr/bin/env bash
#
# By YZBruh
#
VERSION="2.1.0"
CUR_DIR="$(pwd)"
TMP_DIR="${CUR_DIR}/tempinstall"
TERMUX_BIN_PREFIX="/data/data/com.termux/files/usr/bin"
UNAME="$(uname -m)"
abort()
{
rm -rf "${TMP_DIR}"
exit 1
}
echo " ------------ pmt installer ------------"
if [[ "${UNAME}" == "aarch64" ]] || [[ "${UNAME}" == "armv8a" ]]; then
ARCH="aarch64"
elif [[ "${UNAME}" == "aarch32" ]] || [[ "${UNAME}" == "armv7a" ]]; then
ARCH="armv7a"
SUB_PREF="eabi"
else
echo " - Unsupported arch: ${UNAME}!"
abort
fi
REL_LINK="https://github.com/YZBruh/pbt/releases/download/${VERSION}/pmt-${ARCH}-linux-android${SUB_PREF}.xz"
if [ -f "${TERMUX_BIN_PREFIX}/pmt" ]; then
echo " - pmt already installed."
exit
fi
if [ ! -f "${TERMUX_BIN_PREFIX}/wget" ]; then
echo " - Installing wget..."
pkg update || abort
pkg install wget || abort
fi
echo " - Downloading latest version of package..."
mkdir -p "${TMP_DIR}" || abort
wget -q -P "${TMP_DIR}" "${REL_LINK}" || abort
echo " - Extracting downloaded package..."
cd "${TMP_DIR}" || abort
xz -d *.xz || abort
cd "${CUR_DIR}" || abort
echo " - Installing..."
cp "${TMP_DIR}/pmt-${ARCH}-linux-android${SUB_PREF}" "${TERMUX_BIN_PREFIX}/pmt" || abort
chmod 777 "${TERMUX_BIN_PREFIX}/pmt" || abort
rm -rf "${TMP_DIR}" || abort
echo -e " - Success.\n"
# end of script

49
jni/Android.mk Executable file
View File

@@ -0,0 +1,49 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
LOCAL_PATH := $(call my-dir)
ENVCONF := $(LOCAL_PATH)/config/env.mk
include $(CLEAR_VARS)
include $(ENVCONF)
# configration
LOCAL_MODULE = pmt
LOCAL_SRC_FILES = \
pmt.c \
versioner.c \
tools.c \
partition_tool.c \
root.c \
listpart.c \
docs.c
# include dirs
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
# compiler flags settings
ifeq ($(ENABLE_DEBUGGING), true)
LOCAL_CFLAGS = -O3 -g -Wall -Wextra $(EXTRA_COMPILER_FLAGS)
else ifeq ($(ENABLE_DEBUGGING), false)
LOCAL_CFLAGS = -O3 -Wall $(EXTRA_COMPILER_FLAGS)
else
$(warning Unknown debugging flag: $(ENABLE_DEBUGGING). Please see: $(PREDIR)/config/env.mk. Using non-debugging flags)
LOCAL_CFLAGS = -O3 -Wall $(EXTRA_COMPILER_FLAGS)
endif
include $(BUILD_EXECUTABLE)
# end

19
mka/config.mk → jni/Application.mk Normal file → Executable file
View File

@@ -1,6 +1,6 @@
# By YZBruh
# Copyright 2024 YZBruh - Partition Backupper
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,16 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# use custom gcc | true or false
USE_CUST_GCC := false
# architecture
APP_ABI := \
arm64-v8a \
armeabi-v7a
# custom gcc ext (if used)
CUST_GCC :=
APP_PLATFORM := android-21
# addionital gcc flags
EXTRA_GCC_FLAGS :=
APP_OPTIM := release
# apply configration
include mka/apply-config.mk
# end of config
# end

26
mka/apply-config.mk → jni/config/env.mk Normal file → Executable file
View File

@@ -1,6 +1,6 @@
# By YZBruh
# Copyright 2024 YZBruh - Partition Backupper
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,16 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# gcc setting
ifeq ($(USE_CUST_GCC), true)
CC := $(CUST_GCC)
LD := $(CUST_GCC)
else
CC := gcc
LD := gcc
endif
#########################################
# #
# Configuration Flags #
# #
# Warning: you can edit #
# #
#########################################
# gcc flag settings
CFLAGS := -O3 -g -Wno-unused-parameter -Wall -Wextra -static $(EXTRA_GCC_FLAGS)
# addionital compiler flags
EXTRA_COMPILER_FLAGS ?=
# end of code
# debugging mode (binary)
ENABLE_DEBUGGING ?= false
# end of environment configuration

68
jni/docs.c Executable file
View File

@@ -0,0 +1,68 @@
/* By YZBruh */
/*
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdio.h>
#include <pmt-docs.h>
extern char* bin_name;
void licenses(void)
{
printf("Copyright 2024 Partition Manager\n");
printf("Licensed under the Apache License, Version 2.0 (the \"License\");\n");
printf("you may not use this file except in compliance with the License.\n");
printf("You may obtain a copy of the License at\n\n");
printf(" http://www.apache.org/licenses/LICENSE-2.0\n\n");
printf("Unless required by applicable law or agreed to in writing, software\n");
printf("distributed under the License is distributed on an \"AS IS\" BASIS,\n");
printf("WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
printf("See the License for the specific language governing permissions and limitations under the License.\n");
}
void help(void)
{
printf("Usage: \n");
printf(" %s backup PARTITION [OUTPUT] [OPTIONS]...\n", bin_name);
printf(" %s flash FILE PARTITION [OPTIONS]...\n", bin_name);
printf(" %s format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...\n\n", bin_name);
printf("Options: \n");
printf(" -l | --logical it is meant to determine whether the target partition is logical\n");
printf(" -c | --context it is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name)\n");
printf(" -p | --list list partitions\n");
printf(" -s | --silent information and warning messages are silenced in normal work.\n");
printf(" -f | --force force mode. Error messages are silenced and some things are ignored.\n");
printf(" -v | --version see version\n");
printf(" --help see help message\n");
printf(" -L | --license see license\n\n");
printf("Examples:\n");
printf(" %s backup boot_a -c /dev/block/platform/bootdevice/by-name\n", bin_name);
printf(" %s flash /sdcard/twrp/boot.img boot_a -c /dev/block/platform/bootdevice/by-name\n", bin_name);
printf(" %s format ext4 system_a --logical\n", bin_name);
printf(" %s -c /dev/block/platform/bootdevice/by-name --list\n\n", bin_name);
printf("Report bugs to <t.me/YZBruh>\n");
}
#if defined(__cplusplus)
}
#endif /* __cplusplus */
/* end of code */

26
jni/include/pmt-docs.h Executable file
View File

@@ -0,0 +1,26 @@
/* By YZBruh */
/*
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
__BEGIN_DECLS
void help(void);
void licenses(void);
__END_DECLS
/* end */

28
jni/include/pmt-versioning.h Executable file
View File

@@ -0,0 +1,28 @@
/* By YZBruh */
/*
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
__BEGIN_DECLS
/* versioning */
#define PMT_MAJOR 2
#define PMT_MINOR 1
#define PMT_PATCHLEVEL 0
__END_DECLS
/* end */

61
jni/include/pmt.h Executable file
View File

@@ -0,0 +1,61 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
__BEGIN_DECLS
#if !defined(__PMT_H_)
#define __PMT_H_
/* some definations */
#define ANSI_RED "\033[31m"
#define ANSI_YELLOW "\033[33m"
#define ANSI_GREEN "\033[32m"
#define ANSI_RESET "\033[0m"
#define PMT_PACKAGE_NAME "Partition Manager"
/* variable definations */
extern char* out;
extern char* cust_cxt;
extern char* target_partition;
extern char* target_flash_file;
extern char* format_fs;
extern char* partition_type;
extern char* bin_name;
extern bool pmt_use_logical;
extern bool pmt_use_cust_cxt;
extern bool pmt_ab;
extern bool pmt_logical;
extern bool pmt_silent;
extern bool pmt_flash;
extern bool pmt_backup;
extern bool pmt_format;
extern bool pmt_force_mode;
/* function definations */
int listpart(void);
void check_dev_point(void);
void check_root(void);
int pmt(unsigned short progress_code);
void version(void);
#endif /* __PMT_H_ */
__END_DECLS
/* end of code */

99
jni/listpart.c Executable file
View File

@@ -0,0 +1,99 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <errno.h>
#include <err.h>
#include <sysexits.h>
#include <dirent.h>
#include <string.h>
#include <pmt.h>
extern bool pmt_use_cust_cxt;
extern bool pmt_ab;
extern bool pmt_logical;
extern bool pmt_silent;
extern bool pmt_force_mode;
extern char* cust_cxt;
extern char* bin_name;
/* list existing partitions */
int listpart(void) {
DIR *dir;
struct dirent *entry;
if (pmt_use_cust_cxt)
{
dir = opendir(cust_cxt);
if (dir == NULL)
{
if (!pmt_force_mode) errx(EX_OSFILE, "could not open: `%s': %s", cust_cxt, strerror(errno));
else return EX_OSFILE;
}
}
else
{
dir = opendir("/dev/block/by-name");
if (dir == NULL)
{
if (!pmt_force_mode) errx(EX_OSFILE, "could not open: `/dev/block/by-name': %s", strerror(errno));
else return EX_OSFILE;
}
}
while ((entry = readdir(dir)) != NULL) printf("%s\n", entry->d_name);
closedir(dir);
dir = NULL;
if (pmt_logical)
{
dir = opendir("/dev/block/mapper");
if (dir == NULL)
{
if (!pmt_silent) errx(EX_OSFILE, "could not open: `/dev/block/mapper': %s", strerror(errno));
else return EX_OSFILE;
}
else printf("List of logical partitions (`/dev/block/mapper'):\n");
}
while ((entry = readdir(dir)) != NULL) printf("%s\n", entry->d_name);
closedir(dir);
dir = NULL;
if (pmt_ab && !pmt_silent) warnx(ANSI_YELLOW "warning: device using A/B partition style." ANSI_RESET);
if (pmt_logical && !pmt_silent) warnx(ANSI_YELLOW "warning: device using logical partition type." ANSI_RESET);
return EX_OK;
}
#if defined(__cplusplus)
}
#endif /* __cplusplus */
/* end of code */

73
jni/partition_tool.c Executable file
View File

@@ -0,0 +1,73 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pmt.h>
extern bool pmt_use_cust_cxt;
extern bool pmt_ab;
extern bool pmt_logical;
extern char* cust_cxt;
static int
search(const char* _Nonnull target) { return access(target, F_OK); }
/* check parts */
void check_dev_point()
{
/* true = ab | false = a */
if (pmt_use_cust_cxt)
{
static char cust_cxt_ck_path[150];
sprintf(cust_cxt_ck_path, "%s/boot_a", cust_cxt);
if (search(cust_cxt_ck_path) != 0) pmt_ab = false;
else pmt_ab = true;
}
else
{
if (search("/dev/block/by-name/boot_a") != 0) pmt_ab = false;
else pmt_ab = true;
}
/* true = logical | false = classic */
if (pmt_use_cust_cxt)
{
static char cust_cxt_ckl_path[150];
sprintf(cust_cxt_ckl_path, "%s/super", cust_cxt);
if (search(cust_cxt_ckl_path) != 0) pmt_logical = false;
else pmt_logical = true;
}
else
{
if (search("/dev/block/by-name/super") != 0) pmt_logical = false;
else pmt_logical = true;
}
}
#if defined(__cplusplus)
}
#endif /* __cplusplus */
/* end */

387
jni/pmt.c Executable file
View File

@@ -0,0 +1,387 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* force use C std (if default is C++) */
#if defined(__cplusplus)
extern "C" {
#endif
/* include needed libs (headers) */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <stdbool.h>
#include <getopt.h>
#include <errno.h>
#include <err.h>
#include <sysexits.h>
#include <pmt.h>
#include <pmt-docs.h>
/* add value to variables that are added globally and are not worth */
char* out = NULL;
char* cust_cxt = NULL;
char* target_partition = NULL;
char* target_flash_file = NULL;
char* partition_type = NULL;
char* format_fs = NULL;
char* bin_name = NULL;
bool pmt_use_logical = NULL;
bool pmt_use_cust_cxt = NULL;
bool pmt_ab = false;
bool pmt_logical = false;
bool pmt_silent = false;
bool pmt_flash = false;
bool pmt_backup = false;
bool pmt_format = false;
bool pmt_force_mode = false;
/* variables for use in control of '-' expression */
static const char* opt_symbol = "-";
static const char* common_symbol_rule = "When entering the attached argument of an option, an argument of another option type cannot be used. In short, the rule is: there can be no '-' at the beginning of the attached argument.";
/**
* He controls whether the '-' sign at
* the beginning of the given word
*/
static void
check_optsym(const char* _Nonnull mystring)
{
if (strncmp(mystring, opt_symbol, 1) == 0)
{
if (!pmt_force_mode) errx(EX_USAGE, "%s", common_symbol_rule);
else exit(EX_USAGE);
}
}
/**
* The target file is controlled by the stat function.
* Files, directories, links and blocks (disks) are for.
* If it is never found, it returns 1 value.
* If he finds 0 value is returned.
* If the desired type is not in -1 value is returned.
*/
static int
search_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
{
struct stat search_stat;
if (stat(filepath, &search_stat) != 0) return 1;
if (strcmp(stype, "dir") == 0)
{
if (S_ISDIR(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "file") == 0)
{
if (S_ISREG(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "blk") == 0)
{
if (S_ISBLK(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "link") == 0)
{
if (S_ISLNK(search_stat.st_mode)) return 0;
else return -1;
}
return 0;
}
/* classic main function (C binary here xd) */
int main(int argc, char* argv[])
{
/* check argument total */
if (argc < 2) errx(EX_USAGE, "missing operand\nTry `%s --help' for more information.", argv[0]);
bin_name = argv[0];
/* a structure for long arguments */
struct option long_options[] = {
{"logical", no_argument, 0, 'l'},
{"context", required_argument, 0, 'c'},
{"list", no_argument, 0, 'p'},
{"silent", no_argument, 0, 's'},
{"force", no_argument, 0, 'f'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 0},
{"license", no_argument, 0, 'L'},
{0, 0, 0, 0}
};
/* boolean statements (only valid in this file) to distinguish. and pointer from a shortcut for the symbol rule */
static bool wiew_help = false;
static bool wiew_licenses = false;
static bool wiew_version = false;
static bool list_partitions = false;
static bool combo_wiewers = false;
static int search_result = 3;
static int opt;
/* control for each argument */
while ((opt = getopt_long(argc, argv, "lc:psfvL", long_options, NULL)) != -1)
{
/* process arguments */
switch (opt)
{
/* logical partitions option */
case 'l':
check_root();
check_dev_point();
if (pmt_logical) pmt_use_logical = true;
else
{
if (!pmt_force_mode) errx(EX_USAGE, "this device does not have logical partitions!");
else return EX_USAGE;
}
break;
/* context selector option */
case 'c':
pmt_use_cust_cxt = true;
cust_cxt = strdup(optarg);
if (strncmp(cust_cxt, opt_symbol, 1) == 0)
{
if (!pmt_force_mode) errx(EX_USAGE, "%s", common_symbol_rule);
else return EX_USAGE;
}
break;
/* partition lister function */
case 'p':
list_partitions = true;
/* check combo wiewer options and progress */
if (wiew_version || wiew_help || wiew_licenses) combo_wiewers = true;
break;
/* force mode option */
case 'f':
pmt_force_mode = true;
break;
/* silent mode option */
case 's':
pmt_silent = true;
break;
/* version info option */
case 'v':
wiew_version = true;
/* check combo wiewer options and progress */
if (list_partitions || wiew_help || wiew_licenses) combo_wiewers = true;
break;
/* help message opption */
case 0:
wiew_help = true;
/* check combo wiewer options and progress */
if (wiew_version || list_partitions || wiew_licenses) combo_wiewers = true;
break;
/* license wiewer option */
case 'L':
wiew_licenses = true;
/* check combo wiewer options and progress */
if (wiew_version || wiew_help || list_partitions) combo_wiewers = true;
break;
/* for invalid options */
case '?':
printf("Try `%s --help' for more information.\n", argv[0]);
return EX_USAGE;
break;
default:
printf("Usage: %s [backup] flash] [format] [-l | --logical] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", argv[0]);
return EX_USAGE;
}
}
/* stop the program if multiple viewer is used */
if (combo_wiewers) errx(EX_USAGE, "multiple wiewers cannot be used at the same line.");
/* controller to handle viewer */
if (wiew_help)
{
help();
return EX_OK;
}
else if (wiew_version)
{
version();
return EX_OK;
}
else if (wiew_licenses)
{
licenses();
return EX_OK;
}
else if (list_partitions)
{
check_root();
return listpart();
}
/* detect target mode */
static char arg1[20];
sprintf(arg1, "%s", argv[1]);
if (strcmp(arg1, "backup") == 0)
{
if (argc == 2)
{
if (!pmt_force_mode) errx(EX_USAGE, "expected backup argument 2, retrieved 0.");
else return EX_USAGE;
}
target_partition = argv[2];
if (argc != 4) out = target_partition;
else out = argv[3];
check_optsym(target_partition);
check_optsym(out);
pmt_backup = true;
}
else if (strcmp(arg1, "flash") == 0)
{
if (argc == 2)
{
if (!pmt_force_mode) errx(EX_USAGE, "expected flash argument 2, retrieved 0.");
else return EX_USAGE;
}
if (argc == 3)
{
if (!pmt_force_mode) errx(EX_USAGE, "expected flash argument 2, retrieved 0.");
else return EX_USAGE;
}
target_flash_file = argv[2];
target_partition = argv[3];
check_optsym(target_flash_file);
check_optsym(target_partition);
pmt_flash = true;
}
else if (strcmp(arg1, "format") == 0)
{
if (argc == 2)
{
if (!pmt_force_mode) errx(EX_USAGE, "expected format argument 2, retrieved 0.");
else return EX_USAGE;
}
if (argc == 3)
{
if (!pmt_force_mode) errx(EX_USAGE, "expected format argument 2, retrieved 1.");
else return EX_USAGE;
}
format_fs = argv[2];
target_partition = argv[3];
check_optsym(format_fs);
check_optsym(target_partition);
pmt_format = true;
}
/* target control is done */
if (!pmt_backup && !pmt_flash && !pmt_format && !pmt_silent) errx(EX_USAGE, "missing operand.\nTry `%s --help` for more information.", argv[0]);
else return EX_USAGE;
/* prevent multiple mode use */
if (pmt_backup && pmt_flash && pmt_format)
{
if (!pmt_force_mode) errx(EX_USAGE, "multi functions cannot be used in the same command.");
else return EX_USAGE;
}
/* checks */
check_root();
check_dev_point();
if (pmt_format)
{
if (strcmp(format_fs, "ext4") != 0 || strcmp(format_fs, "ext3") != 0 || strcmp(format_fs, "ext2") != 0)
{
if (!pmt_force_mode) errx(EX_USAGE, "formatter: unsupported filesystem: %s", format_fs);
else return EX_USAGE;
}
}
if (pmt_flash)
{
search_result = search_stat(target_flash_file, "file");
if (search_result == 1)
{
if (!pmt_silent) errx(EX_UNAVAILABLE, "cannot stat `%s': %s", target_flash_file, strerror(errno));
else return EX_UNAVAILABLE;
}
else if (search_result == -1)
{
if (!pmt_silent) errx(EX_USAGE, "`%s': is a not file.", target_flash_file);
else return EX_USAGE;
}
}
/* custom context checker */
if (pmt_use_cust_cxt)
{
search_result = search_stat(cust_cxt, "dir");
if (search_result == 1)
{
if (!pmt_silent) errx(EX_UNAVAILABLE, "cannot stat `%s': %s", cust_cxt, strerror(errno));
else return EX_UNAVAILABLE;
}
else if (search_result == -1)
{
if (!pmt_silent) errx(EX_USAGE, "`%s': is a not directory.", cust_cxt);
else return EX_USAGE;
}
if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode) errx(EX_USAGE, ANSI_YELLOW "you're going through my wave? There's nothing about this /dev. Use force mode if you don't want this error." ANSI_RESET);
}
if (target_partition == NULL)
{
if (!pmt_force_mode)
{
if (!pmt_silent) errx(EX_USAGE, "required partition name.\nTry `%s --help' for more information.\n", argv[0]);
}
else return EX_USAGE;
}
else
{
/**
* 1 = backup mode
*
* 2 = flash mode
*
* 3 = format
*/
if (pmt_backup) return pmt(1);
else if (pmt_flash) return pmt(2);
else if (pmt_format) return pmt(3);
else if (!pmt_silent) errx(EX_USAGE, "no target (backup or flash).\nTry `%s --help` for more information.\n", argv[0]);
}
}
#if defined(__cplusplus)
}
#endif
/* end of code */

46
jni/root.c Executable file
View File

@@ -0,0 +1,46 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>
#include <err.h>
#include <sysexits.h>
#include <pmt.h>
/* root checker function */
void check_root(void)
{
/* a quick, easy method to verify root */
if (getuid() != 0)
{
if (!pmt_force_mode) errx(EX_NOPERM, "root access could not be detected! Please run this binary with root.");
else exit(EX_NOPERM);
}
}
#if defined(__cplusplus)
}
#endif /* __cplusplus */
/* end of code */

332
jni/tools.c Executable file
View File

@@ -0,0 +1,332 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include <errno.h>
#include <err.h>
#include <sysexits.h>
#include <fcntl.h>
#include <pmt.h>
#define BFSIZE 1024
extern char* out;
extern char* format_fs;
extern char* cust_cxt;
extern char* target_partition;
extern char* target_flash_file;
extern char* partition_type;
extern bool pmt_use_logical;
extern bool pmt_use_cust_cxt;
extern bool pmt_logical;
extern bool pmt_flash;
extern bool pmt_backup;
extern bool pmt_silent;
extern bool pmt_force_mode;
/**
* if progress_code is a
* 1 = backup mode
*
* 2 = flash mode
*
* 3 = format mode
*/
/**
* it is meant to calculate the size of the quickly given file.
* its purpose is for rapid processing
*/
static double
calc_flsz(const char* _Nonnull filepath)
{
static int calc_flsz_file;
calc_flsz_file = open(filepath, O_RDONLY);
if (calc_flsz_file == -1) return calc_flsz_file;
static off_t flsz;
flsz = lseek(calc_flsz_file, 0, SEEK_END);
close(calc_flsz_file);
if (flsz == (off_t)-1) return -1;
return (double)flsz / (1024 * 1024);
}
/**
* error that the partition is not found.
* It's for quick action.
*/
static int
partition_not_found(void)
{
if (!pmt_silent) errx(EX_OSFILE, "partition not found!");
else return EX_OSFILE;
}
/**
* unknown partition type error.
* It's for quick action.
*/
static int
invalid_partition_type(void)
{
if (!pmt_silent) errx(EX_USAGE, "invalid partition type!");
else exit(EX_USAGE);
return 0;
}
/* to stop use of function type */
#define partition_not_found partition_not_found()
#define invalid_partition_type invalid_partition_type()
/**
* The target file is controlled by the stat function.
* Files, directories, links and blocks (disks) are for.
* If it is never found, it returns 1 value.
* If he finds 0 value is returned.
* If the desired type is not in -1 value is returned.
*/
static int
search_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
{
struct stat search_stat;
if (stat(filepath, &search_stat) != 0) return 1;
if (strcmp(stype, "dir") == 0)
{
if (S_ISDIR(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "file") == 0)
{
if (S_ISREG(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "blk") == 0)
{
if (S_ISBLK(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "link") == 0)
{
if (S_ISLNK(search_stat.st_mode)) return 0;
else return -1;
}
return 2;
}
/* the partitions are meant to quickly find. */
static void
search_partition(const char* _Nonnull partition)
{
static int partition_results = 0;
partition_results = search_stat(partition, "blk");
if (partition_results == 1) partition_not_found;
else if (partition_results == -1 && !pmt_silent) errx(EX_OSFILE, "the specified partition is not the block. I mean, it's not actually an episode (disc). I'm sure it needs to applaud those mistakes.");
else exit(EX_OSFILE);
}
int pmt(unsigned short progress_code)
{
/* required variables */
static int srcf, targetf;
static char backupper_path[512];
static char ppath[100];
static char formatter_cmd[200];
static char outf[512];
static char flasher_path[512];
static char buffer[BFSIZE];
static ssize_t readed_data;
static unsigned long long copied_data = 0;
static unsigned long long count = 1024 * 1024 * 1024;
if (progress_code == 1)
{
if (!pmt_use_logical)
{
if (pmt_use_cust_cxt) sprintf(backupper_path, "%s/%s", cust_cxt, target_partition);
else sprintf(backupper_path, "/dev/block/by-name/%s", target_partition);
}
else if (pmt_use_logical) sprintf(backupper_path, "/dev/block/mapper/%s", target_partition);
else return invalid_partition_type;
search_partition(backupper_path);
if (calc_flsz(backupper_path) != -1 && !pmt_silent) printf("Disk size of the partition to be backed up: %.2f\n", calc_flsz(backupper_path));
else warnx(ANSI_YELLOW "failed to get target partition disk size" ANSI_RESET);
srcf = open(backupper_path, O_RDONLY);
if (srcf == -1)
{
if (!pmt_silent) errx(EX_OSFILE, "couldn't read: %s: %s", backupper_path, strerror(errno));
else return EX_IOERR;
}
/* determine output */
if (strcmp(out, target_partition) == 0)
{
sprintf(outf, "%s.img", target_partition);
if (!pmt_silent) warnx(ANSI_YELLOW "warning: The output file name was not specified. The output file name will be: %s" ANSI_RESET, outf);
}
else sprintf(outf, "%s", target_partition);
targetf = open(outf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (targetf == -1)
{
if (!pmt_silent) errx(EX_CANTCREAT, "couldn't generate: %s: %s", outf, strerror(errno));
else return EX_CANTCREAT;
}
/* start writing */
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
{
ssize_t writed_data = write(targetf, buffer, readed_data);
if (writed_data != readed_data)
{
if (!pmt_silent) warnx("couldn't write: %s: %s", backupper_path, strerror(errno));
close(srcf);
close(targetf);
if (search_stat(outf, "file") == 0) remove(outf);
return EX_IOERR;
}
copied_data += writed_data;
}
/* close files */
close(srcf);
close(targetf);
if (!pmt_silent) printf("%sSuccess. Output: %s%s\n", ANSI_GREEN, outf, ANSI_RESET);
}
else if (progress_code == 2)
{
/* determine device block */
/* for classic */
if (!pmt_use_logical)
{
if (pmt_use_cust_cxt) sprintf(flasher_path, "%s/%s", cust_cxt, target_partition);
else sprintf(flasher_path, "/dev/block/by-name/%s", target_partition);
/* for logical */
}
else if (pmt_use_logical) sprintf(flasher_path, "/dev/block/mapper/%s", target_partition);
else return invalid_partition_type;
/* check partition */
search_partition(flasher_path);
if (calc_flsz(target_flash_file) != -1 && !pmt_force_mode) printf("Size of flash file: %.2f\n", calc_flsz(target_flash_file));
else warnx(ANSI_YELLOW "failed to get flash file size" ANSI_RESET);
if (calc_flsz(target_partition) != -1 && !pmt_force_mode) printf("Disk size of the target partition: %.2f\n", calc_flsz(target_partition));
else warnx(ANSI_YELLOW "failed to get target partition disk size" ANSI_RESET);
if (calc_flsz(target_flash_file) > calc_flsz(target_partition) && !pmt_silent) errx(EX__BASE, "size of the file to flash more than the partition size.");
else return EX__BASE;
srcf = open(target_flash_file, O_RDONLY);
if (srcf == -1)
{
if (!pmt_force_mode) errx(EX_NOINPUT, "couldn't read: %s: %s", target_flash_file, strerror(errno));
else return EX_IOERR;
}
targetf = open(target_partition, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (targetf == -1)
{
if (!pmt_force_mode) errx(EX_OSFILE, "couldn't read: %s: %s", target_partition, strerror(errno));
else return EX_IOERR;
}
/* start writing */
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
{
ssize_t writed_data = write(targetf, buffer, readed_data);
if (writed_data != readed_data)
{
warnx("couldn't write: %s: %s", backupper_path, strerror(errno));
close(srcf);
close(targetf);
return EX_IOERR;
}
copied_data += writed_data;
}
close(srcf);
close(targetf);
if (!pmt_force_mode) printf("%sSuccess.%s\n", ANSI_GREEN, ANSI_RESET);
}
else if (progress_code == 3)
{
/* generate partition extn */
if (!pmt_use_logical)
{
if (pmt_use_cust_cxt) sprintf(ppath, "%s/%s", cust_cxt, target_partition);
else sprintf(ppath, "/dev/block/by-name/%s", target_partition);
/* for logical */
}
else if (pmt_use_logical) sprintf(ppath, "/dev/block/mapper/%s", target_partition);
else return invalid_partition_type;
/* check partition */
search_partition(ppath);
/* get target partition block size */
struct statvfs file_sys_inf;
if (statvfs(ppath, &file_sys_inf) != 0)
{
if (!pmt_force_mode) errx(EX_TEMPFAIL, "the partition block size could not be obtained!");
else return EX_TEMPFAIL;
}
/* generate mke2fs command */
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, ppath);
/* run command */
if (system(formatter_cmd) != 0)
{
if (!pmt_force_mode) errx(EX_TEMPFAIL, "formatting failed! There may be a chance that something has been damaged!");
else return EX_TEMPFAIL;
}
}
return 0;
}
#if defined(__cplusplus)
}
#endif /* __cplusplus */
/* end of code */

52
jni/versioner.c Executable file
View File

@@ -0,0 +1,52 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdio.h>
#include <android/ndk-version.h>
#include <pmt-versioning.h>
extern char* bin_name;
void version(void)
{
printf("%s version %d.%d.%d (code %d%d%d) ", bin_name, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL);
#if __SIZEOF_POINTER__ == 4
printf("32-bit binary\n");
#elif __SIZEOF_POINTER__ == 8
printf("64-bit binary\n");
#else
printf("<unknown> binary\n");
#endif
#if defined(__clang__)
printf("Compiler: clang %d.%d.%d (NDK major r%d)\n", __clang_major__, __clang_minor__, __clang_patchlevel__, __NDK_MAJOR__);
#endif
printf("See licenses with -L argument.\n");
}
#if defined(__cplusplus)
}
#endif /* __cplusplus */
/* end of code */

154
make-deb.sh Executable file
View File

@@ -0,0 +1,154 @@
#!/usr/bin/bash
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ANSI color codes
RED='\e[31m'
NC='\e[0m'
# needed variables
VERSION="2.1.0"
CUR_DIR=$(pwd)
LIB_DIR=${CUR_DIR}/libs
ARMV8A_DIR=${LIB_DIR}/arm64-v8a
ARMV7A_DIR=${LIB_DIR}/armeabi-v7a
DEB_DIR=${CUR_DIR}/deb
DEBUTILS_DIR=${CUR_DIR}/debutils
DEBTERMUX_USR=${DEBUTILS_DIR}/data/data/com.termux/files/usr
# error messages
abort() {
if [ ! "$1" = "" ]; then
printf "${RED}${1}${NC}\n"
fi
if [ -d ${DEBUTILS_DIR}/temp ]; then
rm -rf ${DEBUTILS_DIR}/temp
fi
exit 1
}
# detect arch flag
case "$1" in
arm64-v8a)
PREFIX="64"
ARM_PREFIX="-v8a"
;;
armeabi-v7a)
PREFIX="32"
ARM_PREFIX=""
;;
*)
abort " - Error: unknown architecture flag: $1. Avaiable: arm64-v8a & armeabi-v7a.\n"
esac
case "$2" in
sudo)
SUDO="sudo"
;;
no-sudo)
SUDO=""
;;
*)
SUDO=""
esac
# set file modes (all) to 755
${SUDO} chmod -R 755 *
# start
printf " --------- pmt deb package maker ---------\n";
printf " - Checking all files and directories (only
eededs)...\n";
# check all important files
if [ ! -d ${DEBUTILS_DIR} ]; then
abort " - Not found: ${DEBUTILS_DIR}\n"
fi
if [ ! -d ${DEBUTILS_DIR}/DEBIAN ]; then
abort " - Not found: ${DEBUTILS_DIR}/DEBIAN\n"
fi
if [ ! -d ${DEBUTILS_DIR}/mandoc ]; then
abort " - Not found: ${DEBUTILS_DIR}/mandoc\n"
fi
if [ ! -d ${DEBUTILS_DIR}/data/data/com.termux ]; then
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux\n"
fi
if [ ! -d ${DEBUTILS_DIR}/data/data/com.termux/files/usr ]; then
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux/files/usr\n"
fi
if [ ! -d ${DEBUTILS_DIR}/data/data/com.termux/files/usr/bin ]; then
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux/files/usr/bin\n"
fi
if [ ! -d ${DEBUTILS_DIR}/data/data/com.termux/files/usr/share/man/man8 ]; then
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux/files/usr/share/man/man8\n"
fi
if [ ! -f ${DEBUTILS_DIR}/mandoc/pmt.8.gz ]; then
abort " - Not found: ${DEBUTILS_DIR}/mandoc/pmt.8.gz\n"
fi
if [ ! -f ${DEBUTILS_DIR}/DEBIAN/control_32 ]; then
abort " - Not found: ${DEBUTILS_DIR}/DEBIAN/control_32\n"
fi
if [ ! -f ${DEBUTILS_DIR}/DEBIAN/control_64 ]; then
abort " - Not found: ${DEBUTILS_DIR}/DEBIAN/control_64\n"
fi
if [ ! -f ${ARMV8A_DIR}/pmt ]; then
abort " - Package not comptely builded! Please build package and try again\n"
elif [ ! -f ${ARMV7A_DIR}/pmt ]; then
abort " - Package not comptely builded! Please build package and try again\n"
fi
# generate template dir
printf " - Generating template dir...\n"
${SUDO} mkdir -p ${DEBUTILS_DIR}/temp || abort
# generate out dir
printf " - Generating out dir...\n"
${SUDO} mkdir -p ${DEB_DIR} || abort
# copy files
printf " - Copying files...\n"
${SUDO} cp -r ${DEBUTILS_DIR}/data ${DEBUTILS_DIR}/temp || abort
${SUDO} rm -f ${DEBTERMUX_USR}/share/man/man8/dummy
${SUDO} rm -f ${DEBTERMUX_USR}/bin/dummy
${SUDO} mkdir -p ${DEBUTILS_DIR}/temp/DEBIAN || abort
# select control file
printf " - Selected arm-${PREFIX} package control file.\n"
${SUDO} cp ${DEBUTILS_DIR}/DEBIAN/control_${PREFIX} ${DEBUTILS_DIR}/temp/DEBIAN/control || exit 1
${SUDO} cp ${DEBUTILS_DIR}/mandoc/pmt.8.gz ${DEBTERMUX_USR}/share/man/man8 || abort
if [ "${PREFIX}" = "64" ]; then
${SUDO} cp ${ARMV8A_DIR}/pmt ${DEBTERMUX_USR}/bin || abort
elif [ "${PREFIX}" = "32" ]; then
${SUDO} cp ${ARMV7A_DIR}/pmt ${DEBTERMUX_USR}/bin || abort
fi
# start dpkg-deb
printf " - Starting dpkg-deb...\n"
sleep 2
${SUDO} chmod -R 755 *
# if ARM_PREFIX is '-v7a', unset ARM_PREFIX and PREFIX. Re set PREFIX
if [ "${PREFIX}" = "32" ]; then
unset PREFIX
PREFIX="eabi-v7a"
fi
${SUDO} dpkg-deb -b ${DEBUTILS_DIR}/temp ${DEB_DIR}/pmt-${VERSION}-arm${PREFIX}${ARM_PREFIX}.deb || abort
${SUDO} rm -rf ${DEBUTILS_DIR}/temp
printf " - Done! Package: ${DEB_DIR}/pmt-${VERSION}-arm${PREFIX}${ARM_PREFIX}.deb\n"
# end of script