mirror of
https://github.com/siemens-mobile-hacks/web-devtools.git
synced 2026-11-25 23:57:40 +00:00
ptr89 online
This commit is contained in:
parent
b600c45db3
commit
8b51cd112c
18 changed files with 1446 additions and 13 deletions
51
AGENTS.md
Normal file
51
AGENTS.md
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# Project Guidelines
|
||||
|
||||
## Core Principle
|
||||
|
||||
Follow the code style, architectural decisions, and approaches already established in the project. Before making changes, study the surrounding code and configuration. Match the author's style: existing project conventions take precedence over personal preferences.
|
||||
|
||||
## Change Requirements
|
||||
|
||||
- Write clean, clear, and maintainable code.
|
||||
- Choose the simplest solution that fully addresses the task.
|
||||
- Do not produce AI slop: avoid boilerplate comments, unnecessary verbosity, redundant checks, wrappers, and abstractions.
|
||||
- Do not overengineer or generalize prematurely.
|
||||
- Fix the underlying cause instead of stacking patches or compatibility layers.
|
||||
- Do not preserve duplicate implementations or compatibility code for behavior that has not shipped.
|
||||
- Follow the project's established naming, file structure, formatting, and error-handling conventions.
|
||||
- Whenever the user establishes or clarifies a project code-style rule, immediately record it in `AGENTS.md`.
|
||||
- Before implementing helper logic or adding an abstraction, always inspect the existing project utilities and reuse an established utility when it fits.
|
||||
- In multiline ternary expressions, keep `?` and `:` at the end of the preceding line.
|
||||
- Prefer multiline JSX for nested elements; do not compress parent and child tags onto one line merely to save space.
|
||||
- Do not use namespace imports (`import * as ...`); use explicit named imports instead.
|
||||
- Use braces for an `if` statement whenever it has an `else` branch or its body spans multiple lines.
|
||||
- Do not refactor or reformat code outside the scope of the current task unless necessary.
|
||||
- Do not add dependencies when the task can reasonably be solved with the existing tools.
|
||||
- Always ask the user for explicit confirmation before installing a new dependency.
|
||||
- Preserve existing behavior and public interfaces unless the task explicitly requires changing them.
|
||||
- After making changes, run the relevant project checks and fix any errors caused by the changes.
|
||||
|
||||
## SolidJS
|
||||
|
||||
- Strictly follow SolidJS's reactive model and idioms.
|
||||
- Do not impose React approaches or its mental model on SolidJS code.
|
||||
- Use signals, memos, effects, and stores according to their intended roles in SolidJS, preserving fine-grained reactivity.
|
||||
- Avoid React patterns such as destructuring reactive props, unnecessary effects, manual state synchronization, and components designed around re-renders.
|
||||
- Use lifecycle hooks for DOM measurement; do not defer layout work with `queueMicrotask` when the component lifecycle can express the correct timing.
|
||||
- When a component requires data to render, make the prop required and handle conditional rendering at the caller instead of wrapping the entire component in `Show`.
|
||||
- Avoid unnecessary JSX fragments; use the existing semantic or layout container when sibling elements share one.
|
||||
- Before introducing a custom reactive abstraction, check whether the task can be solved more simply with SolidJS primitives and the project's existing patterns.
|
||||
|
||||
## UX
|
||||
|
||||
- Follow the existing Bootstrap and solid-bootstrap visual language; reuse nearby layout and interaction patterns before adding custom styles or components.
|
||||
- Keep tool interfaces compact: prefer small controls, dense tables, concise action rows, and `mb-2`/`mb-3` spacing over cards, large headings, and excessive whitespace.
|
||||
- Maximize useful information density: every visible element should support the current task, and labels or explanatory text should not repeat context that is already clear.
|
||||
- Prefer single-line toolbars for secondary actions and numeric options, and compact inline lists for selectable collections.
|
||||
- Do not use horizontal scrolling as a layout solution. Reflow or wrap controls, adapt the layout at narrow widths, and remove nonessential information instead.
|
||||
- Do not use `table-layout: fixed`. Let columns size naturally from their content; percentage widths may be assigned to individual columns when proportions need to be controlled.
|
||||
- Keep the primary workflow visible and group related controls in one row when practical. Let controls wrap responsively on narrow screens.
|
||||
- Use modals for focused secondary configuration, not for primary actions or information that belongs on the page.
|
||||
- Preserve accessibility with explicit labels or accessible names, visible status and error feedback, and keyboard-operable controls.
|
||||
- Keep tables within the available width and preserve identifying context when results from multiple sources are combined.
|
||||
- Use Playwright only for complex or high-risk UI scenarios where browser behavior materially needs verification, and only after the interface is complete. Do not run it for routine changes when the implementation and static checks provide sufficient confidence, or after each intermediate UI change.
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
"@codemirror/theme-one-dark": "^6.1.3",
|
||||
"@codemirror/view": "^6.40.0",
|
||||
"@material-design-icons/svg": "^0.14.15",
|
||||
"@sie-js/ptr89": "^3.0.2",
|
||||
"@solid-primitives/context": "^0.3.2",
|
||||
"@solidjs/router": "^0.15.4",
|
||||
"@suid/types": "^0.8.0",
|
||||
|
|
@ -40,10 +41,12 @@
|
|||
"axios-cache-interceptor": "^1.12.0",
|
||||
"bootstrap": "^5.3.8",
|
||||
"bootstrap-icons": "^1.13.1",
|
||||
"browser-fs-access": "^0.38.0",
|
||||
"clsx": "^2.1.1",
|
||||
"date-fns": "^3.6.0",
|
||||
"es-toolkit": "^1.45.1",
|
||||
"highlight.js": "^11.11.1",
|
||||
"idb-keyval": "^6.3.0",
|
||||
"sass": "^1.98.0",
|
||||
"solid-bootstrap": "^1.0.21",
|
||||
"solid-js": "^1.9.11",
|
||||
|
|
|
|||
24
pnpm-lock.yaml
generated
24
pnpm-lock.yaml
generated
|
|
@ -35,6 +35,9 @@ importers:
|
|||
'@material-design-icons/svg':
|
||||
specifier: ^0.14.15
|
||||
version: 0.14.15
|
||||
'@sie-js/ptr89':
|
||||
specifier: ^3.0.2
|
||||
version: 3.0.2
|
||||
'@solid-primitives/context':
|
||||
specifier: ^0.3.2
|
||||
version: 0.3.2(solid-js@1.9.11)
|
||||
|
|
@ -71,6 +74,9 @@ importers:
|
|||
bootstrap-icons:
|
||||
specifier: ^1.13.1
|
||||
version: 1.13.1
|
||||
browser-fs-access:
|
||||
specifier: ^0.38.0
|
||||
version: 0.38.0
|
||||
clsx:
|
||||
specifier: ^2.1.1
|
||||
version: 2.1.1
|
||||
|
|
@ -83,6 +89,9 @@ importers:
|
|||
highlight.js:
|
||||
specifier: ^11.11.1
|
||||
version: 11.11.1
|
||||
idb-keyval:
|
||||
specifier: ^6.3.0
|
||||
version: 6.3.0
|
||||
sass:
|
||||
specifier: ^1.98.0
|
||||
version: 1.98.0
|
||||
|
|
@ -632,6 +641,9 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
'@sie-js/ptr89@3.0.2':
|
||||
resolution: {integrity: sha512-uRaVK4w3dv7A/uhbxqfnpVsYA1IEHO7Q4C6Reict8auWluhkSONvGW5nI5AE+fnQYiVKS8vuws+tDeQTZmhykg==}
|
||||
|
||||
'@solid-devtools/debugger@0.28.1':
|
||||
resolution: {integrity: sha512-6qIUI6VYkXoRnL8oF5bvh2KgH71qlJ18hNw/mwSyY6v48eb80ZR48/5PDXufUa3q+MBSuYa1uqTMwLewpay9eg==}
|
||||
peerDependencies:
|
||||
|
|
@ -797,6 +809,9 @@ packages:
|
|||
peerDependencies:
|
||||
'@popperjs/core': ^2.11.8
|
||||
|
||||
browser-fs-access@0.38.0:
|
||||
resolution: {integrity: sha512-JveqW2w6pEZqFEEfMgCszXzYpE89dG+nPsmOdcs741mFFAROeL+iqjGEpR07RI+s0YY0EFr+4KnOoACprJTpOw==}
|
||||
|
||||
browserslist@4.28.1:
|
||||
resolution: {integrity: sha512-ZC5Bd0LgJXgwGqUknZY/vkUQ04r8NXnJZ3yYi4vDmSiZmC/pdSN0NbNRPxZpbtO4uAfDUAFffO8IZoM3Gj8IkA==}
|
||||
engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7}
|
||||
|
|
@ -1009,6 +1024,9 @@ packages:
|
|||
http-vary@1.0.3:
|
||||
resolution: {integrity: sha512-sx7Y8YTqF3o0mFJJvF66n8dbaE8v3liV1RgCz46XP5xK7dnzyZHvwMWRA115q5kjbCPBV65/nOMlgW54WLyiag==}
|
||||
|
||||
idb-keyval@6.3.0:
|
||||
resolution: {integrity: sha512-um+2dgAWmYsu615EXpWVwSmapJhON0G43t3Ka/EVaohzPQXSMqKEqeDK/oIW3Ow+BXaF2PvSc+oBTFp793A5Ow==}
|
||||
|
||||
immutable@5.1.5:
|
||||
resolution: {integrity: sha512-t7xcm2siw+hlUM68I+UEOK+z84RzmN59as9DZ7P1l0994DKUWV7UXBMQZVxaoMSRQ+PBZbHCOoBt7a2wxOMt+A==}
|
||||
|
||||
|
|
@ -1705,6 +1723,8 @@ snapshots:
|
|||
'@rollup/rollup-win32-x64-msvc@4.59.0':
|
||||
optional: true
|
||||
|
||||
'@sie-js/ptr89@3.0.2': {}
|
||||
|
||||
'@solid-devtools/debugger@0.28.1(solid-js@1.9.11)':
|
||||
dependencies:
|
||||
'@nothing-but/utils': 0.17.0
|
||||
|
|
@ -1918,6 +1938,8 @@ snapshots:
|
|||
dependencies:
|
||||
'@popperjs/core': 2.11.8
|
||||
|
||||
browser-fs-access@0.38.0: {}
|
||||
|
||||
browserslist@4.28.1:
|
||||
dependencies:
|
||||
baseline-browser-mapping: 2.10.7
|
||||
|
|
@ -2132,6 +2154,8 @@ snapshots:
|
|||
|
||||
http-vary@1.0.3: {}
|
||||
|
||||
idb-keyval@6.3.0: {}
|
||||
|
||||
immutable@5.1.5: {}
|
||||
|
||||
is-extglob@2.1.1:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const SwilibCheckPage = lazy(() => import("@/pages/SwilibCheck/SwilibCheckPage")
|
|||
const SwilibMergePage = lazy(() => import("@/pages/SwilibMerge/SwilibMergePage"));
|
||||
const SwilibMergeEditorPage = lazy(() => import("@/pages/SwilibMerge/SwilibMergeEditorPage"));
|
||||
const ReFilesPage = lazy(() => import("@/pages/ReFiles/ReFilesPage"));
|
||||
const Ptr89Page = lazy(() => import("@/pages/Ptr89/Ptr89Page"));
|
||||
|
||||
export const Root: Component = () => {
|
||||
const showAppError = (err: any) => {
|
||||
|
|
@ -24,6 +25,7 @@ export const Root: Component = () => {
|
|||
<Route path="/swilib/check" component={SwilibCheckPage} />
|
||||
<Route path="/swilib/merge" component={SwilibMergePage} />
|
||||
<Route path="/swilib/merge/editor" component={SwilibMergeEditorPage} />
|
||||
<Route path="/re/ptr89" component={Ptr89Page} />
|
||||
<Route path="/re/symbols" component={ReFilesPage} />
|
||||
|
||||
{/* Legacy routes */}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export const Sidebar: Component<SidebarProps> = (props) => {
|
|||
{
|
||||
title: "Reverse engineering",
|
||||
links: [
|
||||
{ label: "Patterns finder", href: "/re/ptr89", icon: "bi bi-search", disabled: true },
|
||||
{ label: "Patterns finder", href: "/re/ptr89", icon: "bi bi-search" },
|
||||
{ label: "Download symbols", href: "/re/symbols", icon: "bi bi-download" }
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -58,6 +58,10 @@ body {
|
|||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.form-control[size] {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.table-sticky-header {
|
||||
thead tr {
|
||||
position: sticky;
|
||||
|
|
|
|||
63
src/pages/Ptr89/FolderSelect.tsx
Normal file
63
src/pages/Ptr89/FolderSelect.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { type Component, createSignal, For, Show } from "solid-js";
|
||||
import { Form } from "solid-bootstrap";
|
||||
|
||||
interface FolderSelectProps {
|
||||
id?: string;
|
||||
class?: string;
|
||||
value: string;
|
||||
folders: string[];
|
||||
onChange: (folder: string) => void;
|
||||
}
|
||||
|
||||
export const FolderSelect: Component<FolderSelectProps> = (props) => {
|
||||
const [adding, setAdding] = createSignal(false);
|
||||
const showInput = () => adding() || Boolean(props.value && !props.folders.includes(props.value));
|
||||
|
||||
const handleSelect = (select: HTMLSelectElement) => {
|
||||
if (select.selectedOptions[0]?.dataset.action === "add") {
|
||||
props.onChange("");
|
||||
setAdding(true);
|
||||
} else {
|
||||
setAdding(false);
|
||||
props.onChange(select.value);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Show
|
||||
when={showInput()}
|
||||
fallback={
|
||||
<Form.Select
|
||||
id={props.id}
|
||||
size="sm"
|
||||
class={props.class}
|
||||
style={{ "min-width": 0, "max-width": "100%" }}
|
||||
value={props.value}
|
||||
onChange={(e) => handleSelect(e.currentTarget)}
|
||||
>
|
||||
<option value="">—</option>
|
||||
<For each={props.folders}>{(folder) => <option value={folder}>{folder}</option>}</For>
|
||||
<option value="" data-action="add">Add new</option>
|
||||
</Form.Select>
|
||||
}
|
||||
>
|
||||
<Form.Control
|
||||
id={props.id}
|
||||
size="sm"
|
||||
class={props.class}
|
||||
style={{ "min-width": 0, "max-width": "100%" }}
|
||||
autofocus
|
||||
placeholder="New folder"
|
||||
value={props.value}
|
||||
onInput={(e) => props.onChange(e.currentTarget.value)}
|
||||
onBlur={() => setAdding(false)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Escape") {
|
||||
props.onChange("");
|
||||
setAdding(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Show>
|
||||
);
|
||||
};
|
||||
94
src/pages/Ptr89/FullflashAddModal.tsx
Normal file
94
src/pages/Ptr89/FullflashAddModal.tsx
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import { type Component, createMemo, createSignal, Show } from "solid-js";
|
||||
import { createStore } from "solid-js/store";
|
||||
import { Button, Modal, Spinner } from "solid-bootstrap";
|
||||
import { type FileWithHandle } from "browser-fs-access";
|
||||
import { FolderSelect } from "@/pages/Ptr89/FolderSelect";
|
||||
import type { Fullflash } from "@/pages/Ptr89/store/ptr89State";
|
||||
import { FullflashTable } from "@/pages/Ptr89/FullflashTable";
|
||||
|
||||
interface FullflashAddModalProps {
|
||||
files: FileWithHandle[];
|
||||
folders: string[];
|
||||
onAdd: (fullflashes: Fullflash[], files: FileWithHandle[]) => Promise<void>;
|
||||
onHide: () => void;
|
||||
}
|
||||
|
||||
export const FullflashAddModal: Component<FullflashAddModalProps> = (props) => {
|
||||
const [show, setShow] = createSignal(true);
|
||||
const [saving, setSaving] = createSignal(false);
|
||||
const [error, setError] = createSignal<string>();
|
||||
const [commonFolder, setCommonFolder] = createSignal("");
|
||||
const [fullflashes, setFullflashes] = createStore<Fullflash[]>(props.files.map((file) => ({
|
||||
id: crypto.randomUUID(),
|
||||
name: file.name.replace(/\.[^.]+$/, "") || file.name,
|
||||
folder: "",
|
||||
arch: "arm",
|
||||
})));
|
||||
const folders = createMemo(() => [...new Set([
|
||||
...props.folders,
|
||||
...fullflashes.map((fullflash) => fullflash.folder),
|
||||
].filter(Boolean))].sort());
|
||||
const handleCommonFolderChange = (folder: string) => {
|
||||
const previousFolder = commonFolder();
|
||||
setCommonFolder(folder);
|
||||
setFullflashes(fullflashes.map((fullflash) => {
|
||||
if (fullflash.folder && fullflash.folder !== previousFolder)
|
||||
return fullflash;
|
||||
return { ...fullflash, folder };
|
||||
}));
|
||||
};
|
||||
|
||||
const handleAdd = async () => {
|
||||
setSaving(true);
|
||||
setError(undefined);
|
||||
|
||||
try {
|
||||
await props.onAdd(fullflashes, props.files);
|
||||
setShow(false);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal size="lg" centered scrollable show={show()} onHide={() => !saving() && setShow(false)} onExited={props.onHide}>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>Add fullflashes</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<div class="d-flex align-items-center gap-2 mb-2">
|
||||
<label for="ptr89-common-folder" class="small text-secondary text-nowrap">Folder for all</label>
|
||||
<FolderSelect
|
||||
id="ptr89-common-folder"
|
||||
class="w-auto"
|
||||
folders={folders()}
|
||||
value={commonFolder()}
|
||||
onChange={handleCommonFolderChange}
|
||||
/>
|
||||
</div>
|
||||
<FullflashTable
|
||||
fullflashes={fullflashes}
|
||||
setFullflashes={setFullflashes}
|
||||
folders={folders()}
|
||||
/>
|
||||
|
||||
<Show when={error()}>
|
||||
<div class="alert alert-danger mt-3 mb-0" role="alert">{error()}</div>
|
||||
</Show>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button size="sm" variant="secondary" onClick={() => setShow(false)} disabled={saving()}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button size="sm" onClick={handleAdd} disabled={saving()}>
|
||||
<Show when={saving()}>
|
||||
<Spinner animation="border" size="sm" class="me-2" />
|
||||
</Show>
|
||||
Save
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
75
src/pages/Ptr89/FullflashSettingsModal.tsx
Normal file
75
src/pages/Ptr89/FullflashSettingsModal.tsx
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import { type Component, createMemo, createSignal, Show } from "solid-js";
|
||||
import { createStore } from "solid-js/store";
|
||||
import { Modal } from "solid-bootstrap";
|
||||
import type { Fullflash } from "@/pages/Ptr89/store/ptr89State";
|
||||
import { FullflashTable } from "@/pages/Ptr89/FullflashTable";
|
||||
|
||||
interface FullflashSettingsModalProps {
|
||||
fullflashes: Fullflash[];
|
||||
folders: string[];
|
||||
onSave: (fullflashes: Fullflash[]) => void;
|
||||
onRemove: (id: string) => Promise<void>;
|
||||
onHide: () => void;
|
||||
}
|
||||
|
||||
export const FullflashSettingsModal: Component<FullflashSettingsModalProps> = (props) => {
|
||||
const [show, setShow] = createSignal(true);
|
||||
const [saving, setSaving] = createSignal(false);
|
||||
const [error, setError] = createSignal<string>();
|
||||
const [fullflashes, setFullflashes] = createStore<Fullflash[]>(props.fullflashes.map((fullflash) => ({ ...fullflash })));
|
||||
const folders = createMemo(() => [...new Set([
|
||||
...props.folders,
|
||||
...fullflashes.map((fullflash) => fullflash.folder),
|
||||
].filter(Boolean))].sort());
|
||||
|
||||
const handleClose = () => {
|
||||
if (saving())
|
||||
return;
|
||||
|
||||
setError(undefined);
|
||||
|
||||
try {
|
||||
props.onSave(fullflashes);
|
||||
setShow(false);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemove = async (id: string) => {
|
||||
if (saving())
|
||||
return;
|
||||
|
||||
setSaving(true);
|
||||
setError(undefined);
|
||||
try {
|
||||
await props.onRemove(id);
|
||||
setFullflashes(fullflashes.filter((fullflash) => fullflash.id !== id));
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal size="lg" centered show={show()} onHide={handleClose} onExited={props.onHide}>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>Fullflashes list</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<FullflashTable
|
||||
fullflashes={fullflashes}
|
||||
setFullflashes={setFullflashes}
|
||||
folders={folders()}
|
||||
onRemove={handleRemove}
|
||||
removeDisabled={saving()}
|
||||
/>
|
||||
|
||||
<Show when={error()}>
|
||||
<div class="alert alert-danger py-2 mt-2 mb-0" role="alert">{error()}</div>
|
||||
</Show>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
99
src/pages/Ptr89/FullflashTable.tsx
Normal file
99
src/pages/Ptr89/FullflashTable.tsx
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import { type Component, For, Show } from "solid-js";
|
||||
import { type SetStoreFunction } from "solid-js/store";
|
||||
import { Button, Form } from "solid-bootstrap";
|
||||
import { FolderSelect } from "@/pages/Ptr89/FolderSelect";
|
||||
import type { Fullflash } from "@/pages/Ptr89/store/ptr89State";
|
||||
|
||||
interface FullflashTableProps {
|
||||
fullflashes: Fullflash[];
|
||||
setFullflashes: SetStoreFunction<Fullflash[]>;
|
||||
folders: string[];
|
||||
onRemove?: (id: string) => void;
|
||||
removeDisabled?: boolean;
|
||||
}
|
||||
|
||||
export const FullflashTable: Component<FullflashTableProps> = (props) => (
|
||||
<table class="table table-sm table-bordered align-middle mb-0">
|
||||
<colgroup>
|
||||
<col style={{ width: "70%" }} />
|
||||
<col style={{ width: "30%" }} />
|
||||
<col />
|
||||
<col />
|
||||
<Show when={props.onRemove}><col /></Show>
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Folder</th>
|
||||
<th>Arch</th>
|
||||
<th>Base</th>
|
||||
<Show when={props.onRemove}><th class="p-1"></th></Show>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<For each={props.fullflashes}>{(fullflash, index) =>
|
||||
<tr>
|
||||
<td>
|
||||
<Form.Control
|
||||
size="sm"
|
||||
value={fullflash.name}
|
||||
onInput={(e) => props.setFullflashes(index(), "name", e.currentTarget.value)}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<FolderSelect
|
||||
folders={props.folders}
|
||||
value={fullflash.folder}
|
||||
onChange={(folder) => props.setFullflashes(index(), "folder", folder)}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<Form.Select
|
||||
size="sm"
|
||||
class="w-auto"
|
||||
value={fullflash.arch}
|
||||
onChange={(e) => props.setFullflashes(index(), "arch", e.currentTarget.value as Fullflash["arch"])}
|
||||
>
|
||||
<option value="arm">ARM</option>
|
||||
<option value="c166">C166</option>
|
||||
</Form.Select>
|
||||
</td>
|
||||
<td>
|
||||
<Form.Control
|
||||
size="sm"
|
||||
htmlSize={4}
|
||||
maxLength={8}
|
||||
class="font-monospace"
|
||||
value={fullflash.base?.toString(16).toUpperCase() ?? ""}
|
||||
placeholder={fullflash.arch === "arm" ? "A0000000" : "Auto"}
|
||||
onInput={(e) => {
|
||||
const value = e.currentTarget.value;
|
||||
if (/^[0-9A-F]{0,8}$/i.test(value)) {
|
||||
props.setFullflashes(index(), "base", value ? Number.parseInt(value, 16) : undefined);
|
||||
} else {
|
||||
e.currentTarget.value = fullflash.base?.toString(16).toUpperCase() ?? "";
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<Show when={props.onRemove}>
|
||||
<td class="text-nowrap text-center p-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline-danger"
|
||||
size="sm"
|
||||
class="py-0 px-1"
|
||||
aria-label={`Remove ${fullflash.name}`}
|
||||
title={`Remove ${fullflash.name}`}
|
||||
disabled={props.removeDisabled}
|
||||
onClick={() => props.onRemove?.(fullflash.id)}
|
||||
>
|
||||
<i class="bi bi-trash"></i>
|
||||
</Button>
|
||||
</td>
|
||||
</Show>
|
||||
</tr>
|
||||
}</For>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
496
src/pages/Ptr89/Ptr89Page.tsx
Normal file
496
src/pages/Ptr89/Ptr89Page.tsx
Normal file
|
|
@ -0,0 +1,496 @@
|
|||
import { type Component, createMemo, createResource, createSignal, For, onCleanup, onMount, Show } from "solid-js";
|
||||
import { Button, Form, Nav, Spinner } from "solid-bootstrap";
|
||||
import { fileOpen, type FileWithHandle } from "browser-fs-access";
|
||||
import type { Ptr89WorkerPayload, Ptr89WorkerResponse } from "@/pages/Ptr89/ptr89.worker";
|
||||
import { FullflashAddModal } from "@/pages/Ptr89/FullflashAddModal";
|
||||
import { FullflashSettingsModal } from "@/pages/Ptr89/FullflashSettingsModal";
|
||||
import {
|
||||
SearchResults,
|
||||
XRefResults,
|
||||
} from "@/pages/Ptr89/Ptr89Results";
|
||||
import {
|
||||
type Fullflash,
|
||||
type FullflashMatch,
|
||||
type SearchResult,
|
||||
type XRefResult,
|
||||
usePtr89State,
|
||||
} from "@/pages/Ptr89/store/ptr89State";
|
||||
|
||||
type ActiveTab = "search" | "xrefs";
|
||||
|
||||
const parseAddress = (value: string) => Number(`0x${value.trim().replace(/^0x/i, "")}`);
|
||||
|
||||
const getErrorMessage = (error: unknown) => error instanceof Error ? error.message : String(error);
|
||||
|
||||
const resizePatternInput = (input: HTMLElement) => {
|
||||
input.style.height = "auto";
|
||||
input.style.height = `${input.scrollHeight}px`;
|
||||
};
|
||||
|
||||
const Ptr89Page: Component = () => {
|
||||
const ptr89Worker = new Worker(new URL("./ptr89.worker.ts", import.meta.url), { type: "module" });
|
||||
let patternInput!: HTMLTextAreaElement;
|
||||
const [ptr89State, ptr89] = usePtr89State();
|
||||
const [fileStorage] = createResource(ptr89.loadFiles);
|
||||
const [pendingFiles, setPendingFiles] = createSignal<FileWithHandle[]>();
|
||||
const [settingsOpen, setSettingsOpen] = createSignal(false);
|
||||
const [activeTab, setActiveTab] = createSignal<ActiveTab>("search");
|
||||
const [searchResult, setSearchResult] = createSignal<SearchResult>();
|
||||
const [xrefResult, setXrefResult] = createSignal<XRefResult>();
|
||||
const [error, setError] = createSignal<string>();
|
||||
const [adding, setAdding] = createSignal(false);
|
||||
const [formatting, setFormatting] = createSignal(false);
|
||||
const [searching, setSearching] = createSignal(false);
|
||||
const [progress, setProgress] = createSignal<string>();
|
||||
const folders = createMemo(() => [...new Set(
|
||||
ptr89State.fullflashes.map((fullflash) => fullflash.folder).filter(Boolean)
|
||||
)].sort());
|
||||
const selectedFolder = createMemo(() => folders().includes(ptr89State.folder) ? ptr89State.folder : "");
|
||||
const filteredFullflashes = createMemo(() => ptr89State.fullflashes.filter((fullflash) =>
|
||||
!selectedFolder() || fullflash.folder === selectedFolder()
|
||||
));
|
||||
const selectedFullflashes = createMemo(() =>
|
||||
filteredFullflashes().filter((fullflash) => !ptr89State.disabledFullflashIds.includes(fullflash.id))
|
||||
);
|
||||
const selectedXrefFullflash = createMemo(() => {
|
||||
const availableFullflashes = filteredFullflashes();
|
||||
return availableFullflashes.find((fullflash) => fullflash.id === ptr89State.xrefFullflashId) ??
|
||||
availableFullflashes[0];
|
||||
});
|
||||
onMount(() => resizePatternInput(patternInput));
|
||||
onCleanup(() => {
|
||||
ptr89Worker.terminate();
|
||||
});
|
||||
|
||||
const runWorker = (payload: Ptr89WorkerPayload) => new Promise<Ptr89WorkerResponse>((resolve, reject) => {
|
||||
ptr89Worker.onmessage = (event: MessageEvent<Ptr89WorkerResponse>) => resolve(event.data);
|
||||
ptr89Worker.onerror = (event) => reject(new Error(event.message));
|
||||
ptr89Worker.postMessage(payload);
|
||||
});
|
||||
|
||||
const handleAdd = async () => {
|
||||
setAdding(true);
|
||||
setError(undefined);
|
||||
|
||||
try {
|
||||
const files = await fileOpen({
|
||||
description: "Fullflash",
|
||||
id: "ptr89-fullflash",
|
||||
multiple: true,
|
||||
});
|
||||
setPendingFiles(files);
|
||||
} catch (err) {
|
||||
if (!(err instanceof DOMException && err.name === "AbortError"))
|
||||
setError(getErrorMessage(err));
|
||||
} finally {
|
||||
setAdding(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveSettings = (settings: Fullflash[]) => {
|
||||
if (ptr89.updateFullflashes(settings)) {
|
||||
setSearchResult(undefined);
|
||||
setXrefResult(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemove = async (id: string) => {
|
||||
await ptr89.removeFullflash(id);
|
||||
setSearchResult(undefined);
|
||||
setXrefResult(undefined);
|
||||
};
|
||||
|
||||
const handleFullflashToggle = (id: string, enabled: boolean) => {
|
||||
ptr89.setFullflashEnabled(id, enabled);
|
||||
};
|
||||
|
||||
const handlePrettify = async () => {
|
||||
if (formatting() || searching())
|
||||
return;
|
||||
|
||||
setFormatting(true);
|
||||
setError(undefined);
|
||||
try {
|
||||
const response = await runWorker({ operation: "prettify", pattern: ptr89State.pattern });
|
||||
if ("error" in response)
|
||||
throw new Error(response.error);
|
||||
if (!("pattern" in response))
|
||||
throw new Error("Unexpected worker response.");
|
||||
ptr89.setState("pattern", response.pattern);
|
||||
resizePatternInput(patternInput);
|
||||
} catch (err) {
|
||||
setError(getErrorMessage(err));
|
||||
} finally {
|
||||
setFormatting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSearch = async (e: SubmitEvent) => {
|
||||
e.preventDefault();
|
||||
if (searching() || formatting() || fileStorage.loading)
|
||||
return;
|
||||
|
||||
const searchFullflashes = selectedFullflashes();
|
||||
if (!searchFullflashes.length) {
|
||||
setError("Select at least one fullflash first.");
|
||||
return;
|
||||
}
|
||||
|
||||
setSearching(true);
|
||||
setError(undefined);
|
||||
setSearchResult(undefined);
|
||||
const startedAt = performance.now();
|
||||
|
||||
try {
|
||||
await ptr89.requestFilePermissions(searchFullflashes);
|
||||
const foundMatches: FullflashMatch[] = [];
|
||||
const searchIssues: SearchResult["issues"] = [];
|
||||
let resultType: SearchResult["type"] | undefined;
|
||||
|
||||
for (let i = 0; i < searchFullflashes.length; i++) {
|
||||
const fullflash = searchFullflashes[i];
|
||||
setProgress(`Searching ${i + 1}/${searchFullflashes.length}: ${fullflash.name}`);
|
||||
|
||||
try {
|
||||
const file = await ptr89.readFile(fullflash);
|
||||
const response = await runWorker({
|
||||
operation: "find",
|
||||
file,
|
||||
options: { arch: fullflash.arch, base: fullflash.base },
|
||||
pattern: ptr89State.pattern.trim(),
|
||||
limit: ptr89State.limit,
|
||||
align: ptr89State.align,
|
||||
});
|
||||
if ("error" in response)
|
||||
throw new Error(response.error);
|
||||
if (!("matches" in response))
|
||||
throw new Error("Unexpected worker response.");
|
||||
|
||||
resultType ??= response.type;
|
||||
foundMatches.push(...response.matches.map((match) => ({
|
||||
...match,
|
||||
fullflashId: fullflash.id,
|
||||
fullflashName: fullflash.name,
|
||||
arch: fullflash.arch,
|
||||
})));
|
||||
} catch (err) {
|
||||
searchIssues.push({ fullflashName: fullflash.name, message: getErrorMessage(err) });
|
||||
}
|
||||
}
|
||||
if (!resultType)
|
||||
throw new Error(searchIssues.map((issue) => `${issue.fullflashName}: ${issue.message}`).join(" "));
|
||||
|
||||
setSearchResult({
|
||||
matches: foundMatches,
|
||||
issues: searchIssues,
|
||||
type: resultType,
|
||||
duration: performance.now() - startedAt,
|
||||
});
|
||||
} catch (err) {
|
||||
setError(getErrorMessage(err));
|
||||
} finally {
|
||||
setProgress(undefined);
|
||||
setSearching(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleXrefSearch = async (e: SubmitEvent) => {
|
||||
e.preventDefault();
|
||||
if (searching() || formatting() || fileStorage.loading)
|
||||
return;
|
||||
|
||||
const fullflash = selectedXrefFullflash();
|
||||
if (!fullflash) {
|
||||
setError("Select a fullflash first.");
|
||||
return;
|
||||
}
|
||||
|
||||
setSearching(true);
|
||||
setError(undefined);
|
||||
setXrefResult(undefined);
|
||||
const startedAt = performance.now();
|
||||
|
||||
try {
|
||||
const address = parseAddress(ptr89State.xrefAddress);
|
||||
await ptr89.requestFilePermissions([fullflash]);
|
||||
|
||||
setProgress(`Searching ${fullflash.name}`);
|
||||
const file = await ptr89.readFile(fullflash);
|
||||
const response = await runWorker({
|
||||
operation: "findXRefs",
|
||||
file,
|
||||
options: { arch: fullflash.arch, base: fullflash.base },
|
||||
address,
|
||||
limit: ptr89State.limit,
|
||||
});
|
||||
if ("error" in response)
|
||||
throw new Error(response.error);
|
||||
if (!("xrefs" in response))
|
||||
throw new Error("Unexpected worker response.");
|
||||
|
||||
setXrefResult({
|
||||
xrefs: response.xrefs,
|
||||
duration: performance.now() - startedAt,
|
||||
});
|
||||
} catch (err) {
|
||||
setError(getErrorMessage(err));
|
||||
} finally {
|
||||
setProgress(undefined);
|
||||
setSearching(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Nav
|
||||
variant="tabs"
|
||||
activeKey={activeTab()}
|
||||
class="mb-2"
|
||||
onSelect={(key) => {
|
||||
if (key !== "search" && key !== "xrefs")
|
||||
return;
|
||||
setActiveTab(key);
|
||||
setError(undefined);
|
||||
}}
|
||||
>
|
||||
<Nav.Item>
|
||||
<Nav.Link eventKey="search">Search</Nav.Link>
|
||||
</Nav.Item>
|
||||
<Nav.Item>
|
||||
<Nav.Link eventKey="xrefs">X-Reference</Nav.Link>
|
||||
</Nav.Item>
|
||||
</Nav>
|
||||
<div class="d-flex flex-wrap align-items-center gap-2 mb-2">
|
||||
<Button type="button" size="sm" variant="outline-primary" class="text-nowrap" onClick={handleAdd} disabled={adding() || fileStorage.loading}>
|
||||
<Show when={adding()}>
|
||||
<Spinner animation="border" size="sm" class="me-2" />
|
||||
</Show>
|
||||
<i class="bi bi-plus-lg me-1"></i>
|
||||
Add fullflashes
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline-secondary"
|
||||
aria-label="Fullflashes list"
|
||||
title="Fullflashes list"
|
||||
disabled={fileStorage.loading || !ptr89State.fullflashes.length}
|
||||
onClick={() => setSettingsOpen(true)}
|
||||
>
|
||||
<i class="bi bi-gear"></i>
|
||||
</Button>
|
||||
<Show when={folders().length > 0}>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<label for="ptr89-folder" class="small text-secondary text-nowrap">Folder</label>
|
||||
<Form.Select
|
||||
id="ptr89-folder"
|
||||
size="sm"
|
||||
class="w-auto"
|
||||
value={selectedFolder()}
|
||||
onChange={(e) => {
|
||||
ptr89.setState("folder", e.currentTarget.value);
|
||||
setXrefResult(undefined);
|
||||
}}
|
||||
>
|
||||
<option value="">All</option>
|
||||
<For each={folders()}>{(folder) => <option value={folder}>{folder}</option>}</For>
|
||||
</Form.Select>
|
||||
</div>
|
||||
</Show>
|
||||
<Show when={activeTab() === "search"}>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<label for="ptr89-align" class="small text-secondary text-nowrap">Align</label>
|
||||
<Form.Control
|
||||
id="ptr89-align"
|
||||
size="sm"
|
||||
type="number"
|
||||
min="1"
|
||||
style={{ width: "4em" }}
|
||||
value={ptr89State.align}
|
||||
onInput={(e) => ptr89.setState("align", Number(e.currentTarget.value))}
|
||||
/>
|
||||
</div>
|
||||
</Show>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<label for="ptr89-limit" class="small text-secondary text-nowrap">Limit</label>
|
||||
<Form.Control
|
||||
id="ptr89-limit"
|
||||
size="sm"
|
||||
type="number"
|
||||
min="0"
|
||||
style={{ width: "5em" }}
|
||||
value={ptr89State.limit}
|
||||
onInput={(e) => ptr89.setState("limit", Number(e.currentTarget.value))}
|
||||
/>
|
||||
</div>
|
||||
<Show when={activeTab() === "search"}>
|
||||
<Button
|
||||
as="a"
|
||||
size="sm"
|
||||
variant="outline-secondary"
|
||||
class="text-nowrap ms-auto"
|
||||
href="https://github.com/siemens-mobile-hacks/ptr89#pattern-syntax"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>
|
||||
<i class="bi bi-question-circle me-1"></i>
|
||||
Help
|
||||
</Button>
|
||||
</Show>
|
||||
</div>
|
||||
|
||||
<Show when={pendingFiles()}>{(files) =>
|
||||
<FullflashAddModal
|
||||
files={files()}
|
||||
folders={folders()}
|
||||
onAdd={ptr89.addFullflashes}
|
||||
onHide={() => setPendingFiles(undefined)}
|
||||
/>
|
||||
}</Show>
|
||||
<Show when={settingsOpen()}>
|
||||
<FullflashSettingsModal
|
||||
fullflashes={ptr89State.fullflashes}
|
||||
folders={folders()}
|
||||
onSave={handleSaveSettings}
|
||||
onRemove={handleRemove}
|
||||
onHide={() => setSettingsOpen(false)}
|
||||
/>
|
||||
</Show>
|
||||
|
||||
<Show when={fileStorage.loading}>
|
||||
<Spinner animation="border" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</Spinner>
|
||||
</Show>
|
||||
<Show when={fileStorage.error}>
|
||||
<div class="alert alert-danger py-2" role="alert">Can't load saved files.</div>
|
||||
</Show>
|
||||
<Show
|
||||
when={ptr89State.fullflashes.length > 0}
|
||||
fallback={<div class="small text-secondary mb-2">No fullflashes added.</div>}
|
||||
>
|
||||
<div class="d-flex flex-wrap align-items-center gap-3 mb-2">
|
||||
<For each={filteredFullflashes()}>{(fullflash) =>
|
||||
<label class="d-flex align-items-center gap-1 text-nowrap">
|
||||
<Show
|
||||
when={activeTab() === "search"}
|
||||
fallback={
|
||||
<input
|
||||
type="radio"
|
||||
name="ptr89-xref-fullflash"
|
||||
class="form-check-input mt-0"
|
||||
checked={selectedXrefFullflash()?.id === fullflash.id}
|
||||
onChange={() => {
|
||||
ptr89.setState("xrefFullflashId", fullflash.id);
|
||||
setXrefResult(undefined);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="form-check-input mt-0"
|
||||
checked={!ptr89State.disabledFullflashIds.includes(fullflash.id)}
|
||||
onChange={(e) => handleFullflashToggle(fullflash.id, e.currentTarget.checked)}
|
||||
/>
|
||||
</Show>
|
||||
<span>{fullflash.name}</span>
|
||||
</label>
|
||||
}</For>
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
<Form hidden={activeTab() !== "search"} onSubmit={handleSearch}>
|
||||
<div class="d-flex flex-nowrap align-items-end gap-2 mb-2">
|
||||
<Form.Group class="flex-grow-1">
|
||||
<Form.Label for="ptr89-pattern" class="visually-hidden">Pattern</Form.Label>
|
||||
<Form.Control
|
||||
ref={patternInput}
|
||||
id="ptr89-pattern"
|
||||
as="textarea"
|
||||
rows={1}
|
||||
class="font-monospace"
|
||||
style={{ resize: "none", overflow: "hidden" }}
|
||||
placeholder="Pattern"
|
||||
value={ptr89State.pattern}
|
||||
onInput={(e) => {
|
||||
ptr89.setState("pattern", e.currentTarget.value);
|
||||
resizePatternInput(e.currentTarget);
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
e.currentTarget.form?.requestSubmit();
|
||||
}
|
||||
}}
|
||||
required
|
||||
/>
|
||||
</Form.Group>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline-secondary"
|
||||
aria-label="Prettify pattern"
|
||||
title="Prettify pattern"
|
||||
disabled={formatting() || searching() || !ptr89State.pattern.trim()}
|
||||
onClick={handlePrettify}
|
||||
>
|
||||
<Show when={formatting()} fallback={<i class="bi bi-magic"></i>}>
|
||||
<Spinner animation="border" size="sm" />
|
||||
</Show>
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
class="text-nowrap"
|
||||
disabled={searching() || formatting() || fileStorage.loading || !selectedFullflashes().length}
|
||||
>
|
||||
<Show when={searching()}>
|
||||
<Spinner animation="border" size="sm" class="me-2" />
|
||||
</Show>
|
||||
Search
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
<Form hidden={activeTab() !== "xrefs"} onSubmit={handleXrefSearch}>
|
||||
<div class="d-flex align-items-end gap-2 mb-2">
|
||||
<Form.Group>
|
||||
<Form.Label for="ptr89-xref-address" class="visually-hidden">Address</Form.Label>
|
||||
<input
|
||||
id="ptr89-xref-address"
|
||||
size={8}
|
||||
class="form-control font-monospace"
|
||||
placeholder="Address"
|
||||
value={ptr89State.xrefAddress}
|
||||
onInput={(e) => ptr89.setState("xrefAddress", e.currentTarget.value)}
|
||||
required
|
||||
/>
|
||||
</Form.Group>
|
||||
<Button
|
||||
type="submit"
|
||||
class="text-nowrap"
|
||||
disabled={searching() || formatting() || fileStorage.loading || !selectedXrefFullflash()}
|
||||
>
|
||||
<Show when={searching()}>
|
||||
<Spinner animation="border" size="sm" class="me-2" />
|
||||
</Show>
|
||||
Search
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
<Show when={progress()}>
|
||||
<div class="small text-secondary mb-2">{progress()}</div>
|
||||
</Show>
|
||||
|
||||
<Show when={error()}>
|
||||
<div class="alert alert-danger py-2 mt-2" role="alert">{error()}</div>
|
||||
</Show>
|
||||
<Show when={activeTab() === "search" ? searchResult() : undefined}>{(result) =>
|
||||
<SearchResults result={result()} />
|
||||
}</Show>
|
||||
<Show when={activeTab() === "xrefs" ? xrefResult() : undefined}>{(result) =>
|
||||
<XRefResults result={result()} />
|
||||
}</Show>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Ptr89Page;
|
||||
288
src/pages/Ptr89/Ptr89Results.tsx
Normal file
288
src/pages/Ptr89/Ptr89Results.tsx
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
import { type Component, createMemo, createSignal, For, Show } from "solid-js";
|
||||
import { Form } from "solid-bootstrap";
|
||||
import {
|
||||
type Ptr89Arch,
|
||||
type Ptr89SearchType,
|
||||
type Ptr89XRefType,
|
||||
} from "@sie-js/ptr89";
|
||||
import { formatAddress } from "@/utils/format";
|
||||
import {
|
||||
type AddressSpace,
|
||||
type FullflashMatch,
|
||||
type SearchResult,
|
||||
type XRefResult,
|
||||
usePtr89State,
|
||||
} from "@/pages/Ptr89/store/ptr89State";
|
||||
|
||||
interface SearchResultsProps {
|
||||
result: SearchResult;
|
||||
}
|
||||
|
||||
interface XRefResultsProps {
|
||||
result: XRefResult;
|
||||
}
|
||||
|
||||
const formatAddressBytes = (value: number) => [0, 8, 16, 24]
|
||||
.map((shift) => ((value >>> shift) & 0xFF).toString(16).toUpperCase().padStart(2, "0"))
|
||||
.join(" ");
|
||||
|
||||
const formatC166Pointer = (value: number, addressSpace: AddressSpace) => {
|
||||
const pageSize = addressSpace === "data" ? 0x4000 : 0x10000;
|
||||
const pageWidth = addressSpace === "data" ? 4 : 2;
|
||||
const offset = value % pageSize;
|
||||
const page = Math.floor(value / pageSize);
|
||||
return {
|
||||
pointer: `${page.toString(16).toUpperCase().padStart(pageWidth, "0")}:${offset.toString(16).toUpperCase().padStart(4, "0")}`,
|
||||
bytes: formatAddressBytes((page << 16) | offset),
|
||||
};
|
||||
};
|
||||
|
||||
const AddressCell: Component<{ address: number; showBytes: boolean; fullflashName?: string }> = (props) => (
|
||||
<td>
|
||||
<Show when={props.fullflashName}>
|
||||
<strong class="d-block d-sm-none mb-1">{props.fullflashName}</strong>
|
||||
</Show>
|
||||
<div>{formatAddress(props.address)}</div>
|
||||
<Show when={props.showBytes}>
|
||||
<code class="d-block text-nowrap">{formatAddressBytes(props.address)}</code>
|
||||
</Show>
|
||||
</td>
|
||||
);
|
||||
|
||||
const C166PointerCell: Component<{
|
||||
address: number;
|
||||
arch: Ptr89Arch;
|
||||
addressSpace: AddressSpace;
|
||||
showBytes: boolean;
|
||||
}> = (props) => {
|
||||
const pointer = createMemo(() => formatC166Pointer(props.address, props.addressSpace));
|
||||
|
||||
return (
|
||||
<td>
|
||||
<Show when={props.arch === "c166"} fallback="-">
|
||||
<div>{pointer().pointer}</div>
|
||||
<Show when={props.showBytes}>
|
||||
<code class="d-block text-nowrap">{pointer().bytes}</code>
|
||||
</Show>
|
||||
</Show>
|
||||
</td>
|
||||
);
|
||||
};
|
||||
|
||||
const BytesCell: Component<{ bytes?: string }> = (props) => {
|
||||
const [expanded, setExpanded] = createSignal(false);
|
||||
const bytes = createMemo(() => props.bytes?.replace(/\s/g, "").match(/.{1,2}/g) ?? []);
|
||||
const visibleBytes = createMemo(() => (expanded() ? bytes() : bytes().slice(0, 16)).join(" "));
|
||||
|
||||
return (
|
||||
<td>
|
||||
<Show when={bytes().length > 0} fallback="-">
|
||||
{visibleBytes()}
|
||||
<Show when={bytes().length > 16}>
|
||||
<Show when={!expanded()}> …</Show>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-link btn-sm p-0 ms-1 align-baseline"
|
||||
title={expanded() ? "Collapse bytes" : "Show all bytes"}
|
||||
aria-label={expanded() ? "Collapse bytes" : "Show all bytes"}
|
||||
aria-expanded={expanded()}
|
||||
onClick={() => setExpanded((value) => !value)}
|
||||
>
|
||||
<i class={expanded() ? "bi bi-chevron-up" : "bi bi-chevron-down"}></i>
|
||||
</button>
|
||||
</Show>
|
||||
</Show>
|
||||
</td>
|
||||
);
|
||||
};
|
||||
|
||||
const formatDuration = (duration: number) => duration < 1000 ?
|
||||
`${Math.round(duration)} ms` :
|
||||
`${(duration / 1000).toFixed(2)} s`;
|
||||
|
||||
const formatResultType = (type: Ptr89SearchType, count: number) => {
|
||||
if (count === 1)
|
||||
return type;
|
||||
if (type === "address")
|
||||
return "addresses";
|
||||
return type === "branch" ? "branches" : `${type}s`;
|
||||
};
|
||||
|
||||
const resultColumnNames: Record<Ptr89SearchType, string> = {
|
||||
address: "Address",
|
||||
pointer: "Pointer",
|
||||
reference: "Address",
|
||||
branch: "Function",
|
||||
};
|
||||
|
||||
const xrefTypeNames: Record<Ptr89XRefType, string> = {
|
||||
pointer: "Pointer",
|
||||
reference: "Address",
|
||||
branch: "Branch",
|
||||
};
|
||||
|
||||
export const SearchResults: Component<SearchResultsProps> = (props) => {
|
||||
const [ptr89State, ptr89] = usePtr89State();
|
||||
const matchGroups = createMemo(() => {
|
||||
const groups: FullflashMatch[][] = [];
|
||||
for (const match of props.result.matches) {
|
||||
const lastGroup = groups.at(-1);
|
||||
if (lastGroup?.[0].fullflashId === match.fullflashId) {
|
||||
lastGroup.push(match);
|
||||
} else {
|
||||
groups.push([match]);
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
});
|
||||
const hasC166Matches = createMemo(() => props.result.matches.some((match) => match.arch === "c166"));
|
||||
const resultColumnName = () => hasC166Matches() ? "Physical" : resultColumnNames[props.result.type];
|
||||
const resultSummary = () => `Found ${props.result.matches.length} ${formatResultType(props.result.type, props.result.matches.length)} in ${formatDuration(props.result.duration)}`;
|
||||
|
||||
return (
|
||||
<div class="mt-3">
|
||||
<Show when={props.result.issues.length > 0}>
|
||||
<div class="alert alert-warning py-2" role="alert">
|
||||
<For each={props.result.issues}>{(issue) =>
|
||||
<div>
|
||||
<strong>{issue.fullflashName}:</strong> {issue.message}
|
||||
</div>
|
||||
}</For>
|
||||
</div>
|
||||
</Show>
|
||||
<h6 class="mb-2">
|
||||
{resultSummary()}
|
||||
</h6>
|
||||
<Show when={props.result.matches.length > 0}>
|
||||
<div class="d-flex flex-row mb-2">
|
||||
<Form.Check
|
||||
inline
|
||||
id="ptr89-show-address-bytes"
|
||||
type="checkbox"
|
||||
class="me-4"
|
||||
label="Show address bytes"
|
||||
checked={ptr89State.showAddressBytes}
|
||||
onChange={(e) => ptr89.setState("showAddressBytes", e.currentTarget.checked)}
|
||||
/>
|
||||
<Show when={hasC166Matches()}>
|
||||
<span class="me-3">Address space:</span>
|
||||
<Form.Check
|
||||
inline
|
||||
id="ptr89-address-space-data"
|
||||
name="ptr89-address-space"
|
||||
type="radio"
|
||||
label="DATA"
|
||||
checked={ptr89State.addressSpace === "data"}
|
||||
onChange={() => ptr89.setState("addressSpace", "data")}
|
||||
/>
|
||||
<Form.Check
|
||||
inline
|
||||
id="ptr89-address-space-code"
|
||||
name="ptr89-address-space"
|
||||
type="radio"
|
||||
label="CODE"
|
||||
checked={ptr89State.addressSpace === "code"}
|
||||
onChange={() => ptr89.setState("addressSpace", "code")}
|
||||
/>
|
||||
</Show>
|
||||
</div>
|
||||
<table class="table table-bordered table-hover table-sticky-header font-monospace" style={{ width: "auto" }}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="d-none d-sm-table-cell">
|
||||
<small>File</small>
|
||||
</th>
|
||||
<th>
|
||||
<small>{resultColumnName()}</small>
|
||||
</th>
|
||||
<th>
|
||||
<small>Offset</small>
|
||||
</th>
|
||||
<Show when={hasC166Matches()}>
|
||||
<th>
|
||||
<small title={ptr89State.addressSpace === "data" ? "PAG:POF" : "SEG:SOF"}>
|
||||
Pointer
|
||||
</small>
|
||||
</th>
|
||||
</Show>
|
||||
<Show when={props.result.type === "address"}>
|
||||
<th>
|
||||
<small>Bytes</small>
|
||||
</th>
|
||||
</Show>
|
||||
</tr>
|
||||
</thead>
|
||||
<For each={matchGroups()}>{(group) =>
|
||||
<tbody>
|
||||
<For each={group}>{(match, index) =>
|
||||
<tr>
|
||||
<td class="d-none d-sm-table-cell text-truncate" title={index() === 0 ? match.fullflashName : undefined}>
|
||||
{index() === 0 ? match.fullflashName : ""}
|
||||
</td>
|
||||
<AddressCell
|
||||
address={match.address}
|
||||
showBytes={ptr89State.showAddressBytes}
|
||||
fullflashName={index() === 0 ? match.fullflashName : undefined}
|
||||
/>
|
||||
{match.offset === undefined ?
|
||||
<td>-</td> :
|
||||
<AddressCell address={match.offset} showBytes={ptr89State.showAddressBytes} />
|
||||
}
|
||||
<Show when={hasC166Matches()}>
|
||||
<C166PointerCell
|
||||
address={match.address}
|
||||
arch={match.arch}
|
||||
addressSpace={ptr89State.addressSpace}
|
||||
showBytes={ptr89State.showAddressBytes}
|
||||
/>
|
||||
</Show>
|
||||
<Show when={props.result.type === "address"}>
|
||||
<BytesCell bytes={match.bytes} />
|
||||
</Show>
|
||||
</tr>
|
||||
}</For>
|
||||
</tbody>
|
||||
}</For>
|
||||
</table>
|
||||
</Show>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const XRefResults: Component<XRefResultsProps> = (props) => {
|
||||
const resultSummary = () => `Found ${props.result.xrefs.length} ${props.result.xrefs.length === 1 ? "x-reference" : "x-references"} in ${formatDuration(props.result.duration)}`;
|
||||
|
||||
return (
|
||||
<div class="mt-3">
|
||||
<h6 class="mb-2">
|
||||
{resultSummary()}
|
||||
</h6>
|
||||
<Show when={props.result.xrefs.length > 0}>
|
||||
<table class="table table-bordered table-hover table-sticky-header font-monospace" style={{ width: "auto" }}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<small>Type</small>
|
||||
</th>
|
||||
<th>
|
||||
<small>X-Reference</small>
|
||||
</th>
|
||||
<th>
|
||||
<small>Offset</small>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<For each={props.result.xrefs}>{(xref) =>
|
||||
<tr>
|
||||
<td>{xrefTypeNames[xref.type]}</td>
|
||||
<td>{formatAddress(xref.xref)}</td>
|
||||
<td>{formatAddress(xref.offset)}</td>
|
||||
</tr>
|
||||
}</For>
|
||||
</tbody>
|
||||
</table>
|
||||
</Show>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
60
src/pages/Ptr89/ptr89.worker.ts
Normal file
60
src/pages/Ptr89/ptr89.worker.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import {
|
||||
type Ptr89OpenOptions,
|
||||
type Ptr89SearchResult,
|
||||
type Ptr89SearchType,
|
||||
type Ptr89XRef,
|
||||
prettify,
|
||||
Ptr89,
|
||||
} from "@sie-js/ptr89";
|
||||
|
||||
export type Ptr89WorkerPayload = {
|
||||
operation: "find";
|
||||
file: File;
|
||||
options: Ptr89OpenOptions;
|
||||
pattern: string;
|
||||
limit: number;
|
||||
align: number;
|
||||
} | {
|
||||
operation: "findXRefs";
|
||||
file: File;
|
||||
options: Ptr89OpenOptions;
|
||||
address: number;
|
||||
limit: number;
|
||||
} | {
|
||||
operation: "prettify";
|
||||
pattern: string;
|
||||
};
|
||||
|
||||
export type Ptr89WorkerResponse =
|
||||
| { matches: Ptr89SearchResult[]; type: Ptr89SearchType }
|
||||
| { xrefs: Ptr89XRef[] }
|
||||
| { pattern: string }
|
||||
| { error: string };
|
||||
|
||||
const worker = self as unknown as Worker;
|
||||
const ptr89 = new Ptr89();
|
||||
|
||||
worker.addEventListener("message", async (event: MessageEvent<Ptr89WorkerPayload>) => {
|
||||
const request = event.data;
|
||||
let response: Ptr89WorkerResponse;
|
||||
|
||||
try {
|
||||
if (request.operation === "prettify") {
|
||||
response = { pattern: await prettify(request.pattern) };
|
||||
} else {
|
||||
await ptr89.openFile(request.file, request.options);
|
||||
if (request.operation === "find") {
|
||||
const search = ptr89.find(request.pattern, request.limit, request.align);
|
||||
response = { matches: search.results, type: search.type };
|
||||
} else {
|
||||
response = { xrefs: ptr89.findXRefs(request.address, request.limit) };
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
response = { error: error instanceof Error ? error.message : String(error) };
|
||||
} finally {
|
||||
ptr89.close();
|
||||
}
|
||||
|
||||
worker.postMessage(response);
|
||||
});
|
||||
107
src/pages/Ptr89/store/ptr89State.ts
Normal file
107
src/pages/Ptr89/store/ptr89State.ts
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
import type { FileWithHandle } from "browser-fs-access";
|
||||
import type {
|
||||
Ptr89Arch,
|
||||
Ptr89SearchResult,
|
||||
Ptr89SearchType,
|
||||
Ptr89XRef,
|
||||
} from "@sie-js/ptr89";
|
||||
import { createStoreWithApi } from "@/utils/createStoreWithApi";
|
||||
import {
|
||||
loadPersistentFiles,
|
||||
readPersistentFile,
|
||||
removePersistentFile,
|
||||
requestPersistentFilePermissions,
|
||||
savePersistentFile,
|
||||
} from "@/utils/persistentFiles";
|
||||
|
||||
export type AddressSpace = "data" | "code";
|
||||
|
||||
export interface Fullflash {
|
||||
id: string;
|
||||
name: string;
|
||||
folder: string;
|
||||
arch: Ptr89Arch;
|
||||
base?: number;
|
||||
}
|
||||
|
||||
export interface FullflashMatch extends Ptr89SearchResult {
|
||||
fullflashId: string;
|
||||
fullflashName: string;
|
||||
arch: Ptr89Arch;
|
||||
}
|
||||
|
||||
export interface SearchResult {
|
||||
matches: FullflashMatch[];
|
||||
issues: Array<{ fullflashName: string; message: string }>;
|
||||
type: Ptr89SearchType;
|
||||
duration: number;
|
||||
}
|
||||
|
||||
export interface XRefResult {
|
||||
xrefs: Ptr89XRef[];
|
||||
duration: number;
|
||||
}
|
||||
|
||||
export const usePtr89State = createStoreWithApi(
|
||||
() => ({
|
||||
fullflashes: [] as Fullflash[],
|
||||
disabledFullflashIds: [] as string[],
|
||||
folder: "",
|
||||
pattern: "",
|
||||
align: 1,
|
||||
limit: 10,
|
||||
showAddressBytes: false,
|
||||
addressSpace: "data" as AddressSpace,
|
||||
xrefAddress: "",
|
||||
xrefFullflashId: "",
|
||||
}),
|
||||
(state, setState) => ({
|
||||
setState,
|
||||
loadFiles: loadPersistentFiles,
|
||||
readFile(fullflash: Fullflash) {
|
||||
return readPersistentFile(fullflash.id);
|
||||
},
|
||||
requestFilePermissions(fullflashes: Fullflash[]) {
|
||||
return requestPersistentFilePermissions(fullflashes.map((fullflash) => fullflash.id));
|
||||
},
|
||||
async addFullflashes(fullflashes: Fullflash[], files: FileWithHandle[]) {
|
||||
const savedIds: string[] = [];
|
||||
try {
|
||||
for (let i = 0; i < fullflashes.length; i++) {
|
||||
await savePersistentFile(fullflashes[i].id, files[i]);
|
||||
savedIds.push(fullflashes[i].id);
|
||||
}
|
||||
} catch (error) {
|
||||
await Promise.all(savedIds.map(removePersistentFile));
|
||||
throw error;
|
||||
}
|
||||
setState("fullflashes", (saved) => [...saved, ...fullflashes]);
|
||||
},
|
||||
updateFullflashes(fullflashes: Fullflash[]) {
|
||||
const savedFullflashes = new Map(state.fullflashes.map((fullflash) => [fullflash.id, fullflash]));
|
||||
const changed = fullflashes.some((fullflash) => {
|
||||
const saved = savedFullflashes.get(fullflash.id);
|
||||
return !saved ||
|
||||
saved.name !== fullflash.name ||
|
||||
saved.arch !== fullflash.arch ||
|
||||
saved.base !== fullflash.base ||
|
||||
saved.folder !== fullflash.folder;
|
||||
});
|
||||
if (changed)
|
||||
setState("fullflashes", fullflashes);
|
||||
return changed;
|
||||
},
|
||||
async removeFullflash(id: string) {
|
||||
await removePersistentFile(id);
|
||||
setState("fullflashes", (fullflashes) => fullflashes.filter((fullflash) => fullflash.id !== id));
|
||||
setState("disabledFullflashIds", (ids) => ids.filter((disabledId) => disabledId !== id));
|
||||
},
|
||||
setFullflashEnabled(id: string, enabled: boolean) {
|
||||
setState("disabledFullflashIds", (ids) => enabled ?
|
||||
ids.filter((disabledId) => disabledId !== id) :
|
||||
[...ids, id]
|
||||
);
|
||||
},
|
||||
}),
|
||||
{ persist: { name: "ptr89", debounce: 250 } }
|
||||
);
|
||||
|
|
@ -12,9 +12,9 @@ export function createStoreWithApi<S extends object, A>(
|
|||
options?: CreateStoreWithApiOptions<S>
|
||||
): () => [store: S, api: A] {
|
||||
const [store, setStore] = createRoot(() => {
|
||||
return options?.persist
|
||||
? makePersistedStore(createStore<S>(initialData()), options.persist)
|
||||
: createStore<S>(initialData());
|
||||
return options?.persist ?
|
||||
makePersistedStore(createStore<S>(initialData()), options.persist) :
|
||||
createStore<S>(initialData());
|
||||
});
|
||||
const api = createApi(store, setStore);
|
||||
return () => [store, api];
|
||||
|
|
|
|||
|
|
@ -36,14 +36,11 @@ export function makePersistedStore<T>(store: [Store<T>, SetStoreFunction<T>], op
|
|||
const storedValue = skipLoad ? null : storage.getItem(name);
|
||||
if (storedValue !== null) {
|
||||
const parsed = deserialize(storedValue) as PersistentStoreInternal;
|
||||
if (parsed != null && parsed.version !== null) {
|
||||
const typedState = parsed.state as T;
|
||||
if (parsed.version !== version) {
|
||||
parsed.state = migrate(typedState, parsed.version);
|
||||
parsed.version = version;
|
||||
}
|
||||
parsed.state = merge(typedState, unwrap(store[0]));
|
||||
store[1](reconcile(typedState));
|
||||
if (parsed != null && typeof parsed.version === "number") {
|
||||
const persistedState = parsed.version === version ?
|
||||
parsed.state as T :
|
||||
migrate(parsed.state as T, parsed.version);
|
||||
store[1](reconcile(merge(persistedState, unwrap(store[0]))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
70
src/utils/persistentFiles.ts
Normal file
70
src/utils/persistentFiles.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import { createStore, del, entries, get, set } from "idb-keyval";
|
||||
import type { FileSystemHandle, FileWithHandle } from "browser-fs-access";
|
||||
|
||||
const storage = createStore("web-dev-tools-files", "files");
|
||||
type FileHandle = NonNullable<FileWithHandle["handle"]> & FileSystemHandle;
|
||||
type StoredFile = File | FileHandle;
|
||||
|
||||
const fileHandles = new Map<string, FileHandle>();
|
||||
|
||||
const isFileHandle = (file: StoredFile): file is FileHandle => "getFile" in file;
|
||||
|
||||
const readFileHandle = async (handle: FileHandle) => {
|
||||
if (await handle.queryPermission({ mode: "read" }) !== "granted")
|
||||
throw new Error(`Access to ${handle.name} was not granted.`);
|
||||
return handle.getFile();
|
||||
};
|
||||
|
||||
export const loadPersistentFiles = async (): Promise<void> => {
|
||||
fileHandles.clear();
|
||||
for (const [id, file] of await entries<string, StoredFile>(storage)) {
|
||||
if (isFileHandle(file))
|
||||
fileHandles.set(id, file);
|
||||
}
|
||||
};
|
||||
|
||||
export const savePersistentFile = async (id: string, file: FileWithHandle): Promise<void> => {
|
||||
if (file.handle) {
|
||||
const handle = file.handle as FileHandle;
|
||||
try {
|
||||
await set(id, handle, storage);
|
||||
fileHandles.set(id, handle);
|
||||
return;
|
||||
} catch {
|
||||
// Fall back to storing the file when the browser cannot clone the handle.
|
||||
}
|
||||
}
|
||||
|
||||
await set(id, file, storage);
|
||||
fileHandles.delete(id);
|
||||
};
|
||||
|
||||
export const requestPersistentFilePermissions = async (ids: string[]): Promise<void> => {
|
||||
const handles = ids.map((id) => fileHandles.get(id)).filter((handle) => handle !== undefined);
|
||||
const permissions = await Promise.all(handles.map((handle) => handle.requestPermission({ mode: "read" })));
|
||||
|
||||
for (let i = 0; i < permissions.length; i++) {
|
||||
if (permissions[i] !== "granted")
|
||||
throw new Error(`Access to ${handles[i].name} was not granted.`);
|
||||
}
|
||||
};
|
||||
|
||||
export const readPersistentFile = async (id: string): Promise<File> => {
|
||||
const cachedHandle = fileHandles.get(id);
|
||||
if (cachedHandle)
|
||||
return readFileHandle(cachedHandle);
|
||||
|
||||
const file = await get<StoredFile>(id, storage);
|
||||
if (!file)
|
||||
throw new Error("File was not found.");
|
||||
if (isFileHandle(file)) {
|
||||
fileHandles.set(id, file);
|
||||
return readFileHandle(file);
|
||||
}
|
||||
return file;
|
||||
};
|
||||
|
||||
export const removePersistentFile = async (id: string): Promise<void> => {
|
||||
await del(id, storage);
|
||||
fileHandles.delete(id);
|
||||
};
|
||||
|
|
@ -89,7 +89,7 @@ export default defineConfig({
|
|||
}),
|
||||
],
|
||||
optimizeDeps: {
|
||||
exclude: [],
|
||||
exclude: ['@sie-js/ptr89'],
|
||||
},
|
||||
server: {
|
||||
port: 3000,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue