File: insn-test.c

package info (click to toggle)
libdisasm 0.23-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,648 kB
  • sloc: sh: 9,096; ansic: 7,970; perl: 1,915; asm: 694; makefile: 133; ruby: 3
file content (43 lines) | stat: -rw-r--r-- 1,046 bytes parent folder | download | duplicates (5)
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
#include <string.h>
#include <stdio.h>
#include <libdis.h>

int main() {
    x86_insn_t insn;
    int size;
    //unsigned char bytes[] = { 0xff, 0x25, 0xed, 0xc0, 0xad, 0xde };
    //unsigned char bytes[] = { 0x0f,0x0f,0xc8,0x1d };
    unsigned char bytes[] = { 0x0f,0x38 };
    char buf[1024];
  
    printf("init...\n");
    x86_init(opt_none, 0, 0);
  
    printf("disasm...\n");
    size = x86_disasm(bytes, sizeof(bytes), 0, 0, &insn);
    if (size != sizeof(bytes)) {
        printf("Eek: disasm %d bytes when given %d bytes\n", size, sizeof(bytes));
    }

    if (size) {
        if (insn.type == insn_invalid) {
            printf("Eek: got insn_invalid with size>0 (%d)!\n",size);
        }
        else {
            x86_format_insn(&insn, buf, 1024, att_syntax);
            printf("Got(%d): %s\n",size,buf);
        }
    }
    else {
        printf("Invalid instruction\n");
    }
  
    printf("free...\n");
    x86_oplist_free(&insn);
  
    printf("cleanup...\n");
    x86_cleanup();
  
    printf("done...\n");
    return 0;
}