Skip to content

Instantly share code, notes, and snippets.

@ferd
Created July 12, 2013 19:05
Show Gist options
  • Save ferd/5986905 to your computer and use it in GitHub Desktop.
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.
%% 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