Update binary dump method
This commit is contained in:
parent
9929e7d8e8
commit
30eb4074cb
30
build.py
30
build.py
@ -42,6 +42,7 @@ else:
|
|||||||
ndk_build = os.path.join(os.environ['ANDROID_HOME'], 'ndk-bundle', 'ndk-build')
|
ndk_build = os.path.join(os.environ['ANDROID_HOME'], 'ndk-bundle', 'ndk-build')
|
||||||
|
|
||||||
cpu_count = multiprocessing.cpu_count()
|
cpu_count = multiprocessing.cpu_count()
|
||||||
|
archs = ['armeabi-v7a', 'x86']
|
||||||
|
|
||||||
def mv(source, target):
|
def mv(source, target):
|
||||||
try:
|
try:
|
||||||
@ -79,13 +80,13 @@ def zip_with_msg(zipfile, source, target):
|
|||||||
zipfile.write(source, target)
|
zipfile.write(source, target)
|
||||||
|
|
||||||
def build_all(args):
|
def build_all(args):
|
||||||
build_binary(args)
|
|
||||||
build_apk(args)
|
build_apk(args)
|
||||||
|
build_binary(args)
|
||||||
zip_main(args)
|
zip_main(args)
|
||||||
zip_uninstaller(args)
|
zip_uninstaller(args)
|
||||||
|
|
||||||
def collect_binary():
|
def collect_binary():
|
||||||
for arch in ['armeabi-v7a', 'x86']:
|
for arch in archs:
|
||||||
mkdir_p(os.path.join('native', 'out', arch))
|
mkdir_p(os.path.join('native', 'out', arch))
|
||||||
for bin in ['magisk', 'magiskinit', 'magiskboot', 'busybox', 'b64xz']:
|
for bin in ['magisk', 'magiskinit', 'magiskboot', 'busybox', 'b64xz']:
|
||||||
source = os.path.join('native', 'libs', arch, bin)
|
source = os.path.join('native', 'libs', arch, bin)
|
||||||
@ -139,16 +140,13 @@ def build_binary(args):
|
|||||||
flags = base_flags
|
flags = base_flags
|
||||||
|
|
||||||
if 'magiskinit' in targets:
|
if 'magiskinit' in targets:
|
||||||
# We need to create dump.h beforehand
|
for arch in archs:
|
||||||
if not os.path.exists(os.path.join('native', 'out', 'armeabi-v7a', 'magisk')):
|
bin_file = os.path.join('native', 'out', arch, 'magisk')
|
||||||
|
if not os.path.exists(bin_file):
|
||||||
error('Build "magisk" before building "magiskinit"')
|
error('Build "magisk" before building "magiskinit"')
|
||||||
for arch in ['armeabi-v7a', 'x86']:
|
with open(os.path.join('native', 'out', arch, 'binaries_arch_xz.h'), 'w') as out:
|
||||||
with open(os.path.join('native', 'out', arch, 'dump.h'), 'w') as dump:
|
with open(bin_file, 'rb') as src:
|
||||||
dump.write('#include "stdlib.h"\n')
|
xz_dump(src, out, 'magisk_xz')
|
||||||
with open(os.path.join('native', 'out', arch, 'magisk'), 'rb') as bin:
|
|
||||||
dump.write('const uint8_t magisk_dump[] = "')
|
|
||||||
dump.write(''.join("\\x{:02X}".format(c) for c in lzma.compress(bin.read(), preset=9)))
|
|
||||||
dump.write('";\n')
|
|
||||||
flags += ' B_INIT=1'
|
flags += ' B_INIT=1'
|
||||||
other = True
|
other = True
|
||||||
|
|
||||||
@ -239,8 +237,18 @@ def build_snet(args):
|
|||||||
with zipfile.ZipFile(source) as zin:
|
with zipfile.ZipFile(source) as zin:
|
||||||
for item in zin.infolist():
|
for item in zin.infolist():
|
||||||
zout.writestr(item.filename, zin.read(item))
|
zout.writestr(item.filename, zin.read(item))
|
||||||
|
rm(source)
|
||||||
header('Output: ' + target)
|
header('Output: ' + target)
|
||||||
|
|
||||||
|
def xz_dump(src, out, var_name):
|
||||||
|
out.write('const static unsigned char {}[] = {{'.format(var_name))
|
||||||
|
for i, c in enumerate(lzma.compress(src.read(), preset=9)):
|
||||||
|
if i % 16 == 0:
|
||||||
|
out.write('\n')
|
||||||
|
out.write('0x{:02X},'.format(c))
|
||||||
|
out.write('\n};\n')
|
||||||
|
out.flush()
|
||||||
|
|
||||||
def gen_update_binary():
|
def gen_update_binary():
|
||||||
update_bin = []
|
update_bin = []
|
||||||
binary = os.path.join('native', 'out', 'armeabi-v7a', 'b64xz')
|
binary = os.path.join('native', 'out', 'armeabi-v7a', 'b64xz')
|
||||||
|
@ -39,7 +39,8 @@
|
|||||||
#include <lzma.h>
|
#include <lzma.h>
|
||||||
#include <cil/cil.h>
|
#include <cil/cil.h>
|
||||||
|
|
||||||
#include "dump.h"
|
#include "binaries_arch_xz.h"
|
||||||
|
|
||||||
#include "magiskrc.h"
|
#include "magiskrc.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "magiskpolicy.h"
|
#include "magiskpolicy.h"
|
||||||
@ -321,7 +322,7 @@ static int unxz(const void *buf, size_t size, int fd) {
|
|||||||
static int dump_magisk(const char *path, mode_t mode) {
|
static int dump_magisk(const char *path, mode_t mode) {
|
||||||
unlink(path);
|
unlink(path);
|
||||||
int fd = creat(path, mode);
|
int fd = creat(path, mode);
|
||||||
int ret = unxz(magisk_dump, sizeof(magisk_dump), fd);
|
int ret = unxz(magisk_xz, sizeof(magisk_xz), fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user