| 1 | # Copyright 2011, 2012, 2013, 2014, 2017 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of X11-Protocol-Other. | ||
| 4 | # | ||
| 5 | # X11-Protocol-Other is free software; you can redistribute it and/or | ||
| 6 | # modify it under the terms of the GNU General Public License as published | ||
| 7 | # by the Free Software Foundation; either version 3, or (at your option) any | ||
| 8 | # later version. | ||
| 9 | # | ||
| 10 | # X11-Protocol-Other 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 GNU General | ||
| 13 | # Public License for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU General Public License along | ||
| 16 | # with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | |||
| 19 | # /usr/share/doc/x11proto-xext-dev/tog-cup.txt.gz | ||
| 20 | # | ||
| 21 | # /usr/include/X11/extensions/cup.h | ||
| 22 | # /usr/include/X11/extensions/cupproto.h | ||
| 23 | # | ||
| 24 | # /usr/include/X11/extensions/Xcup.h | ||
| 25 | # Xlib. | ||
| 26 | # XcupGetReservedColormapEntries() etc | ||
| 27 | # | ||
| 28 | # http://www.xfree86.org/current/specindex.html | ||
| 29 | # http://www.xfree86.org/current/tog-cup.html | ||
| 30 | # | ||
| 31 | # CVE-2007-6428 | ||
| 32 | # http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6428 | ||
| 33 | # xfree86 and x.org before 1.4.1 GetReservedColormapEntries read | ||
| 34 | # arbitrary memory | ||
| 35 | # | ||
| 36 | # /usr/share/doc/x11proto-core-dev/x11protocol.txt.gz | ||
| 37 | |||
| 38 | |||
| 39 | BEGIN { require 5 } | ||
| 40 | package X11::Protocol::Ext::TOG_CUP; | ||
| 41 | use strict; | ||
| 42 | use Carp; | ||
| 43 | |||
| 44 | use vars '$VERSION', '@CARP_NOT'; | ||
| 45 | $VERSION = 31; | ||
| 46 | @CARP_NOT = ('X11::Protocol'); | ||
| 47 | |||
| 48 | # uncomment this to run the ### lines | ||
| 49 | #use Smart::Comments; | ||
| 50 | |||
| 51 | |||
| 52 | # these not documented yet ... | ||
| 53 | use constant CLIENT_MAJOR_VERSION => 1; | ||
| 54 | use constant CLIENT_MINOR_VERSION => 0; | ||
| 55 | |||
| 56 | |||
| 57 | #------------------------------------------------------------------------------ | ||
| 58 | # requests | ||
| 59 | |||
| 60 | sub _reply_listofcoloritem { | ||
| 61 | my ($X, $data) = @_; | ||
| 62 | ### CupGetReservedColormapEntries reply: $data | ||
| 63 | |||
| 64 | # use Data::HexDump::XXD; | ||
| 65 | # print scalar(Data::HexDump::XXD::xxd($data)); | ||
| 66 | # print "\n"; | ||
| 67 | |||
| 68 | my ($num) = unpack 'x4L', $data; | ||
| 69 | $num /= 3; | ||
| 70 | ### $num | ||
| 71 | ### data len: length($data) | ||
| 72 | |||
| 73 | # obey $num rather than the reply length | ||
| 74 | # items start at offset 32 | ||
| 75 | return map {[unpack 'LSSSC', substr ($data, 20 + 12*$_, 12)]} | ||
| 76 | 1 .. $num; | ||
| 77 | } | ||
| 78 | |||
| 79 | my $reqs = | ||
| 80 | [ | ||
| 81 | ["CupQueryVersion", # 0 | ||
| 82 | sub { | ||
| 83 | my ($X, $client_major, $client_minor) = @_; | ||
| 84 | ### CupQueryVersion | ||
| 85 | return pack 'SS', $client_major, $client_minor; | ||
| 86 | }, | ||
| 87 | sub { | ||
| 88 | my ($X, $data) = @_; | ||
| 89 | return unpack 'x8SS', $data; | ||
| 90 | }], | ||
| 91 | |||
| 92 | ["CupGetReservedColormapEntries", # 1 | ||
| 93 | sub { | ||
| 94 | my ($X, $screen) = @_; | ||
| 95 | ### CupGetReservedColormapEntries ... | ||
| 96 | |||
| 97 | # don't normally bother about arg checking, but it's easy to forget | ||
| 98 | # the screen here, and pack() quietly turns undef into 0 | ||
| 99 | @_ == 2 || croak "CupGetReservedColormapEntries() requires single screen number parameter"; | ||
| 100 | |||
| 101 | return pack 'L', $screen; | ||
| 102 | }, | ||
| 103 | \&_reply_listofcoloritem ], | ||
| 104 | |||
| 105 | ["CupStoreColors", # 2 | ||
| 106 | sub { # ($X, $colormap, [$pixel,$red,$green,$blue],...) | ||
| 107 | my $X = shift; | ||
| 108 | my $colormap = shift; | ||
| 109 | return pack('L', $colormap) | ||
| 110 | . join('', map {pack 'LSSSxx', @$_} @_); | ||
| 111 | }, | ||
| 112 | \&_reply_listofcoloritem], | ||
| 113 | ]; | ||
| 114 | |||
| 115 | sub new { | ||
| 116 | my ($class, $X, $request_num, $event_num, $error_num) = @_; | ||
| 117 | ### TOG-CUP new() | ||
| 118 | ### $request_num | ||
| 119 | ### $event_num | ||
| 120 | ### $error_num | ||
| 121 | |||
| 122 | _ext_requests_install ($X, $request_num, $reqs); | ||
| 123 | |||
| 124 | # Any need to negotiate a version? | ||
| 125 | # my ($major, $minor) = $X->req('CupQueryVersion', 1, 0); | ||
| 126 | # if ($major != 1) { | ||
| 127 | # carp "Unrecognised TOG-CUP major version, got $major want 1"; | ||
| 128 | # return 0; | ||
| 129 | # } | ||
| 130 | return bless { | ||
| 131 | # major => $major, | ||
| 132 | # minor => $minor, | ||
| 133 | }, $class; | ||
| 134 | } | ||
| 135 | |||
| 136 | #------------------------------------------------------------------------------ | ||
| 137 | # generic | ||
| 138 | |||
| 139 | sub _ext_requests_install { | ||
| 140 | my ($X, $request_num, $reqs) = @_; | ||
| 141 | |||
| 142 | $X->{'ext_request'}->{$request_num} = $reqs; | ||
| 143 | my $href = $X->{'ext_request_num'}; | ||
| 144 | my $i; | ||
| 145 | foreach $i (0 .. $#$reqs) { | ||
| 146 | $href->{$reqs->[$i]->[0]} = [$request_num, $i]; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | 1; | ||
| 151 | __END__ |