diff options
author | YuutaW <17158086+Trumeet@users.noreply.github.com> | 2019-06-26 11:37:05 +0800 |
---|---|---|
committer | Trumeet <17158086+Trumeet@users.noreply.github.com> | 2019-06-26 11:37:05 +0800 |
commit | e78de74a58c0c28d7a0d999f61cb949060ba620d (patch) | |
tree | 65117171c44489f0348a23c860840f5a88fc96ec | |
parent | cb82c68d0c8d024f8d44147e46833a8f08a92f30 (diff) | |
download | Desktop-1.1.tar Desktop-1.1.tar.gz Desktop-1.1.tar.bz2 Desktop-1.1.zip |
feat: support loading custom programs in the secure desktop1.1
Signed-off-by: Trumeet <17158086+Trumeet@users.noreply.github.com>
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/mingwMain/kotlin/moe.yuuta.desktop/Desktop.kt | 56 |
2 files changed, 49 insertions, 9 deletions
@@ -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 |