1 /*
2  * Copyright 2016, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <stdint.h>
18 #include <stdio.h>
19 
20 #include "disassembler.h"
21 
22 // Disassembles an APF program. A hex dump of the program is supplied on stdin.
23 //
24 // NOTE: This is a simple debugging tool not meant for shipping or production use.  It is by no
25 //       means hardened against malicious input and contains known vulnerabilities.
26 //
27 // Example usage:
28 // adb shell dumpsys wifi ipmanager | sed '/Last program:/,+1!d;/Last program:/d;s/[ ]*//' | out/host/linux-x86/bin/apf_disassembler
main(void)29 int main(void) {
30   uint32_t program_len = 0;
31   uint8_t program[10000];
32 
33   // Read in hex program bytes
34   int byte;
35   while (scanf("%2x", &byte) == 1 && program_len < sizeof(program)) {
36       program[program_len++] = byte;
37   }
38 
39   for (uint32_t pc = 0; pc < program_len;) {
40       pc = apf_disassemble(program, program_len, pc);
41   }
42 }
43