Paul Jensen | 497d4ee | 2016-05-09 10:47:56 -0400 | [diff] [blame] | 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 | |
Lorenzo Colitti | 983eb51 | 2019-09-26 22:14:16 +0900 | [diff] [blame] | 20 | #include "disassembler.h" |
Lorenzo Colitti | 1017073 | 2016-05-19 23:58:25 +0900 | [diff] [blame] | 21 | |
Paul Jensen | 497d4ee | 2016-05-09 10:47:56 -0400 | [diff] [blame] | 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: |
Lorenzo Colitti | 1017073 | 2016-05-19 23:58:25 +0900 | [diff] [blame] | 28 | // adb shell dumpsys wifi ipmanager | sed '/Last program:/,+1!d;/Last program:/d;s/[ ]*//' | out/host/linux-x86/bin/apf_disassembler |
| 29 | int main(void) { |
Paul Jensen | 497d4ee | 2016-05-09 10:47:56 -0400 | [diff] [blame] | 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 | |
Lorenzo Colitti | 1017073 | 2016-05-19 23:58:25 +0900 | [diff] [blame] | 39 | for (uint32_t pc = 0; pc < program_len;) { |
Lorenzo Colitti | 983eb51 | 2019-09-26 22:14:16 +0900 | [diff] [blame] | 40 | pc = apf_disassemble(program, program_len, pc); |
Paul Jensen | 497d4ee | 2016-05-09 10:47:56 -0400 | [diff] [blame] | 41 | } |
Paul Jensen | 497d4ee | 2016-05-09 10:47:56 -0400 | [diff] [blame] | 42 | } |