]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/lualibs/utils.lua
CHG: a message..
[proxmark3-svn] / client / lualibs / utils.lua
index 39f8bca2041b3a7509496868403a2950672de565..9dcb49c7b53abbbf35785089d2de71b6a4dadffa 100644 (file)
@@ -53,6 +53,34 @@ local Utils =
                return hex\r
        end,\r
        \r
+       ------------ FILE WRITING (EML)\r
+       --- Writes an eml-file.\r
+       -- @param uid - the uid of the tag. Used in filename\r
+       -- @param blockData. Assumed to be on the format {'\0\1\2\3,'\b\e\e\f' ..., \r
+       -- that is, blockData[row] contains a string with the actual data, not ascii hex representation \r
+       -- return filename if all went well, \r
+       -- @reurn nil, error message if unsuccessfulls  \r
+       WriteDumpFile = function(uid, blockData)\r
+               local destination = string.format("%s.eml", uid)\r
+               local file = io.open(destination, "w")\r
+               if file == nil then \r
+                       return nil, string.format("Could not write to file %s", destination)\r
+               end\r
+               local rowlen = string.len(blockData[1])\r
+\r
+               for i,block in ipairs(blockData) do\r
+                       if rowlen ~= string.len(block) then\r
+                               prlog(string.format("WARNING: Dumpdata seems corrupted, line %d was not the same length as line 1",i))\r
+                       end\r
+\r
+                       local formatString = string.format("H%d", string.len(block))\r
+                       local _,hex = bin.unpack(formatString,block)\r
+                       file:write(hex.."\n")\r
+               end\r
+               file:close()    \r
+               return destination\r
+       end,\r
+       \r
        ------------ string split function\r
        Split = function( inSplitPattern, outResults )\r
                if not outResults then\r
@@ -262,7 +290,14 @@ local Utils =
                if #s == 0 then return '' end\r
                local t={}\r
                for k in s:gmatch"(%x%x)" do\r
-                       table.insert(t, string.char(tonumber(k,16)))\r
+                       local n = tonumber(k,16)\r
+                       local c \r
+                       if  (n < 32) or (n == 127) then\r
+                               c = '.';\r
+                       else\r
+                               c = string.char(n)\r
+                       end\r
+                       table.insert(t,c)\r
                end\r
                return table.concat(t)  \r
        end,\r
Impressum, Datenschutz