Bumped to version 0.2-RC1 from V.
This commit is contained in:
30
Makefile
30
Makefile
@@ -1,4 +1,24 @@
|
||||
BINARY := FreeCell.exe
|
||||
BINARY := freecell
|
||||
EXEFLAGS :=
|
||||
ARCH := linux
|
||||
CRCLIB := crcutil.a -Icrcutil-1.0/code -Icrcutil-1.0/examples
|
||||
CRC := crcutil-1.0 crcutil.a
|
||||
STRIPARG := -s
|
||||
|
||||
ifeq ($(OS), Windows_NT)
|
||||
BINARY := FreeCell.exe
|
||||
EXEFLAGS := -static
|
||||
ARCH := windows
|
||||
else
|
||||
ifeq ($(shell uname -s), Darwin)
|
||||
EXEFLAGS := -framework IOKit -framework CoreFoundation
|
||||
ARCH := macosx
|
||||
CRCLIB := crc32.c
|
||||
CRC := crc32.c crc32.h
|
||||
STRIPARG :=
|
||||
endif
|
||||
endif
|
||||
|
||||
DISTNAME := $(shell pwd | awk -F '/' '{print $$(NF - 1)}')
|
||||
ZIPNAME := $(shell pwd | awk -F '/' '{print $$(NF - 1)}' | tr "A-Z" "a-z").zip
|
||||
|
||||
@@ -8,7 +28,7 @@ all:
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(BINARY) crcutil.a *.o
|
||||
rm -rf freecell FreeCell.exe crcutil.a *.o
|
||||
|
||||
.PHONY: dist
|
||||
dist:
|
||||
@@ -21,9 +41,9 @@ dist:
|
||||
(cd ../.. ; zip -r $(ZIPNAME) $(DISTNAME))
|
||||
mv ../../$(ZIPNAME) ../$(ZIPNAME)
|
||||
|
||||
$(BINARY): main.cc md5.c md5.h sha1.c sha1.h crcutil-1.0 crcutil.a
|
||||
g++ -O3 -Wall -Werror -o $@ -static main.cc md5.c sha1.c crcutil.a -Icrcutil-1.0/code -Icrcutil-1.0/examples
|
||||
strip -s $@
|
||||
$(BINARY): main.cc $(ARCH).c $(ARCH).h md5.c md5.h sha1.c sha1.h $(CRC)
|
||||
g++ -O3 -Wall -Werror -o $@ $(EXEFLAGS) main.cc $(ARCH).c md5.c sha1.c $(CRCLIB)
|
||||
strip $(STRIPARG) $@
|
||||
|
||||
crcutil.a: crcutil-1.0
|
||||
rm -rf *.o
|
||||
|
||||
13
README.md
Normal file
13
README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
Usage: FreeCell <DRIVE> [-n|-o OUTPUTFILE] [SECTORFILE]
|
||||
|
||||
Dumps an XGD from a compatible drive, padding sectors in SECTORFILE.
|
||||
The resulting OUTPUTFILE will include all video layers data.
|
||||
Outputs the crc, md5 and sha1 of the resulting dump.
|
||||
|
||||
-n don't save to OUTPUTFILE, only calculate and show hashes
|
||||
can not be used together with -o
|
||||
-o OUTPUTFILE use OUTPUTFILE as file to extract to
|
||||
if no -o option is given, it will default to "Track 01.iso"
|
||||
can not be used together with -n
|
||||
|
||||
13
README.txt
Normal file
13
README.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
Usage: FreeCell <DRIVE> [-n|-o OUTPUTFILE] [SECTORFILE]
|
||||
|
||||
Dumps an XGD from a compatible drive, padding sectors in SECTORFILE.
|
||||
The resulting OUTPUTFILE will include all video layers data.
|
||||
Outputs the crc, md5 and sha1 of the resulting dump.
|
||||
|
||||
-n don't save to OUTPUTFILE, only calculate and show hashes
|
||||
can not be used together with -o
|
||||
-o OUTPUTFILE use OUTPUTFILE as file to extract to
|
||||
if no -o option is given, it will default to "Track 01.iso"
|
||||
can not be used together with -n
|
||||
|
||||
54
crc32.c
Normal file
54
crc32.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/* this file is in the public domain */
|
||||
|
||||
#include "crc32.h"
|
||||
|
||||
const unsigned int crc32_table[256] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
||||
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
|
||||
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
|
||||
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
|
||||
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
|
||||
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
|
||||
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
|
||||
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
|
||||
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
|
||||
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
|
||||
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
|
||||
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
|
||||
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
|
||||
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
|
||||
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
|
||||
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
|
||||
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
void CRC32_Init(CRC32_CTX *context) {
|
||||
context->crc = 0xffffffff;
|
||||
}
|
||||
|
||||
void CRC32_Update(CRC32_CTX *context, const void *data, unsigned long len) {
|
||||
while(len > 0) {
|
||||
context->crc = crc32_table[*(unsigned char *)data ^ ((context->crc) & 0xff)] ^ (context->crc >> 8);
|
||||
data = (unsigned char *)data + 1;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
void CRC32_Final(unsigned int *crc, CRC32_CTX *context) {
|
||||
*crc = context->crc ^ 0xffffffff;
|
||||
}
|
||||
14
crc32.h
Normal file
14
crc32.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/* this file is in the public domain */
|
||||
|
||||
#ifndef _CRC32_H
|
||||
#define _CRC32_H
|
||||
|
||||
typedef struct {
|
||||
unsigned int crc;
|
||||
} CRC32_CTX;
|
||||
|
||||
void CRC32_Init(CRC32_CTX *context);
|
||||
void CRC32_Update(CRC32_CTX *context, const void *data, unsigned long len);
|
||||
void CRC32_Final(unsigned int *crc, CRC32_CTX *context);
|
||||
|
||||
#endif /* _CRC32_H */
|
||||
202
crcutil-1.0/LICENSE
Normal file
202
crcutil-1.0/LICENSE
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
91
linux.c
Normal file
91
linux.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <fcntl.h>
|
||||
#include <scsi/sg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "linux.h"
|
||||
|
||||
char *drive;
|
||||
int drivefd;
|
||||
|
||||
int getdrive(char *arg) {
|
||||
int drivenumber;
|
||||
char *endptr;
|
||||
|
||||
if (strlen(arg) < 7 || strlen(arg) > 10) return 1;
|
||||
if (strncmp("/dev/sr", arg, 6) != 0) return 1;
|
||||
if (arg[7] < '0' || arg[7] > '9') return 1;
|
||||
if (arg[7] == '0' && arg[8] != 0) return 1;
|
||||
drivenumber = strtoul(&arg[7], &endptr, 10);
|
||||
if (endptr[0] != 0) return 1;
|
||||
if (drivenumber > 255) return 1;
|
||||
|
||||
drive = arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int opendrive() {
|
||||
if ((drivefd = open(drive, O_RDONLY | O_NONBLOCK)) < 0) {
|
||||
fprintf(stderr, EXECUTABLE "Could not open drive %s.\n", drive);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void closedrive() {
|
||||
close(drivefd);
|
||||
}
|
||||
|
||||
unsigned long long millisecondstime() {
|
||||
struct timeval currenttime;
|
||||
time_t unixtime = time(NULL);
|
||||
gettimeofday(¤ttime, NULL);
|
||||
return ((unixtime * 1000) + (currenttime.tv_usec / 1000));
|
||||
}
|
||||
|
||||
int sendcdb(const unsigned char *cdb, unsigned char cdblength, unsigned char *buffer, size_t size, int in, unsigned int *sense) {
|
||||
struct sg_io_hdr io_hdr;
|
||||
unsigned char sensebuffer[32];
|
||||
|
||||
memset(&io_hdr, 0, sizeof(io_hdr));
|
||||
memset(&sensebuffer, 0, 32);
|
||||
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.cmdp = (unsigned char *)cdb;
|
||||
io_hdr.cmd_len = cdblength;
|
||||
io_hdr.dxferp = buffer;
|
||||
io_hdr.dxfer_len = size;
|
||||
io_hdr.dxfer_direction = (in ? SG_DXFER_FROM_DEV : SG_DXFER_TO_DEV);
|
||||
io_hdr.sbp = sensebuffer;
|
||||
io_hdr.mx_sb_len = sizeof(sensebuffer);
|
||||
io_hdr.timeout = 20000;
|
||||
|
||||
if (ioctl(drivefd, SG_IO, &io_hdr) < 0) {
|
||||
*sense = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*sense = ((sensebuffer[2] & 0x0f) << 16) + (sensebuffer[12] << 8) + sensebuffer[13];
|
||||
return 0;
|
||||
}
|
||||
32
linux.h
Normal file
32
linux.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FREECELL_LINUX_H
|
||||
#define FREECELL_LINUX_H
|
||||
|
||||
#define PROGRAMNAME "freecell"
|
||||
#define EXECUTABLE "freecell"
|
||||
#define DRIVEUSAGE "</dev/sr?>"
|
||||
|
||||
#define O_BINARY 0
|
||||
#define SIZE_T_FORMAT "%lu"
|
||||
|
||||
int getdrive(char *);
|
||||
int opendrive();
|
||||
void closedrive();
|
||||
unsigned long long millisecondstime();
|
||||
int sendcdb(const unsigned char *, unsigned char, unsigned char *, size_t, int, unsigned int *);
|
||||
|
||||
#endif
|
||||
196
macosx.c
Normal file
196
macosx.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <CoreFoundation/CFString.h>
|
||||
#include <IOKit/scsi/SCSITaskLib.h>
|
||||
#include <IOKit/IOBSD.h>
|
||||
#include <IOKit/IOCFPlugIn.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
|
||||
#include "macosx.h"
|
||||
|
||||
int drive;
|
||||
IOCFPlugInInterface **PlugIn;
|
||||
MMCDeviceInterface **MMCDevice;
|
||||
SCSITaskDeviceInterface **SCSITaskDevice;
|
||||
SCSITaskInterface **SCSITask;
|
||||
|
||||
int getdrive(char *arg) {
|
||||
if (strlen(arg) < 13 || strlen(arg) > 15) return 1;
|
||||
if (strncmp("IODVDServices", arg, 13) != 0) return 1;
|
||||
if (strlen(arg) == 13) {
|
||||
drive = 0;
|
||||
return 0;
|
||||
}
|
||||
if (arg[13] != '/') return 1;
|
||||
if (arg[14] < '0' || arg[14] > '9') return 1;
|
||||
|
||||
drive = arg[14] - '0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
int opendrive() {
|
||||
int i;
|
||||
SInt32 score;
|
||||
IOReturn result;
|
||||
io_iterator_t iterator;
|
||||
CFMutableDictionaryRef dict;
|
||||
io_object_t device;
|
||||
CFStringRef devicepathUTF8;
|
||||
char devicepath[256];
|
||||
char *unmountcommand;
|
||||
|
||||
if ((dict = IOServiceMatching("IODVDServices")) == NULL) {
|
||||
printf("IOServiceMatching\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
result = IOServiceGetMatchingServices(kIOMasterPortDefault, dict, &iterator);
|
||||
|
||||
if ((result != kIOReturnSuccess) || (iterator == (io_iterator_t)0)) {
|
||||
printf("IOServiceGetMatchingServices\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; (device = IOIteratorNext(iterator)) != (io_iterator_t)0; i++) {
|
||||
if (drive == i) break;
|
||||
}
|
||||
|
||||
IOObjectRelease(iterator);
|
||||
|
||||
if (device == (io_object_t)0) {
|
||||
printf("IOIteratorNext\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((devicepathUTF8 = (CFStringRef)IORegistryEntrySearchCFProperty(device, kIOServicePlane, CFSTR(kIOBSDNameKey), kCFAllocatorDefault, kIORegistryIterateRecursively)) == NULL) {
|
||||
printf("IORegistryEntrySearchCFProperty\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (CFStringGetCString(devicepathUTF8, devicepath, 256, kCFStringEncodingUTF8) == FALSE) {
|
||||
printf("CFStringGetCString\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((unmountcommand = (char *)malloc(strlen("/usr/sbin/diskutil unmountDisk > /dev/null") + strlen(devicepath) + 1)) == NULL) {
|
||||
printf("malloc\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sprintf(unmountcommand, "/usr/sbin/diskutil unmountDisk %s > /dev/null", devicepath);
|
||||
CFRelease(devicepathUTF8);
|
||||
|
||||
if (system(unmountcommand) != 0) {
|
||||
free(unmountcommand);
|
||||
printf("system\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
free(unmountcommand);
|
||||
|
||||
score = 0;
|
||||
if ((result = IOCreatePlugInInterfaceForService(device, kIOMMCDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &PlugIn, &score)) != kIOReturnSuccess) {
|
||||
printf("IOCreatePlugInInterfaceForService\n");
|
||||
if ((result = IOCreatePlugInInterfaceForService(device, kIOSCSITaskDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &PlugIn, &score)) != kIOReturnSuccess) {
|
||||
printf("IOCreatePlugInInterfaceForService\n");
|
||||
return 1;
|
||||
}
|
||||
if ((*PlugIn)->QueryInterface(PlugIn, CFUUIDGetUUIDBytes(kIOSCSITaskDeviceInterfaceID), (void **)&MMCDevice) != KERN_SUCCESS) {
|
||||
printf("QueryInterface\n");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if ((*PlugIn)->QueryInterface(PlugIn, CFUUIDGetUUIDBytes(kIOMMCDeviceInterfaceID), (void **)&MMCDevice) != KERN_SUCCESS) {
|
||||
printf("QueryInterface\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((SCSITaskDevice = (*MMCDevice)->GetSCSITaskDeviceInterface(MMCDevice)) == NULL) {
|
||||
printf("GetSCSITaskDeviceInterface\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((*SCSITaskDevice)->ObtainExclusiveAccess(SCSITaskDevice) != kIOReturnSuccess) {
|
||||
printf("ObtainExclusiveAccess\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((SCSITask = (*SCSITaskDevice)->CreateSCSITask(SCSITaskDevice)) == NULL) {
|
||||
printf("CreateSCSITask\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
(*SCSITask)->SetTimeoutDuration(SCSITask, 10 * 1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void closedrive() {
|
||||
(*SCSITask)->Release(SCSITask);
|
||||
(*SCSITaskDevice)->ReleaseExclusiveAccess(SCSITaskDevice);
|
||||
(*SCSITaskDevice)->Release(SCSITaskDevice);
|
||||
(*MMCDevice)->Release(MMCDevice);
|
||||
IODestroyPlugInInterface(PlugIn);
|
||||
}
|
||||
|
||||
unsigned long long millisecondstime() {
|
||||
struct timeval currenttime;
|
||||
time_t unixtime = time(NULL);
|
||||
gettimeofday(¤ttime, NULL);
|
||||
return ((unixtime * 1000) + (currenttime.tv_usec / 1000));
|
||||
}
|
||||
|
||||
int sendcdb(const unsigned char *cdb, unsigned char cdblength, unsigned char *buffer, size_t size, int in, unsigned int *sense) {
|
||||
IOVirtualRange range;
|
||||
SCSI_Sense_Data sensedata;
|
||||
SCSITaskStatus status;
|
||||
|
||||
if ((*SCSITask)->SetCommandDescriptorBlock(SCSITask, (unsigned char *)cdb, cdblength) != kIOReturnSuccess) {
|
||||
printf("SetCommandDescriptorBlock\n");
|
||||
*sense = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
range.address = (IOVirtualAddress)buffer;
|
||||
range.length = size;
|
||||
|
||||
if ((*SCSITask)->SetScatterGatherEntries(SCSITask, &range, 1, size, (in ? kSCSIDataTransfer_FromInitiatorToTarget : kSCSIDataTransfer_FromTargetToInitiator)) != kIOReturnSuccess) {
|
||||
printf("SetScatterGatherEntries\n");
|
||||
*sense = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&sensedata, 0, sizeof(SCSI_Sense_Data));
|
||||
|
||||
if ((*SCSITask)->ExecuteTaskSync(SCSITask, &sensedata, &status, NULL) != kIOReturnSuccess) {
|
||||
printf("ExecuteTaskSync\n");
|
||||
*sense = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*sense = ((((unsigned char *)&sensedata)[2] & 0x0f) << 16) + (((unsigned char *)&sensedata)[12] << 8) + ((unsigned char *)&sensedata)[13];
|
||||
return 0;
|
||||
}
|
||||
32
macosx.h
Normal file
32
macosx.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FREECELL_LINUX_H
|
||||
#define FREECELL_LINUX_H
|
||||
|
||||
#define PROGRAMNAME "freecell"
|
||||
#define EXECUTABLE "freecell"
|
||||
#define DRIVEUSAGE "IODVDServices[/?]"
|
||||
|
||||
#define O_BINARY 0
|
||||
#define SIZE_T_FORMAT "%lu"
|
||||
|
||||
int getdrive(char *);
|
||||
int opendrive();
|
||||
void closedrive();
|
||||
unsigned long long millisecondstime();
|
||||
int sendcdb(const unsigned char *, unsigned char, unsigned char *, size_t, int, unsigned int *);
|
||||
|
||||
#endif
|
||||
203
main.cc
203
main.cc
@@ -31,17 +31,26 @@
|
||||
|
||||
// Usage: FreeCell <DRIVE> [-n|-o OUTPUTFILE] [SECTORFILE]
|
||||
|
||||
#include <stddef.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <tchar.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <windows.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "windows.h"
|
||||
#elif defined(__APPLE__)
|
||||
#include "macosx.h"
|
||||
#include "crc32.h"
|
||||
#else
|
||||
#include "linux.h"
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
#include "interface.h"
|
||||
#endif
|
||||
#include "md5.h"
|
||||
#include "sha1.h"
|
||||
|
||||
@@ -66,33 +75,6 @@
|
||||
#define MODE_XTREME 1
|
||||
#define MODE_WXRIPPER 2
|
||||
|
||||
#define SCSI_IOCTL_DATA_OUT 0
|
||||
#define SCSI_IOCTL_DATA_IN 1
|
||||
#define IOCTL_SCSI_PASS_THROUGH_DIRECT 0x0004D014
|
||||
#define SENSE_BUFFER_LENGTH 32
|
||||
|
||||
typedef struct _SCSI_PASS_THROUGH_DIRECT {
|
||||
USHORT Length;
|
||||
UCHAR ScsiStatus;
|
||||
UCHAR PathId;
|
||||
UCHAR TargetId;
|
||||
UCHAR Lun;
|
||||
UCHAR CdbLength;
|
||||
UCHAR SenseInfoLength;
|
||||
UCHAR DataIn;
|
||||
ULONG DataTransferLength;
|
||||
ULONG TimeOutValue;
|
||||
PVOID DataBuffer;
|
||||
ULONG SenseInfoOffset;
|
||||
UCHAR Cdb[16];
|
||||
} SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
|
||||
|
||||
typedef struct _SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER {
|
||||
SCSI_PASS_THROUGH_DIRECT sptd;
|
||||
ULONG Filler;
|
||||
UCHAR ucSenseBuf[SENSE_BUFFER_LENGTH];
|
||||
} SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
|
||||
|
||||
typedef struct {
|
||||
unsigned int start;
|
||||
unsigned int end;
|
||||
@@ -103,36 +85,35 @@ typedef struct {
|
||||
size_t l1;
|
||||
} layersize_t;
|
||||
|
||||
char drive;
|
||||
HANDLE drivehandle;
|
||||
|
||||
const char *outputfile;
|
||||
int fd;
|
||||
|
||||
sectorrange_t *securitysectors;
|
||||
int sectorranges;
|
||||
|
||||
#ifndef __APPLE__
|
||||
crcutil_interface::CRC *crcutil;
|
||||
unsigned long long crc;
|
||||
#else
|
||||
CRC32_CTX crc32context;
|
||||
unsigned int crc;
|
||||
#endif
|
||||
|
||||
MD5_CTX md5context;
|
||||
SHA1_CTX sha1context;
|
||||
|
||||
int readsectorfile(const char *);
|
||||
HANDLE opendrivehandle();
|
||||
int digesttostr(char *, const unsigned char *, size_t);
|
||||
void usage();
|
||||
int freecell();
|
||||
void printprogress(unsigned int, unsigned int);
|
||||
unsigned int getnextgap(unsigned int);
|
||||
unsigned int getgapsize(unsigned int);
|
||||
UINT64 millisecondstime();
|
||||
int setlockingmode(unsigned char);
|
||||
int getlayersizes(layersize_t *);
|
||||
int setstreaming();
|
||||
int readblock(unsigned char *, unsigned int, size_t);
|
||||
int processblock(const unsigned char *, size_t);
|
||||
int sendcdb(const unsigned char *, unsigned char, unsigned char *, size_t, int, unsigned int *);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int option, nooutput, ret;
|
||||
@@ -144,22 +125,21 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
fd = 0;
|
||||
nooutput = 0;
|
||||
drive = 0;
|
||||
outputfile = NULL;
|
||||
sectorfile = NULL;
|
||||
|
||||
|
||||
while ((option = getopt(argc, argv, "no:h?")) != -1) {
|
||||
switch (option) {
|
||||
case 'n':
|
||||
if (outputfile) {
|
||||
fprintf(stderr, "FreeCell.exe: -n option can not be used together with -o\n");
|
||||
fprintf(stderr, EXECUTABLE ": -n option can not be used together with -o\n");
|
||||
return 1;
|
||||
}
|
||||
nooutput = 1;
|
||||
break;
|
||||
case 'o':
|
||||
if (nooutput) {
|
||||
fprintf(stderr, "FreeCell.exe: -p option can not be used together with -n\n");
|
||||
fprintf(stderr, EXECUTABLE ": -p option can not be used together with -n\n");
|
||||
return 1;
|
||||
}
|
||||
outputfile = optarg;
|
||||
@@ -177,17 +157,8 @@ int main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
do {
|
||||
if (strlen(argv[optind]) > 2) break;
|
||||
if (strlen(argv[optind]) == 2 && argv[optind][1] != ':') break;
|
||||
if (argv[optind][0] < 'A' || argv[optind][0] > 'z') break;
|
||||
if (argv[optind][0] > 'Z' && argv[optind][0] < 'a') break;
|
||||
drive = argv[optind][0];
|
||||
if (drive > 'Z') drive -= ('a' - 'A');
|
||||
} while (0);
|
||||
|
||||
if (!drive) {
|
||||
fprintf(stderr, "FreeCell.exe: %s does not look like a valid drive\n", argv[optind]);
|
||||
if (getdrive(argv[optind])) {
|
||||
fprintf(stderr, EXECUTABLE ": %s does not look like a valid drive\n", argv[optind]);
|
||||
return 1;
|
||||
}
|
||||
optind++;
|
||||
@@ -201,27 +172,33 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (readsectorfile(sectorfile)) return 1;
|
||||
|
||||
if ((drivehandle = opendrivehandle()) == INVALID_HANDLE_VALUE) {
|
||||
fprintf(stderr, "Could not open drive %c:.\n", drive);
|
||||
if (opendrive()) {
|
||||
if (securitysectors != NULL) free(securitysectors);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((outputfile != NULL) && ((fd = open(outputfile, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR)) == -1)) {
|
||||
perror(outputfile);
|
||||
CloseHandle(drivehandle);
|
||||
closedrive();
|
||||
if (securitysectors != NULL) free(securitysectors);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
crcutil = crcutil_interface::CRC::Create(POLY, 0, 32, true, 0, 0, 0, 0, NULL);
|
||||
crc = 0;
|
||||
#else
|
||||
CRC32_Init(&crc32context);
|
||||
#endif
|
||||
MD5_Init(&md5context);
|
||||
SHA1_Init(&sha1context);
|
||||
|
||||
ret = freecell();
|
||||
|
||||
if (!ret) {
|
||||
#ifdef __APPLE__
|
||||
CRC32_Final(&crc, &crc32context);
|
||||
#endif
|
||||
MD5_Final(md5digest, &md5context);
|
||||
SHA1_Final(sha1digest, &sha1context);
|
||||
|
||||
@@ -233,9 +210,11 @@ int main(int argc, char *argv[]) {
|
||||
printf("SHA1: %s\n", sha1hash);
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
crcutil->Delete();
|
||||
#endif
|
||||
if (fd) close(fd);
|
||||
CloseHandle(drivehandle);
|
||||
closedrive();
|
||||
if (securitysectors != NULL) free(securitysectors);
|
||||
|
||||
return ret;
|
||||
@@ -303,7 +282,7 @@ int readsectorfile(const char *sectorfile) {
|
||||
state = STATE_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (state == STATE_SECONDVALUE) {
|
||||
if (byte == ' ') continue;
|
||||
if (byte >= '1' && byte <= '9') {
|
||||
@@ -363,24 +342,6 @@ int readsectorfile(const char *sectorfile) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HANDLE opendrivehandle() {
|
||||
LPTSTR drivepath;
|
||||
|
||||
if((drivepath = (LPTSTR)calloc(sizeof("\\\\.\\.:"), sizeof(TCHAR))) == NULL) {
|
||||
fprintf(stderr, "Drivepath calloc failed. Out of memory?\n");
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
_stprintf(drivepath, _T("\\\\.\\%c:"), drive);
|
||||
return CreateFile(drivepath,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
int digesttostr(char *hash, const unsigned char *digest, size_t length) {
|
||||
unsigned int i;
|
||||
|
||||
@@ -397,7 +358,7 @@ int digesttostr(char *hash, const unsigned char *digest, size_t length) {
|
||||
|
||||
void usage() {
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "Usage: FreeCell <DRIVE> [-n|-o OUTPUTFILE] [SECTORFILE]\n");
|
||||
fprintf(stderr, "Usage: " PROGRAMNAME " " DRIVEUSAGE " [-n|-o OUTPUTFILE] [SECTORFILE]\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "Dumps an XGD from a compatible drive, padding sectors in SECTORFILE.\n");
|
||||
fprintf(stderr, "The resulting OUTPUTFILE will include all video layers data.\n");
|
||||
@@ -412,9 +373,9 @@ void usage() {
|
||||
}
|
||||
|
||||
int freecell() {
|
||||
size_t l0_video, l1_video, middlezone, gamedata;
|
||||
size_t l0_video, l1_video, middlezone, gamedata, totalsize;
|
||||
layersize_t layers;
|
||||
unsigned int totalsize, offset, sectorsdone, nextgap, gapsize;
|
||||
unsigned int offset, sectorsdone, nextgap, gapsize;
|
||||
unsigned char buffer[BUFFERSIZE];
|
||||
|
||||
if (setlockingmode(MODE_LOCKED)) return 1;
|
||||
@@ -437,13 +398,13 @@ int freecell() {
|
||||
totalsize = l0_video + l1_video + (2 * middlezone) + gamedata;
|
||||
|
||||
printf("\n");
|
||||
printf("L0 Video Size: %d\n", l0_video);
|
||||
printf("L1 Video Size: %d\n", l1_video);
|
||||
printf("Middle Zone Size: %d\n", middlezone);
|
||||
printf("Game Data Size: %d\n", gamedata);
|
||||
printf("Total Size: %d\n", totalsize);
|
||||
printf("L0 Video Size: " SIZE_T_FORMAT "\n", l0_video);
|
||||
printf("L1 Video Size: " SIZE_T_FORMAT "\n", l1_video);
|
||||
printf("Middle Zone Size: " SIZE_T_FORMAT "\n", middlezone);
|
||||
printf("Game Data Size: " SIZE_T_FORMAT "\n", gamedata);
|
||||
printf("Total Size: " SIZE_T_FORMAT "\n", totalsize);
|
||||
printf("\n");
|
||||
printf("Real Layer Break: %d\n", l0_video + middlezone + (gamedata / 2));
|
||||
printf("Real Layer Break: " SIZE_T_FORMAT "\n", l0_video + middlezone + (gamedata / 2));
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
|
||||
@@ -469,12 +430,27 @@ int freecell() {
|
||||
}
|
||||
|
||||
// Middle Zone A
|
||||
memset(buffer, 0, BUFFERSIZE);
|
||||
while ((offset + SECTORS) < (l0_video + middlezone)) {
|
||||
if (processblock(buffer, BUFFERSIZE)) return 1;
|
||||
sectorsdone += SECTORS;
|
||||
offset += SECTORS;
|
||||
printprogress(totalsize, sectorsdone);
|
||||
}
|
||||
if (offset < (l0_video + middlezone)) {
|
||||
if (processblock(buffer, ((l0_video + middlezone) - offset) * SECTORSIZE)) return 1;
|
||||
sectorsdone += (l0_video + middlezone) - offset;
|
||||
offset += (l0_video + middlezone) - offset;
|
||||
printprogress(totalsize, sectorsdone);
|
||||
}
|
||||
|
||||
/*
|
||||
while ((offset + SECTORS) < (l0_video + middlezone)) {
|
||||
if (readblock(buffer, offset, BUFFERSIZE)) return 1;
|
||||
if ((buffer[0] != 0) || memcmp(buffer, buffer + 1, BUFFERSIZE - 1)) {
|
||||
fprintf(stderr, "Error: Data found in Middle Zone A! Report this as soon as possible please!\n");
|
||||
return 1;
|
||||
}
|
||||
// if ((buffer[0] != 0) || memcmp(buffer, buffer + 1, BUFFERSIZE - 1)) {
|
||||
// fprintf(stderr, "Error: Data found in Middle Zone A! Report this as soon as possible please!\n");
|
||||
// return 1;
|
||||
// }
|
||||
if (processblock(buffer, BUFFERSIZE)) return 1;
|
||||
sectorsdone += SECTORS;
|
||||
offset += SECTORS;
|
||||
@@ -491,6 +467,7 @@ int freecell() {
|
||||
offset += (l0_video + middlezone) - offset;
|
||||
printprogress(totalsize, sectorsdone);
|
||||
}
|
||||
*/
|
||||
|
||||
// Game Data
|
||||
while (offset < (l0_video + middlezone + gamedata)) {
|
||||
@@ -609,9 +586,9 @@ unsigned int getgapsize(unsigned int gap) {
|
||||
}
|
||||
|
||||
void printprogress(unsigned int totalsize, unsigned int sectorsdone) {
|
||||
static UINT64 starttime = millisecondstime();
|
||||
static UINT64 lastupdate = starttime;
|
||||
UINT64 currenttime = millisecondstime();
|
||||
static unsigned long long starttime = millisecondstime();
|
||||
static unsigned long long lastupdate = starttime;
|
||||
unsigned long long currenttime = millisecondstime();
|
||||
static unsigned int rate = 0;
|
||||
static unsigned int ratedivisor = 0;
|
||||
|
||||
@@ -629,13 +606,6 @@ void printprogress(unsigned int totalsize, unsigned int sectorsdone) {
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
UINT64 millisecondstime() {
|
||||
SYSTEMTIME currenttime;
|
||||
time_t unixtime = time(NULL);
|
||||
GetSystemTime(¤ttime);
|
||||
return ((unixtime * 1000) + currenttime.wMilliseconds);
|
||||
}
|
||||
|
||||
int setlockingmode(unsigned char mode) {
|
||||
unsigned char cdb[5] = {0xff, 0x08, 0x01, 0x11};
|
||||
unsigned char buffer[SECTORSIZE];
|
||||
@@ -767,7 +737,11 @@ int readblock(unsigned char *buffer, unsigned int offset, size_t size) {
|
||||
}
|
||||
|
||||
int processblock(const unsigned char *buffer, size_t size) {
|
||||
#ifndef __APPLE__
|
||||
crcutil->Compute(buffer, size, &crc);
|
||||
#else
|
||||
CRC32_Update(&crc32context, buffer, size);
|
||||
#endif
|
||||
MD5_Update(&md5context, buffer, size);
|
||||
SHA1_Update(&sha1context, buffer, size);
|
||||
|
||||
@@ -778,38 +752,3 @@ int processblock(const unsigned char *buffer, size_t size) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sendcdb(const unsigned char *cdb, unsigned char cdblength, unsigned char *buffer, size_t size, int in, unsigned int *sense) {
|
||||
SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER sptdwb;
|
||||
long unsigned int returned;
|
||||
|
||||
memset(&sptdwb, 0, sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER));
|
||||
memset(buffer, 0, size);
|
||||
|
||||
sptdwb.sptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
|
||||
sptdwb.sptd.CdbLength = cdblength;
|
||||
sptdwb.sptd.SenseInfoLength = sizeof(sptdwb.ucSenseBuf);
|
||||
sptdwb.sptd.DataIn = (in ? SCSI_IOCTL_DATA_IN : SCSI_IOCTL_DATA_OUT);
|
||||
sptdwb.sptd.DataTransferLength = size;
|
||||
sptdwb.sptd.TimeOutValue = 20;
|
||||
sptdwb.sptd.DataBuffer = buffer;
|
||||
sptdwb.sptd.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
|
||||
|
||||
memcpy(sptdwb.sptd.Cdb, cdb, cdblength);
|
||||
|
||||
if (!DeviceIoControl(drivehandle,
|
||||
IOCTL_SCSI_PASS_THROUGH_DIRECT,
|
||||
&sptdwb,
|
||||
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
|
||||
&sptdwb,
|
||||
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
|
||||
&returned,
|
||||
NULL
|
||||
)) {
|
||||
*sense = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*sense = ((sptdwb.ucSenseBuf[2] & 0x0f) << 16) + (sptdwb.ucSenseBuf[12] << 8) + sptdwb.ucSenseBuf[13];
|
||||
return 0;
|
||||
}
|
||||
|
||||
135
windows.c
Normal file
135
windows.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <time.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#define SCSI_IOCTL_DATA_OUT 0
|
||||
#define SCSI_IOCTL_DATA_IN 1
|
||||
#define IOCTL_SCSI_PASS_THROUGH_DIRECT 0x0004D014
|
||||
#define SENSE_BUFFER_LENGTH 32
|
||||
|
||||
typedef struct _SCSI_PASS_THROUGH_DIRECT {
|
||||
unsigned short Length;
|
||||
unsigned char ScsiStatus;
|
||||
unsigned char PathId;
|
||||
unsigned char TargetId;
|
||||
unsigned char Lun;
|
||||
unsigned char CdbLength;
|
||||
unsigned char SenseInfoLength;
|
||||
unsigned char DataIn;
|
||||
unsigned long DataTransferLength;
|
||||
unsigned long TimeOutValue;
|
||||
void *DataBuffer;
|
||||
unsigned long SenseInfoOffset;
|
||||
unsigned char Cdb[16];
|
||||
} SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
|
||||
|
||||
typedef struct _SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER {
|
||||
SCSI_PASS_THROUGH_DIRECT sptd;
|
||||
unsigned long Filler;
|
||||
unsigned char ucSenseBuf[SENSE_BUFFER_LENGTH];
|
||||
} SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
|
||||
|
||||
char drive;
|
||||
HANDLE drivehandle;
|
||||
|
||||
int getdrive(char *arg) {
|
||||
if (strlen(arg) > 2) return 1;
|
||||
if (strlen(arg) == 2 && arg[1] != ':') return 1;
|
||||
if (arg[0] < 'A' || arg[0] > 'z') return 1;
|
||||
if (arg[0] > 'Z' && arg[0] < 'a') return 1;
|
||||
|
||||
drive = arg[0];
|
||||
if (drive > 'Z') drive -= ('a' - 'A');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int opendrive() {
|
||||
LPTSTR drivepath;
|
||||
|
||||
if((drivepath = (LPTSTR)calloc(sizeof("\\\\.\\.:"), sizeof(TCHAR))) == NULL) {
|
||||
fprintf(stderr, "Drivepath calloc failed. Out of memory?\n");
|
||||
return 1;
|
||||
}
|
||||
_stprintf(drivepath, _T("\\\\.\\%c:"), drive);
|
||||
drivehandle = CreateFile(drivepath,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (drivehandle == INVALID_HANDLE_VALUE) {
|
||||
fprintf(stderr, EXECUTABLE "Could not open drive %c:.\n", drive);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void closedrive() {
|
||||
CloseHandle(drivehandle);
|
||||
}
|
||||
|
||||
unsigned long long millisecondstime() {
|
||||
SYSTEMTIME currenttime;
|
||||
time_t unixtime = time(NULL);
|
||||
GetSystemTime(¤ttime);
|
||||
return ((unixtime * 1000) + currenttime.wMilliseconds);
|
||||
}
|
||||
|
||||
int sendcdb(const unsigned char *cdb, unsigned char cdblength, unsigned char *buffer, size_t size, int in, unsigned int *sense) {
|
||||
SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER sptdwb;
|
||||
long unsigned int returned;
|
||||
|
||||
memset(&sptdwb, 0, sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER));
|
||||
memset(buffer, 0, size);
|
||||
|
||||
sptdwb.sptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
|
||||
sptdwb.sptd.CdbLength = cdblength;
|
||||
sptdwb.sptd.SenseInfoLength = sizeof(sptdwb.ucSenseBuf);
|
||||
sptdwb.sptd.DataIn = (in ? SCSI_IOCTL_DATA_IN : SCSI_IOCTL_DATA_OUT);
|
||||
sptdwb.sptd.DataTransferLength = size;
|
||||
sptdwb.sptd.TimeOutValue = 20;
|
||||
sptdwb.sptd.DataBuffer = buffer;
|
||||
sptdwb.sptd.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
|
||||
|
||||
memcpy(sptdwb.sptd.Cdb, cdb, cdblength);
|
||||
|
||||
if (!DeviceIoControl(drivehandle,
|
||||
IOCTL_SCSI_PASS_THROUGH_DIRECT,
|
||||
&sptdwb,
|
||||
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
|
||||
&sptdwb,
|
||||
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
|
||||
&returned,
|
||||
NULL
|
||||
)) {
|
||||
*sense = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*sense = ((sptdwb.ucSenseBuf[2] & 0x0f) << 16) + (sptdwb.ucSenseBuf[12] << 8) + sptdwb.ucSenseBuf[13];
|
||||
return 0;
|
||||
}
|
||||
31
windows.h
Normal file
31
windows.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FREECELL_WINDOWS_H
|
||||
#define FREECELL_WINDOWS_H
|
||||
|
||||
#define PROGRAMNAME "FreeCell"
|
||||
#define EXECUTABLE "FreeCell.exe"
|
||||
#define DRIVEUSAGE "<DRIVE>"
|
||||
|
||||
#define SIZE_T_FORMAT "%u"
|
||||
|
||||
int getdrive(char *);
|
||||
int opendrive();
|
||||
void closedrive();
|
||||
unsigned long long millisecondstime();
|
||||
int sendcdb(const unsigned char *cdb, unsigned char cdblength, unsigned char *buffer, size_t size, int in, unsigned int *sense);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user