/*- * Copyright (c) 2008 FUKAUMI Naoki. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include int send_firm(int fd, int req, int16_t idx, uint8_t *data, int off, int size) { struct usb_ctl_request ucr; memset(&ucr, 0, sizeof(ucr)); ucr.ucr_request.bmRequestType = UT_WRITE_VENDOR_DEVICE; ucr.ucr_request.bRequest = req; USETW(ucr.ucr_request.wValue, off); USETW(ucr.ucr_request.wIndex, idx); USETW(ucr.ucr_request.wLength, size); ucr.ucr_data = data + off; return (ioctl(fd, USB_DO_REQUEST, &ucr) == -1) ? -1 : ucr.ucr_actlen; } int main(int argc, char *argv[]) { uint8_t *firm, *data = NULL; uint8_t x0a00[] = { 0x02, 0x00, 0x00, 0x00, 0x14, 0x4a, 0x01, 0x00 }; uint8_t x0a80[] = { 0x02, 0x00, 0x00, 0x00, 0x9c, 0x4a, 0x01, 0x00 }; #ifdef I_KNOW_HOW_TO_DECRYPT_FIRMWARE uint8_t x2980[] = { 0x02, 0x00, 0x00, 0x00, 0x14, 0xd3, 0x01, 0x00 }; #endif off_t size; int16_t idx = 0; int ugen, sys; setprogname(argv[0]); if (argc != 2) { fprintf(stderr, "usage: %s device\n", getprogname()); exit(EXIT_FAILURE); } /* * following drivers can be used: * SKnet HDUS CD Version1.0/1.1 * corega CG-1SGT driver Ver1.1 PL0 * KWorld UB320-i driver V1.08.05.22 * SKnet MonsterTV 1D Express for DELL Ver.1.0.00.0 * Sanwa Supply VGA-TV1S ver. 7.00 #ifdef I_KNOW_HOW_TO_DECRYPT_FIRMWARE * if you know how to decrypt firmware, you may use newer * AS11Loader.sys at your own risk. #endif */ if ((ugen = open(argv[1], O_WRONLY)) == -1) err(EXIT_FAILURE, "%s", argv[1]); if ((sys = open("AS11Loader.sys", O_RDONLY)) != -1) ; else if ((sys = open("SKNET_AS11Loader.sys", O_RDONLY)) != -1) ; else if ((sys = open("SKNET_1SEG_TV_USBLoader.sys", O_RDONLY)) != -1) ; else err(EXIT_FAILURE, "AS11Loader.sys"); size = lseek(sys, 0, SEEK_END); if ((firm = mmap(NULL, size, PROT_READ, MAP_FILE | MAP_SHARED, sys, 0)) == MAP_FAILED) err(EXIT_FAILURE, "mmap()"); if (size == 20992) { if (memcmp(&firm[0x0a00], &x0a00, sizeof(x0a00)) == 0) { idx = ((int16_t)(firm[0x0a09]) << 8) | firm[0x0a08]; data = &firm[0x0a10]; } else if (memcmp(&firm[0x0a80], &x0a80, sizeof(x0a80)) == 0) { idx = ((int16_t)(firm[0x0a89]) << 8) | firm[0x0a88]; data = &firm[0x0a90]; } #ifdef I_KNOW_HOW_TO_DECRYPT_FIRMWARE } else if (size == 56704) { if (memcmp(&firm[0x2980], &x2980, sizeof(x2980)) == 0) { #ifdef PLEASE_MODIFY_HERE idx = ((int16_t)(firm[0x52d1]) << 8) | firm[0x52d0]; data = &firm[0x52d8]; idx = ((int16_t)(firm[0x92d9]) << 8) | firm[0x92d8]; data = &firm[0x92e0]; #endif } #endif } if (idx == 0 || data == NULL) { fprintf(stderr, "unknown AS11Loader.sys\n"); exit(EXIT_FAILURE); } send_firm(ugen, 0xab, idx, data, 0x0000, 0x0c00); send_firm(ugen, 0xab, idx, data, 0x2000, 0x0400); send_firm(ugen, 0xab, idx, data, 0x2800, 0x1000); send_firm(ugen, 0xac, idx, data, 0x3800, 0x0800); munmap(firm, size); close(sys); close(ugen); return EXIT_SUCCESS; }