This commit is contained in:
2026-05-31 19:48:56 +01:00
parent 7f32417736
commit 68f8904282
39 changed files with 4519 additions and 5 deletions
+82
View File
@@ -0,0 +1,82 @@
package antiemul
import (
"os"
"runtime"
"strconv"
"strings"
"time"
)
var platformCheck func() bool
func Check() bool {
if checkTiming() {
return true
}
if checkMemory() {
return true
}
if checkUptime() {
return true
}
if checkCoreCount() {
return true
}
if platformCheck != nil && platformCheck() {
return true
}
return false
}
func checkTiming() bool {
start := time.Now()
for i := 0; i < 1000000; i++ {
_ = i * i
}
return time.Since(start) > 500*time.Millisecond
}
func checkMemory() bool {
data, err := os.ReadFile("/proc/meminfo")
if err != nil {
return false
}
content := string(data)
idx := strings.Index(content, "MemTotal:")
if idx == -1 {
return false
}
rest := content[idx+9:]
rest = strings.TrimSpace(rest)
fields := strings.Fields(rest)
if len(fields) == 0 {
return false
}
kb, err := strconv.ParseInt(fields[0], 10, 64)
if err != nil {
return false
}
return kb < 2000000
}
func checkUptime() bool {
data, err := os.ReadFile("/proc/uptime")
if err != nil {
return false
}
content := strings.TrimSpace(string(data))
fields := strings.Fields(content)
if len(fields) == 0 {
return false
}
seconds, err := strconv.ParseFloat(fields[0], 64)
if err != nil {
return false
}
return seconds < 60.0
}
func checkCoreCount() bool {
return runtime.NumCPU() < 2
}
+9
View File
@@ -0,0 +1,9 @@
//go:build darwin
package antiemul
func init() {
platformCheck = func() bool {
return checkTiming()
}
}
+53
View File
@@ -0,0 +1,53 @@
//go:build linux
package antiemul
import (
"os"
"strings"
)
func init() {
platformCheck = func() bool {
if checkCPUInfo() {
return true
}
if checkDMI() {
return true
}
return false
}
}
func checkCPUInfo() bool {
data, err := os.ReadFile("/proc/cpuinfo")
if err != nil {
return false
}
content := strings.ToUpper(string(data))
signatures := []string{"QEMU", "VIRTUAL", "KVM"}
for _, sig := range signatures {
if strings.Contains(content, sig) {
return true
}
}
return false
}
func checkDMI() bool {
data, err := os.ReadFile("/sys/devices/virtual/dmi/id/product_name")
if err != nil {
return false
}
product := strings.ToUpper(strings.TrimSpace(string(data)))
vmStrings := []string{
"QEMU", "VIRTUAL", "KVM", "VMWARE", "VBOX",
"VIRTUALBOX", "XEN", "HYPER-V", "PARALLELS",
}
for _, vm := range vmStrings {
if strings.Contains(product, vm) {
return true
}
}
return false
}
+44
View File
@@ -0,0 +1,44 @@
//go:build windows
package antiemul
import (
"syscall"
"unsafe"
)
type memoryStatusEx struct {
dwLength uint32
dwMemoryLoad uint32
ullTotalPhys uint64
ullAvailPhys uint64
ullTotalPageFile uint64
ullAvailPageFile uint64
ullTotalVirtual uint64
ullAvailVirtual uint64
ullAvailExtendedVirtual uint64
}
func init() {
platformCheck = func() bool {
if checkTiming() {
return true
}
if checkWindowsMemory() {
return true
}
return false
}
}
func checkWindowsMemory() bool {
mod := syscall.NewLazyDLL("kernel32.dll")
proc := mod.NewProc("GlobalMemoryStatusEx")
var memStatus memoryStatusEx
memStatus.dwLength = uint32(unsafe.Sizeof(memStatus))
r1, _, _ := proc.Call(uintptr(unsafe.Pointer(&memStatus)))
if r1 == 0 {
return false
}
return memStatus.ullTotalPhys < 2*1024*1024*1024
}