Results 1 to 25 of 25

Thread: File specification

  1. #1

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935

    File specification

    Normally, I'd post this in General VB, but threads that I start there don't go that far and don't help much. But you hackers tend to know how to break things.

    I am working on a file specification for PassProg 2. Ignoring encryption for now (I'll work on that after I know what to encrypt ), I need a way to store data in the following format:

    Code:
    File
    |
    +-- Entries
         |
         +-- Username
         +-- Password
         +-- Comments
         +-- etc.
    So there are multiple entries in a file, and each entry contains a username, password, date, etc. What I did in PassProg 1 was use an INI file, but that was crude, IMHO. Any ideas for a proprietary PP2 format?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Make a linked list

    What you do is, have a header Type containing info about the file, for example:
    VB Code:
    1. Type PP2Header
    2.     sOwnerName As String*64 ' Or whatever
    3.     lOtherRandomThing As Long
    4.     lFirstEntry As Long ' Location in the file of the first entry
    5. End Type
    You have one of those first in the file (perhaps some signature bytes as well?) and then follow it up with the entry types. This is where it gets clever...
    VB Code:
    1. Type PP2Entry
    2.     sName As String*64 ' Entry name
    3.     lType As Long ' Entry type (possibly use an Enum for this?
    4.     lLocation As Long ' Location in the file of the data for this entry
    5.     lLength As Long ' Length of the associated data
    6. End Type
    Then you can have different Types for different things you need to store.

    It's a bit abstract, but you might get the gist of it
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    Do you have an example of what it would look like? BTW, I forgot, a master password for the file would be stored there too (not as part of an entry, but by itself).

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Example of what looking like what?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    What a sample file would look like.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    OK you'd have to give me a moment alone with a hex editor though It wouldn't really look like much, but I'll see what I can do (I think in terms of 8-byte aligned and packed structs rather than Types).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    BTW, ALL of the fields must be able to support 65,535 characters (the capacity of a textbox). I was thinking of something newline-delimited.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Oh. I was thinking of something groovy and complicated but pretty simple to read into the program. Do you mind if the fields are padded at all? This is so much easier in C where strings have a nice fat NULL on the end

    Newline-delimited text files are ok, but a ***** to process.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    What do mean, "padded?" Surrounded by null chars or spaces, or am I not thinking along the correct lines?

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    OK, for example you needed to hold 65536 chars per type field. Is it ok just to have that allocated in the type, or to store them separately using a length? Be a bit of a bastard to write but your choice...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    Sorry, I still don't understand. Do you mean declare them in VB as String * 65535?

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yep.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Oooh....65535 is the maximum length for a fixed length string. HAHAHA

    Sorry
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Oh. If you do that you'll have 65K wasted for every entry
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    And one big file, considering that PassProg 2 will support up to however many items a listview or Long can store, whichever is smaller.

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    OK prepare yourself for a way cool method.

    1. Header
    2. Index of data items and their sizes
    3. Entries begin here, and they refer to data items by ID
    4. Data items follow in a big mess

    Just coding it up now (this looks cool )
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    way optimal method goes here

    Code:
    Type PP2File
        sOwnerName As String
        lOtherRandomThing As Long
        PP2Entries() as PP2Entry
    End Type
    
    Type PP2Entry
        sName As String
        lType As Long
        lLocation As Long
        Data as String
    End Type
    ...
    dim x as PP2File
    ...
    Put#f,,x'in a file opened in binary
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  18. #18
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Strings are dynamic length though

    Won't that totally bugger it up?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Nope, typenested strings and arrays will include a 2 or 6 byte descriptor making things so much easier
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  20. #20
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    It all depends on whether you want sequential or random access. Fixed length records are pretty much a necessity for random access but not for sequential access.
    Harry.

    "From one thing, know ten thousand things."

  21. #21
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Instead of making a proprietary format, why don't you just use XML and let the encryption obfuscate the data?
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  22. #22
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    But then you've got a huge waste of space using XML.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  23. #23
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    VB Code:
    1. Private Sub btnRead_Click()
    2.     Dim x As PP2File
    3.     Open "temp.pp2" For Binary As #1
    4.         Get #1, , x
    5.     Close #1
    6.     Dim i As Long
    7.     Dim nd As Node
    8.     Set nd = tvDisplay.Nodes.Add(, , , x.sOwnerName)
    9.     For i = LBound(x.PP2Entries) To UBound(x.PP2Entries)
    10.         Dim ndb As Node
    11.         Set ndb = tvDisplay.Nodes.Add(nd, tvwChild, , x.PP2Entries(i).sName)
    12.         tvDisplay.Nodes.Add ndb, tvwChild, , x.PP2Entries(i).Data
    13.     Next i
    14. End Sub
    15. Private Sub btnWrite_Click()
    16.     Dim x As PP2File
    17.     x.sOwnerName = "Mike Parks"
    18.     ReDim x.PP2Entries(0 To 1)
    19.     x.PP2Entries(0).sName = "Hi there"
    20.     x.PP2Entries(0).Data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    21.     x.PP2Entries(1).sName = "Different"
    22.     x.PP2Entries(1).Data = "BLAH BLAH BLAH"
    23.     Open "temp.pp2" For Binary As #1
    24.         Put #1, , x
    25.     Close #1
    26. End Sub
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  24. #24
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I thought you were lazy parksie ?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  25. #25
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That's why I did it in VB
    Attached Files Attached Files
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width