Oxygen Basic

Programming => Example Code => Data Processing => Topic started by: Aurel on August 26, 2013, 08:31:22 AM

Title: Binder?
Post by: Aurel on August 26, 2013, 08:31:22 AM
Hi Charles...
I know how create binder in CB/EB but i am not sure how to do this in Oxygen.
As you know binder must add source file(in binary format) to already existing executable PE file.
so final exe must look like this:

finalEXE = exeFILE + sourceFILE

Do you have maybe something already created?
Or maybe you can show me how to do this?
Title: Re: Binder?
Post by: JRS on August 26, 2013, 08:46:17 AM
Aurel,

ScriptBasic allows binding it's tokenized binary script to the end of the interpreter to create a standalone app. Take of look at the SB source to see how it's done.

Title: Re: Binder?
Post by: Aurel on August 26, 2013, 08:58:51 AM
Ok John...i will
But i am in first place interested how to do this in Oxygen.. ;)
Title: Re: Binder?
Post by: JRS on August 26, 2013, 09:23:41 AM
I don't understand why you would want to do this with a compiler as this is a way to give interpreters that standalone feel.


Title: Re: Binder?
Post by: Aurel on August 26, 2013, 09:49:42 AM
And i don't understand your question at all ???
This is something what i need for my interpreter not for oxygen compiler...
do you get it now ?
Title: Re: Binder?
Post by: JRS on August 26, 2013, 10:23:49 AM
Quote
do you get it now ?

Yes. Thanks for the clarification.

Quote
But i am in first place interested how to do this in Oxygen..

In SB before the command line is checked for it's options and program to run, it first looks to see if there is a binary SB script attached. If so it runs that script and ends otherwise it's standard scriba.
Title: Re: Binder?
Post by: Charles Pegge on August 26, 2013, 02:10:29 PM
Hi Aurel,

You need to compile the interpreter/script engine with the script.

Something like this:

% filename "t.exe"
includepath "$/inc/"
include "RTL32.inc"

bstring src
includepath ""
embedfile src,"t.bas"

print src 'test

'include script engine here to interpret src string...

Alternatively, treat the script as a string resource, and use GoRc and Res2Exe to bind it to the script engine exe.
Title: Re: Binder?
Post by: Aurel on August 26, 2013, 08:40:02 PM
Hmmm
Charles i will try your way but something is not like i say to you.
i need this:

'in folder ...folder1,already exists
runtime.exe
'and we must add src.txt file but in binary format

so do i need just
 embedfile src,"t.exe"

 ???

In my work in EB i create two memory buffers and connect them into one memory buffer
then save this new memory buffer as final exe.
Do you can show me that way ?
Title: Re: Binder?
Post by: JRS on August 26, 2013, 08:55:41 PM
Here is how it is done in SB.

Linux
Code: [Select]
jrs@laptop:~/sb/sb22/test$ cat hello.sb
PRINT "Hello World\n"

jrs@laptop:~/sb/sb22/test$ /home/jrs/sb/sb22/bin/scriba -Eo hello hello.sb
jrs@laptop:~/sb/sb22/test$ chmod 755 hello
jrs@laptop:~/sb/sb22/test$ ./hello
Hello World
jrs@laptop:~/sb/sb22/test$

Windows
Code: [Select]
C:\SB22\test>type hello.sb
PRINT "Hello World\n"

C:\SB22\test>scriba -Eo hello.exe hello.sb
C:\SB22\test>hello
Hello World
C:\SB22\test>

On my Windows XP VirtualBox, I have associated .sb with scriba.exe so anytime I click on a script it executes from the Windows explorer or the console without having to prefix it with scriba. Isn't that really the same thing as binding but without the bloat of the interpreter attached to each copy of your script?



Title: Re: Binder?
Post by: Aurel on August 26, 2013, 11:38:34 PM
No is not ( i think)  that this is more like thinBasic binding is .
i use this method in Aurelbasic to bind source file on the end of runtime.exe
Title: Re: Binder?
Post by: JRS on August 27, 2013, 12:16:39 AM
No, this is NOT like thinBasic which uses a utility to pack all the files into a self extracting exe. Like I said in the beginning, SB appends the binary/tokenized script to the end of the ScriptBasic interpreter and check if one is present before processing anything on the command line.

I can't make it any more simple than that!  ::)



Title: Re: Binder?
Post by: Aurel on August 27, 2013, 12:37:10 AM
So then it is the same,right...
i think that i need some memory operation here like:

INT buff1,buff2,buffOut

'here is problem -> how load runtime.exe into memory buffer?
ef = Getfile "runtime.exe" ... or something like that ?
buff1 = getmemory bfile
Title: Re: Binder?
Post by: JRS on August 27, 2013, 12:45:21 AM
Aurel,

You're making this much harder than it needs to be.

Create a utility that makes a copy of your interpreter and tags the tokenized script to it. Modify your interpreter on startup to check to see if a script has been appended. If so run it and end the program. The only difference between your standard interpreter and the standalone script is it's name is different and has a script attached.

Title: Re: Binder?
Post by: Charles Pegge on August 27, 2013, 12:46:07 AM
You can embed any kinds of files into Oxygen and access them as bstring constants, text or binary. But it has to be compiled with the source of your runtime.
Title: Re: Binder?
Post by: Aurel on August 27, 2013, 01:16:05 AM
Quote
Create a utility that makes a copy of your interpreter and tags the tokenized script to it. Modify your interpreter on startup to check to see if a script has been appended. If so run it and end the program. The only difference between your standard interpreter and the standalone script is it's name is different and has a script attached.

John...
This is what my binder written in EB do.

Charles
So from you,you mean that there is no need to use any memory allocation and getmemory functions.
And one thing is not clear to me how i can put binary file runtime.exe into bstring ???
Or i completelly don't undertand what you mean :-\
Title: Re: Binder?
Post by: Charles Pegge on August 27, 2013, 01:24:45 AM
You have to oxygen-compile the embeded script with the source of your runtime, so the runtime can process the embedded script. Is that what you intend?
Title: Re: Binder?
Post by: Aurel on August 27, 2013, 03:18:13 AM
Yes .
I don't know why you talk about compiled,of course runtime will be compiled PE exe file
without dll.
So only this runtime.exe + bindedScript.txt
And of course this bindedScript must be added on the end of runtime.exe...
So that is why iask how to connect this both files,and that is why i ask for memory functions.
I hope now Charles that you understand me ;)
Title: Re: Binder?
Post by: Charles Pegge on August 27, 2013, 06:00:29 AM
There is no provision for post-insertion of a script/token code into an exe file, So you have to use your runtime/script engine source code and compile the whole thing into one PE
Title: Re: Binder?
Post by: JRS on August 27, 2013, 10:41:51 AM
Quote
This is what my binder written in EB do.

The only time I use the binding method with SB is if I want to use a script I wrote as part of a batch file which may require redirection and using scriba to start the script becomes problematic. The association method works best in general and I always have the option to translate (-C) my SB script to C.

Title: Re: Binder?
Post by: Aurel on August 27, 2013, 02:24:57 PM
I just say that this method work...
so pleae any piece of code ?
Title: Re: Binder?
Post by: JRS on August 27, 2013, 03:12:08 PM
Personally I think the benefit of binding isn't worth all the effort and band-aiding your doing with your interpreter. Is this feature of binding a show stopper for you?

Title: Re: Binder?
Post by: Charles Pegge on August 27, 2013, 09:28:27 PM
Aurel, could you post some code showing what you do in 'CB / EB'.
Title: Re: Binder?
Post by: Aurel on August 28, 2013, 03:35:32 AM
Yes Charles
What i have is old code from ionicwind forum...only
because i have lost latest binder code...
so here is CB code:
Code: [Select]
'Exe binder ,Thanks to Johnny ....
Def w1:window
DECLARE "kernel32",SetFileAttributesA(lpFileName AS STRING,dwFileAttributes AS INT),INT
CONST FILE_ATTRIBUTE_ARCHIVE = 0x20
CONST FILE_ATTRIBUTE_NORMAL = 0x80
CONST FILE_EXECUTE = 0x20
'declare variables
def runtimeExe:BFILE
def sourceCode:BFILE
def NewExe:BFILE
def membuffer:memory
def membuffer2:memory
def runtimesize:INT
def sourcesize:INT
def newsize:int
def zero:char
def sizeMembuffer:INT
def runtimeName:string
def sourceName:string
def finalSize:INT

'open window
Window w1,0,0,500,400,@minbox,0,"MainGUI",main
Setwindowcolor w1,rgb(200,200,205)

CONTROL w1,"B,LoadRuntimeExe,56,50,120,20,0,1"
Setfont w1,"MS Sans Serif",8,400,0,1
CONTROL w1,"B,LoadSourceCode,56,100,120,20,0,2"
Setfont w1,"MS Sans Serif",8,400,0,2
CONTROL w1,"B,SaveBindedExe,56,150,120,20,0,3"
Setfont w1,"MS Sans Serif",8,400,0,3
'--------------------------------------------------------
'--------------------------------------------------------
run=1
waituntil run=0
'stoptimer w1

'Free the memory in case this was allocated before ending the program
IF Len(membuffer)>0 then FreeMem membuffer
IF Len(membuffer2)>0 then FreeMem membuffer2

closewindow w1
end

'-------------------------------------------------------
Sub main
Select @class
Case @idclosewindow
run=0

'/////////////////////////////////////////////////////////
case @IDCONTROL

IF @CONTROLID = 1
    LoadRuntime()
ENDIF

IF @CONTROLID = 2
    LoadSource()
ENDIF

IF @CONTROLID = 3
    CreateExe()
ENDIF
'////////////////////////////////////////////////////////
Endselect
Return
'-------------------------------------------------------
' load Runtime to memory
SUB LoadRuntime
zero=0

IF (Openfile(runtimeExe,"C:\minGUI.exe","R") = 0)
    runtimesize = Len(runtimeExe) :'runtime=FileSize(runtimeexe)
Messagebox 0,"RuntimeLen(bytes):"+str$(runtimesize),"RUNTIME SIZE"

    AllocMem membuffer,1,runtimesize
READ(runtimeExe,membuffer)

Messagebox 0,"MEMbuffersize(bytes):"+str$(Len(membuffer)),"R-MEMBUFFER SIZE"
CloseFile runtimeExe
ENDIF

RETURN

'-----------------------------------------------------
'load Source to memory
SUB LoadSource
zero=0

IF (Openfile(sourceCode,"C:\CaptionString.abp","R") = 0)
    sourcesize = Len(sourceCode) :'sourcesize=FileSize(sourcecode)
Messagebox 0,"SourceLen(bytes):"+str$(sourcesize),"SOURCE CODE SIZE"

    AllocMem membuffer2,1,sourcesize
READ(sourceCode,membuffer2)

Messagebox 0,"CompleteLen(bytes):"+str$(LEN(membuffer2)),"MEMBUFFER-COMPLETE-SIZE"

CloseFile sourceCode
ENDIF


RETURN

'-----------------------------------------------------
'Create Exe / Write final exe to disk
SUB CreateExe
'Check first that both buffers are already filled with data before writing to a new file
IF runtimesize > 0 & sourcesize > 0
newsize = runtimesize + sourcesize
Messagebox 0,"CompleteLen(bytes):"+str$(newsize),"COMPLETE-SIZE"

IF (Openfile(newExe,"C:\MRuntime.exe","W") = 0)

Write newexe,membuffer,membuffer2
finalsize=Seek(newexe)
CloseFile newexe

Messagebox 0,"FinalLen(bytes):"+str$(finalsize),"BINDED EXE SIZE"
ENDIF
ENDIF
RETURN
Title: Re: Binder?
Post by: Charles Pegge on August 28, 2013, 03:20:21 PM
Thanks Aurel,

It seems that this code is simply tacking the two files together, without further processing.

In Oxygen:

exe=getfile "C:\minGUI.exe"
src=getfile "C:\CaptionString.abp"
putfile "C:\MRuntime.exe",exe+src
Title: Re: Binder?
Post by: Aurel on August 29, 2013, 02:11:35 AM
Hi Charles hmmm
this looks to simple ,infact it is simple operation but ...
ok i wil try ;)