Announcement

Collapse
No announcement yet.

Commodore and old system LHA archive format...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Commodore and old system LHA archive format...

    Hello,

    Are any of you guys familiar with the LHA file format? I believe it was used on the Commodore and maybe Amiga systems back in the day.

    I have a custom DOS archive that is just an LHA archive that's been modified a bit. I can decrypt it but the program I'm using, ar (from way back in the day) doesn't recreate the header properly. In the ar.c file, it shows bits 15 - 18 (starting at 0) are UNUSED but in this custom archive, they are used.

    I was digging around on the net, and I found for the Commodore LHA archive, those bits are used for the date. I believe in this custom archive, they're used for the date as well. When I extract them using the custom program that the original author wrote, I see the first file is created with a time stamp of:
    12-31-97 4:00pm.

    When I use the really old ar program, they're created with today's date. When I create an archive using the really old ar program, those bits are all 0's. However, in the custom archive, those bits are:
    94 6B BA 31

    According to the document I found online for the Commodore LHA archive program, the date format can be broken down like this:
    Code:
    Bytes: $0000-0001: Time of last modification:
                BITS  0 - 4: Seconds divided by 2
                       (0-58, only even numbers)
                BITS 5 - 10: Minutes (0-59)
                BITS 11 - 15: Hours (0-23, no AM or PM)
    
    Bytes: $0002-0003: Date of last modification:
                BITS 0- 4: Day (1-31)
                BITS 5- 9: Month (1-12)
                BITS 10-15: Year minus 1980
    I tried concentrating on calculating the year from the data I have and have been unsuccessful. Any smart math people out there that might want to give me a hand trying to figure this out? Thanks!
    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

    #2
    Re: Commodore and old system LHA archive format...

    why not just get the source?
    remove the ".zip" off the end!
    Attached Files

    Comment


      #3
      Re: Commodore and old system LHA archive format...

      I used LHA255.EXE many years ago.

      http://verdonk.home.xs4all.nl/PG30/LHA/

      Can you upload the file(s) you are talking about, or link to them?

      Comment


        #4
        Re: Commodore and old system LHA archive format...

        Thanks Fzabkar. I will update the .DAT file. I can upload the source code to a program that decrypt them, although it ignores the date stuff.

        I think I made a mistake with the original date. I think the original date is:
        06-08-96 11:13pm

        I changed the 31 to a 30 and adjusted the checksum with a hex editor so the original program wouldn't error out. After I ran the original program that extracts from the custom archive, I noticed the date had changed from:
        06-08-96 11:13pm to 11-27-95 5:53pm

        To me, it's a bit strange, just decrementing that one digit not only affects the year, but the month, the day and the time as well. I started thinking maybe it was minutes since 1980 or something but that'd have to be a bit larger than 4 bytes, wouldn't it?

        If I change the first byte, the 94h to a 95h, the date and time don't change at all.

        The second byte in the file is the checksum. If you change a byte by +1, the checksum needs to be adjusted by +1. If you change a byte by -1, the checksum needs to be adjusted by -1.

        Offsets 0F - 12h are the ones that have something to do with the date. The ar source code I could find from way back in the day seems to ignore those bytes, otherwise it creates a completely duplicate file. I had to modify it a bit. A normal LHA archive from back then had -lh0- and -lh5-'s in it. This custom dat file uses -mg0- and -mg5- (l + 1 = m, h - 1 = g).
        Attached Files
        -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

        Comment


          #5
          Re: Commodore and old system LHA archive format...

          Originally posted by stj View Post
          why not just get the source?
          remove the ".zip" off the end!
          Thank you for the suggestion Stj but the source code you linked me too has changed way to much since the original. I did spend a good two weeks modifying the program you linked to to get it to decrypt this custom archive, but recreating them was a no go. The header format had changed too much.

          If I can figure out this time format stuff, I want to use the program you linked me to and modify it a good bit to get it to work. The code is a lot nicer than the original version from back in the 80's / 90's.
          -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

          Comment


            #6
            Re: Commodore and old system LHA archive format...

            Originally posted by fzabkar View Post
            I used LHA255.EXE many years ago.

            http://verdonk.home.xs4all.nl/PG30/LHA/

            Can you upload the file(s) you are talking about, or link to them?
            The header format goes like this (from offset 0)
            Code:
             1 basic header size
                = 25 + strlen(filename) (= 0 if end of archive)
             1 basic header algebraic sum (mod 256)
            -----basic header
             5 method ("-mg0-" = stored, "-mg5-" = compressed)
             4 compressed size (including extended headers)
             4 original size
             4 UNKNOWN!!! (date / time)
             1 0x20
             1 0x01
             1 filename length (x)
             x filename
             2 original file's CRC
             1 0x20
             2 first extended header size (0 if none)
            -----first extended header, etc.
            -----compressed file
            It's the UNKNOWN!!! part that I'm interested in figuring out.
            -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

            Comment


              #7
              Re: Commodore and old system LHA archive format...

              maybe it's unix-style.
              days from 0, as opposed to a specific date.

              Comment


                #8
                Re: Commodore and old system LHA archive format...

                Aren't Unix styles seconds from 1960?
                -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                Comment


                  #9
                  Re: Commodore and old system LHA archive format...

                  The original custom LHA archive (a dat file) is used by an old DOS program. The owner of the DOS program never released the source code but did make the program freeware. You'd run a program that extracted files from the DAT file. That program you ran to extract the files, I believe he just took ar and modified it. The reason I say that is it has the same typo's and bugs that ar has.

                  The only code I could find that was really close was located here:
                  https://oku.edu.mie-u.ac.jp/~okumura/compression/ar002/

                  All I had to do was change a few characters (like -lh0-, -lh5- to -mg0-, -mg5-) and creates almost identical files. It just ignores the time stamp. I'd like to figure that part out.
                  -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                  Comment


                    #10
                    Re: Commodore and old system LHA archive format...

                    Maybe not all of it's time. I was looking at some other LHA code and I see there's a place after file size (before time) for options / flags....

                    It shows:
                    Code:
                    	lha->compsize = 0;
                    	lha->origsize = 0;
                    	lha->setflag = 0;
                    	lha->birthtime = 0;
                    	lha->birthtime_tv_nsec = 0;
                    	lha->mtime = 0;
                    	lha->mtime_tv_nsec = 0;
                    	lha->atime = 0;
                    	lha->atime_tv_nsec = 0;
                    	lha->mode = (lha->directory)? 0777 : 0666;
                    	lha->uid = 0;
                    	lha->gid = 0;
                    This custom dat file I have, it won't have uid or gid or mode...but maybe the time thing is something similar ? I know with the program you linked me to Stj, when I use the modified version so it recognizes the custom dat file, it shows they're from 1979, which isn't write.
                    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                    Comment


                      #11
                      Re: Commodore and old system LHA archive format...

                      maybe some older amiga version would help?
                      dig through this
                      http://aminet.net/util/arc

                      Comment


                        #12
                        Re: Commodore and old system LHA archive format...

                        Originally posted by Spork Schivago View Post
                        Aren't Unix styles seconds from 1960?
                        1970. 1/1/70 is the start of unix time.
                        sigpic

                        (Insert witty quote here)

                        Comment


                          #13
                          Re: Commodore and old system LHA archive format...

                          I was working with some LZH files while waiting for your updates. AISI, LHA255.EXE appears to produce archives in the same format as your own.

                          Here is an example:

                          Code:
                          Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
                          
                          00000000 23 29 2D 6C 68 35 2D A8 33 00 00 4E AD 00 00 6D #)-lh5-¨3..N*..m
                          00000010 67 55 48 20 01 0A 4C 48 41 32 35 35 2E 54 58 54 gUH ..LHA255.TXT
                          00000020 79 EF 4D 00 00 1C E0 83 BA EE B1 B6 E5 7F EE 37
                          ........
                          000033C0 97 75 3B 38 A7 FF 9F D5 50 53 FF 56 A0 00
                          Here is my analysis (using your info):

                          Code:
                          Byte(s)  Value      Description
                          --------------------------------------------------------------------------------
                          0x00   0x23      Size of header, including file name (35 bytes)
                          0x01   0x29      8-bit checksum of header bytes 0x02 - 0x22
                          0x02-06  "-lh5-"     compression/packing method (confirmed by 7-Zip)
                          0x07-0A  0x000033A8   compressed/packed size (13224, confirmed by 7-Zip)
                          0x0B-0E  0x0000AD4E   original file size (44366, confirmed by 7-Zip)
                          0x0F-12  0x4855676D   date/time stamp (2016-02-21, 12:59, reported by 7-Zip)
                          0x13   0x20
                          0x14   0x01
                          0x15   0x0A      number of characters in filespec (= 10)
                          0x16-1F  "LHA255.TXT"  filespec
                          0x20-21  0xEF79     CRC of original file (confirmed by 7-Zip)
                          0x22   0x4D      differs from yours ???
                          0x25           beginning of file
                          0x33CC          end of file (0x33CC - 0x25 + 1 = 0x33A8)
                          0x33CD  0x00      marker for last file in archive
                          ISTM that you could use LHA255.EXE and 7-Zip to experiment with date/time stamps. I'm working on it now ...

                          Comment


                            #14
                            Re: Commodore and old system LHA archive format...

                            i got it, it's a multi-level standard.
                            the meaning of the bytes depends on the evolution level.

                            look at header.doc
                            (and remember to strip ".zip" off again)
                            Attached Files

                            Comment


                              #15
                              Re: Commodore and old system LHA archive format...

                              I created some test files while fiddling with the system date.

                              Code:
                              TEST1  TXT      18 02-21-16 4:50p test1.txt
                              TEST2  TXT      18 02-21-15 4:50p test2.txt
                              
                              C:\Downloads\Software\LHArc>type test1.txt
                              02-21-2016 4:49
                              
                              C:\Downloads\Software\LHArc>type test2.txt
                              02-21-2015 4:49
                              
                              C:\Downloads\Software\LHArc>debug test.lzh
                              -d
                              1262:0100 22 25 2D 6C 68 30 2D 12-00 00 00 12 00 00 00 43  "%-lh0-........C
                              1262:0110 86 55 48 20 01 09 54 45-53 54 31 2E 54 58 54 AB  .UH ..TEST1.TXT.
                              1262:0120 7C 4D 00 00 30 32 2D 32-31 2D 32 30 31 36 20 34  |M..02-21-2016 4
                              1262:0130 3A 34 39 20 0D 0A 22 5D-2D 6C 68 30 2D 12 00 00  :49 .."]-lh0-...
                              1262:0140 00 12 00 00 00 58 86 55-46 20 01 09 54 45 53 54  .....X.UF ..TEST
                              1262:0150 32 2E 54 58 54 BF 8C 4D-00 00 30 32 2D 32 31 2D  2.TXT..M..02-21-
                              1262:0160 32 30 31 35 20 34 3A 34-39 20 0D 0A 00      2015 4:49 ...
                              
                              02-21-2016 4:49 -> 0x48558643 = 0b 0100100 0010101011000011001000011
                              02-21-2015 4:49 -> 0x46558658 = 0b 0100011 0010101011000011001011000
                              
                              
                              C:\Downloads\Software\LHArc>type test1.txt
                              02-21-2016 5:05
                              
                              C:\Downloads\Software\LHArc>type test2.txt
                              03-21-2016 5:05
                              
                              C:\Downloads\Software\LHArc>debug test.lzh
                              -d
                              1262:0100 22 50 2D 6C 68 30 2D 13-00 00 00 13 00 00 00 CA  "P-lh0-.........
                              1262:0110 88 55 48 20 01 09 54 45-53 54 31 2E 54 58 54 FF  .UH ..TEST1.TXT.
                              1262:0120 C8 4D 00 00 30 32 2D 32-31 2D 32 30 31 36 20 35  .M..02-21-2016 5
                              1262:0130 3A 30 35 20 20 0D 0A 22-9B 2D 6C 68 30 2D 13 00  :05 ..".-lh0-..
                              1262:0140 00 00 13 00 00 00 D9 88-75 48 20 01 09 54 45 53  ........uH ..TES
                              1262:0150 54 32 2E 54 58 54 AE 34-4D 00 00 30 33 2D 32 31  T2.TXT.4M..03-21
                              1262:0160 2D 32 30 31 36 20 35 3A-30 35 20 20 0D 0A 00   -2016 5:05 ...
                              
                              TEST1  TXT      19 02-21-16 5:06p test1.txt
                              TEST2  TXT      19 03-21-16 5:06p test2.txt
                              I can see how the year/month/day are encoded, at least for the DOS program, but I'm still working on the time stamp.

                              Code:
                              02-21-2016 5:06 -> 0x485588CA = 0b 0100100 0010 10101 1000100011001010
                              03-21-2016 5:06 -> 0x487588D9 = 0b 0100100 0011 10101 1000100011011001
                                                year  mth  day    time    
                                                - 1980
                              Last edited by fzabkar; 02-21-2016, 12:58 AM.

                              Comment


                                #16
                                Re: Commodore and old system LHA archive format...

                                It looks like DOS time follows the format in post #1.

                                10001 000110 11001 -> 17:06
                                hours mins seconds/2

                                However, when I decode the Jetbbs archive in the same way, I get a nonsensical date.

                                Code:
                                31BA 6B94
                                
                                0011000 1101 11010 01101 010100 10100
                                
                                2004-[b]13[/b]-25 13:20:40
                                Last edited by fzabkar; 02-21-2016, 01:26 AM.

                                Comment


                                  #17
                                  Re: Commodore and old system LHA archive format...

                                  31BA6B94 --> 06-08-96 11:13pm

                                  30BA 6B94 --> 11-27-95 5:53pm

                                  Number of days from 11-27-95 to 06-08-96 is about 194.

                                  0x31BA6B94 - 0x30BA6B94 = 0x1000000

                                  (194 days) / 0x1000000 = 0.999069214 seconds

                                  Therefore each increment in the date/time dword corresponds to 1 second.

                                  So ...

                                  0x31BA6B94 seconds = 26.4379623 years -> 26th year
                                  0.4379623 years = 5.2555476 months -> 6th month
                                  0.2555476 months = 7.77806394 days -> 8th day

                                  Therefore the date/time appears to be a dword that counts the number of seconds since 1970.
                                  Last edited by fzabkar; 02-21-2016, 01:54 AM.

                                  Comment


                                    #18
                                    Re: Commodore and old system LHA archive format...

                                    Originally posted by fzabkar View Post
                                    However, when I decode the Jetbbs archive in the same way, I get a nonsensical date.

                                    Code:
                                    31BA 6B94
                                    
                                    0011000 1101 11010 01101 010100 10100
                                    
                                    2004-[b]13[/b]-25 13:20:40
                                    That should have been 2004-13-26.

                                    Comment


                                      #19
                                      Re: Commodore and old system LHA archive format...

                                      If I use a hex editor (eg HxD, freeware) to replace all occurrences of "-mg" with "-lh", and rename the file to "JetBBS.lzh", then 7-Zip is able to extract the contents.

                                      However, the date/time reported by 7-Zip for the "jetbbs.exe" file is 2005-01-26 13:28.

                                      When we compare 2005-01-26 with 2004-13-26 we see that 7-Zip has converted 13 months to 1 year and 1 month. Clearly 7-Zip is interpreting the date incorrectly.

                                      The "Host OS" reported by 7-Zip is "Unknown". Byte #22 (OS ID) has a value of 0x20. This corresponds to an ASCII space. In the case of my DOS example the Host OS byte is "M", which corresponds to MS-DOS.
                                      Last edited by fzabkar; 02-21-2016, 11:38 AM.

                                      Comment


                                        #20
                                        Re: Commodore and old system LHA archive format...

                                        Here is an experiment you could try. Place the following lines in a BAT file and then execute the batch. The result should be a text file with a date/time stamp corresponding to 01-01-1970 0:00.

                                        Code:
                                        echo 01-01-1970 | date
                                        echo 0:00 | time
                                        echo 01-01-1970 0:00 > test.txt
                                        type test.txt
                                        Use your utility to compress/pack this file. The date/time dword in the LHA archive should be close to 0x00000000.

                                        Of course you will need to restore your machine's current date and time.

                                        Edit: I just tried it. Apparently DOS doesn't like 1970. It's too early. :-(

                                        What happens if you take your custom archive, replace the date/time bytes with zeros and recalculate the 8-bit checksum? How does your custom software report this date/time stamp?

                                        Code:
                                        Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
                                        
                                        00000000 23 39 2D 6C 68 35 2D 7D 9F 02 00 E8 11 05 00 00 #9-lh5-}Ÿ..è....
                                        00000010 00 00 00 20 01 0A 6A 65 74 62 62 73 2E 65 78 65 ... ..jetbbs.exe
                                        00000020 93 F2 20 00 00
                                        Last edited by fzabkar; 02-21-2016, 04:01 PM.

                                        Comment

                                        Working...
                                        X