This repository has been archived by the owner on Sep 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testarmdisasm.c
executable file
·64 lines (52 loc) · 1.69 KB
/
testarmdisasm.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <bfd.h> //is also done in dis-asm.h
#include <dis-asm.h>
int
my_fprintf(void* stream, const char * format, ...)
{
va_list arg;
va_start(arg,format);
vfprintf(stdout, format, arg);
return 0;
}
int
main ()
{
unsigned int data[3] = {0xE3A01080,
0xE2810001,
0xE1A01001};
bfd_byte* buf = (bfd_byte*) &data[0];
disassemble_info* c = (struct disassemble_info*) calloc(1, sizeof(disassemble_info));
// void init_disassemble_info (struct disassemble_info *dinfo, void *stream, fprintf_ftype fprintf_func)
init_disassemble_info ( c, stdout, my_fprintf);
//c->application_data
//c->memory_error_func
// set architecture
c->arch = bfd_arch_arm;
// set the specific machine: unknown allows all instructions in the libraries database
c->mach = bfd_mach_arm_unknown;
// should set the disassembler field of c to the right function
disassemble_init_for_target( c );
// given a bfd, the disassembler can find the arch by itself.
//disassemble = disassembler( c );
c->buffer_vma = 0;
c->buffer = buf;
c->buffer_length = 12;
// while-loop for calling single instruction decoding:
unsigned int count = 0;
size_t pos = 0;
size_t length = c->buffer_length;
size_t max_pos = c->buffer_vma+length;
while(pos < max_pos)
{
//disassembler-function: print_insn_big_arm
//other possible functions are listed in opcodes/dissassemble.c
unsigned int size = print_insn_little_arm((bfd_vma) pos, c);
pos += size;
count++;
fprintf(stdout, "\n");
}
return 0;
}