Created
January 30, 2022 18:22
-
-
Save dibyasonu/ab5ea01bd31df5201daf71f5f84d7c92 to your computer and use it in GitHub Desktop.
Create .swp file manually which is compatible with nano and vim.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
LOCKSIZE = 1024 | |
lockdata = bytearray(LOCKSIZE) | |
file_name = 'balance.dat' | |
mypid = os.getppid() | |
def strncopy(parent_value, child_value, start): | |
if start >= len(parent_value): | |
parent_value.extend(bytearray(start-len(parent_value)+len(child_value))) | |
for index in range(len(child_value)): | |
parent_value[start+index] = child_value[index] | |
return parent_value | |
lockdata[0] = 0x62 | |
lockdata[1] = 0x30 | |
lockdata = strncopy(lockdata, bytearray("nano 4.8", encoding='utf-8'), 2) | |
lockdata[24] = mypid % 256 | |
lockdata[25] = (mypid//256) % 256 | |
lockdata[26] = (mypid//(256*256)) % 256 | |
lockdata[27] = mypid//(256*256*256) | |
lockdata = strncopy(lockdata, bytearray(os.getlogin(), encoding='utf-8'), 28) | |
lockdata = strncopy(lockdata, bytearray(os.uname()[1], encoding='utf-8'), 68) | |
lockdata = strncopy(lockdata, bytearray(file_name, encoding='utf-8'), 108) | |
lockdata[1007] = 0x55 | |
lockdata = bytes(lockdata) | |
# print(len(lockdata)) | |
with open(f".{file_name}.swp", "wb") as f: | |
f.write(lockdata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment