1/* Bra.h -- Branch converters for executables
22009-02-07 : Igor Pavlov : Public domain */
3
4#ifndef __BRA_H
5#define __BRA_H
6
7#include "Types.h"
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13/*
14These functions convert relative addresses to absolute addresses
15in CALL instructions to increase the compression ratio.
16
17  In:
18    data     - data buffer
19    size     - size of data
20    ip       - current virtual Instruction Pinter (IP) value
21    state    - state variable for x86 converter
22    encoding - 0 (for decoding), 1 (for encoding)
23
24  Out:
25    state    - state variable for x86 converter
26
27  Returns:
28    The number of processed bytes. If you call these functions with multiple calls,
29    you must start next call with first byte after block of processed bytes.
30
31  Type   Endian  Alignment  LookAhead
32
33  x86    little      1          4
34  ARMT   little      2          2
35  ARM    little      4          0
36  PPC     big        4          0
37  SPARC   big        4          0
38  IA64   little     16          0
39
40  size must be >= Alignment + LookAhead, if it's not last block.
41  If (size < Alignment + LookAhead), converter returns 0.
42
43  Example:
44
45    UInt32 ip = 0;
46    for ()
47    {
48      ; size must be >= Alignment + LookAhead, if it's not last block
49      SizeT processed = Convert(data, size, ip, 1);
50      data += processed;
51      size -= processed;
52      ip += processed;
53    }
54*/
55
56#define x86_Convert_Init(state) { state = 0; }
57SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
58SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
59SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
60SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
61SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
62SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
63
64#ifdef __cplusplus
65}
66#endif
67
68#endif
69