more pythonic ;)

This commit is contained in:
erpalma
2018-08-13 14:37:42 -07:00
parent 063bc0c5aa
commit 1d521818e5

View File

@@ -78,8 +78,8 @@ def readmsr(msr, from_bit=0, to_bit=63):
os.lseek(f, msr, os.SEEK_SET) os.lseek(f, msr, os.SEEK_SET)
val = struct.unpack('Q', os.read(f, 8))[0] val = struct.unpack('Q', os.read(f, 8))[0]
os.close(f) os.close(f)
extractor = int(''.join(["0"]*(63-to_bit) + ["1"]*(to_bit+1-from_bit) + ["0"]*from_bit), 2) mask = sum(2**x for x in range(from_bit, to_bit + 1))
return (val & extractor) >> from_bit return (val & mask) >> from_bit
except (IOError, OSError) as e: except (IOError, OSError) as e:
if e.errno == EPERM or e.errno == EACCES: if e.errno == EPERM or e.errno == EACCES:
print('[E] Unable to read from MSR. Try to disable Secure Boot.') print('[E] Unable to read from MSR. Try to disable Secure Boot.')