Unify rooting via webusb instead of webserial #163

Unify rooting via webusb instead of webserial
 #163 Техника

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

<!— —>

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

stylesuxx opened this issue

Sep 27, 2022

· 9 comments

Многим из вас хорошо известно, что смартфоны производства Oneplus кроме мощной начинки и привлекательной цены всегда славились простотой разблокирования загрузчика, получения Root прав, установки модифицированного рекавери и альтернативных прошивок.

Root для Oneplus 5 можно получить с помощью Skipsoft Unified Android Toolkit

Не стал исключением в этом плане и недавно появившийся на рынке свежий флагман этой компании — смартфон Oneplus 5, получить на котором права пользователя Root оказалось относительно несложно.

Сделать это проще всего будет с помощью универсального инструмента Skipsoft Unified Android Toolkit, который позволяет разблокировать загрузчик, устанавливать модифицированное рекавери и кастомные прошивки, получать root права и многое, многое другое на более чем полутора сотнях моделей Android смартфонов и планшетов.

Пользоваться Skipsoft Unified Android Toolkit достаточно просто: все необходимое для своей работы, включая драйверы для подключения вашего смартфона к компьютеру, он скачает самостоятельно.

Вот как выглядит главное меню этого тулкита:

Root для Oneplus 5 можно получить с помощью Skipsoft Unified Android Toolkit

Как видно на скриншоте выше, с его помощью вы можете установить на свой Oneplus 5 модифицированное рекавери (TWRP) или просто загрузить его на смартфоне, получить root, установит busybox и прочее.

Напомню, что для того, чтобы получить возможность сделать всё это вам нужно будет в первую очередь разрешить в меню основных настроек режим отладки через USB (как это сделать читайте в этом материале), и разблокировку загрузчика (соответствующий пункт для этого вы найдете перейдя в Настройки -> Для разработчиков).

Помимо этого вам пригодится следующая информация:

Как перезагрузить Oneplus 5 в режим FastBoot:

1. Выключите полностью свой смартфон
2. Отключите его от USB кабеля (если он был подключен)
3. Включите смартфон нажав одновременно на кнопки включения и увеличения громкости

Как перезагрузить Oneplus 5 в режим рекавери

1. Перезагрузите смартфон в режим FastBoot, как рассказано выше

2. Нажимая на кнопку уменьшения громкости выберите режим Recovery mode и загрузите его нажав на кнопку включения смартфона

Те, кто привык самостоятельно контролировать процесс установки модифицированного рекавери и получения root, могут воспользоваться инструкцией для смартфона OnePlus 3T, скачав предварительно TWRP для OnePlus 5 из этой ветки форума XDA-Developers.


Изучаем Android. Десять основных команд ADB и fastboot, которые вы должны знать 

ADB Console. Windows приложение для выполнения команд ADB и Fastboot без использования Android SDK 

Лучшие приложения для Android. FlashFire: простой способ установки на смартфоны и планшеты новых прошивок, файлов с обновлениями OTA, модов и пр. 

We will do this by booting the VM with a Redhat Centos ISO image. Then we are modifying some parameters and will end up after one reboot with a rooted UCCX system. This guide is also valid for CUCM / CUPS / UCXN. Supported version for this to work is at least 9.x to 10.x. I guess 8.6 should work also.

This guide will walk you through the rooting process of an UCCX 10.6 system. With the 10.x release Cisco switched from a 32bit Linux to a 64bit Linux. So, when you are on a pre 10.x system, you need a 32bit version of Centos. If you are at least on version 10.x you need the 64 bit version.

I use these:
32bit  http://isoredirect.centos.org/centos/5/isos/i386/
64bit  http://isoredirect.centos.org/centos/6/isos/x86_64/

Things needed for the rooting process of UCCX 10.6:

  • Running Cisco UCCX 10.6 System
  • CentOS-6.6-x86_64-bin-DVD1.iso or equivalent.
  • 15-30 min of time to spend on this

I’m showing this  on a Vmware workstation 7.1 host. Other Vmware versions might/will show a different menu. If you are going to do this, you will be able to figure out where to find the relevant checkboxes. 😉

I suggest taking a snapshot of the system before we begin.

We start by  open the settings window of our UCCX machine. There we map our DVD drive to the Centos ISO image. Check that it will connect on power on.

Unify rooting via webusb instead of webserial
 #163

Then we open the VMX file of your UCCX machine and enter an additional line:

bios.bootDelay = «7000»

When we start the UCCX system, this will give us a 7 sec delay to press ESC in the boot process.Which brings us to the boot menu:

Unify rooting via webusb instead of webserial
 #163

Select «CD-ROM Drive» and press enter.

Unify rooting via webusb instead of webserial
 #163

Select «Rescue installed system».

Unify rooting via webusb instead of webserial
 #163

Unify rooting via webusb instead of webserial
 #163

I prefer to leave it at «us». If you are using a non us keyboard this might be a little bit awkward if you are not used to this.

Unify rooting via webusb instead of webserial
 #163

No need for a network here.

Unify rooting via webusb instead of webserial
 #163

Unify rooting via webusb instead of webserial
 #163

This can be a little bit tricky. Choose your active partition. Easy guess here because I came from 9.02 (ver5) to 10.6 (ver6). So it has to be the sda1 partition.

Unify rooting via webusb instead of webserial
 #163

Unify rooting via webusb instead of webserial
 #163

Unify rooting via webusb instead of webserial
 #163

Unify rooting via webusb instead of webserial
 #163

If you get an error reporting that /mnt/sysimage was mounted read only, you can fix it with:

mount -o rw,remount /mnt/sysimage

After checking is mounted as rw you change your root to the mounted, hopefully active, partition:

bash-4.1# chroot /mnt/sysimage

Now we can start editing the systems config for root access via SSH.

Remove securetty to get rid of TTY restrictions:
sh-4.1# rm /etc/securetty

Allow root login via SSH:
sh-4.1# vim /etc/ssh/sshd_config
Add the line “”.
This one is write protected. So quit by using :wq!.

Set Selinux to permissive:
sh-4.1# vim /etc/selinux/config
Replace “” with “”.
Quit and save.

Reboot the system to verify successful root access.

When the reboot is finished try to ssh to the UCCX system. You should be prompted with this:

There we are. Success! This is intended only for use in lab environments! Don’t use this in production environments.

For those not familiar with the VIM editor there are some good tutorials online. This one has the important stuff covered: http://vim.wikia.com/wiki/Tutorial

In short words:
/FindMe        Search for pattern FindMe. Caution! This is case sensitive.
    n          Next hit
    N          Previous hit
To edit a file press i. This will bring you to the insert mode. Now you can insert and delete text.
When you are done press ESC to leave insert mode.
:q!            To quit without saving. You loose changes made.
:wq            To save and close the file.
:wq!           To save and close the file. Even if it is flagged as read only.

u-root

Build Status
codecov
Go Report Card
CodeQL
GoDoc
Slack
License

Description

u-root embodies four different projects.

Usage

Make sure your Go version is >=1.19.

Download and install u-root either via git:

git clone https://github.com/u-root/u-root
 u-root
go build

The resulting binary will the be placed where go build was invoked

Or install directly with go:

go install github.com/u-root/u-root

Note: The u-root command will end up in $GOPATH/bin/u-root, so you may
need to add $GOPATH/bin to your $PATH.

Templates

To quickly specify a set of commands from u-root, you can use any of the
templates as defined in templates.go.

Examples

Here are some examples of using the u-root command to build an initramfs,
with $UROOT_PATH being the path to where the u-root sources are on the disk
(explicitly specifiying this is only necessary if not running u-root inside the
root of the repository):

u-root


 But running the command outside of the repository root
(cd /tmp  GBB_PATH= u-root)

 Generate an archive with bootloaders

 core and boot are templates that expand to sets of commands
u-root core boot

 Generate an archive with only these given commands
u-root ./cmds/core/{init,ls,ip,dhclient,wget,cat,elvish}

 Generate an archive with all of the core tools with some exceptions
u-root core -cmds/core/{ls,losetup}

 Generate an archive with a tool outside of u-root
git clone https://github.com/u-root/cpu
u-root ./cmds/core/{init,ls,elvish} ./cpu/cmds/cpud

 Generate an archive with a tool outside of u-root, in any PWD
(cd /tmp  GBB_PATH=: u-root ./cmds/core/{init,ls,elvish} ./cmds/cpud)

GBB_PATH is a place that u-root will look for commands. Each colon-separated
GBB_PATH element is concatenated with patterns from the command-line and
checked for existence. For example:

GBB_PATH=/u-root:/u-bmc u-root \
    cmds/core/init \
    cmds/core/elvish \
    cmd/socreset


   $HOME/u-root/cmds/core/init
   $HOME/u-root/cmds/core/elvish
   $HOME/u-bmc/cmd/socreset

Extra Files

You may also include additional files in the initramfs using the -files flag.
If you add binaries with -files are listed, their ldd dependencies will be
included as well. As example for Debian, you want to add two kernel modules for
testing, executing your currently booted kernel:

NOTE: these files will be placed in the $HOME dir in the initramfs.

u-root -files /hello.ko -files /hello2.ko
qemu-system-x86_64 -kernel /boot/vmlinuz- -initrd /tmp/initramfs.linux_amd64.cpio

To specify the location in the initramfs, use <sourcefile>:<destinationfile>.
For example:

u-root -files 

Init and Uinit

u-root has a very simple (exchangable) init system controlled by the -initcmd
and -uinitcmd command-line flags.

  • -initcmd determines what /init is symlinked to. -initcmd may be a
    u-root command name or a symlink target.
  • -uinitcmd is run by the default u-root init after some
    basic file system setup. There is no default, users should optionally supply
    their own. -uinitcmd may be a u-root command name with arguments or a
    symlink target with arguments.
  • After running a uinit (if there is one), init will start a
    shell determined by the -defaultsh argument.
Дополнительно:  Методы решения ошибки 0xc0000221

All three command-line args accept both a u-root command name or a target
symlink path. Only -uinitcmd accepts command-line arguments, however. For
example,

<div dir="auto" data-snippet-clipboard-copy-content="u-root -uinitcmd="echo Go Gopher" ./cmds/core/{init,echo,elvish}

cpio -ivt ../bbin/echo
# lrwxrwxrwx 0 root root 9 Dec 31 1969 init -> bbin/init

qemu-system-x86_64 -kernel $KERNEL -initrd /tmp/initramfs.linux_amd64.cpio -nographic -append "console=ttyS0"
# …
# [ 0.848021] Freeing unused kernel memory: 896K
# 2020/05/01 04:04:39 Welcome to u-root!
# _
# _ _ _ __ ___ ___ | |_
# | | | |____| ‘__/ _ \ / _ \| __|
# | |_| |____| | | (_) | (_) | |_
# \__,_| |_| \___/ \___/ \__|
#
# Go Gopher
# ~/>»>

u-root -uinitcmd= ./cmds/core/{init,echo,elvish}

cpio -ivt  /tmp/initramfs.linux_amd64.cpio


 lrwxrwxrwx   0 root     root            9 Dec 31  1969 init -> bbin/init

qemu-system-x86_64 -kernel  -initrd /tmp/initramfs.linux_amd64.cpio -nographic -append 


 2020/05/01 04:04:39 Welcome to u-root!
                              _





 Go Gopher

Passing command line arguments like above is equivalent to passing the arguments to uinit via a flags file in /etc/uinit.flags, see Extra Files.

Additionally, you can pass arguments to uinit via the uroot.uinitargs kernel parameters, for example:

<div dir="auto" data-snippet-clipboard-copy-content="u-root -uinitcmd="echo Gopher" ./cmds/core/{init,echo,elvish}

cpio -ivt ../bbin/echo
# lrwxrwxrwx 0 root root 9 Dec 31 1969 init -> bbin/init

qemu-system-x86_64 -kernel $KERNEL -initrd /tmp/initramfs.linux_amd64.cpio -nographic -append "console=ttyS0 uroot.uinitargs=Go"
# …
# [ 0.848021] Freeing unused kernel memory: 896K
# 2020/05/01 04:04:39 Welcome to u-root!
# _
# _ _ _ __ ___ ___ | |_
# | | | |____| ‘__/ _ \ / _ \| __|
# | |_| |____| | | (_) | (_) | |_
# \__,_| |_| \___/ \___/ \__|
#
# Go Gopher
# ~/>»>

u-root -uinitcmd= ./cmds/core/{init,echo,elvish}

cpio -ivt  /tmp/initramfs.linux_amd64.cpio


 lrwxrwxrwx   0 root     root            9 Dec 31  1969 init -> bbin/init

qemu-system-x86_64 -kernel  -initrd /tmp/initramfs.linux_amd64.cpio -nographic -append 


 2020/05/01 04:04:39 Welcome to u-root!
                              _





 Go Gopher

Note the order of the passed arguments in the above example.

u-root -uinitcmd= ./cmds/core/{init,elvish}

You can also refer to non-u-root-commands; they will be added as symlinks. We
don’t presume to know whether your symlink target is correct or not.

This will build, but not work unless you add a /bin/foobar to the initramfs.

u-root -uinitcmd=/bin/foobar Go Gopher ./cmds/core/{init,elvish}

This will boot the same as the above.

u-root -uinitcmd=/bin/foobar Go Gopher -files /bin/echo:bin/foobar -files your-hosts-file:/etc/hosts ./cmds/core/{init,elvish}

The effect of the above command:

  • Sets up the uinit command to be /bin/foobar, with 2 arguments: Go Gopher
  • Adds /bin/echo as bin/foobar
  • Adds your-hosts-file as etc/hosts
  • builds in the cmds/core/init, and cmds/core/elvish commands.
    The {} are expanded by the shell

This will bypass the regular u-root init and just launch a shell:

<div dir="auto" data-snippet-clipboard-copy-content="u-root -initcmd=elvish ./cmds/core/{elvish,ls}

cpio -ivt bbin/elvish

qemu-system-x86_64 -kernel $KERNEL -initrd /tmp/initramfs.linux_amd64.cpio -nographic -append "console=ttyS0"
# …
# [ 0.848021] Freeing unused kernel memory: 896K
# failed to put myself in foreground: ioctl: inappropriate ioctl for device
# ~/>»>

u-root -initcmd=elvish ./cmds/core/{elvish,ls}

cpio -ivt  /tmp/initramfs.linux_amd64.cpio

 lrwxrwxrwx   0 root     root            9 Dec 31  1969 init -> bbin/elvish

qemu-system-x86_64 -kernel  -initrd /tmp/initramfs.linux_amd64.cpio -nographic -append 


 failed to put myself in foreground: ioctl: inappropriate ioctl for device

(It fails to do that because some initialization is missing when the shell is
started without a proper init.)

Cross Compilation (targeting different architectures and OSes)

Further, we run integration tests on linux/amd64, freebsd/amd64 and linux/arm64,
using several CI systems. If you need to add another CI system, processor or OS,
please let us know.

To cross compile for an ARM, on Linux:

If you are on OSX, and wish to build for Linux on AMD64:

GOOS=linux GOARCH=amd64 u-root

Testing in QEMU

A good way to test the initramfs generated by u-root is with qemu:

qemu-system-x86_64 -nographic -kernel path/to/kernel -initrd /tmp/initramfs.linux_amd64.cpio

Note that you do not have to build a special kernel on your own, it is
sufficient to use an existing one. Usually you can find one in /boot.

Framebuffer

For framebuffer support, append a VESA mode via the vga kernel parameter:

qemu-system-x86_64 \
  -kernel path/to/kernel \
  -initrd /tmp/initramfs.linux_amd64.cpio \
  -append 

For a list of modes, refer to the
Linux kernel documentation.

Entropy / Random Number Generator

CONFIG_VIRTIO_PCI=y
CONFIG_HW_RANDOM_VIRTIO=y
CONFIG_CRYPTO_DEV_VIRTIO=y

Then you can run your kernel in QEMU with a virtio-rng-pci device:

qemu-system-x86_64 \
    -device virtio-rng-pci \
    -kernel vmlinuz \
    -initrd /tmp/initramfs.linux_amd64.cpio

In addition, you can pass your host’s RNG:

qemu-system-x86_64 \
    -object rng-random,filename=/dev/urandom,id=rng0 \
    -device virtio-rng-pci,rng=rng0 \
    -kernel vmlinuz \
    -initrd /tmp/initramfs.linux_amd64.cpio

u-root with Go package paths

For Go package paths to be usable, the path passed to u-root must be in the
go.mod of the working directory or one of its parents. This is mostly useful for
repositories making programmatic use of u-root’s APIs.

 ./u-root

 In u-root's directory itself, github.com/u-root/u-root is resolvable. There is
 a go.mod here that can refer to u-root.
u-root github.com/u-root/u-root/cmds/core/...
u-root github.com/u-root/u-root/cmds/core/
u-root github.com/u-root/u-root/cmds/core/i

TMPDIR=
 
go mod init foobar

Create a file with some unused build tag like this to create dependencies on
commands:

 something

 (
        
        
        
)

The unused build tag keeps it from being compiled, but its existence forces go mod tidy to add these dependencies to go.mod:

go mod tidy

u-root \
  github.com/u-root/u-root/cmds/core/ip \
  github.com/u-root/u-root/cmds/core/init \
  github.com/hugelgupf/p9/cmd/p9ufs

SystemBoot

SystemBoot is a set of bootloaders written in Go. It is meant to be a
distribution for LinuxBoot to create a system firmware + bootloader. All of
these use kexec to boot. The commands are in cmds/boot.
Parsers are available for GRUB, syslinux,
and other config files to make the transition to LinuxBoot easier.

This project started as a loose collection of programs in u-root by various
LinuxBoot contributors, as well as a personal experiment by
Andrea Barberio that has since been merged
in. It is now an effort of a broader community and graduated to a real project
for system firmwares.

More detailed information about the build process for a full LinuxBoot firmware
image using u-root/systemboot and coreboot can be found in the
LinuxBoot book chapter about
LinuxBoot using coreboot, u-root and systemboot.

You can build systemboot like this:

u-root -uinitcmd=systemboot core ./cmds/boot/{systemboot,localboot,fbnetboot}

Compression

You can compress the initramfs. However, for xz compression, the kernel has some
restrictions on the compression options and it is suggested to align the file to
512 byte boundaries:

xz --check=crc32 -9 --lzma2=dict=1MiB \
   --stdout /tmp/initramfs.linux_amd64.cpio \
    dd conv=sync bs=512 \
   of=/tmp/initramfs.linux_amd64.cpio.xz

Getting Packages of TinyCore

Using the tcz command included in u-root, you can install tinycore linux
packages for things you want.

You can use QEMU NAT to allow you to fetch packages. Let’s suppose, for example,
you want bash. Once u-root is running, you can do this:

The tcz command computes and fetches all dependencies. If you can’t get to
tinycorelinux.net, or you want package fetching to be faster, you can run your
own server for tinycore packages.

You can do this to get a local server using the u-root srvfiles command:

% srvfiles -p 80 -d path-to-local-tinycore-packages

Of course you have to fetch all those packages first somehow 🙂

Build an Embeddable u-root

You can build the cpio image created by u-root into a Linux kernel via the
CONFIG_INITRAMFS_SOURCE config variable or coreboot config variable, and
further embed the kernel image into firmware as a coreboot payload.

In the kernel and coreboot case, you may need to configure ethernet. We have a
dhclient command that works for both ipv4 and ipv6. Since v6 does not yet work
that well for most people, a typical invocation looks like this:

% dhclient -ipv4 -ipv6=false

Or, on newer linux kernels (> 4.x) boot with ip=dhcp in the command line,
assuming your kernel is configured to work that way.

Build Modes

u-root can create an initramfs in two different modes, specified by -build:

Updating Dependencies

go get -u
go mod tidy
go mod vendor

Building without network access

Go modules require network access. If you need to make a repeatable build with
no network access, make sure that your code is under $GOPATH and the
environment variable GO111MODULE is set to off. This is:

  1. Pick a location for your off-network build, it can be anywhere and
    the directory does not need to exist ahead of time:
 GOPATH=
  1. Fetch the code, you can use git, go get or even a release file, just
    make sure that the code ends in: ${GOPATH}/src/github.com/u-root/u-root E.g:

mkdir -p /src/github.com/u-root/
 /src/github.com/u-root/
git clone https://github.com/u-root/u-root.git
 u-root

GO111MODULE=off go get github.com/u-root/u-root
 /src/github.com/u-root/u-root
  1. Build u-root and use it normally:

GO111MODULE=off GOPROXY=off go build
GO111MODULE=off GOPROXY=off ./u-root

Hardware

If you want to see u-root on real hardware, this
board is a good start.

Contributions

For information about contributing, including how we sign off commits, please
see CONTRIBUTING.md.

Improving existing commands (e.g., additional currently unsupported flags) is
very welcome. In this case it is not even required to build an initramfs, just
enter the cmds/ directory and start coding. A list of commands that are on the
roadmap can be found here.

unified

Build
Coverage
Downloads
Size
Sponsors
Backers
Chat

unified lets you inspect and transform content with plugins.

Contents

What is this?

unified is two things:

  • unified is a collective of 500+ free and open source packages that work
    with content as structured data (ASTs)
  • unified (this project) is the core package, used in 800k+ projects on GH,
    to process content with plugins
Дополнительно:  Magisk Manager 24.1

Several ecosystems are built on unified around different kinds of content.
Notably, remark (markdown), rehype (HTML), and retext (natural
language).
These ecosystems can be connected together.

  • for more about us, see unifiedjs.com
  • for updates, see @unifiedjs on Twitter
  • for questions, see support
  • to help, see contribute and sponsor below

When should I use this?

In some cases, you are already using unified.
For example, it’s used in MDX, Gatsby, Docusaurus, etc.
In those cases, you don’t need to add unified yourself but you can include
plugins into those projects.

But the real fun (for some) is to get your hands dirty and work with syntax
trees and build with it yourself.
You can create those projects, or things like Prettier, or your own site
generator.
You can connect utilities together and make your own plugins that check for
problems and transform from one thing to another.

When you are dealing with one type of content (such as markdown), it’s
recommended to use the main package of that ecosystem instead (so remark).
When you are dealing with different kinds of content (such as markdown and
HTML), it’s recommended to use unified itself, and pick and choose the plugins
you need.

Install

This package is ESM only.
In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

In Deno with esm.sh:

   

In browsers with esm.sh:

<div dir="auto" data-snippet-clipboard-copy-content="
import {unified} from ‘https://esm.sh/unified@10?bundle’
«>

 =""
     

Use

   
   
   
   
   
   
   

    
  
  
   : 
  
  
  '# Hello world!'


<div dir="auto" data-snippet-clipboard-copy-content="

👋🌍

Hello world!

«>

 =""
  
     =""
    👋🌍
     ="" =""
  
  
    Hello world!
  

Overview

unified is an interface for processing content with syntax trees.
Syntax trees are a representation of content understandable to programs.
Those programs, called plugins, take these trees and inspect and
modify them.
To get to the syntax tree from text, there is a parser.
To get from that back to text, there is a compiler.
This is the process of a processor.

— | Parser | ->- Syntax Tree ->- | Compiler | ->- Output
+———+ | +———-+
X
|
+—————+
| Transformers |
+—————+»>
| ........................ process ........................... |
| .......... parse ... | ... run ... | ... stringify ..........|

          +--------+                     +----------+
Input ->- | Parser | ->- Syntax Tree ->- | Compiler | ->- Output
          +--------+          |          +----------+
                              X
                              |
                       +--------------+
                       | Transformers |
                       +--------------+
Processors

Processors process content.
On its own, unified (the root processor) doesn’t work.
It needs to be configured with plugins to work.
For example:

   
  
  
   : 
  
  

That processor can do different things.
It can:

Every processor implements another processor.
To create a processor, call another processor.
The new processor is configured to work the same as its ancestor.
But when the descendant processor is configured in the future it does not affect
the ancestral processor.

File

When processing a document, metadata is gathered about that document.
vfile is the file format that stores data, metadata, and messages
about files for unified and plugins.

There are several utilities for working with these files.

Syntax tree

The syntax trees used in unified are unist nodes.
A tree represents a whole document and each node is a plain JavaScript
object with a type field.
The semantics of nodes and the format of syntax trees is defined by other
projects:

Ecosystems
Plugins

Each aforementioned ecosystem comes with a large set of plugins that you can
pick and choose from to do all kinds of things.

There are also a few plugins that work in any ecosystem:

Configuration
Integrations

unified can integrate with the file system through
unified-engine.
CLI apps can be created with unified-args, Gulp plugins with
unified-engine-gulp, and language servers with
unified-language-server.
A streaming interface can be created with unified-stream.

Programming interface

The API provided by unified allows multiple files to be processed and
gives access to metadata (such as lint messages):

   
   
   
   
   
   
   
   
   

    
  
  
   
  
  
  '*Emphasis* and _stress_, you guys!'


  1:16-1:24  warning  Emphasis should use `` as a marker                                  emphasis-marker  remark-lint
  1:30-1:34  warning  `guys` may be insensitive, use `people`, `persons`, `folks` instead  gals-man         retext-equality

⚠ 2 warnings

<div dir="auto" data-snippet-clipboard-copy-content="

Emphasis and stress, you guys!

«>

Emphasis and stress, you guys!
Transforming between ecosystems

Ecosystems can be combined in two modes.

Bridge mode transforms the tree from one format (origin) to another
(destination).
A different processor runs on the destination tree.
Afterwards, the original processor continues with the origin tree.

Mutate mode also transforms the syntax tree from one format to another.
But the original processor continues transforming the destination tree.

In the previous example (“Programming interface”), remark-retext is used in
bridge mode: the origin syntax tree is kept after retext is done; whereas
remark-rehype is used in mutate mode: it sets a new syntax tree and discards
the origin tree.

API

This package exports the identifier unified (the root processor).
There is no default export.

processor()

Create a processor.

Returns

New unfrozen processor (processor) that is configured to work the
same as its ancestor.
When the descendant processor is configured in the future it does not affect the
ancestral processor.

Example

This example shows how a new processor can be created (from remark) and linked
to stdin(4) and stdout(4).

{
process.stdout.write(String(remark().processSync(buf)))
})
)»>
   
   
   


    
    
  

processor.use(plugin[, options])

Configure the processor to use a plugin and optionally configure that plugin
with options.

If the processor is already using a plugin, the previous plugin configuration
is changed based on the options that are passed in.
In other words, the plugin is not added a second time.

👉 : use cannot be called on frozen processors.
Call the processor first to create a new unfrozen processor.

Signatures
Parameters
Returns

The processor that use was called on (processor).

Example

There are many ways to pass plugins to .use().
This example gives an overview:

   


  // Plugin with options:
   :  : 
  
   :  : 
  
   
  // Two plugins, the second with options:
    
  // Preset with plugins and settings:
  :    : : 
  // Settings only:
  : : 

processor.parse(file)

Parse text to a syntax tree.

👉 : parse freezes the processor if not already frozen.

👉 : parse performs the parse phase, not the run phase
or other phases.

Parameters
Returns

Syntax tree representing file (Node).

Example

This example shows how parse can be used to create a tree from a file.

   
   

   '# Hello world!'

  : 
  : 
    :  :  :  : 
  
  : 
    : :  :  : 
    : :  :  : 
  

processor.Parser

A parser handles the parsing of text to a syntax tree.
It is used in the parse phase and is called with a string and
VFile of the document to parse.

Parser can be a normal function, in which case it must return the syntax
tree representation of the given file (Node).

Parser can also be a constructor function (a function with a parse field, or
other fields, in its prototype), in which case it is constructed with new.
Instances must have a parse method that is called without arguments and must
return a Node.

processor.stringify(tree[, file])

Compile a syntax tree.

👉 : stringify freezes the processor if not already
frozen.

👉 : stringify performs the stringify phase, not the run
phase or other phases.

Parameters
Returns

Textual representation of the tree (string or Buffer, see note).

👉 : unified typically compiles by serializing: most
compilers return string (or Buffer).
Some compilers, such as the one configured with
rehype-react, return other values (in this case, a React
tree).
If you’re using a compiler that doesn’t serialize, expect different result
values.

Example

This example shows how stringify can be used to serialize a syntax tree:

   
   
   

    

   

processor.Compiler

A compiler handles the compiling of a syntax tree to something else (in
most cases, text).
It is used in the stringify phase and called with a Node
and VFile representation of the document to compile.

Compiler can be a normal function, in which case it should return the textual
representation of the given tree (string).

Compiler can also be a constructor function (a function with a compile
field, or other fields, in its prototype), in which case it is constructed
with new.
Instances must have a compile method that is called without arguments and
should return a string.

👉 : unified typically compiles by serializing: most compilers
return string (or Buffer).
Some compilers, such as the one configured with
rehype-react, return other values (in this case, a React
tree).
If you’re using a compiler that doesn’t serialize, expect different result
values.

processor.run(tree[, file][, done])

Run transformers on a syntax tree.

👉 : run freezes the processor if not already frozen.

👉 : run performs the run phase, not other phases.

Parameters
Returns

Nothing if done is given (void).
A Promise otherwise.
The promise is rejected with a fatal error or resolved with the transformed
tree (Node).

Example

This example shows how run can be used to transform a tree:

   
   
   

    
   
     :   
  


    

  : 
  : 
    :  : 
    :  :  :  : 
  

function done(err[, tree, file])

Callback called when transformers are done.
Called with either an error or results.

Parameters
Дополнительно:  Что делать если ноутбук не выключается: основное способы как это сделать | Блог Comfy

processor.runSync(tree[, file])

Run transformers on a syntax tree.
An error is thrown if asynchronous transforms are configured.

👉 : runSync freezes the processor if not already
frozen.

👉 : runSync performs the run phase, not other phases.

Parameters
Returns

Transformed tree (Node).

processor.process(file[, done])

Process the given file as configured on the processor.

👉 : process freezes the processor if not already
frozen.

👉 : process performs the parse, run, and stringify
phases
.

Parameters
Returns

Nothing if done is given (void).
A Promise otherwise.
The promise is rejected with a fatal error or resolved with the processed
file (VFile).

The parsed, transformed, and compiled value is available at
file.value (see note).

👉 : unified typically compiles by serializing: most
compilers return string (or Buffer).
Some compilers, such as the one configured with
rehype-react, result in other values (in this case, a React
tree).
If you’re using a compiler that does not serialize, the result is available
at file.result.

Example

This example shows how process can be used to process a file:

   
   
   
   
   
   

    
  
  
   : 
  
  
  '# Hello world!'

<div dir="auto" data-snippet-clipboard-copy-content="

👋🌍

Hello world!

«>

 =""
  
     =""
    👋🌍
     ="" =""
  
  
    Hello world!
  

function done(err, file)

Callback called when the process is done.
Called with either an error or a result.

Parameters
Example

This example shows how process can be used to process a file with a callback.

   
   
   
   
   


  
  
  
      
      
      
      
    
  

processor.processSync(file)

Process the given file as configured on the processor.
An error is thrown if asynchronous transforms are configured.

👉 : processSync freezes the processor if not already
frozen.

👉 : processSync performs the parse, run, and stringify
phases
.

Parameters
Returns

The processed file (VFile).

The parsed, transformed, and compiled value is available at
file.value (see note).

👉 : unified typically compiles by serializing: most
compilers return string (or Buffer).
Some compilers, such as the one configured with
rehype-react, result in other values (in this case, a React
tree).
If you’re using a compiler that does not serialize, the result is available
at file.result.

Example

This example shows how processSync can be used to process a file, if all
transformers are synchronous.

   
   
   
   
   
   

   
  
  
   : 
  
  

'# Hello world!'

<div dir="auto" data-snippet-clipboard-copy-content="

👋🌍

Hello world!

«>

 =""
  
     =""
    👋🌍
     ="" =""
  
  
    Hello world!
  

processor.data([key[, value]])

Configure the processor with info available to all plugins.
Information is stored in an object.

👉 : setting information cannot occur on frozen
processors.
Call the processor first to create a new unfrozen processor.

Signatures
Parameters
Returns
Example

This example show how to get and set info:

‘bravo’

processor.data() // => {alpha: ‘bravo’}

processor.data({charlie: ‘delta’})

processor.data() // => {charlie: ‘delta’}»>

   

    

 // => 'bravo'

 

: 

 

processor.freeze()

Freeze a processor.
Frozen processors are meant to be extended and not to be configured directly.

When a processor is frozen it cannot be unfrozen.
New processors working the same way can be created by calling the processor.

It’s possible to freeze processors explicitly by calling .freeze().
Processors freeze automatically when .parse(), .run(),
.runSync(), .stringify(), .process(),
or .processSync() are called.

Returns

The processor that freeze was called on (processor).

Example

This example, index.js, shows how rehype prevents extensions to itself:

   
   
   

    

That processor can be used and configured like so:

   
   



  
  

A similar looking example is broken as operates on the frozen interface.
If this behavior was allowed it would result in unexpected behavior so an error
is thrown.
This is not valid:

   
   



  
  

~/node_modules/unified/index.js:426
    throw new Error(
    

Error: Cannot call `use` on a frozen processor.
Create a new processor first, by calling it: use `processor()` instead of `processor`.
    at assertUnfrozen (~/node_modules/unified/index.js:426:11)
    at Function.use (~/node_modules/unified/index.js:165:5)
    …

Plugin

Plugins are a concept.
They materialize as Attachers.

Example

<div dir="auto" data-snippet-clipboard-copy-content="/**
* @typedef Options
* Configuration (required).
* @property {string} extname
* File extension to use (must start with `.`).
*/

/** @type {import('unified').Plugin} */
export function move(options) {
if (!options || !options.extname) {
throw new Error(‘Missing `options.extname`’)
}

return function (tree, file) {
if (file.extname && file.extname !== options.extname) {
file.extname = options.extname
}
}
}»>

 *   Configuration (required).

 *   File extension to use (must start with `.`).



   
      
      
  

      
          
        
    
  

    
   
   
   
   
   
   

    
  
  
   : 
  
   


  // Written to `index.html`.
index.md: no issues found

function attacher(options?)

Attachers are materialized plugins.
They are functions that can receive options and configure the processor.

Attachers change the processor, such as the parser, the compiler,
by configuring data, or by specifying how the tree and file are handled.

👉 : attachers are called when the processor is frozen,
not when they are applied.

Parameters
Returns

Optional transform (Transformer).

function transformer(tree, file[, next])

Transformers handle syntax trees and files.
They are functions that are called each time a syntax tree and file are passed
through the run phase.
When an error occurs in them (either because it’s thrown, returned, rejected,
or passed to next), the process stops.

The run phase is handled by trough, see its documentation for the
exact semantics of these functions.

Parameters
Returns

function next(err[, tree[, file]])

If the signature of a transformer accepts a third argument, the transformer
may perform asynchronous operations, and must call next().

Parameters

Preset

Presets are sharable configuration.
They can contain plugins and settings.

Example
   
   
   
   
   

    
  : :  :  : 
  : 
    
    
    
     :  : 
    
  

# 

Emphasis and importance.

## Table of contents



    
   
   
   

    
  
   


 
example.md: no issues found

example.md now contains:

# 

Emphasis and importance.

## Table of contents

   API
   License





MIT © Titus Wormer

Types

<div dir="auto" data-snippet-clipboard-copy-content="/**
* @typedef {import('mdast').Root} MdastRoot
* @typedef {import('hast').Root} HastRoot
*
* @typedef Options
* Configuration (optional).
* @property {boolean} [someField]
* Some option.
*/

// To type options:
/** @type {import('unified').Plugin} */
export function myPluginAcceptingOptions(options) {
// `options` is `Options?`.
}

// To type a plugin that works on a certain tree:
/** @type {import(‘unified’).Plugin} */
export function myRemarkPlugin() {
return function (tree, file) {
// `tree` is `MdastRoot`.
}
}

// To type a plugin that transforms one tree into another:
/** @type {import(‘unified’).Plugin} */
export function remarkRehype() {
return function (tree) {
// `tree` is `MdastRoot`.
// Result must be `HastRoot`.
}
}

// To type a plugin that defines a parser:
/** @type {import(‘unified’).Plugin} */
export function remarkParse(options) {}

// To type a plugin that defines a compiler:
/** @type {import(‘unified’).Plugin} */
export function rehypeStringify(options) {}»>




 *   Configuration (optional).

 *   Some option.


// To type options:

   
  // `options` is `Options?`.


// To type a plugin that works on a certain tree:

   
      
    // `tree` is `MdastRoot`.
  


// To type a plugin that transforms one tree into another:

   
     
    // `tree` is `MdastRoot`.
    // Result must be `HastRoot`.
  


// To type a plugin that defines a parser:

   

// To type a plugin that defines a compiler:

   

Compatibility

Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.

Contribute

See contributing.md in unifiedjs/.github for ways
to get started.
See support.md for ways to get help.

This project has a code of conduct.
By interacting with this repository, organization, or community you agree to
abide by its terms.

For info on how to submit a security report, see our
security policy.

Support this effort and give back by sponsoring on OpenCollective!

Acknowledgments

License

Comments

@stylesuxx

@j005u

@stylesuxx




Copy link

Ah yeah, right — now I can remember why I did not use it in the first place — this has actually been an issue with my other configurator too: there are no remove and connect listeners, I submitted a patch which was not merged and the maintainer did not yet implement their intended clean solution.

@stylesuxx




Copy link

The web-serial-polyfill does not want to cooperate if web serial itself is available, I simply can’t claim the device, even with them demo.html provided in the repo I end up getting an error when attempting to open the device:

serial.ts:311 Uncaught (in promise) Error: Error setting up device: NetworkError: Failed to execute 'claimInterface' on 'USBDevice': Unable to claim interface.
    at SerialPort.open (serial.ts:311:13)
    at async demo.html:64:7

@j005u

Presumably you made sure nothing else is claiming the iface? Anything in device-logs? Or maybe some udev bullshit?

@stylesuxx




Copy link

Yes, I did check that nothing else is claiming the interface. device-logs seem fine, nothing out of the ordinary. I am not the only one having this «issue» though.

@j005u

Same, with «Interface 4 uses driver «usbser» instead of WinUSB.» in device-log.

@stylesuxx




Copy link

Yup, I see it the same way. I don’t want to involve external (non cross platform) tools at all.

@D3VL-Jack

@j005u

Оцените статью
Master Hi-technology
Добавить комментарий