 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Laszlo
Joined: 14 Feb 2005 Posts: 4517 Location: Boulder, CO
|
Posted: Mon Jul 17, 2006 7:52 pm Post subject: |
|
|
| If someone is stil interested in direct conversion between hex and base64, I updated the script. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2446
|
Posted: Wed Jul 19, 2006 12:03 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 552
|
Posted: Sat Aug 26, 2006 7:17 pm Post subject: |
|
|
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...
keep in mind im not an expert with AHK..
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!
can someone please help me with this. thanks... |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 841 Location: Berlin
|
Posted: Sun Aug 27, 2006 12:50 am Post subject: |
|
|
Why is this garbled? _________________
My AHK stuff on ahk.net / on DropBox (mirror) / @home (if online) |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Sun Aug 27, 2006 1:31 am Post subject: |
|
|
@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 |
_________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
SoggyDog
Joined: 02 May 2006 Posts: 626 Location: Greeley, CO
|
Posted: Sun Aug 27, 2006 6:23 am Post subject: |
|
|
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. _________________
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played." |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Sun Aug 27, 2006 8:43 am Post subject: |
|
|
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
} |
_________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 552
|
Posted: Mon Aug 28, 2006 2:17 am Post subject: |
|
|
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! this is starting to get over my head! Hell it already is! Thanks again Veovis! |
|
| Back to top |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 552
|
Posted: Wed Aug 30, 2006 6:55 pm Post subject: |
|
|
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! |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Thu Aug 31, 2006 1:14 am Post subject: |
|
|
ROFL 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...  _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 552
|
Posted: Thu Aug 31, 2006 1:30 am Post subject: |
|
|
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. like i said your code is pretty much over my head! as you can see in like line 20 of the code reposted; just some things i was trying to figure it out... im trying to become more proficient with ahk...
thanks again for your help Veovis! much appreciated! |
|
| Back to top |
|
 |
Calimaw
Joined: 25 Aug 2006 Posts: 127 Location: Iowa, USA
|
Posted: Thu Aug 31, 2006 9:11 am Post subject: |
|
|
This stuff is really nifty! Pitty Im a total nubcake and can't do stuff like this 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.
 _________________ 83% Noob, 17% Coached...
Put on your smart face, that one is getting old and tired... |
|
| Back to top |
|
 |
Thalon
Joined: 12 Jul 2005 Posts: 632
|
Posted: Thu Aug 31, 2006 11:43 am Post subject: |
|
|
@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 |
|
| Back to top |
|
 |
Calimaw
Joined: 25 Aug 2006 Posts: 127 Location: Iowa, USA
|
Posted: Fri Sep 01, 2006 2:58 am Post subject: |
|
|
Ich hab gut deutsch, ich wis deutsch von UO DE/ENG shard
And asside from some other stuffs, thats about all I can say Infact my German is pretty poor, but atleast I can lie in german!  _________________ 83% Noob, 17% Coached...
Put on your smart face, that one is getting old and tired... |
|
| Back to top |
|
 |
Justineo14
Joined: 30 Oct 2006 Posts: 43
|
Posted: Wed Apr 04, 2007 4:36 am Post subject: Modified code |
|
|
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 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|