Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created October 18, 2013 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmplinshi/7035871 to your computer and use it in GitHub Desktop.
Save tmplinshi/7035871 to your computer and use it in GitHub Desktop.
; FiletoHex.ahk
#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
ListLines Off
; StringSlice() for FiletoHex - www.autohotkey.com/forum/viewtopic.php?t=8728
; by SKAN Suresh Kumar A N, arian.suresh@gmailcom | CD: 10-Oct-2010 / LM: 10-Oct-2010
File = %1%
IfNotExist, %File%, Return
FileGetSize, dataSz , %File%
If ( dataSz < 1 || dataSz > 32400 ) ; adjust to your needs
Return
FileRead, Bin, *c %File% ; Thanks HotkeyIt, www.autohotkey.com/forum/viewtopic.php?t=62700
BinToHex( &Bin, dataSz, Hex ), spos := 1
;The following is compatibility code for AHK_L and maybe removed if not required
If ( A_IsUnicode ) {
VarSetCapacity( TmpD, Len := (dataSz*4) + 2 )
DllCall( "MultiByteToWideChar", Int,0,Int,0, Str,Hex,UInt,Len//2, Str,TmpD,UInt,Len )
Hex := TmpD, VarSetcapacity( TmpD, 0 )
}
While ( ( Line := StringSlice( Hex, spos, 88, spos ) ) <> "" )
Text .= Line ( Mod(A_Index,180) ? "`n" : "`n`n" )
Clipboard := Text
MsgBox,, Done!, Data copied to clipboard.
Return ; // end of auto-execute section //
BinToHex(Addr, Len, ByRef Hex) { ; Machine code function by Laszlo Hars
Static Fun ; C Source/Author Notes: www.autohotkey.com/forum/viewtopic.php?p=135559#135559
Fun ? False : VarSetCapacity( Fun,68 ), NumPut( 0x000000c3, NumPut( 0x5f0001c6
, NumPut( 0x5ed7754f, NumPut( 0x41018846, NumPut( 0x410441c2, NumPut( 0x2a05eac0
, NumPut( 0xd08a0a2c, NumPut( 0x0f24068a, NumPut( 0x01884104, NumPut( 0xc22a05ea
, NumPut( 0xc0d08a0a, NumPut( 0x2c04e8c0, NumPut( 0x068a1024, NumPut( 0x748b562f
, NumPut( 0x7eff8510, NumPut( 0x247c8b57, NumPut( 0x04244c8b,Fun )))))))))))))))))
VarSetCapacity( Hex,64), VarSetCapacity( Hex,0 ), VarSetCapacity( Hex, 2*Len+1,32 )
Return !! DllCall( &Fun, UInt,&Hex, UInt,Addr, UInt,Len, "CDecl" )
}
StringSlice( byref str, spos=1, len=90, byref n="" ) {
Return substr( str, spos, (n:=spos+len)-spos )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment