commit bc0c8c135d725ce45ce347c53613026e34864c2f Author: Andrew Kesterson Date: Mon May 18 12:45:01 2026 -0400 Commit code, circa 2005 diff --git a/SDIPDATA.CFG b/SDIPDATA.CFG new file mode 100755 index 0000000..a2011eb --- /dev/null +++ b/SDIPDATA.CFG @@ -0,0 +1 @@ +ON 192.168.0.4 9002 192.168.0.254 1234 \ No newline at end of file diff --git a/SDLOADER.BIN b/SDLOADER.BIN new file mode 100755 index 0000000..ac383b9 Binary files /dev/null and b/SDLOADER.BIN differ diff --git a/SDpatch.dol b/SDpatch.dol new file mode 100755 index 0000000..38e0c8a Binary files /dev/null and b/SDpatch.dol differ diff --git a/install.txt b/install.txt new file mode 100755 index 0000000..f4e684f --- /dev/null +++ b/install.txt @@ -0,0 +1,200 @@ +GameCube Action Replay SD Loader V1.00. Copyright 2005. +by Costis (costis@gbaemu.com) and Parasyte + +INSTALLATION GUIDE + +================= + Things You Need +================= + +- Action Replay (ANY version!!!) +- Nintendo SD Adapter +- SD Card (Any size) +- SD Card Reader/Writer for PC and Windows XP, NT, or 2000 (or a way to run code on GC.) + + +============== + Installation +============== + +NOTE: SDLoad works with ALL versions of the Action Replay by Datel! + +1. Ensure that your SD reader creates a virtual drive (Example: F:\) and that you + can read and write files to the card without any problems. Your SD card must also + be formatted with FAT16 (FAT12 and FAT32 are NOT supported.) + +2. Run sdpatch.exe, passing the SD reader drive letter on the command line. + (Example: sdpatch.exe F:\) + + This program will install the boot driver to the SD card. The boot driver will + only have to be installed once, and will have to be installed on each SD card you + wish to use with SD Loader. This is just the initial driver, and NOT the menu + program, so it will never have to be changed! + + Be assured that the file system of the card will remain COMPLETELY in tact after you + have run the sdpatch.exe (or alternatively sdpatch.dol) program! They have advanced + error checking, so there really is NOT any possibility for the file system on your + card to become corrupted. + + NOTE: If you do not have a computer with Windows XP, NT, or 2000 installed, or + you cannot get sdpatch.exe to work for some reason and you already have a + means of uploading code to your GameCube (such as PSO), then you can install + the boot driver to the SD card by booting sdpatch.dol to your GC and following + the on-screen instructions. + +3. Copy SDLOADER.BIN to the root directory of the SD card. This is the DOL file + selection menu that boots up after the Action Replay and lets you select what + DOL to boot from the card. Since it's simply a file on the SD card, upgrading or + replacing it is as easy as overwriting the file with a newer version in Explorer! + + You may also copy any DOL files you want to the SD card, at this point. Try the + included testdemo.dol file, as it's guaranteed to work! The SD boot menu supports + subdirectories as well, so your DOL's can be arranged inside any directories you + want. SDLOADER.BIN, however, MUST be copied to the root directory in order for + the boot driver to locate it. + +4. Additionally, the SD Loader Menu system can setup the BBA for you and allow + NETWORK BOOT support. This means that just like PSOload, you can upload DOL + or binary files from your computer through the network to your GameCube. If + you want this functionality, create a new file named SDIPDATA.CFG containing + the following text: + + ON 192.168.0.4 9002 192.168.0.254 1234 + + The format is "ON PCIP PCPORT GCIP GCPORT" and must NOT contain any additional + spaces or blank lines. Currently, due to a limitation of the current version + of PSOload released, the GC IP address must end in 254 (xxx.xxx.xxx.254) and + the GC port must be 1234. You must set the PC IP to your PC's IP address and + the PC port to any free UDP port. + + If you do not need network boot functionality, you can leave the SDIPDATA.CFG + file off of the SD card, or change the first word of the file to "OFF". + Both SDLOADER.BIN and SDIPDATA.CFG must be in the SD card's root directory. + + You can tell that the SD boot menu has recognized the network configuration file + if you see "INITIALIZING BBA..." at the top once it is running. Refer to the + "Using SD Loader" section for information on how to use the network boot feature. + +5. After installing the boot driver to your SD card, place the card and SD adapter + into your GameCube's memory card slot A. Insert the Action Replay card or a + standard memory card into slot B and start up the Action Replay. From the AR + main menu, select Action Replay Codes. Select the USA flag, then ADD NEW GAME. + Enter "SDLOAD" as the game name and push the "done" key. Now enter "(m)" as + the code name. + + Enter the following code: + + 7YPR-RKZZ-MH6W5 + D26A-PE4J-1XX2W + ZJHY-B1ZH-6P00G + + + Next, select ADD NEW CODE and name the code "SDLOAD". + Enter the following code: + + AF4H-JPF5-H1B5J + MVAB-7TQE-ABZPB + V2CK-QQ1A-Y6P72 + M5N6-CMMH-9EURT + 0JFM-3A6C-VZ6VK + KYV8-0JGV-0GR1N + 2EGU-HVKF-NDMCN + 7AH0-J9JZ-HHGNJ + 4MHU-G8XT-ZRYCJ + 9474-KF41-8KG34 + QMEV-G90N-A8RV0 + KD4G-5QHV-74D46 + V97K-652Q-Y4TEY + 6M4W-9GPT-E99NG + QPFY-DJAF-E01FV + 2Z6E-P2WY-24WV4 + 6NHW-G3NH-HP31Y + A2KF-MCKN-D645J + K5V8-EF9W-7GFQC + XTU3-269T-VH5NE + H9GP-C4PP-6FGF9 + HF77-R45C-ZXPDV + 22Y3-D98C-50AJM + WTWZ-EC88-U5ZTV + 36G1-UGDG-J2G84 + DUMT-15KR-DXJ8K + JV55-6VF5-2Z02T + D4R8-MVJ5-QGR21 + 1G3C-APD7-1CUVD + + + Finally, select the code named "SDLOAD" and press A to enable it. (The + check box next to the code name will be filled when the code is enabled.) + Press START and open/close the lid when asked. + +6. The SD Loader main menu will now be shown on the screen. At this point, you can + select from all dol files you have written to the SD card. You can also pull + the SD card out and write new files to it. Just reinsert the SD card when ready + and the SD Loader menu will refresh the card contents. If you have written the + configuration file for network boot, you can also boot a GC executable with it + at any time of your choice. + + +================= + Using SD Loader +================= + +Many versions of Action Replay contain a bug that will keep newly entered codes +disabled. The second time you use SD Loader, you must enable the code from the +code list. After this has been done, the enabled code will be saved to the card +in slot B. + +You can then get into the SD Loader menu by simply selecting START from the AR +main menu and open/close the disc cover when asked. That's right! All it will +take from this point on to boot back into the menu is simply turning on your GC, +pressing A, and opening\closing your GameCube's cover once! + +Some newer versions of Action Replay may disallow booting their own discs. The +Japanese "Pro Action Replay" is especially sensitive. If you are unable to get +the SD Loader menu to show up (if the GameCube hangs after closing the disc lid, +for example) then you may be required to swap discs when the AR asks. Any game +disc will work, so long as the GameCube can read it properly. +To do this, select START from the AR main manu, as usual. Open the disc cover +and replace the AR disc with another disc. For example, Super Smash Bros. Melee +or Pikmin (whatever games you have). After closing the disc cover, the SD Loader +menu will show up! + +To use the network boot functionality with PSO Loader v2.0, the GC's IP address +must be x.x.x.254, and the GC's Port must be set to 1234. (See the installation +notes above) Use psoload's -r switch to send dol files. +For example: + +psoload.exe -r -u9002 testdemo.dol + + + +=============== + DOL Reloading +=============== + +SD Loader supports DOL reloading in the same way as PSO Loader. To add reload +support to your own DOL files, jump to address 0x80001800 in GameCube memory. +You can achieve this in C by either using function pointers, or by using some +inline assembly: + +asm ("lis 3, 0x8000"); +asm ("ori 3, 3, 0x1800"); +asm ("mtlr 3"); +asm ("blr"); + +Once the reloader has been invoked, the SD card browser menu will be reloaded +and you will be able to network boot again or select another DOL file from the +card to load. + + +============== + Known Issues +============== + +- A few DOL files which rely on Phantasy Star Online may not work well with SD loader. +- The the SD Loader Menu will not show up if the SD card Adapter is removed or + inserted while in the Action Replay menu. The SD card adapter CAN be removed to change + cards or make changes to the current card while in the SD card boot menu, however! +- PC IP must be correct in the SDIPDATA.CFG file if you choose to use it. Otherwise the + menu code may hang. + diff --git a/readme.txt b/readme.txt new file mode 100755 index 0000000..c276e27 --- /dev/null +++ b/readme.txt @@ -0,0 +1,316 @@ +GameCube Action Replay SD Loader V1.00. Copyright 2005. +by Costis (costis@gbaemu.com and http://www.gcdev.com) + +README FIRST!!! + +=================== + Short Description +=================== + +The Action Replay SD Loader (or SDLOAD for short) is an tool which +allows you to boot code on an unmodified GameCube within 10 to 15 +seconds from the time you turn it on! It makes use of an Action Replay +code which tricks the GameCube into running my bootloader code and loading +my SD card selection menu. The selection menu supports all these features: + +- Loading any DOL file from the SD card in any directory and subdirectory. +- Loading any DOL or binary file with PSOload from your computer through + the network. +- Reloading or exiting back to the SD selection menu from your programs + by branching to the small reloader code (just like in PSOload V2.00). +- NO need for a modified GameCube, works on ALL unmodified GameCubes. +- Works on EVERY Action Replay revision -- One code to rule them all! +- Only 29 codes to insert once. They are saved on the Action Replay + memory card after you have written them in the first time and you + just have to select "Start Game" every subsequent time to boot into + the SD loader menu. +- Can be installed WITHOUT a way to run code on the GameCube prior to + this! All you need is an Action Replay, an SD card adapter for the + GameCube, and an SD card. +- Boots to the SDLOADER selection menu on the FIRST Action Replay boot. + +Please read the sections below even though they are lengthy. This can +be the IDEAL GameCube development solution for you! Once you are done +reading and are ready to try out my loader, follow the installation +process in install.txt. + +Also, if you are a developer or hacker, I have included a special section +for you at the end of this readme about source code, etc.... + +Having problems with the loader or cannot get it to work? Post on the +GCDev.com forums with a clear description of your problem or even e-mail +me at costis@gbaemu.com and I will try to get back to you as soon as +possible with the solution. Also, I'd love to hear feedback for this project, +especially after all of the hard work I have to put into it! Send ALL +comments, suggestions, and even constructive criticism to costis@gbaemu.com +as well or likewise post on the forums. + + +====================== + Detailed Description +====================== + +Well... As I promised around a week ago, here it is -- my surprise +GameCube release on New Year's day! Happy New Year everyone!!!! + +Around two years ago, I released a program called PSOload which allowed +people to boot their own homebrew code on the GameCube by exploiting +a network feature of the online game Phantasy Star Online. GameCube +development has come a long way since then, and I find it simply amazing +how many people have ardently coped with the annoyance and inefficiencies +of having to boot through PSO every single time, waiting for it to load +through the title screens, going through the main menu, and then finally +waiting for it to connect to my loader server! I myself used this method +of code uploading for quite some time (until I lost my PSO disk ;)) + +I estimate that it takes more than 2 minutes or so to boot code each time +using the PSO exploit method from the time when the GameCube is turned on! +Sure, now that the viper chip has been released and tmbinc has released +sources for his homebrew BIOS replacement chip, people can go modify their +GC's and run code on them right when they are turned on. But there are many +disadvantages to modifying your GameCube... + + 1. You have to open your GameCube console, voiding your warranty. + 2. If something goes wrong in the installation, you may be forever + left with a broken GameCube. + 3. You can only boot code on that GameCube itself, not on any other + unmodified GameCube's so you can't really show your stuff off + to friends on their own GC's. + 4. The installation process is much more complicated and there are + countless places where it can go wrong... + 5. This new code loading method I have released allows you to develop + for the GameCube just as efficiently as with a modified console! + +SO what is this tool I am releasing? I like to call it SDLOAD. It is a completely +different method of uploading code on unmodified GC's. It takes approximately +10 to 15 seconds from the time you have turned on your GC to the time you are +able to boot any DOL file of your choice. How does this work you say? My SD +bootloader makes use of the Action Replay in order to exploit the GameCube +and gain full control over it, allowing the user to select any homebrew file +to load and run. The Action Replay is a product made by Datel, which normally +allows users to "enhance" their gaming experiences by entering cheat codes for +GameCube games. It can be bought for around $30 at any local video game store or +online at places such as GameStop (http://www.gamestop.com.) + +This is the part that Parasyte contributed a huge amount to... After many hours +of hard work, Parasyte came up with a method to trick ANY version Action Replay +disk to patch *itself* rather than any other game with a small amount of GC +program code encrypted in special Action Replay codes! After the code has been +entered, you select "Start Game", open and close the cover once, and the Action +Replay happily patches itself with a very small amount of code of my choice! + +I had an SD card adapter for the GC laying around, so I came up with the idea of +trying to cram an SD card bootloader inside this small code space... After much +optimization and pure PowerPC assembly code writing, I came up with 29 Action +Replay codes which can be used to load code from an SD card, and this is where +SDLOAD was born! + +This is how it works... You need an SD card adapter (which you can either buy +from places like Lik-Sang, make yourself -- see included instructions, or kindly +request for me to make and sell you one), an Action Replay disk (can be bought +in most stores), an SD card reader for the PC, and of course... an SD card! +That's it! Just these items and you can be set to run code on ANY unmodified +GameCube within seconds!!! I know how tedious it is to have to enter AR codes +by hand, especially if you do not own a GC keyboard and have to use the controller, +so I have worked very hard and have managed to fit the whole bootloader init code +in only 29 AR codes. To "install" SDLOAD, you just have to enter the bootloader code +in the AR and prepare the SD card with the SD card reader and my included PC program. +After you have completed these two steps, you are set to run the SDLOADER menu program +by simply turning on your GameCube, pressing A to Start Game, and opening and closing +the DVD disk cover. + +=============== + SDLOADER MENU +=============== + +Once you are greeted with the menu, you have the power of running homebrew GC code +in your hands! The menu will display a directory and file listing of all of the +DOL files on the SD card. You can browse through and even go into multiple subdirectories. +Use the UP and DOWN D-PAD buttons to step through the menu items in those directions. +The scrollbar on the right side indicates your current position. Press the A button +over a folder in order to go inside that folder, and press A over a DOL file in order +to load that file from the card and execute it. The L trigger button takes you to +the very top of the directory (HOME), and the R trigger button takes you to the very +bottom of the current directory (END). Pressing the B button will lead you to the parent +directory (alternatively you can press A over the ".." folder item to be taken back +to the parent folder.) Finally, the Z button will always return you to the root +directory of the card. + +You can remove the SD card at ANY time while the menu program is running. Once you +have removed the SD card from the memory card slot, the menu will detect this and +will say "REINSERT SD CARD IN SLOT A" at the top right part of the screen. You may +now make any changes to the SD card you want or even reinsert a different SD card, +and the loader will refresh the dir listing. + +There is also a preliminary feature for using programs that do not know how to unlock +official Nintendo memory cards properly (specifically GCS...) I believe this may only +work properly with 59 block cards, but whatever. If you use the X button over a DOL file, +the menu will load it just like if you pressed the A button. However, once it has finished +reading the file from the card, it will say "REMOVE SD CARD" at the top right of the screen. +Once you remove the card from the slot, it will request "INSERT MEMCARD". Insert a +memory card into slot A at this point and SDLOADER will unlock it before executing +the DOL file which it has just loaded! + +Finally, the last two features of the current release are especially useful for homebrew +developers... I have added a Network Boot feature. This allows you to configure the +SDLOADER menu to initialize the BBA and accept DOL or binary files from PSOload at ANY +time while the menu is running. While the BBA has been activated, the PSOload detection +code is running in the background, so you are still free to traverse through the menus +and select a DOL to boot from the SD card itself. However, once you run PSOload with +the -r option, the menu will say "NETWORK BOOT..." in the top right and will load and +execute a GC executable from PSOload through the network. This should make quick changes +and test cycles extremely efficient, reducing the need to write every new build to the +SD card and exchange it back and forth between your GC and PC reader. Details for +configuring SDLOADER to set up the BBA and work with network boot are all included +in install.txt which is included in this package. + +Continuing with the tradition of the reload feature in PSOload, I have included a +reloader feature in SDLOADER as well! In fact, I have been able to make it function +in the exact same way as the PSOload reload feature to the user, except it is even +better this time. Last time, if you executed the reloader before you had PSOload -r +running on your computer, the GameCube would crash. Now, if you jump to the reloader +code, it will reload the menu program from the SD card and execute it, allowing you +to either boot a new DOL from the SD card itself or load another executable from +the network through PSOload -r! Make sure that the sD card is inserted before +using the reloader feature to exit back to the menu, of course. Once again, exact +details for using the reloader feature (including example code for invoking it) +can be found in install.txt + +=================== + SD CARD CONNECTOR +=================== + +I realize that Lik-Sang is one one of the only places where you can buy an SD card +adapter for the GameCube if you are not located in Japan, and they have it for +pretty expensive... ($30 or so). The SD card adapter is very simple hardware, however. +In fact, it is "straight-through" and a homebrew adapter can be made by hacking up +an old GC memory card and soldering a few wires to an SD card connector. SD card connectors +can be removed from cheap SD card readers or even bought as discrete components from +electronic parts stores or online catalogs such as Digikey (http://www.digikey.com). + +To make the connector follow this guide: + +In this PDF document (http://www.egr.msu.edu/classes/ece480/goodman/fall/group05/deliverables/appnote_foust.pdf) +on the second page, there is a pinout of a standard SD card. Match these pins to your +SD connector. + +DarkFader has a memory card connector pinout in this photo: +http://darkfader.net/ngc/files/memcard.jpg + +You must connect the two VSS pins (VSS and VSS2) on the SD card connector together +and to GND on the memory card pad (pin 2 or pin 10). You must connect VCC to 3.3V (pin 8). +You must connect the CLK pin on the SD card to the CLK pad on the memcard (pin 11). +You must connect the CS pin on the SD card to the CS pad on the memcard (pin 9). +You must connect the MOSI pin on the SD card to the MOSI pad on the memcard (pin 5). +Finally, you must connect the MISO pin on the SD card to the MISO pad on the memcard (pin 7.) + +It's around 3 A.M. at night right now, so I am too tired to write a proper how-to +guide with photos and diagrams, etc. But I have promised to release this tonight, +so I am keeping my promise. I will release such a detailed guide within the coming +days to facilitate the process. + +I really do not want the difficulty of obtaining an SD card adapter to hinder +people from using my loader, so if you definitely cannot buy one from an online +store such as Lik-Sang (http://www.lik-sang.com) and do not feel comfortable +making your own, feel free to send me an e-mail and I can probably arrange to make +a homebrew connector for you, provided that you pay all component and shipping +expenses. I estimate that it'll cost maybe around $10-15 or so per connector. + +I have high hopes that my SD bootloader will become THE new development solution for +the GameCube. SD cards are high density, so you can put EVERY homebrew DOL file ever +created on an SD card and have them all to load whenever you want. You can take +your Action Replay disk and SD card to friends' houses and show them all your +neat new GameCube stuff on their own GC's. This does NOT require a PC to boot +code once you have the DOL files on your SD card, so you do not have to drag +laptops along with you, and it works on all GameCubes, so you do not have to +bring along your whole GameCube if you are using a mod-chip for development! + +PLEASE do not let the SD card connector discourage you from trying out this +loader. Like I said, I would be happy to make a few connectors and give them +out for as cheap as I can without a deficit. Send me an e-mail at costis@gbaemu.com +if you want to do this, although if buying an official adapter is not a problem +for you, *please* respect my time and go for that instead. It will look far more +professional anyway, and you will have the guarantee of its durability. And after +all, $30 is almost nothing compared to the cost and rarity of BroadBand Adapters +right now. The PSO method right now costs around $60 for PSO (which is very +difficult to find in stores because it has been discontinued) and $40 for the BBA. +This totals to around $100! For SDLOAD, the Action Replay costs only $30, and the +SD card adapter costs $30 as well if you get the official one! That totals to around +$60 for a complete GameCube development environment that is arguably even MORE +efficient than modifyng your GC with a mod-chip. You may also be able to find +old Action Replay disks on E-Bay for much cheaper. + +================= + FOR DEVELOPERS +================= + +I have included the full source code of the sdpatch.exe program (see install.txt +for instructions on how to use it and what it is for.) The main reason for this is +that it is specific to NT operating systems (Windows NT/2000/XP) and I have no knowledge +of the Linux or Mac OS X operating systems myself... Knowing that many people use +these alternative operating systems (from experience with PSOload), I have released +the source code so that anyone can port it to any other operating system. sdpatch.exe +does use a lot of system specific calls, but it should easily be portable to Linux +and Mac OS X by replacing them with the low-level equivalents for those OS's. If anyone +ports sdpatch.exe to any other OS than Windows, please contact me and I will upload +it to GCDev.com for posting. + +The menu program that is loaded after you open and close the cover on the Action Replay +(SDLOADER) is just a simple file on the SD card. It's the file that you copied to the +root directory of the card while following the installation text called SDLOADER.BIN. +This file is a simple GameCube executable binary which is loaded and copied to RAM +location 0x81700000 (the high 1MB of RAM on the GC's 24MB of main RAM.) You can easily +replace SDLOADER.BIN with your own creation to have it boot at start-up instead of +the default menu if you choose to do so. Just set your compiler to compile for a +target text base section of 0x81700000 (-Ttext 0x81700000) and then use objcopy to +convert the output ELF file from the linker to a binary: + +powerpc-elf-objcopy -O binary sdloader.elf SDLOADER.BIN (for example...) + +The only precaution you have to take is that your binary file is 1MB or less in size, +as otherwise it will overflow through the top of the GC's RAM! + +======================= + CREDITS AND GREETINGS +======================= + +I would like to thank Parasyte first and foremost for making this loader a +possibility. He figured out the incredible Action Replay patching method +which allowed me to create an SD card bootloader code which works on EVERY +Action Replay and on the first boot. He also provided me with stable +network code for interfacing the BroadBand Adapter and helped me test every +stage of the loader as a whole until I got rid of all the visible bugs. + +Other credits and greetings (in no specific order) go out to... + +DayDream -- HUGE thanks for drawing the SD logo at the top of SDLOADER!!!! +smilydude -- Thanks for making some FAT16 raw test images for me! +BigRedPmp +Lord_NightMare +tmbinc +dovoto +The_1 -- Thanks for testing out some AR codes on your Action Replay! +SubDrag +Sappharad +joat +kevtris +DuoDreamer +DarkFader +groepaz +DesktopMan -- Thanks for donating the SD card connector in the first place! +Myria +Samson +sgstair +asterick +Zeus +JustBurn +Guyfawkes +woo + +And everyone else I have missed!!! + +You can contact me at costis@gbaemu.com or by making a post on the GCDev.com forums: +http://forums.gcdev.com. http://www.gcdev.com is and always WILL be the home site +of this project. + +Help me make this project a success! AND HAPPY NEW YEAR EVERYONE!!!!!! \ No newline at end of file diff --git a/src/.svn/all-wcprops b/src/.svn/all-wcprops new file mode 100755 index 0000000..da6d558 --- /dev/null +++ b/src/.svn/all-wcprops @@ -0,0 +1,23 @@ +K 25 +svn:wc:ra_dav:version-url +V 40 +/svn/aklabs/!svn/ver/12/trunk/sdload/src +END +StdAfx.h +K 25 +svn:wc:ra_dav:version-url +V 49 +/svn/aklabs/!svn/ver/12/trunk/sdload/src/StdAfx.h +END +SDpatch.cpp +K 25 +svn:wc:ra_dav:version-url +V 52 +/svn/aklabs/!svn/ver/12/trunk/sdload/src/SDpatch.cpp +END +StdAfx.cpp +K 25 +svn:wc:ra_dav:version-url +V 51 +/svn/aklabs/!svn/ver/12/trunk/sdload/src/StdAfx.cpp +END diff --git a/src/.svn/entries b/src/.svn/entries new file mode 100755 index 0000000..c1a5a16 --- /dev/null +++ b/src/.svn/entries @@ -0,0 +1,133 @@ +10 + +dir +44 +https://127.0.0.1/svn/aklabs/trunk/sdload/src +https://127.0.0.1/svn/aklabs + + + +2007-05-26T23:54:26.388980Z +12 +andrew + + + + + + + + + + + + + + +eb184899-6090-47d4-a65b-558f62f6ea1c + +StdAfx.h +file + + + + +2010-02-05T03:38:37.448248Z +e8e5c1f00c8cf3a330ca2d8e50cb51e1 +2007-05-26T23:54:26.388980Z +12 +andrew +has-props + + + + + + + + + + + + + + + + + + + + +667 + +SDpatch.cpp +file + + + + +2010-02-05T03:38:37.463873Z +93ae488c00f97aca04f0964e4728e860 +2007-05-26T23:54:26.388980Z +12 +andrew +has-props + + + + + + + + + + + + + + + + + + + + +12008 + +StdAfx.cpp +file + + + + +2010-02-05T03:38:37.463873Z +6f6c522057b40e4e3537b61d8bd430e0 +2007-05-26T23:54:26.388980Z +12 +andrew +has-props + + + + + + + + + + + + + + + + + + + + +294 + +CVS +dir + diff --git a/src/.svn/prop-base/SDpatch.cpp.svn-base b/src/.svn/prop-base/SDpatch.cpp.svn-base new file mode 100755 index 0000000..a669705 --- /dev/null +++ b/src/.svn/prop-base/SDpatch.cpp.svn-base @@ -0,0 +1,5 @@ +K 14 +svn:executable +V 0 + +END diff --git a/src/.svn/prop-base/StdAfx.cpp.svn-base b/src/.svn/prop-base/StdAfx.cpp.svn-base new file mode 100755 index 0000000..a669705 --- /dev/null +++ b/src/.svn/prop-base/StdAfx.cpp.svn-base @@ -0,0 +1,5 @@ +K 14 +svn:executable +V 0 + +END diff --git a/src/.svn/prop-base/StdAfx.h.svn-base b/src/.svn/prop-base/StdAfx.h.svn-base new file mode 100755 index 0000000..a669705 --- /dev/null +++ b/src/.svn/prop-base/StdAfx.h.svn-base @@ -0,0 +1,5 @@ +K 14 +svn:executable +V 0 + +END diff --git a/src/.svn/text-base/SDpatch.cpp.svn-base b/src/.svn/text-base/SDpatch.cpp.svn-base new file mode 100755 index 0000000..4321f9b --- /dev/null +++ b/src/.svn/text-base/SDpatch.cpp.svn-base @@ -0,0 +1,267 @@ +// SDpatch.cpp : Defines the entry point for the console application. +// by Costis. Copyright 2005. +// +// This is the source code for the SDpatch.exe program described in +// the install.txt documentation. Feel free to port it to any OS of +// your choice and send it to me for release! +// + + +#include "stdafx.h" + + +#include +#include +#include + +const char *OS_version = "Windows 2000\\NT\\XP"; + +// Usage. +void usage (void) +{ + printf ("Usage: SDpatch.exe drive_letter\n\n"); + printf ("\tdrive_letter\tSD card drive letter mapped by Windows.\n\n"); + printf ("WARNING: If you choose the wrong drive letter, such as\n"); + printf ("\t one mapped to a hard drive, there is a large\n"); + printf ("\t possibility that the drive contents will become\n"); + printf ("\t corrupted!!! CHOOSE THE DRIVE LETTER CAREFULLY!\n"); + exit (0); +} + +// This is the level 2 boot-code for file systems without MBR's. +const int sd_lev2_vbr_size = 352; +const unsigned char sd_lev2_vbr[352] = {0x90, 0x63, 0x68, 0x00, 0x7D, 0x3B, 0x4B, 0x78, 0x3A, 0x20, 0x02, 0x02, 0x3D, 0x20, 0x80, 0x10, + 0x3B, 0x40, 0xFF, 0xD6, 0x7F, 0x5B, 0xD6, 0x2C, 0x3B, 0x20, 0xFF, 0xCE, 0x7F, 0x3B, 0xCE, 0x2C, + 0x8A, 0xFB, 0xFF, 0xD0, 0x7F, 0x5A, 0xB9, 0xD6, 0x57, 0x56, 0x48, 0x2C, 0x7E, 0xE9, 0xB2, 0x14, + 0x7D, 0x36, 0x4B, 0x78, 0x7F, 0x19, 0xD2, 0x14, 0x8B, 0x9B, 0xFF, 0xD1, 0x8B, 0x5B, 0xFF, 0xD2, + 0x53, 0x5C, 0x44, 0x2E, 0x3B, 0x9C, 0x00, 0x0F, 0x57, 0x9C, 0xE1, 0x3E, 0x7F, 0x18, 0xE2, 0x14, + 0x57, 0x27, 0x48, 0x1E, 0x53, 0x27, 0x4C, 0x2C, 0x48, 0x00, 0x00, 0x95, 0x39, 0x29, 0x02, 0x00, + 0x3B, 0x39, 0x00, 0x01, 0x7C, 0x19, 0xC0, 0x00, 0x40, 0x82, 0xFF, 0xE8, 0x83, 0x17, 0x00, 0x00, + 0x3F, 0x18, 0xAC, 0xBC, 0x37, 0x18, 0xB3, 0xB1, 0x40, 0x82, 0x00, 0x14, 0x83, 0x17, 0x00, 0x04, + 0x3F, 0x18, 0xBE, 0xBC, 0x37, 0x18, 0xBA, 0xAE, 0x41, 0x82, 0x00, 0x0C, 0x3A, 0xF7, 0x00, 0x20, + 0x4B, 0xFF, 0xFF, 0xDC, 0x3B, 0x00, 0x00, 0x1A, 0x7F, 0x17, 0xC6, 0x2C, 0x8B, 0x5B, 0xFF, 0xCD, + 0x3D, 0x20, 0x81, 0x70, 0x3A, 0xF8, 0xFF, 0xFE, 0x7E, 0xF7, 0xD1, 0xD6, 0x7E, 0xF7, 0xCA, 0x14, + 0x7E, 0xB7, 0xD2, 0x14, 0x56, 0xE7, 0x48, 0x1E, 0x52, 0xE7, 0x4C, 0x2C, 0x48, 0x00, 0x00, 0x31, + 0x39, 0x29, 0x02, 0x00, 0x3A, 0xF7, 0x00, 0x01, 0x7C, 0x17, 0xA8, 0x00, 0x40, 0x82, 0xFF, 0xE8, + 0x57, 0x18, 0x08, 0x3C, 0x7F, 0x16, 0xC6, 0x2C, 0x28, 0x18, 0xFF, 0xF7, 0x41, 0x80, 0xFF, 0xC8, + 0x3D, 0x20, 0x81, 0x70, 0x7D, 0x28, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x21, 0x7D, 0x48, 0x02, 0xA6, + 0x7E, 0x29, 0x03, 0xA6, 0x90, 0xA3, 0x68, 0x00, 0x4B, 0x00, 0x18, 0x7D, 0x3F, 0xA0, 0x51, 0x00, + 0x4B, 0x00, 0x18, 0x75, 0x3B, 0x80, 0x00, 0x00, 0x7C, 0xFD, 0xE0, 0x30, 0x4B, 0x00, 0x18, 0x69, + 0x3B, 0x9C, 0x00, 0x08, 0x2C, 0x1C, 0x00, 0x20, 0x40, 0x82, 0xFF, 0xF0, 0x3F, 0xA0, 0x95, 0x00, + 0x4B, 0x00, 0x18, 0x55, 0x3F, 0xA0, 0xFF, 0x00, 0x4B, 0x00, 0x18, 0x4D, 0x4B, 0x00, 0x18, 0x49, + 0x3C, 0x9F, 0x02, 0x00, 0x74, 0x84, 0xFF, 0x00, 0x40, 0x82, 0xFF, 0xF4, 0x4B, 0x00, 0x18, 0x39, + 0x57, 0xFF, 0x46, 0x3E, 0x7F, 0xE9, 0x21, 0xAE, 0x7C, 0x09, 0x20, 0xAC, 0x38, 0x84, 0x00, 0x01, + 0x42, 0x00, 0xFF, 0xEC, 0x90, 0x63, 0x68, 0x00, 0x7D, 0x48, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20}; + +// This is the level 2 boot-code for MBR based file systems. +const int sd_lev2_mbr_size = 380; +const unsigned char sd_lev2_mbr[380] = {0x90, 0x63, 0x68, 0x00, 0x3A, 0x20, 0x02, 0x02, 0x3B, 0x00, 0x01, 0x86, 0x7F, 0x09, 0xC4, 0x2C, + 0x57, 0x07, 0x48, 0x1E, 0x53, 0x07, 0x4C, 0x2C, 0x3D, 0x20, 0x81, 0x01, 0x48, 0x00, 0x00, 0xED, + 0x3B, 0x69, 0x00, 0x40, 0x3D, 0x20, 0x80, 0x10, 0x3B, 0x40, 0xFF, 0xD6, 0x7F, 0x5B, 0xD6, 0x2C, + 0x3B, 0x20, 0xFF, 0xCE, 0x7F, 0x3B, 0xCE, 0x2C, 0x7F, 0x39, 0xC2, 0x14, 0x8A, 0xFB, 0xFF, 0xD0, + 0x7F, 0x5A, 0xB9, 0xD6, 0x57, 0x56, 0x48, 0x2C, 0x7E, 0xE9, 0xB2, 0x14, 0x7D, 0x36, 0x4B, 0x78, + 0x7F, 0x19, 0xD2, 0x14, 0x8B, 0x9B, 0xFF, 0xD1, 0x8B, 0x5B, 0xFF, 0xD2, 0x53, 0x5C, 0x44, 0x2E, + 0x3B, 0x9C, 0x00, 0x0F, 0x57, 0x9C, 0xE1, 0x3E, 0x7F, 0x18, 0xE2, 0x14, 0x57, 0x27, 0x48, 0x1E, + 0x53, 0x27, 0x4C, 0x2C, 0x48, 0x00, 0x00, 0x95, 0x39, 0x29, 0x02, 0x00, 0x3B, 0x39, 0x00, 0x01, + 0x7C, 0x19, 0xC0, 0x00, 0x40, 0x82, 0xFF, 0xE8, 0x83, 0x17, 0x00, 0x00, 0x3F, 0x18, 0xAC, 0xBC, + 0x37, 0x18, 0xB3, 0xB1, 0x40, 0x82, 0x00, 0x14, 0x83, 0x17, 0x00, 0x04, 0x3F, 0x18, 0xBE, 0xBC, + 0x37, 0x18, 0xBA, 0xAE, 0x41, 0x82, 0x00, 0x0C, 0x3A, 0xF7, 0x00, 0x20, 0x4B, 0xFF, 0xFF, 0xDC, + 0x3B, 0x00, 0x00, 0x1A, 0x7F, 0x17, 0xC6, 0x2C, 0x8B, 0x5B, 0xFF, 0xCD, 0x3D, 0x20, 0x81, 0x70, + 0x3A, 0xF8, 0xFF, 0xFE, 0x7E, 0xF7, 0xD1, 0xD6, 0x7E, 0xF7, 0xCA, 0x14, 0x7E, 0xB7, 0xD2, 0x14, + 0x56, 0xE7, 0x48, 0x1E, 0x52, 0xE7, 0x4C, 0x2C, 0x48, 0x00, 0x00, 0x31, 0x39, 0x29, 0x02, 0x00, + 0x3A, 0xF7, 0x00, 0x01, 0x7C, 0x17, 0xA8, 0x00, 0x40, 0x82, 0xFF, 0xE8, 0x57, 0x18, 0x08, 0x3C, + 0x7F, 0x16, 0xC6, 0x2C, 0x28, 0x18, 0xFF, 0xF7, 0x41, 0x80, 0xFF, 0xC8, 0x3D, 0x20, 0x81, 0x70, + 0x7D, 0x28, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x21, 0x7D, 0x48, 0x02, 0xA6, 0x7E, 0x29, 0x03, 0xA6, + 0x90, 0xA3, 0x68, 0x00, 0x4B, 0x00, 0x18, 0x61, 0x3F, 0xA0, 0x51, 0x00, 0x4B, 0x00, 0x18, 0x59, + 0x3B, 0x80, 0x00, 0x00, 0x7C, 0xFD, 0xE0, 0x30, 0x4B, 0x00, 0x18, 0x4D, 0x3B, 0x9C, 0x00, 0x08, + 0x2C, 0x1C, 0x00, 0x20, 0x40, 0x82, 0xFF, 0xF0, 0x3F, 0xA0, 0x95, 0x00, 0x4B, 0x00, 0x18, 0x39, + 0x3F, 0xA0, 0xFF, 0x00, 0x4B, 0x00, 0x18, 0x31, 0x4B, 0x00, 0x18, 0x2D, 0x3C, 0x9F, 0x02, 0x00, + 0x74, 0x84, 0xFF, 0x00, 0x40, 0x82, 0xFF, 0xF4, 0x4B, 0x00, 0x18, 0x1D, 0x57, 0xFF, 0x46, 0x3E, + 0x7F, 0xE9, 0x21, 0xAE, 0x7C, 0x09, 0x20, 0xAC, 0x38, 0x84, 0x00, 0x01, 0x42, 0x00, 0xFF, 0xEC, + 0x90, 0x63, 0x68, 0x00, 0x7D, 0x48, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20}; + +int main(int argc, char* argv[]) +{ + int i, ptype; + HANDLE mfile; + DWORD ret; + unsigned char mbuf[512], vbuf[512]; + char tname[512]; + char buffer[MAX_PATH]; + const unsigned char *sd_lev2; + unsigned long sd_lev2_size; + + printf ("SDLoad Card Patcher V1.00 by Costis\n"); + printf ("(%s Version)\n", OS_version); + + // Check the operating system version... + if (GetVersion() & 0x80000000) + { + // Oops! The user has tried to run this under an incompatible OS! + printf ("This program can only be run from Windows 2000\\NT\\XP.\n"); + exit (0); + } + + // Check if the user has passed a valid parameter... + if (argc != 2) + usage (); + + if ((((argv[1][0] < 'A') || (argv[1][0] > 'Z')) && ((argv[1][0] < 'a') || (argv[1][0] > 'z'))) || + (strlen(argv[1]) > 3)) + { + // The drive letter must be from A through Z and + // drive letters must be specified as X, X:, or even X:/ + printf ("Invalid drive letter specification.\n"); + exit (0); + } + + // Fix the drive letter so that QueryDosDevice accepts it. + argv[1][1] = ':'; + argv[1][2] = 0; + + // Check to make sure the drive is removable... + // We don't want a user accidentally corrupting their + // hard drive's MBR! + if (GetDriveType(argv[1]) != DRIVE_REMOVABLE) + { + // Oh, oh! A drive which is not removable has been selected... + printf ("The drive selected is not a removable device.\n"); + printf ("Please specify the drive letter of the SD card adapter!\n"); + exit (0); + } + + printf ("\nQuerying device name of drive %s...", argv[1]); + + ret = QueryDosDevice(argv[1], buffer, sizeof(buffer)); + if (!ret) + { + // The user has selected an invalid driver letter... + printf ("Failed. Invalid drive letter!\n"); + exit (0); + } else + printf ("OK!\n"); + + // Success! We have retrieved a low-level device name for the specified + // drive letter. We want to access partition 0, so remove the last part + // from it which is not needed... + for (i = strlen (buffer) - 1; i >= 0; i--) + { + if (buffer[i] == '\\') + { + buffer[i] = 0; + break; + } + } + // And append a Partition0 indicator to the end of it... + sprintf (tname, "\\\\.\\GLOBALROOT\\%s\\Partition0", buffer); + printf ("Device name: %s\n", tname); + + // Create a low-level Windows file to access the drive as a raw device. + printf ("Obtaining low-level access to drive..."); + mfile = CreateFile (tname, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); + if (mfile == INVALID_HANDLE_VALUE) + { + // Error! + printf ("Failed. Could not create file!\n"); + exit (0); + } else + printf ("OK!\n"); + + printf ("Reading first sector..."); + SetFilePointer (mfile, 0, NULL, FILE_BEGIN); + ReadFile (mfile, &mbuf, 512, &ret, NULL); + if (ret != 512) + { + // Error! Maybe the user has forgotten to insert an SD card?!?! + printf ("Failed! Make sure a working SD card is inserted!\n"); + CloseHandle (mfile); + exit (0); + } else + printf ("OK!\n"); + + // Success! We have managed to read out the first sector of the drive. + // Check byte index 0x15 (drive media type descriptor) and byte index + // 0x26 (extended signature) to find out whether this sector is a + // master boot record or a volume boot record... + if ((mbuf[0x26] == 0x29) && (mbuf[0x15] == 0xF8)) + { + // This is a volume boot record, NOT a master boot record... + printf ("Volume Boot Record found in Sector 0.\n"); + // We therefore want to patch in the VBR level 2 code: + ptype = 1; + sd_lev2 = sd_lev2_vbr; + sd_lev2_size = sd_lev2_vbr_size; + } else { + // This is a master boot record... + printf ("Master Boot Record found in Sector 0.\n"); + // We therefore want to patch in the MBR level 2 code: + ptype = 0; + sd_lev2 = sd_lev2_mbr; + sd_lev2_size = sd_lev2_mbr_size; + } + + printf ("Inserting level 2 boot-code in %cBR...", (ptype ? 'V' : 'M')); + + // Patch in the code in the right offset... + memcpy (mbuf + 0x40, sd_lev2, sd_lev2_size); + + // Attempt to write the new sector 0 back to the card. + SetFilePointer (mfile, 0, NULL, FILE_BEGIN); + WriteFile (mfile, mbuf, 512, &ret, NULL); + + if (ret != 512) + { + // Write failure! Maybe the user has write protected their card?!?! + printf ("Write Error! Check the write protect switch on the SD card.\n"); + CloseHandle (mfile); + exit (0); + } else + printf ("OK!\n"); + + // Apparently our write succeeded! Let's check to make sure... + printf ("Verifying Master Boot Record..."); + + // Read sector 0 again. + SetFilePointer (mfile, 0, NULL, FILE_BEGIN); + ReadFile (mfile, &vbuf, 512, &ret, NULL); + if (ret != 512) + { + printf ("Read Error!\n"); + CloseHandle (mfile); + exit (0); + } + + // Compare the new read back sector 0, with the one that was suppsoed to + // have been written. + if (memcmp (mbuf, vbuf, 512) != 0) + { + // Oops! They are not the same... + printf ("Verification Failed!\n"); + CloseHandle (mfile); + exit (0); + } else + printf ("OK!\n"); + + // Success! We can now release the file handle back to Windows... + printf ("Releasing low-level access handle..."); + + if (!CloseHandle (mfile)) + { + // This would be such a great place for the process to fail, eh? ;) + printf ("Failed!\n"); + exit (0); + } else + printf ("OK!\n"); + + // Finally! The SD card patching process has been completed! Tell the + // user the good news and instruct them to continue the installation + // process... + printf ("\nThe SD card has been patched successfully. The file\n"); + printf ("system on it should remain completely functional as\n"); + printf ("before, and you may now proceed to the next step of\n"); + printf ("the Action Replay SD card bootloader installation\n"); + printf ("process.\n\n"); + + // End of program. + return 0; +} diff --git a/src/.svn/text-base/StdAfx.cpp.svn-base b/src/.svn/text-base/StdAfx.cpp.svn-base new file mode 100755 index 0000000..fd9cd88 --- /dev/null +++ b/src/.svn/text-base/StdAfx.cpp.svn-base @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// writeSD.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/src/.svn/text-base/StdAfx.h.svn-base b/src/.svn/text-base/StdAfx.h.svn-base new file mode 100755 index 0000000..7c5696e --- /dev/null +++ b/src/.svn/text-base/StdAfx.h.svn-base @@ -0,0 +1,19 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__5D442ED7_8B5E_46D9_A725_BBE6D427B72A__INCLUDED_) +#define AFX_STDAFX_H__5D442ED7_8B5E_46D9_A725_BBE6D427B72A__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + + +// TODO: reference additional headers your program requires here + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__5D442ED7_8B5E_46D9_A725_BBE6D427B72A__INCLUDED_) diff --git a/src/CVS/.svn/all-wcprops b/src/CVS/.svn/all-wcprops new file mode 100755 index 0000000..d4886b6 --- /dev/null +++ b/src/CVS/.svn/all-wcprops @@ -0,0 +1,23 @@ +K 25 +svn:wc:ra_dav:version-url +V 44 +/svn/aklabs/!svn/ver/12/trunk/sdload/src/CVS +END +Repository +K 25 +svn:wc:ra_dav:version-url +V 55 +/svn/aklabs/!svn/ver/12/trunk/sdload/src/CVS/Repository +END +Root +K 25 +svn:wc:ra_dav:version-url +V 49 +/svn/aklabs/!svn/ver/12/trunk/sdload/src/CVS/Root +END +Entries +K 25 +svn:wc:ra_dav:version-url +V 52 +/svn/aklabs/!svn/ver/12/trunk/sdload/src/CVS/Entries +END diff --git a/src/CVS/.svn/entries b/src/CVS/.svn/entries new file mode 100755 index 0000000..a2831dc --- /dev/null +++ b/src/CVS/.svn/entries @@ -0,0 +1,130 @@ +10 + +dir +44 +https://127.0.0.1/svn/aklabs/trunk/sdload/src/CVS +https://127.0.0.1/svn/aklabs + + + +2007-05-26T23:54:26.388980Z +12 +andrew + + + + + + + + + + + + + + +eb184899-6090-47d4-a65b-558f62f6ea1c + +Repository +file + + + + +2010-02-05T03:38:37.432623Z +4f439e1598ee78856a826040d07dda7a +2007-05-26T23:54:26.388980Z +12 +andrew + + + + + + + + + + + + + + + + + + + + + +17 + +Root +file + + + + +2010-02-05T03:38:37.432623Z +7af14a164593104c1e7a07a572dd352a +2007-05-26T23:54:26.388980Z +12 +andrew + + + + + + + + + + + + + + + + + + + + + +24 + +Entries +file + + + + +2010-02-05T03:38:37.432623Z +ac052c0d3477c504a3bba1c44f5ca54d +2007-05-26T23:54:26.388980Z +12 +andrew + + + + + + + + + + + + + + + + + + + + + +142 + diff --git a/src/CVS/.svn/text-base/Entries.svn-base b/src/CVS/.svn/text-base/Entries.svn-base new file mode 100755 index 0000000..34237de --- /dev/null +++ b/src/CVS/.svn/text-base/Entries.svn-base @@ -0,0 +1,4 @@ +/SDpatch.cpp/1.1.1.1/Sun Jan 1 00:15:01 2006// +/StdAfx.cpp/1.1.1.1/Sun Jan 1 00:15:01 2006// +/StdAfx.h/1.1.1.1/Sun Jan 1 00:15:01 2006// +D diff --git a/src/CVS/.svn/text-base/Repository.svn-base b/src/CVS/.svn/text-base/Repository.svn-base new file mode 100755 index 0000000..8972706 --- /dev/null +++ b/src/CVS/.svn/text-base/Repository.svn-base @@ -0,0 +1 @@ +utils/sdload/src diff --git a/src/CVS/.svn/text-base/Root.svn-base b/src/CVS/.svn/text-base/Root.svn-base new file mode 100755 index 0000000..180ad4a --- /dev/null +++ b/src/CVS/.svn/text-base/Root.svn-base @@ -0,0 +1 @@ +andrew@gabbo:/home/cvsd diff --git a/src/CVS/Entries b/src/CVS/Entries new file mode 100755 index 0000000..34237de --- /dev/null +++ b/src/CVS/Entries @@ -0,0 +1,4 @@ +/SDpatch.cpp/1.1.1.1/Sun Jan 1 00:15:01 2006// +/StdAfx.cpp/1.1.1.1/Sun Jan 1 00:15:01 2006// +/StdAfx.h/1.1.1.1/Sun Jan 1 00:15:01 2006// +D diff --git a/src/CVS/Repository b/src/CVS/Repository new file mode 100755 index 0000000..8972706 --- /dev/null +++ b/src/CVS/Repository @@ -0,0 +1 @@ +utils/sdload/src diff --git a/src/CVS/Root b/src/CVS/Root new file mode 100755 index 0000000..180ad4a --- /dev/null +++ b/src/CVS/Root @@ -0,0 +1 @@ +andrew@gabbo:/home/cvsd diff --git a/src/SDpatch.cpp b/src/SDpatch.cpp new file mode 100755 index 0000000..4321f9b --- /dev/null +++ b/src/SDpatch.cpp @@ -0,0 +1,267 @@ +// SDpatch.cpp : Defines the entry point for the console application. +// by Costis. Copyright 2005. +// +// This is the source code for the SDpatch.exe program described in +// the install.txt documentation. Feel free to port it to any OS of +// your choice and send it to me for release! +// + + +#include "stdafx.h" + + +#include +#include +#include + +const char *OS_version = "Windows 2000\\NT\\XP"; + +// Usage. +void usage (void) +{ + printf ("Usage: SDpatch.exe drive_letter\n\n"); + printf ("\tdrive_letter\tSD card drive letter mapped by Windows.\n\n"); + printf ("WARNING: If you choose the wrong drive letter, such as\n"); + printf ("\t one mapped to a hard drive, there is a large\n"); + printf ("\t possibility that the drive contents will become\n"); + printf ("\t corrupted!!! CHOOSE THE DRIVE LETTER CAREFULLY!\n"); + exit (0); +} + +// This is the level 2 boot-code for file systems without MBR's. +const int sd_lev2_vbr_size = 352; +const unsigned char sd_lev2_vbr[352] = {0x90, 0x63, 0x68, 0x00, 0x7D, 0x3B, 0x4B, 0x78, 0x3A, 0x20, 0x02, 0x02, 0x3D, 0x20, 0x80, 0x10, + 0x3B, 0x40, 0xFF, 0xD6, 0x7F, 0x5B, 0xD6, 0x2C, 0x3B, 0x20, 0xFF, 0xCE, 0x7F, 0x3B, 0xCE, 0x2C, + 0x8A, 0xFB, 0xFF, 0xD0, 0x7F, 0x5A, 0xB9, 0xD6, 0x57, 0x56, 0x48, 0x2C, 0x7E, 0xE9, 0xB2, 0x14, + 0x7D, 0x36, 0x4B, 0x78, 0x7F, 0x19, 0xD2, 0x14, 0x8B, 0x9B, 0xFF, 0xD1, 0x8B, 0x5B, 0xFF, 0xD2, + 0x53, 0x5C, 0x44, 0x2E, 0x3B, 0x9C, 0x00, 0x0F, 0x57, 0x9C, 0xE1, 0x3E, 0x7F, 0x18, 0xE2, 0x14, + 0x57, 0x27, 0x48, 0x1E, 0x53, 0x27, 0x4C, 0x2C, 0x48, 0x00, 0x00, 0x95, 0x39, 0x29, 0x02, 0x00, + 0x3B, 0x39, 0x00, 0x01, 0x7C, 0x19, 0xC0, 0x00, 0x40, 0x82, 0xFF, 0xE8, 0x83, 0x17, 0x00, 0x00, + 0x3F, 0x18, 0xAC, 0xBC, 0x37, 0x18, 0xB3, 0xB1, 0x40, 0x82, 0x00, 0x14, 0x83, 0x17, 0x00, 0x04, + 0x3F, 0x18, 0xBE, 0xBC, 0x37, 0x18, 0xBA, 0xAE, 0x41, 0x82, 0x00, 0x0C, 0x3A, 0xF7, 0x00, 0x20, + 0x4B, 0xFF, 0xFF, 0xDC, 0x3B, 0x00, 0x00, 0x1A, 0x7F, 0x17, 0xC6, 0x2C, 0x8B, 0x5B, 0xFF, 0xCD, + 0x3D, 0x20, 0x81, 0x70, 0x3A, 0xF8, 0xFF, 0xFE, 0x7E, 0xF7, 0xD1, 0xD6, 0x7E, 0xF7, 0xCA, 0x14, + 0x7E, 0xB7, 0xD2, 0x14, 0x56, 0xE7, 0x48, 0x1E, 0x52, 0xE7, 0x4C, 0x2C, 0x48, 0x00, 0x00, 0x31, + 0x39, 0x29, 0x02, 0x00, 0x3A, 0xF7, 0x00, 0x01, 0x7C, 0x17, 0xA8, 0x00, 0x40, 0x82, 0xFF, 0xE8, + 0x57, 0x18, 0x08, 0x3C, 0x7F, 0x16, 0xC6, 0x2C, 0x28, 0x18, 0xFF, 0xF7, 0x41, 0x80, 0xFF, 0xC8, + 0x3D, 0x20, 0x81, 0x70, 0x7D, 0x28, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x21, 0x7D, 0x48, 0x02, 0xA6, + 0x7E, 0x29, 0x03, 0xA6, 0x90, 0xA3, 0x68, 0x00, 0x4B, 0x00, 0x18, 0x7D, 0x3F, 0xA0, 0x51, 0x00, + 0x4B, 0x00, 0x18, 0x75, 0x3B, 0x80, 0x00, 0x00, 0x7C, 0xFD, 0xE0, 0x30, 0x4B, 0x00, 0x18, 0x69, + 0x3B, 0x9C, 0x00, 0x08, 0x2C, 0x1C, 0x00, 0x20, 0x40, 0x82, 0xFF, 0xF0, 0x3F, 0xA0, 0x95, 0x00, + 0x4B, 0x00, 0x18, 0x55, 0x3F, 0xA0, 0xFF, 0x00, 0x4B, 0x00, 0x18, 0x4D, 0x4B, 0x00, 0x18, 0x49, + 0x3C, 0x9F, 0x02, 0x00, 0x74, 0x84, 0xFF, 0x00, 0x40, 0x82, 0xFF, 0xF4, 0x4B, 0x00, 0x18, 0x39, + 0x57, 0xFF, 0x46, 0x3E, 0x7F, 0xE9, 0x21, 0xAE, 0x7C, 0x09, 0x20, 0xAC, 0x38, 0x84, 0x00, 0x01, + 0x42, 0x00, 0xFF, 0xEC, 0x90, 0x63, 0x68, 0x00, 0x7D, 0x48, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20}; + +// This is the level 2 boot-code for MBR based file systems. +const int sd_lev2_mbr_size = 380; +const unsigned char sd_lev2_mbr[380] = {0x90, 0x63, 0x68, 0x00, 0x3A, 0x20, 0x02, 0x02, 0x3B, 0x00, 0x01, 0x86, 0x7F, 0x09, 0xC4, 0x2C, + 0x57, 0x07, 0x48, 0x1E, 0x53, 0x07, 0x4C, 0x2C, 0x3D, 0x20, 0x81, 0x01, 0x48, 0x00, 0x00, 0xED, + 0x3B, 0x69, 0x00, 0x40, 0x3D, 0x20, 0x80, 0x10, 0x3B, 0x40, 0xFF, 0xD6, 0x7F, 0x5B, 0xD6, 0x2C, + 0x3B, 0x20, 0xFF, 0xCE, 0x7F, 0x3B, 0xCE, 0x2C, 0x7F, 0x39, 0xC2, 0x14, 0x8A, 0xFB, 0xFF, 0xD0, + 0x7F, 0x5A, 0xB9, 0xD6, 0x57, 0x56, 0x48, 0x2C, 0x7E, 0xE9, 0xB2, 0x14, 0x7D, 0x36, 0x4B, 0x78, + 0x7F, 0x19, 0xD2, 0x14, 0x8B, 0x9B, 0xFF, 0xD1, 0x8B, 0x5B, 0xFF, 0xD2, 0x53, 0x5C, 0x44, 0x2E, + 0x3B, 0x9C, 0x00, 0x0F, 0x57, 0x9C, 0xE1, 0x3E, 0x7F, 0x18, 0xE2, 0x14, 0x57, 0x27, 0x48, 0x1E, + 0x53, 0x27, 0x4C, 0x2C, 0x48, 0x00, 0x00, 0x95, 0x39, 0x29, 0x02, 0x00, 0x3B, 0x39, 0x00, 0x01, + 0x7C, 0x19, 0xC0, 0x00, 0x40, 0x82, 0xFF, 0xE8, 0x83, 0x17, 0x00, 0x00, 0x3F, 0x18, 0xAC, 0xBC, + 0x37, 0x18, 0xB3, 0xB1, 0x40, 0x82, 0x00, 0x14, 0x83, 0x17, 0x00, 0x04, 0x3F, 0x18, 0xBE, 0xBC, + 0x37, 0x18, 0xBA, 0xAE, 0x41, 0x82, 0x00, 0x0C, 0x3A, 0xF7, 0x00, 0x20, 0x4B, 0xFF, 0xFF, 0xDC, + 0x3B, 0x00, 0x00, 0x1A, 0x7F, 0x17, 0xC6, 0x2C, 0x8B, 0x5B, 0xFF, 0xCD, 0x3D, 0x20, 0x81, 0x70, + 0x3A, 0xF8, 0xFF, 0xFE, 0x7E, 0xF7, 0xD1, 0xD6, 0x7E, 0xF7, 0xCA, 0x14, 0x7E, 0xB7, 0xD2, 0x14, + 0x56, 0xE7, 0x48, 0x1E, 0x52, 0xE7, 0x4C, 0x2C, 0x48, 0x00, 0x00, 0x31, 0x39, 0x29, 0x02, 0x00, + 0x3A, 0xF7, 0x00, 0x01, 0x7C, 0x17, 0xA8, 0x00, 0x40, 0x82, 0xFF, 0xE8, 0x57, 0x18, 0x08, 0x3C, + 0x7F, 0x16, 0xC6, 0x2C, 0x28, 0x18, 0xFF, 0xF7, 0x41, 0x80, 0xFF, 0xC8, 0x3D, 0x20, 0x81, 0x70, + 0x7D, 0x28, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x21, 0x7D, 0x48, 0x02, 0xA6, 0x7E, 0x29, 0x03, 0xA6, + 0x90, 0xA3, 0x68, 0x00, 0x4B, 0x00, 0x18, 0x61, 0x3F, 0xA0, 0x51, 0x00, 0x4B, 0x00, 0x18, 0x59, + 0x3B, 0x80, 0x00, 0x00, 0x7C, 0xFD, 0xE0, 0x30, 0x4B, 0x00, 0x18, 0x4D, 0x3B, 0x9C, 0x00, 0x08, + 0x2C, 0x1C, 0x00, 0x20, 0x40, 0x82, 0xFF, 0xF0, 0x3F, 0xA0, 0x95, 0x00, 0x4B, 0x00, 0x18, 0x39, + 0x3F, 0xA0, 0xFF, 0x00, 0x4B, 0x00, 0x18, 0x31, 0x4B, 0x00, 0x18, 0x2D, 0x3C, 0x9F, 0x02, 0x00, + 0x74, 0x84, 0xFF, 0x00, 0x40, 0x82, 0xFF, 0xF4, 0x4B, 0x00, 0x18, 0x1D, 0x57, 0xFF, 0x46, 0x3E, + 0x7F, 0xE9, 0x21, 0xAE, 0x7C, 0x09, 0x20, 0xAC, 0x38, 0x84, 0x00, 0x01, 0x42, 0x00, 0xFF, 0xEC, + 0x90, 0x63, 0x68, 0x00, 0x7D, 0x48, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20}; + +int main(int argc, char* argv[]) +{ + int i, ptype; + HANDLE mfile; + DWORD ret; + unsigned char mbuf[512], vbuf[512]; + char tname[512]; + char buffer[MAX_PATH]; + const unsigned char *sd_lev2; + unsigned long sd_lev2_size; + + printf ("SDLoad Card Patcher V1.00 by Costis\n"); + printf ("(%s Version)\n", OS_version); + + // Check the operating system version... + if (GetVersion() & 0x80000000) + { + // Oops! The user has tried to run this under an incompatible OS! + printf ("This program can only be run from Windows 2000\\NT\\XP.\n"); + exit (0); + } + + // Check if the user has passed a valid parameter... + if (argc != 2) + usage (); + + if ((((argv[1][0] < 'A') || (argv[1][0] > 'Z')) && ((argv[1][0] < 'a') || (argv[1][0] > 'z'))) || + (strlen(argv[1]) > 3)) + { + // The drive letter must be from A through Z and + // drive letters must be specified as X, X:, or even X:/ + printf ("Invalid drive letter specification.\n"); + exit (0); + } + + // Fix the drive letter so that QueryDosDevice accepts it. + argv[1][1] = ':'; + argv[1][2] = 0; + + // Check to make sure the drive is removable... + // We don't want a user accidentally corrupting their + // hard drive's MBR! + if (GetDriveType(argv[1]) != DRIVE_REMOVABLE) + { + // Oh, oh! A drive which is not removable has been selected... + printf ("The drive selected is not a removable device.\n"); + printf ("Please specify the drive letter of the SD card adapter!\n"); + exit (0); + } + + printf ("\nQuerying device name of drive %s...", argv[1]); + + ret = QueryDosDevice(argv[1], buffer, sizeof(buffer)); + if (!ret) + { + // The user has selected an invalid driver letter... + printf ("Failed. Invalid drive letter!\n"); + exit (0); + } else + printf ("OK!\n"); + + // Success! We have retrieved a low-level device name for the specified + // drive letter. We want to access partition 0, so remove the last part + // from it which is not needed... + for (i = strlen (buffer) - 1; i >= 0; i--) + { + if (buffer[i] == '\\') + { + buffer[i] = 0; + break; + } + } + // And append a Partition0 indicator to the end of it... + sprintf (tname, "\\\\.\\GLOBALROOT\\%s\\Partition0", buffer); + printf ("Device name: %s\n", tname); + + // Create a low-level Windows file to access the drive as a raw device. + printf ("Obtaining low-level access to drive..."); + mfile = CreateFile (tname, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); + if (mfile == INVALID_HANDLE_VALUE) + { + // Error! + printf ("Failed. Could not create file!\n"); + exit (0); + } else + printf ("OK!\n"); + + printf ("Reading first sector..."); + SetFilePointer (mfile, 0, NULL, FILE_BEGIN); + ReadFile (mfile, &mbuf, 512, &ret, NULL); + if (ret != 512) + { + // Error! Maybe the user has forgotten to insert an SD card?!?! + printf ("Failed! Make sure a working SD card is inserted!\n"); + CloseHandle (mfile); + exit (0); + } else + printf ("OK!\n"); + + // Success! We have managed to read out the first sector of the drive. + // Check byte index 0x15 (drive media type descriptor) and byte index + // 0x26 (extended signature) to find out whether this sector is a + // master boot record or a volume boot record... + if ((mbuf[0x26] == 0x29) && (mbuf[0x15] == 0xF8)) + { + // This is a volume boot record, NOT a master boot record... + printf ("Volume Boot Record found in Sector 0.\n"); + // We therefore want to patch in the VBR level 2 code: + ptype = 1; + sd_lev2 = sd_lev2_vbr; + sd_lev2_size = sd_lev2_vbr_size; + } else { + // This is a master boot record... + printf ("Master Boot Record found in Sector 0.\n"); + // We therefore want to patch in the MBR level 2 code: + ptype = 0; + sd_lev2 = sd_lev2_mbr; + sd_lev2_size = sd_lev2_mbr_size; + } + + printf ("Inserting level 2 boot-code in %cBR...", (ptype ? 'V' : 'M')); + + // Patch in the code in the right offset... + memcpy (mbuf + 0x40, sd_lev2, sd_lev2_size); + + // Attempt to write the new sector 0 back to the card. + SetFilePointer (mfile, 0, NULL, FILE_BEGIN); + WriteFile (mfile, mbuf, 512, &ret, NULL); + + if (ret != 512) + { + // Write failure! Maybe the user has write protected their card?!?! + printf ("Write Error! Check the write protect switch on the SD card.\n"); + CloseHandle (mfile); + exit (0); + } else + printf ("OK!\n"); + + // Apparently our write succeeded! Let's check to make sure... + printf ("Verifying Master Boot Record..."); + + // Read sector 0 again. + SetFilePointer (mfile, 0, NULL, FILE_BEGIN); + ReadFile (mfile, &vbuf, 512, &ret, NULL); + if (ret != 512) + { + printf ("Read Error!\n"); + CloseHandle (mfile); + exit (0); + } + + // Compare the new read back sector 0, with the one that was suppsoed to + // have been written. + if (memcmp (mbuf, vbuf, 512) != 0) + { + // Oops! They are not the same... + printf ("Verification Failed!\n"); + CloseHandle (mfile); + exit (0); + } else + printf ("OK!\n"); + + // Success! We can now release the file handle back to Windows... + printf ("Releasing low-level access handle..."); + + if (!CloseHandle (mfile)) + { + // This would be such a great place for the process to fail, eh? ;) + printf ("Failed!\n"); + exit (0); + } else + printf ("OK!\n"); + + // Finally! The SD card patching process has been completed! Tell the + // user the good news and instruct them to continue the installation + // process... + printf ("\nThe SD card has been patched successfully. The file\n"); + printf ("system on it should remain completely functional as\n"); + printf ("before, and you may now proceed to the next step of\n"); + printf ("the Action Replay SD card bootloader installation\n"); + printf ("process.\n\n"); + + // End of program. + return 0; +} diff --git a/src/StdAfx.cpp b/src/StdAfx.cpp new file mode 100755 index 0000000..fd9cd88 --- /dev/null +++ b/src/StdAfx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// writeSD.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/src/StdAfx.h b/src/StdAfx.h new file mode 100755 index 0000000..7c5696e --- /dev/null +++ b/src/StdAfx.h @@ -0,0 +1,19 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__5D442ED7_8B5E_46D9_A725_BBE6D427B72A__INCLUDED_) +#define AFX_STDAFX_H__5D442ED7_8B5E_46D9_A725_BBE6D427B72A__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + + +// TODO: reference additional headers your program requires here + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__5D442ED7_8B5E_46D9_A725_BBE6D427B72A__INCLUDED_) diff --git a/testdemo.dol b/testdemo.dol new file mode 100755 index 0000000..575b85e Binary files /dev/null and b/testdemo.dol differ