-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmue_idle.py
executable file
·103 lines (85 loc) · 3.11 KB
/
mue_idle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# Idle bypass script by (pussious) cfati
import argparse
import random
import sys
try:
from pycfutils.io import read_key
from pycfutils.miscellaneous import timestamp_string
except ImportError:
# @TODO - cfati: Dev repository
from pycfutils.pycfutils.io import read_key
from pycfutils.pycfutils.miscellaneous import timestamp_string
import gen_evt as ge
__version_info__ = (0, 0, 0)
__version__ = ".".join(str(e) for e in __version_info__)
def parse_args(*argv):
parser = argparse.ArgumentParser(description="Suppress screen saver / turn off")
parser.add_argument(
"--base_interval",
"-i",
default=180,
type=int,
help="interval (seconds) between 2 consecutive events generation",
)
parser.add_argument(
"--key_interval",
"-k",
default=0.5,
type=float,
help="time (max seconds) needed by the script to become responsive to user input",
)
parser.add_argument(
"--max_deviation_percent",
"-p",
default=10,
type=int,
help="maximum base interval deviation percent."
" A constant interval might be an indicator for monitoring tools that something fishy is going on."
" Adding some randomization, so each interval is different."
" Make sure that if an event is required to happen in a certain amount of time,"
" base interval + maximum deviation fit into that",
)
parser.add_argument("--verbose", "-v", action="store_true", help="verbose mode")
args, unk = parser.parse_known_args()
if unk:
print("Warning: Ignoring unknown arguments: {:}".format(unk))
if args.max_deviation_percent < 0:
parser.exit(status=-1, message="Percent must be non negative\n")
if args.base_interval <= 0 or args.key_interval <= 0:
parser.exit(status=-1, message="Intervals must be positive\n")
return args, unk
def generate_interval(base, deviation_percent):
max_dev = base * deviation_percent / 100
dev = max_dev * 2 * random.random()
return max(round(base - max_dev + dev), 1)
def main(*argv):
args, _ = parse_args()
verbose_text_pat = (
"\n{:s}\nAttempting to (fakely) move the mouse in {:d} seconds.\n"
" At any point, press any key to interrupt..."
)
while True:
interval = generate_interval(args.base_interval, args.max_deviation_percent)
if args.verbose:
print(
verbose_text_pat.format(
timestamp_string(human_readable=False)[2:], interval
)
)
res = ge.simulate(verbose=args.verbose)
if read_key(timeout=interval, poll_interval=args.key_interval):
if args.verbose:
print("\nKey pressed. Exiting.")
break
if __name__ == "__main__":
print(
"Python {:s} {:03d}bit on {:s}\n".format(
" ".join(item.strip() for item in sys.version.split("\n")),
64 if sys.maxsize > 0x100000000 else 32,
sys.platform,
)
)
rc = main(*sys.argv[1:])
print("\nDone.\n")
sys.exit(rc)