~ubuntu-branches/ubuntu/maverick/radare/maverick

« back to all changes in this revision

Viewing changes to src/arch/8051/code.c

  • Committer: Bazaar Package Importer
  • Author(s): SevenMachines
  • Date: 2010-09-07 15:44:27 UTC
  • mfrom: (1.1.3 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100907154427-37u92vu12tqabqqz
Tags: 1:1.5.2-3ubuntu1
* Merge from debian testing (LP: #621016)
* debian/control:
     + libvala-dev transition to libval-0.10-dev (LP: #618809) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009
 
3
 *       pancake <nopcode.org>
 
4
 *
 
5
 * radare is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * radare is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with radare; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 *
 
19
 */
 
20
 
 
21
/* code analysis functions */
 
22
 
 
23
#include "../../code.h"
 
24
#include <stdio.h>
 
25
#include <string.h>
 
26
#include <assert.h>
 
27
 
 
28
int arch_8051_aop(ut64 addr, const ut8 *bytes, struct aop_t *aop)
 
29
{
 
30
        int ptr = 0;
 
31
        int ilen, i;
 
32
        int type;
 
33
        char str[128];
 
34
//      assert(bytes);
 
35
 
 
36
        if (aop == NULL)
 
37
                return -1;
 
38
 
 
39
        memset (aop, '\0', sizeof (struct aop_t));
 
40
        aop->type = AOP_TYPE_UNK;
 
41
 
 
42
        ptr = dis51_inst1 (bytes, 0, &type);
 
43
        if ((ptr == -1)&&(bytes[0]!=0x73)&&((bytes[0] & 0xef)!=0x22)) {
 
44
                eprintf ("Invalid instruction %02x %02x\n",
 
45
                        bytes[0], bytes[1]);
 
46
                aop->type = AOP_TYPE_TRAP;
 
47
                return 1; // skip instruction..
 
48
        }
 
49
        ilen = dis51_inst2 (str, bytes, 0);
 
50
 
 
51
        switch (type) {
 
52
        case 'j':
 
53
                aop->type = AOP_TYPE_JMP;
 
54
                aop->jump = ilen + addr + ptr;
 
55
                aop->eob = 1;
 
56
                break;
 
57
        case 'c':
 
58
                aop->type = AOP_TYPE_CALL;
 
59
                aop->jump = ptr;
 
60
                break;
 
61
        case 'b':
 
62
                aop->type = AOP_TYPE_CJMP;
 
63
                aop->jump = ilen + addr + ptr;
 
64
                aop->fail = ilen + addr;
 
65
                aop->eob = 1;
 
66
                break;
 
67
        }
 
68
        aop->length = ilen;
 
69
        aop->ref = 0;
 
70
 
 
71
        return ilen;
 
72
}
 
73
 
 
74
int dis51_udis (char *str, const ut8 *bytes, int len, ut64 seek) {
 
75
        int ptr, type;
 
76
 
 
77
        // TODO: add += seek somewhere :)
 
78
        ptr = dis51_inst1 (bytes, 0, &type);
 
79
        if (ptr == -1) {
 
80
                sprintf (str, "(invalid instruction)");
 
81
                return -1;
 
82
        }
 
83
        return dis51_inst2 (str, bytes, 0);
 
84
}