rlm@1: /* Bra.h -- Branch converters for executables rlm@1: 2008-10-04 : Igor Pavlov : Public domain */ rlm@1: rlm@1: #ifndef __BRA_H rlm@1: #define __BRA_H rlm@1: rlm@1: #include "Types.h" rlm@1: rlm@1: /* rlm@1: These functions convert relative addresses to absolute addresses rlm@1: in CALL instructions to increase the compression ratio. rlm@1: rlm@1: In: rlm@1: data - data buffer rlm@1: size - size of data rlm@1: ip - current virtual Instruction Pinter (IP) value rlm@1: state - state variable for x86 converter rlm@1: encoding - 0 (for decoding), 1 (for encoding) rlm@1: rlm@1: Out: rlm@1: state - state variable for x86 converter rlm@1: rlm@1: Returns: rlm@1: The number of processed bytes. If you call these functions with multiple calls, rlm@1: you must start next call with first byte after block of processed bytes. rlm@1: rlm@1: Type Endian Alignment LookAhead rlm@1: rlm@1: x86 little 1 4 rlm@1: ARMT little 2 2 rlm@1: ARM little 4 0 rlm@1: PPC big 4 0 rlm@1: SPARC big 4 0 rlm@1: IA64 little 16 0 rlm@1: rlm@1: size must be >= Alignment + LookAhead, if it's not last block. rlm@1: If (size < Alignment + LookAhead), converter returns 0. rlm@1: rlm@1: Example: rlm@1: rlm@1: UInt32 ip = 0; rlm@1: for () rlm@1: { rlm@1: ; size must be >= Alignment + LookAhead, if it's not last block rlm@1: SizeT processed = Convert(data, size, ip, 1); rlm@1: data += processed; rlm@1: size -= processed; rlm@1: ip += processed; rlm@1: } rlm@1: */ rlm@1: rlm@1: #define x86_Convert_Init(state) { state = 0; } rlm@1: SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); rlm@1: SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); rlm@1: SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); rlm@1: SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); rlm@1: SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); rlm@1: SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); rlm@1: rlm@1: #endif