Created
July 12, 2013 19:05
-
-
Save ferd/5986905 to your computer and use it in GitHub Desktop.
Convert a crash dump Refc binary back to a regular binary. Uses the erl_eval module to evaluate the 16#... hex conversion much faster than naive string handling would do it in this little space.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Convert a crashdump binary back into a regular binary | |
%% Crash dump binary: | |
%% =binary:CFE75808 % <- reference to refc binary | |
%% CA:2A31300D0A24350D0A484D5345540D0... % <- actual binary | |
CDumpBin = fun(Str) -> | |
[Len,Num] = string:tokens(Str, ":"), | |
Src= lists:flatten(["<<16#",Num,":(16#",Len,"*8)>>."]), | |
{ok, Tokens, _}=erl_scan:string(Src), | |
{ok, [Form]} = erl_parse:parse_exprs(Tokens), | |
{value, Val, _} = erl_eval:expr(Form, erl_eval:new_bindings()), | |
Val | |
end. | |
%% 1> CDumpBin("CA:2A31300D0A24350D0A484D5345540D0A..."). | |
%% <<"*10\r\n$5\r\nHMSET\r\n$16\r\ndrain:661...">> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment