Copy Link
Add to Bookmark
Report

NULL mag Issue 06 29 Accessing mystic files with python

eZine's profile picture
Published in 
null magazine
 · 3 years ago

  




i begun learning programming in python3, so as an exercise i made the
 following functions to read the oneliners.dat and lastcaller.dat files.
it was a bitch to figure how to convert the pascal string format, cause
python likes to read everything as bytes, but at the end i managed to
 make it. there is also a usefull function to unpack a DOS datetime value.
use the code in your own projects. i hate python, but i have to admit that
is something like a "universal language" in the computer tech. area. :(
for this reason, we should make more things with python in bbsing.


--- rip here ----------------------------------------------------------------

#!/usr/bin/python3
import struct
import os
from datetime import datetime
datadir = "/home/x/mysa43/data/"
# OneLineRec = Record
# Text : String[79];
# From : String[30];
# End;
def oneliners():
f = open(datadir+"oneliner.dat","rb") # open the file
sf = '@b79sb30s'
s = struct.calcsize (sf)
size = struct.calcsize(sf)
print(size) # size of record structure, just to know
i = 0
d = 0
while True:
line = f.read(s) # read n bytes as the record size
if len(line) < s:
break
i,onel,d,name = struct.unpack(sf,line) # assign values to variables

# variable i contains the size of the oneliner text
# variable d contains the size of the user name
# we use the length to convert the vars onel and name to strings
# cause right now are byte arrays

print(''.join(str(name[0:d])).strip("b'")) # print user name
print(''.join(str(onel[0:i])).strip("b'")) # print text

print("---")

line = ""

# RecLastOn = Record // CALLERS.DAT
# DateTime : LongInt;
# NewUser : Boolean;
# PeerIP : String[15];
# PeerHost : String[50];
# Node : Byte;
# CallNum : LongInt;
# Handle : String[30];8-9
# City : String[25];10-11
# Address : String[30];12-13
# Gender : Char;14
# EmailAddr : String[35];15-16
# UserInfo : String[30];
# OptionData : Array[1..10] of String[60];
# Reserved : Array[1..53] of Byte;
# End;

def unpackdt(t):
year = 1980 + (t >> 25)
month = (t & 0b00000001111000000000000000000000) >> 21
day = (t & 0b00000000000111110000000000000000) >> 16
hour = (t & 0b00000000000000001111100000000000) >> 11
minute = (t & 0b00000000000000000000011111100000) >> 5
second = (t & 0b00000000000000000000000000011111) * 2
return datetime(year, month, day, hour, minute, second)

def lastcallers():
f = open(datadir+"callers.dat","rb")
sf = '<L?b15sb50sBIb30sb25sb30scb35sb30s663c'
s = struct.calcsize (sf)
size = struct.calcsize(sf)
print(size)
i = 0
d = 0
while True:
line = f.read(s)
if len(line) < s:
break
res = struct.unpack(sf,line)
print(unpackdt(res[0]))
print(''.join(str(res[3][0:res[2]])).strip("b'"))
print(''.join(str(res[5][0:res[4]])).strip("b'"))
print(res[6])
print(res[7])
print(''.join(str(res[9][0:res[8]])).strip("b'"))
print(''.join(str(res[11][0:res[10]])).strip("b'"))
print(''.join(str(res[13][0:res[12]])).strip("b'"))
print(''.join(str(res[14]).strip("b'"))) # gender
print(''.join(str(res[16][0:res[15]])).strip("b'"))
print(''.join(str(res[18][0:res[17]])).strip("b'"))
print("---")
line = ""

oneliners()
print('-' * 79)
lastcallers()
-- stop ripping here ---------------------------------------------------------
say thanks here: ___________ :p



← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT