Announcement

Collapse
No announcement yet.

Fixed length strings

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

  • Scott Turchin
    replied
    Ah, Yes, I am modifying compiled code...
    But I think I have a way to safely do it now, took a while...

    Thanks tho!

    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    I switched everything to Asciiz, hmmm the EXE contains the EXACT same data, so far as I can see there is no difference in THIS case of using it over fixed l ength strings.
    Think "runtime". The string literal "abc" is assigned to the string at runtime, so it only matters at runtime whether the target variable is dynamic, fixed-length, or ASCIIZ.

    Now, obviously there are 3 "1"'s in there.
    <snip>
    The EXE contains ONE.
    This is commonly known as Optimization...
    PowerBASIC has used this technique since PB/DOS to keep the EXE size as small as possible.

    Somewhere in there is a pointer saying, go grab this string with teh "1" in it and re-use it...
    So where do I find that pointer at?
    Now you are starting to toy with modifying the compiled code, rather than the embedded string literals... you are on your own now I'm afraid, sorry!


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    I think I see why I am confused now.

    I switched everything to Asciiz, hmmm the EXE contains the EXACT same data, so far as I can see there is no difference in THIS case of using it over fixed l ength strings.

    But what I did find, and I do like this, and we DID talk about this in the past...

    THis is what's going into the EXE as a test:
    fh.headerstart = "PYTHON32CCS"
    fh.OverwriteFlag = "1"
    fh.LicenseFlag = "1"
    fh.PasswordFlag = "1"
    fh.DoNotOpenFlag = "0"
    fh.PassWord = "PASSWORD"
    fh.UncompressPath = "C:\WINDOWS\TEMP"
    fh.InstallDate = "JAN 20, 2001 12:00 PM"
    fh.DateofExpire = "JAN 29, 2001 12:00 PM"
    fh.TimesUsed = "16"
    fh.TimesAllowed = "17"
    fh.DoNotOpenFlag = "0"


    Now, obviously there are 3 "1"'s in there.
    The EXE contains ONE.

    Somewhere in there is a pointer saying, go grab this string with teh "1" in it and re-use it...

    So where do I find that pointer at?


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    On another note...

    If a 2nd EXE is going to WRITE the strings into the EXE then I better learn how to make the correct string headers so that the EXE can read itself....


    So does an asciiz write to an EXE the same as a fixed length string?

    ie string size, null, actual string?


    COnfused now.....


    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    Makes sense!
    In fixed length strings PB Is writing the length of the string (actual not alloted) in the EXE just before the string.

    It goes like this:

    Marker Null String

    Marker Null String


    8 0 PASSWORD


    Now that works and works fine, so long as It holds still for me hahahaha I have to keep searching for it.

    But, what will Asciiz do, same thing?
    Then it requires going back and changing the functions....

    What's the advantage of using Asciiz vs fixed length? They seem to be doing the same thing..


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    Scott, you seem to be under the impression that declaring an ASCIIZ or Fixed-length string to a particular size reserves that size in the disk image of the EXE. It does not, but rather it just tells the compiler how much space to reserve for the string at runtime.

    If you include a string literal in your code and assign it to such a string, then that literal is copied to the string at runtime. Therefore, if the fixed-length string is, say, 1024 bytes, but your literal is 10 bytes, only the 10 bytes (plus a small header) will appear in the disk image of the EXE/DLL.
    ie,
    Code:
    DIM a AS STRING * 1023
    a = "1234567890"
    To recap: in the case above, only 10 bytes (plus a small header) are stored in the disk image of the EXE.

    The string buffer is allocated in the Data segment at runtime, and then the 10 byte string literal is copied from the code segment into that buffer.

    If the compiler did not work like that, the code segment (and the EXE/DLL size) would be _enormous_ just by declaring a single fixed-length string of, say, 100-Mb!

    Clear as mud?

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    It's getting written into an EXe, how will that affect things?

    I'm looking for specific lengths when I pull this header out, it MUST be 1k (Or whatever size)

    Won't an Asciiz leave a lot of parsing to be done if I pull this header out as one chunk or can i just read it?

    Perhaps I'm looking at this wrong, cna I do a Get$,1024,fh (where fh is a stucture)..?

    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Egbert Zijlema
    replied
    Lance is right, folks!
    Unfort. I did'nt know the use of ASCIIZ strings was allowed in a structure.


    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Leave a comment:


  • Edwin Knoppert
    replied
    Or add the required 0's

    "Password" & String$( Len( Struct.Myelement ), 0 )



    ------------------
    [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    Use ASCIIZ instead of Fixed length strings... the remaining NUL bytes are ignored for the purpose of string comparison, thus:
    Code:
    DIM A AS ASCIIZ * 17 ' 16 plus one nul byte
    DIM B AS STRING * 16 ' 16 bytes
    A = "password"
    B = A
    IF A=B THEN PRINT "The world is falling apart!"
    IF A = TRIM$(B) THEN PRINT "A match!"
    IF LEN(A) = LEN(B) THEN PRINT "The world is falling apart"
    IF SIZEOF(A) = LEN(B) THEN PRINT "Same size!"
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Is there a reason you don't want to use AsciiZ strings?

    ------------------
    Ron

    Leave a comment:


  • Egbert Zijlema
    replied
    Not necessaryly difficult. Use TRIM$.
    Code:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    
    TYPE MYSTRUCT
      password AS STRING * 16
    END TYPE
    
    FUNCTION PBMain() AS LONG
      DIM pw AS MYSTRUCT
      
      pw.password = "SecretWord"
      MSGBOX pw.password + $CRLF + "Length: " + FORMAT$(LEN(TRIM$(pw.password)))
    END FUNCTION
    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Leave a comment:


  • Scott Turchin
    replied
    OK If I want to use that structure and allocate only 16 bytes for the password, how do I distinguish the remaining nulls then?
    I could parse it, egads that's not the right way...

    Hmmmm
    I'm thinking the structure is the best idea, for uniform lengths of strings but this is a new problem..

    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Egbert Zijlema
    replied
    Scott,

    Only when your code contains a structure wherein the fixed string variable 'password', the period is allowed in variable names. Example:
    Code:
    TYPE MYSTRUCT
      password AS STRING * 8
      ' more vars, if necessary, here
    END TYPE
    DIM fh AS MYSTRUCT
    fh.password = "secret"
    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    [This message has been edited by Egbert Zijlema (edited January 23, 2001).]

    Leave a comment:


  • Scott Turchin
    started a topic Fixed length strings

    Fixed length strings

    I like what the help file states about fixed length strings, they are constant...always..

    That makes it easier to determine how much space is available, and in my EXE program I know that if I pull a string out that is 255 bytes long I can start searching for the next variable at 256 bytes.


    Nonetheless this code now fails:

    fh.PassWord = "PASSWORD"

    if St = fh.Password THen


    Where as this code did NOT fail:

    if St = "PASSWORD" Then


    Why is that?


    It mentioned a POINTER is being passed, well that's cool, but do I need to use a pointer to St as well?


    Little confused but almost there..


    Thanks,

    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>
Working...
X