This file is indexed.

/usr/bin/extresso is in icoutils 0.29.1-2ubuntu0.2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#! /usr/bin/perl -w
#
# extresso - Extract and convert resources using resource scripts
#
# Copyright (C) 1998-2005 Oskar Liljeblad
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#

use Getopt::Long;
use File::Spec;
use File::Basename;
use Term::ReadLine;
use LWP::Simple;
use HTTP::Status;

# global stuff
$PROGRAM = 'extresso';

$path_icotool = &path_or('icotool','../icotool/icotool');
$path_w32rtool = &path_or('wrestool','../wrestool/wrestool');
$path_tmpfile = 'extresso.fetch.tmp';
$tmpfile_exists = 0;

# initialize options
$arg_output = '.';
$arg_format = undef;
$arg_base = undef;
$arg_match = undef;
$arg_interactive = 0;
$arg_verbose = 0;
$arg_help = $arg_version = 0;

# get options
exit 1 if (!GetOptions("o|output=s"		=> \$arg_output,
                       "format=s"   		=> \$arg_format,
		       "b|base=s"   		=> \$arg_base,
                       "m|match=s"  		=> \$arg_match,
                       "i|interactive"	=> \$arg_interactive,
         	       "v|verbose"     => \$arg_verbose,
                       "help"          => \$arg_help,
                       "version"       => \$arg_version));

# deal with standard options
if ($arg_help) {
	print "Usage: extresso [OPTION]... [FILE]...\n";
	print "Extract and convert resources using resource scripts.\n";
	print "\n";
	print " -o, --output=DIR     where to place extracted files (default `.')\n";
	print "     --format=FORMAT  extraction format of icon resources (see icotool)\n";
	print " -b, --base=DIR       base directory of local files in scripts\n";
#	print " -m, --match=REGEXP   extract only from binaries whose name match this\n";
	print " -i, --interactive    prompt before extraction\n";
	print " -v, --verbose        explain what is being done\n";
	print "     --help           display this help and exit\n";
	print "     --version        output version information and exit\n";
  print "\n";
	print 'Report bugs to <frank.richter@gmail.com>', "\n";
	exit;
}
if ($arg_version) {
	print "$PROGRAM (icoutils) 0.29.1\n";
	print "Written by Oskar Liljeblad.\n\n";
	print "Copyright (C) 1998-2005 Oskar Liljeblad.\n";
	print "This is free software; see the source for copying conditions.  There is NO\n";
	print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
	exit;
}

# got no arguments?
if ($#ARGV == -1) {
	print STDERR "$PROGRAM: missing file argument\n";
	print STDERR "Try `$PROGRAM --help' for more information.\n"
}

# initialize objects if necessary
$obj_term = new Term::ReadLine 'extresso' if ($arg_interactive);

# process each non-option argument
for ($c = 0 ; $c <= $#ARGV ; $c++) {
	print STDERR "Processing $ARGV[$c]\n" if $arg_verbose;
	&process_script($ARGV[$c]);
}

#
# Subroutines
#
sub process_script {
	my ($file) = @_;

	# open the file
	die "$PROGRAM: $file: $!\n" if (!open(FH, $file));

	# variable initializations
	my ($line, $keyword, $param);

	my ($current_file) = undef;							# name of current resource achive
	my ($process_file) = 1;									# how to process resource archives
	my ($always_process_file) = undef;			# true if process_file should not be changed
	my ($process_resource) = 1;							# how to process a resource
	my ($always_process_resource) = undef;	# true if process_resource should not be changed

	# read each line
	while (defined ($line = <FH>)) {
		# strip leading and trailing whitespace
		$line =~ s/^\s*(\S?.*?\S?)\s*$/$1/;

		# skip empty lines and comments
		next if ($line eq '' || $line =~ /^#/);

		# split line into keyword and parameters
		($keyword,$param) = ($line =~ /^(\S*)\s*(.*)?$/);
		next if (!defined $keyword || $keyword eq '');

		# check parameter
		next if &check_missing($file, $keyword, $param);

		# version keyword
		if ($keyword eq 'version') {
			if ($param > 1) {
				warn "$file: resource script version `$param' not supported\n";
				return;
			}
		}
		# archive keyword
		elsif ($keyword eq 'file') {
			$current_file = $param;

			# if interactive, ask if we are to process this archive
			if (!$always_process_file) {
				if ($arg_interactive) {
					print "line ${.}: $keyword $param\n";
					my $res = &ask_interaction("Process resources in `$param'", 'yin');
					$always_process_file = 1 if (lc $res ne $res);
					$process_file = 0 if (lc $res eq 'n');
					$process_file = 1 if (lc $res eq 'y');
					$process_file = 2 if (lc $res eq 'i');
				} else {
					$process_file = 1;
				}
			}

			# get the file (local or remote)
			if ($tmpfile_exists) {
			    unlink $path_tmpfile;
			    $tmpfile_exists = 0;
			}
			$current_file = &fetch_file($current_file);
			return if (!defined $current_file);

			# check if the file actually exists
			if (!-e $current_file) {
				warn "$current_file: No such file or directory\n";
				return;
			}
		}
		# resource keyword
		elsif ($keyword eq 'resource' && $process_file) {
			($type, $name, $language, $dest_file)
			  = ($param =~ /^([^,]*?)\s*(?:,\s*([^,]*))?\s*(?:,\s*([^,]*))?\s*:\s*(.*)$/);

			# check for missing items
			next if &check_missing($file, $keyword, $type);
			next if &check_missing($file, $keyword, $name);
			next if &check_missing($file, $keyword, $dest_file);

			# if interactive
			if (!$always_process_resource) {
				if ($process_file == 2) {
					print "line ${.}: $keyword $param\n";
					my $res = &ask_interaction("Process resource type `$type' name `$name'", 'yn');
					$always_process_resource = 1 if (lc $res ne $res);
					$process_resource = 0 if (lc $res eq 'n');
					$process_resource = 1 if (lc $res eq 'y');
				} else {
					$process_resource = 1;
				}
			}
			next if !$process_resource;

			warn "Extracting $type resource $name to $dest_file\n" if $arg_verbose;

			&process_resource($current_file, $dest_file, $type, $name, $language);
		}
    # other keywords
    elsif ($keyword ne '') {
    	warn "$file: invalid keyword `$keyword' in line $.\n";
    }
	}

	# finally, close it
	close(FH);
}

sub process_resource {
	my ($resfile, $destfile, $type, $name, $language) = @_;

	# make w32rtool extraction parameters
	my ($cmd);
	$cmd = "-t$type -n$name";
	$cmd .= " -L$language" if (defined $language && $language ne '');
	$cmd = "$path_w32rtool ".&quoteshell($resfile). " -x $cmd";

	# make icotool extraction parameters
	my ($out);
	$out = &quoteshell($destfile);
	$out = File::Spec->catdir($arg_output, $out) if (defined $arg_output && $arg_output ne '');
	&make_directories(File::Basename::dirname($out));

	if (&is_icotool_type($type)) {
		$cmd .= " | $path_icotool -x -o " . $out . " -";
	} else {
		$cmd .= " -o$out";
	}

	# execute the command
#	print $cmd, "\n" if ($arg_verbose);
	system $cmd;

	return $path_icotool;
}

sub is_icotool_type {
	my ($type) = @_;
	
	$type = lc $type;
	return TRUE if (substr($type,0,1) eq '+' &&
		(substr($type,1) eq 'group_icon' || substr($type,1) eq 'group_cursor'));

	return TRUE if (substr($type,0,1) eq '-' &&
		(substr($type,1) == 12 || substr($type,1) == 14));

	return TRUE if ($type eq 'group_icon' || $type eq 'group_cursor'
		|| $type == 12 || $type == 14);

	return FALSE;
}

sub check_missing {
	my ($file, $keyword, $var) = @_;

	if (!defined $var || $var eq '') {
		warn "$file: missing parameter in `$keyword' statement in line ${.}.\n";
		return 1;
	}

	return 0;
}

# quote shell characters
sub quoteshell {
	my ($str) = @_;
	$str =~ s/([^-\w_.\/])/\\$1/g;
	return $str;
}

sub ask_interaction {
	my ($msg, $ch) = @_;

	# lowercase choices and put '/' between characters
	$ch = lc $ch;
	$ch =~ s/(.)(?=.)/$1\//g;

	my $in;
	do {
		$in = $obj_term->readline($msg . " ($ch)? ");
	} while (length($in) != 1 || $in eq '/' || index($ch,lc $in) == -1);

	return $in;
}

sub make_directories {
	my (@comp) = split(/\//, $_[0]);

	my ($check) = undef;
	foreach my $dir (@comp) {
		$check = File::Spec->catdir($check, $dir) if (defined $check);
		$check = $dir if (!defined $check);
		mkdir($check, 0777) if (!-e $check);
	}
}

sub fetch_file {
	my ($file) = @_;

	# if file is local, return it
	return $file if (-e $file);

	# try with --base argument 
  if (defined $arg_base) {
		my $tfile = File::Spec->catfile($arg_base, $file);
		return $tfile if (-e $tfile);
	}

	# absolutely not a file address
	return $file if (substr($file, 0, 1) eq '/');

	# get remote file
	print STDERR "Getting `$file'... ";
	my $rc = LWP::Simple::mirror($file, $path_tmpfile);
	if ($rc != RC_OK) {
		warn "failed!\n";
		warn "$file: " . HTTP::Status::status_message($rc) . "\n";
		return undef;
	}

	warn "done.\n";
	$tmpfile_exists = 1;
	return $path_tmpfile;
}

sub extract_file {
	my ($file, $archive) = @_;

	return "blah";
}

sub path_or {
	my ($cmd,$def) = @_;

	my $real = `which $cmd`;
  return $def if !defined $real;
  chop $real;
  return $def if ($real eq '');

	return $real;
}

sub END {
  unlink $path_tmpfile if $tmpfile_exists;
}