From 14bf6bdae1682001cd0ecfeba04a8f5abb6a0635 Mon Sep 17 00:00:00 2001 From: ultramagnus_tcv Date: Mon, 7 Sep 2015 12:24:01 -0500 Subject: [PATCH] Removed prompts. Place rudimentary if/else for first eight bytes of driver. Attempted function, but it's not working. --- 3Slurp.py | 31 +++++++++++-------------------- Readme.md | 26 ++++++++++++++++++++------ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/3Slurp.py b/3Slurp.py index 9a15265..15e6691 100644 --- a/3Slurp.py +++ b/3Slurp.py @@ -1,33 +1,24 @@ from struct import unpack import os +def tup2int(offset): + offset = unpack ('< H', SOS) + return offset + #Clear SCREEN print("\033c"); -# Ask for the DSK filename then open it -dskname = raw_input("Welcome to the Apple /// SOS.Driver.Slurper.\nAppleCommander _must_ exist in the same directory as this script.\n\nYou must have JAVA on your system. \n\nEnter CaSe-SeNsItIvE DSK filename: ") -if len(dskname) < 1 : - print '\nSorry, you must enter a disk name.' - exit() -else: - try: - dskopen = open(dskname) #Checks to see if DSK exists. - sosdrivername = raw_input('\nEnter the name of the SOS driver file you wish exported [SOS.DRIVER]: ') - if len(sosdrivername) < 1 : - sosdrivername = 'SOS.DRIVER' - print "DEBUG: Taking the default IF. sosdrivername is: " + sosdrivername - os.popen("java -jar AppleCommander-1.3.5.13-ac.jar -g %s %s >%s.SOS.DRIVER" % (dskname, sosdrivername,dskname)) - else: - print 'DEBUG: Taking the else...' - os.popen("java -jar AppleCommander-1.3.5.13-ac.jar -g %s %s >%s.SOS.DRIVER" % (dskname, sosdrivername,dskname)) - except: - print '\n\nI cannot find that disk file. Check path and/or name.\n\n' - exit() #Is File a SOS DRIVER file? + SOSfile = open('SOSCFFA.DRIVER', 'rb') SOS = SOSfile.read(10) filetype, offset = unpack('< 8s H', SOS) -print "Filetype is: %s. Offset is: %04x" % (filetype, offset) + +if 'SOS DRVR' in filetype: + print "This is a proper SOS file." + print "Filetype is: %s. First offset is: %04x" % (filetype, offset) +else: + print "This is not a proper SOS file" #Seek to first driver SOSfile.seek(offset,1) diff --git a/Readme.md b/Readme.md index 8871740..af55b3e 100644 --- a/Readme.md +++ b/Readme.md @@ -1,9 +1,9 @@ # Python-III-Git -A Python Script to open Apple III DSK files, export SOS.DRIVER, and catalog what drivers are installed. +A Python Script to open Apple III DSK files, export SOS.DRIVER, and catalog what drivers are installed. Work History -8/1/2015 -- Approx. +8/1/2015 -- Approx. Initial Commit 8/26/2015 @@ -12,7 +12,7 @@ Goals Defined: 1. Obtain the name of the .dsk image from the command-line (like: python my_script.py my_disk_image.dsk) 2. For each driver: - a. File offset + a. File offset b. List the name of the driver c. Whether it's char or block device d. Manufacturer id @@ -20,7 +20,7 @@ Goals Defined: 3. Print it all on one line in a file, delimited with commas -Example: +Example: $ python sos.extract.py -disk "my_disk_image.dsk" -driver [SOS.DRIVER] -output [diskname.csv] @@ -43,8 +43,22 @@ Problems to solve (in no particular order): 1. How to write to a file. -2. How to seek to an offset. Can that be done in HEX? +2. How to seek to an offset. Can that be done in HEX? 3. How best to approach? Should we run through the file multiple times, marking names and offsets then returning to grab data? Or is one-time best? -4. Can anything be turned into functions? \ No newline at end of file +4. Can anything be turned into functions? + +9/7/2015 + +Completely removed the prompts as they were a pain during troubleshooting. + +Attempted to create a function that will: +1. Take the 2-byte offset found in the file and unpack it then, +2. Convert the resultant tuple into an integer. + +I am having trouble with the return portion. I don't really know how to do it. Will continue to play. + +Implemented a (very) rudimentary IF/ELSE that checks the first eight bytes of the driver file to see if "SOS DRVR" exist. If not, the script ends. If so, we will continue. This entailed unpacking the data as string-data, converting the resultant tuple into an str, then checking what's there. I did verify via HEX edit that if the string is not "SOS DRVR," the else will be taken. + +Is there a way to run the IF/ELSE against the contents of the tuple? It would save my having to convert from tuple to str.