Files
oxmc f6176009b1 Add recovery_ui and recovery_toolkit scaffolding (first draft, not build-tested)
Stages TWRP's GUI engine and standalone tooling as PawletOS-owned modules
instead of a bootable/recovery fork, per the plugin-architecture finding in
NOTES-ota-recovery-ab.md: stock recovery_main.cpp already dlopen()s
librecovery_ui_ext.so and dlsym()s make_device() from it at runtime, so the
UI layer doesn't require touching stock bootable/recovery at all. Confirmed
via source grep that recovery.cpp/install.cpp have zero references into the
partition manager/backup engine/GUI code and vice versa.

recovery_ui/: TWRP's gui/, minuitwrp/, libpixelflinger/ (copied verbatim,
GPL-3.0), plus a new device/ providing PawletTwrpUI (a ScreenRecoveryUI
subclass) and make_device() — written from scratch against stock's
RecoveryUI/ScreenRecoveryUI virtual-method contract, since TWRP's own fork
never ships a make_device() (every real TWRP device provides its own, and
no reference device tree was available to copy from). Top-level Android.bp
defines librecovery_ui_pawlet_twrp, the module TARGET_RECOVERY_UI_LIB should
point at. gui/Android.bp and minuitwrp/Android.bp had their include_dirs
rewritten for the new paths.

recovery_toolkit/: partition manager, backup engine (tar/digest/adbbu/apex),
filesystem/format support (exfat/dosfstools/gpt/fuse/mtp/crypto), scripting
(openrecoveryscript/orscmd/twrpinstall), shared helpers. Source only, no
Android.bp yet for any of it.

Known gap blocking recovery_ui from actually linking: gui/'s libguitwrp
depends on libaosprecovery, built from recovery_toolkit/helpers/twrp.cpp via
a Go Soong plugin (libaosprecovery_defaults.go) not yet ported. Neither repo
has been build-tested — no local AOSP build environment available in this
workspace. See each directory's README.md for a precise done/not-done
breakdown.
2026-07-11 16:34:35 -07:00

167 lines
2.7 KiB
C

/*
* Functions for \oct encoding used in mtab/fstab/swaps/etc.
*
* Based on code from mount(8).
*
* Copyright (C) 2010 Karel Zak <kzak@redhat.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "mangle.h"
#include "c.h"
#define isoctal(a) (((a) & ~7) == '0')
#define from_hex(c) (isdigit(c) ? c - '0' : tolower(c) - 'a' + 10)
#define is_unwanted_char(x) (strchr(" \t\n\\", (unsigned int) x) != NULL)
char *mangle(const char *s)
{
char *ss, *sp;
if (!s)
return NULL;
ss = sp = malloc(4 * strlen(s) + 1);
if (!sp)
return NULL;
while(1) {
if (!*s) {
*sp = '\0';
break;
}
if (is_unwanted_char(*s)) {
*sp++ = '\\';
*sp++ = '0' + ((*s & 0300) >> 6);
*sp++ = '0' + ((*s & 070) >> 3);
*sp++ = '0' + (*s & 07);
} else
*sp++ = *s;
s++;
}
return ss;
}
void unmangle_to_buffer(const char *s, char *buf, size_t len)
{
size_t sz = 0;
if (!s)
return;
while(*s && sz < len - 1) {
if (*s == '\\' && sz + 3 < len - 1 && isoctal(s[1]) &&
isoctal(s[2]) && isoctal(s[3])) {
*buf++ = 64*(s[1] & 7) + 8*(s[2] & 7) + (s[3] & 7);
s += 4;
sz += 4;
} else {
*buf++ = *s++;
sz++;
}
}
*buf = '\0';
}
void unhexmangle_to_buffer(const char *s, char *buf, size_t len)
{
size_t sz = 0;
if (!s)
return;
while(*s && sz < len - 1) {
if (*s == '\\' && sz + 3 < len - 1 && s[1] == 'x' &&
isxdigit(s[2]) && isxdigit(s[3])) {
*buf++ = from_hex(s[2]) << 4 | from_hex(s[3]);
s += 4;
sz += 4;
} else {
*buf++ = *s++;
sz++;
}
}
*buf = '\0';
}
static inline char *skip_nonspaces(const char *s)
{
while (*s && !(*s == ' ' || *s == '\t'))
s++;
return (char *) s;
}
/*
* Returns mallocated buffer or NULL in case of error.
*/
char *unmangle(const char *s, char **end)
{
char *buf;
char *e;
size_t sz;
if (!s)
return NULL;
e = skip_nonspaces(s);
sz = e - s + 1;
if (end)
*end = e;
if (e == s)
return NULL; /* empty string */
buf = malloc(sz);
if (!buf)
return NULL;
unmangle_to_buffer(s, buf, sz);
return buf;
}
#ifdef TEST_PROGRAM
#include <errno.h>
int main(int argc, char *argv[])
{
char *p = NULL;
if (argc < 3) {
fprintf(stderr, "usage: %s --mangle|unmangle <string>\n",
program_invocation_short_name);
return EXIT_FAILURE;
}
if (!strcmp(argv[1], "--mangle")) {
p = mangle(argv[2]);
printf("mangled: '%s'\n", p);
free(p);
}
else if (!strcmp(argv[1], "--unmangle")) {
char *x = unmangle(argv[2], NULL);
if (x) {
printf("unmangled: '%s'\n", x);
free(x);
}
x = strdup(argv[2]);
unmangle_to_buffer(x, x, strlen(x) + 1);
if (x) {
printf("self-unmangled: '%s'\n", x);
free(x);
}
}
return EXIT_SUCCESS;
}
#endif /* TEST_PROGRAM */