From deaa163c1d80d248ab3c4d4fc6275a76c6843c62 Mon Sep 17 00:00:00 2001 From: Compot Developer Date: Sun, 15 Nov 2026 23:26:36 +0000 Subject: [PATCH 1/2] Android app: a hex view of the last dump, as in the web mode Under the status registers: address, bytes and ASCII, 16 bytes a row, 512 bytes a page, 00 and FF dim; Prev, Next and Go to an address in hex (up to 12 digits, inside the dump). Only the page shown is read from the file; the panel follows the newest dump and goes when there is none. Part of #85. --- CHANGELOG.md | 7 ++ README.md | 3 + README.ru.md | 3 + README.zh-CN.md | 2 + .../openipc/microsnander/MainActivity.java | 110 +++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 111 ++++++++++++++++++ android/app/src/main/res/values/strings.xml | 11 ++ src/main.c | 2 +- 8 files changed, 248 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5287fab..b4cbf0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ The version lives in `_VER` in `src/main.c`. Binaries are published only as the [`latest`](https://github.com/OpenIPC/microsnander/releases/latest) release, rebuilt from every push to `main`; this file is the change history. +## 1.43.0 — 2026-11-16 + +- Android app: a hex view of the last dump (#85), under the status registers, as in the web + mode: address, bytes and ASCII, 16 bytes a row, 512 bytes a page, 00 and FF dim; Prev, Next and + Go to an address in hex (up to 12 digits, inside the dump). Only that page is read from the + file, so a dump of any size opens at once; the panel follows the newest dump. + ## 1.42.0 — 2026-11-16 - Web mode: a hex view of the last dump (#85), under the status registers: address, bytes and diff --git a/README.md b/README.md index 99078cc..2a57b7d 100644 --- a/README.md +++ b/README.md @@ -482,6 +482,9 @@ with the remote). - A tap on a register lamp flips that bit: Detect, a question with the old and the new value, the write on every die, then the registers read again. WEL, BUSY (WIP) and SUS are the state of the chip, R bits are reserved and LB1–LB3 are one-time locks: those lamps take no tap. +- **Hex view** of the last dump, as in the web mode: 512 bytes a page, address, bytes and ASCII + (00 and FF dim), Prev, Next and Go to an address in hex; the D-pad of a TV box moves through + them, and the table scrolls sideways on a narrow screen. - The app runs the same C code as microsnander (`src/`), built with the NDK, on the device the Android USB manager opened (its file descriptor, through the usbfs code, no libusb). The signed APK is in the release: `microsnander-android.apk` in [latest](https://github.com/OpenIPC/microsnander/releases/latest). diff --git a/README.ru.md b/README.ru.md index 40b2d2b..3bf6327 100644 --- a/README.ru.md +++ b/README.ru.md @@ -488,6 +488,9 @@ Android TV (Android 5.0 и новее, без root; на приставке он - Нажатие на лампу регистра меняет этот бит: Detect, вопрос со старым и новым значением, запись на всех кристаллах, затем регистры читаются заново. WEL, BUSY (WIP) и SUS — состояние микросхемы, биты R зарезервированы, а LB1–LB3 — одноразовая блокировка: на эти лампы нажать нельзя. +- **Hex view** последнего дампа, как в веб-режиме: по 512 байт, адрес, байты и ASCII (00 и FF + приглушены), Prev, Next и Go — переход по адресу в hex; на ТВ-приставке по ним ходят пультом, + на узком экране таблица прокручивается вбок. - Приложение работает на том же коде C, что и microsnander (`src/`), собранном NDK, с устройством, которое открыл менеджер USB Android (через его файловый дескриптор и код usbfs, без libusb). Подписанный APK — в релизе: `microsnander-android.apk` в [latest](https://github.com/OpenIPC/microsnander/releases/latest). diff --git a/README.zh-CN.md b/README.zh-CN.md index 8d18c9a..4936c1c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -414,6 +414,8 @@ root;在电视盒子上会出现在主屏幕,可用遥控器操作)。 **Self-test**(在 Detect 和确认之后对第一个块执行 `-t`)。 - 点击寄存器指示灯即可翻转该位:先 Detect,再询问并显示旧值和新值,在每个晶粒上写入,然后重新读取寄存器。 WEL、BUSY(WIP)和 SUS 是芯片的状态,R 位为保留位,LB1–LB3 为一次性锁定位:这些指示灯不能点击。 +- 最近一次转储的 **Hex view**,与 Web 模式相同:每页 512 字节,地址、字节和 ASCII(00 和 FF 显示为暗色), + Prev、Next 和 Go(跳转到十六进制地址);电视盒子上可用遥控器方向键操作,窄屏上表格可横向滚动。 - 应用使用与 microsnander 相同的 C 代码(`src/`),由 NDK 编译,访问 Android USB 管理器打开的 设备(通过其文件描述符和 usbfs 代码,不使用 libusb)。签名的 APK 在发布版中:[latest](https://github.com/OpenIPC/microsnander/releases/latest) 里的 `microsnander-android.apk`。 diff --git a/android/app/src/main/java/org/openipc/microsnander/MainActivity.java b/android/app/src/main/java/org/openipc/microsnander/MainActivity.java index 9e0fe0c..385ecce 100644 --- a/android/app/src/main/java/org/openipc/microsnander/MainActivity.java +++ b/android/app/src/main/java/org/openipc/microsnander/MainActivity.java @@ -30,7 +30,9 @@ import android.text.style.ForegroundColorSpan; import android.view.Gravity; import android.view.View; +import android.view.inputmethod.EditorInfo; import android.widget.Button; +import android.widget.EditText; import android.widget.GridLayout; import android.widget.ProgressBar; import android.widget.TextView; @@ -41,6 +43,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.RandomAccessFile; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -100,6 +103,14 @@ public class MainActivity extends Activity { private View regsPanel; private Button[] buttons; private Button saveAs, share; + // the hex view of the last dump: its file and the address of the page shown + private static final int HEX_PAGE = 512; + private static String hexName; + private static long hexOff; + private View hexPanel; + private TextView hexFile, hexText; + private EditText hexAddr; + private Button hexPrev, hexNext; private Runnable afterPermission; @Override @@ -116,6 +127,20 @@ protected void onCreate(Bundle saved) { regsNote = findViewById(R.id.regs_note); saveAs = findViewById(R.id.b_save_as); share = findViewById(R.id.b_share); + hexPanel = findViewById(R.id.hex_panel); + hexFile = findViewById(R.id.hex_file); + hexText = findViewById(R.id.hex); + hexAddr = findViewById(R.id.hex_addr); + hexPrev = findViewById(R.id.b_hex_prev); + hexNext = findViewById(R.id.b_hex_next); + hexPrev.setOnClickListener(v -> { hexOff = Math.max(0, hexOff - HEX_PAGE); showHex(); }); + hexNext.setOnClickListener(v -> { hexOff += HEX_PAGE; showHex(); }); + findViewById(R.id.b_hex_go).setOnClickListener(v -> hexGo()); + hexAddr.setOnEditorActionListener((v, id, e) -> { + if (id != EditorInfo.IME_ACTION_GO && e == null) return false; + hexGo(); + return true; + }); ((TextView) findViewById(R.id.version)).setText(getString(R.string.version, BuildConfig.VERSION_NAME)); buttons = new Button[] { findViewById(R.id.b_detect), findViewById(R.id.b_read), findViewById(R.id.b_erase), @@ -693,6 +718,91 @@ private void enable(boolean on) { boolean dump = on && lastDump() != null; saveAs.setEnabled(dump); share.setEnabled(dump); + if (on) showHex(); + } + + // ---- the hex view ---- + + /** Go: an address in hex inside the dump, the page from it (on a 16-byte row) */ + private void hexGo() { + File f = lastDump(); + String v = hexAddr.getText().toString().trim().replaceFirst("^0[xX]", ""); + if (f == null) return; + if (!v.matches("[0-9a-fA-F]{1,12}")) { + hexText.setText(R.string.hex_bad_addr); + return; + } + long a = Long.parseLong(v, 16); + if (a >= f.length()) { + hexText.setText(getString(R.string.hex_past_end, sizeOf(f.length()), Math.max(0, f.length() - 1))); + return; + } + hexOff = a / 16 * 16; + showHex(); + } + + private static String hex(long v, int n) { + StringBuilder s = new StringBuilder(Long.toHexString(v).toUpperCase(java.util.Locale.ROOT)); + while (s.length() < n) s.insert(0, '0'); + return s.toString(); + } + + /** the page of the last dump at hexOff: address, 16 bytes, ASCII a row; none: the panel goes */ + private void showHex() { + File f = lastDump(); + if (f == null) { + hexPanel.setVisibility(View.GONE); + hexName = null; + return; + } + if (!f.getName().equals(hexName)) { // another dump: from its start + hexName = f.getName(); + hexOff = 0; + } + long len = f.length(); + if (hexOff >= len) hexOff = Math.max(0, (len - 1) / HEX_PAGE * HEX_PAGE); + hexPanel.setVisibility(View.VISIBLE); + hexFile.setText(hexName); + byte[] b = new byte[(int) Math.min(HEX_PAGE, len - hexOff)]; + try (RandomAccessFile r = new RandomAccessFile(f, "r")) { + r.seek(hexOff); + r.readFully(b); + } catch (IOException e) { + hexText.setText(R.string.hex_cannot); + return; + } + int amber = col(R.color.amber), dim = col(R.color.dim); + SpannableStringBuilder h = new SpannableStringBuilder(); + for (int i = 0; i < b.length; i += 16) { + int from = h.length(); + h.append(hex(hexOff + i, 8)); + h.setSpan(new ForegroundColorSpan(amber), from, h.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + h.append(" "); + StringBuilder c = new StringBuilder(); + for (int k = 0; k < 16; k++) { + if (k == 8) h.append(' '); + if (i + k < b.length) { + int v = b[i + k] & 0xff; + int at = h.length(); + h.append(hex(v, 2)); + if (v == 0 || v == 0xff) + h.setSpan(new ForegroundColorSpan(dim), at, h.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + h.append(' '); + c.append(v >= 32 && v < 127 ? (char) v : '.'); + } else + h.append(" "); + } + h.append(' '); + int at = h.length(); + h.append(c); + h.setSpan(new ForegroundColorSpan(dim), at, h.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + if (i + 16 < b.length) h.append('\n'); + } + if (b.length == 0) h.append(getString(R.string.hex_empty)); + hexText.setText(h); + hexAddr.setText(getString(R.string.hex_addr, hexOff)); + hexPrev.setEnabled(hexOff > 0); + hexNext.setEnabled(hexOff + HEX_PAGE < len); } private void showBusy() { diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index 004bb0c..b9727d6 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -242,5 +242,116 @@ android:paddingRight="24dp" android:text="@string/unprotect" /> + + + + + + + + + + + + + + +