├── arnezamidump └── dump32.c ├── dumpana └── dumpana.c ├── hid-desc └── uxb360gp_rdesc.h ├── imgbuild ├── 1920to1921.py ├── build.py ├── hack.txt └── payload.S ├── isd2100 ├── Config │ └── LUFAConfig.h ├── Descriptors.c ├── Descriptors.h ├── Makefile ├── README.md ├── isd2100.c ├── isd2100.h ├── isd2100.py ├── main.c └── main.h ├── lflash ├── Makefile ├── README ├── debian │ ├── changelog │ ├── compat │ ├── control │ ├── copyright │ ├── docs │ ├── rules │ └── source │ │ └── format └── lflash.c ├── picflash ├── Compiler.h ├── Flasher.c ├── Flasher.h ├── GenericTypeDefs.h ├── HardwareProfile.h ├── PICFLASH.lkr ├── PICFLASH.mcp ├── PICFLASH.mcw ├── XNAND.c ├── XNAND.err ├── XNAND.h ├── XSPI.c ├── XSPI.h ├── boot │ ├── CleanUp.bat │ ├── PicXBoot.lkr │ ├── PicXBoot.mcp │ ├── PicXBoot.mcw │ ├── boot.c │ ├── boot.h │ ├── interrupt.c │ ├── interrupt.h │ ├── io_cfg.h │ ├── main.c │ ├── readme.txt │ ├── typedefs.h │ ├── usb.h │ ├── usb9.c │ ├── usb9.h │ ├── usb_compile_time_validation.h │ ├── usbcfg.h │ ├── usbctrltrf.c │ ├── usbctrltrf.h │ ├── usbdefs_ep0_buff.h │ ├── usbdefs_std_dsc.h │ ├── usbdrv.c │ ├── usbdrv.h │ ├── usbdsc.c │ ├── usbdsc.h │ ├── usbmmap.c │ └── usbmmap.h ├── c018i.o ├── main.c ├── readme.txt ├── usb.h ├── usb_ch9.h ├── usb_common.h ├── usb_config.h ├── usb_descriptors.c ├── usb_device.c ├── usb_device.h ├── usb_function_cdc.c ├── usb_hal.h └── usb_hal_pic18.h ├── pirstool ├── Makefile ├── mytypes.h └── pirstool.c ├── pirstools ├── AUTHORS ├── CREDITS ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── autogen.sh ├── config.h ├── configure.ac └── src │ ├── Makefile.am │ ├── lib │ ├── Makefile.am │ ├── libpirs.h │ ├── pirs_alloc.c │ ├── pirs_alloc.h │ ├── pirs_datatypes.h │ ├── pirs_desc.c │ ├── pirs_desc.h │ ├── pirs_extract.c │ ├── pirs_extract.h │ ├── pirs_filetable.c │ ├── pirs_filetable.h │ ├── pirs_hashtables.c │ ├── pirs_hashtables.h │ ├── pirs_main.c │ ├── pirs_main.h │ ├── pirs_titles.c │ ├── pirs_titles.h │ ├── sha1.c │ ├── sha1.h │ ├── util.c │ └── util.h │ ├── pirs.c │ ├── pirs_display.c │ ├── pirs_display.h │ ├── pirsread.c │ ├── test.sh │ ├── util.c │ └── util.h ├── reset_glitch_hack ├── build.py ├── cdxell │ ├── CD.tpl │ ├── CDjasper.tpl │ ├── Makefile │ ├── cdxell.S │ └── xenonsprs.h ├── cpld │ ├── glitch48nofullpost │ │ ├── _pace.ucf │ │ ├── _xmsgs │ │ │ ├── cpldfit.xmsgs │ │ │ ├── hprep6.xmsgs │ │ │ ├── taengine.xmsgs │ │ │ └── tsim.xmsgs │ │ ├── bench_beh.prj │ │ ├── glitch48nofullpost.gise │ │ ├── glitch48nofullpost.xise │ │ ├── iseconfig │ │ │ ├── glitch.projectmgr │ │ │ ├── glitch48.projectmgr │ │ │ ├── glitch48nofullpost.projectmgr │ │ │ └── main.xreport │ │ ├── isim.log │ │ ├── main.ucf │ │ ├── main.vhd │ │ ├── main_summary.html │ │ ├── pepExtractor.prj │ │ └── tmperr.err │ └── glitchslimnodp │ │ ├── _pace.ucf │ │ ├── _xmsgs │ │ ├── cpldfit.xmsgs │ │ ├── hprep6.xmsgs │ │ ├── taengine.xmsgs │ │ └── tsim.xmsgs │ │ ├── glitchslim.gise │ │ ├── glitchslim.xise │ │ ├── iseconfig │ │ ├── glitch.projectmgr │ │ ├── glitch48.projectmgr │ │ ├── glitch48nofullpost.projectmgr │ │ ├── glitchslim.projectmgr │ │ └── main.xreport │ │ ├── isim.log │ │ ├── main.ucf │ │ ├── main.vhd │ │ ├── main_summary.html │ │ ├── pepExtractor.prj │ │ └── tmperr.err ├── finding_the_right_timing.txt ├── reset_glitch_hack.txt └── schematics │ ├── glitch48nofullpost.DSN │ └── glitchslimnodp.DSN ├── shahunt ├── AUTHORS ├── BUILD ├── CREDITS ├── ChangeLog ├── LICENSE ├── Makefile ├── README ├── shahunt └── shahunt.c ├── xboxdumper ├── Makefile ├── README.TXT ├── fatx.c ├── fatx.h ├── file64.c ├── file64.h ├── main.c ├── mytypes.h ├── util.c ├── util.h ├── utility.c └── utility.h ├── xextools ├── .NOTES.swp ├── AUTHORS ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── aclocal.m4 ├── config.h.in ├── configure.ac ├── depcomp ├── libtool ├── src │ ├── Makefile.am │ ├── lib │ │ ├── Makefile.am │ │ ├── libxex.h │ │ ├── main.h │ │ ├── swissknife.c │ │ ├── swissknife.h │ │ ├── xex_alloc.c │ │ ├── xex_alloc.h │ │ ├── xex_cert.c │ │ ├── xex_cert.h │ │ ├── xex_datatypes.h │ │ ├── xex_main.c │ │ ├── xex_main.h │ │ ├── xh_info.c │ │ ├── xh_info.h │ │ ├── xh_info_exec.c │ │ ├── xh_info_exec.h │ │ ├── xh_info_init.c │ │ ├── xh_info_init.h │ │ ├── xh_info_load.c │ │ ├── xh_info_load.h │ │ ├── xh_info_unknown_1.c │ │ ├── xh_info_unknown_1.h │ │ ├── xh_main.c │ │ └── xh_main.h │ ├── swissknife.c │ ├── swissknife.h │ ├── xex_display.c │ ├── xex_display.h │ └── xexread.c └── stamp-h1 └── xflash ├── README ├── setup.py └── xflash ├── XConfig.py ├── XFlash.py ├── XStatus.py └── __init__.py /arnezamidump/dump32.c: -------------------------------------------------------------------------------- 1 | #define MEM_FUSESET_LOC 0x20000020000ULL 2 | #define MEM_FUSESET_SZ 0x10000 3 | 4 | #define MEM_1BL_LOC 0x8000020000000000ULL 5 | #define MEM_1BL_SZ 0x8000 6 | 7 | #define MEM_NAND_LOC 0xC8000000ULL 8 | #define MEM_NAND_SZ 0x1000000 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | volatile void * ioremap(unsigned long long physaddr, unsigned long size) 20 | { 21 | static int axs_mem_fd = -1; 22 | unsigned long long page_addr, ofs_addr, reg, pgmask; 23 | void* reg_mem = NULL; 24 | 25 | /* 26 | * looks like mmap wants aligned addresses? 27 | */ 28 | pgmask = getpagesize()-1; 29 | page_addr = physaddr & ~pgmask; 30 | ofs_addr = physaddr & pgmask; 31 | 32 | /* 33 | * Don't forget O_SYNC, esp. if address is in RAM region. 34 | * Note: if you do know you'll access in Read Only mode, 35 | * pass O_RDONLY to open, and PROT_READ only to mmap 36 | */ 37 | if (axs_mem_fd == -1) { 38 | axs_mem_fd = open("/dev/mem", O_RDWR|O_SYNC); 39 | if (axs_mem_fd < 0) { 40 | perror("AXS: can't open /dev/mem"); 41 | return NULL; 42 | } 43 | } 44 | 45 | /* memory map */ 46 | reg_mem = (void *) mmap64( 47 | 0, 48 | size + (unsigned long) ofs_addr, 49 | PROT_READ, 50 | MAP_SHARED, 51 | axs_mem_fd, 52 | page_addr 53 | ); 54 | if (reg_mem == MAP_FAILED) { 55 | perror("AXS: mmap error"); 56 | close(axs_mem_fd); 57 | return NULL; 58 | } 59 | 60 | reg = (unsigned long) reg_mem + (unsigned long) ofs_addr; 61 | return (volatile void *)reg; 62 | } 63 | 64 | int iounmap(volatile void *start, size_t length) 65 | { 66 | unsigned long ofs_addr; 67 | ofs_addr = (unsigned long)start & (getpagesize()-1); 68 | 69 | /* do some cleanup when you're done with it */ 70 | return munmap((unsigned char*)start-ofs_addr, length+ofs_addr); 71 | } 72 | 73 | 74 | void read64(void * addr, unsigned long long * ptr) 75 | { 76 | __asm__ (" ld %r3, 0(%r3); std %r3, 0(%r4) "); 77 | } 78 | 79 | int main(int argc, char **argv) 80 | { 81 | int i; 82 | FILE * fp; 83 | 84 | unsigned long long * ptr_u64; 85 | unsigned char * ptr_u8; 86 | unsigned char * b; 87 | 88 | printf("dumping fuses...\n"); 89 | ptr_u64 = (unsigned long long *) ioremap(MEM_FUSESET_LOC, MEM_FUSESET_SZ); 90 | unsigned long long tt; 91 | fp=fopen("FUSES.TXT", "w"); 92 | for (i = 0; i < 12; ++i) { 93 | read64((void *) ptr_u64 + i * 0x200, &tt); 94 | printf("%02x: %016llx\n", i, tt); 95 | fprintf(fp, "%02x: %016llx\n", i, tt); 96 | } 97 | fclose(fp); 98 | printf("done!\n"); 99 | 100 | printf("dumping 1BL...\n"); 101 | ptr_u8 = (unsigned char *) ioremap(MEM_1BL_LOC, MEM_1BL_SZ); 102 | b = (unsigned char *) malloc(MEM_1BL_SZ); 103 | memcpy(b, ptr_u8, MEM_1BL_SZ); 104 | fp = fopen("1BL.BIN", "wb"); 105 | fwrite(b, MEM_1BL_SZ, 1, fp); 106 | fclose(fp); 107 | free(b); 108 | printf("done!\n"); 109 | 110 | printf("dumping NAND...\n"); 111 | ptr_u8 = (unsigned char *) ioremap(MEM_NAND_LOC, MEM_NAND_SZ); 112 | b = (unsigned char *) malloc(MEM_NAND_SZ); 113 | memcpy(b, ptr_u8, MEM_NAND_SZ); 114 | fp=fopen("NAND.BIN", "wb"); 115 | fwrite(b, MEM_NAND_SZ, 1, fp); 116 | fclose(fp); 117 | free(b); 118 | printf("done!\n"); 119 | 120 | } 121 | -------------------------------------------------------------------------------- /dumpana/dumpana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | volatile void * ioremap(unsigned long long physaddr, unsigned long size) 8 | { 9 | static int axs_mem_fd = -1; 10 | unsigned long long page_addr, ofs_addr, reg, pgmask; 11 | void* reg_mem = NULL; 12 | 13 | /* 14 | * looks like mmap wants aligned addresses? 15 | */ 16 | pgmask = getpagesize()-1; 17 | page_addr = physaddr & ~pgmask; 18 | ofs_addr = physaddr & pgmask; 19 | 20 | /* 21 | * Don't forget O_SYNC, esp. if address is in RAM region. 22 | * Note: if you do know you'll access in Read Only mode, 23 | * pass O_RDONLY to open, and PROT_READ only to mmap 24 | */ 25 | if (axs_mem_fd == -1) { 26 | axs_mem_fd = open("/dev/mem", O_RDWR|O_SYNC); 27 | if (axs_mem_fd < 0) { 28 | perror("AXS: can't open /dev/mem"); 29 | return NULL; 30 | } 31 | } 32 | 33 | /* memory map */ 34 | reg_mem = (void *) mmap64( 35 | 0, 36 | size + (unsigned long) ofs_addr, 37 | PROT_READ|PROT_WRITE, 38 | MAP_SHARED, 39 | axs_mem_fd, 40 | page_addr 41 | ); 42 | if (reg_mem == MAP_FAILED) { 43 | perror("AXS: mmap error"); 44 | close(axs_mem_fd); 45 | return NULL; 46 | } 47 | 48 | reg = (unsigned long) reg_mem + (unsigned long) ofs_addr; 49 | return (volatile void *)reg; 50 | } 51 | 52 | int fd; 53 | 54 | int _xenon_smc_ana_read(uint8_t addr, uint32_t *val) 55 | { 56 | uint8_t buf[16]; 57 | memset(buf, 0, 16); 58 | 59 | buf[0] = 0x11; 60 | buf[1] = 0x10; 61 | buf[2] = 5; 62 | buf[3] = 0x80 | 0x70; 63 | buf[5] = 0xF0; 64 | buf[6] = addr; 65 | 66 | write(fd, buf, 16); 67 | if (read(fd, buf, 16) != 16) 68 | { 69 | perror("read"); 70 | exit(1); 71 | } 72 | //xenon_smc_send_message(buf); 73 | //xenon_smc_receive_response(buf); 74 | if (buf[1] != 0) 75 | { 76 | printf("xenon_smc_read_smbus failed, addr=%02x, err=%d\n", addr, buf[1]); 77 | return -1; 78 | } 79 | *val = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24); 80 | return 0; 81 | } 82 | 83 | int main(void) 84 | { 85 | volatile uint32_t *gpu = ioremap(0xec800000, 0x10000); 86 | printf("%dx%d\n", gpu[0x6134/4], gpu[0x6138/4]); 87 | 88 | #if 0 89 | volatile uint32_t *smc = ioremap(0xea001000, 0x10000); 90 | smc[0x84/4] = 0; 91 | smc[0x84/4] = 0x04000000; 92 | 93 | smc[0x94/4] = 0x04000000; 94 | smc[0x94/4] = 0; 95 | 96 | 97 | printf("val: %08x %08x\n", smc[0x84/4], smc[0x94/4]); 98 | exit(1); 99 | #endif 100 | 101 | #if 1 102 | fd = open("/dev/smc", O_RDWR); 103 | if (fd <0) 104 | { 105 | perror("smc"); 106 | return 1; 107 | } 108 | 109 | unsigned char dummy[16]; 110 | fcntl(fd, F_SETFL, O_NONBLOCK); 111 | while (read(fd, dummy, 16) == 16); 112 | fcntl(fd, F_SETFL, 0); 113 | 114 | int i; 115 | for (i = 0; i < 0x100; ++i) 116 | { 117 | uint32_t v; 118 | _xenon_smc_ana_read(i, &v); 119 | printf("0x%08x, ",v); 120 | if ((i&0x7)==0x7) 121 | printf(" // %02x\n", i &~0x7); 122 | } 123 | #endif 124 | 125 | 126 | #if 1 127 | for (i = 0x0; i < 0x10000; i += 4) 128 | { 129 | uint32_t v =gpu[i/4]; 130 | if (!v) 131 | continue; 132 | printf("%04x -> %08x\n", 133 | i, v); 134 | } 135 | #endif 136 | } 137 | -------------------------------------------------------------------------------- /isd2100/Config/LUFAConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief LUFA Library Configuration Header File 33 | * 34 | * This header file is used to configure LUFA's compile time options, 35 | * as an alternative to the compile time constants supplied through 36 | * a makefile. 37 | * 38 | * For information on what each token does, refer to the LUFA 39 | * manual section "Summary of Compile Tokens". 40 | */ 41 | 42 | #ifndef _LUFA_CONFIG_H_ 43 | #define _LUFA_CONFIG_H_ 44 | 45 | #if (ARCH == ARCH_AVR8) 46 | 47 | /* Non-USB Related Configuration Tokens: */ 48 | // #define DISABLE_TERMINAL_CODES 49 | 50 | /* USB Class Driver Related Tokens: */ 51 | // #define HID_HOST_BOOT_PROTOCOL_ONLY 52 | // #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} 53 | // #define HID_USAGE_STACK_DEPTH {Insert Value Here} 54 | // #define HID_MAX_COLLECTIONS {Insert Value Here} 55 | // #define HID_MAX_REPORTITEMS {Insert Value Here} 56 | // #define HID_MAX_REPORT_IDS {Insert Value Here} 57 | // #define NO_CLASS_DRIVER_AUTOFLUSH 58 | 59 | /* General USB Driver Related Tokens: */ 60 | // #define ORDERED_EP_CONFIG 61 | #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) 62 | #define USB_DEVICE_ONLY 63 | // #define USB_HOST_ONLY 64 | // #define USB_STREAM_TIMEOUT_MS {Insert Value Here} 65 | // #define NO_LIMITED_CONTROLLER_CONNECT 66 | // #define NO_SOF_EVENTS 67 | 68 | /* USB Device Mode Driver Related Tokens: */ 69 | // #define USE_RAM_DESCRIPTORS 70 | #define USE_FLASH_DESCRIPTORS 71 | // #define USE_EEPROM_DESCRIPTORS 72 | // #define NO_INTERNAL_SERIAL 73 | #define FIXED_CONTROL_ENDPOINT_SIZE 8 74 | #define DEVICE_STATE_AS_GPIOR 0 75 | #define FIXED_NUM_CONFIGURATIONS 1 76 | // #define CONTROL_ONLY_DEVICE 77 | #define INTERRUPT_CONTROL_ENDPOINT 78 | // #define NO_DEVICE_REMOTE_WAKEUP 79 | // #define NO_DEVICE_SELF_POWER 80 | 81 | /* USB Host Mode Driver Related Tokens: */ 82 | // #define HOST_STATE_AS_GPIOR 0 83 | // #define USB_HOST_TIMEOUT_MS {Insert Value Here} 84 | // #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here} 85 | // #define NO_AUTO_VBUS_MANAGEMENT 86 | // #define INVERTED_VBUS_ENABLE_LINE 87 | 88 | #else 89 | 90 | #error Unsupported architecture for this LUFA configuration file. 91 | 92 | #endif 93 | #endif 94 | -------------------------------------------------------------------------------- /isd2100/Descriptors.c: -------------------------------------------------------------------------------- 1 | #include "Descriptors.h" 2 | 3 | USB_Descriptor_Device_t PROGMEM DeviceDescriptor = 4 | { 5 | .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, 6 | 7 | .USBSpecification = VERSION_BCD(02.00), 8 | .Class = 0xFF, 9 | .SubClass = 0x00, 10 | .Protocol = 0x00, 11 | 12 | .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, 13 | 14 | .VendorID = 0xFFFF, 15 | .ProductID = 0x0004, 16 | .ReleaseNumber = 0x0100, 17 | 18 | .ManufacturerStrIndex = 0x01, 19 | .ProductStrIndex = 0x02, 20 | .SerialNumStrIndex = 0x03, 21 | 22 | .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS 23 | }; 24 | 25 | USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = 26 | { 27 | .Config = 28 | { 29 | .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, 30 | 31 | .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), 32 | .TotalInterfaces = 1, 33 | 34 | .ConfigurationNumber = 1, 35 | .ConfigurationStrIndex = NO_DESCRIPTOR, 36 | 37 | .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), 38 | 39 | .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) 40 | }, 41 | 42 | .Interface = 43 | { 44 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, 45 | 46 | .InterfaceNumber = 0x00, 47 | .AlternateSetting = 0x00, 48 | 49 | .TotalEndpoints = 2, 50 | 51 | .Class = 0xFF, 52 | .SubClass = 0x00, 53 | .Protocol = 0x00, 54 | 55 | .InterfaceStrIndex = NO_DESCRIPTOR 56 | }, 57 | 58 | .INEndpoint = 59 | { 60 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, 61 | 62 | .EndpointAddress = FLASHER_STREAM_IN_EPNUM, 63 | .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 64 | .EndpointSize = EPSIZE, 65 | .PollingIntervalMS = 0x00 66 | }, 67 | 68 | .OUTEndpoint = 69 | { 70 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, 71 | 72 | .EndpointAddress = FLASHER_STREAM_OUT_EPNUM, 73 | .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 74 | .EndpointSize = EPSIZE, 75 | .PollingIntervalMS = 0x00 76 | }, 77 | }; 78 | 79 | USB_Descriptor_String_t PROGMEM LanguageString = 80 | { 81 | .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, 82 | 83 | .UnicodeString = {LANGUAGE_ID_ENG} 84 | }; 85 | 86 | USB_Descriptor_String_t PROGMEM ManufacturerString = 87 | { 88 | .Header = {.Size = USB_STRING_LEN(5), .Type = DTYPE_String}, 89 | 90 | .UnicodeString = L"PCUSB" 91 | }; 92 | 93 | USB_Descriptor_String_t PROGMEM ProductString = 94 | { 95 | .Header = {.Size = USB_STRING_LEN(12), .Type = DTYPE_String}, 96 | 97 | .UnicodeString = L"MemoryAccess" 98 | }; 99 | 100 | USB_Descriptor_String_t PROGMEM SerialNumberString = 101 | { 102 | .Header = {.Size = USB_STRING_LEN(8), .Type = DTYPE_String}, 103 | 104 | .UnicodeString = L"DEADC0DE" 105 | }; 106 | 107 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 108 | const uint8_t wIndex, 109 | const void** const DescriptorAddress) 110 | { 111 | const uint8_t DescriptorType = (wValue >> 8); 112 | const uint8_t DescriptorNumber = (wValue & 0xFF); 113 | 114 | void* Address = NULL; 115 | uint16_t Size = NO_DESCRIPTOR; 116 | 117 | switch (DescriptorType) 118 | { 119 | case DTYPE_Device: 120 | Address = (void*)&DeviceDescriptor; 121 | Size = sizeof(USB_Descriptor_Device_t); 122 | break; 123 | case DTYPE_Configuration: 124 | Address = (void*)&ConfigurationDescriptor; 125 | Size = sizeof(USB_Descriptor_Configuration_t); 126 | break; 127 | case DTYPE_String: 128 | switch (DescriptorNumber) 129 | { 130 | case 0x00: 131 | Address = (void*)&LanguageString; 132 | Size = pgm_read_byte(&LanguageString.Header.Size); 133 | break; 134 | case 0x01: 135 | Address = (void*)&ManufacturerString; 136 | Size = pgm_read_byte(&ManufacturerString.Header.Size); 137 | break; 138 | case 0x02: 139 | Address = (void*)&ProductString; 140 | Size = pgm_read_byte(&ProductString.Header.Size); 141 | break; 142 | case 0x03: 143 | Address = (void*)&SerialNumberString; 144 | Size = pgm_read_byte(&SerialNumberString.Header.Size); 145 | break; 146 | } 147 | break; 148 | } 149 | 150 | *DescriptorAddress = Address; 151 | return Size; 152 | } 153 | 154 | -------------------------------------------------------------------------------- /isd2100/Descriptors.h: -------------------------------------------------------------------------------- 1 | #ifndef _DESCRIPTORS_H_ 2 | #define _DESCRIPTORS_H_ 3 | 4 | #include 5 | #include 6 | 7 | typedef struct 8 | { 9 | USB_Descriptor_Configuration_Header_t Config; 10 | USB_Descriptor_Interface_t Interface; 11 | USB_Descriptor_Endpoint_t INEndpoint; 12 | USB_Descriptor_Endpoint_t OUTEndpoint; 13 | } USB_Descriptor_Configuration_t; 14 | 15 | #define EPSIZE 64 16 | 17 | #define FLASHER_STREAM_IN_EPNUM (ENDPOINT_DIR_IN | 2) 18 | 19 | #define FLASHER_STREAM_OUT_EPNUM (ENDPOINT_DIR_OUT | 3) 20 | 21 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 22 | const uint8_t wIndex, 23 | const void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /isd2100/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # LUFA Library 3 | # Copyright (C) Dean Camera, 2012. 4 | # 5 | # dean [at] fourwalledcubicle [dot] com 6 | # www.lufa-lib.org 7 | # 8 | # -------------------------------------- 9 | # LUFA Project Makefile. 10 | # -------------------------------------- 11 | 12 | MCU = at90usb162 13 | ARCH = AVR8 14 | BOARD = OLIMEX162 15 | F_CPU = 8000000 16 | F_USB = $(F_CPU) 17 | OPTIMIZATION = s 18 | TARGET = isd2100_flasher 19 | SRC = main.c isd2100.c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) 20 | LUFA_PATH = ../LUFA-120730/LUFA 21 | CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ 22 | LD_FLAGS = 23 | 24 | # Default target 25 | all: 26 | 27 | zip: 28 | tar cfvz isd2100.tar.gz *.c *.h isd2100.py Makefile README Config 29 | 30 | # Include LUFA build script makefiles 31 | include $(LUFA_PATH)/Build/lufa_core.mk 32 | include $(LUFA_PATH)/Build/lufa_sources.mk 33 | include $(LUFA_PATH)/Build/lufa_build.mk 34 | include $(LUFA_PATH)/Build/lufa_cppcheck.mk 35 | include $(LUFA_PATH)/Build/lufa_doxygen.mk 36 | include $(LUFA_PATH)/Build/lufa_dfu.mk 37 | include $(LUFA_PATH)/Build/lufa_hid.mk 38 | include $(LUFA_PATH)/Build/lufa_avrdude.mk 39 | include $(LUFA_PATH)/Build/lufa_atprogram.mk 40 | -------------------------------------------------------------------------------- /isd2100/README.md: -------------------------------------------------------------------------------- 1 | Author: G33kAtWork (https://github.com/G33KatWork) 2 | 3 | # ISD2100 flash library - ISD Soundchip / sound recorder 4 | 5 | This ISD2100 flash-library is neither complete nor extensively tested. 6 | Take it as it is and use it at your own risk!! 7 | 8 | The firmware was developed on an AT90USB162 (Olimex AVR-USB-162), but similar AVRs supported by LUFA may be compatible as well. 9 | 10 | 11 | ## Requirements 12 | * AT90USB162 or similar @ 3V3 13 | * LUFA-120730 or later (http://www.fourwalledcubicle.com/LUFA.php) 14 | * python-usb version 1.0 15 | 16 | 17 | ## Pinouts 18 | ``` 19 | PIN AT90USB162 ISD2100 20 | SS PB0 (14) (3) 21 | SCK PB1 (15) GPIO1 (2) 22 | MOSI PB2 (16) GPIO0 (4) 23 | MISO PB3 (17) GPIO2 (1) 24 | BSY PB4 (18) GPIO4 (12) 25 | ``` 26 | 27 | ## Usage 28 | ``` 29 | # python isd2100.py 30 | status Shows status 31 | int Shows interrupt status 32 | pwrup Powerup device 33 | pwrdwn Powerdown device 34 | reset Reset device 35 | id Shows device id 36 | read Dumps device 37 | write Writes device 38 | flush Flushs device 39 | voice Plays voice prompt 40 | voicerg Plays voice prompt in register 41 | macro Plays voice macro 42 | macrorg Plays voice macro in register 43 | stop Stops play 44 | help Prints help 45 | ``` 46 | 47 | 48 | ## Thanks/Credits 49 | Thx to all who provided infos and of whom i may have borrowed code/ideas from. 50 | -------------------------------------------------------------------------------- /isd2100/isd2100.c: -------------------------------------------------------------------------------- 1 | /* (c) 2012 g33k @ libxenon.org */ 2 | 3 | #include "isd2100.h" 4 | 5 | 6 | void ISD_init(void) { 7 | /* MOSI */ 8 | PINHIGH(ISDPORT, MOSI); 9 | PINOUT(ISDDDR, MOSI); 10 | 11 | /* SCK */ 12 | PINHIGH(ISDPORT, SCK); 13 | PINOUT(ISDDDR, SCK); 14 | 15 | /* SS */ 16 | PINHIGH(ISDPORT, SS); 17 | PINOUT(ISDDDR, SS); 18 | 19 | /* MISO */ 20 | PINHIGH(ISDPORT, MISO); 21 | PININ(ISDDDR, MISO); 22 | 23 | /* BSY */ 24 | PINHIGH(ISDPORT, BSY); 25 | PININ(ISDDDR, BSY); 26 | 27 | /* SPI */ 28 | SPCR = (1< 8 | 9 | #include 10 | 11 | 12 | #define ISDDDR DDRB 13 | #define ISDPORT PORTB 14 | #define ISDPIN PINB 15 | 16 | #define SS 0 17 | #define SCK 1 18 | #define MOSI 2 19 | #define MISO 3 20 | #define BSY 4 21 | 22 | #define PINOUT(DDR, PIN) (DDR |= (1 << PIN)) 23 | #define PININ(DDR, PIN) (DDR &= ~(1 << PIN)) 24 | #define PINHIGH(PORT, PIN) (PORT |= (1 << PIN)) 25 | #define PINLOW(PORT, PIN) (PORT &= ~(1 << PIN)) 26 | #define PINGET(PORT, PIN) (PORT & (1 << PIN)) 27 | 28 | 29 | #define ISD21_STATUS 0x40 30 | #define ISD21_INT 0x46 31 | #define ISD21_PWRUP 0x10 32 | #define ISD21_PWRDWN 0x12 33 | #define ISD21_RESET 0x14 34 | #define ISD21_ID 0x48 35 | #define ISD21_READ 0xA2 36 | #define ISD21_WRITE 0xA0 37 | #define ISD21_FLUSH 0x26 38 | #define ISD21_VP 0xA6 39 | #define ISD21_VPRN 0xAE 40 | #define ISD21_VM 0xB0 41 | #define ISD21_VMRN 0xBC 42 | #define ISD21_STOP 0x2A 43 | 44 | void ISD_init(void); 45 | uint8_t ISD_execute(uint8_t cmd, uint8_t *buffer, uint8_t len); 46 | uint8_t ISD_startTransfer(uint8_t cmd, uint8_t *buffer, uint8_t len); 47 | void ISD_stopTransfer(void); 48 | void ISD_transfer(uint8_t *buffer, uint8_t len); 49 | uint8_t ISD_rwByte(uint8_t out); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /isd2100/main.h: -------------------------------------------------------------------------------- 1 | /* (c) 2012 g33k @ libxenon.org */ 2 | 3 | #ifndef _MAIN_H_ 4 | #define _MAIN_H_ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "Descriptors.h" 22 | #include "isd2100.h" 23 | 24 | 25 | /* Vendor specific requests */ 26 | #define REQ_STATUS 0x80 27 | #define REQ_INT 0x81 28 | #define REQ_POWERUP 0x82 29 | #define REQ_POWERDOWN 0x83 30 | #define REQ_RESET 0x84 31 | #define REQ_ID 0x85 32 | #define REQ_READ 0x86 33 | #define REQ_WRITE 0x87 34 | #define REQ_FLUSH 0x88 35 | #define REQ_VP 0x89 36 | #define REQ_VPRN 0x8A 37 | #define REQ_VM 0x8B 38 | #define REQ_VMRN 0x8C 39 | #define REQ_STOP 0x8D 40 | 41 | 42 | void SetupHardware(void); 43 | void ISD21_Task(void); 44 | 45 | void getStatus(void); 46 | void getInt(void); 47 | void getId(void); 48 | void readFlash(uint8_t *data); 49 | 50 | void EVENT_USB_Device_ConfigurationChanged(void); 51 | void EVENT_USB_Device_Connect(void); 52 | void EVENT_USB_Device_Disconnect(void); 53 | void EVENT_USB_Device_ConfigurationChanged(void); 54 | void EVENT_USB_Device_UnhandledControlRequest(void); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /lflash/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -g -Wall 3 | 4 | all: lflash 5 | 6 | lflash: lflash.o 7 | $(CC) $(CFLAGS) -o lflash lflash.o 8 | 9 | clean: 10 | rm -f lflash *.o *~ 11 | -------------------------------------------------------------------------------- /lflash/README: -------------------------------------------------------------------------------- 1 | lflash is a linux-based flasher. 2 | 3 | With a lot of caution, it can be used to convert a KK-exploited box into the 4 | new hack. Of course you still need to add the resistors. 5 | 6 | PLEASE DON'T YET USE THIS TOOL UNLESS 7 | - YOU HAVE A WORKING SECONDARY WAY TO FLASH (like the LPT flasher) 8 | - YOU HAVE MADE A NAND BACKUP 9 | 10 | Also please note that lflash tries to do proper badblock remapping. That, 11 | unfortunately, means that you can not expect it to flash full images. 12 | 13 | PLEASE USE THIS FLASHER ONLY WITH IMAGES GENERATED WITH build.py UNLESS YOU 14 | KNOW *EXACTLY* WHATS HAPPENING. 15 | 16 | DO NOT USE THIS WITH FULL 16MB IMAGES (like xenon-hack.bin)! The build.py 17 | script was modified to build images which are badblock-safe, whereas the old 18 | images were not badblock safe. 19 | 20 | lflash doesn't yet support largeblock jasper. 21 | 22 | Usage: 23 | ./lflash backup.bin image_00000000.ecc 24 | 25 | lFlash will generate a backup first, verifies the backup, and then flashes 26 | the new image. If flashing fails, please do not switch off the box, but ask 27 | for help! We can likely recover. 28 | 29 | 30 | 31 | 32 | For the tech-savvy: 33 | 34 | The flash controller gives you access to 15.8MB of logical flash space. 35 | 0.5MB are allocated for badblock replacements. The flash controller 36 | automatically maps them away with the following algorithm: 37 | 38 | If you try to read a sector either with the 0xC8000000 memory map or with 39 | the "read logical" command, it will first look at the given address. If it 40 | doesn't find a sector there which is a.) good (ECC[5] == 0xFF), b.) has a 41 | valid ECC[12..15], c.) has a valid block number in ECC[0..3], then it will 42 | scan for a replacement block. It will do that by starting at the top of the 43 | flash, scanning downwards until it finds a block with the right block 44 | number. This happens completely automatic for reading, but not for writing. 45 | It also doesn't happen when you read physical pages. 46 | 47 | I believe the proper way to handle flash images should be the following: 48 | 49 | We should always read in "logical" mode. This will map away bad sectors, and 50 | replace them with the proper content. Thus, a flash image should never 51 | contain any bad blocks. 52 | 53 | A flash image should only consist of the logical area, i.e. of the first 54 | 15.8MB. The remaining 0.5MB should not be part of the image, since those 55 | blocks are either empty, or are replacement blocks which were already used 56 | in the data area. 57 | 58 | Flashing a 15.8MB image will work without destroying badblock information in 59 | the flash. It will also ensure that whereever your flash has bad sectors, it 60 | will just relocate the blocks. 61 | 62 | If you are using the Xbox 360 NAND controller, I propose the following 63 | algorithm for programming: 64 | 65 | - For every eraseblock (16k on smallblock), 66 | - read the first sector's ECC information in logical mode 67 | - read the physical address from the NAND register space 68 | (if the flash controller determined that this page was bad, it already 69 | looked for a replacement block for you. The address of this block is 70 | placed in the physical address register. 71 | - use the physical address from the NAND register space as target for this 72 | block, i.e. erase the block, and program it. You should not encounter 73 | any errors, unless a *new* bad block developed. 74 | 75 | This way, you shouldn't have problem with bad sectors. 76 | 77 | If you are not using the Xbox 360 NAND controller, you have to do the 78 | remapping on your own: 79 | 80 | - For every eraseblock 81 | - read the first sector. 82 | - check that it's not bad, has valid ECC, and a valid block number. 83 | - if it doesn't have all of them, don't touch this sector. 84 | - start at the top of the flash, scanning downwards, until you find a 85 | sector which is the replacement block for this sector. Use this sector 86 | as target. 87 | - erase&program the block. 88 | 89 | If you have an 16MB image, don't flash it completely. Instead, map away bad 90 | sectors in the flash image. If you don't do this, you will generate a bad 91 | block on the target NAND, even if there isn't really a bad block. Make sure 92 | to only flash the first 15.8MB, but with the badblock remapping. 93 | 94 | This is also the reason why build.py was updated to move the exploit buffer 95 | down from 0xFC000 to 0x200. 96 | 97 | have fun, 98 | tmbinc -------------------------------------------------------------------------------- /lflash/debian/changelog: -------------------------------------------------------------------------------- 1 | lflash (0.1-1~0free60-1) unstable; urgency=low 2 | 3 | * Initial packaging 4 | 5 | -- tuxuser Tue, 25 Sep 2012 23:02:20 +0200 6 | -------------------------------------------------------------------------------- /lflash/debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /lflash/debian/control: -------------------------------------------------------------------------------- 1 | Source: lflash 2 | Section: unknown 3 | Priority: extra 4 | Maintainer: tuxuser 5 | Build-Depends: debhelper (>= 7.0.50~) 6 | Standards-Version: 3.8.4 7 | Homepage: http://free60.org 8 | #Vcs-Git: git://github.com/Free60Project/tools.git 9 | #Vcs-Browser: https://github.com/Free60Project/tools/tree/master/lflash 10 | 11 | Package: lflash 12 | Architecture: powerpc 13 | Depends: ${shlibs:Depends}, ${misc:Depends} 14 | Description: lflash is a linux-based nand flasher for xbox 360. 15 | -------------------------------------------------------------------------------- /lflash/debian/copyright: -------------------------------------------------------------------------------- 1 | This work was packaged for Debian by: 2 | 3 | tuxuser on Tue, 25 Sep 2012 23:02:20 +0200 4 | 5 | It was downloaded from: 6 | 7 | https://github.com/Free60Project/tools/tree/master/lflash 8 | 9 | Upstream Author(s): 10 | 11 | Felix Domke 12 | -------------------------------------------------------------------------------- /lflash/debian/docs: -------------------------------------------------------------------------------- 1 | README 2 | -------------------------------------------------------------------------------- /lflash/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | #export DH_VERBOSE=1 11 | 12 | %: 13 | dh $@ 14 | -------------------------------------------------------------------------------- /lflash/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /picflash/Flasher.h: -------------------------------------------------------------------------------- 1 | extern void FlashPollProc(void); 2 | extern void FlashInitEP(void); 3 | extern void FlashCheckVendorReq(void); 4 | 5 | #define FlashTxSetCBF(pCBF,len) \ 6 | { \ 7 | FlashTxCBF = pCBF; \ 8 | FlashTxLen = len; \ 9 | FlashTxState = FLASH_TX_BUSY; \ 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /picflash/HardwareProfile.h: -------------------------------------------------------------------------------- 1 | #ifndef HARDWARE_PROFILE_H 2 | #define HARDWARE_PROFILE_H 3 | 4 | /*******************************************************************/ 5 | /******** USB stack hardware selection options *********************/ 6 | /*******************************************************************/ 7 | //This section is the set of definitions required by the MCHPFSUSB 8 | // framework. These definitions tell the firmware what mode it is 9 | // running in, and where it can find the results to some information 10 | // that the stack needs. 11 | //These definitions are required by every application developed with 12 | // this revision of the MCHPFSUSB framework. Please review each 13 | // option carefully and determine which options are desired/required 14 | // for your application. 15 | 16 | 17 | 18 | #endif //HARDWARE_PROFILE_H 19 | -------------------------------------------------------------------------------- /picflash/PICFLASH.lkr: -------------------------------------------------------------------------------- 1 | LIBPATH . 2 | 3 | FILES c018i.o 4 | FILES clib.lib 5 | FILES p18f2455.lib 6 | 7 | CODEPAGE NAME=page START=0x000800 END=0x005FFF 8 | 9 | ACCESSBANK NAME=accessram START=0x0 END=0x5F 10 | DATABANK NAME=gpr0 START=0x60 END=0xFF 11 | 12 | DATABANK NAME=gpr1 START=0x100 END=0x1FF 13 | DATABANK NAME=gpr2 START=0x200 END=0x2FF 14 | DATABANK NAME=gpr3 START=0x300 END=0x3FF 15 | DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED 16 | DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED 17 | DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED 18 | DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED 19 | ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED 20 | 21 | STACK SIZE=0x100 RAM=gpr3 22 | -------------------------------------------------------------------------------- /picflash/PICFLASH.mcp: -------------------------------------------------------------------------------- 1 | [HEADER] 2 | magic_cookie={66E99B07-E706-4689-9E80-9B2582898A13} 3 | file_version=1.0 4 | device=PIC18F2455 5 | [PATH_INFO] 6 | BuildDirPolicy=BuildDirIsProjectDir 7 | dir_src= 8 | dir_bin= 9 | dir_tmp= 10 | dir_sin= 11 | dir_inc=C:\MCC18\h 12 | dir_lib=C:\MCC18\lib 13 | dir_lkr= 14 | [CAT_FILTERS] 15 | filter_src=*.asm;*.c 16 | filter_inc=*.h;*.inc 17 | filter_obj=*.o 18 | filter_lib=*.lib 19 | filter_lkr=*.lkr 20 | [CAT_SUBFOLDERS] 21 | subfolder_src= 22 | subfolder_inc= 23 | subfolder_obj= 24 | subfolder_lib= 25 | subfolder_lkr= 26 | [FILE_SUBFOLDERS] 27 | file_000=. 28 | file_001=. 29 | file_002=. 30 | file_003=. 31 | file_004=. 32 | file_005=. 33 | file_006=. 34 | file_007=. 35 | file_008=. 36 | file_009=. 37 | file_010=. 38 | file_011=. 39 | file_012=. 40 | file_013=. 41 | file_014=. 42 | [GENERATED_FILES] 43 | file_000=no 44 | file_001=no 45 | file_002=no 46 | file_003=no 47 | file_004=no 48 | file_005=no 49 | file_006=no 50 | file_007=no 51 | file_008=no 52 | file_009=no 53 | file_010=no 54 | file_011=no 55 | file_012=no 56 | file_013=no 57 | file_014=no 58 | [OTHER_FILES] 59 | file_000=no 60 | file_001=no 61 | file_002=no 62 | file_003=no 63 | file_004=no 64 | file_005=no 65 | file_006=no 66 | file_007=no 67 | file_008=no 68 | file_009=no 69 | file_010=no 70 | file_011=no 71 | file_012=no 72 | file_013=no 73 | file_014=no 74 | [FILE_INFO] 75 | file_000=main.c 76 | file_001=usb_descriptors.c 77 | file_002=usb_device.c 78 | file_003=XSPI.c 79 | file_004=XNAND.c 80 | file_005=Flasher.c 81 | file_006=Compiler.h 82 | file_007=GenericTypeDefs.h 83 | file_008=usb_config.h 84 | file_009=usb.h 85 | file_010=usb_device.h 86 | file_011=XSPI.h 87 | file_012=XNAND.h 88 | file_013=Flasher.h 89 | file_014=PICFLASH.lkr 90 | [SUITE_INFO] 91 | suite_guid={5B7D72DD-9861-47BD-9F60-2BE967BF8416} 92 | suite_state= 93 | [TOOL_SETTINGS] 94 | TS{DD2213A8-6310-47B1-8376-9430CDFC013F}= 95 | TS{BFD27FBA-4A02-4C0E-A5E5-B812F3E7707C}=/m"$(BINDIR_)$(TARGETBASE).map" /w /o"$(BINDIR_)$(TARGETBASE).cof" 96 | TS{C2AF05E7-1416-4625-923D-E114DB6E2B96}=-pa=1 97 | TS{ADE93A55-C7C7-4D4D-A4BA-59305F7D0391}= 98 | [INSTRUMENTED_TRACE] 99 | enable=0 100 | transport=0 101 | format=0 102 | [CUSTOM_BUILD] 103 | Pre-Build= 104 | Pre-BuildEnabled=1 105 | Post-Build= 106 | Post-BuildEnabled=1 107 | -------------------------------------------------------------------------------- /picflash/PICFLASH.mcw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/PICFLASH.mcw -------------------------------------------------------------------------------- /picflash/XNAND.c: -------------------------------------------------------------------------------- 1 | #include "GenericTypeDefs.h" 2 | #include "Compiler.h" 3 | #include "XSPI.h" 4 | 5 | BYTE eraseCycle = 0x00; 6 | 7 | BOOL XNANDWaitReady(WORD timeout) 8 | { 9 | do { 10 | if (!(XSPIReadByte(0x04) & 0x01)) 11 | return TRUE; 12 | } while (timeout--); 13 | 14 | return FALSE; 15 | } 16 | 17 | WORD XNANDGetStatus() 18 | { 19 | return XSPIReadWord(0x04); 20 | } 21 | 22 | WORD XNANDClearStatus() 23 | { 24 | BYTE tmp[4]; 25 | 26 | XSPIRead(4, tmp); 27 | XSPIWrite(4, tmp); 28 | } 29 | 30 | WORD XNANDReadStart(DWORD block) 31 | { 32 | WORD res; 33 | WORD tries = 0x1000; 34 | 35 | XNANDClearStatus(); 36 | 37 | XSPIWriteDWORD(0x0C, block << 9); 38 | 39 | XSPIWriteByte(0x08, 0x03); 40 | 41 | if (!XNANDWaitReady(0x1000)) 42 | return 0x8011; 43 | 44 | res = XNANDGetStatus(); 45 | 46 | XSPIWrite0(0x0C); 47 | 48 | return res; 49 | } 50 | 51 | void XNANDReadProcess(BYTE *buffer, BYTE words) { 52 | while (words--) { 53 | XSPIWrite0(0x08); 54 | XSPIRead(0x10, buffer); 55 | buffer+=4; 56 | } 57 | } 58 | 59 | WORD XNANDErase(DWORD block) 60 | { 61 | WORD res; 62 | BYTE tmp[4]; 63 | // when block bitwises anded with 7 is anything but 0 don't erase the block. 64 | if(eraseCycle != 0) 65 | { 66 | res = (block & (eraseCycle)); 67 | // if(!(block && eraseCycle)) // test to see if erase block level reached 68 | if(res != 0) 69 | { 70 | // XNANDClearStatus(); 71 | // return XNANDGetStatus(); 72 | return 0x200; // this may well screw things up 73 | } 74 | } 75 | 76 | XNANDClearStatus(); 77 | 78 | XSPIRead(0, tmp); 79 | tmp[0] |= 0x08; 80 | XSPIWrite(0, tmp); 81 | 82 | XSPIWriteDWORD(0x0C, block << 14); 83 | 84 | if (!XNANDWaitReady(0x1000)) 85 | return 0x8001; 86 | 87 | XSPIWriteByte(0x08, 0xAA); 88 | XSPIWriteByte(0x08, 0x55); 89 | 90 | if (!XNANDWaitReady(0x1000)) 91 | return 0x8002; 92 | 93 | XSPIWriteByte(0x08, 0x5); 94 | 95 | if (!XNANDWaitReady(0x1000)) 96 | return 0x8003; 97 | 98 | return XNANDGetStatus(); 99 | } 100 | 101 | void XNANDWriteStart() 102 | { 103 | XNANDClearStatus(); 104 | XSPIWrite0(0x0C); 105 | } 106 | 107 | void XNANDWriteProcess(BYTE *buffer, BYTE words) { 108 | while (words--) { 109 | XSPIWrite(0x10, buffer); 110 | XSPIWriteByte(0x08, 0x01); 111 | buffer += 4; 112 | } 113 | } 114 | 115 | WORD XNANDWriteExecute(DWORD block) { 116 | WORD res; 117 | WORD tries = 0x1000; 118 | 119 | XSPIWriteDWORD(0x0C, block << 9); 120 | 121 | XSPIWriteByte(0x08, 0x55); 122 | XSPIWriteByte(0x08, 0xAA); 123 | XSPIWriteByte(0x08, 0x4); 124 | 125 | if (!XNANDWaitReady(0x1000)) 126 | return 0x8021; 127 | 128 | return XNANDGetStatus(); 129 | } 130 | -------------------------------------------------------------------------------- /picflash/XNAND.err: -------------------------------------------------------------------------------- 1 | Warning[2058] C:\Documents and Settings\Cory\Desktop\pic\PicXFlash_v3bmod_pjas\XNAND.c 35 : call of function without prototype 2 | Warning[2058] C:\Documents and Settings\Cory\Desktop\pic\PicXFlash_v3bmod_pjas\XNAND.c 44 : call of function without prototype 3 | Warning[2058] C:\Documents and Settings\Cory\Desktop\pic\PicXFlash_v3bmod_pjas\XNAND.c 76 : call of function without prototype 4 | Warning[2058] C:\Documents and Settings\Cory\Desktop\pic\PicXFlash_v3bmod_pjas\XNAND.c 98 : call of function without prototype 5 | Warning[2058] C:\Documents and Settings\Cory\Desktop\pic\PicXFlash_v3bmod_pjas\XNAND.c 103 : call of function without prototype 6 | Warning[2058] C:\Documents and Settings\Cory\Desktop\pic\PicXFlash_v3bmod_pjas\XNAND.c 128 : call of function without prototype 7 | -------------------------------------------------------------------------------- /picflash/XNAND.h: -------------------------------------------------------------------------------- 1 | extern WORD XNANDReadStart(DWORD block); 2 | extern void XNANDReadProcess(BYTE *buffer, BYTE words); 3 | 4 | extern WORD XNANDErase(DWORD block); 5 | 6 | extern void XNANDWriteStart(void); 7 | extern void XNANDWriteProcess(BYTE *buffer, BYTE words); 8 | extern WORD XNANDWriteExecute(DWORD block); 9 | -------------------------------------------------------------------------------- /picflash/XSPI.h: -------------------------------------------------------------------------------- 1 | 2 | extern void XSPIInit(void); 3 | 4 | extern void XSPIEnterFlashMode(void); 5 | extern void XSPILeaveFlashMode(void); 6 | extern void XSPIPowerUp(); 7 | extern void XSPIShutdown(); 8 | 9 | extern BYTE XSPI(BYTE o); 10 | extern void XSPIRead(BYTE reg, BYTE *data); 11 | extern void XSPIWrite(BYTE reg, BYTE *data); 12 | 13 | //This are optimized special cases for the functions above 14 | extern void XSPIW(BYTE o); 15 | extern void XSPIW0(void); 16 | extern BYTE XSPIR(void); 17 | extern WORD XSPIReadWord(BYTE reg); 18 | extern BYTE XSPIReadByte(BYTE reg); 19 | extern void XSPIWrite0(BYTE reg); 20 | extern void XSPIWriteByte(BYTE reg, BYTE d); 21 | extern void XSPIWriteDWORD(BYTE reg, DWORD data); 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /picflash/boot/CleanUp.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM Remove files generated by compiler in this directory 3 | REM and all subdirectories. 4 | 5 | echo Removing *.$$$ files... 6 | del *.$$$ /f /q /s 7 | echo. 8 | 9 | echo Removing *.bkx files... 10 | del *.bkx /f /q /s 11 | echo. 12 | 13 | echo Removing *.cce files... 14 | del *.cce /f /q /s 15 | echo. 16 | 17 | echo Removing *.cod files... 18 | del *.cod /f /q /s 19 | echo. 20 | 21 | echo Removing *.cof files... 22 | del *.cof /f /q /s 23 | echo. 24 | 25 | echo Removing *.err files... 26 | del *.err /f /q /s 27 | echo. 28 | 29 | echo Removing *.hex files... 30 | del *.hex /f /q /s 31 | echo. 32 | 33 | echo Removing *.i files... 34 | del *.i /f /q /s 35 | echo. 36 | 37 | echo Removing *.lde files... 38 | del *.lde /f /q /s 39 | echo. 40 | 41 | echo Removing *.lst files... 42 | del *.lst /f /q /s 43 | echo. 44 | 45 | echo Removing *.obj files... 46 | del *.obj /f /q /s 47 | echo. 48 | 49 | echo Removing *.o files... 50 | del *.o /f /q /s 51 | echo. 52 | 53 | echo Removing *.rlf files... 54 | del *.rlf /f /q /s 55 | echo. 56 | 57 | echo Removing *.sym files... 58 | del *.sym /f /q /s 59 | echo. 60 | 61 | echo Removing *.sdb files... 62 | del *.sdb /f /q /s 63 | echo. 64 | 65 | echo Removing *.map files... 66 | del *.map /f /q /s 67 | echo. 68 | 69 | echo Removing *.mptags files... 70 | del *.mptags /f /q /s 71 | echo. 72 | 73 | echo Removing *.tagsrc files... 74 | del *.tagsrc /f /q /s 75 | echo. 76 | 77 | echo Removing *.mcs files... 78 | del *.mcs /f /q /s 79 | echo. 80 | 81 | echo Removing *.wat files... 82 | del *.wat /f /q /s 83 | echo. 84 | 85 | echo Done. -------------------------------------------------------------------------------- /picflash/boot/PicXBoot.lkr: -------------------------------------------------------------------------------- 1 | // $Id: 18f4550.lkr,v 1.1.2.2 2004/04/28 00:41:31 curtiss Exp $ 2 | // File: Bootloader_18f4550.lkr 3 | 4 | 5 | // This is a modified linker script for use with the PIC18F4550 processor 6 | // combined with the MCHPUSB Bootloader firmware project. 7 | 8 | 9 | 10 | LIBPATH . 11 | 12 | FILES c018i.o 13 | FILES clib.lib 14 | FILES p18f2455.lib 15 | 16 | CODEPAGE NAME=Bootloader START=0x0 END=0x7FF //For use by this bootloader firmware. 17 | CODEPAGE NAME=page START=0x800 END=0x7FFF PROTECTED //For use by the application to get programmed. 18 | CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED 19 | CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED 20 | CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED 21 | CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED 22 | 23 | ACCESSBANK NAME=accessram START=0x0 END=0x5F 24 | DATABANK NAME=gpr0 START=0x60 END=0xFF 25 | DATABANK NAME=gpr1 START=0x100 END=0x1FF 26 | DATABANK NAME=gpr2 START=0x200 END=0x2FF 27 | DATABANK NAME=gpr3 START=0x300 END=0x3FF 28 | DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED 29 | DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED 30 | DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED 31 | DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED 32 | ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED 33 | 34 | SECTION NAME=CONFIG ROM=config 35 | 36 | STACK SIZE=0x100 RAM=gpr3 37 | -------------------------------------------------------------------------------- /picflash/boot/PicXBoot.mcp: -------------------------------------------------------------------------------- 1 | [HEADER] 2 | magic_cookie={66E99B07-E706-4689-9E80-9B2582898A13} 3 | file_version=1.0 4 | device=PIC18F2455 5 | [PATH_INFO] 6 | BuildDirPolicy=BuildDirIsSourceDir 7 | dir_src= 8 | dir_bin= 9 | dir_tmp= 10 | dir_sin= 11 | dir_inc=C:\MCC18\h 12 | dir_lib=C:\MCC18\lib 13 | dir_lkr=C:\MCC18\lkr 14 | [CAT_FILTERS] 15 | filter_src=*.asm;*.c 16 | filter_inc=*.h;*.inc 17 | filter_obj=*.o 18 | filter_lib=*.lib 19 | filter_lkr=*.lkr 20 | [CAT_SUBFOLDERS] 21 | subfolder_src= 22 | subfolder_inc= 23 | subfolder_obj= 24 | subfolder_lib= 25 | subfolder_lkr= 26 | [FILE_SUBFOLDERS] 27 | file_000=. 28 | file_001=. 29 | file_002=. 30 | file_003=. 31 | file_004=. 32 | file_005=. 33 | file_006=. 34 | file_007=. 35 | file_008=. 36 | file_009=. 37 | file_010=. 38 | file_011=. 39 | file_012=. 40 | file_013=. 41 | file_014=. 42 | file_015=. 43 | file_016=. 44 | file_017=. 45 | file_018=. 46 | file_019=. 47 | [GENERATED_FILES] 48 | file_000=no 49 | file_001=no 50 | file_002=no 51 | file_003=no 52 | file_004=no 53 | file_005=no 54 | file_006=no 55 | file_007=no 56 | file_008=no 57 | file_009=no 58 | file_010=no 59 | file_011=no 60 | file_012=no 61 | file_013=no 62 | file_014=no 63 | file_015=no 64 | file_016=no 65 | file_017=no 66 | file_018=no 67 | file_019=no 68 | [OTHER_FILES] 69 | file_000=no 70 | file_001=no 71 | file_002=no 72 | file_003=no 73 | file_004=no 74 | file_005=no 75 | file_006=no 76 | file_007=no 77 | file_008=no 78 | file_009=no 79 | file_010=no 80 | file_011=no 81 | file_012=no 82 | file_013=no 83 | file_014=no 84 | file_015=no 85 | file_016=no 86 | file_017=no 87 | file_018=no 88 | file_019=no 89 | [FILE_INFO] 90 | file_000=main.c 91 | file_001=boot.c 92 | file_002=usb9.c 93 | file_003=usbctrltrf.c 94 | file_004=usbdrv.c 95 | file_005=usbdsc.c 96 | file_006=usbmmap.c 97 | file_007=io_cfg.h 98 | file_008=boot.h 99 | file_009=typedefs.h 100 | file_010=usb.h 101 | file_011=usb9.h 102 | file_012=usbcfg.h 103 | file_013=usbctrltrf.h 104 | file_014=usbdefs_ep0_buff.h 105 | file_015=usbdefs_std_dsc.h 106 | file_016=usbdrv.h 107 | file_017=usbdsc.h 108 | file_018=usbmmap.h 109 | file_019=PicXBoot.lkr 110 | [SUITE_INFO] 111 | suite_guid={5B7D72DD-9861-47BD-9F60-2BE967BF8416} 112 | suite_state= 113 | [TOOL_SETTINGS] 114 | TS{DD2213A8-6310-47B1-8376-9430CDFC013F}= 115 | TS{BFD27FBA-4A02-4C0E-A5E5-B812F3E7707C}=/m"$(BINDIR_)$(TARGETBASE).map" /w /o"$(BINDIR_)$(TARGETBASE).cof" 116 | TS{C2AF05E7-1416-4625-923D-E114DB6E2B96}=-scs 117 | TS{ADE93A55-C7C7-4D4D-A4BA-59305F7D0391}= 118 | [INSTRUMENTED_TRACE] 119 | enable=0 120 | transport=0 121 | format=0 122 | [CUSTOM_BUILD] 123 | Pre-Build= 124 | Pre-BuildEnabled=1 125 | Post-Build= 126 | Post-BuildEnabled=1 127 | -------------------------------------------------------------------------------- /picflash/boot/PicXBoot.mcw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/PicXBoot.mcw -------------------------------------------------------------------------------- /picflash/boot/boot.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/boot.c -------------------------------------------------------------------------------- /picflash/boot/boot.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/boot.h -------------------------------------------------------------------------------- /picflash/boot/interrupt.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * PIC USB 3 | * interrupt.c 4 | ******************************************************************************/ 5 | 6 | /** I N C L U D E S **********************************************************/ 7 | #include 8 | #include "system/typedefs.h" 9 | #include "system/interrupt/interrupt.h" 10 | 11 | /** V A R I A B L E S ********************************************************/ 12 | 13 | /** I N T E R R U P T V E C T O R S *****************************************/ 14 | 15 | #pragma code high_vector=0x08 16 | void interrupt_at_high_vector(void) 17 | { 18 | _asm goto high_isr _endasm 19 | } 20 | #pragma code 21 | 22 | #pragma code low_vector=0x18 23 | void interrupt_at_low_vector(void) 24 | { 25 | _asm goto low_isr _endasm 26 | } 27 | #pragma code 28 | 29 | /** D E C L A R A T I O N S **************************************************/ 30 | /****************************************************************************** 31 | * Function: void high_isr(void) 32 | * PreCondition: None 33 | * Input: 34 | * Output: 35 | * Side Effects: 36 | * Overview: 37 | *****************************************************************************/ 38 | #pragma interrupt high_isr 39 | void high_isr(void) 40 | { 41 | } 42 | 43 | /****************************************************************************** 44 | * Function: void low_isr(void) 45 | * PreCondition: None 46 | * Input: 47 | * Output: 48 | * Side Effects: 49 | * Overview: 50 | *****************************************************************************/ 51 | #pragma interruptlow low_isr 52 | void low_isr(void) 53 | { 54 | } 55 | #pragma code 56 | 57 | /** EOF interrupt.c **********************************************************/ 58 | -------------------------------------------------------------------------------- /picflash/boot/interrupt.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * PIC USB 3 | * interrupt.h 4 | ******************************************************************************/ 5 | 6 | #ifndef INTERRUPT_H 7 | #define INTERRUPT_H 8 | 9 | /** I N C L U D E S **********************************************************/ 10 | #include "system\typedefs.h" 11 | 12 | /** D E F I N I T I O N S ****************************************************/ 13 | #define mEnableInterrupt() INTCONbits.GIE = 1; 14 | 15 | 16 | /** S T R U C T U R E S ******************************************************/ 17 | 18 | /** E X T E R N S ************************************************************/ 19 | 20 | /** P R O T O T Y P E S ******************************************************/ 21 | void low_isr(void); 22 | void high_isr(void); 23 | 24 | #endif //INTERRUPT_H 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /picflash/boot/io_cfg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/io_cfg.h -------------------------------------------------------------------------------- /picflash/boot/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/main.c -------------------------------------------------------------------------------- /picflash/boot/readme.txt: -------------------------------------------------------------------------------- 1 | This is the bootloader for the PIC 18F2455. You need to program this 2 | bootloader only once. 3 | 4 | There are two ways to program the PIC: 5 | 6 | 1) Low Voltage Programming (LVP) 7 | 2) High Voltage Programming which needs +12V at the MCLR pin. 8 | 9 | The LVP mode requires an additional Signal (Port B5, Pin 26). If LVP is disabled via 10 | a configuration bit in the device, Port B5 can be used as normal IO. 11 | 12 | Because programming via LVP is easier, we do not use Port B5 and leave LVP 13 | enabled. You need to add a pull-down (10k) to Pin 26 to prevent the PIC from 14 | entering LVP mode randomly. 15 | 16 | There are thousands of more or less sophisticated PIC programmers out there. 17 | Some random examples: 18 | 19 | - http://www.finitesite.com/d3jsys/ 20 | - http://products.foxdelta.com/programmer/art2003/ART2003-LVP.pdf 21 | - http://www.sprut.de/electronic/pic/icsp/icsp.htm 22 | 23 | Once the bootloader is programmed, it can be controlled with Port C6, Pin 24 | 17. If the Pin is pulled to ground on reset or power-up, the device will 25 | enter the bootloader. 26 | 27 | The same Port will eventually be used for serial communication with the 28 | mainboard, so do not add any pull-ups or pull-downs. A simple jumper / 29 | switch that connects the Pin to ground is enough. 30 | 31 | So the following Pins are important for the bootloader: 32 | 33 | - Port B5, Pin 26: Pull-down to ground with 10k 34 | - Port C6, Pin 17: Connect to ground if you want to enter bootloader 35 | 36 | Once you programmed the bootloader, you can program / update the flasher 37 | onto your device using the following procedure: 38 | 39 | 1) Connect Port C6, Pin 17 to ground. 40 | 41 | 2) Power-cycle or reset the PIC. 42 | 43 | 3) Install the mchpusb driver for the USB device that shows up. 44 | 45 | 4) Start the programmer (PDFSUSB.exe) 46 | 47 | 5) Select the only device that shows up in the drop-down box 48 | 49 | 6) Use "Load Hex File" to load PixXFlash.mhx and click "Program Device" 50 | 51 | 7) After programming finished, disconnect Port C6, Pin 17 from ground. 52 | 53 | 8) Power-cycle or reset the PIC. 54 | 55 | -------------------------------------------------------------------------------- /picflash/boot/typedefs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/typedefs.h -------------------------------------------------------------------------------- /picflash/boot/usb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usb.h -------------------------------------------------------------------------------- /picflash/boot/usb9.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usb9.c -------------------------------------------------------------------------------- /picflash/boot/usb9.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usb9.h -------------------------------------------------------------------------------- /picflash/boot/usb_compile_time_validation.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usb_compile_time_validation.h -------------------------------------------------------------------------------- /picflash/boot/usbcfg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbcfg.h -------------------------------------------------------------------------------- /picflash/boot/usbctrltrf.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbctrltrf.c -------------------------------------------------------------------------------- /picflash/boot/usbctrltrf.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbctrltrf.h -------------------------------------------------------------------------------- /picflash/boot/usbdefs_ep0_buff.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbdefs_ep0_buff.h -------------------------------------------------------------------------------- /picflash/boot/usbdefs_std_dsc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbdefs_std_dsc.h -------------------------------------------------------------------------------- /picflash/boot/usbdrv.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbdrv.c -------------------------------------------------------------------------------- /picflash/boot/usbdrv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbdrv.h -------------------------------------------------------------------------------- /picflash/boot/usbdsc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbdsc.c -------------------------------------------------------------------------------- /picflash/boot/usbdsc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbdsc.h -------------------------------------------------------------------------------- /picflash/boot/usbmmap.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbmmap.c -------------------------------------------------------------------------------- /picflash/boot/usbmmap.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/boot/usbmmap.h -------------------------------------------------------------------------------- /picflash/c018i.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/c018i.o -------------------------------------------------------------------------------- /picflash/main.c: -------------------------------------------------------------------------------- 1 | #include "GenericTypeDefs.h" 2 | #include "Compiler.h" 3 | #include "usb_config.h" 4 | #include "usb_device.h" 5 | #include "usb.h" 6 | #include "XSPI.h" 7 | #include "Flasher.h" 8 | 9 | /** V A R I A B L E S ********************************************************/ 10 | #pragma udata 11 | 12 | void YourHighPriorityISRCode(); 13 | void YourLowPriorityISRCode(); 14 | 15 | /** VECTOR REMAPPING ***********************************************/ 16 | #if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER) 17 | #define REMAPPED_RESET_VECTOR_ADDRESS 0x1000 18 | #define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x1008 19 | #define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x1018 20 | #elif defined(PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER) 21 | #define REMAPPED_RESET_VECTOR_ADDRESS 0x800 22 | #define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x808 23 | #define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x818 24 | #else 25 | #define REMAPPED_RESET_VECTOR_ADDRESS 0x00 26 | #define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x08 27 | #define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x18 28 | #endif 29 | 30 | #if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER)||defined(PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER) 31 | #pragma code REMAPPED_HIGH_INTERRUPT_VECTOR = REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 32 | void Remapped_High_ISR (void) 33 | { 34 | _asm goto YourHighPriorityISRCode _endasm 35 | } 36 | #pragma code REMAPPED_LOW_INTERRUPT_VECTOR = REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 37 | void Remapped_Low_ISR (void) 38 | { 39 | _asm goto YourLowPriorityISRCode _endasm 40 | } 41 | #pragma code 42 | 43 | 44 | //These are your actual interrupt handling routines. 45 | #pragma interrupt YourHighPriorityISRCode 46 | void YourHighPriorityISRCode() 47 | { 48 | //Check which interrupt flag caused the interrupt. 49 | //Service the interrupt 50 | //Clear the interrupt flag 51 | //Etc. 52 | #if defined(USB_INTERRUPT) 53 | USBDeviceTasks(); 54 | #endif 55 | 56 | } //This return will be a "retfie fast", since this is in a #pragma interrupt section 57 | #pragma interruptlow YourLowPriorityISRCode 58 | void YourLowPriorityISRCode() 59 | { 60 | //Check which interrupt flag caused the interrupt. 61 | //Service the interrupt 62 | //Clear the interrupt flag 63 | //Etc. 64 | 65 | } //This return will be a "retfie", since this is in a #pragma interruptlow section 66 | 67 | /** DECLARATIONS ***************************************************/ 68 | #pragma code 69 | 70 | static void CheckUSBState(void); 71 | 72 | void main(void) 73 | { 74 | // All pins to digital 75 | ADCON1 |= 0x0F; 76 | 77 | XSPIInit(); 78 | 79 | USBDeviceInit(); 80 | USBDeviceAttach(); 81 | 82 | while(1) { 83 | CheckUSBState(); 84 | FlashPollProc(); 85 | } 86 | } 87 | 88 | void CheckUSBState() 89 | { 90 | if (USB_BUS_SENSE) USBDeviceAttach(); 91 | else USBDeviceDetach(); 92 | } 93 | 94 | BOOL USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, WORD size) 95 | { 96 | switch(event) 97 | { 98 | case EVENT_CONFIGURED: 99 | FlashInitEP(); 100 | break; 101 | 102 | case EVENT_EP0_REQUEST: 103 | FlashCheckVendorReq(); 104 | break; 105 | } 106 | 107 | return TRUE; 108 | } -------------------------------------------------------------------------------- /picflash/readme.txt: -------------------------------------------------------------------------------- 1 | Signal Mainboard 18F2455 2 | ---------------------------------- 3 | EJ J2B1.5 B1 Pin 22 (use resistor) 4 | XX J2B1.6 B0 Pin 21 (use resistor) 5 | SS J1D2.2 B4 Pin 25 (use resistor) 6 | SCK J1D2.3 B3 Pin 24 (use resistor) 7 | MOSI J1D2.1 B6 Pin 27 (use resistor) 8 | MISO J1D2.4 B2 Pin 23 (NO RESISTOR) 9 | 10 | and for remote power-on: 11 | 12 | KIOSK J2B1.11 B7 Pin 28 (use resistor) 13 | 14 | You can power the PIC from either the USB or from the mainboard. In any 15 | case, C2 (Pin 13) must be connected to +5V from the USB to allow proper sensing 16 | of the USB state. 17 | 18 | -------------------------------------------------------------------------------- /picflash/usb.h: -------------------------------------------------------------------------------- 1 | #ifndef _USB_H_ 2 | #define _USB_H_ 3 | 4 | #include "usb_config.h" // Must be defined by the application 5 | 6 | #include "usb_common.h" // Common USB library definitions 7 | #include "usb_ch9.h" // USB device framework definitions 8 | 9 | #include "usb_device.h" // USB Device abstraction layer interface 10 | #include "usb_hal.h" // Hardware Abstraction Layer interface 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /picflash/usb_ch9.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/usb_ch9.h -------------------------------------------------------------------------------- /picflash/usb_common.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/usb_common.h -------------------------------------------------------------------------------- /picflash/usb_config.h: -------------------------------------------------------------------------------- 1 | #ifndef USBCFG_H 2 | #define USBCFG_H 3 | 4 | /** DEFINITIONS ****************************************************/ 5 | #define USB_EP0_BUFF_SIZE 8 6 | #define USB_MAX_NUM_INT 1 7 | 8 | #define USB_USER_DEVICE_DESCRIPTOR &device_dsc 9 | #define USB_USER_DEVICE_DESCRIPTOR_INCLUDE extern ROM USB_DEVICE_DESCRIPTOR device_dsc 10 | 11 | #define USB_USER_CONFIG_DESCRIPTOR USB_CD_Ptr 12 | #define USB_USER_CONFIG_DESCRIPTOR_INCLUDE extern ROM BYTE *ROM USB_CD_Ptr[] 13 | 14 | //Make sure only one of the below "#define USB_PING_PONG_MODE" 15 | //is uncommented. 16 | //#define USB_PING_PONG_MODE USB_PING_PONG__NO_PING_PONG 17 | #define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG 18 | //#define USB_PING_PONG_MODE USB_PING_PONG__EP0_OUT_ONLY 19 | //#define USB_PING_PONG_MODE USB_PING_PONG__ALL_BUT_EP0 //NOTE: This mode is not supported in PIC18F4550 family rev A3 devices 20 | 21 | //#define USB_POLLING 22 | #define USB_INTERRUPT 23 | 24 | /* Parameter definitions are defined in usb_device.h */ 25 | #define USB_PULLUP_OPTION USB_PULLUP_ENABLE 26 | //#define USB_PULLUP_OPTION USB_PULLUP_DISABLED 27 | 28 | #define USB_TRANSCEIVER_OPTION USB_INTERNAL_TRANSCEIVER 29 | 30 | #define USB_SPEED_OPTION USB_FULL_SPEED 31 | 32 | #define USB_SUPPORT_DEVICE 33 | 34 | #define USB_NUM_STRING_DESCRIPTORS 4 35 | 36 | //#define USB_INTERRUPT_LEGACY_CALLBACKS 37 | #define USB_ENABLE_ALL_HANDLERS 38 | //#define USB_ENABLE_SUSPEND_HANDLER 39 | //#define USB_ENABLE_WAKEUP_FROM_SUSPEND_HANDLER 40 | //#define USB_ENABLE_SOF_HANDLER 41 | //#define USB_ENABLE_ERROR_HANDLER 42 | //#define USB_ENABLE_OTHER_REQUEST_HANDLER 43 | //#define USB_ENABLE_SET_DESCRIPTOR_HANDLER 44 | //#define USB_ENABLE_INIT_EP_HANDLER 45 | //#define USB_ENABLE_EP0_DATA_HANDLER 46 | //#define USB_ENABLE_TRANSFER_COMPLETE_HANDLER 47 | 48 | /** ENDPOINTS ALLOCATION *******************************************/ 49 | #define USB_MAX_EP_NUMBER 5 50 | 51 | #define NAND_TX_EP 2 52 | #define NAND_RX_EP 5 53 | 54 | #define NAND_RX_EP_SIZE 64 55 | #define NAND_TX_EP_SIZE 64 56 | 57 | /** DEFINITIONS ****************************************************/ 58 | 59 | #define USB_BUS_SENSE PORTCbits.RC2 60 | #define self_power 0 61 | 62 | //Uncomment the following line to make the output HEX of this 63 | // project work with the MCHPUSB Bootloader 64 | #define PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER 65 | 66 | //Uncomment the following line to make the output HEX of this 67 | // project work with the HID Bootloader 68 | //#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER 69 | 70 | #endif //USBCFG_H 71 | -------------------------------------------------------------------------------- /picflash/usb_descriptors.c: -------------------------------------------------------------------------------- 1 | #ifndef __USB_DESCRIPTORS_C 2 | #define __USB_DESCRIPTORS_C 3 | 4 | /** INCLUDES *******************************************************/ 5 | #include "GenericTypeDefs.h" 6 | #include "Compiler.h" 7 | #include "usb_config.h" 8 | #include "usb.h" 9 | 10 | /** CONSTANTS ******************************************************/ 11 | #pragma romdata 12 | 13 | /* Device Descriptor */ 14 | ROM USB_DEVICE_DESCRIPTOR device_dsc= 15 | { 16 | 0x12, // Size of this descriptor in bytes 17 | USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type 18 | 0x0200, // USB Spec Release Number in BCD format 19 | 0xFF, // Class Code 20 | 0x00, // Subclass code 21 | 0x00, // Protocol code 22 | USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h 23 | 0xFFFF, // Vendor ID 24 | 0x0004, // Product ID: Mouse in a circle fw demo 25 | 0x0100, // Device release number in BCD format 26 | 0x01, // Manufacturer string index 27 | 0x02, // Product string index 28 | 0x03, // Device serial number string index 29 | 0x01 // Number of possible configurations 30 | }; 31 | 32 | /* Configuration 1 Descriptor */ 33 | ROM BYTE configDescriptor1[]={ 34 | /* Configuration Descriptor */ 35 | 0x09,//sizeof(USB_CFG_DSC), // Size of this descriptor in bytes 36 | USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type 37 | DESC_CONFIG_WORD(0x0020), // Total length of data for this cfg 38 | 1, // Number of interfaces in this cfg 39 | 1, // Index value of this configuration 40 | 0, // Configuration string index 41 | _DEFAULT | _SELF, // Attributes, see usb_device.h 42 | 50, // Max power consumption (2X mA) 43 | 44 | /* Interface Descriptor */ 45 | 0x09,//sizeof(USB_INTF_DSC), // Size of this descriptor in bytes 46 | USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type 47 | 0, // Interface Number 48 | 0, // Alternate Setting Number 49 | 2, // Number of endpoints in this intf 50 | 0xFF, // Class code 51 | 00, // Subclass code 52 | 00, // Protocol code 53 | 0, // Interface string index 54 | 55 | /* Endpoint Descriptor */ 56 | 0x07,/*sizeof(USB_EP_DSC)*/ 57 | USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor 58 | 0x82, //EndpointAddress 59 | _BULK, //Attributes 60 | DESC_CONFIG_WORD(NAND_TX_EP_SIZE), //size 61 | 0x00, //Interval 62 | 63 | /* Endpoint Descriptor */ 64 | 0x07,/*sizeof(USB_EP_DSC)*/ 65 | USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor 66 | 0x05, //EndpointAddress 67 | _BULK, //Attributes 68 | DESC_CONFIG_WORD(NAND_RX_EP_SIZE), //size 69 | 0x00 //Interval 70 | }; 71 | 72 | 73 | //Language code string descriptor 74 | ROM struct{BYTE bLength;BYTE bDscType;WORD string[1];}sd000={ 75 | sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409 76 | }}; 77 | 78 | //Manufacturer string descriptor 79 | ROM struct{BYTE bLength;BYTE bDscType;WORD string[5];}sd001={ 80 | sizeof(sd001),USB_DESCRIPTOR_STRING, 81 | {'P','C','U','S','B'} 82 | }; 83 | 84 | //Product string descriptor 85 | ROM struct{BYTE bLength;BYTE bDscType;WORD string[12];}sd002={ 86 | sizeof(sd002),USB_DESCRIPTOR_STRING, 87 | {'M','e','m','o','r','y','A','c','c','e','s','s'} 88 | }; 89 | 90 | ROM struct{BYTE bLength;BYTE bDscType;WORD string[8];}sd003={ 91 | sizeof(sd003),USB_DESCRIPTOR_STRING, 92 | {'D','E','A','D','C','0','D','E'} 93 | }; 94 | 95 | 96 | //Array of configuration descriptors 97 | ROM BYTE *ROM USB_CD_Ptr[]= 98 | { 99 | (ROM BYTE *ROM)&configDescriptor1 100 | }; 101 | 102 | //Array of string descriptors 103 | ROM BYTE *ROM USB_SD_Ptr[]= 104 | { 105 | (ROM BYTE *ROM)&sd000, 106 | (ROM BYTE *ROM)&sd001, 107 | (ROM BYTE *ROM)&sd002, 108 | (ROM BYTE *ROM)&sd003 109 | }; 110 | 111 | #pragma code 112 | #endif 113 | -------------------------------------------------------------------------------- /picflash/usb_device.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/usb_device.c -------------------------------------------------------------------------------- /picflash/usb_device.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/usb_device.h -------------------------------------------------------------------------------- /picflash/usb_function_cdc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/usb_function_cdc.c -------------------------------------------------------------------------------- /picflash/usb_hal.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/usb_hal.h -------------------------------------------------------------------------------- /picflash/usb_hal_pic18.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/picflash/usb_hal_pic18.h -------------------------------------------------------------------------------- /pirstool/Makefile: -------------------------------------------------------------------------------- 1 | 2 | OBJS=pirstool.o 3 | 4 | CFLAGS=-O2 5 | 6 | all: $(OBJS) 7 | gcc -o pirstool $(OBJS) 8 | 9 | clean: 10 | rm -fr $(OBJS) pirstool pirstool.exe *# *~ 11 | 12 | .PHONY: clean 13 | -------------------------------------------------------------------------------- /pirstool/mytypes.h: -------------------------------------------------------------------------------- 1 | #ifndef MYTYPES_H 2 | #define MYTYPES_H 3 | 4 | #include 5 | 6 | #ifdef __linux__ 7 | #include 8 | #else // !__linux__ 9 | #include 10 | #ifndef __CYGWIN__ 11 | typedef unsigned __int16 u_int16_t; 12 | typedef unsigned __int32 u_int32_t; 13 | typedef unsigned __int64 u_int64_t; 14 | #endif // __CYGWIN__ 15 | #endif // __linux__ 16 | 17 | #if __GCC__ && __BYTE_ORDER == __BIG_ENDIAN 18 | #define bswap32(v) (v) 19 | #define bswap16(v) (v) 20 | #else // little endian 21 | #define bswap32(v) (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v << 8) & 0xff0000) | ((v << 24) & 0xff000000)) 22 | #define bswap16(v) (((v >> 8) & 0xff) | ((v << 8) & 0xff00)) 23 | #endif 24 | 25 | #endif // MYTYPES_H 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /pirstool/pirstool.c: -------------------------------------------------------------------------------- 1 | //PIRS compatible Generic Xbox 360 File Archive Tool 2 | //(c) 2005 John Kelley - http://free60.org 3 | 4 | #include 5 | #include 6 | #include 7 | #include "mytypes.h" 8 | 9 | //for MSVC8 aka VS2005 10 | #define _CRT_SECURE_NO_DEPRECATE 11 | 12 | //to make it easier to debug from MSVC or other IDEs 13 | #if _DEBUG || DEBUG 14 | #ifdef WIN32 15 | #define pause() getch() 16 | #else 17 | #define pause() getkbchar() 18 | #endif // WIN32 19 | #else 20 | #define pause() {} 21 | #endif // DEBUG 22 | 23 | #define DIR_OFFSET 0xC000 24 | #define CONTENT_TITLE 0x0410 25 | #define CONTENT_DESC 0x0d10 26 | #define CONTENT_PUBLISHER 0x1610 27 | 28 | #pragma pack(push,1) 29 | typedef struct { 30 | char name[38]; 31 | u_int32_t unk1, blockLen, offset; 32 | u_int16_t parent; 33 | u_int32_t size, unk2, unk3; 34 | } fileEntry; 35 | #pragma pack(pop) 36 | 37 | void printUsage() { 38 | printf("Usage: pirstool [l] [e] srcfile [destfile]\n"); 39 | } 40 | 41 | //Recursively build a filename path 42 | void sprintFileEntry(char *out, fileEntry files[], int index) { 43 | if (files[index].parent != 0xFFFF) 44 | sprintFileEntry(out, files, bswap16(files[index].parent)); 45 | strcat(out, "/"); 46 | strcat(out, files[index].name); 47 | } 48 | 49 | int main(int argc, char *argv[]) { 50 | fileEntry files[64]; 51 | wchar_t info[128]; 52 | FILE *in; 53 | char magicNum[4]; 54 | char filePath[1024]; 55 | int i; 56 | 57 | //verify struct size 58 | if (sizeof(fileEntry) != 64) { 59 | printf("fileEntry struct is not packed correctly with the compiler you used. (%d vs 64 bytes)\n", sizeof(fileEntry)); 60 | pause(); 61 | return 1; 62 | } 63 | 64 | //check # of args 65 | if (argc < 3) { 66 | printUsage(); 67 | pause(); 68 | return 1; 69 | } 70 | 71 | //only support list for now 72 | if (argv[1][0] != 'l') { 73 | printUsage(); 74 | pause(); 75 | return 1; 76 | } 77 | 78 | //open and verify file 79 | in = fopen(argv[2], "rb"); 80 | if (in == NULL) { 81 | printf("Error opening '%s' for reading.\n", argv[2]); 82 | pause(); 83 | return 1; 84 | } 85 | 86 | //verify magic number 87 | fread(magicNum, 4, 1, in); 88 | if (strncmp(magicNum, "PIRS", 4) != 0 && strncmp(magicNum, "LIVE", 4) != 0) { 89 | printf("File is not in a PIRS compatible format.\n"); 90 | fclose(in); 91 | pause(); 92 | return 1; 93 | } 94 | 95 | //print out archive info 96 | fseek(in, CONTENT_TITLE, SEEK_SET); 97 | fread(info, sizeof(wchar_t), 128, in); 98 | if (wcslen(&info[1]) > 0) 99 | printf("Title: %S\n", &info[1]); 100 | else 101 | printf("Title: \n"); 102 | fseek(in, CONTENT_DESC, SEEK_SET); 103 | fread(info, sizeof(wchar_t), 128, in); 104 | if (wcslen(&info[1]) > 0) 105 | printf("Desc: %S\n", &info[1]); 106 | fseek(in, CONTENT_PUBLISHER, SEEK_SET); 107 | fread(info, sizeof(wchar_t), 128, in); 108 | if (wcslen(&info[1]) > 0) 109 | printf("Publisher: %S\n", &info[1]); 110 | 111 | //warnings 112 | printf("\nWARNING: currently offsets aren't calulated correctly.\nOnly file name, parent and size are 100%% correct.\nNote offsets are also one unit higher than they should be\n\n"); 113 | 114 | //print out directory contents 115 | printf("%-40s %9s Offset (from 0x%08X)\n", "Filename", "Size", DIR_OFFSET); 116 | fseek(in, DIR_OFFSET, SEEK_SET); 117 | fread(files, sizeof(fileEntry), 64, in); 118 | for(i=0; files[i].name[0] != 0; i++) { 119 | if (files[i].offset != 0) { //skip directories 120 | filePath[0] = 0; 121 | sprintFileEntry(filePath, files, i); 122 | printf("%-40s %9d 0x%08X\n", filePath, bswap32(files[i].size), bswap32(files[i].offset)); 123 | } 124 | } 125 | fclose(in); 126 | pause(); 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /pirstools/AUTHORS: -------------------------------------------------------------------------------- 1 | * superjedi 2 | -------------------------------------------------------------------------------- /pirstools/CREDITS: -------------------------------------------------------------------------------- 1 | A big thanks to these peoples: 2 | 3 | Warren 4 | Thomas 5 | Dave 6 | 7 | Without them, pirstools wouldn't have existed ;-) 8 | -------------------------------------------------------------------------------- /pirstools/ChangeLog: -------------------------------------------------------------------------------- 1 | 2005-12-13 superjedi 2 | * Fixed a bug in pirs_get_titles () and pirs_get_descriptions () 3 | 4 | 2005-12-11 superjedi 5 | 6 | * First release, version 0.1 7 | * All the functions have been splitted in a library, libpirs 8 | -------------------------------------------------------------------------------- /pirstools/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src 2 | -------------------------------------------------------------------------------- /pirstools/NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/pirstools/NEWS -------------------------------------------------------------------------------- /pirstools/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/pirstools/README -------------------------------------------------------------------------------- /pirstools/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | libtoolize 3 | aclocal && autoconf && automake --add-missing 4 | -------------------------------------------------------------------------------- /pirstools/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_DLFCN_H 1 6 | 7 | /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ 8 | /* #undef HAVE_DOPRNT */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_FCNTL_H 1 12 | 13 | /* Define to 1 if you have the `getpagesize' function. */ 14 | #define HAVE_GETPAGESIZE 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_INTTYPES_H 1 18 | 19 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 20 | to 0 otherwise. */ 21 | #define HAVE_MALLOC 1 22 | 23 | /* Define to 1 if you have the header file. */ 24 | #define HAVE_MEMORY_H 1 25 | 26 | /* Define to 1 if you have a working `mmap' system call. */ 27 | #define HAVE_MMAP 1 28 | 29 | /* Define to 1 if you have the `munmap' function. */ 30 | #define HAVE_MUNMAP 1 31 | 32 | /* Define to 1 if you have the header file. */ 33 | #define HAVE_STDINT_H 1 34 | 35 | /* Define to 1 if you have the header file. */ 36 | #define HAVE_STDLIB_H 1 37 | 38 | /* Define to 1 if you have the `strdup' function. */ 39 | #define HAVE_STRDUP 1 40 | 41 | /* Define to 1 if you have the `strerror' function. */ 42 | #define HAVE_STRERROR 1 43 | 44 | /* Define to 1 if you have the header file. */ 45 | #define HAVE_STRINGS_H 1 46 | 47 | /* Define to 1 if you have the header file. */ 48 | #define HAVE_STRING_H 1 49 | 50 | /* Define to 1 if you have the header file. */ 51 | #define HAVE_SYS_STAT_H 1 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #define HAVE_SYS_TYPES_H 1 55 | 56 | /* Define to 1 if you have the header file. */ 57 | #define HAVE_UNISTD_H 1 58 | 59 | /* Define to 1 if you have the `vprintf' function. */ 60 | #define HAVE_VPRINTF 1 61 | 62 | /* Name of package */ 63 | #define PACKAGE "pirstools" 64 | 65 | /* Define to the address where bug reports for this package should be sent. */ 66 | #define PACKAGE_BUGREPORT "ziga@phear.org" 67 | 68 | /* Define to the full name of this package. */ 69 | #define PACKAGE_NAME "pirstools" 70 | 71 | /* Define to the full name and version of this package. */ 72 | #define PACKAGE_STRING "pirstools 0.1" 73 | 74 | /* Define to the one symbol short name of this package. */ 75 | #define PACKAGE_TARNAME "pirstools" 76 | 77 | /* Define to the version of this package. */ 78 | #define PACKAGE_VERSION "0.1" 79 | 80 | /* Define to 1 if you have the ANSI C header files. */ 81 | #define STDC_HEADERS 1 82 | 83 | /* Version number of package */ 84 | #define VERSION "0.1" 85 | 86 | /* Define to empty if `const' does not conform to ANSI C. */ 87 | /* #undef const */ 88 | 89 | /* Define to `__inline__' or `__inline' if that's what the C compiler 90 | calls it, or to nothing if 'inline' is not supported under any name. */ 91 | #ifndef __cplusplus 92 | /* #undef inline */ 93 | #endif 94 | 95 | /* Define to rpl_malloc if the replacement function should be used. */ 96 | /* #undef malloc */ 97 | -------------------------------------------------------------------------------- /pirstools/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.59) 5 | AC_INIT([pirstools], [0.1], [ziga@phear.org]) 6 | AC_CONFIG_HEADER([config.h]) 7 | AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) 8 | 9 | AC_CONFIG_SRCDIR([src/pirsread.c]) 10 | 11 | # Checks for programs. 12 | AC_PROG_CC 13 | AC_PROG_MAKE_SET 14 | AC_PROG_LIBTOOL 15 | 16 | # Checks for header files. 17 | AC_HEADER_STDC 18 | AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h]) 19 | 20 | # Checks for typedefs, structures, and compiler characteristics. 21 | AC_C_CONST 22 | AC_C_INLINE 23 | 24 | # Checks for library functions. 25 | AC_FUNC_MALLOC 26 | AC_FUNC_MMAP 27 | AC_FUNC_VPRINTF 28 | AC_CHECK_FUNCS([munmap strdup strerror]) 29 | 30 | AC_CONFIG_FILES([Makefile 31 | src/Makefile 32 | src/lib/Makefile]) 33 | AC_OUTPUT 34 | -------------------------------------------------------------------------------- /pirstools/src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = pirsread pirs 2 | 3 | pirsread_SOURCES = \ 4 | util.c \ 5 | pirs_display.c \ 6 | pirsread.c \ 7 | util.h \ 8 | pirs_display.h 9 | 10 | pirs_SOURCES = \ 11 | pirs.c 12 | 13 | pirs_LDADD = \ 14 | @LIBS@ $(top_builddir)/src/lib/libpirs.la 15 | 16 | pirsread_LDADD = \ 17 | @LIBS@ $(top_builddir)/src/lib/libpirs.la 18 | 19 | pirsreadincludedir = -I$(top_srcdir)/src/lib 20 | pirsincludedir = -I$(top_srcdir)/src/lib 21 | 22 | pirsreaddir = $(includedir)/pirsread 23 | pirsdir = $(includedir)/pirsread 24 | 25 | pirsread_HEADERS = \ 26 | util.h \ 27 | pirs_display.h 28 | 29 | SUBDIRS = lib 30 | 31 | AM_CPPFLAGS = \ 32 | -Wall -Werror 33 | 34 | INCLUDES = $(pirsreadincludedir) $(pirsincludedir) 35 | 36 | CLEANFILES = core core.* *~ 37 | 38 | indent: 39 | indent -gnu -nut *.c *.h 40 | 41 | strip: 42 | strip pirsread 43 | -------------------------------------------------------------------------------- /pirstools/src/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libpirs.la 2 | 3 | libpirs_la_SOURCES = \ 4 | pirs_alloc.c \ 5 | pirs_alloc.h \ 6 | pirs_hashtables.c \ 7 | pirs_hashtables.h \ 8 | pirs_filetable.c \ 9 | pirs_filetable.h \ 10 | pirs_datatypes.h \ 11 | pirs_main.c \ 12 | pirs_main.h \ 13 | pirs_titles.c \ 14 | pirs_titles.h \ 15 | pirs_desc.c \ 16 | pirs_desc.h \ 17 | pirs_extract.c \ 18 | pirs_extract.h \ 19 | util.c \ 20 | util.h \ 21 | libpirs.h \ 22 | sha1.c \ 23 | sha1.h 24 | 25 | 26 | libpirs_la_LDFLAGS = -version-info 0:1:0 27 | 28 | all: libpirs.la 29 | @echo Done. 30 | -------------------------------------------------------------------------------- /pirstools/src/lib/libpirs.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBPIRS_H 2 | #define LIBPIRS_H 3 | 4 | #include "pirs_main.h" 5 | #include "pirs_datatypes.h" 6 | #include "pirs_extract.h" 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_alloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "util.h" 5 | #include "pirs_datatypes.h" 6 | #include "pirs_alloc.h" 7 | 8 | pirs_dt_table * 9 | pirs_alloc_table (unsigned int width, unsigned int nent, const char *name) 10 | { 11 | pirs_dt_table *table = malloc (sizeof (pirs_dt_table)); 12 | 13 | table->width = width; 14 | table->nent = nent; 15 | table->name = strdup (name); 16 | table->entries = malloc (sizeof (pirs_dt_table_ent *) * nent); 17 | table->header = malloc (sizeof (char *) * width); 18 | table->noheader = 0; 19 | 20 | return table; 21 | } 22 | 23 | pirs_object * 24 | pirs_alloc_object (pirs_dt_object type, void *ptr) 25 | { 26 | pirs_object *object = malloc (sizeof (pirs_object)); 27 | 28 | object->type = type; 29 | object->ptr = ptr; 30 | 31 | return object; 32 | } 33 | 34 | pirs_dt_table_ent * 35 | pirs_alloc_table_ent (pirs_dt_field type, unsigned long content) 36 | { 37 | pirs_dt_table_ent *ent = malloc (sizeof (pirs_dt_table_ent)); 38 | 39 | ent->type = type; 40 | ent->content = content; 41 | 42 | return ent; 43 | } 44 | 45 | pirs_chunk * 46 | pirs_alloc_chunk (unsigned long start, unsigned long end) 47 | { 48 | pirs_chunk *chunk = malloc (sizeof (pirs_chunk)); 49 | 50 | chunk->start = start; 51 | chunk->end = end; 52 | chunk->next = NULL; 53 | 54 | return chunk; 55 | } 56 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef PIRS_ALLOC_H 2 | #define PIRS_ALLOC_H 3 | 4 | #include "pirs_datatypes.h" 5 | 6 | pirs_dt_table *pirs_alloc_table (unsigned int width, unsigned int nent, const char *name); 7 | pirs_object *pirs_alloc_object (pirs_dt_object type, void *ptr); 8 | pirs_dt_table_ent *pirs_alloc_table_ent (pirs_dt_field type, unsigned long content); 9 | pirs_chunk *pirs_alloc_chunk (unsigned long start, unsigned long end); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_datatypes.h: -------------------------------------------------------------------------------- 1 | #ifndef PIRS_DATATYPES_H 2 | #define PIRS_DATATYPES_H 3 | 4 | /* This header defines an abstraction layer to the objects retrieved from the PIRS loader */ 5 | 6 | typedef enum { 7 | Table, 8 | Line 9 | } pirs_dt_object; 10 | 11 | typedef enum { 12 | Hexa32, 13 | Hexa16, 14 | Bits, 15 | String 16 | } pirs_dt_field; 17 | 18 | typedef struct { 19 | pirs_dt_field type; 20 | unsigned long content; 21 | } pirs_dt_table_ent; 22 | 23 | typedef struct { 24 | unsigned int width; 25 | unsigned int nent; /* Number of entries */ 26 | char *name; 27 | char **header; 28 | int noheader; 29 | pirs_dt_table_ent **entries; 30 | } pirs_dt_table; 31 | 32 | typedef struct { 33 | void *ptr; 34 | } pirs_dt_line; 35 | 36 | typedef struct { 37 | pirs_dt_object type; 38 | union { 39 | pirs_dt_table *table; 40 | pirs_dt_line *line; 41 | void *ptr; 42 | }; 43 | } pirs_object; 44 | 45 | 46 | struct _pirs_chunk { 47 | unsigned long start; 48 | unsigned long end; 49 | struct _pirs_chunk *next; 50 | }; 51 | 52 | typedef struct _pirs_chunk pirs_chunk; 53 | 54 | #define DWORD unsigned long 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_desc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "pirs_main.h" 5 | #include "pirs_datatypes.h" 6 | #include "pirs_alloc.h" 7 | #include "pirs_desc.h" 8 | #include "util.h" 9 | 10 | /* *INDENT-OFF* */ 11 | static pirs_desc_languages_t languages[] = { 12 | { P_OFF_DESC_ENGLISH, "English" }, 13 | { P_OFF_DESC_UNKNOWN0, "Unknown 0" }, 14 | { P_OFF_DESC_GERMAN, "German" }, 15 | { P_OFF_DESC_FRENCH, "French" }, 16 | { P_OFF_DESC_SPANISH, "Spanish" }, 17 | { P_OFF_DESC_ITALIAN, "Italian" }, 18 | { P_OFF_DESC_UNKNOWN1, "Unknown 1" }, 19 | { P_OFF_DESC_UNKNOWN2, "Unknown 2" }, 20 | { P_OFF_DESC_PORTUGUESE, "Portuguese" }, 21 | { 0, 0 } 22 | }; 23 | /* *INDENT-ON* */ 24 | 25 | pirs_object *pirs_get_descriptions(pirs_t * pirs) 26 | { 27 | pirs_dt_table *table; 28 | const char *desc_utf8; 29 | int height; 30 | int i, j; 31 | 32 | /* Calculate the number of descriptions */ 33 | height = 0; 34 | 35 | for (i = 0; languages[i].offset; i++) { 36 | desc_utf8 = (const char *) &(pirs->buf[languages[i].offset + 2]); 37 | 38 | if (desc_utf8[0] == '\0') 39 | continue; 40 | 41 | height++; 42 | } 43 | 44 | table = pirs_alloc_table(2, height * 2, "Description"); 45 | 46 | table->header[0] = "Language"; 47 | table->header[1] = "Description"; 48 | 49 | j = 0; 50 | 51 | for (i = 0; languages[i].offset; i++) { 52 | char desc_iso[P_SIZ_DESC]; 53 | 54 | desc_utf8 = (const char *) &(pirs->buf[languages[i].offset + 2]); 55 | 56 | if (desc_utf8[0] == '\0') 57 | continue; 58 | 59 | utf8_to_iso(desc_utf8, desc_iso); 60 | 61 | table->entries[j++] = pirs_alloc_table_ent(String, (unsigned long) strdup(languages[i].language)); 62 | table->entries[j++] = pirs_alloc_table_ent(String, (unsigned long) strdup(desc_iso)); 63 | } 64 | 65 | return pirs_alloc_object(Table, table); 66 | } 67 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_desc.h: -------------------------------------------------------------------------------- 1 | #ifndef PIRS_DESC_H 2 | #define PIRS_DESC_H 3 | 4 | typedef struct { 5 | unsigned int offset; 6 | const char *language; 7 | } pirs_desc_languages_t; 8 | 9 | pirs_object *pirs_get_descriptions (pirs_t *pirs); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_extract.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "pirs_main.h" 4 | #include "pirs_datatypes.h" 5 | #include "pirs_filetable.h" 6 | #include "pirs_extract.h" 7 | #include "pirs_hashtables.h" 8 | #include "pirs_alloc.h" 9 | #include "util.h" 10 | 11 | pirs_chunk *pirs_extract_chunks(pirs_t * pirs, const char *data, unsigned int offset, unsigned int size) 12 | { 13 | pirs_chunk *hash_chunks = pirs_get_hashtables_offsets(pirs); 14 | pirs_chunk *hash_tmp; 15 | pirs_chunk *data_chunks; 16 | pirs_chunk *data_tmp; 17 | 18 | hash_tmp = hash_chunks; 19 | 20 | data_chunks = data_tmp = NULL; 21 | 22 | while (1) { 23 | /* Look if it overlaps */ 24 | while (hash_tmp) { 25 | if (hash_tmp->start > offset && hash_tmp->start < offset + size) { /* Hash table start inside the data */ 26 | if (data_tmp == NULL) { 27 | data_tmp = 28 | pirs_alloc_chunk((unsigned long) pirs->buf + offset, 29 | (unsigned long) pirs->buf + hash_tmp->start); 30 | data_chunks = data_tmp; 31 | } else { 32 | data_tmp->next = 33 | pirs_alloc_chunk((unsigned long) pirs->buf + offset, 34 | (unsigned long) pirs->buf + hash_tmp->start); 35 | data_tmp = data_tmp->next; 36 | } 37 | 38 | size -= hash_tmp->start - offset; 39 | offset = hash_tmp->end; 40 | 41 | break; 42 | } 43 | 44 | hash_tmp = hash_tmp->next; 45 | } 46 | 47 | /* Last chunk */ 48 | if (hash_tmp == NULL) { 49 | if (data_tmp == NULL) { 50 | data_tmp = 51 | pirs_alloc_chunk((unsigned long) pirs->buf + offset, (unsigned long) pirs->buf + (offset + size)); 52 | data_chunks = data_tmp; 53 | } else { 54 | data_tmp->next = 55 | pirs_alloc_chunk((unsigned long) pirs->buf + offset, (unsigned long) pirs->buf + (offset + size)); 56 | } 57 | 58 | break; 59 | } 60 | } 61 | 62 | return data_chunks; 63 | } 64 | 65 | 66 | int pirs_extract_all(pirs_t * pirs, const char *basepath, pirs_extract_callback callback) 67 | { 68 | pirs_object *obj = pirs_get_filetable(pirs); 69 | pirs_object *dirs = pirs_get_directories(pirs); 70 | int i, j; 71 | 72 | for (i = j = 0; i < obj->table->nent / obj->table->width; i++) { 73 | const char *filetype, *filename, *data; 74 | const char *pirs_dir, *output_dir; 75 | unsigned long size; 76 | unsigned long offset; 77 | pirs_chunk *chunks; 78 | 79 | filename = (const char *) obj->table->entries[i * obj->table->width]->content; 80 | filetype = (const char *) obj->table->entries[i * obj->table->width + 1]->content; 81 | 82 | if (strcmp(filetype, "File") != 0) 83 | continue; 84 | 85 | pirs_dir = 86 | pirs_resolve_directory(dirs->table, 87 | (unsigned long) obj->table->entries[i * obj->table->width + 4]->content); 88 | 89 | if (strcmp (pirs_dir, "/") == 0) 90 | output_dir = strdup (basepath); 91 | else 92 | output_dir = str_concatenate(basepath, pirs_dir, 0); 93 | 94 | offset = obj->table->entries[i * obj->table->width + 3]->content; 95 | size = (unsigned long) obj->table->entries[i * obj->table->width + 5]->content; 96 | 97 | data = pirs->buf + offset; 98 | 99 | chunks = pirs_extract_chunks(pirs, data, offset, size); 100 | 101 | callback(pirs, output_dir, filename, chunks); 102 | 103 | free(output_dir); 104 | j++; 105 | } 106 | 107 | return j; 108 | } 109 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_extract.h: -------------------------------------------------------------------------------- 1 | #ifndef PIRS_EXTRACT_H 2 | #define PIRS_EXTRACT_H 3 | 4 | #include "pirs_main.h" 5 | #include "pirs_datatypes.h" 6 | 7 | typedef void (* pirs_extract_callback)(pirs_t *pirs, const char *path, const char *filename, pirs_chunk *chunks); 8 | 9 | int pirs_extract_all (pirs_t *pirs, const char *basepath, pirs_extract_callback callback); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_filetable.h: -------------------------------------------------------------------------------- 1 | #ifndef PIRS_FILETABLET_H 2 | #define PIRS_FILETABLET_H 3 | 4 | #include 5 | 6 | pirs_object *pirs_get_filetable (pirs_t *pirs); 7 | pirs_object *pirs_get_directories (pirs_t *pirs); 8 | const char *pirs_resolve_directory (pirs_dt_table *dirs, unsigned long id); 9 | 10 | struct __pears_file_ent { 11 | char filename[40]; /* Filename */ 12 | uint32_t unknown0; /* Unknown 0 */ 13 | struct { 14 | uint8_t unknown0; /* Offset: Unknown 0 */ 15 | uint8_t unknown1; /* Offset: Unknown 1 */ 16 | uint8_t unknown2; /* Offset: Unknown 2 */ 17 | uint8_t base0:4; /* Offset multiplication factor */ 18 | uint8_t base1:4; /* Base offset (Upper 4 bits) */ 19 | uint8_t base2; /* Base offset (Lower 8 bits) */ 20 | } offset; 21 | uint8_t unknown6; /* Unknown 6 */ 22 | uint16_t diridx; /* Index in the Directory tree */ 23 | uint32_t size; /* Size of the file */ 24 | uint32_t unknown4; /* Unknown 4 */ 25 | uint32_t unknown5; /* Unknown 5 */ 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_hashtables.h: -------------------------------------------------------------------------------- 1 | #ifndef PIRS_HASHES_H 2 | #define PIRS_HASHES_H 3 | 4 | #include 5 | 6 | pirs_object **pirs_get_hashtables (pirs_t *pirs); 7 | unsigned int pirs_count_hashtables (pirs_t *pirs); 8 | pirs_chunk *pirs_get_hashtables_offsets (pirs_t *pirs); 9 | 10 | struct __pears_hash_ent { 11 | uint32_t A; /* SHA-1: A */ 12 | uint32_t B; /* SHA-1: B */ 13 | uint32_t C; /* SHA-1: C */ 14 | uint32_t D; /* SHA-1: D */ 15 | uint32_t E; /* SHA-1: E */ 16 | uint32_t unknown0; /* Unknown 5 */ 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #ifndef __WIN32__ 9 | # include 10 | #endif 11 | #include "util.h" 12 | #include "pirs_datatypes.h" 13 | #include "pirs_filetable.h" 14 | #include "pirs_hashtables.h" 15 | #include "pirs_titles.h" 16 | #include "pirs_desc.h" 17 | #include "pirs_main.h" 18 | 19 | 20 | #ifdef __WIN32__ 21 | static int oflags = O_RDONLY | _O_BINARY; /* Set the file mode to Binary */ 22 | #else 23 | static int oflags = O_RDONLY; 24 | #endif 25 | 26 | pirs_object **pirs_get_all(pirs_t * pirs) 27 | { 28 | pirs_object **objects; 29 | pirs_object **temp; 30 | int nhashes, j, i = 0; 31 | 32 | nhashes = pirs_count_hashtables(pirs); 33 | 34 | objects = malloc(sizeof(pirs_object) * (nhashes + 5)); 35 | 36 | objects[i++] = pirs_get_titles(pirs); 37 | 38 | objects[i++] = pirs_get_descriptions(pirs); 39 | 40 | objects[i++] = pirs_get_filetable(pirs); 41 | 42 | objects[i++] = pirs_get_directories(pirs); 43 | 44 | temp = pirs_get_hashtables(pirs); 45 | 46 | for (j = 0; temp[j]; j++) 47 | objects[i++] = temp[j]; 48 | 49 | objects[i] = NULL; 50 | 51 | return objects; 52 | } 53 | 54 | pirs_t *pirs_load(const char *pathname) 55 | { 56 | struct stat statbuf; 57 | char *ptr; 58 | int tbw; 59 | pirs_t *pirs; 60 | 61 | tbw = 0; 62 | ptr = NULL; 63 | 64 | pirs = malloc(sizeof(pirs_t)); 65 | 66 | pirs->buf = NULL; 67 | 68 | pirs->fd = open(pathname, oflags); 69 | 70 | if (pirs->fd < 0) { 71 | pirs_error("Couldn't open %s: %s\n", pathname, strerror(errno)); 72 | goto cleanup; 73 | } 74 | 75 | fstat(pirs->fd, &statbuf); 76 | 77 | pirs->file_length = statbuf.st_size; 78 | 79 | #ifdef __WIN32__ 80 | pirs->buf = malloc(pirs->file_length); 81 | 82 | tbw = pirs->file_length; 83 | ptr = (char *) pirs->buf; 84 | 85 | do { 86 | int nb = read(pirs->fd, ptr, tbw); 87 | 88 | if (nb < 0) { 89 | if (nb == -1 && errno == EINTR) 90 | continue; 91 | 92 | close(pirs->fd); 93 | 94 | pirs_error("Couldn't read %s: %s\n", pathname, strerror(errno)); 95 | 96 | goto cleanup; 97 | } 98 | 99 | tbw -= nb; 100 | ptr += nb; 101 | } while (tbw > 0); 102 | #else 103 | pirs->buf = mmap(NULL, pirs->file_length, PROT_READ, MAP_PRIVATE, pirs->fd, 0); 104 | #endif 105 | 106 | return pirs; 107 | 108 | cleanup: 109 | 110 | if (pirs->buf) 111 | #ifdef __WIN32__ 112 | free((void *) pirs->buf); 113 | #else 114 | munmap((void *) pirs->buf, pirs->file_length); 115 | #endif 116 | 117 | free(pirs); 118 | 119 | close(pirs->fd); 120 | 121 | return NULL; 122 | } 123 | 124 | void pirs_unload(pirs_t * pirs) 125 | { 126 | if (pirs->buf) 127 | #ifdef __WIN32__ 128 | free((void *) pirs->buf); 129 | #else 130 | munmap((void *) pirs->buf, pirs->file_length); 131 | #endif 132 | 133 | free(pirs); 134 | 135 | close(pirs->fd); 136 | 137 | } 138 | 139 | int pirs_validate(pirs_t * pirs) 140 | { 141 | DWORD magic = get_dword(pirs, P_OFF_MAG); 142 | 143 | if (magic != PIRS_MAGIC && magic != LIVE_MAGIC) 144 | return 0; 145 | 146 | return 1; 147 | } 148 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_main.h: -------------------------------------------------------------------------------- 1 | #ifndef PIRS_MAIN_H 2 | #define PIRS_MAIN_H 3 | 4 | #include "pirs_datatypes.h" 5 | 6 | #define PIRS_MAGIC00 'P' 7 | #define PIRS_MAGIC01 'I' 8 | #define PIRS_MAGIC02 'R' 9 | #define PIRS_MAGIC03 'S' 10 | 11 | #define LIVE_MAGIC00 'L' 12 | #define LIVE_MAGIC01 'I' 13 | #define LIVE_MAGIC02 'V' 14 | #define LIVE_MAGIC03 'E' 15 | 16 | #define PIRS_MAGIC 0x50495253 /* Big endian */ 17 | #define LIVE_MAGIC 0x4C495645 /* Big endian */ 18 | 19 | #define P_OFF_MAG 0x0000 20 | #define P_OFF_HASHTABLE 0xb000 21 | #define P_OFF_FILETABLE 0xc000 22 | #define P_OFF_DATA 0xd000 23 | #define P_OFF_HASHESOFHASHTABLE 0xb6000 24 | 25 | /* Titles */ 26 | #define P_OFF_TIT_ENGLISH 0x0410 27 | #define P_OFF_TIT_UNKNOWN0 0x0510 28 | #define P_OFF_TIT_GERMAN 0x0610 29 | #define P_OFF_TIT_FRENCH 0x0710 30 | #define P_OFF_TIT_SPANISH 0x0810 31 | #define P_OFF_TIT_ITALIAN 0x0910 32 | #define P_OFF_TIT_UNKNOWN1 0x0a10 33 | #define P_OFF_TIT_UNKNOWN2 0x0b10 34 | #define P_OFF_TIT_PORTUGUESE 0x0c10 35 | 36 | #define P_SIZ_TIT 256 37 | 38 | /* Descriptions */ 39 | #define P_OFF_DESC_ENGLISH 0x0d10 40 | #define P_OFF_DESC_UNKNOWN0 0x0e10 41 | #define P_OFF_DESC_GERMAN 0x0f10 42 | #define P_OFF_DESC_FRENCH 0x1010 43 | #define P_OFF_DESC_SPANISH 0x1110 44 | #define P_OFF_DESC_ITALIAN 0x1210 45 | #define P_OFF_DESC_UNKNOWN1 0x1310 46 | #define P_OFF_DESC_UNKNOWN2 0x1410 47 | #define P_OFF_DESC_PORTUGUESE 0x1510 48 | 49 | #define P_SIZ_DESC 256 50 | 51 | #define P_OFF_PUBLISHER 0x1610 52 | 53 | #define P_SIZ_PUBLISHER 256 54 | 55 | #define P_SIZ_HASHTABLE 0x1000 56 | #define P_SIZ_HASHDATASIZE 0x1000 57 | #define P_SIZ_HASHESOFHASHTABLE 0x1000 58 | 59 | typedef struct { 60 | const char *buf; 61 | unsigned int file_length; 62 | int fd; 63 | } pirs_t; 64 | 65 | pirs_t *pirs_load (const char *pathname); 66 | int pirs_validate (pirs_t *pirs); 67 | void pirs_unload (pirs_t *pirs); 68 | pirs_object **pirs_get_all (pirs_t *pirs); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_titles.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "pirs_main.h" 5 | #include "pirs_datatypes.h" 6 | #include "pirs_alloc.h" 7 | #include "pirs_titles.h" 8 | #include "util.h" 9 | 10 | /* *INDENT-OFF* */ 11 | static pirs_title_languages_t languages[] = { 12 | { P_OFF_TIT_ENGLISH, "English" }, 13 | { P_OFF_TIT_UNKNOWN0, "Unknown 0" }, 14 | { P_OFF_TIT_GERMAN, "German" }, 15 | { P_OFF_TIT_FRENCH, "French" }, 16 | { P_OFF_TIT_SPANISH, "Spanish" }, 17 | { P_OFF_TIT_ITALIAN, "Italian" }, 18 | { P_OFF_TIT_UNKNOWN1, "Unknown 1" }, 19 | { P_OFF_TIT_UNKNOWN2, "Unknown 2" }, 20 | { P_OFF_TIT_PORTUGUESE, "Portuguese" }, 21 | { 0, 0 } 22 | }; 23 | /* *INDENT-ON* */ 24 | 25 | pirs_object * 26 | pirs_get_titles (pirs_t * pirs) 27 | { 28 | pirs_dt_table *table; 29 | const char *title_utf8; 30 | int height; 31 | int i, j; 32 | 33 | /* Calculate the number of titles */ 34 | height = 0; 35 | 36 | for (i = 0; languages[i].offset; i++) 37 | { 38 | title_utf8 = (const char *) &(pirs->buf[languages[i].offset + 2]); 39 | 40 | if (title_utf8[0] == '\0') 41 | continue; 42 | 43 | height++; 44 | } 45 | 46 | table = pirs_alloc_table (2, height * 2, "Titles"); 47 | 48 | table->header[0] = "Language"; 49 | table->header[1] = "Title"; 50 | 51 | j = 0; 52 | 53 | for (i = 0; languages[i].offset; i++) 54 | { 55 | char title_iso[P_SIZ_TIT]; 56 | 57 | title_utf8 = (const char *) &(pirs->buf[languages[i].offset + 2]); 58 | 59 | if (title_utf8[0] == '\0') 60 | continue; 61 | 62 | utf8_to_iso (title_utf8, title_iso); 63 | 64 | table->entries[j++] = pirs_alloc_table_ent (String, (unsigned long) strdup (languages[i].language)); 65 | table->entries[j++] = pirs_alloc_table_ent (String, (unsigned long) strdup (title_iso)); 66 | } 67 | 68 | return pirs_alloc_object (Table, table); 69 | } 70 | -------------------------------------------------------------------------------- /pirstools/src/lib/pirs_titles.h: -------------------------------------------------------------------------------- 1 | #ifndef PIRS_TITLES_H 2 | #define PIRS_TITLES_H 3 | 4 | typedef struct { 5 | unsigned int offset; 6 | const char *language; 7 | } pirs_title_languages_t; 8 | 9 | pirs_object *pirs_get_titles (pirs_t *pirs); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pirstools/src/lib/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sha1.h 3 | * 4 | * Description: 5 | * This is the header file for code which implements the Secure 6 | * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published 7 | * April 17, 1995. 8 | * 9 | * Many of the variable names in this code, especially the 10 | * single character names, were used because those were the names 11 | * used in the publication. 12 | * 13 | * Please read the file sha1.c for more information. 14 | * 15 | */ 16 | 17 | #ifndef _SHA1_H_ 18 | #define _SHA1_H_ 19 | 20 | #include 21 | /* 22 | * If you do not have the ISO standard stdint.h header file, then you 23 | * must typdef the following: 24 | * name meaning 25 | * uint32_t unsigned 32 bit integer 26 | * uint8_t unsigned 8 bit integer (i.e., unsigned char) 27 | * int_least16_t integer of >= 16 bits 28 | * 29 | */ 30 | 31 | #ifndef _SHA_enum_ 32 | #define _SHA_enum_ 33 | enum 34 | { 35 | shaSuccess = 0, 36 | shaNull, /* Null pointer parameter */ 37 | shaInputTooLong, /* input data too long */ 38 | shaStateError /* called Input after Result */ 39 | }; 40 | #endif 41 | #define SHA1HashSize 20 42 | 43 | /* 44 | * This structure will hold context information for the SHA-1 45 | * hashing operation 46 | */ 47 | typedef struct SHA1Context 48 | { 49 | uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */ 50 | 51 | uint32_t Length_Low; /* Message length in bits */ 52 | uint32_t Length_High; /* Message length in bits */ 53 | 54 | /* Index into message block array */ 55 | int_least16_t Message_Block_Index; 56 | uint8_t Message_Block[64]; /* 512-bit message blocks */ 57 | 58 | int Computed; /* Is the digest computed? */ 59 | int Corrupted; /* Is the message digest corrupted? */ 60 | } SHA1Context; 61 | 62 | /* 63 | * Function Prototypes 64 | */ 65 | 66 | int SHA1Reset(SHA1Context *); 67 | int SHA1Input( SHA1Context *, 68 | const uint8_t *, 69 | unsigned int); 70 | int SHA1Result( SHA1Context *, 71 | uint8_t Message_Digest[SHA1HashSize]); 72 | 73 | int SHA1ResultInt32( SHA1Context *context, 74 | uint32_t Message_Digest[SHA1HashSize/4]); 75 | 76 | #endif /* _SHA1_H_ */ 77 | -------------------------------------------------------------------------------- /pirstools/src/lib/util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "pirs_main.h" 6 | #include "pirs_datatypes.h" 7 | #include "util.h" 8 | 9 | inline long get_dword(pirs_t * pirs, unsigned int offset) 10 | { 11 | return bs32(*((DWORD *) (pirs->buf + offset))); 12 | } 13 | 14 | void pirs_warning(char *fmt, ...) 15 | { 16 | va_list ap; 17 | 18 | va_start(ap, fmt); 19 | fprintf(stderr, "libpirs: ***WARNING*** "); 20 | vfprintf(stderr, fmt, ap); 21 | fprintf(stderr, "\n"); 22 | va_end(ap); 23 | } 24 | 25 | void pirs_error(char *fmt, ...) 26 | { 27 | va_list ap; 28 | 29 | va_start(ap, fmt); 30 | fprintf(stderr, "libpirs: ***ERROR*** "); 31 | vfprintf(stderr, fmt, ap); 32 | fprintf(stderr, "\n"); 33 | va_end(ap); 34 | } 35 | 36 | int utf8_to_iso(const char *utf8string, char *isobuffer) 37 | { 38 | int i, j; 39 | 40 | for (i = j = 0; utf8string[i]; i += 2) 41 | isobuffer[j++] = utf8string[i]; 42 | 43 | isobuffer[j] = '\0'; 44 | 45 | return j; 46 | } 47 | 48 | const char *str_concatenate(const char *s1, ...) 49 | { 50 | va_list ap; 51 | const char *s; 52 | char *buf, *ptr; 53 | int len = 0; 54 | 55 | /* Calculate the total length */ 56 | va_start(ap, s1); 57 | 58 | len += strlen(s1); 59 | 60 | while (1) { 61 | s = va_arg(ap, const char *); 62 | if (s == NULL) 63 | break; 64 | len += strlen(s); 65 | } 66 | 67 | va_end(ap); 68 | 69 | /* Allocate the memory */ 70 | buf = malloc(len + 1); 71 | 72 | /* Concatenate everything */ 73 | va_start(ap, s1); 74 | 75 | ptr = buf; 76 | 77 | strcpy(ptr, s1); 78 | ptr += strlen(s1); 79 | 80 | while (1) { 81 | s = va_arg(ap, const char *); 82 | if (s == NULL) 83 | break; 84 | 85 | strcpy(ptr, s); 86 | ptr += strlen(s); 87 | } 88 | 89 | va_end(ap); 90 | 91 | *ptr = '\0'; 92 | 93 | return (const char *) buf; 94 | } 95 | 96 | const char *strdup_printf(char *fmt, ...) 97 | { 98 | va_list ap; 99 | 100 | char buffer[MAX_STRDUP_PRINTF_BUF]; 101 | 102 | va_start(ap, fmt); 103 | vsnprintf(buffer, sizeof(buffer), fmt, ap); 104 | va_end(ap); 105 | 106 | return strdup(buffer); 107 | } 108 | -------------------------------------------------------------------------------- /pirstools/src/lib/util.h: -------------------------------------------------------------------------------- 1 | #ifndef SWISSKNIFE_H 2 | #define SWISSKNIFE_H 3 | 4 | #include "pirs_main.h" 5 | 6 | #define bs32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) 7 | #define bs16(x) ((((x) & 0x0000ff00) >> 8) | (((x) & 0x000000ff) << 8)) 8 | #define round(n, r) ((n) + ((r) - ((n) % (r)) == (r) ? 0 : (r) - ((n) % (r)))) 9 | #define bit_get(number, i) (((number) & (1 << (i))) > 0) 10 | 11 | inline long get_dword (pirs_t *pirs, unsigned int offset); 12 | 13 | void pirs_warning (char *fmt, ...); 14 | void pirs_error (char *fmt, ...); 15 | 16 | int utf8_to_iso (const char *utf8string, char *isobuffer); 17 | const char *str_concatenate (const char *s1, ...); 18 | const char *strdup_printf (char *fmt, ...); 19 | 20 | #define MAX_STRDUP_PRINTF_BUF 2048 21 | 22 | #ifndef MAX 23 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /pirstools/src/pirs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef __WIN32__ 13 | static int oflags = _O_BINARY; /* Set the file mode to Binary */ 14 | #else 15 | static int oflags = 0; 16 | #endif 17 | 18 | void usage(const char *pathname) 19 | { 20 | printf("Usage: %s \n", pathname); 21 | } 22 | 23 | void pirs_extract(pirs_t * pirs, const char *path, const char *filename, pirs_chunk * chunks) 24 | { 25 | const char *ptr; 26 | int tbw, fd; 27 | 28 | printf("Extracting %s/%s\n", path, filename); 29 | 30 | if (mkdir(path, 0755) == -1 && errno != EEXIST) { 31 | printf("Couldn't mkdir(%s): %s\n", path, strerror(errno)); 32 | return; 33 | } 34 | 35 | if (chdir(path) == -1) { 36 | printf("Couldn't chdir(%s): %s\n", path, strerror(errno)); 37 | return; 38 | } 39 | 40 | 41 | if ((fd = open(filename, O_CREAT | O_WRONLY | oflags, 0644)) == -1) { 42 | printf("Couldn't open %s: %s\n", filename, strerror(errno)); 43 | return; 44 | } 45 | 46 | while (chunks) { 47 | tbw = chunks->end - chunks->start; 48 | ptr = (const char *) chunks->start; 49 | 50 | do { 51 | int nb = write(fd, ptr, tbw); 52 | 53 | if (nb < 0) { 54 | if (nb == -1 && errno == EINTR) 55 | continue; 56 | 57 | close(fd); 58 | 59 | printf("Couldn't write %s: %s\n", filename, strerror(errno)); 60 | 61 | return; 62 | } 63 | 64 | tbw -= nb; 65 | ptr += nb; 66 | } while (tbw > 0); 67 | 68 | chunks = chunks->next; 69 | } 70 | 71 | close(fd); 72 | } 73 | 74 | int main(int argc, char **argv) 75 | { 76 | pirs_t *pirs; 77 | char basepath[PATH_MAX]; 78 | int n; 79 | 80 | if (argc < 3) { 81 | usage(argv[0]); 82 | return 1; 83 | } 84 | 85 | pirs = pirs_load(argv[1]); 86 | 87 | if (pirs == NULL) { 88 | printf("Couldn't open the pirs file, exiting..\n"); 89 | return 1; 90 | } 91 | 92 | /* Make sure the file is a PIRS File */ 93 | 94 | if (!pirs_validate(pirs)) { 95 | printf("Wrong file type, not a PIRS file\n"); 96 | goto cleanup; 97 | } 98 | 99 | if (mkdir(argv[2], 0755) == -1 && errno != EEXIST) { 100 | printf("Couldn't mkdir(%s): %s\n", argv[1], strerror(errno)); 101 | goto cleanup; 102 | } 103 | 104 | if (chdir(argv[2]) == -1) { 105 | printf("Couldn't chdir(%s): %s\n", argv[1], strerror(errno)); 106 | goto cleanup; 107 | } 108 | 109 | getcwd(basepath, sizeof(basepath)); 110 | 111 | n = pirs_extract_all(pirs, basepath, pirs_extract); 112 | 113 | printf("Extracted %d files\n", n); 114 | 115 | pirs_unload(pirs); 116 | 117 | return 0; 118 | 119 | cleanup: 120 | pirs_unload(pirs); 121 | 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /pirstools/src/pirs_display.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "util.h" 5 | #include "pirs_display.h" 6 | 7 | void pirs_print_table(pirs_dt_table * table) 8 | { 9 | char bits[36]; 10 | int *colsizes; 11 | int height; 12 | int i, j; 13 | 14 | printf("%s\n", table->name); 15 | 16 | if (!table->noheader) 17 | printf("\n"); 18 | 19 | printf(" "); 20 | 21 | colsizes = malloc(sizeof(int) * table->width); 22 | 23 | height = ((float) table->nent / (float) table->width + .99); 24 | 25 | for (i = 0; i < table->width; i++) { 26 | int len; 27 | 28 | if (table->noheader) 29 | colsizes[i] = 8; 30 | else { 31 | len = strlen(table->header[i]); 32 | 33 | colsizes[i] = len < 8 ? 9 : len + 2; 34 | } 35 | 36 | for (j = 0; j < height && (j * table->width + i) < table->nent; j++) { 37 | switch (table->entries[j * table->width + i]->type) { 38 | case Bits: 39 | colsizes[i] = MAX(colsizes[i], 36 + 2); 40 | break; 41 | case String:{ 42 | int len = strlen((const char *) table->entries[j * table->width + i]->content); 43 | colsizes[i] = MAX(colsizes[i], len + 2); 44 | break; 45 | } 46 | case Hexa32: 47 | case Hexa16: 48 | default: 49 | break; 50 | } 51 | } 52 | if (!table->noheader) 53 | printf("%-*s ", colsizes[i], table->header[i]); 54 | } 55 | 56 | printf("\n"); 57 | 58 | for (i = 0; i < height; i++) { 59 | printf("%4d: ", i + 1); 60 | for (j = 0; j < table->width && (i * table->width + j) < table->nent; j++) { 61 | switch (table->entries[i * table->width + j]->type) { 62 | case Hexa32: 63 | printf("%-*.08lx ", colsizes[j], table->entries[i * table->width + j]->content); 64 | break; 65 | case Hexa16: 66 | printf("%-*.04lx ", colsizes[j], table->entries[i * table->width + j]->content); 67 | break; 68 | case Bits: 69 | sprint_bits(bits, table->entries[i * table->width + j]->content); 70 | printf("%-*s ", colsizes[j], bits); 71 | break; 72 | case String: 73 | printf("%-*s ", colsizes[j], (char *) table->entries[i * table->width + j]->content); 74 | break; 75 | default: 76 | printf("Unknown table entry type: %d\n", table->entries[i * table->width + j]->type); 77 | abort(); 78 | } 79 | } 80 | printf("\n"); 81 | } 82 | 83 | printf("\n"); 84 | 85 | free(colsizes); 86 | } 87 | 88 | void pirs_print_object(pirs_object * object) 89 | { 90 | switch (object->type) { 91 | case Table: 92 | pirs_print_table(object->table); 93 | break; 94 | case Line: 95 | break; 96 | default: 97 | printf("Unknown object type: %d\n", object->type); 98 | abort(); 99 | } 100 | } 101 | 102 | void pirs_print_objects(pirs_object ** objects) 103 | { 104 | int i; 105 | 106 | for (i = 0; objects[i]; i++) 107 | pirs_print_object(objects[i]); 108 | } 109 | -------------------------------------------------------------------------------- /pirstools/src/pirs_display.h: -------------------------------------------------------------------------------- 1 | #ifndef XEX_DISPLAY_H 2 | #define XEX_DISPLAY_H 3 | 4 | #include "pirs_datatypes.h" 5 | 6 | void pirs_print_table (pirs_dt_table *table); 7 | void pirs_print_object (pirs_object *object); 8 | void pirs_print_objects (pirs_object **objects); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pirstools/src/pirsread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "pirs_display.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | pirs_t *pirs; 8 | pirs_object **content; 9 | 10 | pirs = pirs_load(argv[1]); 11 | 12 | if (pirs == NULL) { 13 | printf("Couldn't open the pirs file, exiting..\n"); 14 | return 1; 15 | } 16 | 17 | /* Make sure the file is a PIRS File */ 18 | 19 | if (!pirs_validate(pirs)) { 20 | printf("Wrong file type, not a PIRS file\n"); 21 | goto cleanup; 22 | } 23 | 24 | printf ("Analyzing file, this may take a while..\n"); 25 | 26 | content = pirs_get_all(pirs); 27 | 28 | pirs_print_objects(content); 29 | 30 | pirs_unload(pirs); 31 | 32 | return 0; 33 | 34 | cleanup: 35 | pirs_unload(pirs); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /pirstools/src/test.sh: -------------------------------------------------------------------------------- 1 | replace swissknife util < $1 > $1.rep && mv $1.rep $1 2 | -------------------------------------------------------------------------------- /pirstools/src/util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "util.h" 4 | 5 | inline void sprint_bits(char *buffer, unsigned int number) 6 | { 7 | int i, y; 8 | 9 | for (i = y = 0; i < 32; i++) { 10 | buffer[y++] = '0' + bit_get(number, 31 - i); 11 | 12 | if (!((i + 1) % 8) && i != 31) 13 | buffer[y++] = ' '; 14 | } 15 | 16 | buffer[y] = '\0'; 17 | } 18 | -------------------------------------------------------------------------------- /pirstools/src/util.h: -------------------------------------------------------------------------------- 1 | #ifndef SWISSKNIFE_H 2 | #define SWISSKNIFE_H 3 | 4 | inline void sprint_bits (char *buffer, unsigned int number); 5 | 6 | #define bit_get(number, i) (((number) & (1 << (i))) > 0) 7 | 8 | #ifndef MAX 9 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) 10 | #endif 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /reset_glitch_hack/cdxell/CD.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/reset_glitch_hack/cdxell/CD.tpl -------------------------------------------------------------------------------- /reset_glitch_hack/cdxell/CDjasper.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/reset_glitch_hack/cdxell/CDjasper.tpl -------------------------------------------------------------------------------- /reset_glitch_hack/cdxell/Makefile: -------------------------------------------------------------------------------- 1 | CROSS=xenon- 2 | CC=$(CROSS)gcc 3 | OBJCOPY=$(CROSS)objcopy 4 | LD=$(CROSS)ld 5 | AS=$(CROSS)as 6 | STRIP=$(CROSS)strip 7 | 8 | # Configuration 9 | AFLAGS = -m64 10 | 11 | # Build rules 12 | all: CD CDjasper 13 | 14 | clean: 15 | rm -rf cdxell.o cdxell.bin CD CDjasper 16 | 17 | .S.o: 18 | $(CC) $(AFLAGS) -c -o $@ $*.S 19 | 20 | %.bin: %.o 21 | $(OBJCOPY) -O binary $< $@ 22 | 23 | CD: cdxell.bin 24 | cp CD.tpl CD 25 | dd bs=624 seek=1 if=cdxell.bin of=CD conv=notrunc 26 | 27 | CDjasper: cdxell.bin 28 | cp CDjasper.tpl CDjasper 29 | dd bs=624 seek=1 if=cdxell.bin of=CDjasper conv=notrunc -------------------------------------------------------------------------------- /reset_glitch_hack/cdxell/cdxell.S: -------------------------------------------------------------------------------- 1 | #include "xenonsprs.h" 2 | 3 | .macro PATCH Address 4 | .set Pc, \Address 5 | .quad \Address 6 | .long (9f-8f)/4 //Length of patch in words 7 | .endm 8 | 9 | _start: 10 | .globl _start 11 | 12 | bl init_regs 13 | 14 | /* POST = 0x10 */ 15 | li %r3, 0x10 16 | rldicr %r3, %r3, 56, 7 17 | std %r3, 0(%r7) 18 | 19 | bl init_pci 20 | 21 | /* send SMC query for powerup reason */ 22 | stw %r9, 0x1084(%r8) /* 00000004 (byteswapped) */ 23 | stw %r10, 0x1080(%r8) /* 01000000 */ 24 | stw %r11, 0x1080(%r8) /* 00000000 */ 25 | stw %r11, 0x1080(%r8) /* 00000000 */ 26 | stw %r11, 0x1080(%r8) /* 00000000 */ 27 | stw %r11, 0x1084(%r8) /* 00000000 */ 28 | 29 | /* wait for SMC answer */ 30 | 1: 31 | lwz %r12, 0x1094(%r8) 32 | and. %r12, %r12, %r9 /* check for 04 (swapped) */ 33 | beq 1b 34 | stw %r9, 0x1094(%r8) /* 00000004 (byteswapped) */ 35 | lwz %r12, 0x1090(%r8) 36 | lwz %r3, 0x1090(%r8) 37 | lwz %r3, 0x1090(%r8) 38 | lwz %r3, 0x1090(%r8) 39 | stw %r11, 0x1094(%r8) /* 00000000 */ 40 | rlwinm %r3, %r12, 8, 24, 31 41 | cmpwi %r3, 0x1 42 | bne 1b 43 | 44 | /* set HRMOR=0 for main core */ 45 | mtspr hrmor,%r11 46 | 47 | /* POST = 0x11 */ 48 | li %r3, 0x11 49 | rldicr %r3, %r3, 56, 7 50 | std %r3, 0(%r7) 51 | 52 | /* Copy from Flash, src = %r5, dst = %r6 */ 53 | 54 | rlwinm %r3, %r12, 16, 24, 31 55 | cmpwi %r3, 0x5a /* poweron by pressing guide button while connected to the back USB (lowest one on slim) */ 56 | beq backup_xell 57 | cmpwi %r3, 0x24 /* poweron by pressing the windows button on the IR remote */ 58 | beq backup_xell 59 | 60 | mr %r5,%r15 61 | 62 | backup_xell: 63 | 64 | mr %r9,%r6 65 | lis %r4, 1 /* 256k */ 66 | mtctr %r4 67 | 68 | 1: lwz %r8, 0(%r5) //Memcopy 69 | stw %r8, 0(%r6) 70 | dcbst %r0, %r6 //Flush cache to ram 71 | icbi %r0, %r6 72 | sync 0 73 | isync 74 | addi %r6, %r6, 4 75 | addi %r5, %r5, 4 76 | bdnz 1b 77 | 78 | /* POST = 0x12 */ 79 | li %r3, 0x12 80 | rldicr %r3, %r3, 56, 7 81 | std %r3, 0(%r7) 82 | 83 | /* Clear IR/DR and jump to Xell*/ 84 | li %r4, 0x30 85 | mfmsr %r3 86 | andc %r3, %r3, %r4 87 | mtsrr1 %r3 88 | mtsrr0 %r9 89 | rfid 90 | 91 | init_regs: 92 | /* init regs */ 93 | li %r5,0x200 94 | oris %r5,%r5,0x8000 95 | rldicr %r5,%r5,32,31 96 | oris %r5,%r5,0xc80c 97 | 98 | li %r15,0x200 99 | oris %r15,%r15,0x8000 100 | rldicr %r15,%r15,32,31 101 | oris %r15,%r15,0xc810 102 | 103 | lis %r6,0x8000 104 | rldicr %r6,%r6,32,31 105 | oris %r6,%r6,0x1c00 106 | 107 | li %r7,0x200 108 | oris %r7,%r7,0x8000 109 | rldicr %r7,%r7,32,31 110 | ori %r7,%r7,0x1010 111 | oris %r7,%r7,6 112 | 113 | li %r8,0x200 114 | oris %r8,%r8,0x8000 115 | rldicr %r8,%r8,32,31 116 | oris %r8,%r8,0xea00 117 | 118 | lis %r9,0x0400 119 | 120 | lis %r10,0x0100 121 | 122 | li %r11,0 123 | 124 | lis %r20,0x8000 125 | ori %r20,%r20,0x17c 126 | rldicr %r20,%r20,32,31 127 | oris %r20,%r20,0x400 128 | ori %r20,%r20,0x270 /* offset to CD code start : 0x8000.017c.0400.0270 */ 129 | 130 | blr 131 | 132 | init_pci: 133 | /* init PCI devices */ 134 | addi %r3,%r20,pci_inits-_start-4 135 | 136 | li %r30,0x200 137 | oris %r30,%r30,0x8000 138 | rldicr %r30,%r30,32,31 139 | pci_start: 140 | lwzu %r4,4(%r3) 141 | cmpwi %r4,-1 142 | beqlr 143 | lwzu %r31,4(%r3) 144 | stwbrx %r31,%r30,%r4 145 | li %r31,0xff 146 | andc %r4,%r4,%r31 147 | ori %r4,%r4,4 148 | lwbrx %r31,%r30,%r4 149 | lwzu %r29,4(%r3) 150 | or %r31,%r31,%r29 151 | stwbrx %r31,%r30,%r4 152 | b pci_start 153 | 154 | pci_inits: 155 | /* pci-pci bridge */ 156 | .long 0xd0000010,0xea000000,0x156 157 | /* host bridge */ 158 | .long 0xd0008010,0xe0000000,2 159 | /* GPU */ 160 | .long 0xd0010010,0xec800000,2 161 | /* 1414:5801 */ 162 | .long 0xd0100010,0xea001800,2 163 | /* SATA */ 164 | .long 0xd0108010,0xea001200,6 165 | .long 0xd0108014,0xea001220,6 166 | .long 0xd0110010,0xea001300,6 167 | .long 0xd0110014,0xea001320,6 168 | /* USB */ 169 | .long 0xd0120010,0xea002000,0x156 170 | .long 0xd0121010,0xea003000,0x106 171 | .long 0xd0128010,0xea004000,0x156 172 | .long 0xd0129010,0xea005000,0x106 173 | /* Ethernet */ 174 | .long 0xd0138010,0xea001400,6 175 | /* System flash controller */ 176 | .long 0xd0140010,0xea00c000,6 177 | .long 0xd0140014,0xc8000000,6 178 | /* Audio */ 179 | .long 0xd0148010,0xea001600,6 180 | /* SMC */ 181 | .long 0xd0150010,0xea001000,2 182 | .long 0xffffffff /* structure end */ 183 | -------------------------------------------------------------------------------- /reset_glitch_hack/cdxell/xenonsprs.h: -------------------------------------------------------------------------------- 1 | #ifndef XENONSPRS_H_ 2 | #define XENONSPRS_H_ 3 | 4 | #endif /*XENONSPRS_H_*/ 5 | #define esr 62 6 | #define ivpr 63 7 | #define pid 48 8 | #define ctrlrd 136 9 | #define ctrlwr 152 10 | #define pvr 287 11 | #define hsprg0 304 12 | #define hsprg1 305 13 | #define hdsisr 306 14 | #define hdar 307 15 | #define dbcr0 308 16 | #define dbcr1 309 17 | #define hdec 310 18 | #define hior 311 19 | #define rmor 312 20 | #define hrmor 313 21 | #define hsrr0 314 22 | #define hsrr1 315 23 | #define dac1 316 24 | #define dac2 317 25 | #define lpcr 318 26 | #define lpidr 319 27 | #define tsr 336 28 | #define tcr 340 29 | #define tsrl 896 30 | #define tsrr 897 31 | #define tscr 921 32 | #define ttr 922 33 | #define PpeTlbIndexHint 946 34 | #define PpeTlbIndex 947 35 | #define PpeTlbVpn 948 36 | #define PpeTlbRpn 949 37 | #define PpeTlbRmt 951 38 | #define dsr0 952 39 | #define drmr0 953 40 | #define dcidr0 954 41 | #define drsr1 955 42 | #define drmr1 956 43 | #define dcidr1 957 44 | #define issr0 976 45 | #define irmr0 977 46 | #define icidr0 978 47 | #define irsr1 979 48 | #define irmr1 980 49 | #define icidr1 981 50 | #define hid0 1008 51 | #define hid1 1009 52 | #define hid4 1012 53 | #define iabr 1010 54 | #define dabr 1013 55 | #define dabrx 1015 56 | #define buscsr 1016 57 | #define hid6 1017 58 | #define l2sr 1018 59 | #define BpVr 1022 60 | #define pir 1023 61 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/_pace.ucf: -------------------------------------------------------------------------------- 1 | #PACE: Start of Constraints generated by PACE 2 | 3 | #PACE: Start of PACE I/O Pin Assignments 4 | NET "CLK" LOC = "P29" | IOSTANDARD = LVCMOS33 ; 5 | NET "CPU_PLL_BYPASS" LOC = "P22" | IOSTANDARD = LVCMOS33 ; 6 | NET "CPU_RESET" LOC = "P8" | IOSTANDARD = LVCMOS15 | SCHMITT_TRIGGER ; 7 | NET "DBG" LOC = "P27" ; 8 | NET "POSTBIT" LOC = "P40" | IOSTANDARD = LVCMOS15 | SCHMITT_TRIGGER ; 9 | 10 | #PACE: Start of PACE Area Constraints 11 | 12 | #PACE: Start of PACE Prohibit Constraints 13 | 14 | #PACE: End of Constraints generated by PACE 15 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/_xmsgs/cpldfit.xmsgs: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Unable to retrieve the path to the iSE Project Repository. Will use the default filename of 'main.ise'. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/_xmsgs/hprep6.xmsgs: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/_xmsgs/taengine.xmsgs: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/_xmsgs/tsim.xmsgs: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/bench_beh.prj: -------------------------------------------------------------------------------- 1 | vhdl work "main.vhd" 2 | vhdl work "bench.vhd" 3 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/isim.log: -------------------------------------------------------------------------------- 1 | ISim log file 2 | Running: C:\X360 Hack\x360dev\cpld\glitch48nofullpost\main_isim_beh.exe -gui -tclbatch isim.cmd -wdb C:/X360 Hack/x360dev/cpld/glitch48nofullpost/main_isim_beh.wdb 3 | ISim M.63c (signature 0x7dea747) 4 | WARNING: A WEBPACK license was found. 5 | WARNING: Please use Xilinx License Configuration Manager to check out a full ISim license. 6 | WARNING: ISim will run in Lite mode. Please refer to the ISim documentation for more information on the differences between the Lite and the Full version. 7 | This is a Lite version of ISim. 8 | Time resolution is 1 ps 9 | # onerror resume 10 | # wave add / 11 | # run 5ms 12 | Simulator is doing circuit initialization process. 13 | Finished circuit initialization process. 14 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/main.ucf: -------------------------------------------------------------------------------- 1 | #PACE: Start of Constraints generated by PACE 2 | 3 | #PACE: Start of PACE I/O Pin Assignments 4 | NET "CLK" LOC = "P29" | IOSTANDARD = LVCMOS33 ; 5 | NET "CPU_PLL_BYPASS" LOC = "P22" | IOSTANDARD = LVCMOS33 ; 6 | NET "CPU_RESET" LOC = "P8" | IOSTANDARD = LVCMOS15 | SCHMITT_TRIGGER ; 7 | NET "DBG" LOC = "P27" | IOSTANDARD = LVCMOS33 ; 8 | NET "POSTBIT" LOC = "P40" | IOSTANDARD = LVCMOS15 | SCHMITT_TRIGGER ; 9 | 10 | #PACE: Start of PACE Area Constraints 11 | 12 | #PACE: Start of PACE Prohibit Constraints 13 | 14 | #PACE: End of Constraints generated by PACE 15 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/main.vhd: -------------------------------------------------------------------------------- 1 | -- Xbox 360 reset glitch hack, 48Mhz clock + fake POST version 2 | -- by GliGli 3 | 4 | library IEEE; 5 | use IEEE.STD_LOGIC_1164.ALL; 6 | use IEEE.NUMERIC_STD.ALL; 7 | 8 | entity main is 9 | generic ( 10 | POST_WIDTH : integer := 7 11 | ); 12 | port ( 13 | DBG : out STD_LOGIC := '0'; 14 | POSTBIT : in STD_LOGIC; 15 | CLK : in STD_LOGIC; 16 | CPU_PLL_BYPASS : out STD_LOGIC := '0'; 17 | CPU_RESET : inout STD_LOGIC := 'Z' 18 | 19 | -- TEST : out unsigned(4 downto 0) 20 | ); 21 | end main; 22 | 23 | architecture counter of main is 24 | 25 | constant CNT_WIDTH : integer := 16; 26 | constant POSTCNT_WIDTH : integer := 8; 27 | 28 | constant POST_37 : integer := 13; 29 | constant POST_39 : integer := 14; 30 | constant POST_3B : integer := 15; 31 | 32 | constant WIDTH_RESET_START : integer := 1603; -- zephyr: 1723, falcon: 1603, jasper: 1628 33 | constant WIDTH_RESET_END : integer := 5; 34 | constant WIDTH_BYPASS_END : integer := 48000; 35 | 36 | constant TIME_RESET_START : integer := WIDTH_RESET_START; 37 | constant TIME_RESET_END : integer := TIME_RESET_START+WIDTH_RESET_END; 38 | constant TIME_BYPASS_END : integer := TIME_RESET_END+WIDTH_BYPASS_END; 39 | 40 | signal cnt : unsigned(CNT_WIDTH-1 downto 0); 41 | signal postcnt : unsigned(POSTCNT_WIDTH-1 downto 0); 42 | signal pp: STD_LOGIC := '0'; 43 | signal ppp: STD_LOGIC := '0'; 44 | 45 | begin 46 | process(CLK, POSTBIT, CPU_RESET, postcnt) is 47 | begin 48 | -- TEST <= postcnt(TEST'range); 49 | 50 | if rising_edge(CLK) then 51 | -- fake POST 52 | if (to_integer(cnt) = 0) and (CPU_RESET = '0') then 53 | postcnt <= (others => '0'); 54 | pp <= '0'; 55 | ppp <= '0'; 56 | else 57 | if ((to_integer(postcnt) = POST_37) or (POSTBIT = ppp)) and ((POSTBIT xor pp) = '1') then -- detect POST changes / filter POST / don't filter glitch POST 58 | postcnt <= postcnt + 1; 59 | pp <= POSTBIT; 60 | else 61 | ppp <= POSTBIT; 62 | end if; 63 | end if; 64 | 65 | -- main counter 66 | if (to_integer(postcnt) < POST_39) or (to_integer(postcnt) > POST_3B) then 67 | cnt <= (others => '0'); 68 | else 69 | if cnt<2**CNT_WIDTH-1 then 70 | cnt <= cnt + 1; 71 | end if; 72 | end if; 73 | 74 | -- bypass 75 | if (to_integer(postcnt) >= POST_37) and (to_integer(postcnt) <= POST_3B) and (cnt < TIME_BYPASS_END) then 76 | CPU_PLL_BYPASS <= '1'; 77 | DBG <= '1'; 78 | else 79 | CPU_PLL_BYPASS <= '0'; 80 | DBG <= '0'; 81 | end if; 82 | 83 | -- reset 84 | if (cnt >= TIME_RESET_START) and (cnt < TIME_RESET_END) then 85 | CPU_RESET <= '0'; 86 | else 87 | if (cnt >= TIME_RESET_END) and (cnt < TIME_BYPASS_END) then 88 | CPU_RESET <= '1'; 89 | else 90 | CPU_RESET <= 'Z'; 91 | end if; 92 | end if; 93 | end if; 94 | 95 | end process; 96 | end counter; 97 | 98 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/main_summary.html: -------------------------------------------------------------------------------- 1 | Xilinx Design Summary 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 |
main Project Status (09/23/2011 - 12:27:58)
Project File:glitch48nofullpost.xiseParser Errors: No Errors
Module Name:mainImplementation State:Fitted
Target Device:xc2c64a-7VQ44
  • Errors:
23 | No Errors
Product Version:ISE 12.2
  • Warnings:
No Warnings
Design Goal:Balanced
  • Routing Results:
35 |  
Design Strategy:Xilinx Default (unlocked)
  • Timing Constraints:
 
Environment: 46 | 47 | System Settings 48 |
  • Final Timing Score:
  
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |  
65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
Detailed Reports [-]
Report NameStatusGeneratedErrorsWarningsInfos
Synthesis ReportCurrentven. 23. sept. 12:26:25 2011000
Translation ReportCurrentven. 23. sept. 12:27:49 2011000
CPLD Fitter Report (Text)Currentven. 23. sept. 12:27:53 201101 Warning (1 new)0
Power Report     
73 |  
74 | 75 | 76 | 77 | 78 |
Secondary Reports [-]
Report NameStatusGenerated
ISIM Simulator LogOut of Datedim. 11. sept. 11:24:58 2011
Post-Fit Simulation Model Report  
79 | 80 | 81 |
Date Generated: 09/23/2011 - 12:27:58
82 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/pepExtractor.prj: -------------------------------------------------------------------------------- 1 | work "C:/X360 Hack/x360dev/ppc/tools/reset_glitch_hack/cpld/glitch48nofullpost/main.vhd" 2 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitch48nofullpost/tmperr.err: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/reset_glitch_hack/cpld/glitch48nofullpost/tmperr.err -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/_pace.ucf: -------------------------------------------------------------------------------- 1 | #PACE: Start of Constraints generated by PACE 2 | 3 | #PACE: Start of PACE I/O Pin Assignments 4 | NET "CLK" LOC = "P29" | IOSTANDARD = LVCMOS33 ; 5 | NET "CPU_RESET" LOC = "P8" | IOSTANDARD = LVCMOS18 ; 6 | NET "POSTBIT" LOC = "P40" | IOSTANDARD = LVCMOS18 ; 7 | NET "SCL" LOC = "P19" | IOSTANDARD = LVCMOS33 ; 8 | NET "SDA" LOC = "P18" | IOSTANDARD = LVCMOS33 ; 9 | 10 | #PACE: Start of PACE Area Constraints 11 | 12 | #PACE: Start of PACE Prohibit Constraints 13 | 14 | #PACE: End of Constraints generated by PACE 15 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/_xmsgs/hprep6.xmsgs: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/_xmsgs/taengine.xmsgs: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/_xmsgs/tsim.xmsgs: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/glitchslim.gise: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 11.1 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/isim.log: -------------------------------------------------------------------------------- 1 | ISim log file 2 | Running: C:\X360 Hack\x360dev\cpld\glitchslim\main_isim_beh.exe -gui -tclbatch isim.cmd -wdb C:/X360 Hack/x360dev/cpld/glitchslim/main_isim_beh.wdb 3 | ISim M.63c (signature 0x7dea747) 4 | WARNING: A WEBPACK license was found. 5 | WARNING: Please use Xilinx License Configuration Manager to check out a full ISim license. 6 | WARNING: ISim will run in Lite mode. Please refer to the ISim documentation for more information on the differences between the Lite and the Full version. 7 | This is a Lite version of ISim. 8 | Time resolution is 1 ps 9 | # onerror resume 10 | # wave add / 11 | # run 5ms 12 | Simulator is doing circuit initialization process. 13 | Finished circuit initialization process. 14 | # restart 15 | # run 1s 16 | Simulator is doing circuit initialization process. 17 | Finished circuit initialization process. 18 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/main.ucf: -------------------------------------------------------------------------------- 1 | #PACE: Start of Constraints generated by PACE 2 | 3 | #PACE: Start of PACE I/O Pin Assignments 4 | NET "CLK" LOC = "P29" | IOSTANDARD = LVCMOS33 ; 5 | NET "CPU_RESET" LOC = "P8" | IOSTANDARD = LVCMOS18 ; 6 | NET "DBG" LOC = "P27" | IOSTANDARD = LVCMOS33 ; 7 | NET "POSTBIT" LOC = "P40" | IOSTANDARD = LVCMOS18 ; 8 | NET "SCL" LOC = "P19" | IOSTANDARD = LVCMOS33 ; 9 | NET "SDA" LOC = "P18" | IOSTANDARD = LVCMOS33 ; 10 | 11 | #PACE: Start of PACE Area Constraints 12 | 13 | #PACE: Start of PACE Prohibit Constraints 14 | 15 | #PACE: End of Constraints generated by PACE 16 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/main_summary.html: -------------------------------------------------------------------------------- 1 | Xilinx Design Summary 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 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
main Project Status
Project File:glitchslim.xiseParser Errors:
Module Name:mainImplementation State:New
Target Device:xc2c64a-7VQ44
  • Errors:
 
Product Version:ISE 12.2
  • Warnings:
 
Design Goal:Balanced
  • Routing Results:
33 |  
Design Strategy:Xilinx Default (unlocked)
  • Timing Constraints:
 
Environment: 
  • Final Timing Score:
  
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |  
60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
Detailed Reports [-]
Report NameStatusGeneratedErrorsWarningsInfos
Synthesis Report     
Translation Report     
CPLD Fitter Report (Text)     
Power Report     
68 |  
69 | 70 | 71 | 72 | 73 |
Secondary Reports [-]
Report NameStatusGenerated
ISIM Simulator LogOut of Datejeu. 12. mai 21:23:48 2011
Post-Fit Simulation Model Report  
74 | 75 | 76 |
Date Generated: 08/27/2011 - 21:16:37
77 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/pepExtractor.prj: -------------------------------------------------------------------------------- 1 | work "C:/X360 Hack/x360dev/cpld/glitchslimnodp/main.vhd" 2 | -------------------------------------------------------------------------------- /reset_glitch_hack/cpld/glitchslimnodp/tmperr.err: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/reset_glitch_hack/cpld/glitchslimnodp/tmperr.err -------------------------------------------------------------------------------- /reset_glitch_hack/finding_the_right_timing.txt: -------------------------------------------------------------------------------- 1 | ****************************************************** 2 | * Finding the right timing for the reset glitch hack * 3 | ****************************************************** 4 | 5 | Getting memcmp POST length in ticks 6 | =================================== 7 | 8 | First step is to know how long the memcmp POST will last while slowed down. No reset pulse should be sent for this. 9 | Using hardware that can read the POST bus and measure time in a precise way, measure the time between memcmp POST start and 'hash compare failed' final POST (eg on fats, between POST 39 and POST AD) with the next bootloader failing hash check. 10 | 11 | An ARM7 based Olimex LPC-H2148 was used for this task. 12 | 13 | It could look like that: 14 | 15 | for(;;) 16 | { 17 | post = post_read(); 18 | if (post == prev_post) then continue; 19 | 20 | if(post == MEMCMP_POST) 21 | { 22 | t_start = get_tick(); 23 | 24 | while( post_read() == MEMCMP_POST ); 25 | 26 | memcmp_post_length=get_tick()-t_start; 27 | 28 | print(memcmp_post_length); 29 | } 30 | 31 | prev_post=post; 32 | } 33 | 34 | Make sure you note memcmp post length ;) 35 | 36 | Using random timing over the full POST length 37 | ============================================= 38 | 39 | Now you need the hardware to send a reset pulse after a random amount of time in memcmp POST, but no more than previously found memcmp POST length. 40 | 41 | It could look like that: 42 | 43 | for(;;) 44 | { 45 | post = read_post(); 46 | if (post == prev_post) then continue; 47 | 48 | if(post == MEMCMP_POST) 49 | { 50 | t_start = get_tick(); 51 | t_rand = rand() % MEMCMP_POST_LENGTH; 52 | 53 | while( get_tick()< t_start+t_rand ); 54 | 55 | ppc_send_reset_pulse(); 56 | 57 | print(t_rand); 58 | } 59 | 60 | prev_post=post; 61 | } 62 | 63 | Using a hacked smc that reboots infinitely it will take a good amount of time, but it should end up glitching properly. 64 | 65 | Make sure you note the timing that glitched ;) 66 | 67 | Refining the timing, accounting for bell-like curve 68 | =================================================== 69 | 70 | So now we have one timing that glitches, but we don't know if it's really the 'sweet spot' or if we were just lucky. 71 | What needs to be done now is to get the timing of some more successes, I think it's safe to use a smaller random range around previously found glitch timing. my get_tick() function runs at 60Mhz, I found it was safe to make the range -+50 ticks around previously found glitch timing 72 | 73 | It could look like that: 74 | 75 | for(;;) 76 | { 77 | post = read_post(); 78 | if (post == prev_post) then continue; 79 | 80 | if(post == MEMCMP_POST) 81 | { 82 | t_start = get_tick(); 83 | t_rand = PREV_GLITCH_TIMING - 50 + (rand() % 100); 84 | 85 | while( get_tick()< t_start+t_rand ); 86 | 87 | ppc_send_reset_pulse(); 88 | 89 | print(t_rand); 90 | } 91 | 92 | prev_post=post; 93 | } 94 | 95 | You'll need the timing of at least 20-30 successes. Averaging those timings should give you the sweet spot (aka final timing), because empirically we found that success rate vs timing is a bell-like curve. 96 | 97 | Make sure ... you got it ;) 98 | 99 | PS: Those pseudo-code examples don't show the slowdown code for the sake of clarity. -------------------------------------------------------------------------------- /reset_glitch_hack/schematics/glitch48nofullpost.DSN: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/reset_glitch_hack/schematics/glitch48nofullpost.DSN -------------------------------------------------------------------------------- /reset_glitch_hack/schematics/glitchslimnodp.DSN: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/reset_glitch_hack/schematics/glitchslimnodp.DSN -------------------------------------------------------------------------------- /shahunt/AUTHORS: -------------------------------------------------------------------------------- 1 | th0mas - th0mas.sixbit.org@gmail.com 2 | -------------------------------------------------------------------------------- /shahunt/BUILD: -------------------------------------------------------------------------------- 1 | You need to have libxbox installed. Then just run make and supply 2 | the libxbox build directory, like so: 3 | 4 | LIBXBOX_DIR=../libxbox make 5 | 6 | Assuming that libxbox.so is installed properly this will build fine. 7 | 8 | 9 | -------------------------------------------------------------------------------- /shahunt/CREDITS: -------------------------------------------------------------------------------- 1 | Thanks to superjedi for ideas. 2 | -------------------------------------------------------------------------------- /shahunt/ChangeLog: -------------------------------------------------------------------------------- 1 | 2005-12-20 th0mas 2 | * Initial public release 3 | * Still very beta-y, lots of potential features if requested. 4 | -------------------------------------------------------------------------------- /shahunt/Makefile: -------------------------------------------------------------------------------- 1 | all: \ 2 | shahunt 3 | 4 | shahunt: shahunt.c 5 | gcc -O2 -g -o shahunt shahunt.c -I$(LIBXBOX_DIR)/include -lxbox 6 | 7 | -------------------------------------------------------------------------------- /shahunt/README: -------------------------------------------------------------------------------- 1 | Licensed under the GPL. 2 | 3 | SHAHunt loads a set of (presumed) SHA-1 hashes from a file, and then iterates over the file trying to match plaintext chunks to one of the loaded hashes. You can specify a lot of configuration in order to increase compatability with a variety of file types, such as file offsets to load the hashes, and offsets to start the iteration. Run the program without any arguments to see some usage information. 4 | 5 | Requires libxbox from xbox-linux CVS. 6 | 7 | All settings are stored in a settings_t struct, so it would be easy to add support to save state on a break signal and the be able to load the settings back from a file. If a serious need arised the program could also be converted to a distributed client/server model to distribute the load. Email me if you have a need for this and we can work something out. 8 | -------------------------------------------------------------------------------- /shahunt/shahunt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/shahunt/shahunt -------------------------------------------------------------------------------- /xboxdumper/Makefile: -------------------------------------------------------------------------------- 1 | 2 | OBJS=main.o util.o fatx.o file64.o utility.o 3 | 4 | CFLAGS=-O2 -DXBOX360=1 -DMEMCARD=0 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__USE_LARGEFILE64 5 | 6 | all: $(OBJS) 7 | gcc -o xboxdumper $(OBJS) 8 | 9 | clean: 10 | rm -fr $(OBJS) xboxdumper xboxdumper.exe *# *~ 11 | 12 | .PHONY: clean 13 | -------------------------------------------------------------------------------- /xboxdumper/README.TXT: -------------------------------------------------------------------------------- 1 | xboxdumper v0.13 2 | (c) 2001 Andrew de Quincey 3 | 4 | **UPDATE**: oz_paulb modified code to deal with Xbox360 images. 5 | See "XBOX360" define in the Makefile. Still a 6 | work in progress. 7 | 8 | 9 | This program allows files on an xbox hard disk to be dumped out. 10 | 11 | 12 | Two basic commands are supported: 13 | 14 | 15 | xboxdumper list 16 | 17 | This will dump the directory tree of the specified partition. 18 | 19 | (e.g. "./xboxdumper.sh list 1 xboximage.bin" ) 20 | 21 | 22 | 23 | 24 | xboxdumper dump 25 | 26 | This will dump the file into the file 27 | from the specified partition number. The full directory path to the file 28 | using / or \ should be supplied. 29 | 30 | (e.g. "./xboxdumper.sh dump /voice.afs voice.afs 1 xboximage.bin" ) 31 | 32 | 33 | may be between 0 and 4 inclusively. Partition 0 is not 34 | confirmed yet. 35 | 36 | I will not supply images of the xbox hard disk, so please don't bother 37 | asking. 38 | -------------------------------------------------------------------------------- /xboxdumper/fatx.h: -------------------------------------------------------------------------------- 1 | // Definitions for FATX on-disk structures 2 | // (c) 2001 Andrew de Quincey 3 | 4 | #ifndef FATX_H 5 | #define FATX_H 6 | 7 | // FATX partition magic 8 | #define FATX_PARTITION_MAGIC 0x58544146 // "FATX" 9 | 10 | typedef struct tagFATX_PARTITION_HDR { 11 | u_int32_t fph_magic; 12 | u_int32_t fph_volume_id; 13 | u_int32_t fph_cluster_nsects; 14 | u_int32_t fph_num_fat_tables; 15 | } FATX_PARTITION_HDR; 16 | 17 | // Size of FATX partition header 18 | #define FATX_PARTITION_HEADERSIZE 0x1000 19 | 20 | 21 | // FATX chain table block size 22 | #define FATX_CHAINTABLE_BLOCKSIZE 4096 23 | 24 | // ID of the root FAT cluster 25 | #define FATX_ROOT_FAT_CLUSTER 1 26 | 27 | 28 | 29 | typedef struct tagFATX_DIR_ENT { 30 | unsigned char fde_name_len; 31 | unsigned char fde_attributes; 32 | unsigned char fde_name[42]; 33 | u_int32_t fde_first_cluster; 34 | u_int32_t fde_file_size_bytes; 35 | u_int32_t fde_file_mod_datetime; 36 | u_int32_t fde_file_create_datetime; 37 | u_int32_t fde_file_access_datetime; 38 | } FATX_DIR_ENT; 39 | 40 | // Size of FATX directory entries 41 | #define FATX_DIRECTORYENTRY_SIZE 0x40 42 | 43 | // File attribute: read only 44 | #define FATX_FILEATTR_READONLY 0x01 45 | 46 | // File attribute: hidden 47 | #define FATX_FILEATTR_HIDDEN 0x02 48 | 49 | // File attribute: system 50 | #define FATX_FILEATTR_SYSTEM 0x04 51 | 52 | // File attribute: archive 53 | #define FATX_FILEATTR_ARCHIVE 0x20 54 | 55 | // Directory entry flag indicating entry is a sub-directory 56 | #define FATX_FILEATTR_DIRECTORY 0x10 57 | 58 | // max filename size 59 | #define FATX_FILENAME_MAX 42 60 | 61 | // This structure describes a FATX partition 62 | typedef struct { 63 | // The source file 64 | fd64_t sourceFd; 65 | 66 | // The starting byte of the partition 67 | u_int64_t partitionStart; 68 | 69 | // The size of the partition in bytes 70 | u_int64_t partitionSize; 71 | 72 | // The cluster size of the partition 73 | u_int32_t clusterSize; 74 | 75 | // Number of clusters in the partition 76 | u_int32_t clusterCount; 77 | 78 | // Size of entries in the cluster chain map 79 | u_int32_t chainMapEntrySize; 80 | 81 | // The cluster chain map table (which may be in words OR dwords) 82 | union { 83 | u_int16_t* words; 84 | u_int32_t* dwords; 85 | } clusterChainMap; 86 | 87 | // Address of cluster 1 88 | u_int64_t cluster1Address; 89 | 90 | } FATXPartition; 91 | 92 | 93 | 94 | 95 | /** 96 | * Open a FATX partition 97 | * 98 | * @param sourceFd File to read from 99 | * @param partitionOffset Offset into above file that partition starts at 100 | * @param partitionSize Size of partition in bytes 101 | */ 102 | FATXPartition* openPartition(fd64_t sourceFd, 103 | u_int64_t partitionOffset, 104 | u_int64_t partitionSize); 105 | 106 | 107 | /** 108 | * Close a FATX partition 109 | */ 110 | void closePartition(FATXPartition* partition); 111 | 112 | /** 113 | * Dump entire directory tree to supplied stream 114 | * 115 | * @param partition The FATX partition 116 | * @param outputStream Stream to output data to 117 | */ 118 | void dumpTree(FATXPartition* partition, fd64_t outputStream); 119 | 120 | 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /xboxdumper/file64.c: -------------------------------------------------------------------------------- 1 | #ifndef __linux__ 2 | #include "mytypes.h" 3 | #include "file64.h" 4 | #include 5 | #include 6 | 7 | #define VERBOSE_DEBUG 0 8 | 9 | 10 | fd64_t 11 | open64(const char *path, int oflag,...) 12 | { 13 | DWORD desired_access = 0; 14 | DWORD share_mode = 0; 15 | DWORD create_disposition = 0; 16 | fd64_t retval; 17 | 18 | if (oflag & O_CREAT) { 19 | if (oflag & O_TRUNC) { 20 | create_disposition = CREATE_ALWAYS; 21 | } else { 22 | create_disposition = CREATE_NEW; 23 | } 24 | } else { 25 | create_disposition = OPEN_EXISTING; 26 | } 27 | if (oflag & O_RDONLY) { 28 | desired_access = GENERIC_READ; 29 | share_mode = FILE_SHARE_READ; 30 | } else if (oflag & O_RDWR) { 31 | desired_access = GENERIC_READ | GENERIC_WRITE; 32 | share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; 33 | } 34 | 35 | retval = CreateFile(path, desired_access, share_mode, (LPSECURITY_ATTRIBUTES)0, 36 | create_disposition, FILE_ATTRIBUTE_NORMAL, (HANDLE)0); 37 | 38 | 39 | #if VERBOSE_DEBUG 40 | fprintf(stderr, "open64('%s', 0x%x) = 0x%x\n", path, oflag, (unsigned int)(void *)retval); 41 | #endif 42 | return retval; 43 | } 44 | 45 | int 46 | close64(fd64_t fd) 47 | { 48 | if (CloseHandle(fd)) { 49 | return 0; 50 | } else { 51 | return -1; 52 | } 53 | } 54 | 55 | off64_t 56 | lseek64(fd64_t fd, off64_t offset, int whence) 57 | { 58 | LARGE_INTEGER li; 59 | LARGE_INTEGER liret; 60 | DWORD mm; 61 | off64_t retval; 62 | 63 | li.QuadPart = offset; 64 | 65 | 66 | mm = FILE_BEGIN; 67 | if (whence == SEEK_SET) { 68 | mm = FILE_BEGIN; 69 | } else if (whence == SEEK_CUR) { 70 | mm = FILE_CURRENT; 71 | } else if (whence == SEEK_END) { 72 | mm = FILE_END; 73 | } 74 | 75 | 76 | if (SetFilePointerEx(fd, li, &liret, mm)) { 77 | retval = (off64_t)liret.QuadPart; 78 | } else { 79 | retval = (off64_t)-1L; 80 | } 81 | 82 | #if VERBOSE_DEBUG 83 | fprintf(stderr, "lseek64(fd=0x%x, offset=0x%08x%08x) = 0x%08x%08x\n", 84 | (unsigned int)(void *)fd, 85 | (unsigned int)li.HighPart, (unsigned int)li.LowPart, 86 | (unsigned int)liret.HighPart, (unsigned int)liret.LowPart); 87 | #endif 88 | 89 | return retval; 90 | } 91 | 92 | 93 | size64_t 94 | read64(fd64_t fd, void *buf, size64_t count) 95 | { 96 | DWORD actual; 97 | size64_t retval; 98 | 99 | if (ReadFile(fd, (LPVOID)buf, (DWORD)count, &actual, (LPOVERLAPPED)0)) { 100 | retval = (size64_t)actual; 101 | } else { 102 | retval = (size64_t)-1; 103 | } 104 | 105 | #if VERBOSE_DEBUG 106 | fprintf(stderr, "read64(fd=0x%x, count=0x%08x) = 0x%08x\n", 107 | (unsigned int)(void *)fd, 108 | (unsigned int)count, (unsigned int)actual); 109 | #endif 110 | 111 | return retval; 112 | } 113 | 114 | size64_t 115 | write64(fd64_t fd, void *buf, size64_t count) 116 | { 117 | DWORD actual; 118 | size64_t retval; 119 | 120 | if (WriteFile(fd, (LPCVOID)buf, (DWORD)count, &actual, (LPOVERLAPPED)0)) { 121 | retval = (size64_t)actual; 122 | } else { 123 | retval =(size64_t)-1; 124 | } 125 | 126 | #if VERBOSE_DEBUG 127 | fprintf(stderr, "write64(fd=0x%x, count=0x%08x) = 0x%08x\n", 128 | (unsigned int)(void *)fd, 129 | (unsigned int)count, (unsigned int)actual); 130 | #endif 131 | 132 | return retval; 133 | } 134 | #endif // !__linux__ 135 | 136 | -------------------------------------------------------------------------------- /xboxdumper/file64.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE64_H 2 | #define FILE64_H 3 | 4 | #ifndef MYTYPES_H 5 | #include "mytypes.h" 6 | #endif 7 | 8 | #ifdef __linux__ 9 | 10 | typedef int fd64_t; 11 | //typedef _off64_t off64_t; 12 | typedef int size64_t; 13 | 14 | #define open64 open 15 | #define close64 close 16 | #define read64 read 17 | #define write64 write 18 | 19 | #define STDIN_FD64 fileno(stdin) 20 | #define STDOUT_FD64 fileno(stdout) 21 | #define STDERR_FD64 fileno(stderr) 22 | 23 | #define IS_INVALID_FD64(f) ((f) < 0) 24 | 25 | #else // !__linux__ 26 | 27 | typedef u_int64_t off64_t; 28 | typedef HANDLE fd64_t; 29 | typedef int size64_t; 30 | 31 | #define INVALID_FD64 ((fd64_t)INVALID_HANDLE_VALUE) 32 | #define IS_INVALID_FD64(f) ((f) == INVALID_FD64) 33 | 34 | #define STDIN_FD64 ((fd64_t)GetStdHandle(STD_INPUT_HANDLE)) 35 | #define STDOUT_FD64 ((fd64_t)GetStdHandle(STD_OUTPUT_HANDLE)) 36 | #define STDERR_FD64 ((fd64_t)GetStdHandle(STD_ERROR_HANDLE)) 37 | 38 | extern off64_t lseek64(fd64_t fd, off64_t offset, int whence); 39 | extern fd64_t open64(const char *path, int oflag,...); 40 | 41 | extern size64_t read64(fd64_t fd, void *buf, size64_t count); 42 | extern size64_t write64(fd64_t fd, void *buf, size64_t count); 43 | 44 | extern int close64(fd64_t fd); 45 | 46 | #endif // __linux__ 47 | 48 | 49 | #endif // FILE64_H 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /xboxdumper/mytypes.h: -------------------------------------------------------------------------------- 1 | #ifndef MYTYPES_H 2 | #define MYTYPES_H 3 | 4 | #include 5 | 6 | #ifdef __linux__ 7 | #include 8 | #else // !__linux__ 9 | #include 10 | #ifndef __CYGWIN__ 11 | typedef unsigned __int16 u_int16_t; 12 | typedef unsigned __int32 u_int32_t; 13 | typedef unsigned __int64 u_int64_t; 14 | #endif // __CYGWIN__ 15 | #endif // __linux__ 16 | 17 | #if XBOX360 18 | #define bswap32(v) (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v << 8) & 0xff0000) | ((v << 24) & 0xff000000)) 19 | #define bswap16(v) (((v >> 8) & 0xff) | ((v << 8) & 0xff00)) 20 | #else // !XBOX360 21 | #define bswap32(v) (v) 22 | #define bswap16(v) (v) 23 | #endif // XBOX360 24 | 25 | #endif // MYTYPES_H 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /xboxdumper/util.c: -------------------------------------------------------------------------------- 1 | // Utility functions 2 | // (c) 2001 Andrew de Quincey 3 | 4 | #include "mytypes.h" 5 | #include 6 | #include 7 | #include "util.h" 8 | 9 | /** 10 | * Report an error 11 | */ 12 | void error(char *fmt, ...) { 13 | va_list argp; 14 | fprintf(stderr, "error: "); 15 | va_start(argp, fmt); 16 | vfprintf(stderr, fmt, argp); 17 | va_end(argp); 18 | fprintf(stderr, "\n"); 19 | exit(1); 20 | } 21 | 22 | 23 | /** 24 | * Load a DOS date and time stamp 25 | * 26 | * @param dateTime Place to put data 27 | * @param date Raw DOS date value 28 | * @param time Raw DOS time value 29 | */ 30 | void loadDosDateTime(DosDateTime* dateTime, 31 | u_int16_t date, u_int16_t time) { 32 | dateTime->day = date & 0x1f; 33 | dateTime->month = (date & 0x1e0) >> 5; 34 | dateTime->year = ((date & 0xfe00) >> 9) + 1980; 35 | dateTime->secs = (time & 0x1f) * 2; 36 | dateTime->mins = (time & 0x7e0) >> 5; 37 | dateTime->hours = (time & 0xf800) >> 11; 38 | } 39 | 40 | 41 | 42 | /** 43 | * Format a DOSDateTime for printing 44 | * 45 | * @param dateTime DosDateTime to format 46 | * 47 | * @return Formatted string 48 | */ 49 | char* formatDosDate(DosDateTime* dateTime) { 50 | static char formatDosDateSTORE[256]; 51 | 52 | sprintf(formatDosDateSTORE, "%02i:%02i:%02i-%i/%i/%i", 53 | dateTime->hours, dateTime->mins, dateTime->secs, 54 | dateTime->day, dateTime->month, dateTime->year); 55 | return formatDosDateSTORE; 56 | } 57 | -------------------------------------------------------------------------------- /xboxdumper/util.h: -------------------------------------------------------------------------------- 1 | // Utility functions 2 | // (c) 2001 Andrew de Quincey 3 | 4 | 5 | #ifndef UTIL_H 6 | #define UTIL_H 1 7 | 8 | #include 9 | 10 | /** 11 | * Structure to contain a DOS date and timestamp 12 | */ 13 | typedef struct { 14 | int year; 15 | int month; 16 | int day; 17 | int hours; 18 | int mins; 19 | int secs; 20 | } DosDateTime; 21 | 22 | /** 23 | * Report an error 24 | */ 25 | void error(char *fmt, ...); 26 | 27 | /** 28 | * Load a DOS date and time stamp 29 | * 30 | * @param dateTime Place to put data 31 | * @param date Raw DOS date value 32 | * @param time Raw DOS time value 33 | */ 34 | void loadDosDateTime(DosDateTime* dateTime, 35 | u_int16_t date, u_int16_t time); 36 | 37 | 38 | 39 | /** 40 | * Format a DOSDateTime for printing 41 | * 42 | * @param dateTime DosDateTime to format 43 | * 44 | * @return Formatted string 45 | */ 46 | char* formatDosDate(DosDateTime* dateTime); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /xboxdumper/utility.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | char makehexchar(int i) { 5 | return (i<=9) ? '0'+i : 'A'+(i-10); 6 | } 7 | 8 | int hextoint(char c) { 9 | c = toupper(c); 10 | return (c > '9' ? c - 'A' + 10 : c - '0'); 11 | } 12 | 13 | void hexdump(const unsigned char* data, size_t length) { 14 | const int char_offset = 16*3 + 2; 15 | const int line_size = 16*3 + 16 + 3; 16 | char line[line_size+1]; 17 | size_t i; 18 | int line_i; 19 | 20 | printf("OFFSET 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F | 0123456789ABCDEF\n"); 21 | printf("--------------------------------------------------------------------------\n"); 22 | 23 | line[char_offset - 1] = ' '; 24 | line[char_offset - 2] = ' '; 25 | 26 | for (i=0; i>4); 34 | line[bi++] = makehexchar(*data & 0x0f); 35 | line[bi++] = ' '; 36 | line[char_offset+(ci++)]=(isprint(*data) ? *data : '.'); 37 | data++; 38 | } 39 | 40 | while (bi<16*3) { 41 | line[bi++]=' '; 42 | } 43 | 44 | line[char_offset+(ci++)]='\n'; 45 | line[char_offset+ci]=0; 46 | 47 | printf("%06X %s", start_i, line); 48 | } 49 | } 50 | 51 | int char_value(char c) 52 | { 53 | if (c >= '0' && c <= '9') return c - '0'; 54 | if (c >= 'a' && c <= 'z') return c - 'a'; 55 | if (c >= 'A' && c <= 'Z') return c - 'A'; 56 | return 0; 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /xboxdumper/utility.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILITY_H 2 | #define _UTILITY_H 3 | 4 | int hextoint(char c); 5 | void hexdump(const byte* data,size_t length); 6 | 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /xextools/.NOTES.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/xextools/.NOTES.swp -------------------------------------------------------------------------------- /xextools/AUTHORS: -------------------------------------------------------------------------------- 1 | * superjedi 2 | -------------------------------------------------------------------------------- /xextools/ChangeLog: -------------------------------------------------------------------------------- 1 | 2005-12-04 superjedi 2 | 3 | * New release, version 0.2 4 | 5 | * All the functions have been splitted in a new library, libxex 6 | -------------------------------------------------------------------------------- /xextools/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src 2 | -------------------------------------------------------------------------------- /xextools/NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/xextools/NEWS -------------------------------------------------------------------------------- /xextools/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Free60Project/tools/421fddd74492475e19d01d42826c806ca797addb/xextools/README -------------------------------------------------------------------------------- /xextools/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_DLFCN_H 5 | 6 | /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ 7 | #undef HAVE_DOPRNT 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_FCNTL_H 11 | 12 | /* Define to 1 if you have the `getpagesize' function. */ 13 | #undef HAVE_GETPAGESIZE 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_INTTYPES_H 17 | 18 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 19 | to 0 otherwise. */ 20 | #undef HAVE_MALLOC 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #undef HAVE_MEMORY_H 24 | 25 | /* Define to 1 if you have a working `mmap' system call. */ 26 | #undef HAVE_MMAP 27 | 28 | /* Define to 1 if you have the `munmap' function. */ 29 | #undef HAVE_MUNMAP 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #undef HAVE_STDINT_H 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #undef HAVE_STDLIB_H 36 | 37 | /* Define to 1 if you have the `strdup' function. */ 38 | #undef HAVE_STRDUP 39 | 40 | /* Define to 1 if you have the `strerror' function. */ 41 | #undef HAVE_STRERROR 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #undef HAVE_STRINGS_H 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #undef HAVE_STRING_H 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #undef HAVE_SYS_STAT_H 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #undef HAVE_SYS_TYPES_H 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #undef HAVE_UNISTD_H 57 | 58 | /* Define to 1 if you have the `vprintf' function. */ 59 | #undef HAVE_VPRINTF 60 | 61 | /* Name of package */ 62 | #undef PACKAGE 63 | 64 | /* Define to the address where bug reports for this package should be sent. */ 65 | #undef PACKAGE_BUGREPORT 66 | 67 | /* Define to the full name of this package. */ 68 | #undef PACKAGE_NAME 69 | 70 | /* Define to the full name and version of this package. */ 71 | #undef PACKAGE_STRING 72 | 73 | /* Define to the one symbol short name of this package. */ 74 | #undef PACKAGE_TARNAME 75 | 76 | /* Define to the version of this package. */ 77 | #undef PACKAGE_VERSION 78 | 79 | /* Define to 1 if you have the ANSI C header files. */ 80 | #undef STDC_HEADERS 81 | 82 | /* Version number of package */ 83 | #undef VERSION 84 | 85 | /* Define to empty if `const' does not conform to ANSI C. */ 86 | #undef const 87 | 88 | /* Define to `__inline__' or `__inline' if that's what the C compiler 89 | calls it, or to nothing if 'inline' is not supported under any name. */ 90 | #ifndef __cplusplus 91 | #undef inline 92 | #endif 93 | 94 | /* Define to rpl_malloc if the replacement function should be used. */ 95 | #undef malloc 96 | -------------------------------------------------------------------------------- /xextools/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.59) 5 | AC_INIT([xextools], [0.2], [ziga@phear.org]) 6 | AC_CONFIG_HEADER([config.h]) 7 | AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) 8 | 9 | AC_CONFIG_SRCDIR([src/xexread.c]) 10 | 11 | # Checks for programs. 12 | AC_PROG_CC 13 | AC_PROG_MAKE_SET 14 | AC_PROG_LIBTOOL 15 | 16 | # Checks for header files. 17 | AC_HEADER_STDC 18 | AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h]) 19 | 20 | # Checks for typedefs, structures, and compiler characteristics. 21 | AC_C_CONST 22 | AC_C_INLINE 23 | 24 | # Checks for library functions. 25 | AC_FUNC_MALLOC 26 | AC_FUNC_MMAP 27 | AC_FUNC_VPRINTF 28 | AC_CHECK_FUNCS([munmap strdup strerror]) 29 | 30 | AC_CONFIG_FILES([Makefile 31 | src/Makefile 32 | src/lib/Makefile]) 33 | AC_OUTPUT 34 | -------------------------------------------------------------------------------- /xextools/src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = xexread 2 | 3 | xexread_SOURCES = \ 4 | swissknife.c \ 5 | xex_display.c \ 6 | xexread.c \ 7 | swissknife.h \ 8 | xex_display.h 9 | 10 | 11 | xexread_LDADD = \ 12 | @LIBS@ $(top_builddir)/src/lib/libxex.la 13 | 14 | xexreadincludedir = -I$(top_srcdir)/src/lib 15 | 16 | xexreaddir = $(includedir)/xexread 17 | 18 | xexread_HEADERS = \ 19 | swissknife.h \ 20 | xex_display.h 21 | 22 | SUBDIRS = lib 23 | 24 | AM_CPPFLAGS = \ 25 | -Wall #-Werror 26 | 27 | INCLUDES = $(xexreadincludedir) 28 | 29 | CLEANFILES = core core.* *~ 30 | 31 | indent: 32 | indent -gnu -nut *.c *.h 33 | 34 | strip: 35 | strip xexread 36 | -------------------------------------------------------------------------------- /xextools/src/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libxex.la 2 | 3 | libxex_la_SOURCES = \ 4 | swissknife.c \ 5 | xh_info.c \ 6 | xh_info_exec.c \ 7 | xh_info_init.c \ 8 | xh_info_load.c \ 9 | xh_info_unknown_1.c \ 10 | xh_main.c \ 11 | xex_cert.c \ 12 | xex_main.c \ 13 | xex_alloc.c \ 14 | libxex.h \ 15 | swissknife.h \ 16 | xex_cert.h \ 17 | xex_main.h \ 18 | xh_info_exec.h \ 19 | xh_info_load.h \ 20 | xh_main.h \ 21 | xex_alloc.h \ 22 | xex_datatypes.h \ 23 | xh_info.h \ 24 | xh_info_init.h \ 25 | xh_info_unknown_1.h 26 | 27 | 28 | libxex_la_LDFLAGS = -version-info 0:1:0 29 | 30 | all: libxex.la 31 | @echo Done. 32 | -------------------------------------------------------------------------------- /xextools/src/lib/libxex.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXEX_H 2 | #define LIBXEX_H 3 | 4 | #include "xex_main.h" 5 | #include "xex_cert.h" 6 | #include "xh_main.h" 7 | #include "xh_info.h" 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /xextools/src/lib/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | void usage (char *program); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /xextools/src/lib/swissknife.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "xex_main.h" 4 | #include "swissknife.h" 5 | 6 | inline long get_dword (xex_t *xex, unsigned int offset) 7 | { 8 | return bs32(*((DWORD *)(xex->buf + offset))); 9 | } 10 | 11 | void xex_warning (char *fmt, ...) 12 | { 13 | va_list ap; 14 | 15 | va_start (ap, fmt); 16 | fprintf (stderr, "libxex: ***WARNING*** "); 17 | vfprintf (stderr, fmt, ap); 18 | fprintf (stderr, "\n"); 19 | va_end (ap); 20 | } 21 | 22 | void xex_error (char *fmt, ...) 23 | { va_list ap; 24 | 25 | va_start (ap, fmt); 26 | fprintf (stderr, "libxex: ***ERROR*** "); 27 | vfprintf (stderr, fmt, ap); 28 | fprintf (stderr, "\n"); 29 | va_end (ap); 30 | } 31 | -------------------------------------------------------------------------------- /xextools/src/lib/swissknife.h: -------------------------------------------------------------------------------- 1 | #ifndef SWISSKNIFE_H 2 | #define SWISSKNIFE_H 3 | 4 | #include "xex_main.h" 5 | 6 | #define bs32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) 7 | #define bs16(x) ((((x) & 0x0000ff00) >> 8) | (((x) & 0x000000ff) << 8)) 8 | #define round(n, r) ((n) + ((r) - ((n) % (r)) == (r) ? 0 : (r) - ((n) % (r)))) 9 | #define bit_get(number, i) (((number) & (1 << (i))) > 0) 10 | 11 | inline long get_dword (xex_t *xex, unsigned int offset); 12 | 13 | void xex_warning (char *fmt, ...); 14 | void xex_error (char *fmt, ...); 15 | 16 | #define DWORD long 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /xextools/src/lib/xex_alloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "swissknife.h" 5 | #include "xex_datatypes.h" 6 | #include "xex_alloc.h" 7 | 8 | xex_dt_table *xex_alloc_table (unsigned int width, unsigned int nent, char *name) 9 | { 10 | xex_dt_table *table = malloc (sizeof (xex_dt_table)); 11 | 12 | table->width = width; 13 | table->nent = nent; 14 | table->name = strdup (name); 15 | table->entries = malloc (sizeof (xex_dt_table_ent *) * nent); 16 | table->header = malloc (sizeof (char *) * width); 17 | table->noheader = 0; 18 | 19 | return table; 20 | } 21 | 22 | xex_object *xex_alloc_object (xex_dt_object type, void *ptr) 23 | { 24 | xex_object *object = malloc (sizeof (xex_object)); 25 | 26 | object->type = type; 27 | object->ptr = ptr; 28 | 29 | return object; 30 | } 31 | 32 | xex_dt_table_ent *xex_alloc_table_ent (xex_dt_field type, unsigned long content) 33 | { 34 | xex_dt_table_ent *ent = malloc (sizeof (xex_dt_table_ent)); 35 | 36 | ent->type = type; 37 | ent->content = content; 38 | 39 | return ent; 40 | } 41 | -------------------------------------------------------------------------------- /xextools/src/lib/xex_alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef XEX_ALLOC_H 2 | #define XEX_ALLOC_H 3 | 4 | #include "xex_datatypes.h" 5 | 6 | xex_dt_table *xex_alloc_table (unsigned int width, unsigned int nent, char *name); 7 | xex_object *xex_alloc_object (xex_dt_object type, void *ptr); 8 | xex_dt_table_ent *xex_alloc_table_ent (xex_dt_field type, unsigned long content); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /xextools/src/lib/xex_cert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "swissknife.h" 3 | #include "xex_alloc.h" 4 | #include "xex_main.h" 5 | #include "xex_cert.h" 6 | 7 | xex_object **xex_read_certificate (xex_t *xex) { 8 | xex_dt_table *cert, *trailer; 9 | xex_object **objects; 10 | DWORD cert_off, cert_siz; 11 | int i; 12 | 13 | objects = malloc (sizeof (xex_object *) * 3); 14 | 15 | cert_off = get_dword (xex, X_OFF_CERT); 16 | cert_siz = get_dword (xex, cert_off); 17 | 18 | cert = xex_alloc_table (4, 256 / 4, "Certificate"); 19 | cert->noheader = 1; 20 | 21 | objects[0] = xex_alloc_object (Table, cert); 22 | 23 | for (i = 0; i < 256 / 4; i++) { 24 | DWORD ent = get_dword (xex, cert_off + 8 + i * 4); 25 | cert->entries[i] = xex_alloc_table_ent (Hexa32, ent); 26 | } 27 | 28 | trailer = xex_alloc_table (4, (cert_siz / 4) - 4 - 256 / 4, "Certificate Trailer"); 29 | trailer->noheader = 1; 30 | 31 | for (i = 0; i < (cert_siz / 4) - 4 - 256 / 4; i++) { 32 | DWORD ent = get_dword (xex, cert_off + 8 + 256 + i * 4); 33 | trailer->entries[i] = xex_alloc_table_ent (Hexa32, ent); 34 | } 35 | 36 | objects[1] = xex_alloc_object (Table, trailer); 37 | objects[2] = NULL; 38 | 39 | return objects; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /xextools/src/lib/xex_cert.h: -------------------------------------------------------------------------------- 1 | #ifndef XEX_CERT_H 2 | #define XEX_CERT_H 3 | 4 | #include "xex_main.h" 5 | #include "xex_datatypes.h" 6 | 7 | xex_object **xex_read_certificate (xex_t *xex); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /xextools/src/lib/xex_datatypes.h: -------------------------------------------------------------------------------- 1 | #ifndef XEX_DATATYPES_H 2 | #define XEX_DATATYPES_H 3 | 4 | /* This header defines an abstraction layer to the objects retrieved from the XEX loader */ 5 | 6 | typedef enum { 7 | Table, 8 | Line 9 | } xex_dt_object; 10 | 11 | typedef enum { 12 | Hexa32, 13 | Bits, 14 | String 15 | } xex_dt_field; 16 | 17 | typedef struct { 18 | xex_dt_field type; 19 | unsigned long content; 20 | } xex_dt_table_ent; 21 | 22 | typedef struct { 23 | unsigned int width; 24 | unsigned int nent; /* Number of entries */ 25 | char *name; 26 | char **header; 27 | int noheader; 28 | xex_dt_table_ent **entries; 29 | } xex_dt_table; 30 | 31 | typedef struct { 32 | void *ptr; 33 | } xex_dt_line; 34 | 35 | typedef struct { 36 | xex_dt_object type; 37 | union { 38 | xex_dt_table *table; 39 | xex_dt_line *line; 40 | void *ptr; 41 | }; 42 | } xex_object; 43 | 44 | xex_dt_table *xex_alloc_table (unsigned int width, unsigned int height, char *name); 45 | xex_object *xex_alloc_object (xex_dt_object type, void *ptr); 46 | xex_dt_table_ent *xex_alloc_table_ent (xex_dt_field type, unsigned long content); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /xextools/src/lib/xex_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #ifndef __WIN32__ 9 | # include 10 | #endif 11 | #include "swissknife.h" 12 | #include "xex_main.h" 13 | 14 | 15 | #ifdef __WIN32__ 16 | static int oflags = O_RDONLY|_O_BINARY; /* Set the file mode to Binary */ 17 | #else 18 | static int oflags = O_RDONLY; 19 | #endif 20 | 21 | xex_t *xex_load (const char *pathname) 22 | { 23 | struct stat statbuf; 24 | char *ptr; 25 | int tbw; 26 | xex_t *xex; 27 | 28 | tbw = 0; 29 | ptr = NULL; 30 | 31 | xex = malloc (sizeof (xex_t)); 32 | 33 | xex->buf = NULL; 34 | 35 | xex->fd = open (pathname, oflags); 36 | 37 | if (xex->fd < 0) { 38 | xex_error ("Couldn't open %s: %s\n", pathname, strerror (errno)); 39 | goto cleanup; 40 | } 41 | 42 | fstat (xex->fd, &statbuf); 43 | 44 | xex->file_length = statbuf.st_size; 45 | 46 | #ifdef __WIN32__ 47 | xex->buf = malloc (xex->file_length); 48 | 49 | tbw = xex->file_length; 50 | ptr = (char *)xex->buf; 51 | 52 | do { 53 | int nb = read (xex->fd, ptr, tbw); 54 | 55 | if (nb < 0) 56 | { 57 | if (nb == -1 && errno == EINTR) 58 | continue; 59 | 60 | close (xex->fd); 61 | 62 | xex_error ("Couldn't read %s: %s\n", pathname, strerror (errno)); 63 | 64 | goto cleanup; 65 | } 66 | 67 | tbw -= nb; 68 | ptr += nb; 69 | } while (tbw > 0); 70 | #else 71 | xex->buf = mmap (NULL, xex->file_length, PROT_READ, MAP_PRIVATE, xex->fd, 0); 72 | #endif 73 | 74 | return xex; 75 | 76 | cleanup: 77 | 78 | if (xex->buf) 79 | #ifdef __WIN32__ 80 | free ((void *)xex->buf); 81 | #else 82 | munmap ((void *)xex->buf, xex->file_length); 83 | #endif 84 | 85 | free (xex); 86 | 87 | close (xex->fd); 88 | 89 | return NULL; 90 | } 91 | 92 | void xex_unload (xex_t *xex) 93 | { 94 | if (xex->buf) 95 | #ifdef __WIN32__ 96 | free ((void *)xex->buf); 97 | #else 98 | munmap ((void *)xex->buf, xex->file_length); 99 | #endif 100 | 101 | free (xex); 102 | 103 | close (xex->fd); 104 | 105 | } 106 | 107 | int xex_validate (xex_t *xex) { 108 | DWORD magic = get_dword (xex, X_OFF_MAG); 109 | 110 | if (bs32 (magic) != XEX_MAGIC) 111 | return 0; 112 | 113 | return 1; 114 | } 115 | 116 | -------------------------------------------------------------------------------- /xextools/src/lib/xex_main.h: -------------------------------------------------------------------------------- 1 | #ifndef XEX_MAIN_H 2 | #define XEX_MAIN_H 3 | 4 | #include "xex_datatypes.h" 5 | 6 | #define XEX_MAGIC00 'X' 7 | #define XEX_MAGIC01 'E' 8 | #define XEX_MAGIC02 'X' 9 | #define XEX_MAGIC03 '2' 10 | 11 | #define XEX_MAGIC 0x32584558 /* Little endian*/ 12 | 13 | #define X_OFF_MAG 0x0000 14 | #define X_OFF_VERSION 0x0004 15 | #define X_OFF_CODE 0x0008 16 | #define X_OFF_RES0 0x000C 17 | #define X_OFF_CERT 0x0010 18 | #define X_OFF_NUMDW 0x0014 19 | 20 | typedef struct { 21 | const char *buf; 22 | unsigned int file_length; 23 | int fd; 24 | } xex_t; 25 | 26 | xex_t *xex_load (const char *pathname); 27 | int xex_validate (xex_t *xex); 28 | void xex_unload (xex_t *xex); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "swissknife.h" 5 | #include "xh_info.h" 6 | #include "xh_info_exec.h" 7 | #include "xh_info_init.h" 8 | #include "xh_info_load.h" 9 | #include "xh_info_unknown_1.h" 10 | #include "xex_main.h" 11 | #include "xex_datatypes.h" 12 | 13 | xex_object *xh_info_execute_entry (xex_t *xex, DWORD flags, DWORD value) 14 | { 15 | xh_info_t info_ent = (flags & 0x00FF0000) >> 16; 16 | int id = (flags & 0x0000FF00) >> 8; 17 | int size = (flags & 0x00000000FF); 18 | int executed = 0, found = 0; 19 | 20 | xex_object *ret = NULL; 21 | 22 | switch (info_ent) { 23 | case INFO_INIT: 24 | xh_info_execute (xh_info_init_handlers, id, xex, value, size, executed, ret); 25 | break; 26 | case INFO_EXEC: 27 | xh_info_execute (xh_info_exec_handlers, id, xex, value, size, executed, ret); 28 | break; 29 | case INFO_LOAD: 30 | xh_info_execute (xh_info_load_handlers, id, xex, value, size, executed, ret); 31 | break; 32 | case INFO_UNKNOWN_0: 33 | xh_info_execute (xh_info_unknown_1_handlers, id, xex, value, size, executed, ret); 34 | break; 35 | default: 36 | if (!found) { 37 | xex_error ("Unhandled xh info entry type: %x\n", info_ent); 38 | //abort (); 39 | } 40 | } 41 | 42 | if (!executed) 43 | xex_warning ("No handler for info entry type: %x and id %x\n", info_ent, id); 44 | 45 | return ret; 46 | } 47 | 48 | xex_object **xh_info_load_generic (xex_t *xex, xex_dt_table *table) { 49 | xex_object **objects; 50 | DWORD flags, value; 51 | int i, j; 52 | 53 | objects = malloc (sizeof (xex_object *) * ((table->nent / table->width) + 1)); 54 | 55 | for (i = j = 0; i < (table->nent / table->width); i++) { 56 | xex_object *obj; 57 | 58 | flags = table->entries[i * table->width + 0]->content; 59 | value = table->entries[i * table->width + 1]->content; 60 | 61 | obj = xh_info_execute_entry (xex, flags, value); 62 | 63 | if (obj != NULL) 64 | objects[j++] = obj; 65 | } 66 | 67 | objects[j] = NULL; 68 | 69 | return objects; 70 | } 71 | 72 | 73 | xex_object *xh_read_generic_table (xex_t *xex) { 74 | xex_dt_table *table; 75 | int i, j, nent; 76 | 77 | nent = get_dword (xex, X_OFF_NUMDW); 78 | 79 | table = xex_alloc_table (3, nent * 3, "Generic table"); 80 | 81 | table->width = 3; 82 | table->nent = nent * table->width; 83 | 84 | table->header[0] = strdup ("flags"); 85 | table->header[1] = strdup ("value"); 86 | table->header[2] = strdup ("flags (bits)"); 87 | 88 | i = 1; 89 | j = 0; 90 | 91 | while (i < nent * 2) { 92 | DWORD flags, value; 93 | 94 | flags = get_dword (xex, X_OFF_NUMDW + i++ * 4); 95 | value = get_dword (xex, X_OFF_NUMDW + i++ * 4); 96 | 97 | table->entries[j++] = xex_alloc_table_ent (Hexa32, flags); 98 | table->entries[j++] = xex_alloc_table_ent (Hexa32, value); 99 | table->entries[j++] = xex_alloc_table_ent (Bits, flags); 100 | } 101 | 102 | return xex_alloc_object (Table, table); 103 | } 104 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info.h: -------------------------------------------------------------------------------- 1 | #ifndef XH_INFO_H 2 | #define XH_INFO_H 3 | 4 | #include "xex_datatypes.h" 5 | 6 | typedef enum { 7 | INFO_INIT = 0, 8 | INFO_EXEC = 1 << 0, 9 | INFO_LOAD = 1 << 1, 10 | INFO_UNKNOWN_0 = 1 << 2 11 | } xh_info_t; 12 | 13 | xex_object **xh_info_load_generic (xex_t *xex, xex_dt_table *table); 14 | xex_object *xh_read_generic_table (xex_t *xex); 15 | 16 | #define xh_info_execute(table, id, arg1, arg2, arg3, exec, ret) do { \ 17 | int i; \ 18 | for (i = 0; table[i].handler; i++) { \ 19 | if (table[i].id == id) { \ 20 | ret = table[i].handler (arg1, arg2, arg3); \ 21 | exec = 1; \ 22 | } \ 23 | } \ 24 | } while (0) 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info_exec.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "swissknife.h" 4 | #include "xh_info_exec.h" 5 | #include "xex_datatypes.h" 6 | 7 | static struct xh_info_exec_handler _xh_info_exec_handlers[] = { 8 | { EXEC_ORIGINAL_BASE_ADDR, xh_info_exec_original_base_addr }, 9 | { EXEC_ENTRY_POINT, xh_info_exec_entry_point }, 10 | { EXEC_LOAD_TEXT_ADDR, xh_info_exec_load_text_addr }, 11 | { EXEC_UNKNOWN_ADDRESS_TABLE, xh_info_exec_unknown_address_table }, 12 | { EXEC_ID, xh_info_exec_image_timestamp }, 13 | { EXEC_ORIGINAL_PE_FILENAME, xh_info_exec_original_pe_filename }, 14 | { 0, 0 } 15 | }; 16 | 17 | struct xh_info_exec_handler *xh_info_exec_handlers = _xh_info_exec_handlers; 18 | 19 | xex_object *xh_info_exec_original_base_addr (xex_t *xex, int offset, int size) { 20 | xex_dt_table *table; 21 | 22 | table = xex_alloc_table (1, 1, "Exec: Original base address"); 23 | 24 | table->noheader = 1; 25 | 26 | table->entries[0] = xex_alloc_table_ent (Hexa32, offset); 27 | 28 | return xex_alloc_object (Table, table); 29 | } 30 | 31 | xex_object *xh_info_exec_entry_point (xex_t *xex, int offset, int size) { 32 | xex_dt_table *table; 33 | 34 | table = xex_alloc_table (1, 1, "Exec: Entry point"); 35 | 36 | table->noheader = 1; 37 | 38 | table->entries[0] = xex_alloc_table_ent (Hexa32, offset); 39 | 40 | return xex_alloc_object (Table, table); 41 | } 42 | 43 | xex_object *xh_info_exec_load_text_addr (xex_t *xex, int offset, int size) { 44 | xex_dt_table *table; 45 | 46 | table = xex_alloc_table (1, 1, "Exec: Load text address"); 47 | 48 | table->noheader = 1; 49 | 50 | table->entries[0] = xex_alloc_table_ent (Hexa32, offset); 51 | 52 | return xex_alloc_object (Table, table); 53 | } 54 | 55 | xex_object *xh_info_exec_unknown_address_table (xex_t *xex, int offset, int size) { 56 | int real_size = (size == 0xFF ? get_dword (xex, offset) : size); 57 | xex_dt_table *table; 58 | int i; 59 | 60 | real_size -= 4; 61 | offset += 4; 62 | 63 | table = xex_alloc_table (4, real_size / 4, "Exec: Unknown address table -- Relocation table"); 64 | 65 | table->noheader = 1; 66 | 67 | for (i = 0; i < real_size / 4; i++) { 68 | DWORD dword = get_dword (xex, offset + i*4); 69 | table->entries[i] = xex_alloc_table_ent (Hexa32, dword); 70 | } 71 | 72 | return xex_alloc_object (Table, table); 73 | } 74 | 75 | xex_object *xh_info_exec_image_timestamp (xex_t *xex, int offset, int size) { 76 | xex_dt_table *table; 77 | 78 | DWORD dword = get_dword (xex, offset + 4); 79 | 80 | table = xex_alloc_table (1, 1, "Exec: Image timestamp"); 81 | 82 | table->noheader = 1; 83 | 84 | table->entries[0] = xex_alloc_table_ent (Hexa32, dword); 85 | 86 | return xex_alloc_object (Table, table); 87 | } 88 | 89 | xex_object *xh_info_exec_original_pe_filename (xex_t *xex, int offset, int size) { 90 | xex_dt_table *table; 91 | char *orig_filename; 92 | 93 | orig_filename = strdup (xex->buf + offset + 4); 94 | 95 | table = xex_alloc_table (1, 1, "Exec: Original PE Filename"); 96 | 97 | table->noheader = 1; 98 | 99 | table->entries[0] = xex_alloc_table_ent (String, (unsigned long)orig_filename); 100 | 101 | return xex_alloc_object (Table, table); 102 | } 103 | 104 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info_exec.h: -------------------------------------------------------------------------------- 1 | #ifndef XH_INFO_EXEC_H 2 | #define XH_INFO_EXEC_H 3 | 4 | #include "xex_datatypes.h" 5 | 6 | typedef enum { 7 | EXEC_ORIGINAL_BASE_ADDR = 0x00, 8 | EXEC_ENTRY_POINT = 0x01, 9 | EXEC_LOAD_TEXT_ADDR = 0x02, 10 | EXEC_UNKNOWN_ADDRESS_TABLE = 0x03, 11 | EXEC_ID = 0x80, 12 | EXEC_ORIGINAL_PE_FILENAME = 0x83 13 | } xh_info_exec_t; 14 | 15 | struct xh_info_exec_handler { 16 | xh_info_exec_t id; 17 | xex_object *(* handler) (xex_t *xex, int offset, int size); 18 | }; 19 | 20 | struct xh_info_exec_handler *xh_info_exec_handlers; 21 | 22 | xex_object *xh_info_exec_original_base_addr (xex_t *xex, int offset, int size); 23 | xex_object *xh_info_exec_entry_point (xex_t *xex, int offset, int size); 24 | xex_object *xh_info_exec_load_text_addr (xex_t *xex, int offset, int size); 25 | xex_object *xh_info_exec_unknown_address_table (xex_t *xex, int offset, int size); 26 | xex_object *xh_info_exec_image_timestamp (xex_t *xex, int offset, int size); 27 | xex_object *xh_info_exec_original_pe_filename (xex_t *xex, int offset, int size); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info_init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "swissknife.h" 5 | #include "xh_info_init.h" 6 | #include "xex_datatypes.h" 7 | 8 | static struct xh_info_init_handler _xh_info_init_handlers[] = { 9 | { INIT_CONTENT_MAPPING, xh_info_init_content_mapping }, 10 | { INIT_OFFSET_OR_CHECKSUMS, xh_info_init_offset_or_checksums }, 11 | { INIT_EXECUTABLE_PATH, xh_info_init_executable_path }, 12 | { 0 } 13 | }; 14 | 15 | struct xh_info_init_handler *xh_info_init_handlers = _xh_info_init_handlers; 16 | 17 | xex_object *xh_info_init_content_mapping (xex_t *xex, int offset, int size) { 18 | int real_size = (size == 0xFF ? get_dword (xex, offset) : size); 19 | int asczl = 0; 20 | int height, i, j, k; 21 | 22 | xex_dt_table *table; 23 | 24 | offset += sizeof (DWORD); 25 | real_size -= sizeof (DWORD); 26 | 27 | /* Calculate the height of the table */ 28 | for (i = j = 0; i < real_size; i += (asczl + 8)) { 29 | asczl = 8; 30 | j++; 31 | } 32 | 33 | height = j; 34 | 35 | table = xex_alloc_table (3, height * 3, "Init: Resource content mapping"); 36 | 37 | table->header[0] = strdup ("base address"); 38 | table->header[1] = strdup ("size"); 39 | table->header[2] = strdup ("name"); 40 | 41 | for (i = j = 0; i < real_size; i += asczl + 8) { 42 | DWORD size, base; 43 | const char *ptr = xex->buf + offset + i; 44 | char *ascz; 45 | 46 | for (k = 0; k < 8; k++) 47 | if (ptr[k] == '\0') 48 | break; 49 | 50 | asczl = 8; 51 | ascz = malloc (asczl + 1); 52 | memcpy (ascz, ptr, asczl); 53 | ascz[asczl] = '\0'; 54 | 55 | base = get_dword (xex, offset + i + asczl); 56 | size = get_dword (xex, offset + i + asczl + 4); 57 | 58 | table->entries[j++] = xex_alloc_table_ent (Hexa32, base); 59 | table->entries[j++] = xex_alloc_table_ent (Hexa32, size); 60 | table->entries[j++] = xex_alloc_table_ent (String, (unsigned long)ascz); 61 | } 62 | 63 | return xex_alloc_object (Table, table); 64 | } 65 | 66 | xex_object *xh_info_init_offset_or_checksums (xex_t *xex, int offset, int size) { 67 | int real_size = (size == 0xFF ? get_dword (xex, offset) : size); 68 | xex_dt_table *table; 69 | int i; 70 | 71 | real_size -= 4; 72 | offset += 4; 73 | 74 | table = xex_alloc_table (4, real_size / 4, "Init: Offset or checksum table"); 75 | 76 | table->noheader = 1; 77 | 78 | for (i = 0; i < real_size / 4; i++) { 79 | DWORD dword = get_dword (xex, offset + i*4); 80 | table->entries[i] = xex_alloc_table_ent (Hexa32, dword); 81 | } 82 | 83 | return xex_alloc_object (Table, table); 84 | } 85 | 86 | xex_object *xh_info_init_executable_path (xex_t *xex, int offset, int size) { 87 | xex_dt_table *table; 88 | char *pathname; 89 | 90 | pathname = strdup (xex->buf + offset + 4); 91 | 92 | table = xex_alloc_table (1, 1, "Init: Bound pathname"); 93 | 94 | table->noheader = 1; 95 | 96 | table->entries[0] = xex_alloc_table_ent (String, (unsigned long)pathname); 97 | 98 | return xex_alloc_object (Table, table); 99 | } 100 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info_init.h: -------------------------------------------------------------------------------- 1 | #ifndef XH_INFO_INIT_H 2 | #define XH_INFO_INIT_H 3 | 4 | #include "xex_datatypes.h" 5 | 6 | typedef enum { 7 | INIT_CONTENT_MAPPING = 0x02, 8 | INIT_OFFSET_OR_CHECKSUMS = 0x03, 9 | INIT_EXECUTABLE_PATH = 0x80 10 | } xh_info_init_t; 11 | 12 | struct xh_info_init_handler { 13 | xh_info_init_t id; 14 | xex_object *(* handler) (xex_t *xex, int offset, int size); 15 | }; 16 | 17 | struct xh_info_init_handler *xh_info_init_handlers; 18 | 19 | xex_object *xh_info_init_content_mapping (xex_t *xex, int offset, int size); 20 | xex_object *xh_info_init_offset_or_checksums (xex_t *xex, int offset, int size); 21 | xex_object *xh_info_init_executable_path (xex_t *xex, int offset, int size); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info_load.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "swissknife.h" 5 | #include "xh_info_load.h" 6 | #include "xex_datatypes.h" 7 | 8 | static struct xh_info_load_handler _xh_info_load_handlers[] = { 9 | { LOAD_LIBRARIES, xh_info_load_libraries }, 10 | { LOAD_UNKNOWN_DWORDS_0, xh_info_load_dwords_0 }, 11 | { LOAD_UNKNOWN_DWORDS_1, xh_info_load_dwords_1 }, 12 | { 0 } 13 | }; 14 | 15 | struct xh_info_load_handler *xh_info_load_handlers = _xh_info_load_handlers; 16 | 17 | xex_object *xh_info_load_libraries (xex_t *xex, int offset, int size) { 18 | int real_size = (size == 0xFF ? get_dword (xex, offset) : size); 19 | int asczl = 0; 20 | int height, i, j; 21 | 22 | xh_library_version ver; 23 | xex_dt_table *table; 24 | 25 | asczl = 0; 26 | 27 | offset += sizeof (DWORD); 28 | real_size -= sizeof (DWORD); 29 | 30 | /* Calculate the height of the table */ 31 | for (i = j = 0; i < real_size; i += (asczl + 8)) { 32 | asczl = 8; 33 | j++; 34 | } 35 | 36 | height = j; 37 | 38 | table = xex_alloc_table (3, height * 3, "Load: library versions"); 39 | 40 | table->header[0] = strdup ("flags"); 41 | table->header[1] = strdup ("version"); 42 | table->header[2] = strdup ("library"); 43 | 44 | for (i = j = 0; i < real_size; i += asczl + 8) { 45 | char *version = malloc (40); 46 | DWORD flags; 47 | char *ascz; 48 | 49 | ascz = malloc(9); 50 | memcpy (ascz, xex->buf + offset + i, 8); 51 | ascz[8] = '\0'; 52 | asczl = 8; 53 | 54 | flags = get_dword (xex, offset + i + asczl); 55 | *(DWORD *)&ver = bs32(get_dword (xex, offset + i + asczl + 4)); 56 | 57 | /* Swap bytes */ 58 | ver.build = bs16(ver.build); 59 | 60 | snprintf (version, 40, "%#x.%d.%-2d", ver.unk0, ver.build, ver.micro); 61 | 62 | table->entries[j++] = xex_alloc_table_ent (Hexa32, flags); 63 | table->entries[j++] = xex_alloc_table_ent (String, (unsigned long)version); 64 | table->entries[j++] = xex_alloc_table_ent (String, (unsigned long)ascz); 65 | } 66 | 67 | return xex_alloc_object (Table, table); 68 | } 69 | 70 | xex_object *xh_info_load_dwords_0 (xex_t *xex, int offset, int size) { 71 | int real_size = (size == 0xFF ? get_dword (xex, offset) : size); 72 | xex_dt_table *table; 73 | int i; 74 | 75 | /* FIXME: Unknown size */ 76 | 77 | table = xex_alloc_table (4, real_size, "Load: Dwords 0"); 78 | 79 | table->noheader = 1; 80 | 81 | for (i = 0; i < real_size; i++) { 82 | DWORD dword = get_dword (xex, offset + i*4); 83 | table->entries[i] = xex_alloc_table_ent (Hexa32, dword); 84 | } 85 | 86 | return xex_alloc_object (Table, table); 87 | } 88 | 89 | xex_object *xh_info_load_dwords_1 (xex_t *xex, int offset, int size) { 90 | xex_dt_table *table; 91 | 92 | table = xex_alloc_table (1, 1, "Load: Dwords 1"); 93 | 94 | table->noheader = 1; 95 | 96 | table->entries[0] = xex_alloc_table_ent (Hexa32, offset); 97 | 98 | return xex_alloc_object (Table, table); 99 | } 100 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info_load.h: -------------------------------------------------------------------------------- 1 | #ifndef XH_INFO_LOAD_H 2 | #define XH_INFO_LOAD_H 3 | 4 | #include "xex_datatypes.h" 5 | 6 | typedef enum { 7 | LOAD_LIBRARIES = 0x00, 8 | LOAD_UNKNOWN_DWORDS_0 = 0x01, 9 | LOAD_UNKNOWN_DWORDS_1 = 0x02 10 | } xh_info_load_t; 11 | 12 | struct xh_info_load_handler { 13 | xh_info_load_t id; 14 | xex_object *(* handler) (xex_t *xex, int offset, int size); 15 | }; 16 | 17 | struct xh_info_load_handler *xh_info_load_handlers; 18 | 19 | xex_object *xh_info_load_libraries (xex_t *xex, int offset, int size); 20 | xex_object *xh_info_load_dwords_0 (xex_t *xex, int offset, int size); 21 | xex_object *xh_info_load_dwords_1 (xex_t *xex, int offset, int size); 22 | 23 | typedef struct { 24 | unsigned int build:16; 25 | unsigned int unk0:8; 26 | unsigned int micro:8; 27 | } xh_library_version; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info_unknown_1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "swissknife.h" 3 | #include "xh_info_unknown_1.h" 4 | #include "xex_datatypes.h" 5 | 6 | struct xh_info_unknown_1_handler _xh_info_unknown_1_handlers[] = { 7 | { UNKNOWN_DWORDS_0, xh_info_unknown_1_dwords_0 }, 8 | { UNKNOWN_DWORDS_1, xh_info_unknown_1_dwords_1 }, 9 | { 0 } 10 | }; 11 | 12 | struct xh_info_unknown_1_handler *xh_info_unknown_1_handlers = _xh_info_unknown_1_handlers; 13 | 14 | xex_object *xh_info_unknown_1_dwords_0 (xex_t *xex, int offset, int size) { 15 | int real_size = (size == 0xFF ? get_dword (xex, offset) : size); 16 | xex_dt_table *table; 17 | int i; 18 | 19 | table = xex_alloc_table (4, real_size, "Unknown 1: Dwords 0"); 20 | 21 | table->noheader = 1; 22 | 23 | for (i = 0; i < real_size; i++) { 24 | DWORD dword = get_dword (xex, offset + i*4); 25 | table->entries[i] = xex_alloc_table_ent (Hexa32, dword); 26 | } 27 | 28 | return xex_alloc_object (Table, table); 29 | } 30 | 31 | xex_object *xh_info_unknown_1_dwords_1 (xex_t *xex, int offset, int size) { 32 | int real_size = (size == 0xFF ? get_dword (xex, offset) : size); 33 | xex_dt_table *table; 34 | int i; 35 | 36 | table = xex_alloc_table (4, real_size, "Unknown 1: Dwords 1"); 37 | 38 | table->noheader = 1; 39 | 40 | for (i = 0; i < real_size; i++) { 41 | DWORD dword = get_dword (xex, offset + i*4); 42 | table->entries[i] = xex_alloc_table_ent (Hexa32, dword); 43 | } 44 | 45 | return xex_alloc_object (Table, table); 46 | } 47 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_info_unknown_1.h: -------------------------------------------------------------------------------- 1 | #ifndef XH_INFO_UNKNOWN_1_H 2 | #define XH_INFO_UNKNOWN_1_H 3 | 4 | #include "xex_datatypes.h" 5 | 6 | typedef enum { 7 | UNKNOWN_DWORDS_0 = 0x00, 8 | UNKNOWN_DWORDS_1 = 0x04 9 | } xh_info_unknown_1_t; 10 | 11 | struct xh_info_unknown_1_handler { 12 | xh_info_unknown_1_t id; 13 | xex_object *(* handler) (xex_t *xex, int offset, int size); 14 | }; 15 | 16 | struct xh_info_unknown_1_handler *xh_info_unknown_1_handlers; 17 | 18 | xex_object *xh_info_unknown_1_dwords_0 (xex_t *xex, int offset, int size); 19 | xex_object *xh_info_unknown_1_dwords_1 (xex_t *xex, int offset, int size); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "xex_datatypes.h" 3 | #include "xex_main.h" 4 | #include "swissknife.h" 5 | #include "xh_main.h" 6 | 7 | xex_object **xh_get_misc_info (xex_t *xex) { 8 | xex_object **objects = malloc (sizeof (xex_object *) * 6); 9 | xex_dt_table *table; 10 | DWORD dword; 11 | 12 | dword = get_dword (xex, X_OFF_VERSION); 13 | 14 | table = xex_alloc_table (1, 1, "Header: Flags"); 15 | table->noheader = 1; 16 | table->entries[0] = xex_alloc_table_ent (Bits, dword); 17 | objects[0] = xex_alloc_object (Table, table); 18 | 19 | dword = get_dword (xex, X_OFF_CODE); 20 | 21 | table = xex_alloc_table (1, 1, "Header: Code offset"); 22 | table->noheader = 1; 23 | table->entries[0] = xex_alloc_table_ent (Hexa32, dword); 24 | objects[1] = xex_alloc_object (Table, table); 25 | 26 | dword = get_dword (xex, X_OFF_RES0); 27 | 28 | table = xex_alloc_table (1, 1, "Header: Reserved 0"); 29 | table->noheader = 1; 30 | table->entries[0] = xex_alloc_table_ent (Hexa32, dword); 31 | objects[2] = xex_alloc_object (Table, table); 32 | 33 | dword = get_dword (xex, X_OFF_CERT); 34 | 35 | table = xex_alloc_table (1, 1, "Header: Certificate offset"); 36 | table->noheader = 1; 37 | table->entries[0] = xex_alloc_table_ent (Hexa32, dword); 38 | objects[3] = xex_alloc_object (Table, table); 39 | 40 | dword = get_dword (xex, X_OFF_NUMDW); 41 | 42 | table = xex_alloc_table (1, 1, "Header: Number of entries in the generic table"); 43 | table->noheader = 1; 44 | table->entries[0] = xex_alloc_table_ent (Hexa32, dword); 45 | objects[4] = xex_alloc_object (Table, table); 46 | 47 | objects[5] = NULL; 48 | 49 | return objects; 50 | } 51 | -------------------------------------------------------------------------------- /xextools/src/lib/xh_main.h: -------------------------------------------------------------------------------- 1 | #ifndef XH_MAIN_H 2 | #define XH_MAIN_H 3 | 4 | #include "xex_datatypes.h" 5 | 6 | xex_object **xh_get_misc_info (xex_t *xex); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /xextools/src/swissknife.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "swissknife.h" 3 | 4 | /* Need a 36 bytes buffer passed as 'buffer' argument. */ 5 | inline void sprint_bits (char *buffer, unsigned int number) 6 | { 7 | int i, y; 8 | 9 | for (i = y = 0; i < 32; i++) { 10 | buffer[y++] = '0' + bit_get (number, 31 - i); 11 | 12 | if (!((i + 1) % 8) && i != 31) 13 | buffer[y++] = ' '; 14 | } 15 | 16 | buffer[y] = '\0'; 17 | } 18 | -------------------------------------------------------------------------------- /xextools/src/swissknife.h: -------------------------------------------------------------------------------- 1 | #ifndef SWISSKNIFE_H 2 | #define SWISSKNIFE_H 3 | 4 | inline long get_dword (void *data, unsigned int offset); 5 | 6 | void hexdump (unsigned char *data, unsigned int offset, unsigned int size); 7 | 8 | /* Need a 36 bytes buffer passed as 'buffer' argument. */ 9 | inline void sprint_bits (char *buffer, unsigned int number); 10 | 11 | #define bs32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) 12 | #define bs16(x) ((((x) & 0x0000ff00) >> 8) | (((x) & 0x000000ff) << 8)) 13 | #define round(n, r) ((n) + ((r) - ((n) % (r)) == (r) ? 0 : (r) - ((n) % (r)))) 14 | #define bit_get(number, i) (((number) & (1 << (i))) > 0) 15 | 16 | #ifndef MAX 17 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /xextools/src/xex_display.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "swissknife.h" 6 | #include "xex_display.h" 7 | 8 | void xex_print_table (xex_dt_table *table) 9 | { 10 | char bits[36]; 11 | int *colsizes; 12 | int height; 13 | int i, j; 14 | 15 | printf ("%s\n", table->name); 16 | 17 | if (!table->noheader) 18 | printf ("\n"); 19 | 20 | printf (" "); 21 | 22 | colsizes = malloc (sizeof (int) * table->width); 23 | 24 | height = ((float)table->nent / (float)table->width + .99); 25 | 26 | for (i = 0; i < table->width; i++) { 27 | int len; 28 | 29 | if (table->noheader) 30 | colsizes[i] = 8; 31 | else { 32 | len = strlen (table->header[i]); 33 | 34 | colsizes[i] = len < 8 ? 9 : len + 2; 35 | } 36 | 37 | for (j = 0; j < height && (j * table->width + i) < table->nent; j++) { 38 | switch (table->entries[j * table->width + i]->type) { 39 | case Bits: 40 | colsizes[i] = MAX (colsizes[i], 36 + 2); 41 | break; 42 | case String: { 43 | int len = strlen ((const char *)table->entries[j * table->width + i]->content); 44 | colsizes[i] = MAX (colsizes[i], len + 2); 45 | break; 46 | } 47 | case Hexa32: 48 | default: 49 | break; 50 | } 51 | } 52 | if (!table->noheader) 53 | printf ("%-*s ", colsizes[i], table->header[i]); 54 | } 55 | 56 | printf ("\n"); 57 | 58 | for (i = 0; i < height; i++) { 59 | printf ("%4d: ", i + 1); 60 | for (j = 0; j < table->width && (i * table->width + j) < table->nent; j++) { 61 | switch (table->entries[i * table->width + j]->type) { 62 | case Hexa32: 63 | printf ("%-*.08lx ", 64 | colsizes[j], table->entries[i * table->width + j]->content); 65 | break; 66 | case Bits: 67 | sprint_bits (bits, table->entries[i * table->width + j]->content); 68 | printf ("%-*s ", colsizes[j], bits); 69 | break; 70 | case String: 71 | printf ("%-*s ", colsizes[j], (char *)table->entries[i * table->width + j]->content); 72 | break; 73 | default: 74 | printf ("Unknown table entry type: %d\n", table->entries[i * table->width + j]->type); 75 | abort (); 76 | } 77 | } 78 | printf ("\n"); 79 | } 80 | 81 | printf ("\n"); 82 | 83 | free (colsizes); 84 | } 85 | 86 | void xex_print_object (xex_object *object) 87 | { 88 | switch (object->type) { 89 | case Table: 90 | xex_print_table (object->table); 91 | break; 92 | case Line: 93 | break; 94 | default: 95 | printf ("Unknown object type: %d\n", object->type); 96 | abort (); 97 | } 98 | } 99 | 100 | void xex_print_objects (xex_object **objects) 101 | { 102 | int i; 103 | 104 | for (i = 0; objects[i]; i++) 105 | xex_print_object (objects[i]); 106 | } 107 | -------------------------------------------------------------------------------- /xextools/src/xex_display.h: -------------------------------------------------------------------------------- 1 | #ifndef XEX_DISPLAY_H 2 | #define XEX_DISPLAY_H 3 | 4 | #include "libxex.h" 5 | 6 | void xex_print_table (xex_dt_table *table); 7 | void xex_print_object (xex_object *object); 8 | void xex_print_objects (xex_object **objects); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /xextools/src/xexread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "xex_display.h" 4 | 5 | void usage (char *program) 6 | { 7 | printf ("Usage: %s \n", program); 8 | } 9 | 10 | int main (int argc, char **argv) 11 | { 12 | xex_t *xex; 13 | xex_object **objects; 14 | 15 | if (argc < 2) { 16 | usage (argv[0]); 17 | return 1; 18 | } 19 | 20 | xex = xex_load (argv[1]); 21 | 22 | /* Make sure the file is a XEX File */ 23 | 24 | if (!xex_validate (xex)) { 25 | printf ("Wrong file type, not a X360 Executable file\n"); 26 | goto cleanup; 27 | } 28 | 29 | printf ("Filename : %s\n\n", argv[1]); 30 | 31 | objects = xh_get_misc_info (xex); 32 | 33 | xex_print_objects (objects); 34 | 35 | xex_object *obj = xh_read_generic_table (xex); 36 | 37 | xex_print_table (obj->table); 38 | 39 | objects = xh_info_load_generic (xex, obj->table); 40 | 41 | xex_print_objects (objects); 42 | 43 | objects = xex_read_certificate (xex); 44 | 45 | xex_print_objects (objects); 46 | 47 | cleanup: 48 | xex_unload (xex); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /xextools/stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for config.h 2 | -------------------------------------------------------------------------------- /xflash/README: -------------------------------------------------------------------------------- 1 | Features: 2 | * read/write/erase all size nands - 16mb, 64mb, 256mb, 512mb 3 | * flash xsvf's to your CPLD (assuming your nandflasher supports that) - Nand-X 4 | * power on/off the console (assuming your nandflasher supports that and is wired correctly) 5 | * supports armV1 and armV3 flashers (where nandpro only supports armV3) 6 | 7 | Usage: 8 | 9 | xflash [-h] {read,write,erase,xsvf,update,poweroff,poweron} ... 10 | 11 | XBox 360 NAND Flasher 12 | 13 | optional arguments: 14 | -h, --help show this help message and exit 15 | 16 | Operations: 17 | {read,write,erase,xsvf,update,poweroff,poweron} 18 | read Dumps an image from the NAND 19 | write Writes an image into the NAND 20 | erase Erases blocks in the NAND 21 | xsvf Flash a CPLD with an xsvf file 22 | update Jumps into the bootloader of the NAND Flashing device 23 | for updating the firmware 24 | poweroff Shuts down the attached XBox 360 25 | poweron Powers up the attached XBox 360 26 | 27 | 28 | detailed usage for each command can be had with 29 | xflash --help 30 | 31 | Examples: 32 | # dump the full sized nand to 'nanddump.bin' 33 | $sudo xflash read nanddump.bin 34 | 35 | # write the full sized nand from 'nandflash.bin' 36 | $sudo xflash write nandflash.bin 37 | 38 | # dump the first 50 blocks worth of nand to shortdump.bin 39 | $sudo xflash read shortdump.bin 0 50 40 | 41 | # write the first 50 blocks of nand from image.ecc 42 | $sudo xflash write image.ecc 0 50 43 | 44 | Thanks / Credits: 45 | -Whoever wrote the original XFlash.py script 46 | -Anyone else involved the Free60 Project 47 | -The Makers of NandPro and the PIC Flashing code 48 | -G33KatWork (https://github.com/G33KatWork/XBox-360-AVR-flasher) - for his modifications to XFlash.py 49 | -Juvenal - current author of XFlash 1.3 50 | 51 | -------------------------------------------------------------------------------- /xflash/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | import sys, os 3 | 4 | setup(name='xflash', 5 | version='1.3.1', 6 | description='Xbox360 USB SPI Flasher client', 7 | long_description='', 8 | classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers 9 | keywords='', 10 | author='Juvenal', 11 | author_email='none@of.your.biz', 12 | url='https://github.com/Juvenal1228/XFlash/', 13 | license='BSD', 14 | packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), 15 | include_package_data=True, 16 | zip_safe=False, 17 | install_requires=[ 18 | 'pyusb>=1.0.0a1', 19 | 'argparse', 20 | ], 21 | entry_points=""" 22 | [console_scripts] 23 | xflash = xflash:main 24 | """, 25 | ) 26 | -------------------------------------------------------------------------------- /xflash/xflash/XConfig.py: -------------------------------------------------------------------------------- 1 | 2 | class XConfigParseError(Exception): 3 | pass 4 | 5 | class XConfig(object): 6 | def __init__(self, config): 7 | self.config = config 8 | self.controllertype = config >> 17 & 3 9 | self.blocktype = config >> 4 & 3 10 | 11 | self.pagesz = 0x200 12 | self.metasz = 0x10 13 | self.metatype = 0 14 | self.blocksz = 0 15 | self.sizeblocks = 0 16 | self.sizesmallblocks = 0 17 | self.fsblocks = 0 18 | ctype = self.controllertype 19 | btype = self.blocktype 20 | 21 | if ctype == 0: 22 | self.metatype = 0 23 | self.blocksz = 0x20 24 | if btype == 0: 25 | msg = 'nand type 0:0 is invalid' 26 | raise XConfigParseError(msg) 27 | elif btype == 1: 28 | self.sizeblocks = 0x400 29 | self.fsblocks = 0x3E0 30 | elif btype == 2: 31 | self.sizeblocks = 0x800 32 | self.fsblocks = 0x7C0 33 | elif btype == 3: 34 | self.sizeblocks = 0x1000 35 | self.fsblocks = 0xF80 36 | elif ctype == 1 and btype == 0: 37 | msg = 'nand type 1:0 is invalid' 38 | raise XConfigParseError(msg) 39 | elif ctype in (1, 2) and btype in (0, 1): 40 | self.metatype = 1 41 | self.blocksz = 0x20 42 | if btype == 0 or (btype == 1 and ctype == 1): 43 | self.sizeblocks = 0x400 44 | self.fsblocks = 0x3E0 45 | elif ctype == 2 and btype == 1: 46 | self.sizeblocks = 0x1000 47 | self.fsblocks = 0xF80 48 | elif ctype in (1, 2) and btype in (2, 3): 49 | self.metatype = 2 50 | if btype == 2: 51 | self.blocksz = 0x100 52 | self.sizeblocks = 1 << ((config >> 19 & 3) + (config >> 21 & 15) + 23) >> 17 53 | self.fsblocks = 0x1E0 54 | elif btype == 3: 55 | self.blocksz = 0x200 56 | self.sizeblocks = 1 << ((config >> 19 & 3) + (config >> 21 & 15) + 23) >> 18 57 | self.fsblocks = 0xF0 58 | else: 59 | msg = 'controller type %s is invalid' % ctype 60 | raise XConfigParseError(msg) 61 | self.sizesmallblocks = self.sizeblocks * (self.blocksz / 0x20) 62 | self.blocksperlittle = self.blocksz / 0x20 63 | 64 | def printConfig(self): 65 | fmt = """ 66 | FlashConfig:\t%X 67 | PageSize:\t%X 68 | MetaSize:\t%X 69 | MetaType:\t%X 70 | BlockSize:\t%X 71 | SizeInBlocks:\t%X 72 | SizeInSBlocks:\t%X 73 | FileBlocks:\t%X 74 | """ % ( 75 | self.config, 76 | self.pagesz, 77 | self.metasz, 78 | self.metatype, 79 | self.blocksz, 80 | self.sizeblocks, 81 | self.sizesmallblocks, 82 | self.fsblocks, 83 | ) 84 | print fmt 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /xflash/xflash/XStatus.py: -------------------------------------------------------------------------------- 1 | STATUS_ILL_LOG = 0x800 2 | STATUS_PIN_WP_N = 0x400 3 | STATUS_PIN_BY_N = 0x200 4 | STATUS_INT_CP = 0x100 5 | STATUS_ADDR_ER = 0x080 6 | STATUS_BB_ER = 0x040 7 | STATUS_RNP_ER = 0x020 8 | STATUS_ECC_ER = 0x01c 9 | STATUS_WR_ER = 0x002 10 | STATUS_BUSY = 0x001 11 | 12 | STATUS_OK = (STATUS_PIN_BY_N) 13 | STATUS_ERROR = (STATUS_ILL_LOG | 14 | STATUS_ADDR_ER | 15 | STATUS_BB_ER | 16 | STATUS_RNP_ER | 17 | STATUS_ECC_ER | 18 | STATUS_WR_ER) 19 | 20 | def statusIsError(status): 21 | if status & STATUS_ERROR != 0: 22 | return True 23 | if status & STATUS_OK == 0: 24 | return True 25 | return False 26 | 27 | def statusHasBit(status, bit): 28 | return status & bit != 0 --------------------------------------------------------------------------------