-
Notifications
You must be signed in to change notification settings - Fork 9
/
exec_as_gen.erl
40 lines (38 loc) · 1.7 KB
/
exec_as_gen.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
%% @copyright Geoff Cant 2010
%% @author Geoff Cant <[email protected]>
%% @doc Erlang shell code to cause a gen* process to evaluate a fun.
%%
%% @license This code was translated from an ancient tome in the
%% Arkham university library (restricted section, 4th vault). As such,
%% use of this code is restricted to only those who see it as the
%% manifestly evil. Using this code under any circumstances other than in
%% dire need while debugging revokes your right to use, view, posess
%% said code.
%% @end
f(EvalAs).
EvalAs = fun (Pid, Fun) when is_function(Fun, 0) ->
Invocation = <<"Ph'nglui mglw'nafh "
"Cthulhu R'lyeh wgah'nagl fhtan">>,
TerrifyingResponse = <<"Ia! Ia! Cthulhu fhtagn">>,
Ref = make_ref(),
Caller = self(),
F = fun (nostate, {in, {hack,
Invo,
Ref}}, ProcState)
when Invo =:= Invocation ->
Caller ! {hack, TerrifyingResponse, Ref,
catch Fun()},
done
end,
sys:install(Pid, {F,nostate}),
Pid ! {hack, Invocation, Ref},
receive
{hack, TerrifyingResponse, Ref, Result} ->
{TerrifyingResponse, Result}
after timer:seconds(5) ->
timeout
end
end.
%% Eldrich Example -- Erich Zann's 'Secrets Best Forgotten (vol 1)'
EvalAs(application_controller,
fun () -> io:format("Muahahaha, I am ~p!~n", [self()]) end).