MCPcopy Create free account
hub / github.com/hephaest0s/usbkill / kill_computer

Function kill_computer

usbkill/usbkill.py:124–165  ·  view source on GitHub ↗
(settings)

Source from the content-addressed store, hash-verified

122 os.system(shredder + _file )
123
124def kill_computer(settings):
125 # Log what is happening:
126 if not settings['melt_usbkill']: # No need to spend time on logging if logs will be removed
127 log(settings, "Detected a USB change. Dumping the list of connected devices and killing the computer...")
128
129 # Shred as specified in settings
130 shred(settings)
131
132 # Execute kill commands in order.
133 for command in settings['kill_commands']:
134 os.system(command)
135
136 if settings['do_sync']:
137 # Sync the filesystem to save recent changes
138 os.system("sync")
139 else:
140 # If syncing is risky because it might take too long, then sleep for 5ms.
141 # This will still allow for syncing in most cases.
142 sleep(0.05)
143
144 # Wipe ram and/or swap
145 if settings['do_wipe_ram'] and settings['do_wipe_swap']:
146 os.system(settings['wipe_ram_cmd'] + " & " + settings['wipe_swap_cmd'])
147 elif settings['do_wipe_ram']:
148 os.system(settings['wipe_ram_cmd'])
149 elif settings['do_wipe_swap']:
150 os.system(settings['wipe_swap_cmd'])
151
152 if settings['shut_down']: # (Use argument --no-shut-down to prevent a shutdown.)
153 # Finally poweroff computer immediately
154 if CURRENT_PLATFORM.startswith("DARWIN"):
155 # OS X (Darwin) - Will halt ungracefully, without signaling apps
156 os.system("killall Finder ; killall loginwindow ; halt -q")
157 elif CURRENT_PLATFORM.endswith("BSD"):
158 # BSD-based systems - Will shutdown
159 os.system("shutdown -h now")
160 else:
161 # Linux-based systems - Will shutdown
162 os.system("poweroff -f")
163
164 # Exit the process to prevent executing twice (or more) all commands
165 sys.exit(0)
166
167def lsusb_darwin():
168 # Use OS X system_profiler (native and 60% faster than lsusb port)

Callers 1

loopFunction · 0.85

Calls 2

logFunction · 0.85
shredFunction · 0.85

Tested by

no test coverage detected