aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/mingwMain/kotlin/moe.yuuta.desktop/Desktop.kt56
2 files changed, 49 insertions, 9 deletions
diff --git a/README.md b/README.md
index a4a56a1..236e0a2 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,8 @@ Feel free to ask me questions in Issues and I'm sure I cannot answer them becaus
* @duangsuse
+* [https://github.com/AlphaDelta/Secure-Desktop](https://github.com/AlphaDelta/Secure-Desktop)
+
* Others
# Licenses
diff --git a/src/mingwMain/kotlin/moe.yuuta.desktop/Desktop.kt b/src/mingwMain/kotlin/moe.yuuta.desktop/Desktop.kt
index ecef5fd..9d881c9 100644
--- a/src/mingwMain/kotlin/moe.yuuta.desktop/Desktop.kt
+++ b/src/mingwMain/kotlin/moe.yuuta.desktop/Desktop.kt
@@ -1,18 +1,27 @@
package moe.yuuta.desktop
+import kotlinx.cinterop.cValue
+import kotlinx.cinterop.convert
+import kotlinx.cinterop.cstr
+import kotlinx.cinterop.memScoped
import platform.posix.printf
import platform.windows.*
import kotlin.native.concurrent.TransferMode
import kotlin.native.concurrent.Worker
+private data class WorkerArg(val desktopName: String,
+ val desktop: HDESK?,
+ val program: String?)
+
@Suppress("unused")
-fun main() {
+fun main(args: Array<String>?) {
printf("Secure Desktop demo by i@yuuta.moe")
val oldDesktop = GetThreadDesktop(GetCurrentThreadId())
- val newDesktop = CreateDesktopA("desktop_dialog",
+ val desktopName = "desktop_dialog"
+ val newDesktop = CreateDesktopA(desktopName,
null,
null,
- 0,
+ 0.convert(),
(DESKTOP_READOBJECTS or
DESKTOP_CREATEWINDOW or
DESKTOP_CREATEMENU or
@@ -24,14 +33,43 @@ fun main() {
DESKTOP_SWITCHDESKTOP).toUInt(),
null)
SwitchDesktop(newDesktop)
- Worker.start().execute(TransferMode.SAFE, { newDesktop }) {
- SetThreadDesktop(it)
- MessageBoxA(null,
- "Hi! This is message from thread ${GetCurrentThreadId()} in the secure desktop.",
- "Secure Desktop",
- (MB_OK or MB_ICONINFORMATION).toUInt())
+ Worker.start().execute(TransferMode.SAFE,
+ { WorkerArg(desktopName,
+ newDesktop,
+ if (args != null && args.isNotEmpty()) args[0] else null
+ ) }) {
+ exec(it)
}.consume {
SwitchDesktop(oldDesktop)
CloseDesktop(newDesktop)
}
+}
+
+private fun exec(arg: WorkerArg): Int {
+ SetThreadDesktop(arg.desktop)
+ if (arg.program != null) memScoped {
+ val startupInfo = cValue<STARTUPINFOA> {
+ lpDesktop = arg.desktopName.cstr.ptr
+ dwFlags = STARTF_RUNFULLSCREEN.convert()
+ }
+ val pi = cValue<PROCESS_INFORMATION> {
+ }
+ // TODO: Close these objects?
+ return@memScoped CreateProcessA(arg.program,
+ null,
+ null,
+ null,
+ 0,
+ 0.convert(),
+ null,
+ null,
+ startupInfo.ptr,
+ pi.ptr)
+ }
+ return MessageBoxA(null,
+ "Hi! This is message from thread ${GetCurrentThreadId()} in the secure desktop." +
+ "\nTo load a custom program, run Desktop.exe <path\\to\\your\\program\\.exe>." +
+ "\nYou can exit the desktop when you close the dialog or press OK. Programs in the desktop won't be terminated when you exit.",
+ "Secure Desktop",
+ (MB_OK or MB_ICONINFORMATION).toUInt())
} \ No newline at end of file