Author Topic: IncBin instruction  (Read 3965 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
IncBin instruction
« on: April 11, 2013, 09:38:27 AM »
Hi Charles'

does Oxygen basic has something like 'incBin' include binary that will load a file and put it with exe file while
compilation , giving the user the start address of memory containing the file and the length?  

Charles Pegge

  • Guest
Re: IncBin instruction
« Reply #1 on: April 11, 2013, 10:21:59 AM »
Yes you can use embedfile to embed any kind of file (within the includepath spec)

Supposing you had a file: t.txt containing ABC

sys p

embedfile "t.txt",p

byte b at p

print b[3] '67


I haven't got a formal parameter for length but, since it is stored as a pseudo-bstring, you can recover the length like this:

dword le at (p-4)
print le
'3
« Last Edit: April 11, 2013, 10:31:33 AM by Charles Pegge »

Emil_halim

  • Guest
Re: IncBin instruction
« Reply #2 on: April 11, 2013, 10:41:21 AM »

Ok , thanks Charles,

for the length , i have an idea .

can we put a label before and after embedfile instruction , then we can subtract this label to get the length.

so what do you think?

Charles Pegge

  • Guest
Re: IncBin instruction
« Reply #3 on: April 11, 2013, 11:14:45 AM »
Embedded data is stored in dataspace, which is curently unlabelled. All refernces are assigned to pointer variables (also string variables)

PS: Just realised you can also refer to embedded data as a bstring constant

bstring p
embedfile "t.txt",p
print p
print len p


Aurel

  • Guest
Re: IncBin instruction
« Reply #4 on: April 11, 2013, 01:02:46 PM »
Charles ..
I never ask about this but this looks to me like command bind
so do i can bind any file to already created exe ?

Charles Pegge

  • Guest
Re: IncBin instruction
« Reply #5 on: April 11, 2013, 07:41:40 PM »
The bind keyword is used for low level linkage to DLLs. EmbedFile is more like embedding resources.

Emil_halim

  • Guest
Re: IncBin instruction
« Reply #6 on: April 12, 2013, 03:50:39 AM »
Hi Charles,

what about Bin file that may contains many text terminator char.

does the len get it correctly?

Charles Pegge

  • Guest
Re: IncBin instruction
« Reply #7 on: April 12, 2013, 04:53:52 AM »
Yes, it stores the whole file content as a binary string of specified byte count.

Emil_halim

  • Guest
Re: IncBin instruction
« Reply #8 on: April 12, 2013, 05:16:29 AM »
so deos len get the correct length?

Charles Pegge

  • Guest
Re: IncBin instruction
« Reply #9 on: April 12, 2013, 05:43:35 AM »
Yes, if you map a bstring onto the data
sys p
embedfile "t.something",p
bstring s at p
print len s

You can also map any type or structure to p at the same time

byte b at p
image img at p

or at any offset of p

rgba pixel at (p+256)

print pixel[10].blue




Emil_halim

  • Guest
Re: IncBin instruction
« Reply #10 on: April 12, 2013, 06:00:09 AM »

that's great Charles.

one more thing , Sphinx C-- also support including a specific part of the file as well.

what do you think? 

Charles Pegge

  • Guest
Re: IncBin instruction
« Reply #11 on: April 12, 2013, 06:12:30 AM »
Could add offset and length as optional parameters. Does Sphinx do it this way?

Emil_halim

  • Guest
Re: IncBin instruction
« Reply #12 on: April 12, 2013, 06:17:18 AM »

No , it is only include the needed part of the file.

something like this
Code: [Select]
sys p
embedfile "t.something",p , optional offset ,optional  len