Skip to content

Commit

Permalink
Wire up some more
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Sep 24, 2024
1 parent 71b3a3f commit 23618dd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
4 changes: 4 additions & 0 deletions apps/tracer/src/DisassemblyView.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
color: #e4e4e4;
user-select: text;
}

a.disassembly-menu-open {
background-color: #ef6456;
}
63 changes: 51 additions & 12 deletions apps/tracer/src/DisassemblyView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./DisassemblyView.css";
import { useR2 } from "./use-r2.js";
import { Spinner } from "@blueprintjs/core";
import { useEffect, useState } from "react";
import { hideContextMenu, Menu, MenuItem, showContextMenu, Spinner } from "@blueprintjs/core";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";

export interface DisassemblyViewProps {
target?: DisassemblyTarget;
Expand All @@ -21,8 +21,9 @@ export interface InstructionTarget {
}

export default function DisassemblyView({ target }: DisassemblyViewProps = {}) {
const [r2Output, setR2Output] = useState("");
const [r2Output, setR2Output] = useState<string[]>([]);
const [isLoading, setIsLoading] = useState(false);
const highlightedAddressAnchorRef = useRef<HTMLAnchorElement | null>(null);
const { executeR2Command } = useR2();

useEffect(() => {
Expand All @@ -46,13 +47,20 @@ export default function DisassemblyView({ target }: DisassemblyViewProps = {}) {
].join("; ")
: `s ${t.address}; pd`;
let result = await executeR2Command(command);
if (ignore) {
return;
}
if (result === "") {
result = await executeR2Command("pdr");
}
if (!ignore) {
setR2Output(result);
setIsLoading(false);
if (ignore) {
return;
}

setR2Output(result
.split("<br />")
.map(line => line.replace(/\b0x[0-9a-f]+\b/, address => `<a>${address}</a>`)));
setIsLoading(false);
}

start();
Expand All @@ -62,13 +70,44 @@ export default function DisassemblyView({ target }: DisassemblyViewProps = {}) {
};
}, [target]);

if (isLoading) {
return (
<Spinner className="disassembly-view" />
);
}
const handleAddressMenuClose = useCallback(() => {
hideContextMenu();

highlightedAddressAnchorRef.current!.classList.remove("disassembly-menu-open");
highlightedAddressAnchorRef.current = null;
}, []);

const addressMenu = useMemo(() => (
<Menu>
<MenuItem text="Add instruction-level hook" icon="add" />
</Menu>
), [handleAddressMenuClose]);

const handleContextMenu = useCallback((event: React.MouseEvent) => {
const target = event.target;
if (!(target instanceof HTMLAnchorElement)) {
return;
}

event.preventDefault();

showContextMenu({
content: addressMenu,
onClose: handleAddressMenuClose,
targetOffset: {
left: event.clientX,
top: event.clientY
},
});

highlightedAddressAnchorRef.current = target;
target.classList.add("disassembly-menu-open");
}, [handleAddressMenuClose, addressMenu]);

return (
<div className="disassembly-view" dangerouslySetInnerHTML={{ __html: r2Output }} />
<div className="disassembly-view" onContextMenu={handleContextMenu}>
{isLoading ? (<Spinner className="disassembly-view" />) : undefined}
{r2Output.map((line, i) => <div key={i} dangerouslySetInnerHTML={{ __html: line }} />)}
</div>
);
}
2 changes: 1 addition & 1 deletion apps/tracer/src/EventView.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}

.event-highlighted {
background-color: #EF6456;
background-color: #ef6456;
}

.event-highlighted .event-timestamp {
Expand Down

0 comments on commit 23618dd

Please sign in to comment.