1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[misc] move source files to src/ directory

This commit is contained in:
Pete Batard 2011-12-05 10:49:45 +00:00
parent 4edb492c19
commit 48f9dd47ae
53 changed files with 249 additions and 260 deletions

22
src/Makefile.am Normal file
View file

@ -0,0 +1,22 @@
INCLUDES = -I$(top_srcdir)
noinst_PROGRAMS = rufus
pkg_v_rc = $(pkg_v_rc_$(V))
pkg_v_rc_ = $(pkg_v_rc_$(AM_DEFAULT_VERBOSITY))
pkg_v_rc_0 = @echo " RC $@";
rufus_rc.o: rufus.rc
$(pkg_v_rc)$(WINDRES) -i $< -o $@
rufus_SOURCES = fat12.c fat16.c fat32.c br.c file.c drive.c msdos.c format.c stdio.c stdlg.c rufus.c
rufus_CFLAGS = -I./inc $(ARCH_CFLAGS) $(AM_CFLAGS)
# static ensures that the exe can be shared as a standalone, and still allow driver installation
rufus_LDFLAGS = $(AM_LDFLAGS) -mwindows -static
rufus_LDADD = rufus_rc.o -lsetupapi -lole32 -lgdi32
# This step produces the UPX compressed and signed release that is made available for public download
release: rufus.exe
@$(STRIP) rufus.exe
@upx rufus.exe
@cmd.exe /k _sign.bat rufus.exe

490
src/Makefile.in Normal file
View file

@ -0,0 +1,490 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
noinst_PROGRAMS = rufus$(EXEEXT)
subdir = src
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
PROGRAMS = $(noinst_PROGRAMS)
am_rufus_OBJECTS = rufus-fat12.$(OBJEXT) rufus-fat16.$(OBJEXT) \
rufus-fat32.$(OBJEXT) rufus-br.$(OBJEXT) rufus-file.$(OBJEXT) \
rufus-drive.$(OBJEXT) rufus-msdos.$(OBJEXT) \
rufus-format.$(OBJEXT) rufus-stdio.$(OBJEXT) \
rufus-stdlg.$(OBJEXT) rufus-rufus.$(OBJEXT)
rufus_OBJECTS = $(am_rufus_OBJECTS)
rufus_DEPENDENCIES = rufus_rc.o
rufus_LINK = $(CCLD) $(rufus_CFLAGS) $(CFLAGS) $(rufus_LDFLAGS) \
$(LDFLAGS) -o $@
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp =
am__depfiles_maybe =
AM_V_lt = $(am__v_lt_$(V))
am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
am__v_lt_0 = --silent
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_$(V))
am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
am__v_CC_0 = @echo " CC " $@;
AM_V_at = $(am__v_at_$(V))
am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
am__v_at_0 = @
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_$(V))
am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
am__v_CCLD_0 = @echo " CCLD " $@;
AM_V_GEN = $(am__v_GEN_$(V))
am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
am__v_GEN_0 = @echo " GEN " $@;
SOURCES = $(rufus_SOURCES)
ETAGS = etags
CTAGS = ctags
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_CFLAGS = @AM_CFLAGS@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AM_LDFLAGS = @AM_LDFLAGS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EXEEXT = @EXEEXT@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RM = @RM@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
VISIBILITY_CFLAGS = @VISIBILITY_CFLAGS@
WINDRES = @WINDRES@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
am__leading_dot = @am__leading_dot@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build_alias = @build_alias@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
INCLUDES = -I$(top_srcdir)
pkg_v_rc = $(pkg_v_rc_$(V))
pkg_v_rc_ = $(pkg_v_rc_$(AM_DEFAULT_VERBOSITY))
pkg_v_rc_0 = @echo " RC $@";
rufus_SOURCES = fat12.c fat16.c fat32.c br.c file.c drive.c msdos.c format.c stdio.c stdlg.c rufus.c
rufus_CFLAGS = -I./inc $(ARCH_CFLAGS) $(AM_CFLAGS)
# static ensures that the exe can be shared as a standalone, and still allow driver installation
rufus_LDFLAGS = $(AM_LDFLAGS) -mwindows -static
rufus_LDADD = rufus_rc.o -lsetupapi -lole32 -lgdi32
all: all-am
.SUFFIXES:
.SUFFIXES: .c .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign --ignore-deps src/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign --ignore-deps src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
clean-noinstPROGRAMS:
-test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
rufus$(EXEEXT): $(rufus_OBJECTS) $(rufus_DEPENDENCIES)
@rm -f rufus$(EXEEXT)
$(AM_V_CCLD)$(rufus_LINK) $(rufus_OBJECTS) $(rufus_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
.c.o:
$(AM_V_CC) @AM_BACKSLASH@
$(COMPILE) -c $<
.c.obj:
$(AM_V_CC) @AM_BACKSLASH@
$(COMPILE) -c `$(CYGPATH_W) '$<'`
rufus-fat12.o: fat12.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-fat12.o `test -f 'fat12.c' || echo '$(srcdir)/'`fat12.c
rufus-fat12.obj: fat12.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-fat12.obj `if test -f 'fat12.c'; then $(CYGPATH_W) 'fat12.c'; else $(CYGPATH_W) '$(srcdir)/fat12.c'; fi`
rufus-fat16.o: fat16.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-fat16.o `test -f 'fat16.c' || echo '$(srcdir)/'`fat16.c
rufus-fat16.obj: fat16.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-fat16.obj `if test -f 'fat16.c'; then $(CYGPATH_W) 'fat16.c'; else $(CYGPATH_W) '$(srcdir)/fat16.c'; fi`
rufus-fat32.o: fat32.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-fat32.o `test -f 'fat32.c' || echo '$(srcdir)/'`fat32.c
rufus-fat32.obj: fat32.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-fat32.obj `if test -f 'fat32.c'; then $(CYGPATH_W) 'fat32.c'; else $(CYGPATH_W) '$(srcdir)/fat32.c'; fi`
rufus-br.o: br.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-br.o `test -f 'br.c' || echo '$(srcdir)/'`br.c
rufus-br.obj: br.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-br.obj `if test -f 'br.c'; then $(CYGPATH_W) 'br.c'; else $(CYGPATH_W) '$(srcdir)/br.c'; fi`
rufus-file.o: file.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-file.o `test -f 'file.c' || echo '$(srcdir)/'`file.c
rufus-file.obj: file.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-file.obj `if test -f 'file.c'; then $(CYGPATH_W) 'file.c'; else $(CYGPATH_W) '$(srcdir)/file.c'; fi`
rufus-drive.o: drive.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-drive.o `test -f 'drive.c' || echo '$(srcdir)/'`drive.c
rufus-drive.obj: drive.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-drive.obj `if test -f 'drive.c'; then $(CYGPATH_W) 'drive.c'; else $(CYGPATH_W) '$(srcdir)/drive.c'; fi`
rufus-msdos.o: msdos.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-msdos.o `test -f 'msdos.c' || echo '$(srcdir)/'`msdos.c
rufus-msdos.obj: msdos.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-msdos.obj `if test -f 'msdos.c'; then $(CYGPATH_W) 'msdos.c'; else $(CYGPATH_W) '$(srcdir)/msdos.c'; fi`
rufus-format.o: format.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-format.o `test -f 'format.c' || echo '$(srcdir)/'`format.c
rufus-format.obj: format.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-format.obj `if test -f 'format.c'; then $(CYGPATH_W) 'format.c'; else $(CYGPATH_W) '$(srcdir)/format.c'; fi`
rufus-stdio.o: stdio.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-stdio.o `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c
rufus-stdio.obj: stdio.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-stdio.obj `if test -f 'stdio.c'; then $(CYGPATH_W) 'stdio.c'; else $(CYGPATH_W) '$(srcdir)/stdio.c'; fi`
rufus-stdlg.o: stdlg.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-stdlg.o `test -f 'stdlg.c' || echo '$(srcdir)/'`stdlg.c
rufus-stdlg.obj: stdlg.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-stdlg.obj `if test -f 'stdlg.c'; then $(CYGPATH_W) 'stdlg.c'; else $(CYGPATH_W) '$(srcdir)/stdlg.c'; fi`
rufus-rufus.o: rufus.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-rufus.o `test -f 'rufus.c' || echo '$(srcdir)/'`rufus.c
rufus-rufus.obj: rufus.c
$(AM_V_CC) @AM_BACKSLASH@
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-rufus.obj `if test -f 'rufus.c'; then $(CYGPATH_W) 'rufus.c'; else $(CYGPATH_W) '$(srcdir)/rufus.c'; fi`
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
set x; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS)
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-noinstPROGRAMS mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am:
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-noinstPROGRAMS ctags distclean distclean-compile \
distclean-generic distclean-tags dvi dvi-am html html-am info \
info-am install install-am install-data install-data-am \
install-dvi install-dvi-am install-exec install-exec-am \
install-html install-html-am install-info install-info-am \
install-man install-pdf install-pdf-am install-ps \
install-ps-am install-strip installcheck installcheck-am \
installdirs maintainer-clean maintainer-clean-generic \
mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \
ps ps-am tags uninstall uninstall-am
rufus_rc.o: rufus.rc
$(pkg_v_rc)$(WINDRES) -i $< -o $@
# This step produces the UPX compressed and signed release that is made available for public download
release: rufus.exe
@$(STRIP) rufus.exe
@upx rufus.exe
@cmd.exe /k _sign.bat rufus.exe
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

191
src/br.c Normal file
View file

@ -0,0 +1,191 @@
/******************************************************************
Copyright (C) 2009 Henrik Carlqvist
This program 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 2 of the License, or
(at your option) any later version.
This program 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 program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
******************************************************************/
#include <stdio.h>
#include "file.h"
#include "br.h"
int is_br(FILE *fp)
{
/* A "file" is probably some kind of boot record if it contains the magic
chars 0x55, 0xAA at position 0x1FE */
unsigned char aucRef[] = {0x55, 0xAA};
return contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* is_br */
int is_lilo_br(FILE *fp)
{
/* A "file" is probably a LILO boot record if it contains the magic
chars LILO at position 0x6 or 0x2 for floppies */
unsigned char aucRef[] = {'L','I','L','O'};
return ( contains_data(fp, 0x6, aucRef, sizeof(aucRef)) ||
contains_data(fp, 0x2, aucRef, sizeof(aucRef)) );
} /* is_lilo_br */
int is_dos_mbr(FILE *fp)
{
#include "mbr_dos.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
contains_data(fp, 0x0, mbr_dos_0x0, sizeof(mbr_dos_0x0)) &&
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* is_dos_mbr */
int is_dos_f2_mbr(FILE *fp)
{
#include "mbr_dos_f2.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
contains_data(fp, 0x0, mbr_dos_f2_0x0, sizeof(mbr_dos_f2_0x0)) &&
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* is_dos_f2_mbr */
int is_95b_mbr(FILE *fp)
{
#include "mbr_95b.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
contains_data(fp, 0x0, mbr_95b_0x0, sizeof(mbr_95b_0x0)) &&
contains_data(fp, 0x0e0, mbr_95b_0x0e0, sizeof(mbr_95b_0x0e0)) &&
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* is_95b_mbr */
int is_2000_mbr(FILE *fp)
{
#include "mbr_2000.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
contains_data(fp, 0x0, mbr_2000_0x0, sizeof(mbr_2000_0x0)) &&
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* is_2000_mbr */
int is_vista_mbr(FILE *fp)
{
#include "mbr_vista.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
contains_data(fp, 0x0, mbr_vista_0x0, sizeof(mbr_vista_0x0)) &&
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* is_vista_mbr */
int is_win7_mbr(FILE *fp)
{
#include "mbr_win7.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
contains_data(fp, 0x0, mbr_win7_0x0, sizeof(mbr_win7_0x0)) &&
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* is_win7_mbr */
int is_syslinux_mbr(FILE *fp)
{
#include "mbr_syslinux.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
contains_data(fp, 0x0, mbr_syslinux_0x0, sizeof(mbr_syslinux_0x0)) &&
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* is_syslinux_mbr */
int is_zero_mbr(FILE *fp)
{
#include "mbr_zero.h"
return
contains_data(fp, 0x0, mbr_zero_0x0, sizeof(mbr_zero_0x0));
/* Don't bother to check 55AA signature */
} /* is_zero_mbr */
int write_dos_mbr(FILE *fp)
{
#include "mbr_dos.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
write_data(fp, 0x0, mbr_dos_0x0, sizeof(mbr_dos_0x0)) &&
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* write_dos_mbr */
int write_95b_mbr(FILE *fp)
{
#include "mbr_95b.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
write_data(fp, 0x0, mbr_95b_0x0, sizeof(mbr_95b_0x0)) &&
write_data(fp, 0x0e0, mbr_95b_0x0e0, sizeof(mbr_95b_0x0e0)) &&
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* write_95b_mbr */
int write_2000_mbr(FILE *fp)
{
#include "mbr_2000.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
write_data(fp, 0x0, mbr_2000_0x0, sizeof(mbr_2000_0x0)) &&
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* write_2000_mbr */
int write_vista_mbr(FILE *fp)
{
#include "mbr_vista.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
write_data(fp, 0x0, mbr_vista_0x0, sizeof(mbr_vista_0x0)) &&
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* write_vista_mbr */
int write_win7_mbr(FILE *fp)
{
#include "mbr_win7.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
write_data(fp, 0x0, mbr_win7_0x0, sizeof(mbr_win7_0x0)) &&
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* write_win7_mbr */
int write_syslinux_mbr(FILE *fp)
{
#include "mbr_syslinux.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
write_data(fp, 0x0, mbr_syslinux_0x0, sizeof(mbr_syslinux_0x0)) &&
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* write_syslinux_mbr */
int write_zero_mbr(FILE *fp)
{
#include "mbr_zero.h"
unsigned char aucRef[] = {0x55, 0xAA};
return
write_data(fp, 0x0, mbr_zero_0x0, sizeof(mbr_zero_0x0)) &&
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
} /* write_zero_mbr */

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="highestAvailable"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

157
src/drive.c Normal file
View file

@ -0,0 +1,157 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* Drive access function calls
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "msapi_utf8.h"
#include "rufus.h"
#include "resource.h"
/*
* Globals
*/
RUFUS_DRIVE_INFO SelectedDrive;
/*
* Open a drive or volume with optional write and lock access
* Returns INVALID_HANDLE_VALUE (/!\ which is DIFFERENT from NULL /!\) on failure.
* This call is quite risky (left unchecked, inadvertently passing 0 as index would
* return a handle to C:, which we might then proceed to unknowingly repartition!),
* so we apply the following mitigation factors:
* - Valid indexes must belong to a specific range [DRIVE_INDEX_MIN; DRIVE_INDEX_MAX]
* - When opening for write access, we lock the volume. If that fails, which would
* typically be the case on C:\ or any other drive in use, we report failure
* - We report the full path of any drive that was successfully opened for write acces
*/
HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BOOL bLockDrive)
{
BOOL r;
DWORD size;
HANDLE hDrive = INVALID_HANDLE_VALUE;
STORAGE_DEVICE_NUMBER_REDEF device_number = {0};
char drives[26*4]; /* "D:\", "E:\", etc. */
char *drive = drives;
char logical_drive[] = "\\\\.\\#:";
char physical_drive[24];
if ((DriveIndex < DRIVE_INDEX_MIN) || (DriveIndex > DRIVE_INDEX_MAX)) {
uprintf("WARNING: Bad index value. Please check the code!\n");
}
DriveIndex -= DRIVE_INDEX_MIN;
// If no drive letter is requested, open a phyical drive
if (DriveLetter == NULL) {
safe_sprintf(physical_drive, sizeof(physical_drive), "\\\\.\\PHYSICALDRIVE%d", DriveIndex);
hDrive = CreateFileA(physical_drive, GENERIC_READ|(bWriteAccess?GENERIC_WRITE:0),
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if (hDrive == INVALID_HANDLE_VALUE) {
uprintf("Could not open drive %s: %s\n", physical_drive, WindowsErrorString());
goto out;
}
if (bWriteAccess) {
uprintf("Caution: Opened %s drive for write access\n", physical_drive);
}
} else {
*DriveLetter = ' ';
size = GetLogicalDriveStringsA(sizeof(drives), drives);
if (size == 0) {
uprintf("GetLogicalDriveStrings failed: %s\n", WindowsErrorString());
goto out;
}
if (size > sizeof(drives)) {
uprintf("GetLogicalDriveStrings: buffer too small (required %d vs %d)\n", size, sizeof(drives));
goto out;
}
hDrive = INVALID_HANDLE_VALUE;
for ( ;*drive; drive += safe_strlen(drive)+1) {
if (!isalpha(*drive))
continue;
*drive = (char)toupper((int)*drive);
if (*drive < 'C') {
continue;
}
safe_sprintf(logical_drive, sizeof(logical_drive), "\\\\.\\%c:", drive[0]);
hDrive = CreateFileA(logical_drive, GENERIC_READ|(bWriteAccess?GENERIC_WRITE:0),
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if (hDrive == INVALID_HANDLE_VALUE) {
uprintf("Warning: could not open drive %c: %s\n", drive[0], WindowsErrorString());
continue;
}
r = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL,
0, &device_number, sizeof(device_number), &size, NULL);
if ((!r) || (size <= 0)) {
uprintf("IOCTL_STORAGE_GET_DEVICE_NUMBER failed for device %s: %s\n",
logical_drive, WindowsErrorString());
} else if (device_number.DeviceNumber == DriveIndex) {
break;
}
safe_closehandle(hDrive);
}
if (hDrive == INVALID_HANDLE_VALUE) {
goto out;
}
if (bWriteAccess) {
uprintf("Caution: Opened %s drive for write access\n", logical_drive);
}
*DriveLetter = *drive?*drive:' ';
}
if ((bLockDrive) && (!DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL))) {
uprintf("Could not get exclusive access to %s: %s\n", logical_drive, WindowsErrorString());
safe_closehandle(hDrive);
goto out;
}
out:
return hDrive;
}
/*
* Return the drive letter and volume label
*/
BOOL GetDriveLabel(DWORD DriveIndex, char* letter, char** label)
{
HANDLE hDrive;
char DrivePath[] = "#:\\";
static char volume_label[MAX_PATH+1];
*label = STR_NO_LABEL;
hDrive = GetDriveHandle(DriveIndex, DrivePath, FALSE, FALSE);
if (hDrive == INVALID_HANDLE_VALUE)
return FALSE;
safe_closehandle(hDrive);
*letter = DrivePath[0];
if (GetVolumeInformationA(DrivePath, volume_label, sizeof(volume_label),
NULL, NULL, NULL, NULL, 0) && *volume_label) {
*label = volume_label;
}
return TRUE;
}

59
src/fat12.c Normal file
View file

@ -0,0 +1,59 @@
/******************************************************************
Copyright (C) 2009 Henrik Carlqvist
This program 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 2 of the License, or
(at your option) any later version.
This program 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 program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
******************************************************************/
#include <stdio.h>
#include <string.h>
#include "file.h"
#include "fat12.h"
int is_fat_12_fs(FILE *fp)
{
char *szMagic = "FAT12 ";
return contains_data(fp, 0x36, szMagic, strlen(szMagic));
} /* is_fat_12_fs */
int entire_fat_12_br_matches(FILE *fp)
{
#include "br_fat12_0x0.h"
#include "br_fat12_0x3e.h"
return
( contains_data(fp, 0x0, br_fat12_0x0, sizeof(br_fat12_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x3e, br_fat12_0x3e, sizeof(br_fat12_0x3e)) );
} /* entire_fat_12_br_matches */
int write_fat_12_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat12_0x0.h"
#include "br_fat12_0x3e.h"
if(bKeepLabel)
return
( write_data(fp, 0x0, br_fat12_0x0, sizeof(br_fat12_0x0)) &&
/* BIOS Parameter Block might differ between systems */
write_data(fp, 0x3e, br_fat12_0x3e, sizeof(br_fat12_0x3e)) );
else
return
( write_data(fp, 0x0, br_fat12_0x0, sizeof(br_fat12_0x0)) &&
/* BIOS Parameter Block might differ between systems */
write_data(fp, 0x2b, label_11_char, sizeof(label_11_char)) &&
write_data(fp, 0x3e, br_fat12_0x3e, sizeof(br_fat12_0x3e)) );
} /* write_fat_12_br */

103
src/fat16.c Normal file
View file

@ -0,0 +1,103 @@
/******************************************************************
Copyright (C) 2009 Henrik Carlqvist
This program 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 2 of the License, or
(at your option) any later version.
This program 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 program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
******************************************************************/
#include <stdio.h>
#include <string.h>
#include "file.h"
#include "fat16.h"
int is_fat_16_fs(FILE *fp)
{
char *szMagic = "FAT16 ";
return contains_data(fp, 0x36, szMagic, strlen(szMagic));
} /* is_fat_16_fs */
int is_fat_16_br(FILE *fp)
{
/* A "file" is probably some kind of FAT16 boot record if it contains the
magic chars 0x55, 0xAA at positions 0x1FE */
unsigned char aucRef[] = {0x55, 0xAA};
unsigned char aucMagic[] = {'M','S','W','I','N','4','.','1'};
if( ! contains_data(fp, 0x1FE, aucRef, sizeof(aucRef)))
return 0;
if( ! contains_data(fp, 0x03, aucMagic, sizeof(aucMagic)))
return 0;
return 1;
} /* is_fat_16_br */
int entire_fat_16_br_matches(FILE *fp)
{
#include "br_fat16_0x0.h"
#include "br_fat16_0x3e.h"
return
( contains_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
} /* entire_fat_16_br_matches */
int write_fat_16_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat16_0x0.h"
#include "br_fat16_0x3e.h"
if(bKeepLabel)
return
( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
else
return
( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x2b, label_11_char, sizeof(label_11_char)) &&
write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
} /* write_fat_16_br */
int entire_fat_16_fd_br_matches(FILE *fp)
{
#include "br_fat16_0x0.h"
#include "br_fat16fd_0x3e.h"
return
( contains_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
} /* entire_fat_16_fd_br_matches */
int write_fat_16_fd_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat16_0x0.h"
#include "br_fat16fd_0x3e.h"
if(bKeepLabel)
return
( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
else
return
( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x2b, label_11_char, sizeof(label_11_char)) &&
write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
} /* write_fat_16_fd_br */

173
src/fat32.c Normal file
View file

@ -0,0 +1,173 @@
/******************************************************************
Copyright (C) 2009 Henrik Carlqvist
This program 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 2 of the License, or
(at your option) any later version.
This program 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 program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
******************************************************************/
#include <stdio.h>
#include <string.h>
#include "file.h"
#include "fat32.h"
int is_fat_32_fs(FILE *fp)
{
char *szMagic = "FAT32 ";
return contains_data(fp, 0x52, szMagic, strlen(szMagic));
} /* is_fat_32_fs */
int is_fat_32_br(FILE *fp)
{
/* A "file" is probably some kind of FAT32 boot record if it contains the
magic chars 0x55, 0xAA at positions 0x1FE, 0x3FE and 0x5FE */
unsigned char aucRef[] = {0x55, 0xAA};
unsigned char aucMagic[] = {'M','S','W','I','N','4','.','1'};
int i;
for(i=0 ; i<3 ; i++)
if( ! contains_data(fp, 0x1FE + i*0x200, aucRef, sizeof(aucRef)))
return 0;
if( ! contains_data(fp, 0x03, aucMagic, sizeof(aucMagic)))
return 0;
return 1;
} /* is_fat_32_br */
int entire_fat_32_br_matches(FILE *fp)
{
#include "br_fat32_0x0.h"
#include "br_fat32_0x52.h"
#include "br_fat32_0x3f0.h"
return
( contains_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
/* Cluster information might differ between systems */
contains_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
} /* entire_fat_32_br_matches */
int write_fat_32_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat32_0x0.h"
#include "br_fat32_0x52.h"
#include "br_fat32_0x3f0.h"
if(bKeepLabel)
return
( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
/* Cluster information is not overwritten, however, it would bo OK
to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
else
return
( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
/* Cluster information is not overwritten, however, it would bo OK
to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
} /* write_fat_32_br */
int entire_fat_32_fd_br_matches(FILE *fp)
{
#include "br_fat32_0x0.h"
#include "br_fat32fd_0x52.h"
#include "br_fat32fd_0x3f0.h"
return
( contains_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
/* Cluster information might differ between systems */
contains_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
} /* entire_fat_32_fd_br_matches */
int write_fat_32_fd_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat32_0x0.h"
#include "br_fat32fd_0x52.h"
#include "br_fat32fd_0x3f0.h"
if(bKeepLabel)
return
( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
/* Cluster information is not overwritten, however, it would bo OK
to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
else
return
( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
/* Cluster information is not overwritten, however, it would bo OK
to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
} /* write_fat_32_nt_br */
int entire_fat_32_nt_br_matches(FILE *fp)
{
#include "br_fat32nt_0x0.h"
#include "br_fat32nt_0x52.h"
#include "br_fat32nt_0x3f0.h"
#include "br_fat32nt_0x1800.h"
return
( contains_data(fp, 0x0, br_fat32nt_0x0, sizeof(br_fat32nt_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x52, br_fat32nt_0x52, sizeof(br_fat32nt_0x52)) &&
/* Cluster information might differ between systems */
contains_data(fp, 0x3f0, br_fat32nt_0x3f0, sizeof(br_fat32nt_0x3f0)) &&
contains_data(fp, 0x1800, br_fat32nt_0x1800, sizeof(br_fat32nt_0x1800))
);
} /* entire_fat_32_nt_br_matches */
int write_fat_32_nt_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat32nt_0x0.h"
#include "br_fat32nt_0x52.h"
#include "br_fat32nt_0x3f0.h"
#include "br_fat32nt_0x1800.h"
if(bKeepLabel)
return
( write_data(fp, 0x0, br_fat32nt_0x0, sizeof(br_fat32nt_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x52, br_fat32nt_0x52, sizeof(br_fat32nt_0x52)) &&
/* Cluster information is not overwritten, however, it would bo OK
to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
write_data(fp, 0x3f0, br_fat32nt_0x3f0, sizeof(br_fat32nt_0x3f0)) &&
write_data(fp, 0x1800, br_fat32nt_0x1800, sizeof(br_fat32nt_0x1800))
);
else
return
( write_data(fp, 0x0, br_fat32nt_0x0, sizeof(br_fat32nt_0x0)) &&
/* BIOS Parameter Block should not be overwritten */
write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
write_data(fp, 0x52, br_fat32nt_0x52, sizeof(br_fat32nt_0x52)) &&
/* Cluster information is not overwritten, however, it would bo OK
to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
write_data(fp, 0x3f0, br_fat32nt_0x3f0, sizeof(br_fat32nt_0x3f0)) &&
write_data(fp, 0x1800, br_fat32nt_0x1800, sizeof(br_fat32nt_0x1800))
);
} /* write_fat_32_nt_br */

144
src/file.c Normal file
View file

@ -0,0 +1,144 @@
/******************************************************************
Copyright (C) 2009 Henrik Carlqvist
Modified for Rufus/Windows (C) 2011 Pete Batard
This program 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 2 of the License, or
(at your option) any later version.
This program 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 program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
******************************************************************/
#include <stdio.h>
#include <string.h>
#include "rufus.h"
#include "file.h"
int write_sectors(HANDLE hDrive, size_t SectorSize,
size_t StartSector, size_t nSectors,
const void *pBuf, size_t BufSize)
{
LARGE_INTEGER ptr;
DWORD Size;
if(SectorSize * nSectors > BufSize)
{
uprintf("write_sectors: Buffer is too small\n");
return 0;
}
ptr.QuadPart = StartSector*SectorSize;
if(!SetFilePointerEx(hDrive, ptr, NULL, FILE_BEGIN))
{
uprintf("write_sectors: Could not access sector %d - %s\n", StartSector, WindowsErrorString());
return 0;
}
if((!WriteFile(hDrive, pBuf, (DWORD)BufSize, &Size, NULL)) || (Size != BufSize))
{
uprintf("write_sectors: Write error - %s\n", WindowsErrorString());
uprintf(" StartSector:%0X, nSectors:%0X, SectorSize:%0X\n", StartSector, nSectors, SectorSize);
return 0;
}
return 1;
}
int read_sectors(HANDLE hDrive, size_t SectorSize,
size_t StartSector, size_t nSectors,
void *pBuf, size_t BufSize)
{
LARGE_INTEGER ptr;
DWORD Size;
if(SectorSize * nSectors > BufSize)
{
uprintf("read_sectors: Buffer is too small\n");
return 0;
}
ptr.QuadPart = StartSector*SectorSize;
if(!SetFilePointerEx(hDrive, ptr, NULL, FILE_BEGIN))
{
uprintf("read_sectors: Could not access sector %d - %s\n", StartSector, WindowsErrorString());
return 0;
}
if((!ReadFile(hDrive, pBuf, (DWORD)BufSize, &Size, NULL)) || (Size != BufSize))
{
uprintf("read_sectors: Read error - %s\n", WindowsErrorString());
uprintf(" StartSector:%0X, nSectors:%0X, SectorSize:%0X\n", StartSector, nSectors, SectorSize);
return 0;
}
return 1;
}
/* Use a bastardized fp that contains a Windows handle and the sector size */
int contains_data(FILE *fp, size_t Position,
const void *pData, size_t Len)
{
unsigned char aucBuf[MAX_DATA_LEN];
HANDLE hDrive = (HANDLE)fp->_ptr;
size_t SectorSize = (size_t)fp->_bufsiz;
size_t StartSector, EndSector, NumSectors;
StartSector = Position/SectorSize;
EndSector = (Position+Len+SectorSize-1)/SectorSize;
NumSectors = EndSector - StartSector;
if((NumSectors*SectorSize) > MAX_DATA_LEN)
{
uprintf("Please increase MAX_DATA_LEN in file.h\n");
return 0;
}
if(!read_sectors(hDrive, SectorSize, StartSector,
NumSectors, aucBuf, sizeof(aucBuf)))
return 0;
if(memcmp(pData, &aucBuf[Position - StartSector*SectorSize], Len))
return 0;
return 1;
} /* contains_data */
/* May read/write the same sector many times, but compatible with existing ms-sys */
int write_data(FILE *fp, size_t Position,
const void *pData, size_t Len)
{
unsigned char aucBuf[MAX_DATA_LEN];
HANDLE hDrive = (HANDLE)fp->_ptr;
size_t SectorSize = (size_t)fp->_bufsiz;
size_t StartSector, EndSector, NumSectors;
StartSector = Position/SectorSize;
EndSector = (Position+Len+SectorSize-1)/SectorSize;
NumSectors = EndSector - StartSector;
if((NumSectors*SectorSize) > MAX_DATA_LEN)
{
uprintf("Please increase MAX_DATA_LEN in file.h\n");
return 0;
}
/* Data to write may not be aligned on a sector boundary => read into a sector buffer first */
if(!read_sectors(hDrive, SectorSize, StartSector,
NumSectors, aucBuf, sizeof(aucBuf)))
return 0;
if(!memcpy(&aucBuf[Position - StartSector*SectorSize], pData, Len))
return 0;
if(!write_sectors(hDrive, SectorSize, StartSector,
NumSectors, aucBuf, sizeof(aucBuf)))
return 0;
return 1;
} /* write_data */

388
src/format.c Normal file
View file

@ -0,0 +1,388 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* Formatting function calls
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
#include <stddef.h>
#include "msapi_utf8.h"
#include "rufus.h"
#include "resource.h"
#include "br.h"
#include "fat16.h"
#include "fat32.h"
#include "file.h"
#include "format.h"
/*
* Globals
*/
DWORD FormatStatus;
/*
* FormatEx callback. Return FALSE to halt operations
*/
static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, DWORD Action, PVOID pData)
{
DWORD* percent;
int task_number = 0;
if (IS_ERROR(FormatStatus))
return FALSE;
switch(Command) {
case FCC_PROGRESS:
percent = (DWORD*)pData;
PostMessage(hMainDialog, UM_FORMAT_PROGRESS, (WPARAM)*percent, (LPARAM)0);
uprintf("%d percent completed.\n", *percent);
break;
case FCC_STRUCTURE_PROGRESS: // No progress on quick format
uprintf("Format task %d/? completed.\n", ++task_number);
break;
case FCC_DONE:
if(*(BOOLEAN*)pData == FALSE) {
uprintf("Error while formatting.\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_GEN_FAILURE;
}
break;
case FCC_DONE_WITH_STRUCTURE: // We get this message when formatting Small FAT16
// pData Seems to be a struct with at least one (32 BIT!!!) string pointer to the size in MB
uprintf("Done with that sort of things: Action=%d pData=%0p\n", Action, pData);
DumpBufferHex(pData, 8);
uprintf("Volume size: %s MB\n", (char*)(LONG_PTR)(*(ULONG32*)pData));
break;
case FCC_INCOMPATIBLE_FILE_SYSTEM:
uprintf("Incompatible File System\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_INCOMPATIBLE_FS);
break;
case FCC_ACCESS_DENIED:
uprintf("Access denied\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_ACCESS_DENIED;
break;
case FCC_MEDIA_WRITE_PROTECTED:
uprintf("Media is write protected\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_PROTECT;
break;
case FCC_VOLUME_IN_USE:
uprintf("Volume is in use\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_DEVICE_IN_USE;
break;
case FCC_CANT_QUICK_FORMAT:
uprintf("Cannot quick format this volume\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_QUICK_FORMAT);
break;
case FCC_BAD_LABEL:
uprintf("Bad label\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_LABEL_TOO_LONG;
break;
case FCC_OUTPUT:
uprintf("%s\n", ((PTEXTOUTPUT)pData)->Output);
break;
case FCC_CLUSTER_SIZE_TOO_BIG:
case FCC_CLUSTER_SIZE_TOO_SMALL:
uprintf("Unsupported cluster size\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_INVALID_CLUSTER_SIZE);
break;
case FCC_VOLUME_TOO_BIG:
case FCC_VOLUME_TOO_SMALL:
uprintf("Volume is too %s\n", FCC_VOLUME_TOO_BIG?"big":"small");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_INVALID_VOLUME_SIZE);
case FCC_NO_MEDIA_IN_DRIVE:
uprintf("No media in drive\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NO_MEDIA_IN_DRIVE;
break;
default:
uprintf("FormatExCallback: received unhandled command %X\n", Command);
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_SUPPORTED;
break;
}
return (!IS_ERROR(FormatStatus));
}
/*
* Call on fmifs.dll's FormatEx() to format the drive
*/
static BOOL FormatDrive(char DriveLetter)
{
BOOL r = FALSE;
PF_DECL(FormatEx);
WCHAR wDriveRoot[] = L"?:\\";
WCHAR wFSType[32];
WCHAR wLabel[128];
size_t i;
wDriveRoot[0] = (WCHAR)DriveLetter;
PrintStatus("Formatting...");
PF_INIT_OR_OUT(FormatEx, fmifs);
GetWindowTextW(hFileSystem, wFSType, ARRAYSIZE(wFSType));
// We may have a " (Default)" trail
for (i=0; i<wcslen(wFSType); i++) {
if (wFSType[i] == ' ') {
wFSType[i] = 0;
break;
}
}
GetWindowTextW(hLabel, wLabel, ARRAYSIZE(wLabel));
uprintf("Using cluster size: %d bytes\n", ComboBox_GetItemData(hClusterSize, ComboBox_GetCurSel(hClusterSize)));
pfFormatEx(wDriveRoot, SelectedDrive.Geometry.MediaType, wFSType, wLabel,
IsChecked(IDC_QUICKFORMAT), (ULONG)ComboBox_GetItemData(hClusterSize, ComboBox_GetCurSel(hClusterSize)),
FormatExCallback);
if (!IS_ERROR(FormatStatus)) {
uprintf("Format completed.\n");
r = TRUE;
}
out:
return r;
}
static BOOL AnalyzeMBR(HANDLE hPhysicalDrive)
{
FILE fake_fd;
fake_fd._ptr = (char*)hPhysicalDrive;
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
// TODO: Apply this detection before partitioning
if (is_br(&fake_fd)) {
uprintf("Drive has an x86 boot sector\n");
} else{
uprintf("Drive is missing an x86 boot sector!\n");
return FALSE;
}
// TODO: Add/Eliminate FAT12?
if (is_fat_16_br(&fake_fd) || is_fat_32_br(&fake_fd)) {
if (entire_fat_16_br_matches(&fake_fd)) {
uprintf("Exact FAT16 DOS boot record match\n");
} else if (entire_fat_16_fd_br_matches(&fake_fd)) {
uprintf("Exact FAT16 FreeDOS boot record match\n");
} else if (entire_fat_32_br_matches(&fake_fd)) {
uprintf("Exact FAT32 DOS boot record match\n");
} else if (entire_fat_32_nt_br_matches(&fake_fd)) {
uprintf("Exact FAT32 NT boot record match\n");
} else if (entire_fat_32_fd_br_matches(&fake_fd)) {
uprintf("Exactly FAT32 FreeDOS boot record match\n");
} else {
uprintf("Unknown FAT16 or FAT32 boot record\n");
}
} else if (is_dos_mbr(&fake_fd)) {
uprintf("Microsoft DOS/NT/95A master boot record match\n");
} else if (is_dos_f2_mbr(&fake_fd)) {
uprintf("Microsoft DOS/NT/95A master boot record with the undocumented\n");
uprintf("F2 instruction match\n");
} else if (is_95b_mbr(&fake_fd)) {
uprintf("Microsoft 95B/98/98SE/ME master boot record match\n");
} else if (is_2000_mbr(&fake_fd)) {
uprintf("Microsoft 2000/XP/2003 master boot record match\n");
} else if (is_vista_mbr(&fake_fd)) {
uprintf("Microsoft Vista master boot record match\n");
} else if (is_win7_mbr(&fake_fd)) {
uprintf("Microsoft 7 master boot record match\n");
} else if (is_zero_mbr(&fake_fd)) {
uprintf("Zeroed non-bootable master boot record match\n");
} else {
uprintf("Unknown boot record\n");
}
return TRUE;
}
/*
* Process the Master Boot Record
*/
static BOOL WriteMBR(HANDLE hPhysicalDrive)
{
BOOL r = FALSE;
unsigned char* buf = NULL;
size_t SecSize = SelectedDrive.Geometry.BytesPerSector;
size_t nSecs = (0x200 + SecSize -1) / SecSize;
FILE fake_fd;
if (!AnalyzeMBR(hPhysicalDrive)) return FALSE;
// FormatEx rewrites the MBR and removes the LBA attribute of FAT16
// and FAT32 partitions - we need to correct this in the MBR
// TODO: something else for bootable GPT
buf = (unsigned char*)malloc(SecSize * nSecs);
if (buf == NULL) {
uprintf("Could not allocate memory for MBR");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY;
goto out;
}
if (!read_sectors(hPhysicalDrive, SelectedDrive.Geometry.BytesPerSector, 0, nSecs, buf, SecSize)) {
uprintf("Could not read MBR\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_READ_FAULT;
goto out;
}
switch (ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))) {
case FS_FAT16:
if (buf[0x1c2] == 0x0e) {
uprintf("Partition is already FAT16 LBA...\n");
} else if ((buf[0x1c2] != 0x04) && (buf[0x1c2] != 0x06)) {
uprintf("Warning: converting a non FAT16 partition to FAT16 LBA: FS type=0x%02x\n", buf[0x1c2]);
}
buf[0x1c2] = 0x0e;
break;
case FS_FAT32:
if (buf[0x1c2] == 0x0c) {
uprintf("Partition is already FAT32 LBA...\n");
} else if (buf[0x1c2] != 0x0b) {
uprintf("Warning: converting a non FAT32 partition to FAT32 LBA: FS type=0x%02x\n", buf[0x1c2]);
}
buf[0x1c2] = 0x0c;
break;
}
if (IsChecked(IDC_DOS)) {
buf[0x1be] = 0x80; // Set first partition bootable
}
if (!write_sectors(hPhysicalDrive, SelectedDrive.Geometry.BytesPerSector, 0, nSecs, buf, SecSize*nSecs)) {
uprintf("Could not write MBR\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
goto out;
}
fake_fd._ptr = (char*)hPhysicalDrive;
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
r = write_95b_mbr(&fake_fd);
out:
safe_free(buf);
return r;
}
/*
* Process the Partition Boot Record
*/
static BOOL WritePBR(HANDLE hLogicalVolume)
{
FILE fake_fd;
fake_fd._ptr = (char*)hLogicalVolume;
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
switch (ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))) {
case FS_FAT16:
if (write_fat_16_br(&fake_fd, 0))
return TRUE;
case FS_FAT32:
if (write_fat_32_br(&fake_fd, 0))
return TRUE;
default:
uprintf("unsupported FS for FS BR processing\n");
break;
}
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
return FALSE;
}
/*
* Standalone thread for the formatting operation
*/
void __cdecl FormatThread(void* param)
{
DWORD num = (DWORD)(uintptr_t)param;
HANDLE hPhysicalDrive = INVALID_HANDLE_VALUE;
HANDLE hLogicalVolume = INVALID_HANDLE_VALUE;
char drive_name[] = "?:";
int i;
hPhysicalDrive = GetDriveHandle(num, NULL, TRUE, TRUE);
if (hPhysicalDrive == INVALID_HANDLE_VALUE) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED;
goto out;
}
// At this stage with have both a handle and a lock to the physical drive
if (!CreatePartition(hPhysicalDrive)) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE;
goto out;
}
// Make sure we can access the volume again before trying to format it
for (i=0; i<10; i++) {
Sleep(500);
hLogicalVolume = GetDriveHandle(num, drive_name, FALSE, FALSE);
if (hLogicalVolume != INVALID_HANDLE_VALUE) {
break;
}
}
if (i >= 10) {
uprintf("Could not access volume after partitioning\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED;
goto out;
}
// Handle needs to be closed for FormatEx to be happy - we keep a lock though
safe_closehandle(hLogicalVolume);
if (!FormatDrive(drive_name[0])) {
// Error will be set by FormatDrive() in FormatStatus
uprintf("Format error: 0x%08X\n", FormatStatus);
goto out;
}
// TODO: Enable compression on NTFS
// TODO: optionally disable indexing on NTFS
// TODO: use progress bar during MBR/FSBR/MSDOS copy
// TODO: unlock/remount trick to make the volume reappear
PrintStatus("Writing master boot record...\n");
if (!WriteMBR(hPhysicalDrive)) {
// Errorcode has already been set
goto out;
}
if (IsChecked(IDC_DOS)) {
// We must have a lock to modify the FS boot record...
hLogicalVolume = GetDriveHandle(num, drive_name, TRUE, TRUE);
if (hLogicalVolume == INVALID_HANDLE_VALUE) {
uprintf("Could not re-mount volume for partition boot record access\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED;
goto out;
}
PrintStatus("Writing partition boot record...\n");
if (!WritePBR(hLogicalVolume)) {
// Errorcode has already been set
goto out;
}
// ... and we must have relinquished that lock to write the MS-DOS files
safe_unlockclose(hLogicalVolume);
PrintStatus("Copying MS-DOS files...\n");
if (!ExtractMSDOS(drive_name)) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY;
goto out;
}
}
out:
safe_unlockclose(hLogicalVolume);
safe_unlockclose(hPhysicalDrive);
PostMessage(hMainDialog, UM_FORMAT_COMPLETED, 0, 0);
_endthread();
}

106
src/format.h Normal file
View file

@ -0,0 +1,106 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* Formatting function calls
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Windows.h>
#include <winioctl.h> // for MEDIA_TYPE
#pragma once
/*
* typedefs for the function prototypes. Use the something like:
* PF_DECL(FormatEx);
* which translates to:
* FormatEx_t pfFormatEx = NULL;
* in your code, to declare the entrypoint and then use:
* PF_INIT(FormatEx, fmifs);
* which translates to:
* pfFormatEx = (FormatEx_t) GetProcAddress(GetDLLHandle("fmifs"), "FormatEx");
* to make it accessible.
*/
static __inline HMODULE GetDLLHandle(char* szDLLName)
{
HMODULE h = NULL;
if ((h = GetModuleHandleA(szDLLName)) == NULL)
h = LoadLibraryA(szDLLName);
return h;
}
#define PF_DECL(proc) proc##_t pf##proc = NULL
#define PF_INIT(proc, dllname) pf##proc = (proc##_t) GetProcAddress(GetDLLHandle(#dllname), #proc)
#define PF_INIT_OR_OUT(proc, dllname) \
PF_INIT(proc, dllname); if (pf##proc == NULL) { \
uprintf("unable to access %s DLL: %s", #dllname, \
WindowsErrorString()); goto out; }
/* Callback command types (some errorcode were filled from HPUSBFW V2.2.3 and their
designation from msdn.microsoft.com/en-us/library/windows/desktop/aa819439.aspx */
typedef enum {
FCC_PROGRESS,
FCC_DONE_WITH_STRUCTURE,
FCC_UNKNOWN2,
FCC_INCOMPATIBLE_FILE_SYSTEM,
FCC_UNKNOWN4,
FCC_UNKNOWN5,
FCC_ACCESS_DENIED,
FCC_MEDIA_WRITE_PROTECTED,
FCC_VOLUME_IN_USE,
FCC_CANT_QUICK_FORMAT,
FCC_UNKNOWNA,
FCC_DONE,
FCC_BAD_LABEL,
FCC_UNKNOWND,
FCC_OUTPUT,
FCC_STRUCTURE_PROGRESS,
FCC_CLUSTER_SIZE_TOO_SMALL,
FCC_CLUSTER_SIZE_TOO_BIG,
FCC_VOLUME_TOO_SMALL,
FCC_VOLUME_TOO_BIG,
FCC_NO_MEDIA_IN_DRIVE,
} FILE_SYSTEM_CALLBACK_COMMAND;
typedef struct {
DWORD Lines;
CHAR* Output;
} TEXTOUTPUT, *PTEXTOUTPUT;
typedef BOOLEAN (__stdcall *FILE_SYSTEM_CALLBACK)(
FILE_SYSTEM_CALLBACK_COMMAND Command,
ULONG Action,
PVOID pData
);
/* Parameter names aligned to
http://msdn.microsoft.com/en-us/library/windows/desktop/aa819439.aspx */
typedef VOID (WINAPI *FormatEx_t)(
WCHAR* DriveRoot,
MEDIA_TYPE MediaType, // See WinIoCtl.h
WCHAR* FileSystemTypeName,
WCHAR* Label,
BOOL QuickFormat,
ULONG DesiredUnitAllocationSize,
FILE_SYSTEM_CALLBACK Callback
);
/* http://msdn.microsoft.com/en-us/library/windows/desktop/aa383357.aspx */
typedef enum {
FPF_COMPRESSED = 0x01
} FILE_SYSTEM_PROP_FLAG;
typedef BOOLEAN (WINAPI* EnableVolumeCompression_t)(
WCHAR* DriveRoot,
ULONG CompressionFlags // FILE_SYSTEM_PROP_FLAG
);

75
src/inc/br.h Normal file
View file

@ -0,0 +1,75 @@
#ifndef BR_H
#define BR_H
#include <stdio.h>
/* returns TRUE if the file has a boot record, otherwise FALSE.
The file position will change when this function is called! */
int is_br(FILE *fp);
/* returns TRUE if the file has a LILO boot record, otherwise FALSE.
The file position will change when this function is called! */
int is_lilo_br(FILE *fp);
/* returns TRUE if the file has a Microsoft dos master boot record, otherwise
FALSE.The file position will change when this function is called! */
int is_dos_mbr(FILE *fp);
/* returns TRUE if the file has a Microsoft dos master boot record with the
undocumented F2 instruction, otherwise FALSE. The file position will change
when this function is called! */
int is_dos_f2_mbr(FILE *fp);
/* returns TRUE if the file has a Microsoft 95b master boot record, otherwise
FALSE.The file position will change when this function is called! */
int is_95b_mbr(FILE *fp);
/* returns TRUE if the file has a Microsoft 2000 master boot record, otherwise
FALSE.The file position will change when this function is called! */
int is_2000_mbr(FILE *fp);
/* returns TRUE if the file has a Microsoft Vista master boot record, otherwise
FALSE.The file position will change when this function is called! */
int is_vista_mbr(FILE *fp);
/* returns TRUE if the file has a Microsoft 7 master boot record, otherwise
FALSE.The file position will change when this function is called! */
int is_win7_mbr(FILE *fp);
/* returns TRUE if the file has a syslinux master boot record, otherwise
FALSE.The file position will change when this function is called! */
int is_syslinux_mbr(FILE *fp);
/* returns TRUE if the file has a zeroed master boot record, otherwise
FALSE.The file position will change when this function is called! */
int is_zero_mbr(FILE *fp);
/* Writes a dos master boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_dos_mbr(FILE *fp);
/* Writes a 95b master boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_95b_mbr(FILE *fp);
/* Writes a 2000 master boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_2000_mbr(FILE *fp);
/* Writes a Vista master boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_vista_mbr(FILE *fp);
/* Writes a 7 master boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_win7_mbr(FILE *fp);
/* Writes a syslinux master boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_syslinux_mbr(FILE *fp);
/* Writes an empty (zeroed) master boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_zero_mbr(FILE *fp);
#endif

3
src/inc/br_fat12_0x0.h Normal file
View file

@ -0,0 +1,3 @@
unsigned char br_fat12_0x0[] = {
0xeb, 0x3c, 0x90, 0x4d, 0x53, 0x57, 0x49, 0x4e, 0x34, 0x2e, 0x31
};

41
src/inc/br_fat12_0x3e.h Normal file
View file

@ -0,0 +1,41 @@
unsigned char br_fat12_0x3e[] = {
0x33, 0xc9, 0x8e, 0xd1, 0xbc, 0xfc, 0x7b, 0x16, 0x07, 0xbd,
0x78, 0x00, 0xc5, 0x76, 0x00, 0x1e, 0x56, 0x16, 0x55, 0xbf, 0x22, 0x05,
0x89, 0x7e, 0x00, 0x89, 0x4e, 0x02, 0xb1, 0x0b, 0xfc, 0xf3, 0xa4, 0x06,
0x1f, 0xbd, 0x00, 0x7c, 0xc6, 0x45, 0xfe, 0x0f, 0x38, 0x4e, 0x24, 0x7d,
0x20, 0x8b, 0xc1, 0x99, 0xe8, 0x7e, 0x01, 0x83, 0xeb, 0x3a, 0x66, 0xa1,
0x1c, 0x7c, 0x66, 0x3b, 0x07, 0x8a, 0x57, 0xfc, 0x75, 0x06, 0x80, 0xca,
0x02, 0x88, 0x56, 0x02, 0x80, 0xc3, 0x10, 0x73, 0xed, 0x33, 0xc9, 0xfe,
0x06, 0xd8, 0x7d, 0x8a, 0x46, 0x10, 0x98, 0xf7, 0x66, 0x16, 0x03, 0x46,
0x1c, 0x13, 0x56, 0x1e, 0x03, 0x46, 0x0e, 0x13, 0xd1, 0x8b, 0x76, 0x11,
0x60, 0x89, 0x46, 0xfc, 0x89, 0x56, 0xfe, 0xb8, 0x20, 0x00, 0xf7, 0xe6,
0x8b, 0x5e, 0x0b, 0x03, 0xc3, 0x48, 0xf7, 0xf3, 0x01, 0x46, 0xfc, 0x11,
0x4e, 0xfe, 0x61, 0xbf, 0x00, 0x07, 0xe8, 0x28, 0x01, 0x72, 0x3e, 0x38,
0x2d, 0x74, 0x17, 0x60, 0xb1, 0x0b, 0xbe, 0xd8, 0x7d, 0xf3, 0xa6, 0x61,
0x74, 0x3d, 0x4e, 0x74, 0x09, 0x83, 0xc7, 0x20, 0x3b, 0xfb, 0x72, 0xe7,
0xeb, 0xdd, 0xfe, 0x0e, 0xd8, 0x7d, 0x7b, 0xa7, 0xbe, 0x7f, 0x7d, 0xac,
0x98, 0x03, 0xf0, 0xac, 0x98, 0x40, 0x74, 0x0c, 0x48, 0x74, 0x13, 0xb4,
0x0e, 0xbb, 0x07, 0x00, 0xcd, 0x10, 0xeb, 0xef, 0xbe, 0x82, 0x7d, 0xeb,
0xe6, 0xbe, 0x80, 0x7d, 0xeb, 0xe1, 0xcd, 0x16, 0x5e, 0x1f, 0x66, 0x8f,
0x04, 0xcd, 0x19, 0xbe, 0x81, 0x7d, 0x8b, 0x7d, 0x1a, 0x8d, 0x45, 0xfe,
0x8a, 0x4e, 0x0d, 0xf7, 0xe1, 0x03, 0x46, 0xfc, 0x13, 0x56, 0xfe, 0xb1,
0x04, 0xe8, 0xc2, 0x00, 0x72, 0xd7, 0xea, 0x00, 0x02, 0x70, 0x00, 0x52,
0x50, 0x06, 0x53, 0x6a, 0x01, 0x6a, 0x10, 0x91, 0x8b, 0x46, 0x18, 0xa2,
0x26, 0x05, 0x96, 0x92, 0x33, 0xd2, 0xf7, 0xf6, 0x91, 0xf7, 0xf6, 0x42,
0x87, 0xca, 0xf7, 0x76, 0x1a, 0x8a, 0xf2, 0x8a, 0xe8, 0xc0, 0xcc, 0x02,
0x0a, 0xcc, 0xb8, 0x01, 0x02, 0x80, 0x7e, 0x02, 0x0e, 0x75, 0x04, 0xb4,
0x42, 0x8b, 0xf4, 0x8a, 0x56, 0x24, 0xcd, 0x13, 0x61, 0x61, 0x72, 0x0a,
0x40, 0x75, 0x01, 0x42, 0x03, 0x5e, 0x0b, 0x49, 0x75, 0x77, 0xc3, 0x03,
0x18, 0x01, 0x27, 0x0d, 0x0a, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64,
0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x64, 0x69, 0x73, 0x6b,
0xff, 0x0d, 0x0a, 0x44, 0x69, 0x73, 0x6b, 0x20, 0x49, 0x2f, 0x4f, 0x20,
0x65, 0x72, 0x72, 0x6f, 0x72, 0xff, 0x0d, 0x0a, 0x52, 0x65, 0x70, 0x6c,
0x61, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x69, 0x73, 0x6b,
0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70,
0x72, 0x65, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79,
0x0d, 0x0a, 0x00, 0x00, 0x49, 0x4f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x53, 0x59, 0x53, 0x4d, 0x53, 0x44, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x53,
0x59, 0x53, 0x7f, 0x01, 0x00, 0x41, 0xbb, 0x00, 0x07, 0x60, 0x66, 0x6a,
0x00, 0xe9, 0x3b, 0xff, 0x00, 0x00, 0x55, 0xaa
};

3
src/inc/br_fat16_0x0.h Normal file
View file

@ -0,0 +1,3 @@
unsigned char br_fat16_0x0[] = {
0xeb, 0x3c, 0x90, 0x4d, 0x53, 0x57, 0x49, 0x4e, 0x34, 0x2e, 0x31
};

32
src/inc/br_fat16_0x3e.h Normal file
View file

@ -0,0 +1,32 @@
unsigned char br_fat16_0x3e[] = {
0xfa, 0x33,
0xc9, 0x8e, 0xd1, 0xbc, 0xfc, 0x7b, 0x16, 0x07, 0xbd, 0x78, 0x00, 0xc5, 0x76, 0x00, 0x1e, 0x56,
0x16, 0x55, 0xbf, 0x22, 0x05, 0x89, 0x7e, 0x00, 0x89, 0x4e, 0x02, 0xb1, 0x0b, 0xfc, 0xf3, 0xa4,
0x06, 0x1f, 0xbd, 0x00, 0x7c, 0xc6, 0x45, 0xfe, 0x0f, 0x8b, 0x46, 0x18, 0x88, 0x45, 0xf9, 0x38,
0x4e, 0x24, 0x7d, 0x22, 0x8b, 0xc1, 0x99, 0xe8, 0x77, 0x01, 0x72, 0x1a, 0x83, 0xeb, 0x3a, 0x66,
0xa1, 0x1c, 0x7c, 0x66, 0x3b, 0x07, 0x8a, 0x57, 0xfc, 0x75, 0x06, 0x80, 0xca, 0x02, 0x88, 0x56,
0x02, 0x80, 0xc3, 0x10, 0x73, 0xed, 0x33, 0xc9, 0x8a, 0x46, 0x10, 0x98, 0xf7, 0x66, 0x16, 0x03,
0x46, 0x1c, 0x13, 0x56, 0x1e, 0x03, 0x46, 0x0e, 0x13, 0xd1, 0x8b, 0x76, 0x11, 0x60, 0x89, 0x46,
0xfc, 0x89, 0x56, 0xfe, 0xb8, 0x20, 0x00, 0xf7, 0xe6, 0x8b, 0x5e, 0x0b, 0x03, 0xc3, 0x48, 0xf7,
0xf3, 0x01, 0x46, 0xfc, 0x11, 0x4e, 0xfe, 0x61, 0xbf, 0x00, 0x07, 0xe8, 0x23, 0x01, 0x72, 0x39,
0x38, 0x2d, 0x74, 0x17, 0x60, 0xb1, 0x0b, 0xbe, 0xd8, 0x7d, 0xf3, 0xa6, 0x61, 0x74, 0x39, 0x4e,
0x74, 0x09, 0x83, 0xc7, 0x20, 0x3b, 0xfb, 0x72, 0xe7, 0xeb, 0xdd, 0xbe, 0x7f, 0x7d, 0xac, 0x98,
0x03, 0xf0, 0xac, 0x84, 0xc0, 0x74, 0x17, 0x3c, 0xff, 0x74, 0x09, 0xb4, 0x0e, 0xbb, 0x07, 0x00,
0xcd, 0x10, 0xeb, 0xee, 0xbe, 0x82, 0x7d, 0xeb, 0xe5, 0xbe, 0x80, 0x7d, 0xeb, 0xe0, 0x98, 0xcd,
0x16, 0x5e, 0x1f, 0x66, 0x8f, 0x04, 0xcd, 0x19, 0xbe, 0x81, 0x7d, 0x8b, 0x7d, 0x1a, 0x8d, 0x45,
0xfe, 0x8a, 0x4e, 0x0d, 0xf7, 0xe1, 0x03, 0x46, 0xfc, 0x13, 0x56, 0xfe, 0xb1, 0x04, 0xe8, 0xc1,
0x00, 0x72, 0xd6, 0xea, 0x00, 0x02, 0x70, 0x00, 0xb4, 0x42, 0xeb, 0x2d, 0x60, 0x66, 0x6a, 0x00,
0x52, 0x50, 0x06, 0x53, 0x6a, 0x01, 0x6a, 0x10, 0x8b, 0xf4, 0x74, 0xec, 0x91, 0x92, 0x33, 0xd2,
0xf7, 0x76, 0x18, 0x91, 0xf7, 0x76, 0x18, 0x42, 0x87, 0xca, 0xf7, 0x76, 0x1a, 0x8a, 0xf2, 0x8a,
0xe8, 0xc0, 0xcc, 0x02, 0x0a, 0xcc, 0xb8, 0x01, 0x02, 0x8a, 0x56, 0x24, 0xcd, 0x13, 0x8d, 0x64,
0x10, 0x61, 0x72, 0x0a, 0x40, 0x75, 0x01, 0x42, 0x03, 0x5e, 0x0b, 0x49, 0x75, 0x77, 0xc3, 0x03,
0x18, 0x01, 0x27, 0x0d, 0x0a, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x73, 0x79, 0x73,
0x74, 0x65, 0x6d, 0x20, 0x64, 0x69, 0x73, 0x6b, 0xff, 0x0d, 0x0a, 0x44, 0x69, 0x73, 0x6b, 0x20,
0x49, 0x2f, 0x4f, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0xff, 0x0d, 0x0a, 0x52, 0x65, 0x70, 0x6c,
0x61, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x69, 0x73, 0x6b, 0x2c, 0x20, 0x61, 0x6e,
0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x79,
0x20, 0x6b, 0x65, 0x79, 0x0d, 0x0a, 0x00, 0x00, 0x49, 0x4f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x53, 0x59, 0x53, 0x4d, 0x53, 0x44, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x53, 0x59, 0x53, 0x7f, 0x01,
0x00, 0x41, 0xbb, 0x00, 0x07, 0x80, 0x7e, 0x02, 0x0e, 0xe9, 0x40, 0xff, 0x00, 0x00, 0x55, 0xaa
};

37
src/inc/br_fat16fd_0x3e.h Normal file
View file

@ -0,0 +1,37 @@
/* br_fat16_0x3e.h
//
// ANI
// substring gmbh/tw 14.9.04
// modified bootsector 0x03e - 0x200 to support FreeDOS
*/
unsigned char br_fat16_0x3e[] = { 0xfa, 0xfc,
0x31, 0xc0, 0x8e, 0xd8, 0xbd, 0x00, 0x7c, 0xb8, 0xe0, 0x1f, 0x8e, 0xc0, 0x89, 0xee, 0x89, 0xef,
0xb9, 0x00, 0x01, 0xf3, 0xa5, 0xea, 0x5e, 0x7c, 0xe0, 0x1f, 0x00, 0x00, 0x60, 0x00, 0x8e, 0xd8,
0x8e, 0xd0, 0x8d, 0x66, 0xa0, 0xfb, 0x80, 0x7e, 0x24, 0xff, 0x75, 0x03, 0x88, 0x56, 0x24, 0xc7,
0x46, 0xc0, 0x10, 0x00, 0xc7, 0x46, 0xc2, 0x01, 0x00, 0xe8, 0xe6, 0x00, 0x46, 0x72, 0x65, 0x65,
0x44, 0x4f, 0x53, 0x00, 0x8b, 0x76, 0x1c, 0x8b, 0x7e, 0x1e, 0x03, 0x76, 0x0e, 0x83, 0xd7, 0x00,
0x89, 0x76, 0xd2, 0x89, 0x7e, 0xd4, 0x8a, 0x46, 0x10, 0x98, 0xf7, 0x66, 0x16, 0x01, 0xc6, 0x11,
0xd7, 0x89, 0x76, 0xd6, 0x89, 0x7e, 0xd8, 0x8b, 0x5e, 0x0b, 0xb1, 0x05, 0xd3, 0xeb, 0x8b, 0x46,
0x11, 0x31, 0xd2, 0xf7, 0xf3, 0x89, 0x46, 0xd0, 0x01, 0xc6, 0x83, 0xd7, 0x00, 0x89, 0x76, 0xda,
0x89, 0x7e, 0xdc, 0x8b, 0x46, 0xd6, 0x8b, 0x56, 0xd8, 0x8b, 0x7e, 0xd0, 0xc4, 0x5e, 0x5a, 0xe8,
0x98, 0x00, 0x72, 0x2f, 0xc4, 0x7e, 0x5a, 0xb9, 0x0b, 0x00, 0xbe, 0xf1, 0x7d, 0x57, 0xf3, 0xa6,
0x5f, 0x26, 0x8b, 0x45, 0x1a, 0x74, 0x0b, 0x83, 0xc7, 0x20, 0x26, 0x80, 0x3d, 0x00, 0x75, 0xe7,
0x72, 0x56, 0x50, 0xc4, 0x5e, 0x5a, 0x8b, 0x7e, 0x16, 0x8b, 0x46, 0xd2, 0x8b, 0x56, 0xd4, 0xe8,
0x68, 0x00, 0x58, 0x72, 0x43, 0x1e, 0x07, 0x8e, 0x5e, 0x5c, 0xbf, 0x00, 0x20, 0xab, 0x89, 0xc6,
0x8b, 0x56, 0x5c, 0x01, 0xf6, 0x73, 0x03, 0x80, 0xc6, 0x10, 0x8e, 0xda, 0xad, 0x3d, 0xf8, 0xff,
0x72, 0xeb, 0x31, 0xc0, 0xab, 0x0e, 0x1f, 0xc4, 0x5e, 0x5a, 0xbe, 0x00, 0x20, 0xad, 0x09, 0xc0,
0x74, 0x24, 0x48, 0x48, 0x8b, 0x7e, 0x0d, 0x81, 0xe7, 0xff, 0x00, 0xf7, 0xe7, 0x03, 0x46, 0xda,
0x13, 0x56, 0xdc, 0xe8, 0x24, 0x00, 0x73, 0xe5, 0xe8, 0x17, 0x00, 0x20, 0x65, 0x72, 0x72, 0x00,
0x30, 0xe4, 0xcd, 0x16, 0xcd, 0x19, 0x8a, 0x5e, 0x24, 0xff, 0x6e, 0x5a, 0x31, 0xdb, 0xb4, 0x0e,
0xcd, 0x10, 0x5e, 0xac, 0x56, 0x3c, 0x00, 0x75, 0xf3, 0xc3, 0x56, 0x89, 0x46, 0xc8, 0x89, 0x56,
0xca, 0x8c, 0x46, 0xc6, 0x89, 0x5e, 0xc4, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0x8a, 0x56, 0x24, 0x84,
0xd2, 0x74, 0x19, 0xcd, 0x13, 0x72, 0x15, 0xd1, 0xe9, 0x81, 0xdb, 0x54, 0xaa, 0x75, 0x0d, 0x8d,
0x76, 0xc0, 0x89, 0x5e, 0xcc, 0x89, 0x5e, 0xce, 0xb4, 0x42, 0xeb, 0x2c, 0x8b, 0x4e, 0xc8, 0x8b,
0x56, 0xca, 0x8a, 0x46, 0x18, 0xf6, 0x66, 0x1a, 0x91, 0xf7, 0xf1, 0x92, 0xf6, 0x76, 0x18, 0x89,
0xd1, 0x88, 0xc6, 0x86, 0xe9, 0xd0, 0xc9, 0xd0, 0xc9, 0x8a, 0x46, 0x18, 0x28, 0xe0, 0xfe, 0xc4,
0x08, 0xe1, 0xc4, 0x5e, 0xc4, 0xb8, 0x01, 0x02, 0x8a, 0x56, 0x24, 0xcd, 0x13, 0x73, 0x06, 0x30,
0xe4, 0xcd, 0x13, 0xeb, 0xa2, 0x8b, 0x46, 0x0b, 0xf6, 0x76, 0xc0, 0x01, 0x46, 0xc6, 0x83, 0x46,
0xc8, 0x01, 0x83, 0x56, 0xca, 0x00, 0x4f, 0x75, 0xea, 0x8e, 0x46, 0xc6, 0x5e, 0xc3, 0x00, 0x00,
0x00, 0x4b, 0x45, 0x52, 0x4e, 0x45, 0x4c, 0x20, 0x20, 0x53, 0x59, 0x53, 0x00, 0x00, 0x55, 0xaa
};

3
src/inc/br_fat32_0x0.h Normal file
View file

@ -0,0 +1,3 @@
unsigned char br_fat32_0x0[] = {
0xeb, 0x58, 0x90, 0x4d, 0x53, 0x57, 0x49, 0x4e, 0x34, 0x2e, 0x31
};

46
src/inc/br_fat32_0x3f0.h Normal file
View file

@ -0,0 +1,46 @@
unsigned char br_fat32_0x3f0[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x55, 0xaa, 0xfa, 0x66, 0x0f, 0xb6, 0x46, 0x10, 0x66, 0x8b,
0x4e, 0x24, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7,
0x56, 0x0e, 0x66, 0x03, 0xc2, 0x33, 0xc9, 0x66, 0x89, 0x46, 0xfc, 0x66,
0xc7, 0x46, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xfa, 0x66, 0x8b, 0x46, 0x2c,
0x66, 0x83, 0xf8, 0x02, 0x0f, 0x82, 0xcf, 0xfc, 0x66, 0x3d, 0xf8, 0xff,
0xff, 0x0f, 0x0f, 0x83, 0xc5, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb,
0x52, 0x50, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x66, 0x0f, 0xac, 0xd0, 0x10,
0x66, 0x83, 0xe8, 0x02, 0x66, 0x0f, 0xb6, 0x5e, 0x0d, 0x8b, 0xf3, 0x66,
0xf7, 0xe3, 0x66, 0x03, 0x46, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb,
0xbb, 0x00, 0x07, 0x8b, 0xfb, 0xb9, 0x01, 0x00, 0xe8, 0xbe, 0xfc, 0x0f,
0x82, 0xaa, 0xfc, 0x38, 0x2d, 0x74, 0x1e, 0xb1, 0x0b, 0x56, 0xbe, 0xd8,
0x7d, 0xf3, 0xa6, 0x5e, 0x74, 0x19, 0x03, 0xf9, 0x83, 0xc7, 0x15, 0x3b,
0xfb, 0x72, 0xe8, 0x4e, 0x75, 0xd6, 0x58, 0x5a, 0xe8, 0x66, 0x00, 0x72,
0xab, 0x83, 0xc4, 0x04, 0xe9, 0x64, 0xfc, 0x83, 0xc4, 0x04, 0x8b, 0x75,
0x09, 0x8b, 0x7d, 0x0f, 0x8b, 0xc6, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x8b,
0xc7, 0x66, 0x83, 0xf8, 0x02, 0x72, 0x3b, 0x66, 0x3d, 0xf8, 0xff, 0xff,
0x0f, 0x73, 0x33, 0x66, 0x48, 0x66, 0x48, 0x66, 0x0f, 0xb6, 0x4e, 0x0d,
0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10,
0xfb, 0xbb, 0x00, 0x07, 0x53, 0xb9, 0x04, 0x00, 0xe8, 0x52, 0xfc, 0x5b,
0x0f, 0x82, 0x3d, 0xfc, 0x81, 0x3f, 0x4d, 0x5a, 0x75, 0x08, 0x81, 0xbf,
0x00, 0x02, 0x42, 0x4a, 0x74, 0x06, 0xbe, 0x80, 0x7d, 0xe9, 0x0e, 0xfc,
0xea, 0x00, 0x02, 0x70, 0x00, 0x03, 0xc0, 0x13, 0xd2, 0x03, 0xc0, 0x13,
0xd2, 0xe8, 0x18, 0x00, 0xfa, 0x26, 0x66, 0x8b, 0x01, 0x66, 0x25, 0xff,
0xff, 0xff, 0x0f, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0x66, 0x3d, 0xf8, 0xff,
0xff, 0x0f, 0xfb, 0xc3, 0xbf, 0x00, 0x7e, 0xfa, 0x66, 0xc1, 0xe0, 0x10,
0x66, 0x0f, 0xac, 0xd0, 0x10, 0x66, 0x0f, 0xb7, 0x4e, 0x0b, 0x66, 0x33,
0xd2, 0x66, 0xf7, 0xf1, 0x66, 0x3b, 0x46, 0xf8, 0x74, 0x44, 0x66, 0x89,
0x46, 0xf8, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x4e, 0x0e, 0x66,
0x03, 0xc1, 0x66, 0x0f, 0xb7, 0x5e, 0x28, 0x83, 0xe3, 0x0f, 0x74, 0x16,
0x3a, 0x5e, 0x10, 0x0f, 0x83, 0xa4, 0xfb, 0x52, 0x66, 0x8b, 0xc8, 0x66,
0x8b, 0x46, 0x24, 0x66, 0xf7, 0xe3, 0x66, 0x03, 0xc1, 0x5a, 0x52, 0x66,
0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0x8b, 0xdf, 0xb9, 0x01, 0x00, 0xe8, 0xb4,
0xfb, 0x5a, 0x0f, 0x82, 0x9f, 0xfb, 0xfb, 0x8b, 0xda, 0xc3, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
};

80
src/inc/br_fat32_0x52.h Normal file
View file

@ -0,0 +1,80 @@
unsigned char br_fat32_0x52[] = {
0x46, 0x41,
0x54, 0x33, 0x32, 0x20, 0x20, 0x20, 0xfa, 0x33, 0xc9, 0x8e, 0xd1, 0xbc,
0xf8, 0x7b, 0x8e, 0xc1, 0xbd, 0x78, 0x00, 0xc5, 0x76, 0x00, 0x1e, 0x56,
0x16, 0x55, 0xbf, 0x22, 0x05, 0x89, 0x7e, 0x00, 0x89, 0x4e, 0x02, 0xb1,
0x0b, 0xfc, 0xf3, 0xa4, 0x8e, 0xd9, 0xbd, 0x00, 0x7c, 0xc6, 0x45, 0xfe,
0x0f, 0x8b, 0x46, 0x18, 0x88, 0x45, 0xf9, 0x38, 0x4e, 0x40, 0x7d, 0x25,
0x8b, 0xc1, 0x99, 0xbb, 0x00, 0x07, 0xe8, 0x97, 0x00, 0x72, 0x1a, 0x83,
0xeb, 0x3a, 0x66, 0xa1, 0x1c, 0x7c, 0x66, 0x3b, 0x07, 0x8a, 0x57, 0xfc,
0x75, 0x06, 0x80, 0xca, 0x02, 0x88, 0x56, 0x02, 0x80, 0xc3, 0x10, 0x73,
0xed, 0xbf, 0x02, 0x00, 0x83, 0x7e, 0x16, 0x00, 0x75, 0x45, 0x8b, 0x46,
0x1c, 0x8b, 0x56, 0x1e, 0xb9, 0x03, 0x00, 0x49, 0x40, 0x75, 0x01, 0x42,
0xbb, 0x00, 0x7e, 0xe8, 0x5f, 0x00, 0x73, 0x26, 0xb0, 0xf8, 0x4f, 0x74,
0x1d, 0x8b, 0x46, 0x32, 0x33, 0xd2, 0xb9, 0x03, 0x00, 0x3b, 0xc8, 0x77,
0x1e, 0x8b, 0x76, 0x0e, 0x3b, 0xce, 0x73, 0x17, 0x2b, 0xf1, 0x03, 0x46,
0x1c, 0x13, 0x56, 0x1e, 0xeb, 0xd1, 0x73, 0x0b, 0xeb, 0x27, 0x83, 0x7e,
0x2a, 0x00, 0x77, 0x03, 0xe9, 0xfd, 0x02, 0xbe, 0x7e, 0x7d, 0xac, 0x98,
0x03, 0xf0, 0xac, 0x84, 0xc0, 0x74, 0x17, 0x3c, 0xff, 0x74, 0x09, 0xb4,
0x0e, 0xbb, 0x07, 0x00, 0xcd, 0x10, 0xeb, 0xee, 0xbe, 0x81, 0x7d, 0xeb,
0xe5, 0xbe, 0x7f, 0x7d, 0xeb, 0xe0, 0x98, 0xcd, 0x16, 0x5e, 0x1f, 0x66,
0x8f, 0x04, 0xcd, 0x19, 0x41, 0x56, 0x66, 0x6a, 0x00, 0x52, 0x50, 0x06,
0x53, 0x6a, 0x01, 0x6a, 0x10, 0x8b, 0xf4, 0x60, 0x80, 0x7e, 0x02, 0x0e,
0x75, 0x04, 0xb4, 0x42, 0xeb, 0x1d, 0x91, 0x92, 0x33, 0xd2, 0xf7, 0x76,
0x18, 0x91, 0xf7, 0x76, 0x18, 0x42, 0x87, 0xca, 0xf7, 0x76, 0x1a, 0x8a,
0xf2, 0x8a, 0xe8, 0xc0, 0xcc, 0x02, 0x0a, 0xcc, 0xb8, 0x01, 0x02, 0x8a,
0x56, 0x40, 0xcd, 0x13, 0x61, 0x8d, 0x64, 0x10, 0x5e, 0x72, 0x0a, 0x40,
0x75, 0x01, 0x42, 0x03, 0x5e, 0x0b, 0x49, 0x75, 0xb4, 0xc3, 0x03, 0x18,
0x01, 0x27, 0x0d, 0x0a, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20,
0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x64, 0x69, 0x73, 0x6b, 0xff,
0x0d, 0x0a, 0x44, 0x69, 0x73, 0x6b, 0x20, 0x49, 0x2f, 0x4f, 0x20, 0x65,
0x72, 0x72, 0x6f, 0x72, 0xff, 0x0d, 0x0a, 0x52, 0x65, 0x70, 0x6c, 0x61,
0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x69, 0x73, 0x6b, 0x2c,
0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x72,
0x65, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79, 0x0d,
0x0a, 0x00, 0x00, 0x00, 0x49, 0x4f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x53, 0x59, 0x53, 0x4d, 0x53, 0x44, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x53,
0x59, 0x53, 0x7e, 0x01, 0x00, 0x57, 0x49, 0x4e, 0x42, 0x4f, 0x4f, 0x54,
0x20, 0x53, 0x59, 0x53, 0x00, 0x00, 0x55, 0xaa, 0x52, 0x52, 0x61, 0x41,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x72, 0x72, 0x41, 0x61
};

View file

@ -0,0 +1,53 @@
/* br_fat32_0x52.h
//
// ANI
// substring gmbh/tw 14.9.04
// modified cluster code 0x3f0 to support FreeDOS
*/
unsigned char br_fat32_0x3f0[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x55, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
};

86
src/inc/br_fat32fd_0x52.h Normal file
View file

@ -0,0 +1,86 @@
/* br_fat32_0x52.h
//
// ANI
// substring gmbh/tw 14.9.04
// modified bootstrap code 0x052 to support FreeDOS
*/
unsigned char br_fat32_0x52[] = {
0x46, 0x41, 0x54, 0x33, 0x32, 0x20, 0x20, 0x20, 0xfc, 0xfa, 0x29, 0xc0,
0x8e, 0xd8, 0xbd, 0x00, 0x7c, 0xb8, 0xe0, 0x1f, 0x8e, 0xc0, 0x89, 0xee,
0x89, 0xef, 0xb9, 0x00, 0x01, 0xf3, 0xa5, 0xea, 0x7a, 0x7c, 0xe0, 0x1f,
0x00, 0x00, 0x60, 0x00, 0x8e, 0xd8, 0x8e, 0xd0, 0x8d, 0x66, 0xe0, 0xfb,
0x88, 0x56, 0x40, 0xbe, 0xc1, 0x7d, 0xe8, 0xf4, 0x00, 0x66, 0x31, 0xc0,
0x66, 0x89, 0x46, 0x44, 0x8b, 0x46, 0x0e, 0x66, 0x03, 0x46, 0x1c, 0x66,
0x89, 0x46, 0x48, 0x66, 0x89, 0x46, 0x4c, 0x66, 0x8b, 0x46, 0x10, 0x66,
0xf7, 0x6e, 0x24, 0x66, 0x01, 0x46, 0x4c, 0xb8, 0x00, 0x02, 0x3b, 0x46,
0x0b, 0x74, 0x08, 0x01, 0xc0, 0xff, 0x06, 0x34, 0x7d, 0xeb, 0xf3, 0x66,
0x8b, 0x46, 0x2c, 0x66, 0x50, 0xe8, 0x94, 0x00, 0x72, 0x4d, 0xc4, 0x5e,
0x76, 0xe8, 0xb7, 0x00, 0x31, 0xff, 0xb9, 0x0b, 0x00, 0xbe, 0xf1, 0x7d,
0xf3, 0xa6, 0x74, 0x15, 0x83, 0xc7, 0x20, 0x83, 0xe7, 0xe0, 0x3b, 0x7e,
0x0b, 0x75, 0xeb, 0x4a, 0x75, 0xe0, 0x66, 0x58, 0xe8, 0x34, 0x00, 0xeb,
0xd2, 0x26, 0xff, 0x75, 0x09, 0x26, 0xff, 0x75, 0x0f, 0x66, 0x58, 0x29,
0xdb, 0x66, 0x50, 0xe8, 0x5a, 0x00, 0x72, 0x0d, 0xe8, 0x80, 0x00, 0x4a,
0x75, 0xfa, 0x66, 0x58, 0xe8, 0x14, 0x00, 0xeb, 0xec, 0x8a, 0x5e, 0x40,
0xff, 0x6e, 0x76, 0xbe, 0xee, 0x7d, 0xe8, 0x64, 0x00, 0x30, 0xe4, 0xcd,
0x16, 0xcd, 0x19, 0x06, 0x57, 0x53, 0x89, 0xc7, 0xc1, 0xe7, 0x02, 0x50,
0x8b, 0x46, 0x0b, 0x48, 0x21, 0xc7, 0x58, 0x66, 0xc1, 0xe8, 0x07, 0x66,
0x03, 0x46, 0x48, 0xbb, 0x00, 0x20, 0x8e, 0xc3, 0x29, 0xdb, 0x66, 0x3b,
0x46, 0x44, 0x74, 0x07, 0x66, 0x89, 0x46, 0x44, 0xe8, 0x38, 0x00, 0x26,
0x80, 0x65, 0x03, 0x0f, 0x26, 0x66, 0x8b, 0x05, 0x5b, 0x5f, 0x07, 0xc3,
0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x73, 0x15, 0x66, 0x48, 0x66, 0x48,
0x66, 0x0f, 0xb6, 0x56, 0x0d, 0x66, 0x52, 0x66, 0xf7, 0xe2, 0x66, 0x5a,
0x66, 0x03, 0x46, 0x4c, 0xc3, 0xf9, 0xc3, 0x31, 0xdb, 0xb4, 0x0e, 0xcd,
0x10, 0xac, 0x3c, 0x00, 0x75, 0xf5, 0xc3, 0x52, 0x56, 0x57, 0x66, 0x50,
0x89, 0xe7, 0x6a, 0x00, 0x6a, 0x00, 0x66, 0x50, 0x06, 0x53, 0x6a, 0x01,
0x6a, 0x10, 0x89, 0xe6, 0x8a, 0x56, 0x40, 0xb4, 0x42, 0xcd, 0x13, 0x89,
0xfc, 0x66, 0x58, 0x73, 0x08, 0x50, 0x30, 0xe4, 0xcd, 0x13, 0x58, 0xeb,
0xd9, 0x66, 0x40, 0x03, 0x5e, 0x0b, 0x73, 0x07, 0x8c, 0xc2, 0x80, 0xc6,
0x10, 0x8e, 0xc2, 0x5f, 0x5e, 0x5a, 0xc3, 0x4c, 0x6f, 0x61, 0x64, 0x69,
0x6e, 0x67, 0x20, 0x46, 0x72, 0x65, 0x65, 0x44, 0x4f, 0x53, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x4e, 0x6f, 0x20, 0x4b, 0x45, 0x52, 0x4e, 0x45,
0x4c, 0x20, 0x20, 0x53, 0x59, 0x53, 0x00, 0x00, 0x55, 0xaa, 0x52, 0x52,
0x61, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x72, 0x72, 0x41, 0x61
};

3
src/inc/br_fat32nt_0x0.h Normal file
View file

@ -0,0 +1,3 @@
unsigned char br_fat32nt_0x0[] = {
0xeb, 0x58, 0x90, 0x4d, 0x53, 0x57, 0x49, 0x4e, 0x34, 0x2e, 0x31
};

View file

@ -0,0 +1,45 @@
unsigned char br_fat32nt_0x1800[] = {
0x66, 0x0f, 0xb6, 0x46, 0x10, 0x66, 0x8b, 0x4e, 0x24, 0x66, 0xf7, 0xe1,
0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x56, 0x0e, 0x66, 0x03, 0xc2,
0x66, 0x89, 0x46, 0xfc, 0x66, 0xc7, 0x46, 0xf4, 0xff, 0xff, 0xff, 0xff,
0x66, 0x8b, 0x46, 0x2c, 0x66, 0x83, 0xf8, 0x02, 0x0f, 0x82, 0xa6, 0xfc,
0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x0f, 0x83, 0x9c, 0xfc, 0x66, 0x50,
0x66, 0x83, 0xe8, 0x02, 0x66, 0x0f, 0xb6, 0x5e, 0x0d, 0x8b, 0xf3, 0x66,
0xf7, 0xe3, 0x66, 0x03, 0x46, 0xfc, 0xbb, 0x00, 0x82, 0x8b, 0xfb, 0xb9,
0x01, 0x00, 0xe8, 0x87, 0xfc, 0x38, 0x2d, 0x74, 0x1e, 0xb1, 0x0b, 0x56,
0xbe, 0x70, 0x7d, 0xf3, 0xa6, 0x5e, 0x74, 0x1b, 0x03, 0xf9, 0x83, 0xc7,
0x15, 0x3b, 0xfb, 0x72, 0xe8, 0x4e, 0x75, 0xda, 0x66, 0x58, 0xe8, 0x65,
0x00, 0x72, 0xbf, 0x83, 0xc4, 0x04, 0xe9, 0x55, 0xfc, 0x00, 0x20, 0x83,
0xc4, 0x04, 0x8b, 0x75, 0x09, 0x8b, 0x7d, 0x0f, 0x8b, 0xc6, 0x66, 0xc1,
0xe0, 0x10, 0x8b, 0xc7, 0x66, 0x83, 0xf8, 0x02, 0x0f, 0x82, 0x3a, 0xfc,
0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x0f, 0x83, 0x30, 0xfc, 0x66, 0x50,
0x66, 0x83, 0xe8, 0x02, 0x66, 0x0f, 0xb6, 0x4e, 0x0d, 0x66, 0xf7, 0xe1,
0x66, 0x03, 0x46, 0xfc, 0xbb, 0x00, 0x00, 0x06, 0x8e, 0x06, 0x81, 0x80,
0xe8, 0x1d, 0xfc, 0x07, 0x66, 0x58, 0xc1, 0xeb, 0x04, 0x01, 0x1e, 0x81,
0x80, 0xe8, 0x0e, 0x00, 0x0f, 0x83, 0x02, 0x00, 0x72, 0xd0, 0x8a, 0x56,
0x40, 0xea, 0x00, 0x00, 0x00, 0x20, 0x66, 0xc1, 0xe0, 0x02, 0xe8, 0x11,
0x00, 0x26, 0x66, 0x8b, 0x01, 0x66, 0x25, 0xff, 0xff, 0xff, 0x0f, 0x66,
0x3d, 0xf8, 0xff, 0xff, 0x0f, 0xc3, 0xbf, 0x00, 0x7e, 0x66, 0x0f, 0xb7,
0x4e, 0x0b, 0x66, 0x33, 0xd2, 0x66, 0xf7, 0xf1, 0x66, 0x3b, 0x46, 0xf4,
0x74, 0x3a, 0x66, 0x89, 0x46, 0xf4, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f,
0xb7, 0x4e, 0x0e, 0x66, 0x03, 0xc1, 0x66, 0x0f, 0xb7, 0x5e, 0x28, 0x83,
0xe3, 0x0f, 0x74, 0x16, 0x3a, 0x5e, 0x10, 0x0f, 0x83, 0xab, 0xfb, 0x52,
0x66, 0x8b, 0xc8, 0x66, 0x8b, 0x46, 0x24, 0x66, 0xf7, 0xe3, 0x66, 0x03,
0xc1, 0x5a, 0x52, 0x8b, 0xdf, 0xb9, 0x01, 0x00, 0xe8, 0x9d, 0xfb, 0x5a,
0x8b, 0xda, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
};

View file

@ -0,0 +1,46 @@
unsigned char br_fat32nt_0x3f0[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x55, 0xaa, 0xfa, 0x66, 0x0f, 0xb6, 0x46, 0x10, 0x66, 0x8b,
0x4e, 0x24, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7,
0x56, 0x0e, 0x66, 0x03, 0xc2, 0x33, 0xc9, 0x66, 0x89, 0x46, 0xfc, 0x66,
0xc7, 0x46, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xfa, 0x66, 0x8b, 0x46, 0x2c,
0x66, 0x83, 0xf8, 0x02, 0x0f, 0x82, 0xcf, 0xfc, 0x66, 0x3d, 0xf8, 0xff,
0xff, 0x0f, 0x0f, 0x83, 0xc5, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb,
0x52, 0x50, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x66, 0x0f, 0xac, 0xd0, 0x10,
0x66, 0x83, 0xe8, 0x02, 0x66, 0x0f, 0xb6, 0x5e, 0x0d, 0x8b, 0xf3, 0x66,
0xf7, 0xe3, 0x66, 0x03, 0x46, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb,
0xbb, 0x00, 0x07, 0x8b, 0xfb, 0xb9, 0x01, 0x00, 0xe8, 0xbe, 0xfc, 0x0f,
0x82, 0xaa, 0xfc, 0x38, 0x2d, 0x74, 0x1e, 0xb1, 0x0b, 0x56, 0xbe, 0xd8,
0x7d, 0xf3, 0xa6, 0x5e, 0x74, 0x19, 0x03, 0xf9, 0x83, 0xc7, 0x15, 0x3b,
0xfb, 0x72, 0xe8, 0x4e, 0x75, 0xd6, 0x58, 0x5a, 0xe8, 0x66, 0x00, 0x72,
0xab, 0x83, 0xc4, 0x04, 0xe9, 0x64, 0xfc, 0x83, 0xc4, 0x04, 0x8b, 0x75,
0x09, 0x8b, 0x7d, 0x0f, 0x8b, 0xc6, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x8b,
0xc7, 0x66, 0x83, 0xf8, 0x02, 0x72, 0x3b, 0x66, 0x3d, 0xf8, 0xff, 0xff,
0x0f, 0x73, 0x33, 0x66, 0x48, 0x66, 0x48, 0x66, 0x0f, 0xb6, 0x4e, 0x0d,
0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10,
0xfb, 0xbb, 0x00, 0x07, 0x53, 0xb9, 0x04, 0x00, 0xe8, 0x52, 0xfc, 0x5b,
0x0f, 0x82, 0x3d, 0xfc, 0x81, 0x3f, 0x4d, 0x5a, 0x75, 0x08, 0x81, 0xbf,
0x00, 0x02, 0x42, 0x4a, 0x74, 0x06, 0xbe, 0x80, 0x7d, 0xe9, 0x0e, 0xfc,
0xea, 0x00, 0x02, 0x70, 0x00, 0x03, 0xc0, 0x13, 0xd2, 0x03, 0xc0, 0x13,
0xd2, 0xe8, 0x18, 0x00, 0xfa, 0x26, 0x66, 0x8b, 0x01, 0x66, 0x25, 0xff,
0xff, 0xff, 0x0f, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0x66, 0x3d, 0xf8, 0xff,
0xff, 0x0f, 0xfb, 0xc3, 0xbf, 0x00, 0x7e, 0xfa, 0x66, 0xc1, 0xe0, 0x10,
0x66, 0x0f, 0xac, 0xd0, 0x10, 0x66, 0x0f, 0xb7, 0x4e, 0x0b, 0x66, 0x33,
0xd2, 0x66, 0xf7, 0xf1, 0x66, 0x3b, 0x46, 0xf8, 0x74, 0x44, 0x66, 0x89,
0x46, 0xf8, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x4e, 0x0e, 0x66,
0x03, 0xc1, 0x66, 0x0f, 0xb7, 0x5e, 0x28, 0x83, 0xe3, 0x0f, 0x74, 0x16,
0x3a, 0x5e, 0x10, 0x0f, 0x83, 0xa4, 0xfb, 0x52, 0x66, 0x8b, 0xc8, 0x66,
0x8b, 0x46, 0x24, 0x66, 0xf7, 0xe3, 0x66, 0x03, 0xc1, 0x5a, 0x52, 0x66,
0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0x8b, 0xdf, 0xb9, 0x01, 0x00, 0xe8, 0xb4,
0xfb, 0x5a, 0x0f, 0x82, 0x9f, 0xfb, 0xfb, 0x8b, 0xda, 0xc3, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
};

80
src/inc/br_fat32nt_0x52.h Normal file
View file

@ -0,0 +1,80 @@
unsigned char br_fat32nt_0x52[] = {
0x46, 0x41,
0x54, 0x33, 0x32, 0x20, 0x20, 0x20, 0x33, 0xc9, 0x8e, 0xd1, 0xbc, 0xf4,
0x7b, 0x8e, 0xc1, 0x8e, 0xd9, 0xbd, 0x00, 0x7c, 0x88, 0x4e, 0x02, 0x8a,
0x56, 0x40, 0xb4, 0x08, 0xcd, 0x13, 0x73, 0x05, 0xb9, 0xff, 0xff, 0x8a,
0xf1, 0x66, 0x0f, 0xb6, 0xc6, 0x40, 0x66, 0x0f, 0xb6, 0xd1, 0x80, 0xe2,
0x3f, 0xf7, 0xe2, 0x86, 0xcd, 0xc0, 0xed, 0x06, 0x41, 0x66, 0x0f, 0xb7,
0xc9, 0x66, 0xf7, 0xe1, 0x66, 0x89, 0x46, 0xf8, 0x83, 0x7e, 0x16, 0x00,
0x75, 0x38, 0x83, 0x7e, 0x2a, 0x00, 0x77, 0x32, 0x66, 0x8b, 0x46, 0x1c,
0x66, 0x83, 0xc0, 0x0c, 0xbb, 0x00, 0x80, 0xb9, 0x01, 0x00, 0xe8, 0x2b,
0x00, 0xe9, 0x48, 0x03, 0xa0, 0xfa, 0x7d, 0xb4, 0x7d, 0x8b, 0xf0, 0xac,
0x84, 0xc0, 0x74, 0x17, 0x3c, 0xff, 0x74, 0x09, 0xb4, 0x0e, 0xbb, 0x07,
0x00, 0xcd, 0x10, 0xeb, 0xee, 0xa0, 0xfb, 0x7d, 0xeb, 0xe5, 0xa0, 0xf9,
0x7d, 0xeb, 0xe0, 0x98, 0xcd, 0x16, 0xcd, 0x19, 0x66, 0x60, 0x66, 0x3b,
0x46, 0xf8, 0x0f, 0x82, 0x4a, 0x00, 0x66, 0x6a, 0x00, 0x66, 0x50, 0x06,
0x53, 0x66, 0x68, 0x10, 0x00, 0x01, 0x00, 0x80, 0x7e, 0x02, 0x00, 0x0f,
0x85, 0x20, 0x00, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0x8a, 0x56, 0x40, 0xcd,
0x13, 0x0f, 0x82, 0x1c, 0x00, 0x81, 0xfb, 0x55, 0xaa, 0x0f, 0x85, 0x14,
0x00, 0xf6, 0xc1, 0x01, 0x0f, 0x84, 0x0d, 0x00, 0xfe, 0x46, 0x02, 0xb4,
0x42, 0x8a, 0x56, 0x40, 0x8b, 0xf4, 0xcd, 0x13, 0xb0, 0xf9, 0x66, 0x58,
0x66, 0x58, 0x66, 0x58, 0x66, 0x58, 0xeb, 0x2a, 0x66, 0x33, 0xd2, 0x66,
0x0f, 0xb7, 0x4e, 0x18, 0x66, 0xf7, 0xf1, 0xfe, 0xc2, 0x8a, 0xca, 0x66,
0x8b, 0xd0, 0x66, 0xc1, 0xea, 0x10, 0xf7, 0x76, 0x1a, 0x86, 0xd6, 0x8a,
0x56, 0x40, 0x8a, 0xe8, 0xc0, 0xe4, 0x06, 0x0a, 0xcc, 0xb8, 0x01, 0x02,
0xcd, 0x13, 0x66, 0x61, 0x0f, 0x82, 0x54, 0xff, 0x81, 0xc3, 0x00, 0x02,
0x66, 0x40, 0x49, 0x0f, 0x85, 0x71, 0xff, 0xc3, 0x4e, 0x54, 0x4c, 0x44,
0x52, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0a, 0x4e, 0x54,
0x4c, 0x44, 0x52, 0x20, 0x69, 0x73, 0x20, 0x6d, 0x69, 0x73, 0x73, 0x69,
0x6e, 0x67, 0xff, 0x0d, 0x0a, 0x44, 0x69, 0x73, 0x6b, 0x20, 0x65, 0x72,
0x72, 0x6f, 0x72, 0xff, 0x0d, 0x0a, 0x50, 0x72, 0x65, 0x73, 0x73, 0x20,
0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x72,
0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x0d, 0x0a, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xac, 0xbf, 0xcc, 0x00, 0x00, 0x55, 0xaa, 0x52, 0x52, 0x61, 0x41,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x72, 0x72, 0x41, 0x61
};

18
src/inc/fat12.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef FAT12_H
#define FAT12_H
/* returns TRUE if the file has a FAT12 file system, otherwise FALSE.
The file position will change when this function is called! */
int is_fat_12_fs(FILE *fp);
/* returns TRUE if the file has an exact match ot the FAT12 boot record this
program would create, otherwise FALSE.
The file position will change when this function is called! */
int entire_fat_12_br_matches(FILE *fp);
/* Writes a FAT12 boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_fat_12_br(FILE *fp, int bKeepLabel);
#endif

32
src/inc/fat16.h Normal file
View file

@ -0,0 +1,32 @@
#ifndef FAT16_H
#define FAT16_H
#include <stdio.h>
/* returns TRUE if the file has a FAT16 file system, otherwise FALSE.
The file position will change when this function is called! */
int is_fat_16_fs(FILE *fp);
/* returns TRUE if the file has a FAT16 boot record, otherwise FALSE.
The file position will change when this function is called! */
int is_fat_16_br(FILE *fp);
/* returns TRUE if the file has an exact match ot the FAT16 boot record this
program would create, otherwise FALSE.
The file position will change when this function is called! */
int entire_fat_16_br_matches(FILE *fp);
/* Writes a FAT16 boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_fat_16_br(FILE *fp, int bKeepLabel);
/* returns TRUE if the file has an exact match ot the FAT16 boot record this
program would create for FreeDOS, otherwise FALSE.
The file position will change when this function is called! */
int entire_fat_16_fd_br_matches(FILE *fp);
/* Writes a FAT16 FreeDOS boot record to a file, returns TRUE on success,
otherwise FALSE */
int write_fat_16_fd_br(FILE *fp, int bKeepLabel);
#endif

41
src/inc/fat32.h Normal file
View file

@ -0,0 +1,41 @@
#ifndef FAT32_H
#define FAT32_H
#include <stdio.h>
/* returns TRUE if the file has a FAT32 file system, otherwise FALSE.
The file position will change when this function is called! */
int is_fat_32_fs(FILE *fp);
/* returns TRUE if the file has a FAT32 DOS boot record, otherwise FALSE.
The file position will change when this function is called! */
int is_fat_32_br(FILE *fp);
/* returns TRUE if the file has an exact match of the FAT32 DOS boot record
this program would create, otherwise FALSE.
The file position will change when this function is called! */
int entire_fat_32_br_matches(FILE *fp);
/* Writes a FAT32 DOS boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_fat_32_br(FILE *fp, int bKeepLabel);
/* returns TRUE if the file has an exact match ot the FAT32 boot record this
program would create for FreeDOS, otherwise FALSE.
The file position will change when this function is called! */
int entire_fat_32_fd_br_matches(FILE *fp);
/* Writes a FAT32 FreeDOS boot record to a file, returns TRUE on success,
otherwise FALSE */
int write_fat_32_fd_br(FILE *fp, int bKeepLabel);
/* returns TRUE if the file has an exact match ot the FAT32 boot record this
program would create for NT, otherwise FALSE.
The file position will change when this function is called! */
int entire_fat_32_nt_br_matches(FILE *fp);
/* Writes a FAT32 NT boot record to a file, returns TRUE on success, otherwise
FALSE */
int write_fat_32_nt_br(FILE *fp, int bKeepLabel);
#endif

27
src/inc/file.h Normal file
View file

@ -0,0 +1,27 @@
#ifndef FILE_H
#define FILE_H
/* Max valid value of uiLen for contains_data */
#define MAX_DATA_LEN 4096
/* Checks if a file contains a data pattern of length uiLen at position
ulPositoin. The file pointer will change when calling this function! */
int contains_data(FILE *fp, size_t ulPosition,
const void *pData, size_t uiLen);
/* Writes a data pattern of length uiLen at position ulPositoin.
The file pointer will change when calling this function! */
int write_data(FILE *fp, size_t ulPosition,
const void *pData, size_t uiLen);
/* Checks if a file contains a data pattern of length uiLen at position
ulPositoin. The file pointer will change when calling this function! */
int write_sectors(void *hDrive, size_t SectorSize,
size_t StartSector, size_t nSectors,
const void *pBuf, size_t BufSize);
int read_sectors(void *hDrive, size_t SectorSize,
size_t StartSector, size_t nSectors,
void *pBuf, size_t BufSize);
#endif

1
src/inc/label_11_char.h Normal file
View file

@ -0,0 +1 @@
unsigned char label_11_char[] = {'N','O',' ','N','A','M','E',' ',' ',' ',' '};

50
src/inc/mbr_2000.h Normal file
View file

@ -0,0 +1,50 @@
/* First 446 bytes of MBR from Windows 2000, XP and 2003 */
/* This is English version. Bytes 0x12c onwards vary with language. */
/* Last two bytes 1b6 and 1b7 point to language-specific messages. */
/* Support of other languages is an exercise for the reader! */
unsigned char mbr_2000_0x0[] = {
0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0xfb, 0x50, 0x07, 0x50, 0x1f,
0xfc, 0xbe, 0x1b, 0x7c, 0xbf, 0x1b, 0x06, 0x50, 0x57, 0xb9, 0xe5, 0x01,
0xf3, 0xa4, 0xcb, 0xbd, 0xbe, 0x07, 0xb1, 0x04, 0x38, 0x6e, 0x00, 0x7c,
0x09, 0x75, 0x13, 0x83, 0xc5, 0x10, 0xe2, 0xf4, 0xcd, 0x18, 0x8b, 0xf5,
0x83, 0xc6, 0x10, 0x49, 0x74, 0x19, 0x38, 0x2c, 0x74, 0xf6, 0xa0, 0xb5,
0x07, 0xb4, 0x07, 0x8b, 0xf0, 0xac, 0x3c, 0x00, 0x74, 0xfc, 0xbb, 0x07,
0x00, 0xb4, 0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0x88, 0x4e, 0x10, 0xe8, 0x46,
0x00, 0x73, 0x2a, 0xfe, 0x46, 0x10, 0x80, 0x7e, 0x04, 0x0b, 0x74, 0x0b,
0x80, 0x7e, 0x04, 0x0c, 0x74, 0x05, 0xa0, 0xb6, 0x07, 0x75, 0xd2, 0x80,
0x46, 0x02, 0x06, 0x83, 0x46, 0x08, 0x06, 0x83, 0x56, 0x0a, 0x00, 0xe8,
0x21, 0x00, 0x73, 0x05, 0xa0, 0xb6, 0x07, 0xeb, 0xbc, 0x81, 0x3e, 0xfe,
0x7d, 0x55, 0xaa, 0x74, 0x0b, 0x80, 0x7e, 0x10, 0x00, 0x74, 0xc8, 0xa0,
0xb7, 0x07, 0xeb, 0xa9, 0x8b, 0xfc, 0x1e, 0x57, 0x8b, 0xf5, 0xcb, 0xbf,
0x05, 0x00, 0x8a, 0x56, 0x00, 0xb4, 0x08, 0xcd, 0x13, 0x72, 0x23, 0x8a,
0xc1, 0x24, 0x3f, 0x98, 0x8a, 0xde, 0x8a, 0xfc, 0x43, 0xf7, 0xe3, 0x8b,
0xd1, 0x86, 0xd6, 0xb1, 0x06, 0xd2, 0xee, 0x42, 0xf7, 0xe2, 0x39, 0x56,
0x0a, 0x77, 0x23, 0x72, 0x05, 0x39, 0x46, 0x08, 0x73, 0x1c, 0xb8, 0x01,
0x02, 0xbb, 0x00, 0x7c, 0x8b, 0x4e, 0x02, 0x8b, 0x56, 0x00, 0xcd, 0x13,
0x73, 0x51, 0x4f, 0x74, 0x4e, 0x32, 0xe4, 0x8a, 0x56, 0x00, 0xcd, 0x13,
0xeb, 0xe4, 0x8a, 0x56, 0x00, 0x60, 0xbb, 0xaa, 0x55, 0xb4, 0x41, 0xcd,
0x13, 0x72, 0x36, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x30, 0xf6, 0xc1, 0x01,
0x74, 0x2b, 0x61, 0x60, 0x6a, 0x00, 0x6a, 0x00, 0xff, 0x76, 0x0a, 0xff,
0x76, 0x08, 0x6a, 0x00, 0x68, 0x00, 0x7c, 0x6a, 0x01, 0x6a, 0x10, 0xb4,
0x42, 0x8b, 0xf4, 0xcd, 0x13, 0x61, 0x61, 0x73, 0x0e, 0x4f, 0x74, 0x0b,
0x32, 0xe4, 0x8a, 0x56, 0x00, 0xcd, 0x13, 0xeb, 0xd6, 0x61, 0xf9, 0xc3,
0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74,
0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00,
0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e,
0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20,
0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69,
0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67,
0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x44, 0x63
};
/* Next four bytes used for Windows Disk Signature / Drive serial number */
/*
unsigned char mbr_2000_0x1b8[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
*/

56
src/inc/mbr_95b.h Normal file
View file

@ -0,0 +1,56 @@
/* First 446 bytes of MBR from Windows 95B, 98, 98SE and ME */
unsigned char mbr_95b_0x0[] = {
0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0xfb, 0x50, 0x07, 0x50, 0x1f,
0xfc, 0xbe, 0x1b, 0x7c, 0xbf, 0x1b, 0x06, 0x50, 0x57, 0xb9, 0xe5, 0x01,
0xf3, 0xa4, 0xcb, 0xbe, 0xbe, 0x07, 0xb1, 0x04, 0x38, 0x2c, 0x7c, 0x09,
0x75, 0x15, 0x83, 0xc6, 0x10, 0xe2, 0xf5, 0xcd, 0x18, 0x8b, 0x14, 0x8b,
0xee, 0x83, 0xc6, 0x10, 0x49, 0x74, 0x16, 0x38, 0x2c, 0x74, 0xf6, 0xbe,
0x10, 0x07, 0x4e, 0xac, 0x3c, 0x00, 0x74, 0xfa, 0xbb, 0x07, 0x00, 0xb4,
0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0x89, 0x46, 0x25, 0x96, 0x8a, 0x46, 0x04,
0xb4, 0x06, 0x3c, 0x0e, 0x74, 0x11, 0xb4, 0x0b, 0x3c, 0x0c, 0x74, 0x05,
0x3a, 0xc4, 0x75, 0x2b, 0x40, 0xc6, 0x46, 0x25, 0x06, 0x75, 0x24, 0xbb,
0xaa, 0x55, 0x50, 0xb4, 0x41, 0xcd, 0x13, 0x58, 0x72, 0x16, 0x81, 0xfb,
0x55, 0xaa, 0x75, 0x10, 0xf6, 0xc1, 0x01, 0x74, 0x0b, 0x8a, 0xe0, 0x88,
0x56, 0x24, 0xc7, 0x06, 0xa1, 0x06, 0xeb, 0x1e, 0x88, 0x66, 0x04, 0xbf,
0x0a, 0x00, 0xb8, 0x01, 0x02, 0x8b, 0xdc, 0x33, 0xc9, 0x83, 0xff, 0x05,
0x7f, 0x03, 0x8b, 0x4e, 0x25, 0x03, 0x4e, 0x02, 0xcd, 0x13, 0x72, 0x29,
0xbe, 0x46, 0x07, 0x81, 0x3e, 0xfe, 0x7d, 0x55, 0xaa, 0x74, 0x5a, 0x83,
0xef, 0x05, 0x7f, 0xda, 0x85, 0xf6, 0x75, 0x83, 0xbe, 0x27, 0x07, 0xeb,
0x8a, 0x98, 0x91, 0x52, 0x99, 0x03, 0x46, 0x08, 0x13, 0x56, 0x0a, 0xe8,
0x12, 0x00, 0x5a, 0xeb, 0xd5, 0x4f, 0x74, 0xe4, 0x33, 0xc0, 0xcd, 0x13,
0xeb, 0xb8
};
/* Next 6 bytes used to write boot drive and time by some Windows OSs */
/*
unsigned char mbr_95b_0x0da[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
*/
unsigned char mbr_95b_0x0e0[] = {
0x56, 0x33, 0xf6, 0x56,
0x56, 0x52, 0x50, 0x06, 0x53, 0x51, 0xbe, 0x10, 0x00, 0x56, 0x8b, 0xf4,
0x50, 0x52, 0xb8, 0x00, 0x42, 0x8a, 0x56, 0x24, 0xcd, 0x13, 0x5a, 0x58,
0x8d, 0x64, 0x10, 0x72, 0x0a, 0x40, 0x75, 0x01, 0x42, 0x80, 0xc7, 0x02,
0xe2, 0xf7, 0xf8, 0x5e, 0xc3, 0xeb, 0x74, 0x49, 0x6e, 0x76, 0x61, 0x6c,
0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72,
0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65,
0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65,
0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70,
0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x8b, 0xfc, 0x1e, 0x57, 0x8b, 0xf5, 0xcb, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/* Next four bytes used for Windows Disk Signature / Drive serial number */
/*
unsigned char mbr_95b_0x1b8[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
*/

47
src/inc/mbr_dos.h Normal file
View file

@ -0,0 +1,47 @@
/* First 446 bytes of MBR from Dos 3.3 onwards and Windows 95A */
unsigned char mbr_dos_0x0[] = {
0xfa, 0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x8b, 0xf4, 0x50, 0x07,
0x50, 0x1f, 0xfb, 0xfc, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x01, 0xf3, 0xa5,
0xea, 0x1d, 0x06, 0x00, 0x00, 0xbe, 0xbe, 0x07, 0xb3, 0x04, 0x80, 0x3c,
0x80, 0x74, 0x0e, 0x80, 0x3c, 0x00, 0x75, 0x1c, 0x83, 0xc6, 0x10, 0xfe,
0xcb, 0x75, 0xef, 0xcd, 0x18, 0x8b, 0x14, 0x8b, 0x4c, 0x02, 0x8b, 0xee,
0x83, 0xc6, 0x10, 0xfe, 0xcb, 0x74, 0x1a, 0x80, 0x3c, 0x00, 0x74, 0xf4,
0xbe, 0x8b, 0x06, 0xac, 0x3c, 0x00, 0x74, 0x0b, 0x56, 0xbb, 0x07, 0x00,
0xb4, 0x0e, 0xcd, 0x10, 0x5e, 0xeb, 0xf0, 0xeb, 0xfe, 0xbf, 0x05, 0x00,
0xbb, 0x00, 0x7c, 0xb8, 0x01, 0x02, 0x57, 0xcd, 0x13, 0x5f, 0x73, 0x0c,
0x33, 0xc0, 0xcd, 0x13, 0x4f, 0x75, 0xed, 0xbe, 0xa3, 0x06, 0xeb, 0xd3,
0xbe, 0xc2, 0x06, 0xbf, 0xfe, 0x7d, 0x81, 0x3d, 0x55, 0xaa, 0x75, 0xc7,
0x8b, 0xf5, 0xea, 0x00, 0x7c, 0x00, 0x00, 0x49, 0x6e, 0x76, 0x61, 0x6c,
0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72,
0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65,
0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65,
0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70,
0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/* Next four bytes used for Windows Disk Signature / Drive serial number */
/*
unsigned char mbr_dos_0x1b8[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
*/

40
src/inc/mbr_dos_f2.h Normal file
View file

@ -0,0 +1,40 @@
/* First 446 bytes of MBR from Dos 3.3 onwards and Windows 95A */
unsigned char mbr_dos_f2_0x0[] = {
0xfa, 0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x8b, 0xf4, 0x50, 0x07,
0x50, 0x1f, 0xfb, 0xfc, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x01, 0xf2, 0xa5,
0xea, 0x1d, 0x06, 0x00, 0x00, 0xbe, 0xbe, 0x07, 0xb3, 0x04, 0x80, 0x3c,
0x80, 0x74, 0x0e, 0x80, 0x3c, 0x00, 0x75, 0x1c, 0x83, 0xc6, 0x10, 0xfe,
0xcb, 0x75, 0xef, 0xcd, 0x18, 0x8b, 0x14, 0x8b, 0x4c, 0x02, 0x8b, 0xee,
0x83, 0xc6, 0x10, 0xfe, 0xcb, 0x74, 0x1a, 0x80, 0x3c, 0x00, 0x74, 0xf4,
0xbe, 0x8b, 0x06, 0xac, 0x3c, 0x00, 0x74, 0x0b, 0x56, 0xbb, 0x07, 0x00,
0xb4, 0x0e, 0xcd, 0x10, 0x5e, 0xeb, 0xf0, 0xeb, 0xfe, 0xbf, 0x05, 0x00,
0xbb, 0x00, 0x7c, 0xb8, 0x01, 0x02, 0x57, 0xcd, 0x13, 0x5f, 0x73, 0x0c,
0x33, 0xc0, 0xcd, 0x13, 0x4f, 0x75, 0xed, 0xbe, 0xa3, 0x06, 0xeb, 0xd3,
0xbe, 0xc2, 0x06, 0xbf, 0xfe, 0x7d, 0x81, 0x3d, 0x55, 0xaa, 0x75, 0xc7,
0x8b, 0xf5, 0xea, 0x00, 0x7c, 0x00, 0x00, 0x49, 0x6e, 0x76, 0x61, 0x6c,
0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72,
0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65,
0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65,
0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70,
0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

29
src/inc/mbr_syslinux.h Normal file
View file

@ -0,0 +1,29 @@
/* Public domain MBR by H. Peter Anvin supplied with Syslinux */
/* This version from mbr.asm,v 1.6 2--2/10/03 10:02:50 */
unsigned char mbr_syslinux_0x0[] = {
0xfa, 0x31, 0xc0, 0x8e, 0xd8, 0x8e, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c,
0xfb, 0xfc, 0x89, 0xe6, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x01, 0xf3, 0xa5,
0xea, 0x1d, 0x06, 0x00, 0x00, 0x88, 0x16, 0x00, 0x08, 0xb4, 0x08, 0xcd,
0x13, 0x31, 0xc0, 0x88, 0xf0, 0x40, 0xa3, 0xec, 0x06, 0x80, 0xe1, 0x3f,
0x88, 0x0e, 0xee, 0x06, 0xbe, 0xbe, 0x07, 0x31, 0xc0, 0xb9, 0x04, 0x00,
0xf6, 0x04, 0x80, 0x74, 0x03, 0x40, 0x89, 0xf7, 0x83, 0xc6, 0x10, 0xe2,
0xf3, 0x83, 0xf8, 0x01, 0x75, 0x73, 0x8a, 0x16, 0x00, 0x08, 0xb8, 0x00,
0x41, 0xbb, 0xaa, 0x55, 0x31, 0xc9, 0x30, 0xf6, 0xf9, 0xcd, 0x13, 0x72,
0x23, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x1d, 0xf6, 0xc1, 0x01, 0x74, 0x18,
0x57, 0xbe, 0xdc, 0x06, 0x8b, 0x5d, 0x08, 0x89, 0x5c, 0x08, 0x8b, 0x5d,
0x0a, 0x89, 0x5c, 0x0a, 0x8a, 0x16, 0x00, 0x08, 0xb4, 0x42, 0xeb, 0x2a,
0x57, 0x8b, 0x45, 0x08, 0x8b, 0x55, 0x0a, 0xf7, 0x36, 0xee, 0x06, 0x42,
0x89, 0xd1, 0x31, 0xd2, 0xf7, 0x36, 0xec, 0x06, 0x88, 0xc5, 0xd1, 0xe8,
0xd1, 0xe8, 0x24, 0xc0, 0x08, 0xc1, 0x88, 0xd6, 0x8a, 0x16, 0x00, 0x08,
0xbb, 0x00, 0x7c, 0xb8, 0x01, 0x02, 0xcd, 0x13, 0x72, 0x16, 0x5e, 0x81,
0x3e, 0xfe, 0x7d, 0x55, 0xaa, 0x75, 0x08, 0xfa, 0xea, 0x00, 0x7c, 0x00,
0x00, 0x77, 0x05, 0xbe, 0xf0, 0x06, 0xeb, 0x03, 0xbe, 0x0b, 0x07, 0xac,
0x30, 0xc0, 0x74, 0x09, 0xb4, 0x0e, 0xbb, 0x07, 0x00, 0xcd, 0x10, 0xeb,
0xf2, 0xeb, 0xfe, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x7c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72,
0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d,
0x0d, 0x0a, 0x00, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67,
0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x6c, 0x6f, 0x61, 0x64,
0x69, 0x6e, 0x67, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0d, 0x0a, 0x00
};

50
src/inc/mbr_vista.h Normal file
View file

@ -0,0 +1,50 @@
/* First 446 bytes of MBR from Windows Vista */
/* This is English version. Bytes 0x12c onwards vary with language. */
/* Last two bytes 1b6 and 1b7 point to language-specific messages. */
/* Support of other languages is an exercise for the reader! */
unsigned char mbr_vista_0x0[] = {
0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x8e, 0xc0, 0x8e, 0xd8, 0xbe,
0x00, 0x7c, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x02, 0xfc, 0xf3, 0xa4, 0x50,
0x68, 0x1c, 0x06, 0xcb, 0xfb, 0xb9, 0x04, 0x00, 0xbd, 0xbe, 0x07, 0x80,
0x7e, 0x00, 0x00, 0x7c, 0x0b, 0x0f, 0x85, 0x10, 0x01, 0x83, 0xc5, 0x10,
0xe2, 0xf1, 0xcd, 0x18, 0x88, 0x56, 0x00, 0x55, 0xc6, 0x46, 0x11, 0x05,
0xc6, 0x46, 0x10, 0x00, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0xcd, 0x13, 0x5d,
0x72, 0x0f, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x09, 0xf7, 0xc1, 0x01, 0x00,
0x74, 0x03, 0xfe, 0x46, 0x10, 0x66, 0x60, 0x80, 0x7e, 0x10, 0x00, 0x74,
0x26, 0x66, 0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0xff, 0x76, 0x08, 0x68,
0x00, 0x00, 0x68, 0x00, 0x7c, 0x68, 0x01, 0x00, 0x68, 0x10, 0x00, 0xb4,
0x42, 0x8a, 0x56, 0x00, 0x8b, 0xf4, 0xcd, 0x13, 0x9f, 0x83, 0xc4, 0x10,
0x9e, 0xeb, 0x14, 0xb8, 0x01, 0x02, 0xbb, 0x00, 0x7c, 0x8a, 0x56, 0x00,
0x8a, 0x76, 0x01, 0x8a, 0x4e, 0x02, 0x8a, 0x6e, 0x03, 0xcd, 0x13, 0x66,
0x61, 0x73, 0x1e, 0xfe, 0x4e, 0x11, 0x0f, 0x85, 0x0c, 0x00, 0x80, 0x7e,
0x00, 0x80, 0x0f, 0x84, 0x8a, 0x00, 0xb2, 0x80, 0xeb, 0x82, 0x55, 0x32,
0xe4, 0x8a, 0x56, 0x00, 0xcd, 0x13, 0x5d, 0xeb, 0x9c, 0x81, 0x3e, 0xfe,
0x7d, 0x55, 0xaa, 0x75, 0x6e, 0xff, 0x76, 0x00, 0xe8, 0x8a, 0x00, 0x0f,
0x85, 0x15, 0x00, 0xb0, 0xd1, 0xe6, 0x64, 0xe8, 0x7f, 0x00, 0xb0, 0xdf,
0xe6, 0x60, 0xe8, 0x78, 0x00, 0xb0, 0xff, 0xe6, 0x64, 0xe8, 0x71, 0x00,
0xb8, 0x00, 0xbb, 0xcd, 0x1a, 0x66, 0x23, 0xc0, 0x75, 0x3b, 0x66, 0x81,
0xfb, 0x54, 0x43, 0x50, 0x41, 0x75, 0x32, 0x81, 0xf9, 0x02, 0x01, 0x72,
0x2c, 0x66, 0x68, 0x07, 0xbb, 0x00, 0x00, 0x66, 0x68, 0x00, 0x02, 0x00,
0x00, 0x66, 0x68, 0x08, 0x00, 0x00, 0x00, 0x66, 0x53, 0x66, 0x53, 0x66,
0x55, 0x66, 0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0x68, 0x00, 0x7c, 0x00,
0x00, 0x66, 0x61, 0x68, 0x00, 0x00, 0x07, 0xcd, 0x1a, 0x5a, 0x32, 0xf6,
0xea, 0x00, 0x7c, 0x00, 0x00, 0xcd, 0x18, 0xa0, 0xb7, 0x07, 0xeb, 0x08,
0xa0, 0xb6, 0x07, 0xeb, 0x03, 0xa0, 0xb5, 0x07, 0x32, 0xe4, 0x05, 0x00,
0x07, 0x8b, 0xf0, 0xac, 0x3c, 0x00, 0x74, 0xfc, 0xbb, 0x07, 0x00, 0xb4,
0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0x2b, 0xc9, 0xe4, 0x64, 0xeb, 0x00, 0x24,
0x02, 0xe0, 0xf8, 0x24, 0x02, 0xc3, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69,
0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20,
0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20,
0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72,
0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d,
0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65,
0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65,
0x6d, 0x00, 0x00, 0x00, 0x00, 0x62, 0x7a, 0x99
};
/* Next four bytes used for Windows Disk Signature / Drive serial number */
/*
unsigned char mbr_vista_0x1b8[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
*/

50
src/inc/mbr_win7.h Normal file
View file

@ -0,0 +1,50 @@
/* First 446 bytes of MBR from Windows 7 */
/* This is English version. Bytes 0x12c onwards vary with language. */
/* Last two bytes 1b6 and 1b7 point to language-specific messages. */
/* Support of other languages is an exercise for the reader! */
unsigned char mbr_win7_0x0[] = {
0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x8e, 0xc0, 0x8e, 0xd8, 0xbe,
0x00, 0x7c, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x02, 0xfc, 0xf3, 0xa4, 0x50,
0x68, 0x1c, 0x06, 0xcb, 0xfb, 0xb9, 0x04, 0x00, 0xbd, 0xbe, 0x07, 0x80,
0x7e, 0x00, 0x00, 0x7c, 0x0b, 0x0f, 0x85, 0x0e, 0x01, 0x83, 0xc5, 0x10,
0xe2, 0xf1, 0xcd, 0x18, 0x88, 0x56, 0x00, 0x55, 0xc6, 0x46, 0x11, 0x05,
0xc6, 0x46, 0x10, 0x00, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0xcd, 0x13, 0x5d,
0x72, 0x0f, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x09, 0xf7, 0xc1, 0x01, 0x00,
0x74, 0x03, 0xfe, 0x46, 0x10, 0x66, 0x60, 0x80, 0x7e, 0x10, 0x00, 0x74,
0x26, 0x66, 0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0xff, 0x76, 0x08, 0x68,
0x00, 0x00, 0x68, 0x00, 0x7c, 0x68, 0x01, 0x00, 0x68, 0x10, 0x00, 0xb4,
0x42, 0x8a, 0x56, 0x00, 0x8b, 0xf4, 0xcd, 0x13, 0x9f, 0x83, 0xc4, 0x10,
0x9e, 0xeb, 0x14, 0xb8, 0x01, 0x02, 0xbb, 0x00, 0x7c, 0x8a, 0x56, 0x00,
0x8a, 0x76, 0x01, 0x8a, 0x4e, 0x02, 0x8a, 0x6e, 0x03, 0xcd, 0x13, 0x66,
0x61, 0x73, 0x1c, 0xfe, 0x4e, 0x11, 0x75, 0x0c, 0x80, 0x7e, 0x00, 0x80,
0x0f, 0x84, 0x8a, 0x00, 0xb2, 0x80, 0xeb, 0x84, 0x55, 0x32, 0xe4, 0x8a,
0x56, 0x00, 0xcd, 0x13, 0x5d, 0xeb, 0x9e, 0x81, 0x3e, 0xfe, 0x7d, 0x55,
0xaa, 0x75, 0x6e, 0xff, 0x76, 0x00, 0xe8, 0x8d, 0x00, 0x75, 0x17, 0xfa,
0xb0, 0xd1, 0xe6, 0x64, 0xe8, 0x83, 0x00, 0xb0, 0xdf, 0xe6, 0x60, 0xe8,
0x7c, 0x00, 0xb0, 0xff, 0xe6, 0x64, 0xe8, 0x75, 0x00, 0xfb, 0xb8, 0x00,
0xbb, 0xcd, 0x1a, 0x66, 0x23, 0xc0, 0x75, 0x3b, 0x66, 0x81, 0xfb, 0x54,
0x43, 0x50, 0x41, 0x75, 0x32, 0x81, 0xf9, 0x02, 0x01, 0x72, 0x2c, 0x66,
0x68, 0x07, 0xbb, 0x00, 0x00, 0x66, 0x68, 0x00, 0x02, 0x00, 0x00, 0x66,
0x68, 0x08, 0x00, 0x00, 0x00, 0x66, 0x53, 0x66, 0x53, 0x66, 0x55, 0x66,
0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0x68, 0x00, 0x7c, 0x00, 0x00, 0x66,
0x61, 0x68, 0x00, 0x00, 0x07, 0xcd, 0x1a, 0x5a, 0x32, 0xf6, 0xea, 0x00,
0x7c, 0x00, 0x00, 0xcd, 0x18, 0xa0, 0xb7, 0x07, 0xeb, 0x08, 0xa0, 0xb6,
0x07, 0xeb, 0x03, 0xa0, 0xb5, 0x07, 0x32, 0xe4, 0x05, 0x00, 0x07, 0x8b,
0xf0, 0xac, 0x3c, 0x00, 0x74, 0x09, 0xbb, 0x07, 0x00, 0xb4, 0x0e, 0xcd,
0x10, 0xeb, 0xf2, 0xf4, 0xeb, 0xfd, 0x2b, 0xc9, 0xe4, 0x64, 0xeb, 0x00,
0x24, 0x02, 0xe0, 0xf8, 0x24, 0x02, 0xc3, 0x49, 0x6e, 0x76, 0x61, 0x6c,
0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72,
0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65,
0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65,
0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70,
0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x00, 0x00, 0x00, 0x63, 0x7b, 0x9a
};
/* Next four bytes used for Windows Disk Signature / Drive serial number */
/*
unsigned char mbr_win7_0x1b8[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
*/

39
src/inc/mbr_zero.h Normal file
View file

@ -0,0 +1,39 @@
/* First 440 bytes of a zeroed MBR (disk signature is excluded) */
unsigned char mbr_zero_0x0[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

674
src/license.h Normal file
View file

@ -0,0 +1,674 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* Licensing Data
* Copyright (c) 20111 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
const char* additional_copyrights =
"Icon by PC Unleashed:\r\n"
"http://pcunleashed.com\r\n"
"Freeware\r\n"
"\r\n"
"Boot record handling from ms-sys by Henrik Carlqvist:\r\n"
"http://ms-sys.sourceforge.net\r\n"
"GNU General Public License (GPL) v2 or later\r\n"
"\r\n"
"fmifs.dll usage based on Formatx by Mark Russinovich:\r\n"
"http://doc.sch130.nsc.ru/www.sysinternals.com/ntw2k/source/fmifs.shtml\r\n"
"http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/libs/fmifs\r\n"
"Public Domain\r\n"
"\r\n"
"Device enumeration based on TestUSBDriveEject.cpp by ahmd:\r\n"
"http://www.codeguru.com/forum/showthread.php?p=1951973\r\n"
"Public Domain\r\n"
"\r\n"
"Some FAT and time-conversion handling by ReactOS:\r\n"
"http://svn.reactos.org/svn/reactos/trunk/reactos\r\n"
"GNU General Public License (GPL) v3 compatible\r\n"
"\r\n"
"FS Type description from by GNU fdisk:\r\n"
"http://www.gnu.org/software/fdisk\r\n"
"GNU General Public License (GPL) v3 or later\r\n"
"\r\n"
"About and License dialogs inspired by WinSCP\r\n"
"Copyright (c) 2000-2011 Martin Prikryl\r\n"
"GNU General Public License (GPL) v3 or later\r\n"
"\r\n"
"\r\n"
"All other references are to be found in the source.\r\n";
const char* gplv3 =
" GNU GENERAL PUBLIC LICENSE\r\n"
" Version 3, 29 June 2007\r\n"
"\r\n"
" Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\r\n"
" Everyone is permitted to copy and distribute verbatim copies\r\n"
" of this license document, but changing it is not allowed.\r\n"
"\r\n"
" Preamble\r\n"
"\r\n"
" The GNU General Public License is a free, copyleft license for\r\n"
"software and other kinds of works.\r\n"
"\r\n"
" The licenses for most software and other practical works are designed\r\n"
"to take away your freedom to share and change the works. By contrast,\r\n"
"the GNU General Public License is intended to guarantee your freedom to\r\n"
"share and change all versions of a program--to make sure it remains free\r\n"
"software for all its users. We, the Free Software Foundation, use the\r\n"
"GNU General Public License for most of our software; it applies also to\r\n"
"any other work released this way by its authors. You can apply it to\r\n"
"your programs, too.\r\n"
"\r\n"
" When we speak of free software, we are referring to freedom, not\r\n"
"price. Our General Public Licenses are designed to make sure that you\r\n"
"have the freedom to distribute copies of free software (and charge for\r\n"
"them if you wish), that you receive source code or can get it if you\r\n"
"want it, that you can change the software or use pieces of it in new\r\n"
"free programs, and that you know you can do these things.\r\n"
"\r\n"
" To protect your rights, we need to prevent others from denying you\r\n"
"these rights or asking you to surrender the rights. Therefore, you have\r\n"
"certain responsibilities if you distribute copies of the software, or if\r\n"
"you modify it: responsibilities to respect the freedom of others.\r\n"
"\r\n"
" For example, if you distribute copies of such a program, whether\r\n"
"gratis or for a fee, you must pass on to the recipients the same\r\n"
"freedoms that you received. You must make sure that they, too, receive\r\n"
"or can get the source code. And you must show them these terms so they\r\n"
"know their rights.\r\n"
"\r\n"
" Developers that use the GNU GPL protect your rights with two steps:\r\n"
"(1) assert copyright on the software, and (2) offer you this License\r\n"
"giving you legal permission to copy, distribute and/or modify it.\r\n"
"\r\n"
" For the developers' and authors' protection, the GPL clearly explains\r\n"
"that there is no warranty for this free software. For both users' and\r\n"
"authors' sake, the GPL requires that modified versions be marked as\r\n"
"changed, so that their problems will not be attributed erroneously to\r\n"
"authors of previous versions.\r\n"
"\r\n"
" Some devices are designed to deny users access to install or run\r\n"
"modified versions of the software inside them, although the manufacturer\r\n"
"can do so. This is fundamentally incompatible with the aim of\r\n"
"protecting users' freedom to change the software. The systematic\r\n"
"pattern of such abuse occurs in the area of products for individuals to\r\n"
"use, which is precisely where it is most unacceptable. Therefore, we\r\n"
"have designed this version of the GPL to prohibit the practice for those\r\n"
"products. If such problems arise substantially in other domains, we\r\n"
"stand ready to extend this provision to those domains in future versions\r\n"
"of the GPL, as needed to protect the freedom of users.\r\n"
"\r\n"
" Finally, every program is threatened constantly by software patents.\r\n"
"States should not allow patents to restrict development and use of\r\n"
"software on general-purpose computers, but in those that do, we wish to\r\n"
"avoid the special danger that patents applied to a free program could\r\n"
"make it effectively proprietary. To prevent this, the GPL assures that\r\n"
"patents cannot be used to render the program non-free.\r\n"
"\r\n"
" The precise terms and conditions for copying, distribution and\r\n"
"modification follow.\r\n"
"\r\n"
" TERMS AND CONDITIONS\r\n"
"\r\n"
" 0. Definitions.\r\n"
"\r\n"
" \"This License\" refers to version 3 of the GNU General Public License.\r\n"
"\r\n"
" \"Copyright\" also means copyright-like laws that apply to other kinds of\r\n"
"works, such as semiconductor masks.\r\n"
"\r\n"
" \"The Program\" refers to any copyrightable work licensed under this\r\n"
"License. Each licensee is addressed as \"you\". \"Licensees\" and\r\n"
"\"recipients\" may be individuals or organizations.\r\n"
"\r\n"
" To \"modify\" a work means to copy from or adapt all or part of the work\r\n"
"in a fashion requiring copyright permission, other than the making of an\r\n"
"exact copy. The resulting work is called a \"modified version\" of the\r\n"
"earlier work or a work \"based on\" the earlier work.\r\n"
"\r\n"
" A \"covered work\" means either the unmodified Program or a work based\r\n"
"on the Program.\r\n"
"\r\n"
" To \"propagate\" a work means to do anything with it that, without\r\n"
"permission, would make you directly or secondarily liable for\r\n"
"infringement under applicable copyright law, except executing it on a\r\n"
"computer or modifying a private copy. Propagation includes copying,\r\n"
"distribution (with or without modification), making available to the\r\n"
"public, and in some countries other activities as well.\r\n"
"\r\n"
" To \"convey\" a work means any kind of propagation that enables other\r\n"
"parties to make or receive copies. Mere interaction with a user through\r\n"
"a computer network, with no transfer of a copy, is not conveying.\r\n"
"\r\n"
" An interactive user interface displays \"Appropriate Legal Notices\"\r\n"
"to the extent that it includes a convenient and prominently visible\r\n"
"feature that (1) displays an appropriate copyright notice, and (2)\r\n"
"tells the user that there is no warranty for the work (except to the\r\n"
"extent that warranties are provided), that licensees may convey the\r\n"
"work under this License, and how to view a copy of this License. If\r\n"
"the interface presents a list of user commands or options, such as a\r\n"
"menu, a prominent item in the list meets this criterion.\r\n"
"\r\n"
" 1. Source Code.\r\n"
"\r\n"
" The \"source code\" for a work means the preferred form of the work\r\n"
"for making modifications to it. \"Object code\" means any non-source\r\n"
"form of a work.\r\n"
"\r\n"
" A \"Standard Interface\" means an interface that either is an official\r\n"
"standard defined by a recognized standards body, or, in the case of\r\n"
"interfaces specified for a particular programming language, one that\r\n"
"is widely used among developers working in that language.\r\n"
"\r\n"
" The \"System Libraries\" of an executable work include anything, other\r\n"
"than the work as a whole, that (a) is included in the normal form of\r\n"
"packaging a Major Component, but which is not part of that Major\r\n"
"Component, and (b) serves only to enable use of the work with that\r\n"
"Major Component, or to implement a Standard Interface for which an\r\n"
"implementation is available to the public in source code form. A\r\n"
"\"Major Component\", in this context, means a major essential component\r\n"
"(kernel, window system, and so on) of the specific operating system\r\n"
"(if any) on which the executable work runs, or a compiler used to\r\n"
"produce the work, or an object code interpreter used to run it.\r\n"
"\r\n"
" The \"Corresponding Source\" for a work in object code form means all\r\n"
"the source code needed to generate, install, and (for an executable\r\n"
"work) run the object code and to modify the work, including scripts to\r\n"
"control those activities. However, it does not include the work's\r\n"
"System Libraries, or general-purpose tools or generally available free\r\n"
"programs which are used unmodified in performing those activities but\r\n"
"which are not part of the work. For example, Corresponding Source\r\n"
"includes interface definition files associated with source files for\r\n"
"the work, and the source code for shared libraries and dynamically\r\n"
"linked subprograms that the work is specifically designed to require,\r\n"
"such as by intimate data communication or control flow between those\r\n"
"subprograms and other parts of the work.\r\n"
"\r\n"
" The Corresponding Source need not include anything that users\r\n"
"can regenerate automatically from other parts of the Corresponding\r\n"
"Source.\r\n"
"\r\n"
" The Corresponding Source for a work in source code form is that\r\n"
"same work.\r\n"
"\r\n"
" 2. Basic Permissions.\r\n"
"\r\n"
" All rights granted under this License are granted for the term of\r\n"
"copyright on the Program, and are irrevocable provided the stated\r\n"
"conditions are met. This License explicitly affirms your unlimited\r\n"
"permission to run the unmodified Program. The output from running a\r\n"
"covered work is covered by this License only if the output, given its\r\n"
"content, constitutes a covered work. This License acknowledges your\r\n"
"rights of fair use or other equivalent, as provided by copyright law.\r\n"
"\r\n"
" You may make, run and propagate covered works that you do not\r\n"
"convey, without conditions so long as your license otherwise remains\r\n"
"in force. You may convey covered works to others for the sole purpose\r\n"
"of having them make modifications exclusively for you, or provide you\r\n"
"with facilities for running those works, provided that you comply with\r\n"
"the terms of this License in conveying all material for which you do\r\n"
"not control copyright. Those thus making or running the covered works\r\n"
"for you must do so exclusively on your behalf, under your direction\r\n"
"and control, on terms that prohibit them from making any copies of\r\n"
"your copyrighted material outside their relationship with you.\r\n"
"\r\n"
" Conveying under any other circumstances is permitted solely under\r\n"
"the conditions stated below. Sublicensing is not allowed; section 10\r\n"
"makes it unnecessary.\r\n"
"\r\n"
" 3. Protecting Users' Legal Rights From Anti-Circumvention Law.\r\n"
"\r\n"
" No covered work shall be deemed part of an effective technological\r\n"
"measure under any applicable law fulfilling obligations under article\r\n"
"11 of the WIPO copyright treaty adopted on 20 December 1996, or\r\n"
"similar laws prohibiting or restricting circumvention of such\r\n"
"measures.\r\n"
"\r\n"
" When you convey a covered work, you waive any legal power to forbid\r\n"
"circumvention of technological measures to the extent such circumvention\r\n"
"is effected by exercising rights under this License with respect to\r\n"
"the covered work, and you disclaim any intention to limit operation or\r\n"
"modification of the work as a means of enforcing, against the work's\r\n"
"users, your or third parties' legal rights to forbid circumvention of\r\n"
"technological measures.\r\n"
"\r\n"
" 4. Conveying Verbatim Copies.\r\n"
"\r\n"
" You may convey verbatim copies of the Program's source code as you\r\n"
"receive it, in any medium, provided that you conspicuously and\r\n"
"appropriately publish on each copy an appropriate copyright notice;\r\n"
"keep intact all notices stating that this License and any\r\n"
"non-permissive terms added in accord with section 7 apply to the code;\r\n"
"keep intact all notices of the absence of any warranty; and give all\r\n"
"recipients a copy of this License along with the Program.\r\n"
"\r\n"
" You may charge any price or no price for each copy that you convey,\r\n"
"and you may offer support or warranty protection for a fee.\r\n"
"\r\n"
" 5. Conveying Modified Source Versions.\r\n"
"\r\n"
" You may convey a work based on the Program, or the modifications to\r\n"
"produce it from the Program, in the form of source code under the\r\n"
"terms of section 4, provided that you also meet all of these conditions:\r\n"
"\r\n"
" a) The work must carry prominent notices stating that you modified\r\n"
" it, and giving a relevant date.\r\n"
"\r\n"
" b) The work must carry prominent notices stating that it is\r\n"
" released under this License and any conditions added under section\r\n"
" 7. This requirement modifies the requirement in section 4 to\r\n"
" \"keep intact all notices\".\r\n"
"\r\n"
" c) You must license the entire work, as a whole, under this\r\n"
" License to anyone who comes into possession of a copy. This\r\n"
" License will therefore apply, along with any applicable section 7\r\n"
" additional terms, to the whole of the work, and all its parts,\r\n"
" regardless of how they are packaged. This License gives no\r\n"
" permission to license the work in any other way, but it does not\r\n"
" invalidate such permission if you have separately received it.\r\n"
"\r\n"
" d) If the work has interactive user interfaces, each must display\r\n"
" Appropriate Legal Notices; however, if the Program has interactive\r\n"
" interfaces that do not display Appropriate Legal Notices, your\r\n"
" work need not make them do so.\r\n"
"\r\n"
" A compilation of a covered work with other separate and independent\r\n"
"works, which are not by their nature extensions of the covered work,\r\n"
"and which are not combined with it such as to form a larger program,\r\n"
"in or on a volume of a storage or distribution medium, is called an\r\n"
"\"aggregate\" if the compilation and its resulting copyright are not\r\n"
"used to limit the access or legal rights of the compilation's users\r\n"
"beyond what the individual works permit. Inclusion of a covered work\r\n"
"in an aggregate does not cause this License to apply to the other\r\n"
"parts of the aggregate.\r\n"
"\r\n"
" 6. Conveying Non-Source Forms.\r\n"
"\r\n"
" You may convey a covered work in object code form under the terms\r\n"
"of sections 4 and 5, provided that you also convey the\r\n"
"machine-readable Corresponding Source under the terms of this License,\r\n"
"in one of these ways:\r\n"
"\r\n"
" a) Convey the object code in, or embodied in, a physical product\r\n"
" (including a physical distribution medium), accompanied by the\r\n"
" Corresponding Source fixed on a durable physical medium\r\n"
" customarily used for software interchange.\r\n"
"\r\n"
" b) Convey the object code in, or embodied in, a physical product\r\n"
" (including a physical distribution medium), accompanied by a\r\n"
" written offer, valid for at least three years and valid for as\r\n"
" long as you offer spare parts or customer support for that product\r\n"
" model, to give anyone who possesses the object code either (1) a\r\n"
" copy of the Corresponding Source for all the software in the\r\n"
" product that is covered by this License, on a durable physical\r\n"
" medium customarily used for software interchange, for a price no\r\n"
" more than your reasonable cost of physically performing this\r\n"
" conveying of source, or (2) access to copy the\r\n"
" Corresponding Source from a network server at no charge.\r\n"
"\r\n"
" c) Convey individual copies of the object code with a copy of the\r\n"
" written offer to provide the Corresponding Source. This\r\n"
" alternative is allowed only occasionally and noncommercially, and\r\n"
" only if you received the object code with such an offer, in accord\r\n"
" with subsection 6b.\r\n"
"\r\n"
" d) Convey the object code by offering access from a designated\r\n"
" place (gratis or for a charge), and offer equivalent access to the\r\n"
" Corresponding Source in the same way through the same place at no\r\n"
" further charge. You need not require recipients to copy the\r\n"
" Corresponding Source along with the object code. If the place to\r\n"
" copy the object code is a network server, the Corresponding Source\r\n"
" may be on a different server (operated by you or a third party)\r\n"
" that supports equivalent copying facilities, provided you maintain\r\n"
" clear directions next to the object code saying where to find the\r\n"
" Corresponding Source. Regardless of what server hosts the\r\n"
" Corresponding Source, you remain obligated to ensure that it is\r\n"
" available for as long as needed to satisfy these requirements.\r\n"
"\r\n"
" e) Convey the object code using peer-to-peer transmission, provided\r\n"
" you inform other peers where the object code and Corresponding\r\n"
" Source of the work are being offered to the general public at no\r\n"
" charge under subsection 6d.\r\n"
"\r\n"
" A separable portion of the object code, whose source code is excluded\r\n"
"from the Corresponding Source as a System Library, need not be\r\n"
"included in conveying the object code work.\r\n"
"\r\n"
" A \"User Product\" is either (1) a \"consumer product\", which means any\r\n"
"tangible personal property which is normally used for personal, family,\r\n"
"or household purposes, or (2) anything designed or sold for incorporation\r\n"
"into a dwelling. In determining whether a product is a consumer product,\r\n"
"doubtful cases shall be resolved in favor of coverage. For a particular\r\n"
"product received by a particular user, \"normally used\" refers to a\r\n"
"typical or common use of that class of product, regardless of the status\r\n"
"of the particular user or of the way in which the particular user\r\n"
"actually uses, or expects or is expected to use, the product. A product\r\n"
"is a consumer product regardless of whether the product has substantial\r\n"
"commercial, industrial or non-consumer uses, unless such uses represent\r\n"
"the only significant mode of use of the product.\r\n"
"\r\n"
" \"Installation Information\" for a User Product means any methods,\r\n"
"procedures, authorization keys, or other information required to install\r\n"
"and execute modified versions of a covered work in that User Product from\r\n"
"a modified version of its Corresponding Source. The information must\r\n"
"suffice to ensure that the continued functioning of the modified object\r\n"
"code is in no case prevented or interfered with solely because\r\n"
"modification has been made.\r\n"
"\r\n"
" If you convey an object code work under this section in, or with, or\r\n"
"specifically for use in, a User Product, and the conveying occurs as\r\n"
"part of a transaction in which the right of possession and use of the\r\n"
"User Product is transferred to the recipient in perpetuity or for a\r\n"
"fixed term (regardless of how the transaction is characterized), the\r\n"
"Corresponding Source conveyed under this section must be accompanied\r\n"
"by the Installation Information. But this requirement does not apply\r\n"
"if neither you nor any third party retains the ability to install\r\n"
"modified object code on the User Product (for example, the work has\r\n"
"been installed in ROM).\r\n"
"\r\n"
" The requirement to provide Installation Information does not include a\r\n"
"requirement to continue to provide support service, warranty, or updates\r\n"
"for a work that has been modified or installed by the recipient, or for\r\n"
"the User Product in which it has been modified or installed. Access to a\r\n"
"network may be denied when the modification itself materially and\r\n"
"adversely affects the operation of the network or violates the rules and\r\n"
"protocols for communication across the network.\r\n"
"\r\n"
" Corresponding Source conveyed, and Installation Information provided,\r\n"
"in accord with this section must be in a format that is publicly\r\n"
"documented (and with an implementation available to the public in\r\n"
"source code form), and must require no special password or key for\r\n"
"unpacking, reading or copying.\r\n"
"\r\n"
" 7. Additional Terms.\r\n"
"\r\n"
" \"Additional permissions\" are terms that supplement the terms of this\r\n"
"License by making exceptions from one or more of its conditions.\r\n"
"Additional permissions that are applicable to the entire Program shall\r\n"
"be treated as though they were included in this License, to the extent\r\n"
"that they are valid under applicable law. If additional permissions\r\n"
"apply only to part of the Program, that part may be used separately\r\n"
"under those permissions, but the entire Program remains governed by\r\n"
"this License without regard to the additional permissions.\r\n"
"\r\n"
" When you convey a copy of a covered work, you may at your option\r\n"
"remove any additional permissions from that copy, or from any part of\r\n"
"it. (Additional permissions may be written to require their own\r\n"
"removal in certain cases when you modify the work.) You may place\r\n"
"additional permissions on material, added by you to a covered work,\r\n"
"for which you have or can give appropriate copyright permission.\r\n"
"\r\n"
" Notwithstanding any other provision of this License, for material you\r\n"
"add to a covered work, you may (if authorized by the copyright holders of\r\n"
"that material) supplement the terms of this License with terms:\r\n"
"\r\n"
" a) Disclaiming warranty or limiting liability differently from the\r\n"
" terms of sections 15 and 16 of this License; or\r\n"
"\r\n"
" b) Requiring preservation of specified reasonable legal notices or\r\n"
" author attributions in that material or in the Appropriate Legal\r\n"
" Notices displayed by works containing it; or\r\n"
"\r\n"
" c) Prohibiting misrepresentation of the origin of that material, or\r\n"
" requiring that modified versions of such material be marked in\r\n"
" reasonable ways as different from the original version; or\r\n"
"\r\n"
" d) Limiting the use for publicity purposes of names of licensors or\r\n"
" authors of the material; or\r\n"
"\r\n"
" e) Declining to grant rights under trademark law for use of some\r\n"
" trade names, trademarks, or service marks; or\r\n"
"\r\n"
" f) Requiring indemnification of licensors and authors of that\r\n"
" material by anyone who conveys the material (or modified versions of\r\n"
" it) with contractual assumptions of liability to the recipient, for\r\n"
" any liability that these contractual assumptions directly impose on\r\n"
" those licensors and authors.\r\n"
"\r\n"
" All other non-permissive additional terms are considered \"further\r\n"
"restrictions\" within the meaning of section 10. If the Program as you\r\n"
"received it, or any part of it, contains a notice stating that it is\r\n"
"governed by this License along with a term that is a further\r\n"
"restriction, you may remove that term. If a license document contains\r\n"
"a further restriction but permits relicensing or conveying under this\r\n"
"License, you may add to a covered work material governed by the terms\r\n"
"of that license document, provided that the further restriction does\r\n"
"not survive such relicensing or conveying.\r\n"
"\r\n"
" If you add terms to a covered work in accord with this section, you\r\n"
"must place, in the relevant source files, a statement of the\r\n"
"additional terms that apply to those files, or a notice indicating\r\n"
"where to find the applicable terms.\r\n"
"\r\n"
" Additional terms, permissive or non-permissive, may be stated in the\r\n"
"form of a separately written license, or stated as exceptions;\r\n"
"the above requirements apply either way.\r\n"
"\r\n"
" 8. Termination.\r\n"
"\r\n"
" You may not propagate or modify a covered work except as expressly\r\n"
"provided under this License. Any attempt otherwise to propagate or\r\n"
"modify it is void, and will automatically terminate your rights under\r\n"
"this License (including any patent licenses granted under the third\r\n"
"paragraph of section 11).\r\n"
"\r\n"
" However, if you cease all violation of this License, then your\r\n"
"license from a particular copyright holder is reinstated (a)\r\n"
"provisionally, unless and until the copyright holder explicitly and\r\n"
"finally terminates your license, and (b) permanently, if the copyright\r\n"
"holder fails to notify you of the violation by some reasonable means\r\n"
"prior to 60 days after the cessation.\r\n"
"\r\n"
" Moreover, your license from a particular copyright holder is\r\n"
"reinstated permanently if the copyright holder notifies you of the\r\n"
"violation by some reasonable means, this is the first time you have\r\n"
"received notice of violation of this License (for any work) from that\r\n"
"copyright holder, and you cure the violation prior to 30 days after\r\n"
"your receipt of the notice.\r\n"
"\r\n"
" Termination of your rights under this section does not terminate the\r\n"
"licenses of parties who have received copies or rights from you under\r\n"
"this License. If your rights have been terminated and not permanently\r\n"
"reinstated, you do not qualify to receive new licenses for the same\r\n"
"material under section 10.\r\n"
"\r\n"
" 9. Acceptance Not Required for Having Copies.\r\n"
"\r\n"
" You are not required to accept this License in order to receive or\r\n"
"run a copy of the Program. Ancillary propagation of a covered work\r\n"
"occurring solely as a consequence of using peer-to-peer transmission\r\n"
"to receive a copy likewise does not require acceptance. However,\r\n"
"nothing other than this License grants you permission to propagate or\r\n"
"modify any covered work. These actions infringe copyright if you do\r\n"
"not accept this License. Therefore, by modifying or propagating a\r\n"
"covered work, you indicate your acceptance of this License to do so.\r\n"
"\r\n"
" 10. Automatic Licensing of Downstream Recipients.\r\n"
"\r\n"
" Each time you convey a covered work, the recipient automatically\r\n"
"receives a license from the original licensors, to run, modify and\r\n"
"propagate that work, subject to this License. You are not responsible\r\n"
"for enforcing compliance by third parties with this License.\r\n"
"\r\n"
" An \"entity transaction\" is a transaction transferring control of an\r\n"
"organization, or substantially all assets of one, or subdividing an\r\n"
"organization, or merging organizations. If propagation of a covered\r\n"
"work results from an entity transaction, each party to that\r\n"
"transaction who receives a copy of the work also receives whatever\r\n"
"licenses to the work the party's predecessor in interest had or could\r\n"
"give under the previous paragraph, plus a right to possession of the\r\n"
"Corresponding Source of the work from the predecessor in interest, if\r\n"
"the predecessor has it or can get it with reasonable efforts.\r\n"
"\r\n"
" You may not impose any further restrictions on the exercise of the\r\n"
"rights granted or affirmed under this License. For example, you may\r\n"
"not impose a license fee, royalty, or other charge for exercise of\r\n"
"rights granted under this License, and you may not initiate litigation\r\n"
"(including a cross-claim or counterclaim in a lawsuit) alleging that\r\n"
"any patent claim is infringed by making, using, selling, offering for\r\n"
"sale, or importing the Program or any portion of it.\r\n"
"\r\n"
" 11. Patents.\r\n"
"\r\n"
" A \"contributor\" is a copyright holder who authorizes use under this\r\n"
"License of the Program or a work on which the Program is based. The\r\n"
"work thus licensed is called the contributor's \"contributor version\".\r\n"
"\r\n"
" A contributor's \"essential patent claims\" are all patent claims\r\n"
"owned or controlled by the contributor, whether already acquired or\r\n"
"hereafter acquired, that would be infringed by some manner, permitted\r\n"
"by this License, of making, using, or selling its contributor version,\r\n"
"but do not include claims that would be infringed only as a\r\n"
"consequence of further modification of the contributor version. For\r\n"
"purposes of this definition, \"control\" includes the right to grant\r\n"
"patent sublicenses in a manner consistent with the requirements of\r\n"
"this License.\r\n"
"\r\n"
" Each contributor grants you a non-exclusive, worldwide, royalty-free\r\n"
"patent license under the contributor's essential patent claims, to\r\n"
"make, use, sell, offer for sale, import and otherwise run, modify and\r\n"
"propagate the contents of its contributor version.\r\n"
"\r\n"
" In the following three paragraphs, a \"patent license\" is any express\r\n"
"agreement or commitment, however denominated, not to enforce a patent\r\n"
"(such as an express permission to practice a patent or covenant not to\r\n"
"sue for patent infringement). To \"grant\" such a patent license to a\r\n"
"party means to make such an agreement or commitment not to enforce a\r\n"
"patent against the party.\r\n"
"\r\n"
" If you convey a covered work, knowingly relying on a patent license,\r\n"
"and the Corresponding Source of the work is not available for anyone\r\n"
"to copy, free of charge and under the terms of this License, through a\r\n"
"publicly available network server or other readily accessible means,\r\n"
"then you must either (1) cause the Corresponding Source to be so\r\n"
"available, or (2) arrange to deprive yourself of the benefit of the\r\n"
"patent license for this particular work, or (3) arrange, in a manner\r\n"
"consistent with the requirements of this License, to extend the patent\r\n"
"license to downstream recipients. \"Knowingly relying\" means you have\r\n"
"actual knowledge that, but for the patent license, your conveying the\r\n"
"covered work in a country, or your recipient's use of the covered work\r\n"
"in a country, would infringe one or more identifiable patents in that\r\n"
"country that you have reason to believe are valid.\r\n"
"\r\n"
" If, pursuant to or in connection with a single transaction or\r\n"
"arrangement, you convey, or propagate by procuring conveyance of, a\r\n"
"covered work, and grant a patent license to some of the parties\r\n"
"receiving the covered work authorizing them to use, propagate, modify\r\n"
"or convey a specific copy of the covered work, then the patent license\r\n"
"you grant is automatically extended to all recipients of the covered\r\n"
"work and works based on it.\r\n"
"\r\n"
" A patent license is \"discriminatory\" if it does not include within\r\n"
"the scope of its coverage, prohibits the exercise of, or is\r\n"
"conditioned on the non-exercise of one or more of the rights that are\r\n"
"specifically granted under this License. You may not convey a covered\r\n"
"work if you are a party to an arrangement with a third party that is\r\n"
"in the business of distributing software, under which you make payment\r\n"
"to the third party based on the extent of your activity of conveying\r\n"
"the work, and under which the third party grants, to any of the\r\n"
"parties who would receive the covered work from you, a discriminatory\r\n"
"patent license (a) in connection with copies of the covered work\r\n"
"conveyed by you (or copies made from those copies), or (b) primarily\r\n"
"for and in connection with specific products or compilations that\r\n"
"contain the covered work, unless you entered into that arrangement,\r\n"
"or that patent license was granted, prior to 28 March 2007.\r\n"
"\r\n"
" Nothing in this License shall be construed as excluding or limiting\r\n"
"any implied license or other defenses to infringement that may\r\n"
"otherwise be available to you under applicable patent law.\r\n"
"\r\n"
" 12. No Surrender of Others' Freedom.\r\n"
"\r\n"
" If conditions are imposed on you (whether by court order, agreement or\r\n"
"otherwise) that contradict the conditions of this License, they do not\r\n"
"excuse you from the conditions of this License. If you cannot convey a\r\n"
"covered work so as to satisfy simultaneously your obligations under this\r\n"
"License and any other pertinent obligations, then as a consequence you may\r\n"
"not convey it at all. For example, if you agree to terms that obligate you\r\n"
"to collect a royalty for further conveying from those to whom you convey\r\n"
"the Program, the only way you could satisfy both those terms and this\r\n"
"License would be to refrain entirely from conveying the Program.\r\n"
"\r\n"
" 13. Use with the GNU Affero General Public License.\r\n"
"\r\n"
" Notwithstanding any other provision of this License, you have\r\n"
"permission to link or combine any covered work with a work licensed\r\n"
"under version 3 of the GNU Affero General Public License into a single\r\n"
"combined work, and to convey the resulting work. The terms of this\r\n"
"License will continue to apply to the part which is the covered work,\r\n"
"but the special requirements of the GNU Affero General Public License,\r\n"
"section 13, concerning interaction through a network will apply to the\r\n"
"combination as such.\r\n"
"\r\n"
" 14. Revised Versions of this License.\r\n"
"\r\n"
" The Free Software Foundation may publish revised and/or new versions of\r\n"
"the GNU General Public License from time to time. Such new versions will\r\n"
"be similar in spirit to the present version, but may differ in detail to\r\n"
"address new problems or concerns.\r\n"
"\r\n"
" Each version is given a distinguishing version number. If the\r\n"
"Program specifies that a certain numbered version of the GNU General\r\n"
"Public License \"or any later version\" applies to it, you have the\r\n"
"option of following the terms and conditions either of that numbered\r\n"
"version or of any later version published by the Free Software\r\n"
"Foundation. If the Program does not specify a version number of the\r\n"
"GNU General Public License, you may choose any version ever published\r\n"
"by the Free Software Foundation.\r\n"
"\r\n"
" If the Program specifies that a proxy can decide which future\r\n"
"versions of the GNU General Public License can be used, that proxy's\r\n"
"public statement of acceptance of a version permanently authorizes you\r\n"
"to choose that version for the Program.\r\n"
"\r\n"
" Later license versions may give you additional or different\r\n"
"permissions. However, no additional obligations are imposed on any\r\n"
"author or copyright holder as a result of your choosing to follow a\r\n"
"later version.\r\n"
"\r\n"
" 15. Disclaimer of Warranty.\r\n"
"\r\n"
" THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\r\n"
"APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\r\n"
"HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\r\n"
"OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\r\n"
"THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r\n"
"PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\r\n"
"IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\r\n"
"ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r\n"
"\r\n"
" 16. Limitation of Liability.\r\n"
"\r\n"
" IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\r\n"
"WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\r\n"
"THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\r\n"
"GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\r\n"
"USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\r\n"
"DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\r\n"
"PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\r\n"
"EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\r\n"
"SUCH DAMAGES.\r\n"
"\r\n"
" 17. Interpretation of Sections 15 and 16.\r\n"
"\r\n"
" If the disclaimer of warranty and limitation of liability provided\r\n"
"above cannot be given local legal effect according to their terms,\r\n"
"reviewing courts shall apply local law that most closely approximates\r\n"
"an absolute waiver of all civil liability in connection with the\r\n"
"Program, unless a warranty or assumption of liability accompanies a\r\n"
"copy of the Program in return for a fee.\r\n"
"\r\n"
" END OF TERMS AND CONDITIONS";

53
src/mkf Normal file
View file

@ -0,0 +1,53 @@
# Rufus STANDALONE Makefile - invoke with "make -f mf"
# This file is part of the Rufus project.
#
# Copyright (c) 2011 Pete Batard <pbatard@akeo.ie>
#
# This program 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 program 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 program; if not, see <http://www.gnu.org/licenses/>.
#
OBJECTS = fat12.o fat16.o fat32.o br.o file.o drive.o msdos.o format.o stdio.o stdlg.o rufus.o
TARGET = rufus
CC = gcc
RC = windres
STRIP = strip
CFLAGS = -DWINVER=0x501 -D_WIN32_IE=0x501 -I./inc -std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow
LDFLAGS = -O2 -Wall -Wl,--subsystem,windows
LIBS = -lsetupapi -lole32 -lgdi32
.PHONY: all clean
all: $(TARGET)
$(TARGET): $(OBJECTS) $(TARGET)_rc.o
@echo "[CCLD] $@"
@$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(TARGET)_rc.o $(LIBS)
%.o: %.c
@echo "[CC] $@"
@$(CC) -c -o $*.o $(CFLAGS) $<
%_rc.o: %.rc
@echo "[RC] $@"
@$(RC) -i $< -o $@
clean:
rm -f *.exe *.o
# This step produces the UPX compressed and signed release that is made available for public download
release: $(TARGET)
@$(STRIP) $(TARGET).exe
@upx $(TARGET).exe
@cmd.exe /k _sign.bat rufus.exe

584
src/msapi_utf8.h Normal file
View file

@ -0,0 +1,584 @@
/*
* MSAPI_UTF8: Common API calls using UTF-8 strings
* Compensating for what Microsoft should have done a long long time ago.
*
* Copyright (c) 2010-2011 Pete Batard <pete@akeo.ie>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <windows.h>
#include <stdio.h>
#include <shlobj.h>
#include <commdlg.h>
#include <shellapi.h>
#include <setupapi.h>
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define wchar_to_utf8_no_alloc(wsrc, dest, dest_size) \
WideCharToMultiByte(CP_UTF8, 0, wsrc, -1, dest, dest_size, NULL, NULL)
#define utf8_to_wchar_no_alloc(src, wdest, wdest_size) \
MultiByteToWideChar(CP_UTF8, 0, src, -1, wdest, wdest_size)
#define Edit_ReplaceSelU(hCtrl, str) ((void)SendMessageLU(hCtrl, EM_REPLACESEL, (WPARAM)FALSE, str))
#define ComboBox_AddStringU(hCtrl, str) ((int)(DWORD)SendMessageLU(hCtrl, CB_ADDSTRING, (WPARAM)FALSE, str))
#define ComboBox_GetTextU(hCtrl, str, max_str) GetWindowTextU(hCtrl, str, max_str)
#define GetSaveFileNameU(p) GetOpenSaveFileNameU(p, TRUE)
#define GetOpenFileNameU(p) GetOpenSaveFileNameU(p, FALSE)
#define ListView_SetItemTextU(hwndLV,i,iSubItem_,pszText_) { LVITEMW _ms_wlvi; _ms_wlvi.iSubItem = iSubItem_; \
_ms_wlvi.pszText = utf8_to_wchar(pszText_); \
SNDMSG((hwndLV),LVM_SETITEMTEXTW,(WPARAM)(i),(LPARAM)&_ms_wlvi); sfree(_ms_wlvi.pszText);}
#define sfree(p) do {if (p != NULL) {free((void*)(p)); p = NULL;}} while(0)
#define wconvert(p) wchar_t* w ## p = utf8_to_wchar(p)
#define walloc(p, size) wchar_t* w ## p = (wchar_t*)calloc(size, sizeof(wchar_t))
#define wfree(p) sfree(w ## p)
/*
* Converts an UTF-16 string to UTF8 (allocate returned string)
* Returns NULL on error
*/
static __inline char* wchar_to_utf8(const wchar_t* wstr)
{
int size = 0;
char* str = NULL;
// Find out the size we need to allocate for our converted string
size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
if (size <= 1) // An empty string would be size 1
return NULL;
if ((str = (char*)calloc(size, 1)) == NULL)
return NULL;
if (wchar_to_utf8_no_alloc(wstr, str, size) != size) {
sfree(str);
return NULL;
}
return str;
}
/*
* Converts an UTF8 string to UTF-16 (allocate returned string)
* Returns NULL on error
*/
static __inline wchar_t* utf8_to_wchar(const char* str)
{
int size = 0;
wchar_t* wstr = NULL;
// Find out the size we need to allocate for our converted string
size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
if (size <= 1) // An empty string would be size 1
return NULL;
if ((wstr = (wchar_t*)calloc(size, sizeof(wchar_t))) == NULL)
return NULL;
if (utf8_to_wchar_no_alloc(str, wstr, size) != size) {
sfree(wstr);
return NULL;
}
return wstr;
}
static __inline DWORD FormatMessageU(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId,
DWORD dwLanguageId, char* lpBuffer, DWORD nSize, va_list *Arguments)
{
DWORD ret = 0, err = ERROR_INVALID_DATA;
walloc(lpBuffer, nSize);
ret = FormatMessageW(dwFlags, lpSource, dwMessageId, dwLanguageId, wlpBuffer, nSize, Arguments);
err = GetLastError();
if ((ret != 0) && ((ret = wchar_to_utf8_no_alloc(wlpBuffer, lpBuffer, nSize)) == 0)) {
err = GetLastError();
ret = 0;
}
wfree(lpBuffer);
SetLastError(err);
return ret;
}
// SendMessage, with LPARAM as UTF-8 string
static __inline LRESULT SendMessageLU(HWND hWnd, UINT Msg, WPARAM wParam, const char* lParam)
{
LRESULT ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
wconvert(lParam);
ret = SendMessageW(hWnd, Msg, wParam, (LPARAM)wlParam);
err = GetLastError();
wfree(lParam);
SetLastError(err);
return ret;
}
static __inline BOOL SHGetPathFromIDListU(LPCITEMIDLIST pidl, char* pszPath)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
walloc(pszPath, MAX_PATH);
ret = SHGetPathFromIDListW(pidl, wpszPath);
err = GetLastError();
if ((ret) && (wchar_to_utf8_no_alloc(wpszPath, pszPath, MAX_PATH) == 0)) {
err = GetLastError();
ret = FALSE;
}
wfree(pszPath);
SetLastError(err);
return ret;
}
static __inline HWND CreateWindowU(char* lpClassName, char* lpWindowName,
DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent,
HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
HWND ret = NULL;
DWORD err = ERROR_INVALID_DATA;
wconvert(lpClassName);
wconvert(lpWindowName);
ret = CreateWindowW(wlpClassName, wlpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
err = GetLastError();
wfree(lpClassName);
wfree(lpWindowName);
SetLastError(err);
return ret;
}
static __inline int GetWindowTextU(HWND hWnd, char* lpString, int nMaxCount)
{
int ret = 0;
DWORD err = ERROR_INVALID_DATA;
walloc(lpString, nMaxCount);
ret = GetWindowTextW(hWnd, wlpString, nMaxCount);
err = GetLastError();
if ( (ret != 0) && ((ret = wchar_to_utf8_no_alloc(wlpString, lpString, nMaxCount)) == 0) ) {
err = GetLastError();
}
wfree(lpString);
SetLastError(err);
return ret;
}
static __inline BOOL SetWindowTextU(HWND hWnd, const char* lpString)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
wconvert(lpString);
ret = SetWindowTextW(hWnd, wlpString);
err = GetLastError();
wfree(lpString);
SetLastError(err);
return ret;
}
static __inline int GetWindowTextLengthU(HWND hWnd)
{
int ret = 0;
DWORD err = ERROR_INVALID_DATA;
wchar_t* wbuf = NULL;
char* buf = NULL;
ret = GetWindowTextLengthW(hWnd);
err = GetLastError();
if (ret == 0) goto out;
wbuf = calloc(ret, sizeof(wchar_t));
err = GetLastError();
if (wbuf == NULL) {
err = ERROR_OUTOFMEMORY; ret = 0; goto out;
}
ret = GetWindowTextW(hWnd, wbuf, ret);
err = GetLastError();
if (ret == 0) goto out;
buf = wchar_to_utf8(wbuf);
err = GetLastError();
if (buf == NULL) {
err = ERROR_OUTOFMEMORY; ret = 0; goto out;
}
ret = (int)strlen(buf) + 2; // GetDlgItemText seems to add a character
err = GetLastError();
out:
sfree(wbuf);
sfree(buf);
SetLastError(err);
return ret;
}
static __inline UINT GetDlgItemTextU(HWND hDlg, int nIDDlgItem, char* lpString, int nMaxCount)
{
UINT ret = 0;
DWORD err = ERROR_INVALID_DATA;
walloc(lpString, nMaxCount);
ret = GetDlgItemTextW(hDlg, nIDDlgItem, wlpString, nMaxCount);
err = GetLastError();
if ((ret != 0) && ((ret = wchar_to_utf8_no_alloc(wlpString, lpString, nMaxCount)) == 0)) {
err = GetLastError();
}
wfree(lpString);
SetLastError(err);
return ret;
}
static __inline BOOL SetDlgItemTextU(HWND hDlg, int nIDDlgItem, const char* lpString)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
wconvert(lpString);
ret = SetDlgItemTextW(hDlg, nIDDlgItem, wlpString);
err = GetLastError();
wfree(lpString);
SetLastError(err);
return ret;
}
static __inline int ComboBox_GetLBTextU(HWND hCtrl, int index, char* lpString)
{
int size;
DWORD err = ERROR_INVALID_DATA;
wchar_t* wlpString;
if (lpString == NULL)
return CB_ERR;
size = (int)SendMessageW(hCtrl, CB_GETLBTEXTLEN, (WPARAM)index, (LPARAM)0);
if (size < 0)
return size;
wlpString = (wchar_t*)calloc(size+1, sizeof(wchar_t));
size = (int)SendMessageW(hCtrl, CB_GETLBTEXT, (WPARAM)index, (LPARAM)wlpString);
err = GetLastError();
if (size > 0)
wchar_to_utf8_no_alloc(wlpString, lpString, size+1);
wfree(lpString);
SetLastError(err);
return size;
}
static __inline HANDLE CreateFileU(const char* lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
HANDLE ret = INVALID_HANDLE_VALUE;
DWORD err = ERROR_INVALID_DATA;
wconvert(lpFileName);
ret = CreateFileW(wlpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
err = GetLastError();
wfree(lpFileName);
SetLastError(err);
return ret;
}
static __inline BOOL DeleteFileU(const char* lpFileName)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
wconvert(lpFileName);
ret = DeleteFileW(wlpFileName);
err = GetLastError();
wfree(lpFileName);
SetLastError(err);
return ret;
}
// This function differs from regular GetTextExtentPoint in that it uses a zero terminated string
static __inline BOOL GetTextExtentPointU(HDC hdc, const char* lpString, LPSIZE lpSize)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
wconvert(lpString);
ret = GetTextExtentPointW(hdc, wlpString, (int)wcslen(wlpString)+1, lpSize);
err = GetLastError();
wfree(lpString);
SetLastError(err);
return ret;
}
static __inline DWORD GetCurrentDirectoryU(DWORD nBufferLength, char* lpBuffer)
{
DWORD ret = 0, err = ERROR_INVALID_DATA;
walloc(lpBuffer, nBufferLength);
ret = GetCurrentDirectoryW(nBufferLength, wlpBuffer);
err = GetLastError();
if ((ret != 0) && ((ret = wchar_to_utf8_no_alloc(wlpBuffer, lpBuffer, nBufferLength)) == 0)) {
err = GetLastError();
}
wfree(lpBuffer);
SetLastError(err);
return ret;
}
static __inline DWORD GetFullPathNameU(const char* lpFileName, DWORD nBufferLength, char* lpBuffer, char** lpFilePart)
{
DWORD ret = 0, err = ERROR_INVALID_DATA;
wchar_t* wlpFilePart;
wconvert(lpFileName);
walloc(lpBuffer, nBufferLength);
// lpFilePart is not supported
if (lpFilePart != NULL) goto out;
ret = GetFullPathNameW(wlpFileName, nBufferLength, wlpBuffer, &wlpFilePart);
err = GetLastError();
if ((ret != 0) && ((ret = wchar_to_utf8_no_alloc(wlpBuffer, lpBuffer, nBufferLength)) == 0)) {
err = GetLastError();
}
out:
wfree(lpBuffer);
wfree(lpFileName);
SetLastError(err);
return ret;
}
static __inline DWORD GetFileAttributesU(const char* lpFileName)
{
DWORD ret = 0xFFFFFFFF, err = ERROR_INVALID_DATA;
wconvert(lpFileName);
ret = GetFileAttributesW(wlpFileName);
err = GetLastError();
wfree(lpFileName);
SetLastError(err);
return ret;
}
static __inline int SHCreateDirectoryExU(HWND hwnd, const char* pszPath, SECURITY_ATTRIBUTES *psa)
{
int ret = ERROR_INVALID_DATA;
DWORD err = ERROR_INVALID_DATA;
wconvert(pszPath);
ret = SHCreateDirectoryExW(hwnd, wpszPath, psa);
err = GetLastError();
wfree(pszPath);
SetLastError(err);
return ret;
}
static __inline BOOL ShellExecuteExU(SHELLEXECUTEINFOA* lpExecInfo)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
SHELLEXECUTEINFOW wExecInfo;
// Because we're lazy, we'll assume that the A and W structs inherently have the same size
if (lpExecInfo->cbSize != sizeof(SHELLEXECUTEINFOW)) {
SetLastError(ERROR_BAD_LENGTH); return FALSE;
}
memcpy(&wExecInfo, lpExecInfo, lpExecInfo->cbSize);
wExecInfo.lpVerb = utf8_to_wchar(lpExecInfo->lpVerb);
wExecInfo.lpFile = utf8_to_wchar(lpExecInfo->lpFile);
wExecInfo.lpParameters = utf8_to_wchar(lpExecInfo->lpParameters);
wExecInfo.lpDirectory = utf8_to_wchar(lpExecInfo->lpDirectory);
if (wExecInfo.fMask & SEE_MASK_CLASSNAME) {
wExecInfo.lpClass = utf8_to_wchar(lpExecInfo->lpClass);
} else {
wExecInfo.lpClass = NULL;
}
ret = ShellExecuteExW(&wExecInfo);
err = GetLastError();
// Copy the returned values back
lpExecInfo->hInstApp = wExecInfo.hInstApp;
lpExecInfo->hProcess = wExecInfo.hProcess;
sfree(wExecInfo.lpVerb);
sfree(wExecInfo.lpFile);
sfree(wExecInfo.lpParameters);
sfree(wExecInfo.lpDirectory);
sfree(wExecInfo.lpClass);
SetLastError(err);
return ret;
}
// Doesn't support LPSTARTUPINFOEX struct
static __inline BOOL CreateProcessU(const char* lpApplicationName, const char* lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags,
LPVOID lpEnvironment, const char* lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
STARTUPINFOW wStartupInfo;
wconvert(lpApplicationName);
wconvert(lpCommandLine);
wconvert(lpCurrentDirectory);
// Because we're lazy, we'll assume that the A and W structs inherently have the same size
// Also prevents the use of STARTUPINFOEX
if (lpStartupInfo->cb != sizeof(STARTUPINFOW)) {
err = ERROR_BAD_LENGTH; goto out;
}
memcpy(&wStartupInfo, lpStartupInfo, lpStartupInfo->cb);
wStartupInfo.lpDesktop = utf8_to_wchar(lpStartupInfo->lpDesktop);
wStartupInfo.lpTitle = utf8_to_wchar(lpStartupInfo->lpTitle);
ret = CreateProcessW(wlpApplicationName, wlpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles,
dwCreationFlags, lpEnvironment, wlpCurrentDirectory, &wStartupInfo, lpProcessInformation);
err = GetLastError();
sfree(wStartupInfo.lpDesktop);
sfree(wStartupInfo.lpTitle);
out:
wfree(lpApplicationName);
wfree(lpCommandLine);
wfree(lpCurrentDirectory);
SetLastError(err);
return ret;
}
// NOTE: when used, nFileOffset & nFileExtension MUST be provided
// in number of Unicode characters, NOT number of UTF-8 bytes
static __inline BOOL WINAPI GetOpenSaveFileNameU(LPOPENFILENAMEA lpofn, BOOL save)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
size_t i, len;
OPENFILENAMEW wofn;
memset(&wofn, 0, sizeof(wofn));
wofn.lStructSize = sizeof(wofn);
wofn.hwndOwner = lpofn->hwndOwner;
wofn.hInstance = lpofn->hInstance;
// No support for custom filters
if (lpofn->lpstrCustomFilter != NULL) goto out;
// Count on Microsoft to use an moronic scheme for filters
// that relies on NULL separators and double NULL terminators
if (lpofn->lpstrFilter != NULL) {
// Replace the NULLs by something that can be converted
for (i=0; ; i++) {
if (lpofn->lpstrFilter[i] == 0) {
((char*)lpofn->lpstrFilter)[i] = '\r';
if (lpofn->lpstrFilter[i+1] == 0) {
break;
}
}
}
wofn.lpstrFilter = utf8_to_wchar(lpofn->lpstrFilter);
// And revert
len = wcslen(wofn.lpstrFilter); // don't use in the loop as it would be reevaluated
for (i=0; i<len; i++) {
if (wofn.lpstrFilter[i] == '\r') {
((wchar_t*)wofn.lpstrFilter)[i] = 0;
}
}
len = strlen(lpofn->lpstrFilter);
for (i=0; i<len; i++) {
if (lpofn->lpstrFilter[i] == '\r') {
((char*)lpofn->lpstrFilter)[i] = 0;
}
}
} else {
wofn.lpstrFilter = NULL;
}
wofn.nMaxCustFilter = lpofn->nMaxCustFilter;
wofn.nFilterIndex = lpofn->nFilterIndex;
wofn.lpstrFile = calloc(lpofn->nMaxFile, sizeof(wchar_t));
utf8_to_wchar_no_alloc(lpofn->lpstrFile, wofn.lpstrFile, lpofn->nMaxFile);
wofn.nMaxFile = lpofn->nMaxFile;
wofn.lpstrFileTitle = calloc(lpofn->nMaxFileTitle, sizeof(wchar_t));
utf8_to_wchar_no_alloc(lpofn->lpstrFileTitle, wofn.lpstrFileTitle, lpofn->nMaxFileTitle);
wofn.nMaxFileTitle = lpofn->nMaxFileTitle;
wofn.lpstrInitialDir = utf8_to_wchar(lpofn->lpstrInitialDir);
wofn.lpstrTitle = utf8_to_wchar(lpofn->lpstrTitle);
wofn.Flags = lpofn->Flags;
wofn.nFileOffset = lpofn->nFileOffset;
wofn.nFileExtension = lpofn->nFileExtension;
wofn.lpstrDefExt = utf8_to_wchar(lpofn->lpstrDefExt);
wofn.lCustData = lpofn->lCustData;
wofn.lpfnHook = lpofn->lpfnHook;
wofn.lpTemplateName = utf8_to_wchar(lpofn->lpTemplateName);
wofn.pvReserved = lpofn->pvReserved;
wofn.dwReserved = lpofn->dwReserved;
wofn.FlagsEx = lpofn->FlagsEx;
if (save) {
ret = GetSaveFileNameW(&wofn);
} else {
ret = GetOpenFileNameW(&wofn);
}
err = GetLastError();
if ( (ret)
&& ( (wchar_to_utf8_no_alloc(wofn.lpstrFile, lpofn->lpstrFile, lpofn->nMaxFile) == 0)
|| (wchar_to_utf8_no_alloc(wofn.lpstrFileTitle, lpofn->lpstrFileTitle, lpofn->nMaxFileTitle) == 0) ) ) {
err = GetLastError();
ret = FALSE;
}
out:
sfree(wofn.lpstrDefExt);
sfree(wofn.lpstrFile);
sfree(wofn.lpstrFileTitle);
sfree(wofn.lpstrFilter);
sfree(wofn.lpstrInitialDir);
sfree(wofn.lpstrTitle);
sfree(wofn.lpTemplateName);
SetLastError(err);
return ret;
}
extern BOOL WINAPI UpdateDriverForPlugAndPlayDevicesW(HWND hwndParent, LPCWSTR HardwareId,
LPCWSTR FullInfPath, DWORD InstallFlags, PBOOL bRebootRequired);
static __inline BOOL UpdateDriverForPlugAndPlayDevicesU(HWND hwndParent, const char* HardwareId, const char* FullInfPath,
DWORD InstallFlags, PBOOL bRebootRequired)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
wconvert(HardwareId);
wconvert(FullInfPath);
ret = UpdateDriverForPlugAndPlayDevicesW(hwndParent, wHardwareId, wFullInfPath, InstallFlags, bRebootRequired);
err = GetLastError();
wfree(HardwareId);
wfree(FullInfPath);
SetLastError(err);
return ret;
}
static __inline BOOL SetupCopyOEMInfU(const char* SourceInfFileName, const char* OEMSourceMediaLocation, DWORD OEMSourceMediaType,
DWORD CopyStyle, char* DestinationInfFileName, DWORD DestinationInfFileNameSize,
PDWORD RequiredSize, PTSTR DestinationInfFileNameComponent)
{
BOOL ret = FALSE;
DWORD err = ERROR_INVALID_DATA;
wconvert(SourceInfFileName);
wconvert(OEMSourceMediaLocation);
walloc(DestinationInfFileName, DestinationInfFileNameSize);
// DestinationInfFileNameComponent is not supported
if (DestinationInfFileNameComponent != NULL) goto out;
ret = SetupCopyOEMInfW(wSourceInfFileName, wOEMSourceMediaLocation, OEMSourceMediaType, CopyStyle,
wDestinationInfFileName, DestinationInfFileNameSize, RequiredSize, NULL);
err = GetLastError();
if ((ret != FALSE) && ((ret = wchar_to_utf8_no_alloc(wDestinationInfFileName, DestinationInfFileName, DestinationInfFileNameSize)) == 0)) {
err = GetLastError();
}
out:
wfree(SourceInfFileName);
wfree(OEMSourceMediaLocation);
wfree(DestinationInfFileName);
SetLastError(err);
return ret;
}
static __inline FILE* fopenU(const char* filename, const char* mode)
{
FILE* ret = NULL;
wconvert(filename);
wconvert(mode);
ret = _wfopen(wfilename, wmode);
wfree(filename);
wfree(mode);
return ret;
}
#ifdef __cplusplus
}
#endif

337
src/msdos.c Normal file
View file

@ -0,0 +1,337 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* MS-DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Memory leaks detection - define _CRTDBG_MAP_ALLOC as preprocessor macro */
#ifdef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "rufus.h"
#include "msdos.h"
static BYTE* DiskImage;
static size_t DiskImageSize;
/*
* FAT time conversion, from ReactOS' time.c
*/
#define TICKSPERMIN 600000000
#define TICKSPERSEC 10000000
#define TICKSPERMSEC 10000
#define SECSPERDAY 86400
#define SECSPERHOUR 3600
#define SECSPERMIN 60
#define MINSPERHOUR 60
#define HOURSPERDAY 24
#define EPOCHWEEKDAY 1
#define DAYSPERWEEK 7
#define EPOCHYEAR 1601
#define DAYSPERNORMALYEAR 365
#define DAYSPERLEAPYEAR 366
#define MONSPERYEAR 12
typedef struct _TIME_FIELDS {
short Year;
short Month;
short Day;
short Hour;
short Minute;
short Second;
short Milliseconds;
short Weekday;
} TIME_FIELDS, *PTIME_FIELDS;
#define ARGUMENT_PRESENT(ArgumentPointer) \
((CHAR*)((ULONG_PTR)(ArgumentPointer)) != (CHAR*)NULL)
static const int YearLengths[2] =
{
DAYSPERNORMALYEAR, DAYSPERLEAPYEAR
};
static const UCHAR MonthLengths[2][MONSPERYEAR] =
{
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
static __inline int IsLeapYear(int Year)
{
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
}
static int DaysSinceEpoch(int Year)
{
int Days;
Year--; /* Don't include a leap day from the current year */
Days = Year * DAYSPERNORMALYEAR + Year / 4 - Year / 100 + Year / 400;
Days -= (EPOCHYEAR - 1) * DAYSPERNORMALYEAR + (EPOCHYEAR - 1) / 4 - (EPOCHYEAR - 1) / 100 + (EPOCHYEAR - 1) / 400;
return Days;
}
static BOOLEAN RtlTimeFieldsToTime(PTIME_FIELDS TimeFields, PLARGE_INTEGER Time)
{
int CurMonth;
TIME_FIELDS IntTimeFields;
memcpy(&IntTimeFields,
TimeFields,
sizeof(TIME_FIELDS));
if (TimeFields->Milliseconds < 0 || TimeFields->Milliseconds > 999 ||
TimeFields->Second < 0 || TimeFields->Second > 59 ||
TimeFields->Minute < 0 || TimeFields->Minute > 59 ||
TimeFields->Hour < 0 || TimeFields->Hour > 23 ||
TimeFields->Month < 1 || TimeFields->Month > 12 ||
TimeFields->Day < 1 ||
TimeFields->Day >
MonthLengths[IsLeapYear(TimeFields->Year)][TimeFields->Month - 1] ||
TimeFields->Year < 1601) {
return FALSE;
}
/* Compute the time */
Time->QuadPart = DaysSinceEpoch(IntTimeFields.Year);
for (CurMonth = 1; CurMonth < IntTimeFields.Month; CurMonth++) {
Time->QuadPart += MonthLengths[IsLeapYear(IntTimeFields.Year)][CurMonth - 1];
}
Time->QuadPart += IntTimeFields.Day - 1;
Time->QuadPart *= SECSPERDAY;
Time->QuadPart += IntTimeFields.Hour * SECSPERHOUR + IntTimeFields.Minute * SECSPERMIN +
IntTimeFields.Second;
Time->QuadPart *= TICKSPERSEC;
Time->QuadPart += IntTimeFields.Milliseconds * TICKSPERMSEC;
return TRUE;
}
static void FatDateTimeToSystemTime(PLARGE_INTEGER SystemTime, PFAT_DATETIME FatDateTime, UCHAR TenMs OPTIONAL)
{
TIME_FIELDS TimeFields;
/* Setup time fields */
TimeFields.Year = FatDateTime->Date.Year + 1980;
TimeFields.Month = FatDateTime->Date.Month;
TimeFields.Day = FatDateTime->Date.Day;
TimeFields.Hour = FatDateTime->Time.Hour;
TimeFields.Minute = FatDateTime->Time.Minute;
TimeFields.Second = (FatDateTime->Time.DoubleSeconds << 1);
/* Adjust up to 10 milliseconds
* if the parameter was supplied
*/
if (ARGUMENT_PRESENT(TenMs)) {
TimeFields.Second += TenMs / 100;
TimeFields.Milliseconds = (TenMs % 100) * 10;
} else {
TimeFields.Milliseconds = 0;
}
/* Fix seconds value that might get beyond the bound */
if (TimeFields.Second > 59) TimeFields.Second = 0;
/* Perform ceonversion to system time if possible */
if (!RtlTimeFieldsToTime(&TimeFields, SystemTime)) {
/* Set to default time if conversion failed */
SystemTime->QuadPart = 0;
}
}
/* http://www.multiboot.ru/msdos8.htm & http://en.wikipedia.org/wiki/Windows_Me#Real_mode_DOS
* COMMAND.COM and IO.SYS from diskcopy.dll are from the WinME crippled version
* that removed real mode DOS => they must be patched:
* IO.SYS 000003AA 75 -> EB
* COMMAND.COM 00006510 75 -> EB
*/
static BOOL Patch_COMMAND_COM(size_t filestart, size_t filesize)
{
const BYTE expected[8] = { 0x15, 0x80, 0xFA, 0x03, 0x75, 0x10, 0xB8, 0x0E };
uprintf("Patching COMMAND.COM...\n");
if (filesize != 93040) {
uprintf(" unexpected file size\n");
return FALSE;
}
if (memcmp(&DiskImage[filestart+0x650c], expected, sizeof(expected)) != 0) {
uprintf(" unexpected binary data\n");
return FALSE;
}
DiskImage[filestart+0x6510] = 0xeb;
return TRUE;
}
static BOOL Patch_IO_SYS(size_t filestart, size_t filesize)
{
const BYTE expected[8] = { 0xFA, 0x80, 0x75, 0x09, 0x8D, 0xB6, 0x99, 0x00 };
uprintf("Patching IO.SYS...\n");
if (filesize != 116736) {
uprintf(" unexpected file size\n");
return FALSE;
}
if (memcmp(&DiskImage[filestart+0x3a8], expected, sizeof(expected)) != 0) {
uprintf(" unexpected binary data\n");
return FALSE;
}
DiskImage[filestart+0x3aa] = 0xeb;
return TRUE;
}
/* Extract the file identified by FAT RootDir index 'entry' to 'path' */
static BOOL ExtractFAT(int entry, const char* path)
{
HANDLE hFile;
DWORD Size;
char filename[MAX_PATH];
size_t i, pos, fnamepos;
size_t filestart, filesize;
FAT_DATETIME LastAccessTime;
LARGE_INTEGER liCreationTime, liLastAccessTime, liLastWriteTime;
FILETIME ftCreationTime, ftLastAccessTime, ftLastWriteTime;
PDIR_ENTRY dir_entry = (PDIR_ENTRY)&DiskImage[FAT12_ROOTDIR_OFFSET + entry*FAT_BYTES_PER_DIRENT];
if ((path == NULL) || ((safe_strlen(path) + 14) > sizeof(filename))) {
uprintf("invalid path supplied for MS-DOS FAT extraction\n");
return FALSE;
}
strcpy(filename, path);
pos = strlen(path);
filename[pos++] = '\\';
fnamepos = pos;
for(i=0; i<8; i++) {
if (dir_entry->FileName[i] == ' ')
break;
filename[pos++] = dir_entry->FileName[i];
}
filename[pos++] = '.';
for (i=8; i<11; i++) {
if (dir_entry->FileName[i] == ' ')
break;
filename[pos++] = dir_entry->FileName[i];
}
filename[pos] = 0;
filestart = (dir_entry->FirstCluster + FAT12_CLUSTER_OFFSET)*FAT12_CLUSTER_SIZE;
filesize = dir_entry->FileSize;
if ((filestart + filesize) > DiskImageSize) {
uprintf("FAT File %s would be out of bounds: %X, %X\n", filename, filestart, filesize);
uprintf("%X, %X\n", dir_entry->FirstCluster, dir_entry->FileSize);
return FALSE;
}
/* WinME DOS files need to be patched */
if (strcmp(&filename[fnamepos], "COMMAND.COM") == 0) {
Patch_COMMAND_COM(filestart, filesize);
} else if (strcmp(&filename[fnamepos], "IO.SYS") == 0) {
Patch_IO_SYS(filestart, filesize);
}
/* Create a file, using the same attributes as found in the FAT */
hFile = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, dir_entry->Attributes, 0);
if (hFile == INVALID_HANDLE_VALUE) {
uprintf("Unable to create file '%s': %s.\n", filename, WindowsErrorString());
return FALSE;
}
if ((!WriteFile(hFile, &DiskImage[filestart], (DWORD)filesize, &Size, 0)) || (filesize != Size)) {
uprintf("Couldn't write file '%s': %s.\n", filename, WindowsErrorString());
safe_closehandle(hFile);
return FALSE; safe_closehandle(hFile);
}
/* Restore timestamps from FAT */
FatDateTimeToSystemTime(&liCreationTime, &dir_entry->CreationDateTime, dir_entry->CreationTimeTenMs);
ftCreationTime.dwHighDateTime = liCreationTime.HighPart;
ftCreationTime.dwLowDateTime = liCreationTime.LowPart;
LastAccessTime.Value = 0;
LastAccessTime.Date = dir_entry->LastAccessDate;
FatDateTimeToSystemTime(&liLastAccessTime, &LastAccessTime, 0);
ftLastAccessTime.dwHighDateTime = liLastAccessTime.HighPart;
ftLastAccessTime.dwLowDateTime = liLastAccessTime.LowPart;
FatDateTimeToSystemTime(&liLastWriteTime, &dir_entry->LastWriteDateTime, 0);
ftLastWriteTime.dwHighDateTime = liLastWriteTime.HighPart;
ftLastWriteTime.dwLowDateTime = liLastWriteTime.LowPart;
if (!SetFileTime(hFile, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime)) {
uprintf("Could not set timestamps: %s\n", WindowsErrorString());
}
safe_closehandle(hFile);
uprintf("Succesfully wrote '%s' (%d bytes)\n", filename, filesize);
return TRUE;
}
/* Extract the MS-DOS files contained in the FAT12 1.4MB floppy
image included as resource "BINFILE" in diskcopy.dll */
BOOL ExtractMSDOS(const char* path)
{
char dllname[MAX_PATH] = "C:\\Windows\\System32";
int i, j;
HMODULE hDLL;
HRSRC hDiskImage;
// TODO: optionally extract some more, including "deleted" entries
char* extractlist[] = {"MSDOS SYS", "COMMAND COM", "IO SYS"};
GetSystemDirectoryA(dllname, sizeof(dllname));
safe_strcat(dllname, sizeof(dllname), "\\diskcopy.dll");
hDLL = LoadLibraryA(dllname);
if (hDLL == NULL) {
uprintf("Unable to open %s: %s\n", dllname, WindowsErrorString());
return FALSE;
}
hDiskImage = FindResourceA(hDLL, MAKEINTRESOURCEA(1), "BINFILE");
if (hDiskImage == NULL) {
uprintf("Unable to locate disk image in %s: %s\n", dllname, WindowsErrorString());
FreeLibrary(hDLL);
return FALSE;
}
DiskImage = (BYTE*)LockResource(LoadResource(hDLL, hDiskImage));
if (DiskImage == NULL) {
uprintf("Unable to access disk image in %s: %s\n", dllname, WindowsErrorString());
FreeLibrary(hDLL);
return FALSE;
}
DiskImageSize = (size_t)SizeofResource(hDLL, hDiskImage);
// Sanity check
if (DiskImageSize < 700*1024) {
uprintf("MS-DOS disk image is too small (%d bytes)\n", dllname, DiskImageSize);
FreeLibrary(hDLL);
return FALSE;
}
for (i=0; i<FAT_FN_DIR_ENTRY_LAST; i++) {
if (DiskImage[FAT12_ROOTDIR_OFFSET + i*FAT_BYTES_PER_DIRENT] == FAT_DIRENT_DELETED)
continue;
for (j=0; j<ARRAYSIZE(extractlist); j++) {
if (memcmp(extractlist[j], &DiskImage[FAT12_ROOTDIR_OFFSET + i*FAT_BYTES_PER_DIRENT], 8+3) == 0) {
ExtractFAT(i, path);
}
}
}
FreeLibrary(hDLL);
return TRUE;
}

138
src/msdos.h Normal file
View file

@ -0,0 +1,138 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* MS-DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
/* http://www.c-jump.com/CIS24/Slides/FAT/lecture.html
Ideally, we'd read the following from the FAT Boot Sector, but we have
a pretty good idea of what they are for a 1.44 MB floppy image */
#define FAT12_ROOTDIR_OFFSET 0x2600
#define FAT12_CLUSTER_SIZE 0x200 // = sector size
#define FAT12_DATA_START 0x4200
#define FAT12_CLUSTER_OFFSET ((FAT12_DATA_START/FAT12_CLUSTER_SIZE)-2) // First cluster in data area is #2
/*
* Lifted from ReactOS:
* http://reactos-mirror.googlecode.com/svn/trunk/reactos/drivers/filesystems/fastfat_new/fat.h
*/
#pragma pack(push, 1) // You *DO* want packed structs here
//
// Directory Structure:
//
typedef struct _FAT_TIME
{
union {
struct {
USHORT DoubleSeconds : 5;
USHORT Minute : 6;
USHORT Hour : 5;
};
USHORT Value;
};
} FAT_TIME, *PFAT_TIME;
//
//
//
typedef struct _FAT_DATE {
union {
struct {
USHORT Day : 5;
USHORT Month : 4;
/* Relative to 1980 */
USHORT Year : 7;
};
USHORT Value;
};
} FAT_DATE, *PFAT_DATE;
//
//
//
typedef struct _FAT_DATETIME {
union {
struct {
FAT_TIME Time;
FAT_DATE Date;
};
ULONG Value;
};
} FAT_DATETIME, *PFAT_DATETIME;
//
//
//
typedef struct _DIR_ENTRY
{
UCHAR FileName[11];
UCHAR Attributes;
UCHAR Case;
UCHAR CreationTimeTenMs;
FAT_DATETIME CreationDateTime;
FAT_DATE LastAccessDate;
union {
USHORT ExtendedAttributes;
USHORT FirstClusterOfFileHi;
};
FAT_DATETIME LastWriteDateTime;
USHORT FirstCluster;
ULONG FileSize;
} DIR_ENTRY, *PDIR_ENTRY;
// sizeof = 0x020
typedef struct _LONG_FILE_NAME_ENTRY {
UCHAR SeqNum;
UCHAR NameA[10];
UCHAR Attributes;
UCHAR Type;
UCHAR Checksum;
USHORT NameB[6];
USHORT Reserved;
USHORT NameC[2];
} LONG_FILE_NAME_ENTRY, *PLONG_FILE_NAME_ENTRY;
// sizeof = 0x020
#pragma pack()
#define FAT_LFN_NAME_LENGTH \
(RTL_FIELD_SIZE(LONG_FILE_NAME_ENTRY, NameA) \
+ RTL_FIELD_SIZE(LONG_FILE_NAME_ENTRY, NameB) \
+ RTL_FIELD_SIZE(LONG_FILE_NAME_ENTRY, NameC))
#define FAT_FN_DIR_ENTRY_LAST 0x40
#define FAT_FN_MAX_DIR_ENTIES 0x14
#define FAT_BYTES_PER_DIRENT 0x20
#define FAT_BYTES_PER_DIRENT_LOG 0x05
#define FAT_DIRENT_NEVER_USED 0x00
#define FAT_DIRENT_REALLY_0E5 0x05
#define FAT_DIRENT_DIRECTORY_ALIAS 0x2e
#define FAT_DIRENT_DELETED 0xe5
#define FAT_CASE_LOWER_BASE 0x08
#define FAT_CASE_LOWER_EXT 0x10
#define FAT_DIRENT_ATTR_READ_ONLY 0x01
#define FAT_DIRENT_ATTR_HIDDEN 0x02
#define FAT_DIRENT_ATTR_SYSTEM 0x04
#define FAT_DIRENT_ATTR_VOLUME_ID 0x08
#define FAT_DIRENT_ATTR_DIRECTORY 0x10
#define FAT_DIRENT_ATTR_ARCHIVE 0x20
#define FAT_DIRENT_ATTR_DEVICE 0x40
#define FAT_DIRENT_ATTR_LFN (FAT_DIRENT_ATTR_READ_ONLY | \
FAT_DIRENT_ATTR_HIDDEN | \
FAT_DIRENT_ATTR_SYSTEM | \
FAT_DIRENT_ATTR_VOLUME_ID)

43
src/resource.h Normal file
View file

@ -0,0 +1,43 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by rufus.rc
//
#define IDD_DIALOG 101
#define IDI_ICON 102
#define IDD_ABOUTBOX 103
#define IDD_NOTIFICATION 104
#define IDD_LICENSE 105
#define IDS_VERSION 106
#define IDC_DEVICE 1001
#define IDC_FILESYSTEM 1002
#define IDC_START 1003
#define IDC_CAPACITY 1004
#define IDC_CLUSTERSIZE 1005
#define IDC_STATUS 1006
#define IDC_ABOUT 1007
#define IDC_LABEL 1008
#define IDC_QUICKFORMAT 1009
#define IDC_DOS 1010
#define IDC_PROGRESS 1011
#define IDC_ABOUT_LICENSE 1030
#define IDC_ABOUT_ICON 1031
#define IDC_RUFUS_BOLD 1032
#define IDC_ABOUT_COPYRIGHTS 1033
#define IDC_ABOUT_RUFUS_URL 1034
#define IDC_ABOUT_BUG_URL 1035
#define IDC_LICENSE_TEXT 1036
#define IDC_NOTIFICATION_ICON 1040
#define IDC_NOTIFICATION_TEXT 1041
#define IDC_NOTIFICATION_LINE 1042
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 107
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1043
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

821
src/rufus.c Normal file
View file

@ -0,0 +1,821 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Memory leaks detection - define _CRTDBG_MAP_ALLOC as preprocessor macro */
#ifdef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <commctrl.h>
#include <setupapi.h>
#include <winioctl.h>
#include <process.h>
#include <dbt.h>
// http://git.kernel.org/?p=fs/ext2/e2fsprogs.git;a=blob;f=misc/badblocks.c
// http://thestarman.pcministry.com/asm/mbr/MSWIN41.htm
// http://sourceforge.net/projects/grub4dos/ (bootable NTFS?)
#include "msapi_utf8.h"
#include "resource.h"
#include "rufus.h"
#include "sys_types.h"
static const char* FileSystemLabel[FS_MAX] = { "FAT", "FAT32", "NTFS", "exFAT" };
// Don't ask me - just following the MS standard here
static const char* ClusterSizeLabel[] = { "512 bytes", "1024 bytes","2048 bytes","4096 bytes","8192 bytes",
"16 kilobytes", "32 kilobytes", "64 kilobytes", "128 kilobytes", "256 kilobytes", "512 kilobytes",
"1024 kilobytes","2048 kilobytes","4096 kilobytes","8192 kilobytes","16 megabytes","32 megabytes" };
/*
* Globals
*/
HINSTANCE hMainInstance;
HWND hMainDialog;
char szFolderPath[MAX_PATH];
float fScale = 1.0f;
int default_fs;
HWND hDeviceList, hCapacity, hFileSystem, hClusterSize, hLabel;
static HWND hDeviceTooltip = NULL, hFSTooltip = NULL;
static StrArray DriveID, DriveLabel;
/*
* Convert a partition type to its human readable form using
* (slightly modified) entries from GNU fdisk
*/
static const char* GetPartitionType(BYTE Type)
{
int i;
for (i=0; i<ARRAYSIZE(msdos_systypes); i++) {
if (msdos_systypes[i].type == Type)
return msdos_systypes[i].name;
}
return "Unknown";
}
#define KB 1024LL
#define MB 1048576LL
#define GB 1073741824LL
#define TB 1099511627776LL
/*
* Set cluster size values according to http://support.microsoft.com/kb/140365
* this call will return FALSE if we can't find a supportable FS for the drive
*/
static BOOL DefineClusterSizes(void)
{
LONGLONG i;
int fs;
BOOL r = FALSE;
char tmp[64] = "";
default_fs = FS_UNKNOWN;
memset(&SelectedDrive.ClusterSize, 0, sizeof(SelectedDrive.ClusterSize));
if (SelectedDrive.DiskSize < 8*MB) {
// TODO: muck with FAT12 and Small FAT16 like Microsoft does
uprintf("This application does not support volumes smaller than 8 MB yet\n");
goto out;
}
// FAT 16
if (SelectedDrive.DiskSize < 4*GB) {
// TODO: Refine the following according to size
SelectedDrive.ClusterSize[FS_FAT16].Allowed = 0x0001FE00;
for (i=32; i<=4096; i<<=1) { // 8 MB -> 4 GB
if (SelectedDrive.DiskSize < i*MB) {
SelectedDrive.ClusterSize[FS_FAT16].Default = 16*(ULONG)i;
break;
}
}
}
// FAT 32
if (SelectedDrive.DiskSize < 256*MB) {
// TODO: Refine the following according to size
SelectedDrive.ClusterSize[FS_FAT32].Allowed = 0x0001FE00;
for (i=64; i<=256; i<<=1) { // 8 MB -> 256 MB
if (SelectedDrive.DiskSize < i*MB) {
SelectedDrive.ClusterSize[FS_FAT32].Default = 8*(ULONG)i;
break;
}
}
} else if (SelectedDrive.DiskSize < 32*GB) {
SelectedDrive.ClusterSize[FS_FAT32].Allowed = 0x0001FE00;
for (i=8; i<=32; i<<=1) { // 256 MB -> 32 GB
if (SelectedDrive.DiskSize < i*GB) {
SelectedDrive.ClusterSize[FS_FAT32].Default = ((ULONG)i/2)*1024;
break;
}
}
}
// NTFS
if (SelectedDrive.DiskSize < 256*TB) {
SelectedDrive.ClusterSize[FS_NTFS].Allowed = 0x0001FE00;
for (i=16; i<=256; i<<=1) { // 7 MB -> 256 TB
if (SelectedDrive.DiskSize < i*TB) {
SelectedDrive.ClusterSize[FS_NTFS].Default = ((ULONG)i/4)*1024;
break;
}
}
}
// exFAT
if (SelectedDrive.DiskSize < 256*TB) {
SelectedDrive.ClusterSize[FS_EXFAT].Allowed = 0x03FFFE00;
if (SelectedDrive.DiskSize < 256*MB) // < 256 MB
SelectedDrive.ClusterSize[FS_EXFAT].Default = 4*1024;
else if (SelectedDrive.DiskSize < 32*GB) // < 32 GB
SelectedDrive.ClusterSize[FS_EXFAT].Default = 32*1024;
else
SelectedDrive.ClusterSize[FS_EXFAT].Default = 28*1024;
}
out:
// Only add the filesystems we can service
for (fs=0; fs<FS_MAX; fs++) {
if (SelectedDrive.ClusterSize[fs].Allowed != 0) {
safe_sprintf(tmp, sizeof(tmp), FileSystemLabel[fs]);
if (default_fs == FS_UNKNOWN) {
safe_strcat(tmp, sizeof(tmp), " (Default)");
default_fs = fs;
}
IGNORE_RETVAL(ComboBox_SetItemData(hFileSystem,
ComboBox_AddStringU(hFileSystem, tmp), fs));
r = TRUE;
}
}
return r;
}
#undef KB
#undef MB
#undef GB
#undef TB
/*
* Populate the Allocation unit size field
*/
static BOOL SetClusterSizes(int FSType)
{
char szClustSize[64];
int i, default_index = 0;
ULONG j;
IGNORE_RETVAL(ComboBox_ResetContent(hClusterSize));
if ((FSType < 0) || (FSType >= FS_MAX)) {
uprintf("Invalid FS value passed to SetClusterSizes\n");
return FALSE;
}
if ( (SelectedDrive.ClusterSize[FSType].Allowed == 0)
|| (SelectedDrive.ClusterSize[FSType].Default == 0) ) {
uprintf("The drive is incompatible with FS type #%d\n", FSType);
return FALSE;
}
for(i=0,j=0x200;j<0x10000000;i++,j<<=1) {
if (j & SelectedDrive.ClusterSize[FSType].Allowed) {
safe_sprintf(szClustSize, sizeof(szClustSize), "%s", ClusterSizeLabel[i]);
if (j == SelectedDrive.ClusterSize[FSType].Default) {
safe_strcat(szClustSize, sizeof(szClustSize), " (Default)");
default_index = i;
}
IGNORE_RETVAL(ComboBox_SetItemData(hClusterSize, ComboBox_AddStringU(hClusterSize, szClustSize), j));
}
}
IGNORE_RETVAL(ComboBox_SetCurSel(hClusterSize, default_index));
return TRUE;
}
/*
* Fill the drive properties (size, FS, etc)
*/
static BOOL GetDriveInfo(void)
{
BOOL r;
HANDLE hDrive;
DWORD size;
BYTE geometry[128], layout[1024];
void* disk_geometry = (void*)geometry;
void* drive_layout = (void*)layout;
PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)disk_geometry;
PDRIVE_LAYOUT_INFORMATION_EX DriveLayout = (PDRIVE_LAYOUT_INFORMATION_EX)drive_layout;
char DrivePath[] = "#:\\", tmp[128], fs_type[32];
DWORD i, nb_partitions = 0;
SelectedDrive.DiskSize = 0;
hDrive = GetDriveHandle(SelectedDrive.DeviceNumber, DrivePath, FALSE, FALSE);
if (hDrive == INVALID_HANDLE_VALUE)
return FALSE;
r = DeviceIoControl(hDrive, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL, 0, geometry, sizeof(geometry), &size, NULL );
if (!r || size <= 0) {
uprintf("IOCTL_DISK_GET_DRIVE_GEOMETRY_EX failed: %s\n", WindowsErrorString());
safe_closehandle(hDrive);
return FALSE;
}
SelectedDrive.DiskSize = DiskGeometry->DiskSize.QuadPart;
memcpy(&SelectedDrive.Geometry, &DiskGeometry->Geometry, sizeof(DISK_GEOMETRY));
uprintf("Cylinders: %lld, TracksPerCylinder: %d, SectorsPerTrack: %d, BytesPerSector: %d\n",
DiskGeometry->Geometry.Cylinders, DiskGeometry->Geometry.TracksPerCylinder,
DiskGeometry->Geometry.SectorsPerTrack, DiskGeometry->Geometry.BytesPerSector);
r = DeviceIoControl(hDrive, IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
NULL, 0, layout, sizeof(layout), &size, NULL );
if (!r || size <= 0) {
uprintf("IOCTL_DISK_GET_DRIVE_LAYOUT_EX failed: %s\n", WindowsErrorString());
} else {
DestroyTooltip(hFSTooltip);
hFSTooltip = NULL;
switch (DriveLayout->PartitionStyle) {
case PARTITION_STYLE_MBR:
for (i=0; i<DriveLayout->PartitionCount; i++) {
if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
uprintf("Partition #%d:\n", ++nb_partitions);
if (hFSTooltip == NULL) {
// TODO: provide all partitions FS on tooltip, not just the one
safe_sprintf(tmp, sizeof(tmp), "Current file system: %s (0x%02x)",
GetPartitionType(DriveLayout->PartitionEntry[i].Mbr.PartitionType),
DriveLayout->PartitionEntry[i].Mbr.PartitionType);
hFSTooltip = CreateTooltip(hFileSystem, tmp, -1);
}
uprintf(" Type: %s (0x%02x)\n Boot: %s\n Recognized: %s\n Hidden Sectors: %d\n",
GetPartitionType(DriveLayout->PartitionEntry[i].Mbr.PartitionType),
DriveLayout->PartitionEntry[i].Mbr.PartitionType,
DriveLayout->PartitionEntry[i].Mbr.BootIndicator?"Yes":"No",
DriveLayout->PartitionEntry[i].Mbr.RecognizedPartition?"Yes":"No",
DriveLayout->PartitionEntry[i].Mbr.HiddenSectors);
}
}
uprintf("Partition type: MBR, NB Partitions: %d\n", nb_partitions);
break;
case PARTITION_STYLE_GPT:
uprintf("Partition type: GPT, NB Partitions: %d\n", DriveLayout->PartitionCount);
break;
default:
uprintf("Partition type: RAW\n");
break;
}
}
safe_closehandle(hDrive);
if (!DefineClusterSizes()) {
uprintf("no file system is selectable for this drive\n");
return FALSE;
}
// re-select existing FS if it's one we know
if (GetVolumeInformationA(DrivePath, NULL, 0, NULL, NULL, NULL,
fs_type, sizeof(fs_type))) {
for (SelectedDrive.FSType=FS_MAX-1; SelectedDrive.FSType>=0; SelectedDrive.FSType--) {
if (safe_strcmp(fs_type, FileSystemLabel[SelectedDrive.FSType]) == 0) {
break;
}
}
} else {
SelectedDrive.FSType = FS_UNKNOWN;
}
for (i=0; i<ComboBox_GetCount(hFileSystem); i++) {
if (ComboBox_GetItemData(hFileSystem, i) == SelectedDrive.FSType) {
IGNORE_RETVAL(ComboBox_SetCurSel(hFileSystem, i));
break;
}
}
if (i == ComboBox_GetCount(hFileSystem)) {
// failed to reselect => pick default
for (i=0; i<ComboBox_GetCount(hFileSystem); i++) {
if (ComboBox_GetItemData(hFileSystem, i) == default_fs) {
IGNORE_RETVAL(ComboBox_SetCurSel(hFileSystem, i));
break;
}
}
}
// At least one filesystem is go => enable formatting
EnableWindow(GetDlgItem(hMainDialog, IDC_START), TRUE);
return SetClusterSizes((int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem)));
}
/*
* Populate the UI properties
*/
static BOOL PopulateProperties(int ComboIndex)
{
double HumanReadableSize;
char capacity[64];
static char *suffix[] = { "KB", "MB", "GB", "TB", "PB"};
char proposed_label[16], no_label[] = STR_NO_LABEL;
int i;
IGNORE_RETVAL(ComboBox_ResetContent(hCapacity));
IGNORE_RETVAL(ComboBox_ResetContent(hFileSystem));
IGNORE_RETVAL(ComboBox_ResetContent(hClusterSize));
EnableWindow(GetDlgItem(hMainDialog, IDC_START), FALSE);
SetWindowTextA(hLabel, "");
DestroyTooltip(hDeviceTooltip);
DestroyTooltip(hFSTooltip);
hDeviceTooltip = NULL;
hFSTooltip = NULL;
memset(&SelectedDrive, 0, sizeof(SelectedDrive));
if (ComboIndex < 0) {
return TRUE;
}
SelectedDrive.DeviceNumber = (DWORD)ComboBox_GetItemData(hDeviceList, ComboIndex);
if (!GetDriveInfo())
return FALSE;
HumanReadableSize = (double)SelectedDrive.DiskSize;
for (i=0; i<ARRAYSIZE(suffix); i++) {
HumanReadableSize /= 1024.0;
if (HumanReadableSize < 512.0) {
safe_sprintf(capacity, sizeof(capacity), "%0.2f %s", HumanReadableSize, suffix[i]);
break;
}
}
IGNORE_RETVAL(ComboBox_AddStringU(hCapacity, capacity));
IGNORE_RETVAL(ComboBox_SetCurSel(hCapacity, 0));
hDeviceTooltip = CreateTooltip(hDeviceList, DriveID.Table[ComboIndex], -1);
// If no existing label is available, propose one according to the size (eg: "256MB", "8GB")
if (safe_strcmp(no_label, DriveLabel.Table[ComboIndex]) == 0) {
if (HumanReadableSize < 1.0) {
HumanReadableSize *= 1024.0;
i--;
}
// If we're beneath the tolerance, round proposed label to an integer, if not, show one decimal point
if (fabs(HumanReadableSize / ceil(HumanReadableSize) - 1.0) < PROPOSEDLABEL_TOLERANCE) {
safe_sprintf(proposed_label, sizeof(proposed_label), "%0.0f%s", ceil(HumanReadableSize), suffix[i]);
} else {
safe_sprintf(proposed_label, sizeof(proposed_label), "%0.1f%s", HumanReadableSize, suffix[i]);
}
SetWindowTextA(hLabel, proposed_label);
} else {
SetWindowTextA(hLabel, DriveLabel.Table[ComboIndex]);
}
return TRUE;
}
/*
* Create a partition table
*/
BOOL CreatePartition(HANDLE hDrive)
{
BYTE layout[sizeof(DRIVE_LAYOUT_INFORMATION_EX) + 3*sizeof(PARTITION_INFORMATION_EX)] = {0};
PDRIVE_LAYOUT_INFORMATION_EX DriveLayoutEx = (PDRIVE_LAYOUT_INFORMATION_EX)layout;
BOOL r;
DWORD size;
PrintStatus("Partitioning...");
DriveLayoutEx->PartitionStyle = PARTITION_STYLE_MBR;
DriveLayoutEx->PartitionCount = 4; // Must be multiple of 4 for MBR
DriveLayoutEx->Mbr.Signature = GetTickCount();
DriveLayoutEx->PartitionEntry[0].PartitionStyle = PARTITION_STYLE_MBR;
DriveLayoutEx->PartitionEntry[0].StartingOffset.QuadPart =
SelectedDrive.Geometry.BytesPerSector * SelectedDrive.Geometry.SectorsPerTrack;
DriveLayoutEx->PartitionEntry[0].PartitionLength.QuadPart = SelectedDrive.DiskSize -
DriveLayoutEx->PartitionEntry[0].StartingOffset.QuadPart;
DriveLayoutEx->PartitionEntry[0].PartitionNumber = 1;
DriveLayoutEx->PartitionEntry[0].RewritePartition = TRUE;
DriveLayoutEx->PartitionEntry[0].Mbr.HiddenSectors = SelectedDrive.Geometry.SectorsPerTrack;
switch (ComboBox_GetCurSel(hFileSystem)) {
case FS_FAT16:
DriveLayoutEx->PartitionEntry[0].Mbr.PartitionType = 0x0e; // FAT16 LBA
break;
case FS_NTFS:
case FS_EXFAT:
// TODO: but how do we set this thing up afterwards?
DriveLayoutEx->PartitionEntry[0].Mbr.PartitionType = 0x07; // NTFS
break;
default:
DriveLayoutEx->PartitionEntry[0].Mbr.PartitionType = 0x0c; // FAT32 LBA
break;
}
// For the remaining partitions, PartitionStyle & PartitionType have already
// been zeroed => set to MBR/unused
r = DeviceIoControl(hDrive, IOCTL_DISK_SET_DRIVE_LAYOUT_EX,
layout, sizeof(layout), NULL, 0, &size, NULL );
if (!r) {
uprintf("IOCTL_DISK_SET_DRIVE_LAYOUT_EX failed: %s\n", WindowsErrorString());
safe_closehandle(hDrive);
return FALSE;
}
return TRUE;
}
/*
* Refresh the list of USB devices
*/
static BOOL GetUSBDevices(void)
{
BOOL r;
HDEVINFO dev_info = NULL;
SP_DEVINFO_DATA dev_info_data;
SP_DEVICE_INTERFACE_DATA devint_data;
PSP_DEVICE_INTERFACE_DETAIL_DATA_A devint_detail_data;
STORAGE_DEVICE_NUMBER_REDEF device_number;
DWORD size, i, j, datatype;
HANDLE hDrive;
char drive_letter;
char *label, entry[MAX_PATH], buffer[MAX_PATH];
const char* usbstor_name = "USBSTOR";
GUID _GUID_DEVINTERFACE_DISK = // only known to some...
{ 0x53f56307L, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b} };
IGNORE_RETVAL(ComboBox_ResetContent(hDeviceList));
StrArrayClear(&DriveID);
StrArrayClear(&DriveLabel);
dev_info = SetupDiGetClassDevsA(&_GUID_DEVINTERFACE_DISK, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
if (dev_info == INVALID_HANDLE_VALUE) {
uprintf("SetupDiGetClassDevs (Interface) failed: %d\n", WindowsErrorString());
return FALSE;
}
dev_info_data.cbSize = sizeof(dev_info_data);
for (i=0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) {
memset(buffer, 0, sizeof(buffer));
if (!SetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_ENUMERATOR_NAME,
&datatype, (LPBYTE)buffer, sizeof(buffer), &size)) {
uprintf("SetupDiGetDeviceRegistryProperty (Enumerator Name) failed: %d\n", WindowsErrorString());
continue;
}
if (safe_strcmp(buffer, usbstor_name) != 0)
continue;
memset(buffer, 0, sizeof(buffer));
if (!SetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_FRIENDLYNAME,
&datatype, (LPBYTE)buffer, sizeof(buffer), &size)) {
uprintf("SetupDiGetDeviceRegistryProperty (Friendly Name) failed: %d\n", WindowsErrorString());
continue;
}
uprintf("Found drive '%s'\n", buffer);
devint_data.cbSize = sizeof(devint_data);
hDrive = INVALID_HANDLE_VALUE;
devint_detail_data = NULL;
for (j=0; ;j++) {
safe_closehandle(hDrive);
safe_free(devint_detail_data);
if (!SetupDiEnumDeviceInterfaces(dev_info, &dev_info_data, &_GUID_DEVINTERFACE_DISK, j, &devint_data)) {
if(GetLastError() != ERROR_NO_MORE_ITEMS) {
uprintf("SetupDiEnumDeviceInterfaces failed: %s\n", WindowsErrorString());
}
break;
}
if (!SetupDiGetDeviceInterfaceDetailA(dev_info, &devint_data, NULL, 0, &size, NULL)) {
if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
devint_detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A)calloc(1, size);
if (devint_detail_data == NULL) {
uprintf("unable to allocate data for SP_DEVICE_INTERFACE_DETAIL_DATA\n");
return FALSE;
}
devint_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
} else {
uprintf("SetupDiGetDeviceInterfaceDetail (dummy) failed: %s\n", WindowsErrorString());
continue;
}
}
if(!SetupDiGetDeviceInterfaceDetailA(dev_info, &devint_data, devint_detail_data, size, &size, NULL)) {
uprintf("SetupDiGetDeviceInterfaceDetail (actual) failed: %s\n", WindowsErrorString());
continue;
}
hDrive = CreateFileA(devint_detail_data->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if(hDrive == INVALID_HANDLE_VALUE) {
uprintf("could not open '%s': %s\n", devint_detail_data->DevicePath, WindowsErrorString());
continue;
}
memset(&device_number, 0, sizeof(device_number));
r = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER,
NULL, 0, &device_number, sizeof(device_number), &size, NULL );
if (!r || size <= 0) {
uprintf("IOCTL_STORAGE_GET_DEVICE_NUMBER (GetUSBDevices) failed: %s\n", WindowsErrorString());
continue;
}
if (GetDriveLabel(device_number.DeviceNumber + DRIVE_INDEX_MIN, &drive_letter, &label)) {
// Must ensure that the combo box is UNSORTED for indexes to be the same
StrArrayAdd(&DriveID, buffer);
StrArrayAdd(&DriveLabel, label);
safe_sprintf(entry, sizeof(entry), "%s (%c:)", label, drive_letter);
IGNORE_RETVAL(ComboBox_SetItemData(hDeviceList, ComboBox_AddStringU(hDeviceList, entry),
device_number.DeviceNumber + DRIVE_INDEX_MIN));
safe_closehandle(hDrive);
safe_free(devint_detail_data);
break;
}
}
}
IGNORE_RETVAL(ComboBox_SetCurSel(hDeviceList, 0));
SendMessage(hMainDialog, WM_COMMAND, (CBN_SELCHANGE<<16) | IDC_DEVICE, 0);
return TRUE;
}
/*
* Toggle controls according to operation
*/
static void EnableControls(BOOL bEnable)
{
int fs;
EnableWindow(GetDlgItem(hMainDialog, IDC_DEVICE), bEnable);
EnableWindow(GetDlgItem(hMainDialog, IDC_CAPACITY), bEnable);
EnableWindow(GetDlgItem(hMainDialog, IDC_FILESYSTEM), bEnable);
EnableWindow(GetDlgItem(hMainDialog, IDC_CLUSTERSIZE), bEnable);
EnableWindow(GetDlgItem(hMainDialog, IDC_LABEL), bEnable);
EnableWindow(GetDlgItem(hMainDialog, IDC_QUICKFORMAT), bEnable);
if (bEnable) {
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
EnableWindow(GetDlgItem(hMainDialog, IDC_DOS), (fs == FS_FAT16) || (fs == FS_FAT32));
} else {
EnableWindow(GetDlgItem(hMainDialog, IDC_DOS), FALSE);
}
EnableWindow(GetDlgItem(hMainDialog, IDC_ABOUT), bEnable);
EnableWindow(GetDlgItem(hMainDialog, IDC_START), bEnable);
SetDlgItemTextA(hMainDialog, IDCANCEL, bEnable?"Close":"Cancel");
}
/*
* Main dialog callback
*/
#ifndef PBS_MARQUEE // Some versions of MinGW don't know these
#define PBS_MARQUEE 0x08
#endif
#ifndef PBM_SETMARQUEE
#define PBM_SETMARQUEE (WM_USER+10)
#endif
static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
HICON hSmallIcon, hBigIcon;
int nDeviceIndex, fs;
DWORD DeviceNum;
char str[MAX_PATH], tmp[128];
static uintptr_t format_thid = -1L;
static HWND hProgress, hDOS;
static LONG ProgressStyle = 0;
static UINT uDOSChecked = BST_CHECKED;
switch (message) {
case WM_DEVICECHANGE:
if ( (format_thid == -1L) &&
((wParam == DBT_DEVICEARRIVAL) || (wParam == DBT_DEVICEREMOVECOMPLETE)) ) {
GetUSBDevices();
return (INT_PTR)TRUE;
}
break;
case WM_INITDIALOG:
hMainDialog = hDlg;
hDeviceList = GetDlgItem(hDlg, IDC_DEVICE);
hCapacity = GetDlgItem(hDlg, IDC_CAPACITY);
hFileSystem = GetDlgItem(hDlg, IDC_FILESYSTEM);
hClusterSize = GetDlgItem(hDlg, IDC_CLUSTERSIZE);
hLabel = GetDlgItem(hDlg, IDC_LABEL);
hProgress = GetDlgItem(hDlg, IDC_PROGRESS);
hDOS = GetDlgItem(hDlg, IDC_DOS);
// High DPI scaling
hDC = GetDC(hDlg);
fScale = GetDeviceCaps(hDC, LOGPIXELSX) / 96.0f;
ReleaseDC(hDlg, hDC);
// Create the title bar icon
hSmallIcon = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
SendMessage (hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hSmallIcon);
hBigIcon = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
SendMessage (hDlg, WM_SETICON, ICON_BIG, (LPARAM)hBigIcon);
// Create the status line
hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hMainDialog, (HMENU)IDC_STATUS, hMainInstance, NULL);
// We'll switch the progressbar to marquee and back => keep a copy of current style
ProgressStyle = GetWindowLong(hProgress, GWL_STYLE);
// Create the string array
StrArrayCreate(&DriveID, MAX_DRIVES);
StrArrayCreate(&DriveLabel, MAX_DRIVES);
// Set the quick format & create DOS disk checkboxes
CheckDlgButton(hDlg, IDC_QUICKFORMAT, BST_CHECKED);
CheckDlgButton(hDlg, IDC_DOS, BST_CHECKED);
GetUSBDevices();
return (INT_PTR)TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK: // close application
case IDCANCEL:
if (format_thid != -1L) {
if (MessageBoxA(hMainDialog, "Cancelling may leave the device in an UNUSABLE state.\r\n"
"If you are sure you want to cancel, click YES. Otherwise, click NO.",
RUFUS_CANCELBOX_TITLE, MB_YESNO|MB_ICONWARNING) == IDYES) {
// Operation may have completed in the meantime
if (format_thid != -1L) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED;
PrintStatus("Cancelling - please wait...");
}
}
return (INT_PTR)TRUE;
}
PostQuitMessage(0);
StrArrayDestroy(&DriveID);
StrArrayDestroy(&DriveLabel);
DestroyAllTooltips();
EndDialog(hDlg, 0);
break;
case IDC_ABOUT:
CreateAboutBox();
break;
case IDC_DEVICE:
switch (HIWORD(wParam)) {
case CBN_SELCHANGE:
PrintStatus("%d device%s found.", ComboBox_GetCount(hDeviceList),
(ComboBox_GetCount(hDeviceList)!=1)?"s":"");
PopulateProperties(ComboBox_GetCurSel(hDeviceList));
break;
}
break;
case IDC_FILESYSTEM:
switch (HIWORD(wParam)) {
case CBN_SELCHANGE:
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
SetClusterSizes(fs);
// Disable/Restore the DOS checkbox according to FS
if ((fs == FS_FAT16) || (fs == FS_FAT32)) {
if (!IsWindowEnabled(hDOS)) {
EnableWindow(hDOS, TRUE);
CheckDlgButton(hDlg, IDC_DOS, uDOSChecked);
}
} else {
if (IsWindowEnabled(hDOS)) {
uDOSChecked = IsDlgButtonChecked(hMainDialog, IDC_DOS);
CheckDlgButton(hDlg, IDC_DOS, BST_UNCHECKED);
EnableWindow(hDOS, FALSE);
}
}
break;
}
break;
case IDC_START:
if (format_thid != -1L) {
return (INT_PTR)TRUE;
}
nDeviceIndex = ComboBox_GetCurSel(hDeviceList);
if (nDeviceIndex != CB_ERR) {
GetWindowTextA(hDeviceList, tmp, sizeof(tmp));
safe_sprintf(str, sizeof(str), "WARNING: ALL DATA ON DEVICE %s\r\nWILL BE DESTROYED.\r\n"
"To continue with this operation, click OK. To quit click CANCEL.", tmp);
if (MessageBoxA(hMainDialog, str, "Rufus", MB_OKCANCEL|MB_ICONWARNING) == IDOK) {
// Disable all controls except cancel
EnableControls(FALSE);
// Handle marquee progress bar on quickformat
SetWindowLongPtr(hProgress, GWL_STYLE, ProgressStyle | (IsChecked(IDC_QUICKFORMAT)?PBS_MARQUEE:0));
if (IsChecked(IDC_QUICKFORMAT)) {
SendMessage(hProgress, PBM_SETMARQUEE, TRUE, 0);
}
DeviceNum = (DWORD)ComboBox_GetItemData(hDeviceList, nDeviceIndex);
FormatStatus = 0;
format_thid = _beginthread(FormatThread, 0, (void*)(uintptr_t)DeviceNum);
if (format_thid == -1L) {
uprintf("Unable to start formatting thread");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_START_THREAD);
PostMessage(hMainDialog, UM_FORMAT_COMPLETED, 0, 0);
}
}
}
break;
default:
return (INT_PTR)FALSE;
}
return (INT_PTR)TRUE;
case WM_CLOSE:
if (format_thid != -1L) {
return (INT_PTR)TRUE;
}
PostQuitMessage(0);
break;
case UM_FORMAT_PROGRESS:
SendMessage(hProgress, PBM_SETPOS, wParam, lParam);
return (INT_PTR)TRUE;
case UM_FORMAT_COMPLETED:
format_thid = -1L;
// Close the cancel MessageBox if active
SendMessage(FindWindowA(MAKEINTRESOURCEA(32770), RUFUS_CANCELBOX_TITLE), WM_COMMAND, IDNO, 0);
if (IsChecked(IDC_QUICKFORMAT)) {
SendMessage(hProgress, PBM_SETMARQUEE, FALSE, 0);
SetWindowLongPtr(hProgress, GWL_STYLE, ProgressStyle);
// This is the only way to achieve instantenous progress transition
SendMessage(hProgress, PBM_SETRANGE, 0, 101<<16);
SendMessage(hProgress, PBM_SETPOS, 101, 0);
SendMessage(hProgress, PBM_SETRANGE, 0, 100<<16);
}
SendMessage(hProgress, PBM_SETPOS, FormatStatus?0:100, 0);
EnableControls(TRUE);
GetUSBDevices();
if (!IS_ERROR(FormatStatus)) {
PrintStatus("DONE");
} else if (SCODE_CODE(FormatStatus) == ERROR_CANCELLED) {
PrintStatus("Cancelled");
Notification(MSG_INFO, "Cancelled", "Operation cancelled by the user.");
} else {
PrintStatus("FAILED");
Notification(MSG_ERROR, "Error", "Error: %s", StrError(FormatStatus));
}
return (INT_PTR)TRUE;
}
return (INT_PTR)FALSE;
}
/*
* Application Entrypoint
*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HANDLE mutex = NULL;
HWND hDlg = NULL;
MSG msg;
uprintf("*** RUFUS INIT ***\n");
// Prevent 2 applications from running at the same time
mutex = CreateMutexA(NULL, TRUE, "Global/RUFUS");
if ((mutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS))
{
MessageBoxA(NULL, "Another Rufus application is running.\n"
"Please close the first application before running another one.",
"Other instance detected", MB_ICONSTOP);
return 0;
}
// Save instance of the application for further reference
hMainInstance = hInstance;
// Initialize COM for folder selection
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
// Create the main Window
if ( (hDlg = CreateDialogA(hInstance, MAKEINTRESOURCEA(IDD_DIALOG), NULL, MainCallback)) == NULL ) {
MessageBoxA(NULL, "Could not create Window", "DialogBox failure", MB_ICONSTOP);
goto out;
}
CenterDialog(hDlg);
ShowWindow(hDlg, SW_SHOWNORMAL);
UpdateWindow(hDlg);
// Do our own event processing
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
out:
CloseHandle(mutex);
uprintf("*** RUFUS EXIT ***\n");
#ifdef _CRTDBG_MAP_ALLOC
_CrtDumpMemoryLeaks();
#endif
return 0;
}

185
src/rufus.h Normal file
View file

@ -0,0 +1,185 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <windows.h>
#include <winioctl.h> // for DISK_GEOMETRY
#pragma once
#define RUFUS_DEBUG
#define STR_NO_LABEL "NO_LABEL"
#define RUFUS_CANCELBOX_TITLE "Rufus - Cancellation"
#define DRIVE_INDEX_MIN 0x80
#define DRIVE_INDEX_MAX 0xC0
#define MAX_DRIVES 16
#define MAX_TOOLTIPS 16
#define PROPOSEDLABEL_TOLERANCE 0.10
#define FS_DEFAULT FS_FAT32
#define WHITE RGB(255,255,255)
#define SEPARATOR_GREY RGB(223,223,223)
#define RUFUS_URL "https://github.com/pbatard/rufus/wiki/Rufus"
#define BUG_URL "https://github.com/pbatard/rufus/issues"
#define IGNORE_RETVAL(expr) do { (void)(expr); } while(0)
#ifndef ARRAYSIZE
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
#endif
#define IsChecked(CheckBox_ID) (IsDlgButtonChecked(hMainDialog, CheckBox_ID) == BST_CHECKED)
#define safe_free(p) do {free((void*)p); p = NULL;} while(0)
#define safe_closehandle(h) do {if (h != INVALID_HANDLE_VALUE) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
#define safe_min(a, b) min((size_t)(a), (size_t)(b))
#define safe_strcp(dst, dst_max, src, count) do {memcpy(dst, src, safe_min(count, dst_max)); \
((char*)dst)[safe_min(count, dst_max)-1] = 0;} while(0)
#define safe_strcpy(dst, dst_max, src) safe_strcp(dst, dst_max, src, safe_strlen(src)+1)
#define safe_strncat(dst, dst_max, src, count) strncat(dst, src, safe_min(count, dst_max - safe_strlen(dst) - 1))
#define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, safe_strlen(src)+1)
#define safe_strcmp(str1, str2) strcmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2))
#define safe_stricmp(str1, str2) _stricmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2))
#define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2), count)
#define safe_closehandle(h) do {if (h != INVALID_HANDLE_VALUE) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
#define safe_unlockclose(h) do {if (h != INVALID_HANDLE_VALUE) {UnlockDrive(h); CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
#define safe_sprintf _snprintf
#define safe_strlen(str) ((((char*)str)==NULL)?0:strlen(str))
#define safe_strdup _strdup
#if defined(_MSC_VER)
#define safe_vsnprintf(buf, size, format, arg) _vsnprintf_s(buf, size, _TRUNCATE, format, arg)
#else
#define safe_vsnprintf vsnprintf
#endif
#ifdef RUFUS_DEBUG
extern void _uprintf(const char *format, ...);
#define uprintf(...) _uprintf(__VA_ARGS__)
#else
#define uprintf(...)
#endif
/* Custom Windows messages */
enum user_message_type {
UM_FORMAT_PROGRESS = WM_APP,
UM_FORMAT_COMPLETED
};
/* Custom notifications */
enum MessageType {
MSG_INFO,
MSG_WARNING,
MSG_ERROR
};
/* File system indexes in our FS combobox */
// TODO: FormatEx should support "NTFS", "FAT", "FAT32", "UDF", and "EXFAT" as per
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa819439.aspx
enum {
FS_UNKNOWN = -1,
FS_FAT16 = 0,
FS_FAT32,
FS_NTFS,
FS_EXFAT,
FS_MAX
};
/* Current drive info */
typedef struct {
DWORD DeviceNumber;
LONGLONG DiskSize;
DISK_GEOMETRY Geometry;
DWORD FirstSector;
int FSType;
struct {
ULONG Allowed;
ULONG Default;
} ClusterSize[FS_MAX];
} RUFUS_DRIVE_INFO;
/*
* Globals
*/
extern HINSTANCE hMainInstance;
extern HWND hMainDialog, hStatus, hDeviceList, hCapacity;
extern HWND hFileSystem, hClusterSize, hLabel;
extern float fScale;
extern char szFolderPath[MAX_PATH];
extern DWORD FormatStatus;
extern RUFUS_DRIVE_INFO SelectedDrive;
/*
* Shared prototypes
*/
extern const char *WindowsErrorString(void);
extern void DumpBufferHex(void *buf, size_t size);
extern void PrintStatus(const char *format, ...);
extern const char* StrError(DWORD error_code);
extern void CenterDialog(HWND hDlg);
extern void CreateStatusBar(void);
extern INT_PTR CreateAboutBox(void);
extern HWND CreateTooltip(HWND hControl, const char* message, int duration);
extern void DestroyTooltip(HWND hWnd);
extern void DestroyAllTooltips(void);
extern BOOL Notification(int type, char* title, char* format, ...);
extern BOOL ExtractMSDOS(const char* path);
extern void __cdecl FormatThread(void* param);
extern BOOL CreatePartition(HANDLE hDrive);
extern HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BOOL bLockDrive);
extern BOOL GetDriveLabel(DWORD DriveIndex, char* letter, char** label);
__inline static BOOL UnlockDrive(HANDLE hDrive)
{
DWORD size;
return DeviceIoControl(hDrive, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL);
}
/* Basic String Array */
typedef struct {
char** Table;
size_t Size;
size_t Index;
size_t Max;
} StrArray;
extern void StrArrayCreate(StrArray* arr, size_t initial_size);
extern void StrArrayAdd(StrArray* arr, const char* str);
extern void StrArrayClear(StrArray* arr);
extern void StrArrayDestroy(StrArray* arr);
/* Clang/MinGW32 has an issue with intptr_t */
#ifndef _UINTPTR_T_DEFINED
#define _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else
typedef unsigned int uintptr_t;
#endif
#endif
/* We need a redef of this MS structure */
typedef struct {
DWORD DeviceType;
ULONG DeviceNumber;
ULONG PartitionNumber;
} STORAGE_DEVICE_NUMBER_REDEF;
/* Custom application errors */
#define FAC(f) (f<<16)
#define APPERR(err) (APPLICATION_ERROR_MASK|err)
#define ERROR_INCOMPATIBLE_FS 0x1201
#define ERROR_CANT_QUICK_FORMAT 0x1202
#define ERROR_INVALID_CLUSTER_SIZE 0x1203
#define ERROR_INVALID_VOLUME_SIZE 0x1204
#define ERROR_CANT_START_THREAD 0x1205

BIN
src/rufus.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

226
src/rufus.rc Normal file
View file

@ -0,0 +1,226 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
#pragma code_page(1252)
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG DIALOGEX 12, 12, 206, 263
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.0.1.71"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,223,50,14
PUSHBUTTON "Close",IDCANCEL,148,223,50,14
COMBOBOX IDC_DEVICE,8,17,190,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "&Device",IDC_STATIC,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,9,6,22,8
COMBOBOX IDC_FILESYSTEM,8,75,190,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&File system",IDC_STATIC,9,64,51,10
COMBOBOX IDC_CAPACITY,8,46,190,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
LTEXT "Ca&pacity",IDC_STATIC,9,35,29,8
COMBOBOX IDC_CLUSTERSIZE,8,104,190,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&Allocation unit size",IDC_STATIC,9,93,105,10
PUSHBUTTON "About...",IDC_ABOUT,8,223,50,14
GROUPBOX "Format Options",IDC_STATIC,7,149,189,40
EDITTEXT IDC_LABEL,7,131,190,13,ES_AUTOHSCROLL
CONTROL "&Quick Format",IDC_QUICKFORMAT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,161,58,10
CONTROL "Create an &MS-DOS startup disk",IDC_DOS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,173,115,10
LTEXT "New volume &label",IDC_STATIC,9,121,105,10
CONTROL "",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | WS_BORDER,7,197,189,9
END
IDD_ABOUTBOX DIALOGEX 0, 0, 287, 195
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Rufus"
FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
BEGIN
ICON IDI_ICON,IDC_ABOUT_ICON,11,8,20,20
LTEXT "Rufus - The Resourceful USB Formatting Utility *BETA*",IDC_RUFUS_BOLD,46,8,240,10,SS_NOPREFIX | SS_NOTIFY
LTEXT "Copyright (c) 2011 Pete Batard",IDC_STATIC,46,36,139,8
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
CONTROL "<a href=""https://github.com/pbatard/rufus/wiki/Rufus"">https://github.com/pbatard/rufus</a>",IDC_ABOUT_RUFUS_URL,
"SysLink",WS_TABSTOP,46,47,114,9
LTEXT "Version 1.0.1 (Build 71)",IDC_STATIC,46,19,78,8
PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP
EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL
LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
LTEXT "Portions copyright:",IDC_STATIC,46,95,59,8
CONTROL "<a>https://github.com/pbatard/rufus/issues</a>",IDC_ABOUT_BUG_URL,
"SysLink",WS_TABSTOP,46,76,203,14
END
IDD_NOTIFICATION DIALOGEX 0, 0, 263, 63
STYLE DS_SETFONT | DS_FIXEDSYS | DS_NOFAILCREATE | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME
CAPTION "Rufus"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "",IDC_NOTIFICATION_LINE,0,0,263,39
CONTROL "",IDC_STATIC,"Static",SS_WHITERECT,0,0,263,38
ICON 32516,IDC_NOTIFICATION_ICON,6,6,20,20
LTEXT "",IDC_NOTIFICATION_TEXT,35,10,219,20
DEFPUSHBUTTON "Close",IDCANCEL,211,44,50,14
END
IDD_LICENSE DIALOGEX 0, 0, 335, 205
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus License"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Close",IDOK,278,187,50,14
EDITTEXT IDC_LICENSE_TEXT,7,7,321,176,ES_MULTILINE | ES_READONLY | WS_VSCROLL
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include <windows.h>\r\n"
"#ifndef IDC_STATIC\r\n"
"#define IDC_STATIC -1\r\n"
"#endif\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"// Must reference a manifest for visual styles and elevation\r\n"
"// Oh, and it must happen at the end, or MinGW will ignore it!\r\n"
"#if defined(__GNUC__)\r\n"
"CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST ""common_controls_and_elevation.manifest""\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG, DIALOG
BEGIN
BOTTOMMARGIN, 249
END
IDD_ABOUTBOX, DIALOG
BEGIN
END
IDD_NOTIFICATION, DIALOG
BEGIN
END
IDD_LICENSE, DIALOG
BEGIN
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,1,71
PRODUCTVERSION 1,0,1,71
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000904b0"
BEGIN
VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.0.1.71"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.0.1.71"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x9, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON ICON "rufus.ico"
#endif // English resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
// Must reference a manifest for visual styles and elevation
// Oh, and it must happen at the end, or MinGW will ignore it!
#if defined(__GNUC__)
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "common_controls_and_elevation.manifest"
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

200
src/stdio.c Normal file
View file

@ -0,0 +1,200 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* Standard I/O Routines (logging, status, etc.)
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "msapi_utf8.h"
#include "rufus.h"
#include "resource.h"
/*
* Globals
*/
HWND hStatus;
#ifdef RUFUS_DEBUG
void _uprintf(const char *format, ...)
{
char buf[4096], *p = buf;
va_list args;
int n;
va_start(args, format);
n = safe_vsnprintf(p, sizeof(buf)-3, format, args); // buf-3 is room for CR/LF/NUL
va_end(args);
p += (n < 0)?sizeof(buf)-3:n;
while((p>buf) && (isspace(p[-1])))
*--p = '\0';
*p++ = '\r';
*p++ = '\n';
*p = '\0';
OutputDebugStringA(buf);
}
#endif
void DumpBufferHex(void *buf, size_t size)
{
unsigned char* buffer = (unsigned char*)buf;
size_t i, j, k;
char line[80] = "";
for (i=0; i<size; i+=16) {
if (i!=0)
uprintf("%s\n", line);
line[0] = 0;
sprintf(&line[strlen(line)], " %08x ", (unsigned int)i);
for(j=0,k=0; k<16; j++,k++) {
if (i+j < size) {
sprintf(&line[strlen(line)], "%02x", buffer[i+j]);
} else {
sprintf(&line[strlen(line)], " ");
}
sprintf(&line[strlen(line)], " ");
}
sprintf(&line[strlen(line)], " ");
for(j=0,k=0; k<16; j++,k++) {
if (i+j < size) {
if ((buffer[i+j] < 32) || (buffer[i+j] > 126)) {
sprintf(&line[strlen(line)], ".");
} else {
sprintf(&line[strlen(line)], "%c", buffer[i+j]);
}
}
}
}
uprintf("%s\n", line);
}
/*
* Convert a windows error to human readable string
* uses retval as errorcode, or, if 0, use GetLastError()
*/
const char *WindowsErrorString(void)
{
static char err_string[256];
DWORD size;
DWORD error_code, format_error;
error_code = GetLastError();
safe_sprintf(err_string, sizeof(err_string), "[0x%08X] ", error_code);
size = FormatMessageU(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &err_string[strlen(err_string)],
sizeof(err_string)-(DWORD)strlen(err_string), NULL);
if (size == 0) {
format_error = GetLastError();
if ((format_error) && (format_error != 0x13D)) // 0x13D, decode error, is returned for unknown codes
safe_sprintf(err_string, sizeof(err_string),
"Windows error code 0x%08X (FormatMessage error code 0x%08X)", error_code, format_error);
else
safe_sprintf(err_string, sizeof(err_string), "Unknown error 0x%08X", error_code);
}
return err_string;
}
void PrintStatus(const char *format, ...)
{
char buf[256], *p = buf;
va_list args;
int n;
va_start(args, format);
n = safe_vsnprintf(p, sizeof(buf)-1, format, args); // room for NUL
va_end(args);
p += (n < 0)?sizeof(buf)-1:n;
while((p>buf) && (isspace(p[-1])))
*--p = '\0';
*p = '\0';
SetDlgItemTextU(hMainDialog, IDC_STATUS, buf);
}
const char* StrError(DWORD error_code)
{
if ( (!IS_ERROR(error_code)) || (SCODE_CODE(error_code) == ERROR_SUCCESS)) {
return "Success";
}
if (SCODE_FACILITY(error_code) != FACILITY_STORAGE) {
uprintf("StrError: non storage - %08X (%X)\n", error_code, SCODE_FACILITY(error_code));
SetLastError(error_code);
return WindowsErrorString();
}
switch (SCODE_CODE(error_code)) {
case ERROR_GEN_FAILURE:
return "Undetermined error while formatting";
case ERROR_INCOMPATIBLE_FS:
return "Cannot use the selected file system for this media";
case ERROR_ACCESS_DENIED:
return "Access to the media is denied";
case ERROR_WRITE_PROTECT:
return "Media is write protected";
case ERROR_DEVICE_IN_USE:
return "The device is in use by another process\n"
"Please close any other process that may be accessing the device";
case ERROR_CANT_QUICK_FORMAT:
return "Quick format is not available for this device";
case ERROR_LABEL_TOO_LONG:
return "The volume label is invalid";
case ERROR_INVALID_CLUSTER_SIZE:
return "The selected allocation unit size is not valid for this device";
case ERROR_INVALID_VOLUME_SIZE:
return "The volume size is invalid";
case ERROR_NO_MEDIA_IN_DRIVE:
return "Please insert a media in drive";
case ERROR_NOT_SUPPORTED:
return "An unsupported command was received";
case ERROR_NOT_ENOUGH_MEMORY:
return "Memory allocation error";
case ERROR_READ_FAULT:
return "Read error";
case ERROR_WRITE_FAULT:
return "Write error";
case ERROR_OPEN_FAILED:
return "Could not open media";
case ERROR_PARTITION_FAILURE:
return "Error while partitioning drive";
case ERROR_CANNOT_COPY:
return "Could not copy MS-DOS files";
case ERROR_CANCELLED:
return "Cancelled by user";
case ERROR_CANT_START_THREAD:
return "Unable to create formatting thread";
default:
uprintf("StrError: hit default - %08X\n", error_code);
SetLastError(error_code);
return WindowsErrorString();
}
}

653
src/stdlg.c Normal file
View file

@ -0,0 +1,653 @@
/*
* Rufus: The Resourceful USB Formatting Utility
* Standard Dialog Routines (Browse for folder, About, etc)
* Copyright (c) 2011 Pete Batard <pete@akeo.ie>
*
* Based on zadig_stdlg.c, part of libwdi: http://libwdi.sf.net
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Memory leaks detection - define _CRTDBG_MAP_ALLOC as preprocessor macro */
#ifdef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <shlobj.h>
#include <commdlg.h>
#include "rufus.h"
#include "msapi_utf8.h"
#include "resource.h"
#include "license.h"
/* Windows versions */
enum WindowsVersion {
WINDOWS_UNDEFINED,
WINDOWS_UNSUPPORTED,
WINDOWS_2K,
WINDOWS_XP,
WINDOWS_2003_XP64,
WINDOWS_VISTA,
WINDOWS_7,
WINDOWS_8
};
/* The following is only available on Vista and later */
#if (_WIN32_WINNT >= 0x0600)
static HRESULT (WINAPI *pSHCreateItemFromParsingName)(PCWSTR, IBindCtx*, REFIID, void **) = NULL;
#endif
#define INIT_VISTA_SHELL32 if (pSHCreateItemFromParsingName == NULL) { \
pSHCreateItemFromParsingName = (HRESULT (WINAPI *)(PCWSTR, IBindCtx*, REFIID, void **)) \
GetProcAddress(GetModuleHandleA("SHELL32"), "SHCreateItemFromParsingName"); \
}
#define IS_VISTA_SHELL32_AVAILABLE (pSHCreateItemFromParsingName != NULL)
// And this one is simply not available in MinGW32
static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPath)(PCWSTR pszPath) = NULL;
#define INIT_XP_SHELL32 if (pSHSimpleIDListFromPath == NULL) { \
pSHSimpleIDListFromPath = (LPITEMIDLIST (WINAPI *)(PCWSTR)) \
GetProcAddress(GetModuleHandleA("SHELL32"), "SHSimpleIDListFromPath"); \
}
/* Globals */
static HICON hMessageIcon = (HICON)INVALID_HANDLE_VALUE;
static char* szMessageText = NULL;
static char* szMessageTitle = NULL;
enum WindowsVersion nWindowsVersion = WINDOWS_UNSUPPORTED;
static HWND hBrowseEdit;
static WNDPROC pOrgBrowseWndproc;
HFONT hBoldFont = NULL;
/*
* Detect Windows version
*/
void DetectWindowsVersion(void)
{
OSVERSIONINFO OSVersion;
memset(&OSVersion, 0, sizeof(OSVERSIONINFO));
OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
nWindowsVersion = WINDOWS_UNSUPPORTED;
if ((GetVersionEx(&OSVersion) != 0) && (OSVersion.dwPlatformId == VER_PLATFORM_WIN32_NT)) {
if ((OSVersion.dwMajorVersion == 5) && (OSVersion.dwMinorVersion == 0)) {
nWindowsVersion = WINDOWS_2K;
} else if ((OSVersion.dwMajorVersion == 5) && (OSVersion.dwMinorVersion == 1)) {
nWindowsVersion = WINDOWS_XP;
} else if ((OSVersion.dwMajorVersion == 5) && (OSVersion.dwMinorVersion == 2)) {
nWindowsVersion = WINDOWS_2003_XP64;
} else if (OSVersion.dwMajorVersion == 6) {
if (OSVersion.dwBuildNumber < 7000) {
nWindowsVersion = WINDOWS_VISTA;
} else {
nWindowsVersion = WINDOWS_7;
}
} else if (OSVersion.dwMajorVersion >= 8) {
nWindowsVersion = WINDOWS_8;
}
}
}
/*
* String array manipulation
*/
void StrArrayCreate(StrArray* arr, size_t initial_size)
{
if (arr == NULL) return;
arr->Max = initial_size; arr->Index = 0;
arr->Table = (char**)calloc(arr->Max, sizeof(char*));
if (arr->Table == NULL)
uprintf("Could not allocate string array\n");
}
void StrArrayAdd(StrArray* arr, const char* str)
{
if ((arr == NULL) || (arr->Table == NULL))
return;
if (arr->Index == arr->Max) {
arr->Max *= 2;
arr->Table = (char**)realloc(arr->Table, arr->Max*sizeof(char*));
if (arr->Table == NULL) {
uprintf("Could not reallocate string array\n");
return;
}
}
arr->Table[arr->Index] = safe_strdup(str);
if (arr->Table[arr->Index++] == NULL) {
uprintf("Could not store string in array\n");
}
}
void StrArrayClear(StrArray* arr)
{
size_t i;
if ((arr == NULL) || (arr->Table == NULL))
return;
for (i=0; i<arr->Index; i++) {
safe_free(arr->Table[i]);
}
arr->Index = 0;
}
void StrArrayDestroy(StrArray* arr)
{
StrArrayClear(arr);
safe_free(arr->Table);
}
/*
* We need a sub-callback to read the content of the edit box on exit and update
* our path, else if what the user typed does match the selection, it is discarded.
* Talk about a convoluted way of producing an intuitive folder selection dialog
*/
INT CALLBACK BrowseDlgCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_DESTROY:
GetWindowTextU(hBrowseEdit, szFolderPath, sizeof(szFolderPath));
break;
}
return (INT)CallWindowProc(pOrgBrowseWndproc, hDlg, message, wParam, lParam);
}
/*
* Main BrowseInfo callback to set the initial directory and populate the edit control
*/
INT CALLBACK BrowseInfoCallback(HWND hDlg, UINT message, LPARAM lParam, LPARAM pData)
{
char dir[MAX_PATH];
wchar_t* wpath;
LPITEMIDLIST pidl;
switch(message) {
case BFFM_INITIALIZED:
pOrgBrowseWndproc = (WNDPROC)SetWindowLongPtr(hDlg, GWLP_WNDPROC, (LONG_PTR)BrowseDlgCallback);
// Windows hides the full path in the edit box by default, which is bull.
// Get a handle to the edit control to fix that
hBrowseEdit = FindWindowExA(hDlg, NULL, "Edit", NULL);
SetWindowTextU(hBrowseEdit, szFolderPath);
SetFocus(hBrowseEdit);
// On XP, BFFM_SETSELECTION can't be used with a Unicode Path in SendMessageW
// or a pidl (at least with MinGW) => must use SendMessageA
if (nWindowsVersion <= WINDOWS_XP) {
SendMessageLU(hDlg, BFFM_SETSELECTION, (WPARAM)TRUE, szFolderPath);
} else {
// On Windows 7, MinGW only properly selects the specified folder when using a pidl
wpath = utf8_to_wchar(szFolderPath);
pidl = (*pSHSimpleIDListFromPath)(wpath);
safe_free(wpath);
// NB: see http://connect.microsoft.com/VisualStudio/feedback/details/518103/bffm-setselection-does-not-work-with-shbrowseforfolder-on-windows-7
// for details as to why we send BFFM_SETSELECTION twice.
SendMessageW(hDlg, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pidl);
Sleep(100);
PostMessageW(hDlg, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pidl);
}
break;
case BFFM_SELCHANGED:
// Update the status
if (SHGetPathFromIDListU((LPITEMIDLIST)lParam, dir)) {
SendMessageLU(hDlg, BFFM_SETSTATUSTEXT, 0, dir);
SetWindowTextU(hBrowseEdit, dir);
}
break;
}
return 0;
}
/*
* Browse for a folder and update the folder edit box
* Will use the newer IFileOpenDialog if *compiled* for Vista or later
*/
void BrowseForFolder(void) {
BROWSEINFOW bi;
LPITEMIDLIST pidl;
#if (_WIN32_WINNT >= 0x0600) // Vista and later
WCHAR *wpath;
size_t i;
HRESULT hr;
IShellItem *psi = NULL;
IShellItem *si_path = NULL; // Automatically freed
IFileOpenDialog *pfod = NULL;
WCHAR *fname;
char* tmp_path = NULL;
// Even if we have Vista support with the compiler,
// it does not mean we have the Vista API available
INIT_VISTA_SHELL32;
if (IS_VISTA_SHELL32_AVAILABLE) {
hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC,
&IID_IFileOpenDialog, (LPVOID)&pfod);
if (FAILED(hr)) {
uprintf("CoCreateInstance for FileOpenDialog failed: error %X", hr);
pfod = NULL; // Just in case
goto fallback;
}
hr = pfod->lpVtbl->SetOptions(pfod, FOS_PICKFOLDERS);
if (FAILED(hr)) {
uprintf("Failed to set folder option for FileOpenDialog: error %X", hr);
goto fallback;
}
// Set the initial folder (if the path is invalid, will simply use last)
wpath = utf8_to_wchar(szFolderPath);
// The new IFileOpenDialog makes us split the path
fname = NULL;
if ((wpath != NULL) && (wcslen(wpath) >= 1)) {
for (i=wcslen(wpath)-1; i!=0; i--) {
if (wpath[i] == L'\\') {
wpath[i] = 0;
fname = &wpath[i+1];
break;
}
}
}
hr = (*pSHCreateItemFromParsingName)(wpath, NULL, &IID_IShellItem, (LPVOID)&si_path);
if (SUCCEEDED(hr)) {
if (wpath != NULL) {
hr = pfod->lpVtbl->SetFolder(pfod, si_path);
}
if (fname != NULL) {
hr = pfod->lpVtbl->SetFileName(pfod, fname);
}
}
safe_free(wpath);
hr = pfod->lpVtbl->Show(pfod, hMainDialog);
if (SUCCEEDED(hr)) {
hr = pfod->lpVtbl->GetResult(pfod, &psi);
if (SUCCEEDED(hr)) {
psi->lpVtbl->GetDisplayName(psi, SIGDN_FILESYSPATH, &wpath);
tmp_path = wchar_to_utf8(wpath);
CoTaskMemFree(wpath);
if (tmp_path == NULL) {
uprintf("Could not convert path");
} else {
safe_strcpy(szFolderPath, MAX_PATH, tmp_path);
safe_free(tmp_path);
}
} else {
uprintf("Failed to set folder option for FileOpenDialog: error %X", hr);
}
} else if ((hr & 0xFFFF) != ERROR_CANCELLED) {
// If it's not a user cancel, assume the dialog didn't show and fallback
uprintf("could not show FileOpenDialog: error %X", hr);
goto fallback;
}
pfod->lpVtbl->Release(pfod);
return;
}
fallback:
if (pfod != NULL) {
pfod->lpVtbl->Release(pfod);
}
#endif
INIT_XP_SHELL32;
memset(&bi, 0, sizeof(BROWSEINFOW));
bi.hwndOwner = hMainDialog;
bi.lpszTitle = L"Please select the installation folder:";
bi.lpfn = BrowseInfoCallback;
// BIF_NONEWFOLDERBUTTON = 0x00000200 is unknown on MinGW
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS |
BIF_DONTGOBELOWDOMAIN | BIF_EDITBOX | 0x00000200;
pidl = SHBrowseForFolderW(&bi);
if (pidl != NULL) {
CoTaskMemFree(pidl);
}
}
void CreateBoldFont(HDC dc) {
TEXTMETRIC tm;
LOGFONT lf;
if (hBoldFont != NULL)
return;
GetTextMetrics(dc, &tm);
lf.lfHeight = tm.tmHeight+1;
lf.lfWidth = tm.tmAveCharWidth+1;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_BOLD;
lf.lfItalic = tm.tmItalic;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = tm.tmStruckOut;
lf.lfCharSet = tm.tmCharSet;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = tm.tmPitchAndFamily;
GetTextFace(dc, LF_FACESIZE, lf.lfFaceName);
hBoldFont = CreateFontIndirect(&lf);
}
/*
* Center a dialog with regards to the main application Window or the desktop
*/
void CenterDialog(HWND hDlg)
{
POINT Point;
HWND hParent;
RECT DialogRect;
RECT ParentRect;
int nWidth;
int nHeight;
// Get the size of the dialog box.
GetWindowRect(hDlg, &DialogRect);
// Get the parent
hParent = GetParent(hDlg);
if (hParent == NULL) {
hParent = GetDesktopWindow();
}
GetClientRect(hParent, &ParentRect);
// Calculate the height and width of the current dialog
nWidth = DialogRect.right - DialogRect.left;
nHeight = DialogRect.bottom - DialogRect.top;
// Find the center point and convert to screen coordinates.
Point.x = (ParentRect.right - ParentRect.left) / 2;
Point.y = (ParentRect.bottom - ParentRect.top) / 2;
ClientToScreen(hParent, &Point);
// Calculate the new x, y starting point.
Point.x -= nWidth / 2;
Point.y -= nHeight / 2 + 35;
// Move the window.
MoveWindow(hDlg, Point.x, Point.y, nWidth, nHeight, FALSE);
}
/*
* License callback
*/
INT_PTR CALLBACK LicenseCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_INITDIALOG:
CenterDialog(hDlg);
SetDlgItemTextA(hDlg, IDC_LICENSE_TEXT, gplv3);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
}
return (INT_PTR)FALSE;
}
/*
* About dialog callback
*/
INT_PTR CALLBACK AboutCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_INITDIALOG:
CenterDialog(hDlg);
SetDlgItemTextA(hDlg, IDC_ABOUT_COPYRIGHTS, additional_copyrights);
break;
case WM_CTLCOLORSTATIC:
if ((HWND)lParam == GetDlgItem(hDlg, IDC_RUFUS_BOLD)) {
CreateBoldFont((HDC)wParam);
SetBkMode((HDC)wParam, TRANSPARENT);
SelectObject((HDC)wParam, hBoldFont);
return (INT_PTR)CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
}
break;
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code) {
case NM_CLICK:
case NM_RETURN:
switch (LOWORD(wParam)) {
case IDC_ABOUT_RUFUS_URL:
ShellExecuteA(hDlg, "open", RUFUS_URL, NULL, NULL, SW_SHOWNORMAL);
break;
case IDC_ABOUT_BUG_URL:
ShellExecuteA(hDlg, "open", BUG_URL, NULL, NULL, SW_SHOWNORMAL);
break;
}
break;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
case IDC_ABOUT_LICENSE:
DialogBoxA(hMainInstance, MAKEINTRESOURCEA(IDD_LICENSE), hDlg, LicenseCallback);
break;
}
break;
}
return (INT_PTR)FALSE;
}
INT_PTR CreateAboutBox(void)
{
return DialogBoxA(hMainInstance, MAKEINTRESOURCEA(IDD_ABOUTBOX), hMainDialog, AboutCallback);
}
/*
* We use our own MessageBox for notifications to have greater control (center, no close button, etc)
*/
INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT loc;
int i;
// Prevent resizing
static LRESULT disabled[9] = { HTLEFT, HTRIGHT, HTTOP, HTBOTTOM, HTSIZE,
HTTOPLEFT, HTTOPRIGHT, HTBOTTOMLEFT, HTBOTTOMRIGHT };
static HBRUSH white_brush, separator_brush;
switch (message) {
case WM_INITDIALOG:
white_brush = CreateSolidBrush(WHITE);
separator_brush = CreateSolidBrush(SEPARATOR_GREY);
CenterDialog(hDlg);
// Change the default icon
if (Static_SetIcon(GetDlgItem(hDlg, IDC_NOTIFICATION_ICON), hMessageIcon) == 0) {
uprintf("could not set dialog icon");
}
// Set the dialog title
if (szMessageTitle != NULL) {
SetWindowTextA(hDlg, szMessageTitle);
}
// Set the control text
if (szMessageText != NULL) {
SetWindowTextA(GetDlgItem(hDlg, IDC_NOTIFICATION_TEXT), szMessageText);
}
return (INT_PTR)TRUE;
case WM_CTLCOLORSTATIC:
// Change the background colour for static text and icon
SetBkMode((HDC)wParam, TRANSPARENT);
if ((HWND)lParam == GetDlgItem(hDlg, IDC_NOTIFICATION_LINE)) {
return (INT_PTR)separator_brush;
}
return (INT_PTR)white_brush;
case WM_NCHITTEST:
// Check coordinates to prevent resize actions
loc = DefWindowProc(hDlg, message, wParam, lParam);
for(i = 0; i < 9; i++) {
if (loc == disabled[i]) {
return (INT_PTR)TRUE;
}
}
return (INT_PTR)FALSE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
/*
* Display a custom notification
*/
BOOL Notification(int type, char* title, char* format, ...)
{
va_list args;
szMessageText = (char*)malloc(MAX_PATH);
if (szMessageText == NULL) return FALSE;
szMessageTitle = title;
va_start(args, format);
safe_vsnprintf(szMessageText, MAX_PATH-1, format, args);
va_end(args);
szMessageText[MAX_PATH-1] = 0;
switch(type) {
case MSG_WARNING:
hMessageIcon = LoadIcon(NULL, IDI_WARNING);
break;
case MSG_ERROR:
hMessageIcon = LoadIcon(NULL, IDI_ERROR);
break;
case MSG_INFO:
default:
hMessageIcon = LoadIcon(NULL, IDI_INFORMATION);
break;
}
DialogBox(hMainInstance, MAKEINTRESOURCE(IDD_NOTIFICATION), hMainDialog, NotificationCallback);
safe_free(szMessageText);
return TRUE;
}
struct {
HWND hTip;
WNDPROC original_proc;
LPWSTR wstring;
} ttlist[MAX_TOOLTIPS] = { {0} };
INT_PTR CALLBACK TooltipCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
LPNMTTDISPINFOW lpnmtdi;
int i = MAX_TOOLTIPS;
// Make sure we have an original proc
for (i=0; i<MAX_TOOLTIPS; i++) {
if (ttlist[i].hTip == hDlg) break;
}
if (i == MAX_TOOLTIPS) {
return (INT_PTR)FALSE;
}
switch (message)
{
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code) {
case TTN_GETDISPINFOW:
lpnmtdi = (LPNMTTDISPINFOW)lParam;
lpnmtdi->lpszText = ttlist[i].wstring;
SendMessage(hDlg, TTM_SETMAXTIPWIDTH, 0, 300);
return (INT_PTR)TRUE;
}
break;
}
return CallWindowProc(ttlist[i].original_proc, hDlg, message, wParam, lParam);
}
/*
* Create a tooltip for the control passed as first parameter
* duration sets the duration in ms. Use -1 for default
* message is an UTF-8 string
*/
HWND CreateTooltip(HWND hControl, const char* message, int duration)
{
TOOLINFOW toolInfo = {0};
int i;
if ( (hControl == NULL) || (message == NULL) ) {
return (HWND)NULL;
}
// Find an empty slot
for (i=0; i<MAX_TOOLTIPS; i++) {
if (ttlist[i].hTip == NULL) break;
}
if (i == MAX_TOOLTIPS) {
uprintf("Maximum number of tooltips reached\n");
return (HWND)NULL;
}
// Create the tooltip window
ttlist[i].hTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hMainDialog, NULL,
hMainInstance, NULL);
if (ttlist[i].hTip == NULL) {
return (HWND)NULL;
}
// Subclass the tooltip to handle multiline
ttlist[i].original_proc = (WNDPROC)SetWindowLongPtr(ttlist[i].hTip, GWLP_WNDPROC, (LONG_PTR)TooltipCallback);
// Set the string to display (can be multiline)
ttlist[i].wstring = utf8_to_wchar(message);
// Set tooltip duration (ms)
PostMessage(ttlist[i].hTip, TTM_SETDELAYTIME, (WPARAM)TTDT_AUTOPOP, (LPARAM)duration);
// Associate the tooltip to the control
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = ttlist[i].hTip; // Set to the tooltip itself to ease up subclassing
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hControl;
toolInfo.lpszText = LPSTR_TEXTCALLBACKW;
SendMessageW(ttlist[i].hTip, TTM_ADDTOOLW, 0, (LPARAM)&toolInfo);
return ttlist[i].hTip;
}
void DestroyTooltip(HWND hWnd)
{
int i;
if (hWnd == NULL) return;
for (i=0; i<MAX_TOOLTIPS; i++) {
if (ttlist[i].hTip == hWnd) break;
}
if (i == MAX_TOOLTIPS) return;
DestroyWindow(hWnd);
safe_free(ttlist[i].wstring);
ttlist[i].original_proc = NULL;
ttlist[i].hTip = NULL;
}
void DestroyAllTooltips(void)
{
int i;
for (i=0; i<MAX_TOOLTIPS; i++) {
if (ttlist[i].hTip == NULL) continue;
DestroyWindow(ttlist[i].hTip);
safe_free(ttlist[i].wstring);
}
}

144
src/sys_types.h Normal file
View file

@ -0,0 +1,144 @@
/*
GNU fdisk - a clone of Linux fdisk.
Copyright (C) 2006
Free Software Foundation, Inc.
This program 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 program 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 program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef SYS_TYPES_H_INCLUDED
#define SYS_TYPES_H_INCLUDED
typedef struct {
unsigned char type;
const char *name;
} SysType;
#define N_(String) String
/* The system types for msdos partition tables
* Needed for lfdisk and some interface improvements
*/
SysType msdos_systypes[] = {
{ 0x00, N_("Empty") },
{ 0x01, N_("FAT12") },
{ 0x02, N_("XENIX root") },
{ 0x03, N_("XENIX usr") },
{ 0x04, N_("Small FAT16") },
{ 0x05, N_("Extended") },
{ 0x06, N_("FAT16") },
{ 0x07, N_("NTFS") },
{ 0x08, N_("AIX") },
{ 0x09, N_("AIX Bootable") },
{ 0x0a, N_("OS/2 Boot Manager") },
{ 0x0b, N_("FAT32") },
{ 0x0c, N_("FAT32 LBA") },
{ 0x0e, N_("FAT16 LBA") },
{ 0x0f, N_("Extended LBA") },
{ 0x10, N_("OPUS") },
{ 0x11, N_("Hidden FAT12") },
{ 0x12, N_("Compaq Diagnostics") },
{ 0x14, N_("Hidden Small FAT16") },
{ 0x16, N_("Hidden FAT16") },
{ 0x17, N_("Hidden NTFS") },
{ 0x18, N_("AST SmartSleep") },
{ 0x1b, N_("Hidden FAT32") },
{ 0x1c, N_("Hidden FAT32 LBA") },
{ 0x1e, N_("Hidden FAT16 LBA") },
{ 0x24, N_("NEC DOS") },
{ 0x27, N_("Hidden NTFS WinRE") },
{ 0x39, N_("Plan 9") },
{ 0x3c, N_("PMagic recovery") },
{ 0x40, N_("Venix 80286") },
{ 0x41, N_("PPC PReP Boot") },
{ 0x42, N_("SFS") },
{ 0x4d, N_("QNX4.x") },
{ 0x4e, N_("QNX4.x 2nd Partition") },
{ 0x4f, N_("QNX4.x 3rd Partition") },
{ 0x50, N_("OnTrack DM") },
{ 0x51, N_("OnTrackDM6 Aux1") },
{ 0x52, N_("CP/M") },
{ 0x53, N_("OnTrackDM6 Aux3") },
{ 0x54, N_("OnTrack DM6") },
{ 0x55, N_("EZ Drive") },
{ 0x56, N_("Golden Bow") },
{ 0x5c, N_("Priam Edisk") },
{ 0x61, N_("SpeedStor") },
{ 0x63, N_("GNU HURD/SysV") },
{ 0x64, N_("Netware 286") },
{ 0x65, N_("Netware 386") },
{ 0x70, N_("DiskSec MultiBoot") },
{ 0x75, N_("PC/IX") },
{ 0x80, N_("Minix <1.4a") },
{ 0x81, N_("Minix >1.4b") },
{ 0x82, N_("Linux Swap") },
{ 0x83, N_("Linux") },
{ 0x84, N_("OS/2 Hidden C:") },
{ 0x85, N_("Linux Extended") },
{ 0x86, N_("NTFS Volume Set") },
{ 0x87, N_("NTFS Volume Set") },
{ 0x88, N_("Linux Plaintext") },
{ 0x8e, N_("Linux LVM") },
{ 0x93, N_("Amoeba") },
/*This guys created a seperate partition for badblocks?! */
{ 0x94, N_("Amoeba BBT") },
{ 0x9f, N_("BSD/OS") },
{ 0xa0, N_("Thinkpad Hibernation") },
{ 0xa5, N_("FreeBSD") },
{ 0xa6, N_("OpenBSD") },
{ 0xa7, N_("NeXTSTEP") },
{ 0xa8, N_("Darwin UFS") },
{ 0xa9, N_("NetBSD") },
{ 0xab, N_("Darwin Boot") },
{ 0xaf, N_("HFS/HFS+") },
{ 0xb7, N_("BSDI") },
{ 0xb8, N_("BSDI Swap") },
/* Beware of the Hidden wizard */
{ 0xbb, N_("Boot Wizard Hidden") },
{ 0xbe, N_("Solaris Boot") },
{ 0xbf, N_("Solaris") },
{ 0xc1, N_("DRDOS/2 FAT12") },
{ 0xc4, N_("DRDOS/2 smFAT16") },
{ 0xc6, N_("DRDOS/2 FAT16") },
/* Reminds me of Rush - 2112 */
{ 0xc7, N_("Syrinx") },
{ 0xda, N_("Non-FS Data") },
{ 0xdb, N_("CP/M") },
{ 0xde, N_("Dell Utility") },
/* Should 0x20 be DontBootIt then? */
{ 0xdf, N_("BootIt") },
{ 0xe1, N_("DOS Access") },
{ 0xe3, N_("DOS R/O") },
/*I sense some strange déjà vu */
{ 0xe4, N_("SpeedStor") },
{ 0xfb, N_("VMware VMFS") },
{ 0xfc, N_("VMware VMKCORE") },
{ 0xeb, N_("BeOS") },
{ 0xee, N_("GPT") },
{ 0xef, N_("EFI FAT") },
{ 0xf0, N_("Linux/PA-RISC Boot") },
{ 0xf1, N_("SpeedStor") },
{ 0xf2, N_("DOS secondary") },
/* Are these guys trying for a Guinness record or something? */
{ 0xf4, N_("SpeedStor") },
{ 0xfd, N_("Linux RAID Auto") },
{ 0xfe, N_("LANstep") },
{ 0xff, N_("XENIX BBT") },
{ 0, NULL }
};
#endif