AutoHotkey Community

It is currently May 27th, 2012, 10:09 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 85 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject:
PostPosted: July 17th, 2006, 7:52 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
If someone is stil interested in direct conversion between hex and base64, I updated the script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2006, 12:03 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Laszlo wrote:
If someone is stil interested in direct conversion between hex and base64, I updated the script.
Thanks :) . I'll take it for a spin soon.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2006, 7:17 pm 
Offline

Joined: July 21st, 2006, 6:13 am
Posts: 558
ok so i have been trying to figure this out on my own and i cant, so i come to you guru's for help... :D
keep in mind im not an expert with AHK.. :x
here is what im trying to do:

Code:
#singleinstance force
#noenv
gosub, definepicture
WriteFile("logo.bmp",picture)
gui, add, pic,x100,logo.bmp
gui, add, text,xm,The Image above was created by the script.
gui, show,, by Veovis
return

WriteFile(file,data)
{
   Handle :=  DllCall("CreateFile","str",file,"Uint",0x40000000
                  ,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
   Loop
   {
     if strlen(data) = 0
        break
     StringLeft, Hex, data, 2         
     StringTrimLeft, data, data, 2 
     Hex = 0x%Hex%
     DllCall("WriteFile","UInt", Handle,"UChar *", Hex
     ,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
    }
 
   DllCall("CloseHandle", "Uint", Handle)
   return
}

definepicture:
picture =
( join
0000010006003030000001000800a80e0000660000002020000001000800a
)
return

guiclose:
exitapp


i keep getting this error. this is an .ico file btw... is it even possible with an .ico file?
i assume it is, but you know what they say when you assume!

Image

can someone please help me with this. :oops: thanks...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 12:50 am 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
Why is this garbled?

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 1:31 am 
Offline

Joined: February 13th, 2006, 10:40 pm
Posts: 389
Location: Utah
@aCkRiTe

you have run into the 16 kb line limit of ahk.
each line of code in AHK can only be 16384 chars long.

basically you can't encode a file larger than 16 kb on one line but you can split it into several different lines

you might have to change the function a bit but this is the concept
Code:
part1= ae76b3ae97bca4....
part2 = aef809438abc908e33..
part3 = bacd36764bacdc9...
;then write each part

_________________
Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 6:23 am 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
I ran in to this myself, but understood the limitation.
I didn't, however, know how to overcome it.
Being an intermediate user (not a noob, but far from an expert),
could you give an example of how this might be done?

This is a brilliant script, however, I would like to see it used with files larger than 16kb.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 8:43 am 
Offline

Joined: February 13th, 2006, 10:40 pm
Posts: 389
Location: Utah
Sigh I have been trying to crack this for hours. (yeah i can come up with brialliant code sometimes but it takes me a while)

Ill give you guys the code and let you try it out. This code works fine for files smaller than 16 kb. Its designed to be able to handle more. But for somereason it creates the file, and its the right size and everything, its just... it isnt right. I cant view the picture files i try it out on. Its like 1:30 in the morning and im going to sleep now. Hopefully someone can shed some light on what im doing wrong.

Code:
StringCaseSense On
Chars = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
gui, add, button, w100 gOpen,Open File
gui, add, text, x+10,var name:
gui, add, edit, x+10 w100 vName,File
gui, add, text, x+10,extract to:
gui, add, edit, x+10 w100 vwriteto,file.ext
gui, add, edit, r40 w510 vOutput xm
gui, show
return

Open:
gui, submit, nohide
fileselectFile,file
BinRead(file,data)
Bin2Hex(h,data,0)
output =
count = 0
loop,
{
   if not h
      break
   stringleft, peice%A_index%,h,16000
   stringtrimright,h,         h,16000
   output := output "`n" name "_peice" A_index " = " peice%A_index%
   count ++
}
output := output "`n`nWriteFile(""" writeto ""","""
loop, %count%
   output := output name "_peice" A_index "|"
stringtrimright,output,output,1
output := output """)   `n`n"
function =
(join`n
WriteFile(file,peices)
{
   global
   local Handle,data,hex
   Handle :=  DllCall("CreateFile","str",file,"Uint",0x40000000
                  ,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
   Loop,parse,peices,|
   {
     peice := `%A_loopfield`%
     data := data peice
   }
   Loop,
   {
      if strlen(data) = 0
        break
     StringLeft, Hex, data, 2
     StringTrimLeft, data, data, 2
     Hex = 0x`%hex`%
     DllCall("WriteFile","UInt", Handle,"UChar *", Hex
     ,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
   }
   DllCall("CloseHandle", "Uint", Handle)
   return
}
)
output := output function
guicontrol,,output,%output%
return

Bin2Hex(ByRef h, ByRef b, n=0)      ; n bytes binary data -> stream of 2-digit hex
{                                   ; n = 0: all (SetCapacity can be larger than used!)
   format = %A_FormatInteger%       ; save original integer format
   SetFormat Integer, Hex           ; for converting bytes to hex

   m := VarSetCapacity(b)
   If (n < 1 or n > m)
       n := m
   Address := &b
   h =
   Loop %n%
   {
      x := *Address                 ; get byte in hex
      StringTrimLeft x, x, 2        ; remove 0x
      x = 0%x%                      ; pad left
      StringRight x, x, 2           ; 2 hex digits
      h = %h%%x%
      Address++
   }
   SetFormat Integer, %format%      ; restore original format
}


BinRead(file, ByRef data, n=0, offset=0)
{
   h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0)
   IfEqual h,-1, SetEnv, ErrorLevel, -1
   IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file

   m = 0                            ; seek to offset
   IfLess offset,0, SetEnv,m,2
   r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m)
   IfEqual r,0, SetEnv, ErrorLevel, -3
   IfNotEqual ErrorLevel,0, {
      t = %ErrorLevel%              ; save ErrorLevel to be returned
      DllCall("CloseHandle", "Uint", h)
      ErrorLevel = %t%              ; return seek error
      Return 0
   }

   m := DllCall("GetFileSize","UInt",h,"Int64 *",r)
   If (n < 1 or n > m)
       n := m
   Granted := VarSetCapacity(data, n, 0)
   IfLess Granted,%n%, {
      ErrorLevel = Mem=%Granted%
      Return 0
   }

   result := DllCall("ReadFile","UInt",h,"Str",data,"UInt",n,"UInt *",Read,"UInt",0)

   if (!result or Read < n)
       t = -3
   IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel%

   h := DllCall("CloseHandle", "Uint", h)
   IfEqual h,-1, SetEnv, ErrorLevel, -2
   IfNotEqual t,,SetEnv, ErrorLevel, %t%-%ErrorLevel%

   Return Read
}


or try this substitute WriteFile function (just paste it in whre the other one is, i think this one is faster...)

Code:
WriteFile(file,peices)
{
   global
   local Handle,data,hex
   Handle :=  DllCall("CreateFile","str",file,"Uint",0x40000000
                  ,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
   Loop,parse,peices,|
   {
      data := %A_loopfield%
      tooltip, piece %A_index%
      Loop,
      {
         if strlen(data) = 0
           break
         StringLeft, Hex, data, 2
         StringTrimLeft, data, data, 2
         Hex = 0x%hex%
         DllCall("WriteFile","UInt", Handle,"UChar *", Hex
         ,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
      }
   }
   DllCall("CloseHandle", "Uint", Handle)
   return
}

_________________
Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2006, 2:17 am 
Offline

Joined: July 21st, 2006, 6:13 am
Posts: 558
Thanks Veovis for the help... Yeah Im not sure what the problem is either. :( Like you said your code works fine except the picture wont view properly. If you open the picture (.bmp, jpg, ect..) it only shows the first 16kb that was copied to the file, but yet all the data is there if you view it in hex. So you code words fine, Im just not sure why it wont view properly if all the data is there. Well I hope someone can help out with this, cause Id be the last one that will figure this out! :P this is starting to get over my head! Hell it already is! :shock: Thanks again Veovis!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 30th, 2006, 6:55 pm 
Offline

Joined: July 21st, 2006, 6:13 am
Posts: 558
Well after giving up on this because I couldnt understand some of the code, I decided to get back in there and give it a try. This is what I found...

Code:
stringtrimright,h,         h,16000


needs to be changed to

Code:
stringtrimleft,h,         h,16000


this solves the problem.

new code:
Code:
StringCaseSense On
Chars = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
gui, add, button, w100 gOpen,Open File
gui, add, text, x+10,var name:
gui, add, edit, x+10 w100 vName,File
gui, add, text, x+10,extract to:
gui, add, edit, x+10 w100 vwriteto,file.ext
gui, add, edit, r40 w510 vOutput xm
gui, show
return

Open:
gui, submit, nohide
fileselectFile,file
BinRead(file,data)
Bin2Hex(h,data,0)
output =
count = 0
;fileappend, %h% `n, abc.txt
loop,
{
   if not h
      break
   stringleft, peice%A_index%,h,16000
   stringtrimleft,h,h,16000
   output := output "`n" name "_peice" A_index " = " peice%A_index%
   count ++
}

output := output "`n`nWriteFile(""" writeto ""","""

loop, %count%
   output := output name "_peice" A_index "|"
stringtrimright,output,output,1
output := output """)   `n`n"
function =
(join`n
WriteFile(file,peices)
{
   global
   local Handle,data,hex
   Handle :=  DllCall("CreateFile","str",file,"Uint",0x40000000
                  ,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
   Loop,parse,peices,|
   {
     peice := `%A_loopfield`%
     data := data peice
   }
   Loop,
   {
      if strlen(data) = 0
        break
     StringLeft, Hex, data, 2
     StringTrimLeft, data, data, 2
     Hex = 0x`%hex`%
     DllCall("WriteFile","UInt", Handle,"UChar *", Hex
     ,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
   }
   DllCall("CloseHandle", "Uint", Handle)
   return
}
)
output := output function
guicontrol,,output,%output%
return

Bin2Hex(ByRef h, ByRef b, n=0)      ; n bytes binary data -> stream of 2-digit hex
{                                   ; n = 0: all (SetCapacity can be larger than used!)
   format = %A_FormatInteger%       ; save original integer format
   SetFormat Integer, Hex           ; for converting bytes to hex

   m := VarSetCapacity(b)
   If (n < 1 or n > m)
       n := m
   Address := &b
   h =
   Loop %n%
   {
      x := *Address                 ; get byte in hex
      StringTrimLeft x, x, 2        ; remove 0x
      x = 0%x%                      ; pad left
      StringRight x, x, 2           ; 2 hex digits
      h = %h%%x%
      Address++
   }
   SetFormat Integer, %format%      ; restore original format
}


BinRead(file, ByRef data, n=0, offset=0)
{
   h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0)
   IfEqual h,-1, SetEnv, ErrorLevel, -1
   IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file

   m = 0                            ; seek to offset
   IfLess offset,0, SetEnv,m,2
   r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m)
   IfEqual r,0, SetEnv, ErrorLevel, -3
   IfNotEqual ErrorLevel,0, {
      t = %ErrorLevel%              ; save ErrorLevel to be returned
      DllCall("CloseHandle", "Uint", h)
      ErrorLevel = %t%              ; return seek error
      Return 0
   }

   m := DllCall("GetFileSize","UInt",h,"Int64 *",r)
   If (n < 1 or n > m)
       n := m
   Granted := VarSetCapacity(data, n, 0)
   IfLess Granted,%n%, {
      ErrorLevel = Mem=%Granted%
      Return 0
   }

   result := DllCall("ReadFile","UInt",h,"Str",data,"UInt",n,"UInt *",Read,"UInt",0)

   if (!result or Read < n)
       t = -3
   IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel%

   h := DllCall("CloseHandle", "Uint", h)
   IfEqual h,-1, SetEnv, ErrorLevel, -2
   IfNotEqual t,,SetEnv, ErrorLevel, %t%-%ErrorLevel%

   Return Read
}
GuiClose:
ExitApp



Thanks for the code Veovis! Works great!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2006, 1:14 am 
Offline

Joined: February 13th, 2006, 10:40 pm
Posts: 389
Location: Utah
ROFL :shock: :shock: :shock: I cant beleive i did that

Terribly Sorry about that. Man that was really stupid. Thanks for catching that aCkRiTe. Thats the most embarrassing mistake i've made yet.

Take the left 16000 chars, and then destroy the last 16000 chars... :oops:

_________________
Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2006, 1:30 am 
Offline

Joined: July 21st, 2006, 6:13 am
Posts: 558
no worries at all.... you solved my problem! thanks. you said it yourself, it was late that night you were working on it. i guess i was just waiting on an answer from someone that i never got so it just made me get back in there myself to try and figure it out on my own which i should have done in the first place and put some effort into. :oops: like i said your code is pretty much over my head! :lol: as you can see in like line 20 of the code reposted; just some things i was trying to figure it out... :oops: :lol: im trying to become more proficient with ahk...
thanks again for your help Veovis! much appreciated!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2006, 9:11 am 
Offline

Joined: August 25th, 2006, 3:57 am
Posts: 127
Location: Iowa, USA
This stuff is really nifty! Pitty Im a total nubcake and can't do stuff like this :P I'm still having troubles with the simple stuffs, but this is really interesting.

I changed 2 lines in the script that had the Stop/Resume animation button on the gui to put the picture in the gui itself. I can see it being used for something like a translucent fog in a credits gui or other stuffs.

:D

_________________
83% Noob, 17% Coached...
Put on your smart face, that one is getting old and tired...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2006, 11:43 am 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
@Last posted Script (Converting File into useable code for scripts)
You should write "Piece" instead of "Peice" ;)

@Discussion about encoding and compression ...
After I few posts I fall out of context (it's hard to read unknown content in a unknown language (=english) *g*).

Maybe the first post could be updated to the last state of the art?
I am not shure which code-piece offered here would do what exactly...

Thalon

P.S.: The best solution would be: All are learning german and post there in the forum (I mentioned out that many of the most active posters are already able to speak german :) )

Thalon

_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2006, 2:58 am 
Offline

Joined: August 25th, 2006, 3:57 am
Posts: 127
Location: Iowa, USA
Ich hab gut deutsch, ich wis deutsch von UO DE/ENG shard :D

And asside from some other stuffs, thats about all I can say :P Infact my German is pretty poor, but atleast I can lie in german! :D

_________________
83% Noob, 17% Coached...
Put on your smart face, that one is getting old and tired...


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Modified code
PostPosted: April 4th, 2007, 4:36 am 
Offline

Joined: October 30th, 2006, 10:17 pm
Posts: 43
I modified the first code that breaks a file into hex:

Code:
gui, add, edit, w400 vFilename,
gui, add, button, w100 gOpen x+10,Open File
gui, add, edit, r40 w510 vOutput xm
gui, show
return

Open:
FileSelectFile, File, 3, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}, Selet Pic,
GuiControl,, Filename, %File%
gui, submit, nohide
BinRead(file,data)
Bin2Hex(h,data,res)
guicontrol,,output,%h%
return

Bin2Hex(ByRef h, ByRef b, n=0)      ; n bytes binary data -> stream of 2-digit hex
{                                   ; n = 0: all (SetCapacity can be larger than used!)
   format = %A_FormatInteger%       ; save original integer format
   SetFormat Integer, Hex           ; for converting bytes to hex

   m := VarSetCapacity(b)
   If (n < 1 or n > m)
       n := m
   Address := &b
   h =
   Loop %n%
   {
      x := *Address                 ; get byte in hex
      StringTrimLeft x, x, 2        ; remove 0x
      x = 0%x%                      ; pad left
      StringRight x, x, 2           ; 2 hex digits
      h = %h%%x%
      Address++
   }
   SetFormat Integer, %format%      ; restore original format
}

BinRead(file, ByRef data, n=0, offset=0)
{
   h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0)
   IfEqual h,-1, SetEnv, ErrorLevel, -1
   IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file

   m = 0                            ; seek to offset
   IfLess offset,0, SetEnv,m,2
   r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m)
   IfEqual r,0, SetEnv, ErrorLevel, -3
   IfNotEqual ErrorLevel,0, {
      t = %ErrorLevel%              ; save ErrorLevel to be returned
      DllCall("CloseHandle", "Uint", h)
      ErrorLevel = %t%              ; return seek error
      Return 0
   }

   m := DllCall("GetFileSize","UInt",h,"Int64 *",r)
   If (n < 1 or n > m)
       n := m
   Granted := VarSetCapacity(data, n, 0)
   IfLess Granted,%n%, {
      ErrorLevel = Mem=%Granted%
      Return 0
   }

   result := DllCall("ReadFile","UInt",h,"Str",data,"UInt",n,"UInt *",Read,"UInt",0)

   if (!result or Read < n)
       t = -3
   IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel%

   h := DllCall("CloseHandle", "Uint", h)
   IfEqual h,-1, SetEnv, ErrorLevel, -2
   IfNotEqual t,,SetEnv, ErrorLevel, %t%-%ErrorLevel%

   Return Read
}
return

GuiClose:
ExitApp



hope everybody likes this

I also realy like this Idea + cant you break up other file types like .mp3 or .exe and so on?

_________________
Tex© Click here to mail me


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 85 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: specter333, sumon, XX0 and 24 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group