initial commit
This commit is contained in:
commit
f841702690
148
parser.py
Normal file
148
parser.py
Normal file
@ -0,0 +1,148 @@
|
||||
"""
|
||||
mSecure6 CSV export file
|
||||
^.*?,.*?,.*?,.*?,
|
||||
name|id,type de l'entree,tag,note, dynamic
|
||||
"""
|
||||
from os import curdir
|
||||
import re
|
||||
|
||||
def line_split(line):
|
||||
new_line = []
|
||||
s = ""
|
||||
inString = False
|
||||
while len(line) != 0:
|
||||
current_car = line[0]
|
||||
if current_car == '"' and inString == False:
|
||||
line = line[1:]
|
||||
inString = True
|
||||
continue
|
||||
if current_car == '"' and inString == True:
|
||||
line = line[1:]
|
||||
inString = False
|
||||
continue
|
||||
|
||||
if current_car == "," and inString != True:
|
||||
new_line.append(s)
|
||||
s = ""
|
||||
line = line[1:]
|
||||
continue
|
||||
|
||||
s+=current_car
|
||||
line = line[1:]
|
||||
return new_line
|
||||
|
||||
|
||||
class Entry:
|
||||
def __init__(self,line = None):
|
||||
self.name = ''
|
||||
self.display_type = ''
|
||||
self.tag = ''
|
||||
self.note = ''
|
||||
|
||||
self.licence_user = ''
|
||||
self.email = ''
|
||||
self.url = ''
|
||||
self.text_field = ''
|
||||
self.phone_number = ''
|
||||
self.unknown = ''
|
||||
self.number = ''
|
||||
self.username = ''
|
||||
self.passwrd = ''
|
||||
self.pin = ''
|
||||
self.date = ''
|
||||
self.expiration_date = ''
|
||||
self.carte_bleu = ''
|
||||
|
||||
if line is not None:
|
||||
self.from_line(line)
|
||||
|
||||
|
||||
def from_line(self, line: str):
|
||||
"""
|
||||
Parse a line of text into an Entry object.
|
||||
|
||||
Args:
|
||||
line (str): The line of text to parse.
|
||||
"""
|
||||
|
||||
# Split the line into individual fields
|
||||
print(line)
|
||||
lsplit = line_split(line)
|
||||
print(lsplit)
|
||||
|
||||
# Extract the first field as the name
|
||||
self.name = lsplit[0].split("|")[0].strip()
|
||||
|
||||
# Extract the second and third fields as the display type and tag
|
||||
self.display_type = lsplit[1]
|
||||
self.tag = lsplit[2]
|
||||
|
||||
# Extract the fourth field as the note
|
||||
self.note = lsplit[3] if len(lsplit) > 3 else ''
|
||||
|
||||
# Split the fifth line into individual fields
|
||||
lsplit = lsplit[4:]
|
||||
|
||||
while lsplit:
|
||||
col = lsplit.pop(0)
|
||||
# If there are no more lines, stop parsing
|
||||
if not col or len(col) == 1 : continue
|
||||
# Split the column into a type and value
|
||||
col_parts = col.split("|")
|
||||
# Extract the type and value as an integer
|
||||
type_val = int(col_parts[1])
|
||||
val = col_parts[2] # Remove leading/trailing spaces
|
||||
match type_val:
|
||||
case 0: # Licence User
|
||||
self.licence_user = val
|
||||
case 1: # Email
|
||||
self.email = val
|
||||
case 2: # Phone Number
|
||||
self.url = val
|
||||
case 3: # Unknown Field
|
||||
self.text_field = val
|
||||
|
||||
case 4: # URL
|
||||
self.phone_number = val
|
||||
|
||||
case 5:
|
||||
self.unknown = val
|
||||
|
||||
case 6: # Username
|
||||
self.number = val
|
||||
|
||||
case 7: # Password
|
||||
self.username = val
|
||||
|
||||
case 8: # PIN
|
||||
self.passwrd = val
|
||||
print(self.passwrd)
|
||||
case 9: # Date
|
||||
self.pin = val
|
||||
|
||||
case 10: # Expiration Date
|
||||
self.date = val
|
||||
|
||||
case 11: # Blue Card
|
||||
self.expiration_date = val
|
||||
|
||||
# Set default values for missing fields
|
||||
if self.name == '':
|
||||
self.name = 'Unknown'
|
||||
if self.display_type == '':
|
||||
self.display_type = 'Unknown'
|
||||
if self.tag == '':
|
||||
self.tag = 'Unknown'
|
||||
|
||||
def to_password(self):
|
||||
return f"{self.name},{self.url},{self.username},{self.passwrd},{self.note},,"
|
||||
|
||||
entrs = []
|
||||
with open("ms.csv","r") as file:
|
||||
with open("test.txt","w+") as export:
|
||||
export.write("Title,URL,Username,Password,Notes,OTPAuth\n")
|
||||
for line in file.readlines():
|
||||
entry = Entry(line)
|
||||
print(entry.to_password())
|
||||
export.write(entry.to_password()+"\n")
|
||||
print(50 * "-")
|
||||
Loading…
Reference in New Issue
Block a user