about summary refs log tree commit diff
path: root/frida_mode/src/js/api.js
blob: 983f1efad8424610832d6e8926a1b1f42db64a1b (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const write = new NativeFunction(
    Module.getExportByName(null, 'write'),
    'int',
    ['int', 'pointer', 'int']
);

const afl_frida_trace = Process.findModuleByName('afl-frida-trace.so');

function get_api(name, ret, args) {
    const addr = afl_frida_trace.findExportByName(name);
    return new NativeFunction(addr, ret, args);
}

const js_api_done = get_api(
    'js_api_done',
    'void',
    []);

const js_api_error = get_api(
    'js_api_error',
    'void',
    ['pointer']);

const js_api_set_entrypoint = get_api(
    'js_api_set_entrypoint',
    'void',
    ['pointer']);

const js_api_set_persistent_address = get_api(
    'js_api_set_persistent_address',
    'void',
    ['pointer']);

const js_api_set_persistent_return = get_api(
    'js_api_set_persistent_return',
    'void',
    ['pointer']);

const js_api_set_persistent_count = get_api(
    'js_api_set_persistent_count',
    'void',
    ['uint64']);

const js_api_set_persistent_debug = get_api(
    'js_api_set_persistent_debug',
    'void',
    []);

const js_api_set_debug_maps = get_api(
    'js_api_set_debug_maps',
    'void',
    []);

const js_api_add_include_range = get_api(
    'js_api_add_include_range',
    'void',
    ['pointer', 'size_t']);

const js_api_add_exclude_range = get_api(
    'js_api_add_exclude_range',
    'void',
    ['pointer', 'size_t']);

const js_api_set_instrument_libraries = get_api(
    'js_api_set_instrument_libraries',
    'void',
    []);

const js_api_set_instrument_debug_file = get_api(
    'js_api_set_instrument_debug_file',
    'void',
    ['pointer']);

const js_api_set_prefetch_disable = get_api(
    'js_api_set_prefetch_disable',
    'void',
    []);

const js_api_set_instrument_no_optimize = get_api(
    'js_api_set_instrument_no_optimize',
    'void',
    []);

const js_api_set_instrument_trace = get_api(
    'js_api_set_instrument_trace',
    'void',
    []);

const js_api_set_instrument_trace_unique = get_api(
    'js_api_set_instrument_trace_unique',
    'void',
    []);

const js_api_set_stdout = get_api(
    'js_api_set_stdout',
    'void',
    ['pointer']);

const js_api_set_stderr = get_api(
    'js_api_set_stderr',
    'void',
    ['pointer']);

const js_api_set_stats_file = get_api(
    'js_api_set_stats_file',
    'void',
    ['pointer']);

const js_api_set_stats_interval = get_api(
    'js_api_set_stats_interval',
    'void',
    ['uint64']);

const js_api_set_stats_transitions = get_api(
    'js_api_set_stats_transitions',
    'void',
    []);

const afl = {
    print: function (msg) {
        const STDOUT_FILENO = 2;
        const log = `${msg}\n`;
        const buf = Memory.allocUtf8String(log);
        write(STDOUT_FILENO, buf, log.length);
    },
    done: function() {
        js_api_done();
    },
    error: function(msg) {
        const buf = Memory.allocUtf8String(msg);
        js_api_error(buf);
    },
    setEntryPoint: function(addr) {
        js_api_set_entrypoint(addr);
    },
    setPersistentAddress: function(addr) {
        js_api_set_persistent_address(addr);
    },
    setPersistentReturn: function(addr) {
        js_api_set_persistent_return(addr);
    },
    setPersistentCount: function(addr) {
        js_api_set_persistent_count(addr);
    },
    setPersistentDebug: function() {
        js_api_set_persistent_debug();
    },
    setDebugMaps: function() {
        js_api_set_debug_maps();
    },
    addIncludedRange: function(address, size) {
        js_api_add_include_range(address, size);
    },
    addExcludedRange: function(address, size) {
        js_api_add_exclude_range(address, size);
    },
    setInstrumentLibraries: function() {
        js_api_set_instrument_libraries();
    },
    setInstrumentDebugFile: function(file) {
        const buf = Memory.allocUtf8String(file);
        js_api_set_instrument_debug_file(buf)
    },
    setPrefetchDisable: function() {
        js_api_set_prefetch_disable();
    },
    setInstrumentNoOptimize: function() {
        js_api_set_instrument_no_optimize();
    },
    setInstrumentEnableTracing: function() {
        js_api_set_instrument_trace();
    },
    setInstrumentTracingUnique: function() {
        js_api_set_instrument_trace_unique();
    },
    setStdOut: function(file) {
        const buf = Memory.allocUtf8String(file);
        js_api_set_stdout(buf)
    },
    setStdErr: function(file) {
        const buf = Memory.allocUtf8String(file);
        js_api_set_stderr(buf)
    },
    setStatsFile: function(file) {
        const buf = Memory.allocUtf8String(file);
        js_api_set_stats_file(buf)
    },
    setStatsInterval: function(interval) {
        js_api_set_stats_interval(interval);
    },
    setStatsTransitions: function() {
        js_api_set_stats_transitions();
    }

};

Object.defineProperty(global, 'Afl', {value: afl, writeable: false});

////////////////////////////////////////////////////////////////////////////////
//                          END OF API                                        //
////////////////////////////////////////////////////////////////////////////////