Explorations in a shitty printer driver written a 15 years ago
Okay so
https://pad.devhack.net/v-pZH3svRwioj63h_Hgt1w#
Jaguar Zebra zc300. Has linux drivers.
Here's what the linux drivers do:
root@b3f6b53369e7:~# ls
Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install.tar.zip
root@b3f6b53369e7:~# unzip Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install.tar.zip
Archive: Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install.tar.zip
inflating: Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install.tar.gz
root@b3f6b53369e7:~# tar -xzvf Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install.tar.gz
Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install
root@b3f6b53369e7:~# file Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install
Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, no section header
root@b3f6b53369e7:~# ls -lhart Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install
-rwxr-xr-x 1 ubuntu ubuntu 98M Jun 22 2018 Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install
root@b3f6b53369e7:~# ./Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install
172.17.0.2
This will install Zebra ZC Card Printer Driver on your computer. Continue?
[n/Y]
Where do you want to install Zebra ZC Card Printer Driver?
[/usr/local/ZebraJaguarDriver]
Installing Zebra ZC Card Printer Driver... Installing Program Files...
Installation complete.
root@b3f6b53369e7:~# cd /usr/local/ZebraJaguarDriver/
root@b3f6b53369e7:/usr/local/ZebraJaguarDriver# ls
10-ZebraJaguar.rules JgErrorNotify KillJgDiscoverPrinter.sh LICENSE.LGPLv3 com.zebra.jaguar.pkexec.policy jre1.8.0_111.tar.gz pdftojgpdf zebralogo.png
EthernetInstall.sh JgErrorNotify.sh LICENSE.FDL ZebraZC100Printer.ppd com.zebra.jaguar.uninst.pkexec.policy launch.sh rastertojg
Install.sh JgPnP LICENSE.GPLv2 ZebraZC150Printer.ppd config libtinyxml.so.2.6.2 uninstall
JgConfig JgPrinterProperties LICENSE.GPLv3 ZebraZC300Printer.ppd images libudev_64bit.so.1 uninstall.ico
JgDiscoverPrinter JgRemovePrinter LICENSE.LGPLv21 ZebraZC350Printer.ppd jar libzmjxml.so zcusb
root@b3f6b53369e7:/usr/local/ZebraJaguarDriver# ./Install.sh install
Ubuntu System
This is Ubuntu System
installing files
'/usr/local/ZebraJaguarDriver/pdftojgpdf' -> '/usr/lib/cups/filter/pdftojgpdf'
'/usr/local/ZebraJaguarDriver/rastertojg' -> '/usr/lib/cups/filter/rastertojg'
'/usr/local/ZebraJaguarDriver/zcusb' -> '/usr/lib/cups/backend/zcusb'
'/usr/local/ZebraJaguarDriver/10-ZebraJaguar.rules' -> '/lib/udev/rules.d/10-ZebraJaguar.rules'
'/usr/local/ZebraJaguarDriver/JgPnP' -> '/lib/udev/JgPnP'
'/usr/local/ZebraJaguarDriver/ZebraZC100Printer.ppd' -> '/usr/share/cups/model/ZebraZC100Printer.ppd'
'/usr/local/ZebraJaguarDriver/ZebraZC150Printer.ppd' -> '/usr/share/cups/model/ZebraZC150Printer.ppd'
'/usr/local/ZebraJaguarDriver/ZebraZC300Printer.ppd' -> '/usr/share/cups/model/ZebraZC300Printer.ppd'
'/usr/local/ZebraJaguarDriver/ZebraZC350Printer.ppd' -> '/usr/share/cups/model/ZebraZC350Printer.ppd'
jre1.8.0_111/lib/deploy/splash_11-lic.gif
jre1.8.0_111/lib/amd64/libjsound.so
...
jre1.8.0_111/lib/desktop/icons/LowContrast/16x16/apps/sun-java.png
'/usr/local/ZebraJaguarDriver/libtinyxml.so.2.6.2' -> '/usr/lib/x86_64-linux-gnu/libtinyxml.so.2.6.2'
libtinyxml Library File Copied
'/usr/local/ZebraJaguarDriver/libzmjxml.so' -> '/usr/lib/libzmjxml.so'
libzmjxml Library File Copied
./Install.sh: 28: /etc/profile: xhost: not found
./Install.sh: 29: /etc/profile: xhost: not found
Installation Completed for Ubuntu
Ubuntu PKEXEC
chmod: cannot access '/usr/share/polkit-1/actions/com.ubuntu.pkexec.zebra.policy': No such file or directory
libudev.so.1 is not present
libudev.so.1 is present
libudev.so.1 is not present
64 Bit System
* Restarting Common Unix Printing System cupsd [ OK ]
Failed to send reload request: No such file or directory
* Restarting Common Unix Printing System cupsd [ OK ]
Installation Completed
and this whole process works well enough, the Install.sh script is a bit jank and explicitly assumes you select the default location to extract it at /usr/local/ZebraJaguarDriver and fails if you extract it anywhere else. Also fails confusingly if you don't pass the install argument as it's first and only argument.
BUT. this is shitty. I shouldn't have to run a self-extracting executable to get a bunch of ppd files (and also some executables ????). Maybe I want to package this. Maybe I don't want to run binary blobs downloaded from the internet. what the fuck???
I started running strings on the file in the casual reverse engineering process, but I stumbled onto this:
root@b3f6b53369e7:~# cd wasd
root@b3f6b53369e7:~/wasd# rmdir ../wasd
root@b3f6b53369e7:~/wasd# /root/Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install
error getting working directory name: no such file or directory
while executing
"pwd"
(procedure "::InstallJammer::CommonInit" line 209)
invoked from within
"::InstallJammer::CommonInit"
(procedure "::InstallJammer::InitInstall" line 19)
invoked from within
"::InstallJammer::InitInstall"
(file "/installkitvfs/main2.tcl" line 28750)
invoked from within
"source [file join $::installkit::root main2.tcl]"
(file "/installkitvfs/main.tcl" line 3)
this is a tkl file! There are some references to "installkit" and "vfs"a s well.
I don't know much about tcl (except when I use expect to interface and reverse engineer some uart interactive shells). I've stumbled onto this assortment of links:
-
https://stackoverflow.com/questions/3783560/is-there-a-way-to-unwrap-a-tclkit-packed-exe
-
https://code.google.com/archive/p/tclkit/source/default/source
and I quickly started going down the path of "how do I get a runnable program that can extract a tcklit/starkit/starpack(/metakit/vfs)
It turns out this is pretty much impossible to do!!!!
Two issues with getting a runnable program:
- finding the source code for what I'm trying to run
- finding the dependencies of that thing
- and finding the source code of those dependencies.
given a "I can extract a starpack with: sdx, starkit developer extension" (this is an unverified claim), I can locate this website:
https://www.equi4.com/starkit/sdx.html
But the download link 404s and the last mentioned year on this page is 2005 (which is 20 years ago from when I've written this post!)
tcl-vfs $ ./configure --with-tcl=/usr/lib64 --with-tk=/usr/lib64
$ tclsh
% lappend auto_path [file join [pwd] "sdx" "lib"]
/usr/lib64/tcl8.6 /usr/lib64 /usr/lib /tmp/tmp.EFnGrQAgdR/tclkit/sdx/lib
% package require app-sdx
can't find package vfs::mk4
% lappend auto_path "/tmp/tmp.EFnGrQAgdR/tcl-vfs"
/usr/lib64/tcl8.6 /usr/lib64 /usr/lib /tmp/tmp.EFnGrQAgdR/tclkit/sdx/lib /tmp/tmp.EFnGrQAgdR/tcl-vfs
% package require app-sdx
couldn't read file "/tmp/tmp.EFnGrQAgdR/tcl-vfs/mk4vfs.tcl": no such file or directory
% package require app-sdx
Specify one of the following commands:
addtoc eval fetch ftpd httpd httpdist ls lsk md5sum mkinfo mkpack mkshow mksplit mkzipkit qwrap ratarx rexecd starsync sync tgz2kit treetime unwrap update version wrap
For more information, type: tclsh help ?command?
2.0
% package require app-sdx unwrap
expected version number but got "unwrap"
% unwrap
invalid command name "unwrap"
%
google, search 'tcl "crapvfs"'
https://sourceforge.net/projects/installjammer/
crapvfs::mount "../../Zebra_ZC_Card_Printer_Driver-1.0.0.0-Linux-x86_64-Install" "wasd"
glob -nocomplain -directory wasd *
proc list_files {dir} {
foreach item [glob -nocomplain -directory $dir *] {
if {[file isdirectory $item]} {
# Recursively list contents of directories
list_files $item
} else {
puts $item
}
}
}
set vfs_root "wasd"
list_files $vfs_root
proc extract_vfs {src_dir dest_dir} {
# Ensure the destination directory exists
file mkdir $dest_dir
foreach item [glob -nocomplain -directory $src_dir *] {
set relative_path [file tail $item]
set dest_path [file join $dest_dir $relative_path]
if {[file isdirectory $item]} {
# Recursively process subdirectories
extract_vfs $item $dest_path
} else {
# Copy file to destination
file copy -force $item $dest_path
puts "Copied: $item -> $dest_path"
}
}
}
extract_vfs "wasd" "./dest"