Announcement

Collapse
No announcement yet.

Reading text file from code

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

  • Reading text file from code

    Hi,
    I'm doing a project using GEN4-ULCD-43DCT-CLB-SB and in one of the forms it is necessary to insert the password to go to the next form. I've just purchased the license of Workshop4 and I'using 'Code' and 'KbClr' tools to do that.
    It seems to work, but I'd like to ask you if it is possible to read an encrypted text file from the code, because I want to save my password there. Also other solutions are welcome (the aim is to hide the password), for example an encrypted executable with any file inside the microSD might be a solution. Is it possible? How?
    Thank you very much in advance.

    Best regards,

    Samuele

  • #2
    Hi Samuele,

    One thing that I can think of is you generate a .txt file with random characters on it (approx. 100 to 1000), then use the FAT16 File Functions available on the display to search for the password which is hidden inside those characters.

    For more information about the FAT16 File Functions, you can refer to DIABLO16 Internal Functions Reference Manual.

    Since you are using ViSi Genie-Magic, it will be best to be familiar first with Magic Codes. Please have a look at this application note:
    AN-00199 ViSi-Genie Magic Code Insertion Points:
    https://4dsystems.com.au/blog/4d-an-00199/

    For reference, here is an application note which demonstrates how to read a file using ViSi-Genie Magic
    AN-00161 ViSi-Genie Magic How to Read a File:
    https://4dsystems.com.au/blog/4d-an-00161/

    There is a lot of examples on the forum which shows how to read a file on uSD card. You can also use that as a reference.

    For the uSD card, you could try to create a RAW partition to store the password so that it can make your file more secure.

    Another option is to store the password inside the flashbank memory of the Diablo16. In this case, another program is loaded on a different flashbank - which contains the password you will look into.

    I hope this helps.

    Best Regards,
    Kevin
    Last edited by John Kevin; 27th August 2019, 08:01 PM.

    Comment


    • Sam93
      Sam93 commented
      Editing a comment
      Thank you very much for your reply. I saw the examples and I'm following them, but what I look for is something to hide the password.
      I think I get what you meant, so after I created the .txt file with random letters+password, I can use the following FAT16 File Functions:
      1) file_Read(destination,size,handle) to open the .txt file;
      2) file_Index(handle,Hisize,Losize,recordnum) to place the pointer in the positions that contain the password letters;
      3) file_GetC(handle) to take the letter;
      4) repeat the process to get any letter.
      Is it right?
      If so, it is not a very safe way because it is possible to get the password reading the code, isn't it?

      Best regards,

      Samuele

  • #3
    Hello Samuele,

    In this case, you may want to use a RAW partitioned drive.

    To partition your uSD card into FAT and RAW components, please follow the step by step procedure on this application note:
    AN-00042 General Partitioning a micro-SD into FAT and RAW Components
    https://4dsystems.com.au/blog/4D-AN-00042/

    Click image for larger version

Name:	raw.png
Views:	101
Size:	13.9 KB
ID:	69446

    Please take note of the starting sector address of your RAW uSD card. In hex format, the value is 003B 9000.

    After successfully partitioning the drive, you can use the "Media Functions" to write and read to the RAW uSD card.
    To write a byte on the drive, first set the address using media_SetSector or media_SetAdd
    Please take a look at this snippet of code:

    Code:
    while (media_Init() == 0); // if there is SD card
        print("SD card Detected! \n");
        //media_SetSector(0, 7624); // starting sector of RAW uSD card
        media_SetAdd(0x003B,0x9000 );
        to(MDA); putstr("TESTs ThE pAsSWord iS 123456");
        media_WriteByte('\0');
    
        media_Flush(); //close the sector
    To read the file and save it in the buffer:
    Code:
    //Read Files from the uSD Card
        media_SetAdd(0x003B,0x9000 + 6);
    
        //save it in a buffer
        ptr:=str_Ptr(buffer);
        while(char:=media_ReadByte())
           str_PutByte(ptr + i, char);
           i++;
        wend
    
        txt_MoveCursor(10,0);
        print("Password Length: ",str_Length(ptr));
        print("\nThe Password is: ",[STR]buffer);
    You may want to have a separate file/program for writing on RAW uSD card, so it will not be visible on your Main program.


    Another option to write on RAW uSD card is through ScriptC utility. Perhaps this forum thread may help you on how you can use ScriptC:
    How can I copy Media Files from a Project to SD Card without IDE: https://forum.4dsystems.com.au/node/55675

    I hope this helps.
    Best Regards,
    Kevin

    Comment

    Working...
    X