import type { MemShellResult } from "@/types/memshell";
import { DownloadIcon } from "lucide-react";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import CodeViewer from "@/components/code-viewer";
import { Button } from "@/components/ui/button";
import { base64ToBytes, downloadBytes, downloadContent } from "@/lib/utils";
import { AgentResult } from "./agent";
import { JarResult } from "./jar-result";
export function ResultComponent({
packResult,
packMethod,
generateResult,
}: Readonly<{
packResult: string | undefined;
packMethod: string;
generateResult?: MemShellResult;
}>) {
const showCode = packMethod === "JSP";
const isAgent = packMethod.startsWith("Agent");
const isJar = packMethod.endsWith("Jar");
const { t } = useTranslation();
const shellClassName = generateResult?.shellClassName;
const handleDownload = useCallback(() => {
const fileName = shellClassName?.substring(shellClassName?.lastIndexOf(".") ?? 0) ?? "";
if (packMethod.includes("JSP")) {
const fileExtension = packMethod.includes("JSPX") ? ".jspx" : ".jsp";
const content = new Blob([packResult as string], { type: "text/plain" });
return downloadContent(content, fileName, fileExtension);
} else if (packMethod.includes("JavaCommons") || packMethod.includes("Hessian")) {
const content = new Blob([base64ToBytes(packResult as string)], {
type: "application/octet-stream",
});
return downloadContent(content, fileName, ".data");
} else if (packMethod === "Base64") {
return downloadBytes(packResult as string, shellClassName);
}
}, [packMethod, packResult, shellClassName]);
if (isAgent) {
return (
);
}
if (isJar) {
return (
);
}
return (
{t("common:packerMethod")}:{packMethod}
({packResult?.length})
}
button={
packMethod.includes("JSP") ||
packMethod === "Base64" ||
packMethod.includes("JavaCommons") ||
packMethod.includes("Hessian") ? (
) : null
}
wrapLongLines={!showCode}
showLineNumbers={showCode}
language={showCode ? "java" : "text"}
height={350}
/>
);
}