Skip to content

Commit

Permalink
tracer: Support customizing memory view formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Oct 6, 2024
1 parent 4c7dbfa commit 768a919
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 10 additions & 0 deletions apps/tracer/src/MemoryView.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@
color: #e4e4e4;
user-select: text;
}

.memory-view .bp5-segmented-control {
position: absolute;
bottom: 5px;
right: 5px;
}

.memory-view .bp5-segmented-control .bp5-button {
font-size: 10px;
}
32 changes: 27 additions & 5 deletions apps/tracer/src/MemoryView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "./MemoryView.css";
import { Spinner } from "@blueprintjs/core";
import { SegmentedControl, Spinner } from "@blueprintjs/core";
import { useR2 } from "@frida/react-use-r2";
import { useEffect, useState } from "react";

Expand All @@ -8,7 +8,8 @@ export interface MemoryViewProps {
}

export default function MemoryView({ address }: MemoryViewProps) {
const [data, setData] = useState<string>("");
const [format, setFormat] = useState("x");
const [data, setData] = useState("");
const [isLoading, setIsLoading] = useState(false);
const { executeR2Command } = useR2();

Expand All @@ -21,7 +22,7 @@ export default function MemoryView({ address }: MemoryViewProps) {
setIsLoading(true);

async function start() {
const data = await executeR2Command(`x @ 0x${address!.toString(16)}`);
const data = await executeR2Command(`${format} @ 0x${address!.toString(16)}`);
if (ignore) {
return;
}
Expand All @@ -35,7 +36,7 @@ export default function MemoryView({ address }: MemoryViewProps) {
return () => {
ignore = true;
};
}, [address, executeR2Command]);
}, [format, address, executeR2Command]);

if (isLoading) {
return (
Expand All @@ -44,6 +45,27 @@ export default function MemoryView({ address }: MemoryViewProps) {
}

return (
<div className="memory-view" dangerouslySetInnerHTML={{ __html: data }} />
<div className="memory-view">
<SegmentedControl
small={true}
options={[
{
label: "Raw",
value: "x",
},
{
label: "64",
value: "pxq"
},
{
label: "32",
value: "pxw"
},
]}
defaultValue="x"
onValueChange={setFormat}
/>
<div dangerouslySetInnerHTML={{ __html: data }} />
</div>
);
}

0 comments on commit 768a919

Please sign in to comment.