blob: a7401f397aeb5c510ccc7cf12ddde288cfcede35 [file] [log] [blame]
Paul Jensen497d4ee2016-05-09 10:47:56 -04001/*
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 Colitti983eb512019-09-26 22:14:16 +090020#include "disassembler.h"
Lorenzo Colitti10170732016-05-19 23:58:25 +090021
Paul Jensen497d4ee2016-05-09 10:47:56 -040022// 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 Colitti10170732016-05-19 23:58:25 +090028// adb shell dumpsys wifi ipmanager | sed '/Last program:/,+1!d;/Last program:/d;s/[ ]*//' | out/host/linux-x86/bin/apf_disassembler
29int main(void) {
Paul Jensen497d4ee2016-05-09 10:47:56 -040030 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 Colitti10170732016-05-19 23:58:25 +090039 for (uint32_t pc = 0; pc < program_len;) {
Lorenzo Colitti983eb512019-09-26 22:14:16 +090040 pc = apf_disassemble(program, program_len, pc);
Paul Jensen497d4ee2016-05-09 10:47:56 -040041 }
Paul Jensen497d4ee2016-05-09 10:47:56 -040042}