1. Embedding Graphics.
I want tamper-proof graphics for my programs (i.e.: Someone could change a
bmp or gif file that is just hanging around in the executables directory to
whatever they want....) What is the best way to embed or keep graphics from
being changed by users? I would like to use gifs in my programs due to the
size of the files. I am currently using Michael Bolin's GIF loader to load
graphics into my program. Let me know what the best way to mask or embed
my graphics might be. Please include any source that might be helpful if it
is handy!
Thanks,
Don Scott
2. Re: Embedding Graphics.
------ =_NextPart_000_01BD5BCC.86CA41E0
Content-Transfer-Encoding: quoted-printable
> I want tamper-proof graphics for my programs
I've been musing about this, as well. It might be nice if someone would =
write a routine that would convert a list of bytes into text format that =
would be easy to place into programs by including the file - something =
along the lines of what UUE does.
Win32 programs typically expect bitmaps will be in a resource file - =
something not typically available to dynamically created Win32 Euphoria =
programs.
For example, you could have a series of number such as:
{ 0, 1, 2, 3, 4 }
and convert it to something like:
"01234"
To convert a byte to it's value, you would just subtract the ASCII '0' =
from it. If you limited the character set to '0'..'z', you could fit the =
range of bytes into 3 groups: { 0-85, 86-170, 171-255 }.=20
The '+' character could be used to denote that the next byte's value =
should have 85 added on to it, and the '*' character indicates the next =
byte would need 170 added to it.=20
Obviously, the '\' character would need to be translated into '\\' in =
the string.
Even with an average of 2 characters per byte, it seems that storing the =
data in the program in something like:
Bitmap1 =3D uncompress(
"H+lj+sd+sdfjhs+ghsdJ" &
"T+yu+w+7hj+s+fjb+sd8" &
"sdfjkh8jJKiutmbSIUDg" )
is more space efficient than:
Bitmap1 =3D
{ 32, 88, 213, 23, 123, ... }
If you added a compression flag that marked that the following byte was =
to be repeated n times, you might get even better efficiency. Something =
along the lines of:
<flag><repetition><byte>
So if '%' marked the repetition flag,=20
"%87"
would say that eight bytes of value 7 followed.
As it stands, the scheme is fairly tamper-proof from the casual =
observer.
Any takers?
-- David Cuny
------ =_NextPart_000_01BD5BCC.86CA41E0
3. Re: Embedding Graphics.
On Mon, 30 Mar 1998, Don Scott wrote:
> I want tamper-proof graphics for my programs (i.e.: Someone could change a
> bmp or gif file that is just hanging around in the executables directory to
> whatever they want....) What is the best way to embed or keep graphics from
> being changed by users? I would like to use gifs in my programs due to the
> size of the files. I am currently using Michael Bolin's GIF loader to load
> graphics into my program. Let me know what the best way to mask or embed
> my graphics might be. Please include any source that might be helpful if it
> is handy!
I usually combine the images into a single data file so people can't load
and change them. When that isn't desireable, I sometimes remap the
palette of the images to something hideous, and store the real palette in
the program. Then when they try and load the images they get garbage on
their screen. (I did this for OidZone)
The easiest thing to do is just change the extension from .GIF to .SMQ or
something (adjusting the picture loader if necessary to handle
the new extension) so people won't think to try loading it. Many graphics
programs won't try and load a .SMQ file even though it's really a GIF in
disguise.
2 cents.
Michael Packard
Lord Generic Productions
4. Re: Embedding Graphics.
>I want tamper-proof graphics for my programs (i.e.: Someone could
>change a bmp or gif file that is just hanging around in the executables
>directory to whatever they want....) What is the best way to embed or
>keep graphics from being changed by users? I would like to use gifs in
>my programs due to the size of the files. I am currently using Michael
>Bolin's GIF loader to load graphics into my program. Let me know what
the
>best way to mask or embed my graphics might be. Please include any
source
>that might be helpful if it is handy!
You could run a simple encryption of the files, enough to scramble the
data so editing programs don't recognize them and then decrypt the data
as it's being loaded. (Something as simple as adding a certain number to
the byte value and then wrapping it if it goes above 255, then
subtracting that number to
decrypt.) You would need to edit the GIF loader routines to subtract the
number before doing anything with the data, though, then rename the file
to something other than GIF (otherwise they'll get upset they can't load
the GIFs and they know it should be a GIF... then they'll get curious and
try to decrypt....)
_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]
5. Re: Embedding Graphics.
- Posted by Michael Raley <mjronline at IT-WORKS.COM>
Mar 30, 1998
-
Last edited Mar 31, 1998
Store your images in either a single binary data file
or as encoded strings in the program. Write them out at run-time and then
delete when finished.
Even if the User stopped the program and modified the images, the next time
it was run the
master images would be restored...
NEW! HTTP://www.geocities.com/SiliconValley/Lab/7577
Michael J Raley's Modular Reality Journal
-----Original Message-----
From: Don Scott <dts33 at LIGHTSPEED.NET>
To: Multiple recipients of list EUPHORIA <EUPHORIA at MIAMIU.ACS.MUOHIO.EDU>
Date: Monday, March 30, 1998 10:26 AM
Subject: Embedding Graphics.
>I want tamper-proof graphics for my programs (i.e.: Someone could change a
>bmp or gif file that is just hanging around in the executables directory to
>whatever they want....) What is the best way to embed or keep graphics from
>being changed by users? I would like to use gifs in my programs due to the
>size of the files. I am currently using Michael Bolin's GIF loader to load
>graphics into my program. Let me know what the best way to mask or embed
>my graphics might be. Please include any source that might be helpful if it
>is handy!
>
>
>Thanks,
>Don Scott
>
6. Re: Embedding Graphics.
- Posted by "Graeme." <hmi at POWERUP.COM.AU>
Mar 31, 1995
-
Last edited Apr 01, 1995
At 11:10 AM 3/30/98 -0800, you wrote:
>> I want tamper-proof graphics for my programs
>
>I've been musing about this, as well. It might be nice if someone would =
>write a routine that would convert a list of bytes into text format that =
>would be easy to place into programs by including the file - something =
>along the lines of what UUE does.
I did it a while ago. It's on the RDS page in the 'recent user contributions'
section under the heading of 'Convert bitmap to .e' or something similar.
Graeme.
7. Re: Embedding Graphics.
David Cuny wrote:
> I want tamper-proof graphics for my programs
I've been musing about this, as well. It might be nice if someone would
write a routine that would convert a list of bytes into text format that
would be easy to place into programs by including the file - something along
the lines of what UUE does.
No need for something like that because of the couple escape codes that
appear.
Simply replace all *illigal* values with " & ascII-value & " and then
continue with the next byte.
All other legal bytes are just filled in. No conversion to numbers
(inefficient)
If you want to store something else than only pictures (highscores, pictures
& settings included within an program) I could make a extend edo_save to
store stuff a file or somehting in the beginning. Only the resulted edom -
bytes will be treated with an illigal value killer (kills the '"', the '\\'
and the '\n'.. I mean handle them with " & value & " ) so ex.exe
interpreters it right.
But it would need to check if its binded (by calling command_line ), cause
if not it will save it in an incldue file named after your program, but has
an ede extension, however when in binded form it will store its data in its
own program file, just before the code starts 8-) Good idea, don't you think
?
Only how well will this go together with encryption.. ?
Ralf
nieuwen at xs4all.nl
8. Re: Embedding Graphics.
> Any takers?
Me. In fact, the ability to include other files in a euphoria .ex for
distribution would be extremely useful. This could be they key to an idea I've
been brewing for a while, which was probably discussed previously anyway.
--------Installer----------
How about, if all somebody needed was a copy of ex.exe on their hard disk, to
download unbound Euphoria programmes which when run, create executables ?
I would work like this :
Installer file :
**setup.ex
-Setup program and extractor, shrouded for small size, containing all
necessary routines (from graphics.e or whatever)
-abort(0)
-archive of file(s) and bind.ex, compressed using compress.e (Available from
FilesEu)
**End of File
The person has previously downloaded Euphoria Lite (ex.exe and association of
.ex files with it)
They double click setup.ex, unaware of anything special.
Setup then extracts the necessary files from itself, using its built-in
decompression routine. It then calls bind.ex with the necessary arguments, to
create an executable in the directory chosen by the user (Nice proper gui here
if it is not too big). Then finally it deletes all the extracted files.
The file sizes here should be kept down significantly, because downloading
multiple bound files is redundant (Hear this, Michael Packard
). Also,
security can be kept because even the setup program is shrouded, while the
rest is shrouded AND compressed. With allow_break(0), people would have a
tough time even getting your shrouded code, which incidentally can be
extracted from a bound file anyway.
Also, in the end the result can be a single EXE, with graphics stuck on the
end (setup will handle this).
Daniel
9. Re: Embedding Graphics.
For those of you who missed it:
-- Begin INCBM.E --
--- Include Bitmap --- BMP to ASCII with mild compression --- G.Burke 1/98
--- Include Sequence - Added 2/98
--
--- (c)1998 HMI Software. --- SHAREWARE ---
--
--
-- Usage: i1 = incbm( s1 , i2 )
--
-- Where s1 is the full bitmap path
-- i1 will return 0 if successful or a
-- read_bitmap() error code.
-- i2 is the desired number of characters
-- per line in the created file (max 197)
--
-- --------------------------------------------------------------
--
-- include name.e
-- bm = ebm(name)
--
-- Where name is the name of the origional bitmap.
-- bm will be a {palette,bitmap} sequence as returned
-- by read_bitmap()
--
-- --------------------------------------------------------------
--
-- Examples: include incbm.e
-- integer ret
--
-- ret=incbm("c:\\this.bmp",80)
--
-- if ret then
-- puts(1,"Error loading .BMP")
-- abort(0)
-- end if
--
-- --- --- --- --- --- --- --- --- ---
--
-- include this.e
-- include ebm.e
-- include image.e
-- sequence bm
--
-- if graphics_mode(261) then end if
--
-- bm=ebm(this)
--
-- all_palette(bm[1])
-- display_image({0,0},bm[2])
--
--
-- incbm() generates a file with the same name as the origional bitmap
-- file but with a .E extension. This file comtains the data for the
-- bitmap and can be included in your programs like any other .E file.
--
--- incbm() works with any 256 color bitmap file readable by read_bitmap().
--
-- Euphoria currently (1.5a) has limits to the size of a single command,
-- so large complex bitmaps may generate an error when you attempt to
-- retrieve them. This problem is compounded when a program is bound with
-- the hide strings option. According to Rob future releases of Euphoria
-- will not have this limit.
--
--- Including a bitmap in this fashion is *NOT* the most efficiant way to
--- package graphics with a program. It usually results in two copies of
--- the image being kept in memory (and probably swapped out). It is however
--- the easiest way I know of to achieve this. This progam was designed for
--- no-fuss including of small or simple bitmaps with programs.
--
-- For simple images, despite the conversion to ASCII, and the char(34)
-- overhead, the generated .e file will be smaller than the origional bitmap
-- and will also compress to a smaller .ZIP file. If the image is complex
-- (i.e. digitized photos) the .E/.ZIP may be slightly larger than the
-- origional.
--
--- If you are including a file for your use in a program only, use 197
--- characters per line. If you want the code to be visable in a standard
--- editor, use 80.
--
--
-------------------------------------------------------------------------------
-- INCSEQ --
--
-- incseq() & eseq() work in the same fashion as incbm() & ebm().
--
-- incseq only works with 1D sequences and 2D sequences that are 'rectangular'
-- i.e all level 2 sequences are of equal length;- tipically a bitmap. In both
-- cases, the sequences must contain only 8 bit integers.
include machine.e
include image.e
integer fn,cpl,op
procedure cr()
if op=cpl-4 then
puts(fn,{34,'\n','&',34})
op=0
end if
op=op+1
end procedure
procedure pts(integer p)
if p='\\' then
if op>cpl-6 then
puts(fn,{34,'\n','&',34,'\\','\\'})
op=2
else
puts(fn,{'\\','\\'})
op=op+1
end if
else
puts(fn,p)
end if
end procedure
procedure putseven(integer c)
c=c+35
if c>255 then
cr() puts(fn,32)
cr() pts(c-200)
else
cr() pts(c)
end if
end procedure
global function incbm(sequence path,integer cperl)
sequence data,s,name,al,bmp
integer xx,n,w,h,p,f,c
object rb
if cperl>197 then
cperl=197
end if
cpl=cperl
rb=read_bitmap(path)
if atom(rb) then
return rb
end if
bmp=rb[2] name=path al=rb[1]
c=find('\\',name)
while c do
name=name[c+1..length(name)]
c=find('\\',name)
end while
name=name[1..length(name)-4]
fn=open(name&".e","wb")
puts(fn,"\nglobal constant "&name&"="&"\n"&34)
w=length(bmp[1])
h=length(bmp)
s=int_to_bytes(w)
op=0
putseven(s[1])
putseven(s[2])
putseven(length(al))
for x=1 to length(al) do
for q=1 to 3 do
putseven(al[x][q])
end for
end for
for y=1 to h do
xx=1 data={}
while xx<=w do
n=1 f=1
p=bmp[y][xx]
for q= xx+1 to length(bmp[y]) do
if bmp[y][q]=p then
n=n+1
if n>255 then
n=255 f=0 exit
end if
else
f=0 exit
end if
end for
if f then n= 258 end if
if n<4 then
putseven(bmp[y][xx])
xx=xx+1
else
cr()
puts(fn,33)
putseven(n-4)
putseven(bmp[y][xx])
if n=258 then
exit
end if
xx=xx+n
end if
end while
end for
bmp={}
puts(fn,34&"\n\n")
close(fn)
return 0
end function
global function incseq(sequence bmp,integer cperl)
sequence data,s,name
integer xx,n,w,h,p,f
if cperl>197 then
cperl=197
end if
cpl=cperl
puts(1,"Enter a name for the generated file :")
name=gets(0)
puts(1,"\n")
name=name[1..length(name)-1]
fn=open(name&".e","wb")
puts(fn,"\nglobal constant "&name&"="&"\n"&34)
if atom(bmp[1]) then
puts(fn,'o')
w=length(bmp)
s=int_to_bytes(w)
op=1
putseven(s[1])
putseven(s[2])
xx=1 data={}
while xx<=w do
n=1 f=1
p=bmp[xx]
for q= xx+1 to w do
if bmp[q]=p then
n=n+1
if n>255 then
n=255 f=0 exit
end if
else
f=0 exit
end if
end for
if f then n= 258 end if
if n<4 then
putseven(bmp[xx])
xx=xx+1
else
cr()
puts(fn,33)
putseven(n-4)
putseven(bmp[xx])
if n=258 then
exit
end if
xx=xx+n
end if
end while
bmp={}
puts(fn,34&"\n\n")
close(fn)
return 0
else
puts(fn,'t')
w=length(bmp[1])
h=length(bmp)
s=int_to_bytes(w)
op=1
putseven(s[1])
putseven(s[2])
for y=1 to h do
xx=1 data={}
while xx<=w do
n=1 f=1
p=bmp[y][xx]
for q= xx+1 to length(bmp[y]) do
if bmp[y][q]=p then
n=n+1
if n>255 then
n=255 f=0 exit
end if
else
f=0 exit
end if
end for
if f then n= 258 end if
if n<4 then
putseven(bmp[y][xx])
xx=xx+1
else
cr()
puts(fn,33)
putseven(n-4)
putseven(bmp[y][xx])
if n=258 then
exit
end if
xx=xx+n
end if
end while
end for
bmp={}
puts(fn,34&"\n\n")
close(fn)
return 0
end if
end function
global function eseq(sequence dat)
-- optomized for speed
sequence b,l,s
integer x,c,n,w,nc
s=repeat(0,4)
x=2
nc=dat[1]
s[1]=dat[x]-35
if s[1]=-3 then
x=x+1
s[1]=dat[x]+165
end if
x=x+1
s[2]=dat[x]-35
if s[2]=-3 then
x=x+1
s[2]=dat[x]+165
end if
w=bytes_to_int(s)
l={} b={}
x=x+1
while x<= length(dat) do
if dat[x]!=33 then
if dat[x]!=32 then
l=l&dat[x]-35
x=x+1
else
l=l&dat[x+1]+165
x=x+2
end if
else
x=x+1
if dat[x]=32 then
x=x+1
c=dat[x]+165
else
c=dat[x]-35
end if
if c=254 then
x=x+1
if dat[x]=32 then
x=x+1
c=dat[x]+165
else
c=dat[x]-35
end if
l=l&repeat(c,w-length(l))
x=x+1
else
x=x+1
if dat[x]=32 then
x=x+1
n=dat[x]+165
else
n=dat[x]-35
end if
l=l&repeat(n,c+4)
x=x+1
end if
end if
if length(l)=w then
if nc='o' then
return l
end if
b=append(b,l)
l={}
end if
end while
return b
end function
global function ebm(sequence dat)
-- optomized for speed
sequence b,l,s,p
integer x,c,n,w,nc
s=repeat(0,4)
x=1
s[1]=dat[x]-35
if s[1]=-3 then
x=x+1
s[1]=dat[x]+165
end if
x=x+1
s[2]=dat[x]-35
if s[2]=-3 then
x=x+1
s[2]=dat[x]+165
end if
x=x+1
nc=dat[x]-35
if nc=-3 then
x=x+1
nc=dat[x]+165
end if
w=bytes_to_int(s)
l={} b={}
x=x+1
p=repeat(repeat(0,3),nc)
for g=1 to nc do
for q=1 to 3 do
p[g][q]=dat[x]-35
if p[g][q]=-3 then
x=x+1
p[g][q]=dat[x]+165
end if
x=x+1
end for
end for
while x<= length(dat) do
if dat[x]!=33 then
if dat[x]!=32 then
l=l&dat[x]-35
x=x+1
else
l=l&dat[x+1]+165
x=x+2
end if
else
x=x+1
if dat[x]=32 then
x=x+1
c=dat[x]+165
else
c=dat[x]-35
end if
if c=254 then
x=x+1
if dat[x]=32 then
x=x+1
c=dat[x]+165
else
c=dat[x]-35
end if
l=l&repeat(c,w-length(l))
x=x+1
else
x=x+1
if dat[x]=32 then
x=x+1
n=dat[x]+165
else
n=dat[x]-35
end if
l=l&repeat(n,c+4)
x=x+1
end if
end if
if length(l)=w then
b=append(b,l)
l={}
end if
end while
return {p,b}
end function
-- END INCBM.E --
10. Re: Embedding Graphics.
- Posted by "Graeme." <hmi at POWERUP.COM.AU>
Apr 02, 1995
-
Last edited Apr 03, 1995
Here's another one - short and sweet
--- begin incsesf.e --
-- incsesf -- Sequence to include file -- G.Burke 4/98 -- <hmi at
powerup.com.au>
--
-- Pass the procedure any sequence as data, give it a name, and an include
-- file will be generated. This method uses standard Euphoria sequence format
-- which results in larger generated files than the method employed in
-- incbm() and incseq(). The advantage is that it is more memory efficiant;
-- provided that the sequence is left unaltered, only one copy will be kept in
-- memory. I imagine pk/win zip will make light work of all those commas.
-- If you get a "subprogram too large" message, update to the current version
-- of Euphoria.
include file.e
global procedure incsesf(sequence data,sequence name)
integer fn,fn2,c,l,flag
fn2=open("temp.hmi","wb") print(fn2,data) close(fn2)
fn2=open("temp.hmi","rb") fn=open(name&".e","wb")
puts(fn,"\n-- incsesf -- "&name&
" -- G.Burke 4/98\nglobal constant "&name&" =\n")
l=seek(fn2,-1) l=where(fn2) c=seek(fn2,0) flag=0
for x=1 to l do
c=getc(fn2) puts(fn,c)
if flag then
if c=',' then
puts(fn,"\n") flag=0
end if end if
if remainder(x,75)=0 then
flag=1
end if
end for
puts(fn,"\n\n") close(fn) close(fn2)
system("del temp.hmi",2)
end procedure
--- end incsesf.e ---
11. Re: Embedding Graphics.
> I've been musing about this, as well. It might be nice if someone would
>write a routine that would convert a list of bytes into text format that
>would be easy to place into programs by including the file - something
along
>the lines of what UUE does.
Well, some months ago (6/8) I wrote Install Kit. The way it works:
1.- Code your program. and declare a constant (integer) called OFFSET.
2.- Make a function that loads on DATA the data that is stored from OFFSET
to EOF of the first filename in a call to command_line(). Example:
function load_data(integer offset)
integer fn
sequence data
object aux
-- Get filename
aux = command_line()
aux = aux[1]
-- Open file for binary read
fn = open(aux,"rb")
-- Start reading from given offset
aux = seek(fn,offset)
-- Lets fill data
data = ""
aux = getc(fn)
while aux != -1 do
data = data & aux
end while
-- Voila! return data.
return data
end function
3.- Put at the very end of your code abort(0) followed by a blank line.
4.- Bind your program and take note of it length.
5.- Go back to your code and set OFFSET value to the length of your binded
program.
6.- Go to step 3 until the value in OFFSET equals the length of the .exe
file.
7.- Make a copy /b of your .exe file(s) and the file you want to embed.
Note: As you can see you can store as many files as you want, as long as you
write a suitable routine for reading them. You could, for instance, put a
"table of contents" at OFFSET and then "jump" to the disered file (that's
what I did on IK).
I hope this helps on the subject.
Regards,
Daniel Berstein.
12. Embedding Graphics.
Well, my method doesn't use any compression, but it seems to work for
what I designed it for. And it's simple.
I make a directory for the icons I want to use in my program, put all my
icon bmp files in it, put this program in the directory and run it. It
creates a file called Icons.e that defines a global sequence of icons. Then
if for example, all of my icons have a bright white background and I want to
change it to light gray, all I have to do is open the include file in a text
editor and use it's search function to replace all occurrences of 15 with 7.
All of the icons are changed.
To use an icon, I can just say display_image( {x, y}, icon[UPARROW] )
or whatever. (constants for icons are named after their bmp file name)
Of course, I suppose everyone's already done this. But thought I might
as well share anyway.
Falkon
----------------------------------------------------------------------------
----
-- concat.ex
-- concatenates several small bmps into one include file
----------------------------------------------------------------------------
----
include graphics.e
include image.e
include file.e
include wildcard.e
sequence filelist1, filelist2
filelist1 = dir(current_dir())
filelist2 = {}
-- make a list of all *.bmp files in the directory
for count = 1 to length(filelist1) do
if wildcard_file("*.bmp", filelist1[count][1]) then
filelist2 = append(filelist2, filelist1[count][1])
end if
end for
filelist1 = {}
-- create include file "Icons.e" and write the list of constants
object result, fn
fn = open( "Icons.e", "w" )
if fn = -1 then abort(2) end if
puts( fn, "global sequence icon \n icon = repeat( {}, " )
print( fn, length(filelist2) )
puts( fn, " ) \n\n" )
puts( fn, "constant " )
for count = 1 to length(filelist2) do
if count = length(filelist2) then
puts( fn, "
"&filelist2[count][1..length(filelist2[count])-4]&" = "&sprintf("%d \n\n",
count))
else
puts( fn, "
"&filelist2[count][1..length(filelist2[count])-4]&" = "&sprintf("%d,\n",
count))
end if
end for
-- write image data
for count = 1 to length(filelist2) do
result = read_bitmap( filelist2[count] )
if atom(result) then
puts( 2, "Unable to open "&filelist2[count]&"\n" )
abort(1)
end if
puts( fn, "icon[" )
puts( fn, filelist2[count][1..(length(filelist2[count])-4)] )
puts( fn, "] = {\n" )
for count2 = 1 to length(result[2]) do
puts( fn, " " )
print( fn, result[2][count2] )
if count2 = length(result[2]) then
puts( fn, " \n" )
else
puts( fn, ", \n" )
end if
end for
puts( fn, " }\n\n" )
end for
close( fn )
----------------------------------------------------------------------------
----
----------------------------------------------------------------------------
----