Page 1 of 6

Stores simple states in exe

Posted: Thu Apr 05, 2018 1:35 pm
by Kwai chang caine
Hello at all

I search to store simple states in a STANDALONE exe.
Obviously they are numerous way for do this, but this time i not need to store datas, but just one or several state.
So i know the DATA method, with creating a copy of an exe, poke inside datas, and run it another time for read new datas poked, but this heavy method is not really necessary for just few bits.
Furthermore i don't want use the BDR

So i have try numerous things for modify hitself the attribute of an exe
The firsts who works is #PB_FileSystem_System / #PB_FileSystem_Archive / #PB_FileSystem_ReadOnly that i can modify dynamicaly even if the EXE run
But i'm a little bit affraid, because sometime windows explorer change without alert this attribute :cry:

And i have also found another attribute #FILE_ATTRIBUTE_TEMPORARY or #FILE_ATTRIBUTE_ENCRYPTED :shock:
I suppose this CONSTANT is not really used in the case of personal exe ? so why not use it myself for my own need ? :D

Create an EXE of this code, run the exe, the first time the MsgBox is "32" and all the futur time "256"

Code: Select all

MyExe.s = ProgramFilename()
Attribute = GetFileAttributes(MyExe)

If Attribute = 32
 MessageRequester("Temporary attribute", Trim(Str(Attribute)))
 Attribut = #FILE_ATTRIBUTE_TEMPORARY ; or #FILE_ATTRIBUTE_ENCRYPTED 
 SetFileAttributes(MyExe, Attribut)
Else 
 MessageRequester("Temporary attribute", Trim(Str(Attribute)))
EndIf 
Have you another idee for auto writing simple states in an exe without recreate it

Have a good day

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 1:49 pm
by walbus
You can simply append the data to the end of the exe with writedata

Code: Select all

file=OpenfileFile(#PB_Any, "My File")
file_length=Lof(file)
FileSeek(file, file_length)
WriteQuad(file, file_length)  
CloseFile(file)

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 1:53 pm
by PedroMartins
*** to Administrator: please delete this post reply ***

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 2:12 pm
by Kwai chang caine
@Walbus
Yes it's one or the several solution for writing datas in an exe, but the problem, like with poke DataSection, it's impossible to change the datas when the EXE run :cry:

@PedroMartins
No because i try to create a standalone exe, and not want writing something in BDR or external file, etc ...
Furthermore create a txt file for just writing one "1" or "0".... :|

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 2:17 pm
by Kwai chang caine
I have also found another funny tips, but it's not really nice :oops:
Like windows not care of the case of the exe, and i have tested it's possible to rename an exe during it's works
I can uppercase or lower case each characters of the EXE, like this i can memorise one state "0/1" by character , and this time windows never change alone the case :idea: 8) :mrgreen:

Code: Select all

MyExe.s = ProgramFilename()
RenameFile(MyExe, UCase(MyExe))

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 2:23 pm
by RSBasic
You can copy your original program into the Temp folder and start it with a parameter (/SetState) (exit the original program at the same time) and modify the original executable. Then start the modified exe file.

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 2:33 pm
by Kwai chang caine
Yeeees !! it's a good idea :D
Sure it's when even rewriting the EXE :| but i don't know this way
Usually i rename the original in TempName, create copy of original with his name, add the modification in the copy
And when i close the original "TempName" extract a batch who erase the original and hitself...very very less simple than your solution, you see :wink:

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 3:31 pm
by walbus
It only works with a temporary exe
But there is a trick
You include a small start exe in the exe you want to patch
From the main exe copy this small start exe into the home folder, the temp folder does not work with Linux.
Then you start the small exe in the Home folder from the main exe
At startup, pass the parameter to be saved and exit the main exe
Now the little exe can patch the big one and then terminate its

The parameter is read in exactly the same way

Yes, I know it's not very nice, but it goes and is the answer to his question

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 4:07 pm
by Kwai chang caine
Yes it's one of numerous another way 8)
but it goes and is the answer to his question
Not fully, because like i have say in my question, i try to not recreate the exe or other exe.
Just try to writing a simple state, so one bit (or more is it's possible obviously :mrgreen:) in an exe working.
It's the reason why i try to found an attribute not really used, like the example above, or the tips of case changing, or perhaps another idea possible for put this state somewhere in the EXE.

For the moment, i have choose to use the #FILE_ATTRIBUTE_TEMPORARY and that works perfectly 8)
Apparently the only one danger is if they are not enough space in the drive, Windows delete all the file with this flag :shock:

Image

So it's not really often they are not enough space in a drive...finally i hop :oops: :lol:

If a day my exe disapears like a miracle, i use the case first letter like this :

Code: Select all

MyExe.exe ==> 0 ==> First option
Myexe.exe ==> 1 ==> Second option
Or perhaps a new idea come to someone

Image

So thanks at all for your precious advice 8)

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 4:21 pm
by walbus
You can also write the parameter in the file name if it does not need to be hidden
"MyFile_3456.exe"
However, all these constructions should be avoided as much as possible

If you use it, you have to make sure that it works always and without problems

You can delete the small temporary file from the main exe again
This small file only exists for fractions of a second, you can't see it and you won't even notice its temporary existence.

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 4:52 pm
by Kwai chang caine
Yes at the begining, i have thinking to this solution too :wink:
But if the user make a shortcut, that's dead, the link is broken :lol:

But the only thing who not change the windows behaviour, is the case for the name, and again fortunately i not use LINUX :wink:
Perhaps i can also writing something in the shortcut, but it's dangerous, if the exe is moving and shortcut recreated :|

Perhaps they are some space not really used in the header of EXE, or something like this, but here it's to strong for me, and furthermore i'm not sure i can modify the header when EXE run :|

Decidedly ....long life to access :lol: :lol: :|

Image

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 4:59 pm
by said
Hi KCC,

You can also make use of a file date attribute using GetFileDate() and SetFileDate(), you know in a date there is a time part that you can use as you like ... change the time in #PB_Date_Created/#PB_Date_Modified as you like

Said

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 5:01 pm
by walbus
I used to have a lot to do with these things
there is hardly anything I don't know or haven't used yet

Try my new BF GIF tool, it has become absolutely cool, today it was finished :wink:

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 5:06 pm
by Kwai chang caine
Hello SAID :D
I have try that also, but the problem it's impossible to change the CREATED DATE when the exe run :?
And the other dates is always changed by the system :|
But thanks for your idea :wink:

@WALBUS
Thanks WALBUS, i take a new look soon, if KCC not try a GIF tool...it's the end of the world :lol: :lol:

Image

Re: Stores simple states in exe

Posted: Thu Apr 05, 2018 5:25 pm
by firace