Class: Omnizip::Filters::BcjIa64

Inherits:
Omnizip::Filter show all
Defined in:
lib/omnizip/filters/bcj_ia64.rb

Overview

BCJ filter for IA-64 (Itanium) executables.

This filter preprocesses Itanium machine code by converting relative addresses in branch instructions. IA-64 uses a complex VLIW (Very Long Instruction Word) architecture with 16-byte instruction bundles containing 3 instructions plus a template.

The filter improves compression by making branch targets position-independent.

Constant Summary collapse

BUNDLE_SIZE =

Size of IA-64 instruction bundle (16 bytes, little-endian)

16
TEMPLATE_MASKS =

Template lookup table for instruction slot positions Each bit pattern indicates which slots may contain branch instr

0x334B0000

Instance Attribute Summary

Attributes inherited from Omnizip::Filter

#architecture, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Omnizip::Filter

#id_for_format, #initialize

Constructor Details

This class inherits a constructor from Omnizip::Filter

Class Method Details

.metadataHash

Get metadata about this filter.

Returns:

  • (Hash)

    Filter metadata



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/omnizip/filters/bcj_ia64.rb', line 106

def 
  {
    name: "BCJ-IA64",
    description: "Branch converter for IA-64 (Itanium) " \
                 "executables",
    architecture: "IA-64 / Itanium",
    alignment: 16,
    endian: "little",
    complexity: "high",
  }
end

Instance Method Details

#decode(data, position = 0) ⇒ String

Decode (postprocess) IA-64 executable data after decompression.

Reverses the encoding by converting absolute addresses back to relative addresses.

Parameters:

  • data (String)

    Binary executable data

  • position (Integer) (defaults to: 0)

    Current stream position

Returns:

  • (String)

    Decoded binary data



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/omnizip/filters/bcj_ia64.rb', line 78

def decode(data, position = 0)
  return data.dup if data.bytesize < BUNDLE_SIZE

  result = data.b
  size = data.bytesize & ~(BUNDLE_SIZE - 1)
  i = 0
  pc = (position >> 4) << 1

  while i < size
    # Check template byte for slots with potential branches
    template = result.getbyte(i) & 0x1E
    mask = (TEMPLATE_MASKS >> template) & 3
    pc += 2

    i += BUNDLE_SIZE
    next if mask.zero?

    # Process each marked slot
    process_bundle_slots(result, i - BUNDLE_SIZE, mask, pc, false)
  end

  result
end

#encode(data, position = 0) ⇒ String

Encode (preprocess) IA-64 executable data for compression.

Scans 16-byte instruction bundles for branch instructions and converts relative addresses to absolute addresses.

Parameters:

  • data (String)

    Binary executable data

  • position (Integer) (defaults to: 0)

    Current stream position

Returns:

  • (String)

    Encoded binary data



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/omnizip/filters/bcj_ia64.rb', line 46

def encode(data, position = 0)
  return data.dup if data.bytesize < BUNDLE_SIZE

  result = data.b
  size = data.bytesize & ~(BUNDLE_SIZE - 1)
  i = 0
  pc = (position >> 4) << 1

  while i < size
    # Check template byte for slots with potential branches
    template = result.getbyte(i) & 0x1E
    mask = (TEMPLATE_MASKS >> template) & 3
    pc += 2

    i += BUNDLE_SIZE
    next if mask.zero?

    # Process each marked slot
    process_bundle_slots(result, i - BUNDLE_SIZE, mask, pc, true)
  end

  result
end