feat: done with gui

This commit is contained in:
amelia 2024-08-31 14:31:00 +01:00
parent cb1f9315de
commit 0cf7c4f6c0
No known key found for this signature in database
13 changed files with 311 additions and 23 deletions

2
Cargo.lock generated
View File

@ -1373,7 +1373,6 @@ dependencies = [
"dll-syringe",
"poggers 1.2.1 (git+https://github.com/pozm/poggers.git)",
"rust-embed",
"tauri-plugin-dialog",
"thiserror",
"windows 0.56.0",
]
@ -1382,6 +1381,7 @@ dependencies = [
name = "gdke-gui"
version = "0.1.0"
dependencies = [
"anyhow",
"serde",
"serde_json",
"tauri",

View File

@ -1,4 +1,4 @@
workspace = { members = ["gdkeinj","gdke-gui/src-tauri"] }
workspace = { members = ["gdkeinj", "gdke-gui/src-tauri"] }
[package]
name = "gdke"
version = "0.2.2"
@ -42,4 +42,3 @@ windows = { features = [
], version = "0.56" }
dll-syringe = "*"
poggers = { version = "*", git = "https://github.com/pozm/poggers.git" }
tauri-plugin-dialog = "2.0.0-rc.2"

BIN
gdke-gui/bun.lockb Normal file → Executable file

Binary file not shown.

View File

@ -10,6 +10,8 @@
"tauri": "tauri"
},
"dependencies": {
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@tauri-apps/api": ">=2.0.0-rc.0",
"@tauri-apps/plugin-dialog": "^2.0.0-rc.0",

View File

@ -20,4 +20,5 @@ tauri-plugin-shell = "2.0.0-rc"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-dialog = "2.0.0-rc"
anyhow = "*"
# gdke = { path = "../.." }

View File

@ -2,9 +2,12 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"windows": [
"main"
],
"permissions": [
"core:default",
"shell:allow-open"
"shell:allow-open",
"dialog:allow-open"
]
}

View File

@ -1,7 +1,22 @@
use std::{ffi::OsStr, path::Path};
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
fn get_secret(program: &Path, sig: &str) -> Result<String, String> {
spawn_and_inject_sig(program, sig)
.map_err(|e| e.to_string())
.map(|val| {
let mut hex_str = "0x".to_string();
for char in val {
hex_str.push_str(&format!("{char:02X}"))
}
hex_str
})
// String::new()
}
fn spawn_and_inject_sig<T: AsRef<OsStr>>(proc: T, sig: &str) -> anyhow::Result<[u8; 32]> {
Ok([62; 32])
// Err(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
@ -9,7 +24,7 @@ pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_dialog::init())
.invoke_handler(tauri::generate_handler![greet])
.invoke_handler(tauri::generate_handler![get_secret])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -1,4 +1,5 @@
{
"$schema": "https://github.com/tauri-apps/tauri/releases/download/tauri-build-v2.0.0-beta.13/schema.json",
"productName": "gdke-gui",
"version": "0.1.0",
"identifier": "one.meli.gdke-gui",
@ -30,5 +31,6 @@
"icons/icon.icns",
"icons/icon.ico"
]
}
},
"plugins": {}
}

View File

@ -3,5 +3,5 @@
@tailwind utilities;
body {
@apply dark:bg-black dark:text-white
@apply dark:bg-black dark:text-white;
}

View File

@ -1,23 +1,145 @@
import { useState } from "react";
import reactLogo from "./assets/react.svg";
import { invoke } from "@tauri-apps/api/core";
import { useEffect, useState } from "react";
import "./App.css";
import { Input } from "./components/ui/input";
import { open } from "@tauri-apps/plugin-dialog";
import { event } from "@tauri-apps/api";
import { invoke } from "@tauri-apps/api/core";
import {
Dialog,
DialogContent,
DialogTitle,
DialogDescription,
DialogHeader,
} from "./components/ui/dialog";
import { Label } from "./components/ui/label";
import { Input } from "./components/ui/input";
import { Button } from "./components/ui/button";
function App() {
const [greetMsg, setGreetMsg] = useState("");
const [name, setName] = useState("");
function get_file() {
open({
const [drag_over, set_drag_over] = useState(false);
const [show_pre_run, set_show_pre_run] = useState(false);
const [signature, set_signature] = useState("");
const [program, set_program] = useState("");
const [loading, set_loading] = useState(false);
const [outcome, set_outcome] = useState<null | [true, string] | [false]>(
null,
);
async function get_file() {
const outcome = await open({
title: "File picker",
filters: [{ name: "Applications", extensions: ["exe"] }],
directory: false,
});
if (!outcome) return;
ask_for_sig(outcome.path);
}
const run_program = () => {
set_loading(true);
invoke("get_secret", { sig: signature, program }).then(
(out) => {
set_outcome([true, out as string]);
set_loading(false);
},
(e) => {
set_loading(false);
set_outcome([false]);
},
);
};
const ask_for_sig = async (path: string) => {
set_outcome(null);
set_signature("");
set_show_pre_run(true);
set_program(path);
};
useEffect(() => {
const listeners: Promise<event.UnlistenFn>[] = [];
listeners.push(
event.listen<{ paths: string[] }>(event.TauriEvent.DRAG_DROP, (evt) => {
set_drag_over(false);
console.log(evt);
ask_for_sig(evt.payload.paths[0]);
}),
);
listeners.push(
event.listen(event.TauriEvent.DRAG_LEAVE, (evt) => {
set_drag_over(false);
console.log(evt);
}),
);
listeners.push(
event.listen(event.TauriEvent.DRAG_ENTER, (evt) => {
set_drag_over(true);
console.log(evt);
}),
);
return () => {
(async () => {
for await (const off_fn of listeners) {
off_fn();
}
})();
};
}, []);
return (
<div className="container dark:bg-black dark:text-white">
<div
className={`container dark:bg-black dark:text-white ${drag_over ? "border-dotted min-h-screen rounded-lg border-2 border-neutral-300 dark:border-neutral-700" : ""}`}
>
<Dialog open={show_pre_run} onOpenChange={(e) => set_show_pre_run(e)}>
<DialogContent>
<DialogHeader>
<DialogTitle>Extract Secret Key</DialogTitle>
{outcome === null && !loading && (
<DialogDescription>
After entering a sig we will try our hardest to search for the
key with that signature.
</DialogDescription>
)}
</DialogHeader>
<div className="flex gap-3 flex-col">
{outcome === null || loading ? (
<div>
<Label>Signature</Label>
<Input
onChange={(e) => set_signature(e.currentTarget.value)}
placeholder="59 48 29 ?? 92 47 ?? .."
/>
</div>
) : loading ? (
<div>Loading just give us a sec</div>
) : outcome?.[0] === true ? (
<>
<p className="text-neutral-300 tracking-wide">
Successfully got Key!
</p>{" "}
<Label>Secret Key</Label>{" "}
<Input readOnly={true} value={outcome[1]} />
</>
) : (
<div>failure</div>
)}
<div className="ml-auto flex flex-row gap-3">
{outcome?.[0] && (
<Button
onClick={() => navigator.clipboard.writeText(outcome[1])}
variant={"ghost"}
disabled={signature.length === 0}
>
Copy Key
</Button>
)}
<Button
onClick={
outcome === null ? run_program : () => set_show_pre_run(false)
}
disabled={signature.length === 0}
>
{outcome === null ? "Ready" : "Close"}
</Button>
</div>
</div>
</DialogContent>
</Dialog>
<h1 className="text-2xl tracking-tight">👋 Welcome to Gdke</h1>
<p className="text-neutral-400 text-lg tracking-wide">
To get started drop your program below:

View File

@ -0,0 +1,120 @@
import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { X } from "lucide-react"
import { cn } from "@/lib/utils"
const Dialog = DialogPrimitive.Root
const DialogTrigger = DialogPrimitive.Trigger
const DialogPortal = DialogPrimitive.Portal
const DialogClose = DialogPrimitive.Close
const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-slate-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-slate-800 dark:bg-slate-950",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-slate-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-slate-100 data-[state=open]:text-slate-500 dark:ring-offset-slate-950 dark:focus:ring-slate-300 dark:data-[state=open]:bg-slate-800 dark:data-[state=open]:text-slate-400">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName
const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className
)}
{...props}
/>
)
DialogHeader.displayName = "DialogHeader"
const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
DialogFooter.displayName = "DialogFooter"
const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName
const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-slate-500 dark:text-slate-400", className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName
export {
Dialog,
DialogPortal,
DialogOverlay,
DialogClose,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
}

View File

@ -0,0 +1,24 @@
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
)
const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
))
Label.displayName = LabelPrimitive.Root.displayName
export { Label }

View File

@ -1,6 +1,6 @@
pub mod versioning;
use std::{
ffi::{c_void, CStr, CString},
ffi::{c_void, CStr, CString, OsStr},
io::{Read, Write},
mem::{size_of, transmute},
net::UdpSocket,
@ -61,8 +61,8 @@ impl Drop for ProcKiller {
}
}
}
pub unsafe fn spawn_and_inject(proc: &str, sig: &str) -> anyhow::Result<[u8; 32]> {
let pth = Path::new(proc);
pub unsafe fn spawn_and_inject<T: AsRef<OsStr>>(proc: T, sig: &str) -> anyhow::Result<[u8; 32]> {
let pth = Path::new(&proc);
if !pth.is_file() {
panic!("file does not exist");
}