diff --git a/index.html b/index.html index 29d8b03..82bb85d 100644 --- a/index.html +++ b/index.html @@ -1,23 +1,30 @@ - + Siemens Dev Tools - - diff --git a/package.json b/package.json index cb7716f..eb65f8b 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "vite-plugin-solid-svg": "^0.8.1" }, "dependencies": { + "@material-design-icons/svg": "^0.14.15", "@solid-primitives/context": "^0.3.2", "@solidjs/router": "^0.15.4", "@suid/types": "^0.8.0", @@ -30,6 +31,7 @@ "bootstrap-icons": "^1.13.1", "clsx": "^2.1.1", "date-fns": "^3.6.0", + "es-toolkit": "^1.43.0", "highlight.js": "^11.11.1", "sass": "^1.97.2", "solid-bootstrap": "^1.0.21", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 72f5480..9fd261f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@material-design-icons/svg': + specifier: ^0.14.15 + version: 0.14.15 '@solid-primitives/context': specifier: ^0.3.2 version: 0.3.2(solid-js@1.9.10) @@ -41,6 +44,9 @@ importers: date-fns: specifier: ^3.6.0 version: 3.6.0 + es-toolkit: + specifier: ^1.43.0 + version: 1.43.0 highlight.js: specifier: ^11.11.1 version: 11.11.1 @@ -341,6 +347,9 @@ packages: '@jridgewell/trace-mapping@0.3.31': resolution: {integrity: sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==} + '@material-design-icons/svg@0.14.15': + resolution: {integrity: sha512-6nbjwGwyJnphwQUscJAYqw1Tk6+W8KvsgOAeyVgzIFXVsHfgX5XyplTUcZ29wbcTUysMMyCUi1LYpmFKA/e61g==} + '@nothing-but/utils@0.17.0': resolution: {integrity: sha512-TuCHcHLOqDL0SnaAxACfuRHBNRgNJcNn9X0GiH5H3YSDBVquCr3qEIG3FOQAuMyZCbu9w8nk2CHhOsn7IvhIwQ==} @@ -834,6 +843,9 @@ packages: resolution: {integrity: sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==} engines: {node: '>= 0.4'} + es-toolkit@1.43.0: + resolution: {integrity: sha512-SKCT8AsWvYzBBuUqMk4NPwFlSdqLpJwmy6AP322ERn8W2YLIB6JBXnwMI2Qsh2gfphT3q7EKAxKb23cvFHFwKA==} + esbuild@0.27.2: resolution: {integrity: sha512-HyNQImnsOC7X9PMNaCIeAm4ISCQXs5a5YasTXVliKv4uuBo1dKrG0A+uQS8M5eXjVMnLg3WgXaKvprHlFJQffw==} engines: {node: '>=18'} @@ -1419,6 +1431,8 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.5 + '@material-design-icons/svg@0.14.15': {} + '@nothing-but/utils@0.17.0': {} '@parcel/watcher-android-arm64@2.5.1': @@ -1867,6 +1881,8 @@ snapshots: has-tostringtag: 1.0.2 hasown: 2.0.2 + es-toolkit@1.43.0: {} + esbuild@0.27.2: optionalDependencies: '@esbuild/aix-ppc64': 0.27.2 diff --git a/src/assets/icons/menu.svg b/src/assets/icons/menu.svg new file mode 100644 index 0000000..c127b55 --- /dev/null +++ b/src/assets/icons/menu.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/Header.tsx b/src/components/Header.tsx deleted file mode 100644 index 97df4e3..0000000 --- a/src/components/Header.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { ParentProps, Component } from "solid-js"; -import { A, useMatch } from "@solidjs/router"; - -import { Container } from 'solid-bootstrap'; -import { Navbar } from 'solid-bootstrap'; -import { Nav } from 'solid-bootstrap'; - -import { resolveURL } from '@/utils'; - -const HeaderLink: Component> = (props) => { - const match = useMatch(() => resolveURL(props.href)); - return ( - - {props.children} - - ); -}; - -export const Header: Component = () => { - return ( - - - Dev Tools - - - - - - - ); -}; diff --git a/src/components/Layout/App.tsx b/src/components/Layout/App.tsx index 20015c9..a72285d 100644 --- a/src/components/Layout/App.tsx +++ b/src/components/Layout/App.tsx @@ -1,13 +1,58 @@ /* @refresh reload */ -import { ParentComponent } from "solid-js"; -import { Header } from "@/components/Header"; -import { Container } from "solid-bootstrap"; +import { createSignal, onCleanup, onMount, ParentComponent, Show } from "solid-js"; +import { Header } from "@/components/Layout/Header"; +import { Container, Offcanvas } from "solid-bootstrap"; +import { Sidebar } from "@/components/Layout/Sidebar/Sidebar"; +import { ThemeProvider } from "@/context/ThemeProvider"; export const App: ParentComponent = (props) => { - return <> -
- - {props.children} - - ; + const [sidebarIsOffcanvas, setSidebarOffcanvas] = createSignal(false); + const [sidebarIsOpen, setSidebarOpen] = createSignal(false); + + const handleSidebarHide = () => { + setSidebarOpen(false); + }; + + onMount(() => { + const handleWindowResize = () => { + const width = window.innerWidth; + setSidebarOffcanvas(width <= 1200); + setSidebarOpen(false); + }; + window.addEventListener('resize', handleWindowResize); + handleWindowResize(); + onCleanup(() => window.removeEventListener('resize', handleWindowResize)); + }); + + return ( + +
setSidebarOpen((prev) => !prev)} + /> + +
+ + }> + + + + + + + +
+ {props.children} +
+
+
+ + ); + }; diff --git a/src/components/Layout/Header.scss b/src/components/Layout/Header.scss new file mode 100644 index 0000000..63f9bb1 --- /dev/null +++ b/src/components/Layout/Header.scss @@ -0,0 +1,35 @@ +.header { + --bs-navbar-padding-y: 0.2rem; + + display: flex; + align-items: center; + justify-content: space-between; + height: var(--bs-header-height); + padding: 0 0.5rem; + + position: sticky; + top: 0; + z-index: 1020; + + background: var(--bs-body-bg); + border-bottom: 1px solid var(--bs-content-separator); + + &__title { + font-size: 1.25rem; + font-weight: 500; + color: var(--bs-primary-color); + text-decoration: none; + padding: 0 0.5rem; + } + + &__button { + display: flex; + align-items: center; + justify-content: center; + background: transparent; + border: none; + padding: 0.5rem; + cursor: pointer; + font-size: 2rem; + } +} diff --git a/src/components/Layout/Header.tsx b/src/components/Layout/Header.tsx new file mode 100644 index 0000000..87eccd5 --- /dev/null +++ b/src/components/Layout/Header.tsx @@ -0,0 +1,47 @@ +import './Header.scss'; +import { Component, Match, Show, Switch } from "solid-js"; +import { A } from "@solidjs/router"; +import MenuIcon from '@/assets/icons/menu.svg'; +import BrightnessIcon from '@material-design-icons/svg/outlined/brightness_medium.svg'; +import BedtimeIcon from '@material-design-icons/svg/outlined/bedtime.svg'; +import LightModeIcon from '@material-design-icons/svg/outlined/light_mode.svg'; +import { useTheme } from "@/context/ThemeProvider"; + +interface HeaderProps { + showSidebarToggleButton: boolean; + onSidebarToggle?: () => void; +} + +export const Header: Component = (props) => { + const { theme, switchTheme } = useTheme(); + + return ( +
+ + + + + + Dev Tools + + + +
+ ); +}; diff --git a/src/components/Layout/Root.tsx b/src/components/Layout/Root.tsx index 7a7e3c3..79b17fc 100644 --- a/src/components/Layout/Root.tsx +++ b/src/components/Layout/Root.tsx @@ -15,10 +15,10 @@ export const Root: Component = () => { return ( - "/swilib"} />} /> - - - + "/swilib/analysis/summary"} />} /> + + + ); diff --git a/src/components/Layout/Sidebar/Sidebar.scss b/src/components/Layout/Sidebar/Sidebar.scss new file mode 100644 index 0000000..2848ff4 --- /dev/null +++ b/src/components/Layout/Sidebar/Sidebar.scss @@ -0,0 +1,62 @@ +.sidebar { + height: calc(100dvh - var(--bs-header-height)); + + width: 280px; + flex-shrink: 0; + background: var(--bs-body-bg); + border-right: 1px solid var(--bs-content-separator); + padding-top: 0.5rem; + + position: sticky; + top: var(--bs-header-height); + + &--offcanvas { + height: auto; + border-right: none; + position: static; + } + + &__section { + margin-bottom: 0.35rem; + } + + &__section-title { + text-transform: uppercase; + color: var(--bs-secondary-color); + letter-spacing: 0.04em; + padding: 0.35rem 1rem; + } + + &__link { + position: relative; + display: flex; + align-items: center; + column-gap: 8px; + + padding: 0.35rem 1rem 0.35rem 2rem; + + color: var(--bs-body-color); + text-decoration: none; + + transition: + background-color 0.15s ease, + color 0.15s ease; + + &:hover:not(&--active) { + text-decoration: none; + background-color: var(--sidebar-link-hover-bg); + } + + &--active { + background-color: var(--sidebar-link-active-bg); + color: var(--sidebar-link-active-color); + font-weight: 400; + } + } + + &__label { + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + } +} diff --git a/src/components/Layout/Sidebar/Sidebar.tsx b/src/components/Layout/Sidebar/Sidebar.tsx new file mode 100644 index 0000000..5697335 --- /dev/null +++ b/src/components/Layout/Sidebar/Sidebar.tsx @@ -0,0 +1,55 @@ +import "./Sidebar.scss"; +import { Component, For } from "solid-js"; +import { SidebarLink, SidebarLinkProps } from "@/components/Layout/Sidebar/SidebarLink"; +import clsx from "clsx"; + +interface SidebarSection { + title: string; + links: Array +} + +interface SidebarProps { + offcanvas?: boolean +} + +export const Sidebar: Component = (props) => { + const sections: SidebarSection[] = [ + { + title: "Functions library", + links: [ + { label: "Swilib analysis", href: "/swilib/analysis/summary", icon: "bi bi-activity" }, + { label: "Check swilib.vkp", href: "/swilib/check", icon: "bi bi-file-earmark-check" }, + { label: "Merge swilib.vkp", href: "/swilib/merge", icon: "bi bi-arrow-left-right" } + ] + }, + + { + title: "Reverse engineering", + links: [ + { label: "Patterns finder", href: "/re/ptr89", icon: "bi bi-search" }, + { label: "Download symbols", href: "/re/symbols", icon: "bi bi-download" } + ] + }, + + { + title: "Database", + links: [ + { label: "Patches map", href: "/db/patches-map", icon: "bi bi-diagram-3" }, + { label: "Memory map", href: "/db/memory-map", icon: "bi bi-grid-3x3-gap" } + ] + } + ]; + + return ( + + ); +}; diff --git a/src/components/Layout/Sidebar/SidebarLink.tsx b/src/components/Layout/Sidebar/SidebarLink.tsx new file mode 100644 index 0000000..4067918 --- /dev/null +++ b/src/components/Layout/Sidebar/SidebarLink.tsx @@ -0,0 +1,23 @@ +import { Component } from "solid-js"; +import { useMatch } from "@solidjs/router"; +import { resolveURL } from "@/utils"; +import clsx from "clsx"; + +export interface SidebarLinkProps { + label: string; + href: string; + icon: string; +} + +export const SidebarLink: Component = (props) => { + const match = useMatch(() => resolveURL(props.href)); + return ( + + + {props.label} + + ); +}; diff --git a/src/components/Swilib/SwilibEntryTypeBadge.tsx b/src/components/Swilib/SwilibEntryTypeBadge.tsx index fb5ce7d..495350e 100644 --- a/src/components/Swilib/SwilibEntryTypeBadge.tsx +++ b/src/components/Swilib/SwilibEntryTypeBadge.tsx @@ -7,15 +7,15 @@ interface SwilibEntryTypeBadgeProps { export const SwilibEntryTypeBadge: Component = (props) => { return ( - }> + }> - + - + - + ); diff --git a/src/components/Swilib/SwilibTargetsTabs.tsx b/src/components/Swilib/SwilibTargetsTabs.tsx index 90b674c..eec9939 100644 --- a/src/components/Swilib/SwilibTargetsTabs.tsx +++ b/src/components/Swilib/SwilibTargetsTabs.tsx @@ -10,14 +10,14 @@ interface SwilibTargetsTabsProps { export const SwilibTargetsTabs: Component = (props) => { return ( }> -
+
{(device) => {device.model}
diff --git a/src/context/ThemeProvider.tsx b/src/context/ThemeProvider.tsx new file mode 100644 index 0000000..3034bb5 --- /dev/null +++ b/src/context/ThemeProvider.tsx @@ -0,0 +1,75 @@ +import { + Accessor, + createContext, + createEffect, + createSignal, + onCleanup, + onMount, + ParentComponent, + useContext +} from "solid-js"; +import { ThemeType } from "@/store/globalSettingsStore"; +import { makePersistedSignal } from "@/utils/makePersistedSignal"; + +interface ThemeContext { + theme: Accessor; + effectiveTheme: Accessor; + switchTheme: () => void; +} + +export const ThemeContext = createContext(); + +export const ThemeProvider: ParentComponent = (props) => { + const [effectiveTheme, setEffectiveTheme] = createSignal("light"); + const [theme, setTheme] = makePersistedSignal( + createSignal("system"), + { name: "bootstrapTheme" } + ); + const [count, setCount] = createSignal(0); + + onMount(() => { + const media = window.matchMedia('(prefers-color-scheme: dark)'); + const handleThemeChange = () => { + if (theme() == "system") { + setEffectiveTheme(media.matches ? 'dark' : 'light'); + } else { + setEffectiveTheme(theme()); + } + }; + media.addEventListener('change', handleThemeChange); + handleThemeChange(); + createEffect(handleThemeChange); + onCleanup(() => media.removeEventListener('change', handleThemeChange)); + }); + + createEffect(() => document.documentElement.dataset.bsTheme = effectiveTheme()); + + return ( + { + if (theme() == "system") { + setCount(0); + setTheme(effectiveTheme() == "dark" ? "light" : "dark"); + } else { + if (count() == 2) { + setTheme("system"); + } else { + setTheme(effectiveTheme() == "dark" ? "light" : "dark"); + } + } + setCount((prev) => prev + 1); + } + }}> + {props.children} + + ); +}; + +export function useTheme() { + const value = useContext(ThemeContext); + if (!value) + throw new Error("useTheme must be used within a "); + return value; +} diff --git a/src/index.scss b/src/index.scss index 10abe62..7e78556 100644 --- a/src/index.scss +++ b/src/index.scss @@ -53,6 +53,7 @@ $info: #0aa7c7; @import "bootstrap/scss/utilities/api"; // 8. Add additional custom code here + body { overflow-y: scroll; } @@ -62,16 +63,14 @@ body { } .table-sticky-header { - thead { + thead tr { position: sticky; - top: -1px; - } - - thead { + top: calc(var(--bs-header-height) - 1px); + background-color: var(--bs-tertiary-bg); + z-index: 3; box-shadow: 0 1px 0 var(--bs-table-border-color); } - - th { + thead th { background-color: var(--bs-tertiary-bg); } } @@ -85,13 +84,46 @@ body { cursor: pointer; } +:root { + --bs-header-height: 47px; +} + +/* Light theme fixes */ +@include color-mode(light) { + --bs-content-separator: #dfe0df; + + --sidebar-link-active-bg: #e9f2fe; + --sidebar-link-active-color: #1868db; + + --sidebar-link-hover-bg: #f0f1f2; + + .dropdown-menu { + --bs-dropdown-link-hover-bg: #e9ecef; + } +} + /* Dark theme fixes */ @include color-mode(dark) { + --bs-body-bg: #1f1f21; + --bs-tertiary-bg: #303134; + --bs-content-separator: #38393c; + + --sidebar-link-active-bg: #1c2b42; + --sidebar-link-active-color: #669df1; + + --sidebar-link-hover-bg: #242528; + + table { + --bs-table-border-color: #4b4d51; + } + /* Fix text colors */ + --bs-primary: #6da7fe; --bs-danger-rgb: 224, 82, 96; --bs-primary-rgb: 109, 167, 254; --bs-info-rgb: 11, 171, 203; --bs-success-rgb: 32, 172, 107; + --bs-secondary-rgb: 140, 148, 155; /* Fix table rows */ .table-danger { @@ -195,4 +227,10 @@ body { } } +svg { + width: 1em; + height: 1em; + fill: currentColor; +} + @import "bootstrap-icons/font/bootstrap-icons.css"; diff --git a/src/pages/Swilib/SwilibPage.tsx b/src/pages/Swilib/SwilibPage.tsx index 98a69fe..2c2dadf 100644 --- a/src/pages/Swilib/SwilibPage.tsx +++ b/src/pages/Swilib/SwilibPage.tsx @@ -1,6 +1,6 @@ -import { Component, createResource, createSignal, For, Show } from 'solid-js'; -import { A, useSearchParams } from '@solidjs/router'; -import { Button, Form, Spinner } from 'solid-bootstrap'; +import { Component, createMemo, createResource, createSignal, For, Show } from 'solid-js'; +import { useSearchParams } from '@solidjs/router'; +import { Button, Dropdown, Form, Spinner } from 'solid-bootstrap'; import { SwilibTargetsTabs } from '@/components/Swilib/SwilibTargetsTabs'; import { useSwilibTableOptionsStore } from "@/store/swilibTableOptionsStore"; import { @@ -33,6 +33,25 @@ const SwilibPage: Component = () => { setTableOptions("filterByType", e.currentTarget.value); }; + const downloadLinks = createMemo(() => ([ + { + label: <>V-Klay patch .vkp, + href: `${BACKEND_URL}/api/swilib/download/${target()}/swilib_${target()}.vkp` + }, + { + label: <>Binary library .blib, + href: `${BACKEND_URL}/api/swilib/download/${target()}/swilib_${target()}.blib` + }, + { + label: <>Ghidra symbols .txt, + href: `${BACKEND_URL}/api/swilib/download/${target()}/symbols-${target()}.txt` + }, + { + label: <>IDA Pro symbols .idc, + href: `${BACKEND_URL}/api/swilib/download/${target()}/symbols-${target()}.idc` + }, + ])); + return <>
@@ -79,7 +98,11 @@ const SwilibPage: Component = () => { />
-
-
- +
+ + + Download as … + + + {(link) => <> + + {link.label} + + } + + - - -
- - {(file) => diff --git a/src/pages/Swilib/SwilibStatistic.tsx b/src/pages/Swilib/SwilibStatistic.tsx index de30c09..2583e7f 100644 --- a/src/pages/Swilib/SwilibStatistic.tsx +++ b/src/pages/Swilib/SwilibStatistic.tsx @@ -9,24 +9,27 @@ interface SwilibStatisticProps { export const SwilibStatistic: Component = (props) => { const getPercent = (v: number) => (v / props.statistic.total * 100).toFixed(0); return ( -
+
OK: {props.statistic.good} | {getPercent(props.statistic.good)}% - {' '} - {' '} diff --git a/src/pages/Swilib/SwilibTable.tsx b/src/pages/Swilib/SwilibTable.tsx index 8036cf1..723a3b0 100644 --- a/src/pages/Swilib/SwilibTable.tsx +++ b/src/pages/Swilib/SwilibTable.tsx @@ -60,7 +60,7 @@ export const SwilibTable: Component = (props) => { diff --git a/src/pages/Swilib/SwilibTableRow.tsx b/src/pages/Swilib/SwilibTableRow.tsx index 7b339bb..abdea7d 100644 --- a/src/pages/Swilib/SwilibTableRow.tsx +++ b/src/pages/Swilib/SwilibTableRow.tsx @@ -42,8 +42,14 @@ export const SwilibTableRow: Component = (props) => { return ''; }); + const handleClick = () => props.onSelect?.(props.entry, props.targetEntry); + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Enter' || event.key === ' ') + handleClick(); + }; + return ( - props.onSelect?.(props.entry, props.targetEntry)}> + @@ -53,19 +59,16 @@ export const SwilibTableRow: Component = (props) => {