local ffi=require 'ffi' local C=ffi.C ffi.cdef[[ typedef struct { int a; } FILE; int fread(void*,size_t,size_t,FILE*); int fwrite(const void*,size_t,size_t,FILE*); ]] Macro { description=""; area="Shell"; key="CtrlShift3"; flags="NoPluginPanels NoFolders"; action=function() --local t1=Far.UpTime local f_in=assert(io.open(APanel.Path.."\\"..APanel.Current, "rb")) local f_out=assert(io.open(APanel.Path.."\\"..APanel.Current..".hex", "wb")) local h_in, h_out = f_in:rawhandle(), f_out:rawhandle() local ibuf=ffi.new("unsigned char[?]",0x10000) local obuf=ffi.new("unsigned char[?]",0x20000) while true do local n = C.fread(ibuf, 1, ffi.sizeof(ibuf), h_in) if n == 0 then break end for i=0,n-1 do local low = bit.band(ibuf[i],0xf) local high = bit.rshift(ibuf[i],4) obuf[i+i] = high<10 and high+48 or high+55 obuf[i+i+1] = low<10 and low+48 or low+55 end C.fwrite(obuf, 1, n+n, h_out) end f_out:close() f_in:close() panel.UpdatePanel(nil,1) panel.RedrawPanel(nil,1) --far.Message(Far.UpTime-t1) end; } |