AutoHotkey Community

It is currently May 27th, 2012, 1:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: hexdump to file
PostPosted: June 2nd, 2008, 4:11 pm 
Offline

Joined: June 2nd, 2008, 4:01 pm
Posts: 16
i have an old hexdump from a file that i want to create back (about 3Kb)

Code:
FFD8FFE000104A46494600010100000100010000FFDB00430003020203................


i tried to put them in pairs of 2 characters and use numput but i cannot get it to a saved file Numput( %A%,testbin,counter) but i do not find a way to save the testbin variable in a file

can anyone give advice?

thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2008, 10:01 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
what is your expected output?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2008, 9:38 am 
Offline

Joined: June 2nd, 2008, 4:01 pm
Posts: 16
it is a jpg ,an avatar that is send by mail instead of attachment

i found this forum topic but the link to the getbyte is dead

http://www.autohotkey.com/forum/topic3229.html

i wonder why when it seems so simple in c++ it is not implemented in ahk
or am i missing something (i cannot program so maybe it only looks simple.......)javascript:emoticon(':(')

if anyone still has the getbyte and putbyte mentioned in the forum post please leave a note


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2008, 10:14 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Here is a template on how you could do it :

Code:
hex=
( join
424D3E000000000000003600000028000000010000000200000001001800000000000800000000000000000000
000000000000000000C0FFFF00FF404000
)

nSize := StrLen( hex ) // 2
Hex2Bin( BMP, hex )           ; Convert Hex to Binary Byte Array

; Create a file and Write the Byte Array to it

FileIO16_Init()
hFile := FCreate( "twopixel.bmp", F_NORMAL )
FWrite( hFile, &BMP, nSize )
FClose( hFile )

; lets test the created file

Gui, Margin,0,0
Gui, Add, Picture, w640 h480, twopixel.bmp ; stretch bitmap to create gradient
Gui, Show
Return

Hex2Bin(ByRef bin, hex) { ; Hex2Bin(fun,"8B4C24") = MCode(fun,"8B4C24")
   ; Laszlo : http://www.autohotkey.com/forum/viewtopic.php?p=180469#180469
   Static fun
   If (fun = "") {
      h:="568b74240c8a164684d2743b578b7c240c538ac2c0e806b109f6e98ac802cac0e104880f8"
       . "a164684d2741a8ac2c0e806b309f6eb80e20f02c20ac188078a16474684d275cd5b5f5ec3"
      VarSetCapacity(fun,StrLen(h)//2)
      Loop % StrLen(h)//2
         NumPut("0x" . SubStr(h,2*A_Index-1,2), fun, A_Index-1, "Char")
   }
   VarSetCapacity(bin,StrLen(hex)//2)
   dllcall(&fun, "uint",&bin, "Str",hex, "cdecl")
}

#Include FileIO16.ahk ; http://www.autohotkey.net/~Skan/wrapper/FileIO16/FileIO16.ahk


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2008, 1:51 pm 
Offline

Joined: June 2nd, 2008, 4:01 pm
Posts: 16
thanks Skan

it will take me some time to unravel how it works but it looks good javascript:emoticon(':D')

will let you know the result


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2008, 1:53 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
do not forget tp download the include file: FileIO16.ahk :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2008, 6:11 pm 
Offline

Joined: June 2nd, 2008, 4:01 pm
Posts: 16
thanks Skan it worked well javascript:emoticon(':D')


it took some time to unravel your programs but it was worth it!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2010, 10:36 pm 
Hi SKAN,

Since I didn't find a post where you posted the File16IO.ahk directly, I'll post here. I used your FileReadEx function quite a lot. But it has one drawback: It can't read from the end of a file with an offset. So I modified it a little.
Code:
FileReadEx2( F,ByRef V,B,O=0 )  {  ;B= Number of bytes, O = Offset, when negative from EOF   
 by:= (O<0 ? B+1 : B), VarSetCapacity(V,By,0), H:=DllCall("_lopen",Str,F,UInt,0)
 IfLess,H,1, Return,-1
 DllCall( "_llseek",UInt,H,UInt,O, UInt,(O < 0 ? 2 : 0) )
 Return DllCall("_lread",UInt,H,Str,V,UInt,by) ( DllCall("_lclose",UInt,H)+n )     
}


The only drawback is now, that in case 128 bytes from EOF should be read, it will be this
Code:
FileReadEx2( File,Var,128,-128 )


Ciao
toralf


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Amandaville, Bing [Bot], BrandonHotkey, chaosad, Yahoo [Bot] and 22 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:
Powered by phpBB® Forum Software © phpBB Group