Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Commit [49340e] Maximize Restore History

* ChangeLog: New file.

* .gitignore: Ditto.
* .gitmodules: Ditto.
* Makefile.am: Ditto.
* config.h.in: Ditto.
* configure.ac: Ditto.
* doc/gendef/COPYING: Moved from the gendef/ directory.
* doc/gendef/ChangeLog*: Ditto.
* gendef/Makefile.am: Removed.
* gendef/aclocal.m4: Ditto.
* gendef/config.h.in: Ditto.
* gendef/configure.ac: Ditto.
* gendef/src/*: Moved to gendef/.
* gendef/src: Removed.
* doc/genidl/COPYING: Moved from the genidl/ directory.
* doc/genidl/ChangeLog*: Ditto.
* genidl/Makefile.am: Removed.
* genidl/aclocal.m4: Ditto.
* genidl/config.h.in: Ditto.
* genidl/configure.ac: Ditto.
* genidl/src/*: Moved to genidl/.
* genidl/src: Removed.
* doc/widl/COPYING: New file - version based on source preamble.
* widl/Makefile.am: Removed.
* widl/aclocal.m4: Ditto.
* widl/configure.ac: Ditto.
* widl/include/config.h.in: Ditto.
* widl/include/winbase.h: Ditto.
* widl/include/windef.h: Ditto.
* widl/indlude/winerror.h: Ditto.
* widl/include/winnls.h: Ditto.
* widl/include/winnt.h: Ditto.
* widl/src/*: Moved to widl/.
* widl/src: Removed.
* build-aux: Add submodule.

Earnie Boyd Earnie Boyd 2012-08-08

1 2 3 4 > >> (Page 1 of 4)
added gendef/compat_string.h
added gendef/gendef.h
removed gendef/src
removed gendef/ChangeLog
removed gendef/ChangeLog.2010
removed gendef/ChangeLog.2011
removed gendef/configure.ac
removed genidl/src
removed genidl/COPYING
removed genidl/ChangeLog
removed genidl/ChangeLog.2010
removed genidl/ChangeLog.2011
removed genidl/Makefile.am
removed genidl/aclocal.m4
removed genidl/config.h.in
copied gendef/COPYING -> gendef/fsredir.h
copied gendef/ChangeLog-2009 -> gendef/fsredir.c
copied gendef/Makefile.am -> gendef/compat_string.c
copied gendef/aclocal.m4 -> gendef/gendef.c
copied gendef/config.h.in -> gendef/gendef_def.c
gendef/compat_string.h Diff Switch to side-by-side view
Loading...
gendef/gendef.h Diff Switch to side-by-side view
Loading...
gendef/src
File was removed.
gendef/ChangeLog
File was removed.
gendef/ChangeLog.2010
File was removed.
gendef/ChangeLog.2011
File was removed.
gendef/configure.ac
File was removed.
genidl/src
File was removed.
genidl/COPYING
File was removed.
genidl/ChangeLog
File was removed.
genidl/ChangeLog.2010
File was removed.
genidl/ChangeLog.2011
File was removed.
genidl/Makefile.am
File was removed.
genidl/aclocal.m4
File was removed.
genidl/config.h.in
File was removed.
gendef/COPYING to gendef/fsredir.h
--- a/gendef/COPYING
+++ b/gendef/fsredir.h
@@ -1,21 +1,32 @@
-Copyright (c) 2009 mingw-w64 project
+/*
+   Copyright (c) 2009, 2010 mingw-w64 project
 
-Contributing authors: Kai Tietz, Jonathan Yong
+   Contributing authors: Kai Tietz, Jonathan Yong
 
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+   The above copyright notice and this permission notice shall be included in
+   all copies or substantial portions of the Software.
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+#ifndef FSREDIR_HEADER
+#define FSREDIR_HEADER
+
+#if defined (_WIN32) || defined (__CYGWIN__)
+#define REDIRECTOR 1 /* Allow disabling win64 FS redirection */
+void doredirect(const int redir);
+#endif
+
+#endif
gendef/ChangeLog-2009 to gendef/fsredir.c
--- a/gendef/ChangeLog-2009
+++ b/gendef/fsredir.c
@@ -1,110 +1,65 @@
-2009-12-24  Alon Bar-Lev  <alon.barlev@gmail.com>
+/*
+   Copyright (c) 2009, 2010 mingw-w64 project
 
-	* Makefile.am (gendef_SOURCES): Add src/compat_string.c file.
-	* configure.ac (AC_CHECK_FUNCS): Check for strlwr.
-	* src/compat-string.h: New header.
-	* sre/compat_string.c: New source-file.
-	* Makefile.in: Regenerated.
-	* config.h.in: Likewise.
-	* configure: Likewise.
+   Contributing authors: Kai Tietz, Jonathan Yong
 
-2009-12-23  Kai Tietz  <kai.tietz@onevision.com>
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
 
-	* src/gendef.c: Avoid warnings by building without libmangle.
+   The above copyright notice and this permission notice shall be included in
+   all copies or substantial portions of the Software.
 
-2009-12-13  Jonathan Yong  <jon_y@users.sourceforge.net>
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+#include "fsredir.h"
 
-	* src/gendef.c: Change include path to -I/--include-def-path.
-	Add "Built on __DATE__".
+#ifdef REDIRECTOR
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
 
-2009-12-13  Kai Tietz  <kai.tietz@onevision.com>
+static PVOID revert; /*revert pointer*/
+static HMODULE kernel32handle;
+typedef WINBOOL (__stdcall (*redirector))(PVOID *);
+typedef WINBOOL (__stdcall (*revertor))(PVOID);
+static redirector redirectorfunction; /*Wow64DisableWow64FsRedirection*/
+static revertor revertorfunction;     /*Wow64RevertWow64FsRedirection*/
 
-	* src/gendef.c: Add option -p/-path-defs.
-	* src/gendef_def.c: Add search-paths for def file seeking.
+static void undoredirect(void) {
+    revertorfunction(revert);
+}
 
-2009-12-12  Jonathan Yong  <jon_y@users.sourceforge.net>
-
-	* src/gendef.c (show_usage): Improve help message about -a.
-
-2009-12-12  Kai Tietz  <kai.tietz@onevision.com>
-
-	* src/gendef_def.c: New file.
-	* src/gendef.c: Add config.h header.
-	Add optional use of libmangle.
-	Improved output of .def files.
-	Ouput forwarders, too.
-
-2009-12-12  Jonathan Yong  <jon_y@users.sourceforge.net>
-
-	* configure.ac: Check for libmangle install.
-	* Makefile.am: Add libmangle dependencies.
-
-	* Makefile.am: Add gendef_def.c dependencies.
-	* configure: Regenerate.
-	* Makefile.in: Ditto.
-	* config.h.in: Ditto.
-
-2009-12-11  Kai Tietz  <kai.tietz@onevision.com>
-
-	* src/gendef.c (assume_stdcall): New variable.
-	(opt_chain): Check for -a and --assume-stdcall option.
-	(disassembleRetIntern): Use assume_stdcall for ret.
-
-2009-12-10  Kai Tietz  <kai.tietz@onevision.com>
-
-	* src/gendef.c (decodeMemonic): Fixed typo.
-	(Additionally added more debug output)
-
-2009-12-01  Jonathan Yong  <jon_y@users.sourceforge.net>
-
-	* src/gendef.c (show_usage): New.
-	(main): Use show_usage.
-	(opt_chain): use show_usage.
-
-2009-09-02  Kai Tietz  <kai.tietz@onevision.com>
-
-	* src/gendef.c (disassembleRetIntern): Pre-initialize local
-	variables by zero.
-
-2009-08-17  Kai Tietz  <kai.tietz@onevision.com>
-
-	* gendef.h, gendef.c: Add BSD license.
-	* COPYING: New file.
-
-2009-02-18  Kai Tietz  <kai.tietz@onevision.com>
-
-	* gendef.c (main): Check if gPEDta or gPEPDta is
-	valid, before trying to dump.
-
-2009-01-15  Kai Tietz  <kai.tietz@onevision.com>
-
-	* gendef.c (is_reloc): New.
-	(is_data): Check if va is relocated.
-
-2009-01-14  Kai Tietz  <kai.tietz@onevision.com>
-
-	* gendef.h (IMAGE_FIRST_SECTION): Added.
-	(Gendefopts): Added.
-	(sExportName): Moved from gendef.c.
-	(eOpCodeKind): Likewise.
-	(sAddresses): Likewise.
-	* gendef.c: Remove unused nacro,
-	(IMAGE_DIRECTORY_ENTRY_EXPORT): Removed.
-	(sExportName): Moved to header.
-	(eOpCodeKind): Likewise.
-	(sAddresses): Likewise.
-
-2009-01-07  jonY  <10walls@gmail.com>
-
-	* gendef.c (struct gendefopts): New.
-	(opt_chain): New.
-	(std_output): New.
-	(main): Use opt_chain.
-	(dump_def): Treat std_output.
-	(load_pep): Adjust error messages.
-
-2009-01-07  Kai Tietz  <kai.tietz@onevision.com>
-
-	* gendef.c: New.
-	* gendef.h: New.
-
+void doredirect(const int redir) {
+  if (redir) {
+    kernel32handle = GetModuleHandleW(L"kernel32.dll");
+    if (!kernel32handle) {
+      fprintf(stderr, "kernel32.dll failed to load, failed to disable FS redirection.\n");
+      return;
+    }
+    redirectorfunction = (redirector)GetProcAddress(kernel32handle, "Wow64DisableWow64FsRedirection");
+    revertorfunction = (revertor)GetProcAddress(kernel32handle, "Wow64RevertWow64FsRedirection");
+    if (!redirectorfunction || ! revertorfunction) {
+      FreeLibrary(kernel32handle);
+      fprintf(stderr, "Wow64DisableWow64FsRedirection or Wow64RevertWow64FsRedirection functions missing.\n");
+      return;
+    }
+    if (!redirectorfunction(&revert)) {
+      fprintf(stderr, "Wow64DisableWow64FsRedirection failed.\n");
+      return;
+    } else {
+      atexit(undoredirect);
+    }
+  }
+}
+#endif
gendef/Makefile.am to gendef/compat_string.c
--- a/gendef/Makefile.am
+++ b/gendef/compat_string.c
@@ -1,11 +1,19 @@
-bin_PROGRAMS = gendef
-AM_LDFLAGS = @GENDEF_LDFLAGS@
-AM_CPPFLAGS = @GENDEF_CPPFLAGS@
+#ifdef CONFIG_H
+#include <config.h>
+#endif
 
-gendef_SOURCES = src/gendef.h src/compat_string.h src/gendef.c src/gendef_def.c src/compat_string.c \
-                 src/fsredir.c src/fsredir.h
-gendef_CFLAGS = $(AM_CFLAGS) -O3 -g -Werror -Wall -Wextra
+#ifndef HAVE_STRLWER
 
-EXTRA_DIST = ChangeLog-2009
-DISTCHECK_CONFIGURE_FLAGS = --host=$(host) --with-mangle=@with_mangle@
+#include <ctype.h>
+#include "compat_string.h"
 
+char *strlwr(char *s) {
+	while(*s != '\x0') {
+		*s = tolower(*s);
+		s++;
+	}
+
+	return s;
+}
+
+#endif /* HAVE_STRLWER */
gendef/aclocal.m4 to gendef/gendef.c
--- a/gendef/aclocal.m4
+++ b/gendef/gendef.c
@@ -1,991 +1,1189 @@
-# generated automatically by aclocal 1.11.1 -*- Autoconf -*-
-
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
-# This file 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.
-
-m4_ifndef([AC_AUTOCONF_VERSION],
-  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
-m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],,
-[m4_warning([this file was generated for autoconf 2.68.
-You have another version of autoconf.  It may work, but is not guaranteed to.
-If you have problems, you may need to regenerate the build system entirely.
-To do so, use the procedure documented by the package, typically `autoreconf'.])])
-
-# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# AM_AUTOMAKE_VERSION(VERSION)
-# ----------------------------
-# Automake X.Y traces this macro to ensure aclocal.m4 has been
-# generated from the m4 files accompanying Automake X.Y.
-# (This private macro should not be called outside this file.)
-AC_DEFUN([AM_AUTOMAKE_VERSION],
-[am__api_version='1.11'
-dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
-dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.11.1], [],
-      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
-])
-
-# _AM_AUTOCONF_VERSION(VERSION)
-# -----------------------------
-# aclocal traces this macro to find the Autoconf version.
-# This is a private macro too.  Using m4_define simplifies
-# the logic in aclocal, which can simply ignore this definition.
-m4_define([_AM_AUTOCONF_VERSION], [])
-
-# AM_SET_CURRENT_AUTOMAKE_VERSION
-# -------------------------------
-# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
-# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
-AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.11.1])dnl
-m4_ifndef([AC_AUTOCONF_VERSION],
-  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
-_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
-
-# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
-
-# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
-# $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
-# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
-#
-# Of course, Automake must honor this variable whenever it calls a
-# tool from the auxiliary directory.  The problem is that $srcdir (and
-# therefore $ac_aux_dir as well) can be either absolute or relative,
-# depending on how configure is run.  This is pretty annoying, since
-# it makes $ac_aux_dir quite unusable in subdirectories: in the top
-# source directory, any form will work fine, but in subdirectories a
-# relative path needs to be adjusted first.
-#
-# $ac_aux_dir/missing
-#    fails when called from a subdirectory if $ac_aux_dir is relative
-# $top_srcdir/$ac_aux_dir/missing
-#    fails if $ac_aux_dir is absolute,
-#    fails when called from a subdirectory in a VPATH build with
-#          a relative $ac_aux_dir
-#
-# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
-# are both prefixed by $srcdir.  In an in-source build this is usually
-# harmless because $srcdir is `.', but things will broke when you
-# start a VPATH build or use an absolute $srcdir.
-#
-# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
-# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
-#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
-# and then we would define $MISSING as
-#   MISSING="\${SHELL} $am_aux_dir/missing"
-# This will work as long as MISSING is not called from configure, because
-# unfortunately $(top_srcdir) has no meaning in configure.
-# However there are other variables, like CC, which are often used in
-# configure, and could therefore not use this "fixed" $ac_aux_dir.
-#
-# Another solution, used here, is to always expand $ac_aux_dir to an
-# absolute PATH.  The drawback is that using absolute paths prevent a
-# configured tree to be moved without reconfiguration.
-
-AC_DEFUN([AM_AUX_DIR_EXPAND],
-[dnl Rely on autoconf to set up CDPATH properly.
-AC_PREREQ([2.50])dnl
-# expand $ac_aux_dir to an absolute path
-am_aux_dir=`cd $ac_aux_dir && pwd`
-])
-
-# AM_CONDITIONAL                                            -*- Autoconf -*-
-
-# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
-# Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 9
-
-# AM_CONDITIONAL(NAME, SHELL-CONDITION)
-# -------------------------------------
-# Define a conditional.
-AC_DEFUN([AM_CONDITIONAL],
-[AC_PREREQ(2.52)dnl
- ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
-	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
-AC_SUBST([$1_TRUE])dnl
-AC_SUBST([$1_FALSE])dnl
-_AM_SUBST_NOTMAKE([$1_TRUE])dnl
-_AM_SUBST_NOTMAKE([$1_FALSE])dnl
-m4_define([_AM_COND_VALUE_$1], [$2])dnl
-if $2; then
-  $1_TRUE=
-  $1_FALSE='#'
-else
-  $1_TRUE='#'
-  $1_FALSE=
-fi
-AC_CONFIG_COMMANDS_PRE(
-[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
-  AC_MSG_ERROR([[conditional "$1" was never defined.
-Usually this means the macro was only invoked conditionally.]])
-fi])])
-
-# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
-# Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 10
-
-# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
-# written in clear, in which case automake, when reading aclocal.m4,
-# will think it sees a *use*, and therefore will trigger all it's
-# C support machinery.  Also note that it means that autoscan, seeing
-# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
-
-
-# _AM_DEPENDENCIES(NAME)
-# ----------------------
-# See how the compiler implements dependency checking.
-# NAME is "CC", "CXX", "GCJ", or "OBJC".
-# We try a few techniques and use that to set a single cache variable.
-#
-# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
-# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
-# dependency, and given that the user is not expected to run this macro,
-# just rely on AC_PROG_CC.
-AC_DEFUN([_AM_DEPENDENCIES],
-[AC_REQUIRE([AM_SET_DEPDIR])dnl
-AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
-AC_REQUIRE([AM_MAKE_INCLUDE])dnl
-AC_REQUIRE([AM_DEP_TRACK])dnl
-
-ifelse([$1], CC,   [depcc="$CC"   am_compiler_list=],
-       [$1], CXX,  [depcc="$CXX"  am_compiler_list=],
-       [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
-       [$1], UPC,  [depcc="$UPC"  am_compiler_list=],
-       [$1], GCJ,  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
-                   [depcc="$$1"   am_compiler_list=])
-
-AC_CACHE_CHECK([dependency style of $depcc],
-               [am_cv_$1_dependencies_compiler_type],
-[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
-  # We make a subdir and do the tests there.  Otherwise we can end up
-  # making bogus files that we don't know about and never remove.  For
-  # instance it was reported that on HP-UX the gcc test will end up
-  # making a dummy file named `D' -- because `-MD' means `put the output
-  # in D'.
-  mkdir conftest.dir
-  # Copy depcomp to subdir because otherwise we won't find it if we're
-  # using a relative directory.
-  cp "$am_depcomp" conftest.dir
-  cd conftest.dir
-  # We will build objects and dependencies in a subdirectory because
-  # it helps to detect inapplicable dependency modes.  For instance
-  # both Tru64's cc and ICC support -MD to output dependencies as a
-  # side effect of compilation, but ICC will put the dependencies in
-  # the current directory while Tru64 will put them in the object
-  # directory.
-  mkdir sub
-
-  am_cv_$1_dependencies_compiler_type=none
-  if test "$am_compiler_list" = ""; then
-     am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
-  fi
-  am__universal=false
-  m4_case([$1], [CC],
-    [case " $depcc " in #(
-     *\ -arch\ *\ -arch\ *) am__universal=true ;;
-     esac],
-    [CXX],
-    [case " $depcc " in #(
-     *\ -arch\ *\ -arch\ *) am__universal=true ;;
-     esac])
-
-  for depmode in $am_compiler_list; do
-    # Setup a source with many dependencies, because some compilers
-    # like to wrap large dependency lists on column 80 (with \), and
-    # we should not choose a depcomp mode which is confused by this.
-    #
-    # We need to recreate these files for each test, as the compiler may
-    # overwrite some of them when testing with obscure command lines.
-    # This happens at least with the AIX C compiler.
-    : > sub/conftest.c
-    for i in 1 2 3 4 5 6; do
-      echo '#include "conftst'$i'.h"' >> sub/conftest.c
-      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
-      # Solaris 8's {/usr,}/bin/sh.
-      touch sub/conftst$i.h
-    done
-    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
-
-    # We check with `-c' and `-o' for the sake of the "dashmstdout"
-    # mode.  It turns out that the SunPro C++ compiler does not properly
-    # handle `-M -o', and we need to detect this.  Also, some Intel
-    # versions had trouble with output in subdirs
-    am__obj=sub/conftest.${OBJEXT-o}
-    am__minus_obj="-o $am__obj"
-    case $depmode in
-    gcc)
-      # This depmode causes a compiler race in universal mode.
-      test "$am__universal" = false || continue
-      ;;
-    nosideeffect)
-      # after this tag, mechanisms are not by side-effect, so they'll
-      # only be used when explicitly requested
-      if test "x$enable_dependency_tracking" = xyes; then
-	continue
+/*
+   Copyright (c) 2009, 2010 mingw-w64 project
+
+   Contributing authors: Kai Tietz, Jonathan Yong
+
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included in
+   all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <string.h>
+#include "compat_string.h"
+#include "gendef.h"
+#include "fsredir.h"
+#ifdef HAVE_LIBMANGLE
+#include <libmangle.h>
+#endif
+
+#define ENABLE_DEBUG 0
+
+#if ENABLE_DEBUG == 1
+#define PRDEBUG(...)  fprintf(stderr, __VA_ARGS__)
+#else
+#define PRDEBUG(...)
+#endif
+
+static void decode_mangle (FILE *fp, const char *n);
+static int load_pep (void);
+static void do_pedef (void);
+static void do_pepdef (void);
+static void do_import_read32 (uint32_t va_imp, uint32_t sz_imp);
+static void do_export_read (uint32_t va_exp,uint32_t sz_exp,int be64);
+static void add_export_list (uint32_t ord,uint32_t func,const char *name, const char *forward,int be64,int beData);
+static void dump_def (void);
+static int disassembleRet (uint32_t func,uint32_t *retpop,const char *name, sImportname **ppimpname, int *seen_ret);
+static size_t getMemonic (int *aCode,uint32_t pc,volatile uint32_t *jmp_pc,const char *name, sImportname **ppimpname);
+
+static sImportname *imp32_add (const char *dll, const char *name, uint32_t addr, uint16_t ord);
+static void imp32_free (void);
+static sImportname *imp32_findbyaddress (uint32_t addr);
+
+static sImportname *theImports = NULL;
+
+static void *map_va (uint32_t va);
+static int is_data (uint32_t va);
+static int is_reloc (uint32_t va);
+
+static int disassembleRetIntern (uint32_t pc, uint32_t *retpop, sAddresses *seen, sAddresses *stack,
+				 int *hasret, int *atleast_one, const char *name, sImportname **ppimpname);
+static sAddresses*init_addr (void);
+static void dest_addr (sAddresses *ad);
+static int push_addr (sAddresses *ad,uint32_t val);
+static int pop_addr (sAddresses *ad,uint32_t *val);
+
+static sExportName *gExp = NULL;
+static sExportName *gExpTail = NULL;
+char *fninput;
+char *fnoutput;
+char *fndllname;
+
+size_t gDta_size;
+unsigned char *gDta;
+PIMAGE_DOS_HEADER gMZDta;
+PIMAGE_NT_HEADERS32 gPEDta;
+PIMAGE_NT_HEADERS64 gPEPDta;
+
+#ifdef REDIRECTOR
+static int use_redirector = 0; /* Use/Disable FS redirector */
+#endif
+
+static int std_output = 0;
+static int assume_stdcall = 0; /* Set to one, if function symbols should be assumed to have stdcall.  */
+static int no_forward_output = 0; /* Set to one, if in .def files forwarders shouldn't be displayed.  */
+
+static Gendefopts *chain_ptr = NULL;
+ __attribute__((noreturn)) static void show_usage (void);
+static int opt_chain (const char *, const char *);
+
+static int
+opt_chain (const char *opts, const char *next)
+{
+  static Gendefopts *prev, *current;
+  char *r1, *r2;
+  
+  if (!strncmp (opts, "-", 2))
+    {
+      std_output = 1;
+      return 0;
+    }
+  if (!strcmp (opts, "--help") || !strcmp (opts, "-h"))
+    {
+      show_usage();
+      return 0;
+    }
+  if (!strcmp (opts, "--assume-stdcall") || !strcmp (opts, "-a"))
+    {
+      assume_stdcall = 1;
+      return 0;
+    }
+  if (!strcmp (opts, "--include-def-path") || !strcmp (opts, "-I"))
+    {
+      if (!next)
+        {
+	  fprintf (stderr, "Error: %s expects path as next arguement.", opts);
+	  return 0;
+        }
+      gendef_addpath_def (next);
+      return 1;
+    }
+  if (!strcmp (opts, "--no-forward-output") || !strcmp (opts, "-f"))
+    {
+      no_forward_output = 1;
+      return 0;
+    }
+
+#ifdef REDIRECTOR
+  if (!strcmp (opts, "--disable-fs-redirector") || !strcmp (opts, "-r"))
+    {
+      use_redirector = 1;
+      return 0;
+    }
+#endif
+
+  current = malloc (sizeof(Gendefopts));
+  if (current)
+    {
+      memset (current, 0, sizeof (Gendefopts));
+      current->next = NULL;
+
+      if (!prev)
+        chain_ptr = current;
       else
-	break
-      fi
-      ;;
-    msvisualcpp | msvcmsys)
-      # This compiler won't grok `-c -o', but also, the minuso test has
-      # not run yet.  These depmodes are late enough in the game, and
-      # so weak that their functioning should not be impacted.
-      am__obj=conftest.${OBJEXT-o}
-      am__minus_obj=
-      ;;
-    none) break ;;
-    esac
-    if depmode=$depmode \
-       source=sub/conftest.c object=$am__obj \
-       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
-       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
-         >/dev/null 2>conftest.err &&
-       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
-       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
-       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
-       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
-      # icc doesn't choke on unknown options, it will just issue warnings
-      # or remarks (even with -Werror).  So we grep stderr for any message
-      # that says an option was ignored or not supported.
-      # When given -MP, icc 7.0 and 7.1 complain thusly:
-      #   icc: Command line warning: ignoring option '-M'; no argument required
-      # The diagnosis changed in icc 8.0:
-      #   icc: Command line remark: option '-MP' not supported
-      if (grep 'ignoring option' conftest.err ||
-          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
-        am_cv_$1_dependencies_compiler_type=$depmode
-        break
-      fi
-    fi
-  done
-
-  cd ..
-  rm -rf conftest.dir
-else
-  am_cv_$1_dependencies_compiler_type=none
-fi
-])
-AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
-AM_CONDITIONAL([am__fastdep$1], [
-  test "x$enable_dependency_tracking" != xno \
-  && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
-])
-
-
-# AM_SET_DEPDIR
-# -------------
-# Choose a directory name for dependency files.
-# This macro is AC_REQUIREd in _AM_DEPENDENCIES
-AC_DEFUN([AM_SET_DEPDIR],
-[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
-AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
-])
-
-
-# AM_DEP_TRACK
-# ------------
-AC_DEFUN([AM_DEP_TRACK],
-[AC_ARG_ENABLE(dependency-tracking,
-[  --disable-dependency-tracking  speeds up one-time build
-  --enable-dependency-tracking   do not reject slow dependency extractors])
-if test "x$enable_dependency_tracking" != xno; then
-  am_depcomp="$ac_aux_dir/depcomp"
-  AMDEPBACKSLASH='\'
-fi
-AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
-AC_SUBST([AMDEPBACKSLASH])dnl
-_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
-])
-
-# Generate code to set up dependency tracking.              -*- Autoconf -*-
-
-# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
-# Free Software Foundation, Inc.
-#
-# This file 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.
-
-#serial 5
-
-# _AM_OUTPUT_DEPENDENCY_COMMANDS
-# ------------------------------
-AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
-[{
-  # Autoconf 2.62 quotes --file arguments for eval, but not when files
-  # are listed without --file.  Let's play safe and only enable the eval
-  # if we detect the quoting.
-  case $CONFIG_FILES in
-  *\'*) eval set x "$CONFIG_FILES" ;;
-  *)   set x $CONFIG_FILES ;;
-  esac
-  shift
-  for mf
-  do
-    # Strip MF so we end up with the name of the file.
-    mf=`echo "$mf" | sed -e 's/:.*$//'`
-    # Check whether this is an Automake generated Makefile or not.
-    # We used to match only the files named `Makefile.in', but
-    # some people rename them; so instead we look at the file content.
-    # Grep'ing the first line is not enough: some people post-process
-    # each Makefile.in and add a new line on top of each file to say so.
-    # Grep'ing the whole file is not good either: AIX grep has a line
-    # limit of 2048, but all sed's we know have understand at least 4000.
-    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
-      dirpart=`AS_DIRNAME("$mf")`
+        prev->next = current;
+      r1 = strrchr (opts,'/');
+      r2 = strrchr (opts,'\\');
+      current->fninput = strdup (opts);
+      
+      if (!r1 && r2 != NULL)
+        r1 = r2 + 1;
+      else if(r1 == NULL && r2 == NULL)
+        r1 = current->fninput;
+      else if (r2 != NULL && r1 != NULL && r1 < r2)
+        r1 = r2 + 1;
+      else
+        r1++;
+      current->fnoutput = (char *) malloc (strlen (current->fninput) + 5);
+      strcpy (current->fnoutput,r1);
+
+      r1 = strrchr (current->fnoutput,'.');
+      if (r1)
+        strcpy (r1,".def");
+      else
+        strcat (current->fnoutput,".def");
+      prev = current;
+   }
+  return 0;
+}
+
+void
+show_usage (void)
+{
+  fprintf (stderr, "Usage: gendef [OPTION]... [DLL]...\n");
+  fprintf (stderr, "Dumps DLL exports information from PE32/PE32+ executables\n");
+  fprintf (stderr, "\n");
+  fprintf (stderr, "Options:\n"
+    "  -                        Dump to stdout\n"
+    "  -h, --help               Show this help.\n"
+    "  -a, --assume-stdcall     Assume functions with ambiguous call\n"
+    "                           convention as stdcall.\n"
+    "  -I, --include-def-path <path>\n"
+    "                           Add additional search paths to find\n"
+    "                           hint .def files.\n"
+    "  -f, --no-forward-output  Don't output forwarders in .def file\n"
+#ifdef REDIRECTOR
+    "  -r, --disable-fs-redirector\n"
+    "                           Disable Win64 FS redirection, for 32-bit\n"
+    "                           gendef on 64-bit Windows\n"
+#endif
+  );
+  fprintf (stderr, "\n");
+  fprintf (stderr, "Usage example: \n"
+                   "  By default, the output files are named after their DLL counterparts\n"
+                   "  gendef MYDLL.DLL     Produces MYDLL.def\n"
+                   "  gendef - MYDLL.DLL   Prints the exports to stdout\n");
+  fprintf (stderr, "\nBuilt on %s\n", __DATE__);
+  fprintf (stderr, "\nReport bugs to <mingw-w64-public@lists.sourceforge.net>\n");
+  exit (0);
+}
+
+int main(int argc,char **argv)
+{
+  int i;
+  Gendefopts *opt;
+
+  if (argc < 2)
+  {
+    show_usage ();
+    return 0;
+  }
+
+  for (i = 1; i < argc; i++)
+    i += opt_chain (argv[i], ((i+1) < argc ? argv[i+1] : NULL));
+#ifdef REDIRECTOR
+  doredirect(use_redirector);
+#endif
+  opt = chain_ptr;
+  while (opt)
+    {
+      fninput = opt->fninput;
+      fnoutput = opt->fnoutput;
+
+      if (load_pep ())
+        {
+	  if (gPEDta || gPEPDta)
+	    {
+	      if (gPEDta)
+		do_pedef ();
+	      else
+		do_pepdef ();
+	      dump_def ();
+	    }
+	}
+      if (fndllname)
+	free (fndllname);
+      fndllname = NULL;
+      if (gDta)
+	{
+	  free (gDta);
+	  gDta = NULL;
+	}
+      free(opt->fninput);
+      free(opt->fnoutput);
+      free(opt);
+      opt = opt->next;
+    }
+  return 0;
+}
+
+static int
+load_pep (void)
+{
+  FILE *fp = fopen (fninput, "rb");
+
+  if (!fp)
+    {
+      fprintf (stderr, "*** [%s] failed to open()\n", fninput);
+      return 0;
+    }
+  fseek (fp, 0, SEEK_END);
+  gDta_size = (size_t) ftell (fp);
+  if (gDta_size > 0) {
+    fseek (fp,0,SEEK_SET);
+    gDta = (unsigned char *) malloc (gDta_size + 1);
+    if (gDta)
+      {
+        if (fread (gDta, gDta_size, 1, fp) != 1)
+	  {
+	    free (gDta);
+	    gDta = NULL;
+	  }
+	else
+          gDta[gDta_size] = 0;
+    }
+  }
+  fclose (fp);
+  if (!gDta)
+    {
+      fprintf (stderr, "*** [%s] unable to allocate %lu bytes\n", fninput,
+	       (unsigned long) gDta_size);
+      return 0;
+    }
+  gMZDta = (PIMAGE_DOS_HEADER) gDta;
+  if (gDta_size < sizeof(IMAGE_DOS_HEADER) || gDta[0]!='M' || gDta[1]!='Z'
+      || gMZDta->e_lfanew <= 0
+      || gMZDta->e_lfanew >= (int32_t) gDta_size)
+  {
+    fprintf(stderr,"*** [%s] not a PE(+) file\n", fninput);
+    free(gDta);
+    gDta = NULL;
+    return 0;
+  }
+  gPEDta = (PIMAGE_NT_HEADERS32) &gDta[gMZDta->e_lfanew];
+  gPEPDta = (PIMAGE_NT_HEADERS64) gPEDta;
+  if (gPEDta->Signature != IMAGE_NT_SIGNATURE)
+    {
+      fprintf (stderr, "*** [%s] no PE(+) signature\n", fninput);
+      free (gDta);
+      gDta = NULL;
+      gPEPDta = NULL;
+      gPEDta = NULL;
+      return 0;
+    }
+  if (gPEDta->FileHeader.SizeOfOptionalHeader == IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
+      && gPEDta->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
+    {
+      gPEPDta = NULL;
+      fprintf (stderr, " * [%s] Found PE image\n", fninput);
+    }
+  else if (gPEPDta->FileHeader.SizeOfOptionalHeader == IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
+    && gPEPDta->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
+    {
+      gPEDta = NULL;
+      fprintf (stderr, " * [%s] Found PE+ image\n", fninput);
+    }
+  else
+    {
+      free (gDta);
+      gDta = NULL;
+      fprintf (stderr, "*** [%s] no PE(+) optional header\n", fninput);
+      gPEPDta = NULL;
+      gPEDta = NULL;
+      return 0;
+    }
+  return 1;
+}
+
+static int
+is_data (uint32_t va)
+{
+  PIMAGE_SECTION_HEADER sec;
+  uint32_t sec_cnt,i;
+
+  /* If export va is directly relocated, so it must be data.  */  
+  if (is_reloc (va))
+    return 1;
+  
+  if (gPEDta)
+    {
+      sec_cnt = gPEDta->FileHeader.NumberOfSections;
+      sec = IMAGE_FIRST_SECTION(gPEDta);
+    }
+  else
+    {
+      sec_cnt = gPEPDta->FileHeader.NumberOfSections;
+      sec = IMAGE_FIRST_SECTION(gPEPDta);
+    }
+  if (!sec)
+    return 0;
+  for (i = 0;i < sec_cnt;i++)
+    {
+      if (va >= sec[i].VirtualAddress && va < (sec[i].VirtualAddress+sec[i].Misc.VirtualSize))
+        break;
+    }
+  if (i == sec_cnt)
+    return 0; 
+  if ((sec[i].Characteristics & (IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_CNT_CODE)) != 0)
+    return 0;
+  if ((sec[i].Characteristics & IMAGE_SCN_MEM_DISCARDABLE) != 0)
+    return 1;
+  if ((sec[i].Characteristics & IMAGE_SCN_MEM_READ) ==0)
+    return 0;
+  if ((sec[i].Characteristics & (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_LNK_COMDAT)) != 0)
+    return 1;
+  return 1;
+}
+
+static int
+is_reloc (uint32_t va)
+{
+  uint32_t va_rel, sz_rel, pos;
+  unsigned char *p;
+  PIMAGE_BASE_RELOCATION brel;
+
+  if (gPEDta)
+    {
+      va_rel = gPEDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
+      sz_rel = gPEDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
+    }
+  else
+    {
+      va_rel = gPEPDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
+      sz_rel = gPEPDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
+    }
+  if (va_rel == 0 || sz_rel < IMAGE_SIZEOF_BASE_RELOCATION)
+    return 0;
+  p = (unsigned char *) map_va (va_rel);
+  for (pos = 0; pos < sz_rel;)
+    {
+      uint16_t *r;
+      uint32_t nums, j;
+      if ((sz_rel - pos) < IMAGE_SIZEOF_BASE_RELOCATION)
+        break;
+      brel = (PIMAGE_BASE_RELOCATION) &p[pos];
+      if (brel->SizeOfBlock == 0)
+         break;
+      pos += IMAGE_SIZEOF_BASE_RELOCATION;
+      nums = (brel->SizeOfBlock - IMAGE_SIZEOF_BASE_RELOCATION) / 2;
+      r = (uint16_t *) &p[pos];
+      if (va >= brel->VirtualAddress && va < (brel->VirtualAddress + 0x1008))
+        {
+          for (j = 0; j < nums; j++)
+            {
+              uint32_t relsz = 0;
+              uint32_t offs = (uint32_t) (r[j] & 0xfff) + brel->VirtualAddress;
+              uint16_t typ = (r[j] >> 12) & 0xf;
+              if (typ == IMAGE_REL_BASED_HIGHADJ)
+                j++;
+              switch (typ)
+                {
+                case IMAGE_REL_BASED_HIGHLOW:
+                  relsz = 4;
+                  break;
+                case IMAGE_REL_BASED_DIR64:
+                  relsz = 8;
+                  break;
+                }
+              if (relsz != 0 && va >= offs && va < (offs + relsz))
+                return 1;
+            }
+        }
+      pos += (brel->SizeOfBlock - IMAGE_SIZEOF_BASE_RELOCATION);
+    }
+  return 0;
+}
+
+static void *
+map_va (uint32_t va)
+{
+  PIMAGE_SECTION_HEADER sec;
+  uint32_t sec_cnt,i;
+  char *dptr;
+
+  if (gPEDta)
+    {
+      sec_cnt = gPEDta->FileHeader.NumberOfSections;
+      sec = IMAGE_FIRST_SECTION(gPEDta);
+    }
+  else
+    {
+      sec_cnt = gPEPDta->FileHeader.NumberOfSections;
+      sec = IMAGE_FIRST_SECTION(gPEPDta);
+    }
+  for (i = 0;i < sec_cnt;i++)
+    {
+      if (va >= sec[i].VirtualAddress && va < (sec[i].VirtualAddress+sec[i].Misc.VirtualSize))
+        {
+          dptr = (char *) &gDta[va-sec[i].VirtualAddress+sec[i].PointerToRawData];
+          return (void *)dptr;
+        }
+    }
+  return NULL;
+}
+
+/* For pep we can take the exports itself, there is no additional decoration necessary.  */
+static void
+do_pepdef (void)
+{
+  uint32_t va_exp = gPEPDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
+  uint32_t sz_exp = gPEPDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
+
+  do_export_read (va_exp, sz_exp, 1);
+}
+
+static void
+do_pedef (void)
+{
+  uint32_t va_exp = gPEDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
+  uint32_t sz_exp = gPEDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
+  uint32_t va_imp = gPEDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
+  uint32_t sz_imp = gPEDta->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size;
+
+  imp32_free ();
+  do_import_read32 (va_imp, sz_imp);
+  do_export_read (va_exp, sz_exp, 0);
+}
+
+static void
+do_import_read32 (uint32_t va_imp, uint32_t sz_imp)
+{
+  IMAGE_IMPORT_DESCRIPTOR *pid;
+  if (!sz_imp || !va_imp)
+    return;
+  pid = (IMAGE_IMPORT_DESCRIPTOR *) map_va (va_imp);
+  while (pid != NULL && sz_imp >= 20 && pid->Name != 0 && pid->OriginalFirstThunk != 0)
+    {
+      uint32_t index = 0;
+      PIMAGE_THUNK_DATA32 pIAT;
+      PIMAGE_THUNK_DATA32 pFT;
+      char *imp_name = (char *) map_va (pid->Name);
+
+      for (;;) {
+	char *fctname;
+	pIAT = (PIMAGE_THUNK_DATA32) map_va (pid->OriginalFirstThunk + index);
+	pFT = (PIMAGE_THUNK_DATA32) map_va (pid->FirstThunk + index);
+	if (pIAT->u1.Ordinal == 0 || pFT->u1.Ordinal == 0)
+	  break;
+	if (IMAGE_SNAP_BY_ORDINAL32 (pIAT->u1.Ordinal))
+	  fctname = NULL;
+	else
+	  fctname = (char *) map_va (pIAT->u1.Function + 2);
+	if (fctname)
+	  imp32_add (imp_name, fctname,
+	  //pid->OriginalFirstThunk + index + gPEDta->OptionalHeader.ImageBase,
+	  pid->FirstThunk + index + gPEDta->OptionalHeader.ImageBase,
+	    *((uint16_t *) map_va (pIAT->u1.Function)));
+	index += 4;
+      }
+      sz_imp -= 20;
+      va_imp += 20;
+      if (sz_imp >= 20)
+	pid = (IMAGE_IMPORT_DESCRIPTOR *) map_va (va_imp);
+    }
+}
+
+static sImportname *
+imp32_findbyaddress (uint32_t addr)
+{
+  sImportname *h = theImports;
+  while (h != NULL && h->addr_iat != addr)
+    h = h->next;
+  return h;
+}
+
+static void
+imp32_free (void)
+{
+  while (theImports != NULL)
+    {
+      sImportname *h = theImports;
+      theImports = theImports->next;
+      if (h->dll)
+	free (h->dll);
+      if (h->name)
+	free (h->name);
+      free (h);
+    }
+}
+
+static sImportname *
+imp32_add (const char *dll, const char *name, uint32_t addr, uint16_t ord)
+{
+  sImportname *n = (sImportname *) malloc (sizeof (sImportname));
+  memset (n, 0, sizeof (sImportname));
+  n->dll = strdup (dll);
+  n->name = strdup (name);
+  n->ord = ord;
+  n->addr_iat = addr;
+  n->next = theImports;
+  theImports = n;
+  return n;
+}
+
+static void
+do_export_read (uint32_t va_exp, uint32_t sz_exp, int be64)
+{
+  uint32_t i;
+  PIMAGE_EXPORT_DIRECTORY exp_dir;
+  uint32_t *functions;
+  uint16_t *ordinals;
+  uint32_t *name;
+
+  if (va_exp == 0 || sz_exp == 0)
+    return;
+  exp_dir = (PIMAGE_EXPORT_DIRECTORY) map_va (va_exp);
+  PRDEBUG(" * export directory at VA = 0x%x size=0x%x\n", (unsigned int) va_exp, (unsigned int) sz_exp);
+  fndllname = strdup ((char *) map_va (exp_dir->Name));
+  PRDEBUG(" * Name: %s\n * Base: %u\n", fndllname, (unsigned int) exp_dir->Base);
+  functions = (uint32_t *) map_va (exp_dir->AddressOfFunctions);
+  ordinals = (uint16_t *) map_va (exp_dir->AddressOfNameOrdinals);
+  name = (uint32_t *) map_va (exp_dir->AddressOfNames);
+  
+  for (i = 0;i < exp_dir->NumberOfFunctions;i++)
+    {
+      uint32_t entryPointRVA = functions[i];
+      uint32_t j;
+      char *fname;
+      uint32_t ord;
+      fname = NULL;
+      if (!entryPointRVA)
+        continue;
+      ord = i + exp_dir->Base;
+      for (j = 0;j < exp_dir->NumberOfNames;j++)
+        if (ordinals[j]==i)
+          fname = (char *) map_va (name[j]);
+      if (entryPointRVA >= va_exp && entryPointRVA <= (va_exp + sz_exp))
+        add_export_list (ord, 0, fname,(char *) map_va (entryPointRVA), be64, 0);
+      else
+        add_export_list(ord, entryPointRVA, fname, NULL, be64, is_data (entryPointRVA));
+    }
+}
+
+static void
+add_export_list(uint32_t ord,uint32_t func,const char *name, const char *forward,int be64,int beData)
+{
+  sExportName *exp = NULL;
+
+  if (!name)
+    name = "";
+  if (!forward)
+    forward = "";
+  exp = (sExportName *) malloc (sizeof (sExportName) + strlen (name) + strlen (forward) + 2);
+  if (!exp)
+    return;
+  exp->name = (char *) &exp[1];
+  exp->forward = exp->name + strlen (name) + 1;
+  strcpy (exp->name, name);
+  strcpy (exp->forward, forward);
+  exp->next = NULL;
+  exp->ord = ord;
+  exp->func = func;
+  exp->be64 = be64;
+  exp->beData = beData;
+  exp->retpop = (uint32_t)-1;
+  if (gExpTail)
+    gExpTail->next = exp;
+  else
+    gExp = exp;
+  gExpTail = exp;
+}
+
+static void
+dump_def (void)
+{
+  sExportName *exp;
+  FILE *fp;
+
+  if (!fndllname || gExp == NULL)
+    return;
+  if (!std_output)
+    fp = fopen(fnoutput,"wt");
+  else
+    fp = stdout;
+  if(!fp) {
+    fprintf(stderr," * failed to create %s ...\n",fnoutput);
+    return;
+  }
+  fprintf (fp,"; Definition file for %s dynamic library.\n; Generated by gendef written by Kai Tietz 2008\n;\n; This file is a part of the MinGW.org SDK.\n; See the file DISCLAIMER for your rights of use.\n;\n",
+    fndllname);
+  fprintf (fp,"LIBRARY \"%s\"\nEXPORTS\n",fndllname);
+  while ((exp = gExp) != NULL)
+    {
+      sImportname *pimpname;
+      int seen_ret;
+      seen_ret = 1;
+      gExp = exp->next;
+      if (exp->name[0] == '?')
+        {
+          decode_mangle (fp, exp->name);
+        }
+      if (exp->name[0] == 0)
+        fprintf (fp, "ord_%u", (unsigned int) exp->ord);
+      else
+        fprintf (fp, "%s", exp->name);
+      if (exp->name[0] == '?' && exp->name[1] == '?')
+        {
+          if (!strncmp (exp->name, "??_7", 4))
+	    exp->beData = 1;
+        }
+      pimpname = NULL;
+      if (!exp->beData && !exp->be64 && exp->func != 0)
+	{
+	  seen_ret = 0;
+	  exp->beData = disassembleRet (exp->func, &exp->retpop, exp->name, &pimpname, &seen_ret);
+        }
+      if (!exp->be64 && exp->retpop == (uint32_t) -1 && pimpname)
+	{
+	  int isD = 0;
+	  uint32_t at = 0;
+	  if (gendef_getsymbol_info (pimpname->dll, pimpname->name, &isD, &at))
+	    {
+	      exp->beData = isD;
+	      if (!isD)
+		exp->retpop = at;
+	    }
+	}
+      else if (exp->func == 0 && !exp->beData)
+	{
+	  int isD = 0;
+	  uint32_t at = 0;
+	  if (gendef_getsymbol_info (exp->forward, NULL, &isD, &at))
+	    {
+	      exp->beData = isD;
+	      if (!isD)
+	        exp->retpop = at;
+	    }
+	}
+
+      if (exp->be64)
+        exp->retpop = 0;
+
+      if (exp->retpop != (uint32_t) -1 && !exp->be64)
+        {
+          if (exp->name[0]=='?')
+            fprintf(fp," ; has WINAPI (@%u)", (unsigned int) exp->retpop);
+          else
+            fprintf(fp,"@%u", (unsigned int) exp->retpop);
+        }
+      if (exp->func == 0 && no_forward_output == 0)
+	fprintf (fp, " = %s", exp->forward);
+      if (exp->name[0] == 0)
+        fprintf(fp," @%u", (unsigned int) exp->ord);
+      if (exp->beData)
+        fprintf(fp," DATA");
+
+      if (exp->retpop != (uint32_t) -1 || (exp->be64 && exp->retpop == 0))
+	{
+	}
+      else if (pimpname)
+        {
+	  fprintf (fp, " ; Check!!! forwards to %s in %s (ordinal %u)",
+	    pimpname->name, pimpname->dll, pimpname->ord);
+        }
+      else if (exp->func == 0 && !exp->beData)
+	{
+	  fprintf (fp, " ; Check!!! forwards to %s", exp->forward);
+	}
+      else if (seen_ret == 0 && !exp->beData)
+        {
+	  fprintf (fp, " ; Check!!! Couldn't determine function argument count. Function doesn't return. ");
+        }
+      fprintf(fp,"\n");
+      free (exp);
+    }
+  gExpTail=NULL;
+  if (!std_output)
+    fclose(fp);
+}
+
+static sAddresses *
+init_addr (void)
+{
+  sAddresses *r = (sAddresses*) malloc (sizeof (sAddresses));
+  r->max = 8;
+  r->cnt = 0;
+  r->ptrs = (uint32_t *) malloc (sizeof (uint32_t) * 8);
+  r->idx = 0;
+  return r;
+}
+
+static void
+dest_addr (sAddresses *ad)
+{
+  free (ad->ptrs);
+  free (ad);
+}
+
+static int
+push_addr (sAddresses *ad, uint32_t val)
+{
+  uint32_t i;
+
+  for (i = 0;i < ad->cnt; i++)
+    {
+      if (ad->ptrs[i] == val)
+        return 0;
+    }
+  if (ad->max == ad->cnt)
+    {
+      uint32_t *p = (uint32_t *) malloc (sizeof (uint32_t) * (ad->max + 8));
+
+      memcpy (p, ad->ptrs, sizeof (uint32_t) * ad->max);
+      ad->max += 8;
+      free (ad->ptrs);
+      ad->ptrs = p;
+    }
+  ad->ptrs[ad->cnt++] = val;
+  return 1;
+}
+
+static int
+pop_addr (sAddresses *ad, uint32_t *val)
+{
+  if (!ad || ad->idx == ad->cnt)
+    return 0;
+  ad->idx++;
+  *val = ad->ptrs[ad->idx-1];
+  return 1;
+}
+
+/* exp->beData */
+static int
+disassembleRet (uint32_t func, uint32_t *retpop, const char *name, sImportname **ppimpname, int *seen_ret)
+{
+  sAddresses *seen = init_addr ();
+  sAddresses *stack = init_addr ();
+  uint32_t pc;
+  int hasret = 0;
+  int atleast_one = 0;
+
+  *retpop = (uint32_t) -1;
+  push_addr (stack, func);
+
+  while (!hasret && pop_addr (stack,&pc))
+    {
+      if (disassembleRetIntern (pc, retpop, seen, stack, &hasret, &atleast_one, name, ppimpname))
+        break;
+    }
+  *seen_ret = hasret;
+  dest_addr (seen);
+  dest_addr (stack);
+  return (atleast_one ? 0 : 1);
+}
+
+static int
+disassembleRetIntern (uint32_t pc, uint32_t *retpop, sAddresses *seen, sAddresses *stack,
+		      int *hasret, int *atleast_one, const char *name, sImportname **ppimpname)
+{
+  size_t sz = 0;
+  int code = 0,break_it = 0;
+  volatile uint32_t tojmp = 0;
+
+  while(1)
+    {
+      if (!push_addr (seen, pc))
+        return 0;
+      sz = getMemonic (&code, pc, &tojmp, name, ppimpname) & 0xffffffff;
+      if (!sz || code == c_ill)
+        {
+          PRDEBUG(" %s = 0x08%x ILL (%u) at least one==%d\n",name,
+	 	  (unsigned int) pc, (unsigned int) sz,atleast_one[0]);
+#if ENABLE_DEBUG == 1
+      {
+        unsigned char *ppc = (unsigned char *) map_va (pc);
+        size_t i;
+
+        fprintf (stderr, "%s(0x%x): ",name, (unsigned int) pc);
+        for (i = 0;i < sz; i++)
+          {
+            fprintf (stderr, "%s0x%x", (i == 0 ? " ":","), ppc[i]);
+          }
+        fprintf (stderr, "\n");
+      }
+      exit (0);
+#endif
+          break;
+        }
+#if ENABLE_DEBUG == 1
+      {
+        unsigned char *ppc = (unsigned char *) map_va (pc);
+        size_t i;
+
+        fprintf (stderr, "%s(0x%x): ",name, (unsigned int) pc);
+        for (i = 0;i < sz; i++)
+          {
+            fprintf (stderr, "%s0x%x", (i == 0 ? " ":","), ppc[i]);
+          }
+        fprintf (stderr, "\n");
+      }
+#endif
+      atleast_one[0] += 1;
+      break_it = 0;
+      pc += sz;
+      switch(code)
+        {
+        case c_jmpnjb: case c_jmpnjv:
+          pc = tojmp;
+          break;
+        case c_jxx:
+          push_addr (stack, tojmp);
+          break;
+        case c_jmpfap: case c_int3:
+          break_it = 1;
+          break;
+        case c_iret: case c_retf: case c_retn:
+          *hasret = 1;
+          if (assume_stdcall)
+            *retpop = 0;
+          return 1;
+        case c_retflw: case c_retnlw:
+          *hasret = 1;
+          *retpop = tojmp;
+          return 1;
+        }
+      if (break_it)
+        break;
+    }
+
+  return 0;
+}
+
+static int opMap2[256] = {
+  c_EG,c_EG,c_EG,c_EG,c_1,c_1,c_ill,c_ill, /* 0x00-0x07 */
+  c_1,c_1,c_ill,c_ill,c_ill,c_ill,c_ill,c_ill, /* 0x08-0x0f */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x10-0x17 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x18-0x1f */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_ill,c_EG,c_ill, /* 0x20-0x27 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x28-0x2f */
+  c_1,c_1,c_1,c_1,c_1,c_1,c_ill,c_1, /* 0x30-0x37 */
+  c_ill,c_ill,c_ill,c_ill,c_ill,c_ill,c_ill,c_ill, /* 0x38-0x3f */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x40-0x47 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x48-0x4f */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x50-0x57 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x58-0x5f */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x60-0x67 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x68-0x6f */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x70-0x77 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x78-0x7f */
+  c_jxxv,c_jxxv,c_jxxv,c_jxxv,c_jxxv,c_jxxv,c_jxxv,c_jxxv, /* 0x80-0x87 */
+  c_jxxv,c_jxxv,c_jxxv,c_jxxv,c_jxxv,c_jxxv,c_jxxv,c_jxxv, /* 0x88-0x8f */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x90-0x97 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x98-0x9f */
+  c_1,c_1,c_1,c_EG,c_EGlb,c_EG,c_ill,c_ill, /* 0xa0-0xa7 */
+  c_1,c_1,c_1,c_EG,c_EGlb,c_EG,c_EG,c_EG, /* 0xa8-0xaf */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0xb0-0xb7 */
+  c_EG,c_1,c_EGlb,c_EG, c_EG,c_EG,c_EG,c_EG, /* 0xb8-0xbf */
+  c_EG,c_EG,c_EGlb,c_EG,c_EGlb,c_EGlb,c_EGlb,c_EG, /* 0xc0-0xc7 */
+  c_1,c_1,c_1,c_1,c_1,c_1,c_1,c_1, /* 0xc8-0xcf */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0xd0-0xd7 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0xd8-0xdf */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0xe0-0xe7 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0xe8-0xef */
+  c_ill,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0xf0-0xf7 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_ill /* 0xf8-0xff */
+};
+
+static int opMap1[256] = {
+  c_EG,c_EG,c_EG,c_EG,c_lb,c_lv,c_1,c_1, /* 0x00-0x07 */
+  c_EG,c_EG,c_EG,c_EG,c_lb,c_lv,c_1,c_0f, /* 0x08-0x0f */
+  c_EG,c_EG,c_EG,c_EG,c_lb,c_lv,c_1,c_1, /* 0x10-0x17 */
+  c_EG,c_EG,c_EG,c_EG,c_lb,c_lv,c_1,c_1, /* 0x18-0x1f */
+  c_EG,c_EG,c_EG,c_EG,c_lb,c_lv,c_1,c_1, /* 0x20-0x27 */
+  c_EG,c_EG,c_EG,c_EG,c_lb,c_lv,c_1,c_1, /* 0x28-0x2f */
+  c_EG,c_EG,c_EG,c_EG,c_lb,c_lv,c_1,c_1, /* 0x30-0x37 */
+  c_EG,c_EG,c_EG,c_EG,c_lb,c_lv,c_1,c_1, /* 0x38-0x3f */
+  c_1,c_1,c_1,c_1,c_1,c_1,c_1,c_1, /* 0x40-0x47 */
+  c_1,c_1,c_1,c_1,c_1,c_1,c_1,c_1, /* 0x48-0x4f */
+  c_1,c_1,c_1,c_1,c_1,c_1,c_1,c_1, /* 0x50-0x57 */
+  c_1,c_1,c_1,c_1,c_1,c_1,c_1,c_1, /* 0x58-0x5f */
+  c_1,c_1,c_EG,c_EG,c_1,c_1,c_op,c_ad, /* 0x60-0x67 */
+  c_lv,c_EGlv,c_lb,c_EGlb,c_1,c_1,c_1,c_1, /* 0x68-0x6f */
+  c_jxx,c_jxx,c_jxx,c_jxx,c_jxx,c_jxx,c_jxx,c_jxx, /* 0x70-0x77 */
+  c_jxx,c_jxx,c_jxx,c_jxx,c_jxx,c_jxx,c_jxx,c_jxx, /* 0x78-0x7f */
+  c_EGlb,c_EGlv,c_EGlb,c_EGlb,c_EG,c_EG,c_EG,c_EG, /* 0x80-0x87 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0x88-0x8f */
+  c_1,c_1,c_1,c_1,c_1,c_1,c_1,c_1, /* 0x90-0x97 */
+  c_1,c_1,c_callfar,c_1,c_1,c_1,c_1,c_1, /* 0x98-0x9f */
+  c_O,c_O,c_O,c_O,c_1,c_1,c_1,c_1, /* 0xa0-0xa7 */
+  c_lb,c_lv,c_1,c_1,c_1,c_1,c_1,c_1, /* 0xa8- 0xaf */
+  c_2,c_2,c_2,c_2,c_2,c_2,c_2,c_2, /* 0xb0-0xb7 */
+  c_lv,c_lv,c_lv,c_lv,c_lv,c_lv,c_lv,c_lv, /* 0xb8-0xbf */
+  c_EGlb,c_EGlb,c_retnlw,c_retn,c_EG,c_EG,c_EGlb,c_EGlv, /* 0xc0-0xc7 */
+  c_4,c_1,c_retflw,c_retf,c_int3,c_2,c_1,c_iret, /* 0xc8-0xcf */
+  c_EG,c_EG,c_EG,c_EG,c_2,c_2,c_1,c_1, /* 0xd0-0xd7 */
+  c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG,c_EG, /* 0xd8-0xdf */
+  c_jxx,c_jxx,c_jxx,c_jxx,c_2,c_2,c_2,c_2, /* 0xe0-0xe7 */
+  c_calljv,c_jmpnjv,c_jmpfap,c_jmpnjb,c_1,c_1,c_1,c_1, /* 0xe8-0xef */
+  c_1,c_1,c_1,c_1, c_1,c_1,c_EGg3b,c_EGg3v, /* 0xf0-0xf7 */
+  c_1,c_1,c_1,c_1,c_1,c_1,c_g4,c_g4 /* 0xf8-0xff */
+};
+
+#if ENABLE_DEBUG == 1
+
+#define MAX_INSN_SAVE	20
+
+static void
+enter_save_insn (unsigned char *s, unsigned char b)
+{
+  int i;
+  for (i=0;i<MAX_INSN_SAVE-1;i++)
+    s[i]=s[i+1];
+  s[MAX_INSN_SAVE-1]=b;
+}
+
+static void
+print_save_insn (const char *name, unsigned char *s)
+{
+  int i;
+  
+  PRDEBUG("From %s: ",name);
+  for (i=0;i<MAX_INSN_SAVE;i++)
+  {
+    PRDEBUG("%s0x%x",(i!=0 ? "," : ""), (unsigned int) s[i]);
+  }
+}
+#endif
+
+static size_t
+getMemonic(int *aCode,uint32_t pc,volatile uint32_t *jmp_pc, __attribute__((unused)) const char *name, sImportname **ppimpname)
+{
+#if ENABLE_DEBUG == 1
+  static unsigned char lw[MAX_INSN_SAVE];
+#endif
+  unsigned char *p;
+  int addr_mode = 1;
+  int oper_mode = 1;
+  size_t sz = 0;
+  unsigned char b;
+  int tb1;
+
+  for(;;) {
+    p = (unsigned char *) map_va (pc + sz);
+    if (!p) { *aCode=c_ill; return 0; }
+    b = p[0];
+    if (b==0x26 || b==0x2e || b==0x36 || b==0x3e || b==0x64 || b==0x65)
+      ++sz;
+    else if (b==0x66) { oper_mode^=1; sz++; }
+    else if (b==0x67) { addr_mode^=1; sz++; }
+    else if (b==0xf2 || b==0xf3 || b==0xf0) sz++;
+    else break;
+  }
+  sz++;
+  tb1=opMap1[(unsigned int) b];
+  
+redo_switch:
+#if ENABLE_DEBUG == 1
+  if (tb1!=c_ill) { enter_save_insn(lw,b); }
+#endif
+  switch (tb1) {
+  case c_ill:
+#if ENABLE_DEBUG == 1
+    print_save_insn (name, lw);
+    PRDEBUG(" 0x%x illegal ", (unsigned int) b);
+#endif
+    *aCode=c_ill; return 0;
+  case c_4: sz++;
+  case c_3: sz++;
+  case c_lb:
+  case c_2: sz++;
+  case c_retn: case c_retf:
+  case c_iret: case c_int3:
+  case c_ad: case c_op:
+  case c_1: *aCode=tb1; return sz;
+  case c_lv:
+    if (oper_mode) sz+=4;
+    else sz+=2;
+    *aCode=tb1; return sz;
+  case c_O: case c_calljv:
+    if (addr_mode) sz+=4;
+    else sz+=2;
+    *aCode=tb1; return sz;
+  case c_EG: case c_EGlv: case c_EGlb: case c_g4: case c_EGg3v: case c_EGg3b:
+    p = (unsigned char *) map_va (pc + sz);
+    sz++;
+    if (!p) { *aCode=c_ill; return 0; }
+    b = p[0];
+#if ENABLE_DEBUG == 1
+    enter_save_insn(lw,b);
+#endif
+    if (addr_mode) {
+      if((b&0xc0)!=0xc0 && (b&0x7)==4)
+        {
+          p = (unsigned char *) map_va (pc + sz);
+          if (!p) { *aCode=c_ill; return 0; }
+#if ENABLE_DEBUG == 1
+    enter_save_insn(lw,p[0]);
+#endif
+          b&=~0x7; b|=(p[0]&7);
+	  sz+=1;
+	}
+      if((b&0xc0)==0 && (b&7)==5)
+        {
+	  /* Here we check if for jmp instruction it points to an IAT entry.  */
+	  if(tb1==c_g4 && ((b&0x38)==0x20 || (b&0x38)==0x28))
+	    {
+	      uint32_t vaddr;
+	      sImportname *inss;
+	      vaddr = *((uint32_t *) map_va (pc + sz));
+	      inss = imp32_findbyaddress (vaddr);
+	      if (inss)
+		*ppimpname = inss;
+	    }
+	  sz+=4;
+        }
+      else if((b&0xc0)==0x40)
+	sz+=1;
+      else if((b&0xc0)==0x80)
+	sz+=4;
+    } else {
+      if((b&0xc0)==0) {
+	if((b&0x07)==6) sz+=2;
+      } else if((b&0xc0)==0x40)
+	sz+=1;
+      else if((b&0xc0)==0x80)
+	sz+=2;
+    }
+    if (tb1==c_EGlv) sz+=(oper_mode ? 4 : 2);
+    else if(tb1==c_EGlb) sz++;
+    else if(tb1==c_g4) {
+      if ((b&0x38)==0x20 || (b&0x38)==0x28)
+	tb1=c_int3;
+      else if((b&0x38)==0x38)
+        tb1=c_ill;
+    } else if (tb1==c_EGg3v || tb1==c_EGg3b) {
+      switch (((b&0x38)>>3)) {
+      case 1:
+      case 0: sz+= (tb1==c_EGg3v ? (oper_mode ? 4 : 2) : 1); break;
+      default: break;
+      }
+    }
+    *aCode=tb1; return sz;
+  case c_jxx: case c_jmpnjb:
+    p = (unsigned char *) map_va (pc + sz);
+    if (!p) { *aCode=c_ill; return 0; }
+    b = p[0];
+    sz++;
+    jmp_pc[0]=(uint32_t) pc + (uint32_t) sz;
+    if ((b&0x80)!=0)
+      jmp_pc[0] = jmp_pc[0] + (((uint32_t) b) | 0xffffff00);
     else
-      continue
-    fi
-    # Extract the definition of DEPDIR, am__include, and am__quote
-    # from the Makefile without running `make'.
-    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
-    test -z "$DEPDIR" && continue
-    am__include=`sed -n 's/^am__include = //p' < "$mf"`
-    test -z "am__include" && continue
-    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
-    # When using ansi2knr, U may be empty or an underscore; expand it
-    U=`sed -n 's/^U = //p' < "$mf"`
-    # Find all dependency output files, they are included files with
-    # $(DEPDIR) in their names.  We invoke sed twice because it is the
-    # simplest approach to changing $(DEPDIR) to its actual value in the
-    # expansion.
-    for file in `sed -n "
-      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
-	 sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
-      # Make sure the directory exists.
-      test -f "$dirpart/$file" && continue
-      fdir=`AS_DIRNAME(["$file"])`
-      AS_MKDIR_P([$dirpart/$fdir])
-      # echo "creating $dirpart/$file"
-      echo '# dummy' > "$dirpart/$file"
-    done
-  done
-}
-])# _AM_OUTPUT_DEPENDENCY_COMMANDS
-
-
-# AM_OUTPUT_DEPENDENCY_COMMANDS
-# -----------------------------
-# This macro should only be invoked once -- use via AC_REQUIRE.
-#
-# This code is only required when automatic dependency tracking
-# is enabled.  FIXME.  This creates each `.P' file that we will
-# need in order to bootstrap the dependency handling code.
-AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
-[AC_CONFIG_COMMANDS([depfiles],
-     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
-     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
-])
-
-# Do all the work for Automake.                             -*- Autoconf -*-
-
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-# 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 16
-
-# This macro actually does too much.  Some checks are only needed if
-# your package does certain things.  But this isn't really a big deal.
-
-# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
-# AM_INIT_AUTOMAKE([OPTIONS])
-# -----------------------------------------------
-# The call with PACKAGE and VERSION arguments is the old style
-# call (pre autoconf-2.50), which is being phased out.  PACKAGE
-# and VERSION should now be passed to AC_INIT and removed from
-# the call to AM_INIT_AUTOMAKE.
-# We support both call styles for the transition.  After
-# the next Automake release, Autoconf can make the AC_INIT
-# arguments mandatory, and then we can depend on a new Autoconf
-# release and drop the old call support.
-AC_DEFUN([AM_INIT_AUTOMAKE],
-[AC_PREREQ([2.62])dnl
-dnl Autoconf wants to disallow AM_ names.  We explicitly allow
-dnl the ones we care about.
-m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
-AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
-AC_REQUIRE([AC_PROG_INSTALL])dnl
-if test "`cd $srcdir && pwd`" != "`pwd`"; then
-  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
-  # is not polluted with repeated "-I."
-  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
-  # test to see if srcdir already configured
-  if test -f $srcdir/config.status; then
-    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
-  fi
-fi
-
-# test whether we have cygpath
-if test -z "$CYGPATH_W"; then
-  if (cygpath --version) >/dev/null 2>/dev/null; then
-    CYGPATH_W='cygpath -w'
-  else
-    CYGPATH_W=echo
-  fi
-fi
-AC_SUBST([CYGPATH_W])
-
-# Define the identity of the package.
-dnl Distinguish between old-style and new-style calls.
-m4_ifval([$2],
-[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
- AC_SUBST([PACKAGE], [$1])dnl
- AC_SUBST([VERSION], [$2])],
-[_AM_SET_OPTIONS([$1])dnl
-dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
-m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
-  [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
- AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
- AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
-
-_AM_IF_OPTION([no-define],,
-[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
- AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
-
-# Some tools Automake needs.
-AC_REQUIRE([AM_SANITY_CHECK])dnl
-AC_REQUIRE([AC_ARG_PROGRAM])dnl
-AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
-AM_MISSING_PROG(AUTOCONF, autoconf)
-AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
-AM_MISSING_PROG(AUTOHEADER, autoheader)
-AM_MISSING_PROG(MAKEINFO, makeinfo)
-AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
-AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
-AC_REQUIRE([AM_PROG_MKDIR_P])dnl
-# We need awk for the "check" target.  The system "awk" is bad on
-# some platforms.
-AC_REQUIRE([AC_PROG_AWK])dnl
-AC_REQUIRE([AC_PROG_MAKE_SET])dnl
-AC_REQUIRE([AM_SET_LEADING_DOT])dnl
-_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
-	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
-			     [_AM_PROG_TAR([v7])])])
-_AM_IF_OPTION([no-dependencies],,
-[AC_PROVIDE_IFELSE([AC_PROG_CC],
-		  [_AM_DEPENDENCIES(CC)],
-		  [define([AC_PROG_CC],
-			  defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
-AC_PROVIDE_IFELSE([AC_PROG_CXX],
-		  [_AM_DEPENDENCIES(CXX)],
-		  [define([AC_PROG_CXX],
-			  defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
-AC_PROVIDE_IFELSE([AC_PROG_OBJC],
-		  [_AM_DEPENDENCIES(OBJC)],
-		  [define([AC_PROG_OBJC],
-			  defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
-])
-_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl
-dnl The `parallel-tests' driver may need to know about EXEEXT, so add the
-dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This macro
-dnl is hooked onto _AC_COMPILER_EXEEXT early, see below.
-AC_CONFIG_COMMANDS_PRE(dnl
-[m4_provide_if([_AM_COMPILER_EXEEXT],
-  [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
-])
-
-dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
-dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
-dnl mangled by Autoconf and run in a shell conditional statement.
-m4_define([_AC_COMPILER_EXEEXT],
-m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
-
-
-# When config.status generates a header, we must update the stamp-h file.
-# This file resides in the same directory as the config header
-# that is generated.  The stamp files are numbered to have different names.
-
-# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
-# loop where config.status creates the headers, so we can generate
-# our stamp files there.
-AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
-[# Compute $1's index in $config_headers.
-_am_arg=$1
-_am_stamp_count=1
-for _am_header in $config_headers :; do
-  case $_am_header in
-    $_am_arg | $_am_arg:* )
-      break ;;
-    * )
-      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
-  esac
-done
-echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
-
-# Copyright (C) 2001, 2003, 2005, 2008  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# AM_PROG_INSTALL_SH
-# ------------------
-# Define $install_sh.
-AC_DEFUN([AM_PROG_INSTALL_SH],
-[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
-if test x"${install_sh}" != xset; then
-  case $am_aux_dir in
-  *\ * | *\	*)
-    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
-  *)
-    install_sh="\${SHELL} $am_aux_dir/install-sh"
-  esac
-fi
-AC_SUBST(install_sh)])
-
-# Copyright (C) 2003, 2005  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 2
-
-# Check whether the underlying file-system supports filenames
-# with a leading dot.  For instance MS-DOS doesn't.
-AC_DEFUN([AM_SET_LEADING_DOT],
-[rm -rf .tst 2>/dev/null
-mkdir .tst 2>/dev/null
-if test -d .tst; then
-  am__leading_dot=.
-else
-  am__leading_dot=_
-fi
-rmdir .tst 2>/dev/null
-AC_SUBST([am__leading_dot])])
-
-# Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
-# From Jim Meyering
-
-# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008
-# Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 5
-
-# AM_MAINTAINER_MODE([DEFAULT-MODE])
-# ----------------------------------
-# Control maintainer-specific portions of Makefiles.
-# Default is to disable them, unless `enable' is passed literally.
-# For symmetry, `disable' may be passed as well.  Anyway, the user
-# can override the default with the --enable/--disable switch.
-AC_DEFUN([AM_MAINTAINER_MODE],
-[m4_case(m4_default([$1], [disable]),
-       [enable], [m4_define([am_maintainer_other], [disable])],
-       [disable], [m4_define([am_maintainer_other], [enable])],
-       [m4_define([am_maintainer_other], [enable])
-        m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])])
-AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles])
-  dnl maintainer-mode's default is 'disable' unless 'enable' is passed
-  AC_ARG_ENABLE([maintainer-mode],
-[  --][am_maintainer_other][-maintainer-mode  am_maintainer_other make rules and dependencies not useful
-			  (and sometimes confusing) to the casual installer],
-      [USE_MAINTAINER_MODE=$enableval],
-      [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes]))
-  AC_MSG_RESULT([$USE_MAINTAINER_MODE])
-  AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes])
-  MAINT=$MAINTAINER_MODE_TRUE
-  AC_SUBST([MAINT])dnl
-]
-)
-
-AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
-
-# Check to see how 'make' treats includes.	            -*- Autoconf -*-
-
-# Copyright (C) 2001, 2002, 2003, 2005, 2009  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 4
-
-# AM_MAKE_INCLUDE()
-# -----------------
-# Check to see how make treats includes.
-AC_DEFUN([AM_MAKE_INCLUDE],
-[am_make=${MAKE-make}
-cat > confinc << 'END'
-am__doit:
-	@echo this is the am__doit target
-.PHONY: am__doit
-END
-# If we don't find an include directive, just comment out the code.
-AC_MSG_CHECKING([for style of include used by $am_make])
-am__include="#"
-am__quote=
-_am_result=none
-# First try GNU make style include.
-echo "include confinc" > confmf
-# Ignore all kinds of additional output from `make'.
-case `$am_make -s -f confmf 2> /dev/null` in #(
-*the\ am__doit\ target*)
-  am__include=include
-  am__quote=
-  _am_result=GNU
-  ;;
-esac
-# Now try BSD make style include.
-if test "$am__include" = "#"; then
-   echo '.include "confinc"' > confmf
-   case `$am_make -s -f confmf 2> /dev/null` in #(
-   *the\ am__doit\ target*)
-     am__include=.include
-     am__quote="\""
-     _am_result=BSD
-     ;;
-   esac
-fi
-AC_SUBST([am__include])
-AC_SUBST([am__quote])
-AC_MSG_RESULT([$_am_result])
-rm -f confinc confmf
-])
-
-# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
-
-# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008
-# Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 6
-
-# AM_MISSING_PROG(NAME, PROGRAM)
-# ------------------------------
-AC_DEFUN([AM_MISSING_PROG],
-[AC_REQUIRE([AM_MISSING_HAS_RUN])
-$1=${$1-"${am_missing_run}$2"}
-AC_SUBST($1)])
-
-
-# AM_MISSING_HAS_RUN
-# ------------------
-# Define MISSING if not defined so far and test if it supports --run.
-# If it does, set am_missing_run to use it, otherwise, to nothing.
-AC_DEFUN([AM_MISSING_HAS_RUN],
-[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
-AC_REQUIRE_AUX_FILE([missing])dnl
-if test x"${MISSING+set}" != xset; then
-  case $am_aux_dir in
-  *\ * | *\	*)
-    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
-  *)
-    MISSING="\${SHELL} $am_aux_dir/missing" ;;
-  esac
-fi
-# Use eval to expand $SHELL
-if eval "$MISSING --run true"; then
-  am_missing_run="$MISSING --run "
-else
-  am_missing_run=
-  AC_MSG_WARN([`missing' script is too old or missing])
-fi
-])
-
-# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# AM_PROG_MKDIR_P
-# ---------------
-# Check for `mkdir -p'.
-AC_DEFUN([AM_PROG_MKDIR_P],
-[AC_PREREQ([2.60])dnl
-AC_REQUIRE([AC_PROG_MKDIR_P])dnl
-dnl Automake 1.8 to 1.9.6 used to define mkdir_p.  We now use MKDIR_P,
-dnl while keeping a definition of mkdir_p for backward compatibility.
-dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
-dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
-dnl Makefile.ins that do not define MKDIR_P, so we do our own
-dnl adjustment using top_builddir (which is defined more often than
-dnl MKDIR_P).
-AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
-case $mkdir_p in
-  [[\\/$]]* | ?:[[\\/]]*) ;;
-  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
-esac
-])
-
-# Helper functions for option handling.                     -*- Autoconf -*-
-
-# Copyright (C) 2001, 2002, 2003, 2005, 2008  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 4
-
-# _AM_MANGLE_OPTION(NAME)
-# -----------------------
-AC_DEFUN([_AM_MANGLE_OPTION],
-[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
-
-# _AM_SET_OPTION(NAME)
-# ------------------------------
-# Set option NAME.  Presently that only means defining a flag for this option.
-AC_DEFUN([_AM_SET_OPTION],
-[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
-
-# _AM_SET_OPTIONS(OPTIONS)
-# ----------------------------------
-# OPTIONS is a space-separated list of Automake options.
-AC_DEFUN([_AM_SET_OPTIONS],
-[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
-
-# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
-# -------------------------------------------
-# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
-AC_DEFUN([_AM_IF_OPTION],
-[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
-
-# Check to make sure that the build environment is sane.    -*- Autoconf -*-
-
-# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008
-# Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 5
-
-# AM_SANITY_CHECK
-# ---------------
-AC_DEFUN([AM_SANITY_CHECK],
-[AC_MSG_CHECKING([whether build environment is sane])
-# Just in case
-sleep 1
-echo timestamp > conftest.file
-# Reject unsafe characters in $srcdir or the absolute working directory
-# name.  Accept space and tab only in the latter.
-am_lf='
-'
-case `pwd` in
-  *[[\\\"\#\$\&\'\`$am_lf]]*)
-    AC_MSG_ERROR([unsafe absolute working directory name]);;
-esac
-case $srcdir in
-  *[[\\\"\#\$\&\'\`$am_lf\ \	]]*)
-    AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);;
-esac
-
-# Do `set' in a subshell so we don't clobber the current shell's
-# arguments.  Must try -L first in case configure is actually a
-# symlink; some systems play weird games with the mod time of symlinks
-# (eg FreeBSD returns the mod time of the symlink's containing
-# directory).
-if (
-   set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
-   if test "$[*]" = "X"; then
-      # -L didn't work.
-      set X `ls -t "$srcdir/configure" conftest.file`
-   fi
-   rm -f conftest.file
-   if test "$[*]" != "X $srcdir/configure conftest.file" \
-      && test "$[*]" != "X conftest.file $srcdir/configure"; then
-
-      # If neither matched, then we have a broken ls.  This can happen
-      # if, for instance, CONFIG_SHELL is bash and it inherits a
-      # broken ls alias from the environment.  This has actually
-      # happened.  Such a system could not be considered "sane".
-      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
-alias in your environment])
-   fi
-
-   test "$[2]" = conftest.file
-   )
-then
-   # Ok.
-   :
-else
-   AC_MSG_ERROR([newly created file is older than distributed files!
-Check your system clock])
-fi
-AC_MSG_RESULT(yes)])
-
-# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# AM_PROG_INSTALL_STRIP
-# ---------------------
-# One issue with vendor `install' (even GNU) is that you can't
-# specify the program used to strip binaries.  This is especially
-# annoying in cross-compiling environments, where the build's strip
-# is unlikely to handle the host's binaries.
-# Fortunately install-sh will honor a STRIPPROG variable, so we
-# always use install-sh in `make install-strip', and initialize
-# STRIPPROG with the value of the STRIP variable (set by the user).
-AC_DEFUN([AM_PROG_INSTALL_STRIP],
-[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
-# Installed binaries are usually stripped using `strip' when the user
-# run `make install-strip'.  However `strip' might not be the right
-# tool to use in cross-compilation environments, therefore Automake
-# will honor the `STRIP' environment variable to overrule this program.
-dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
-if test "$cross_compiling" != no; then
-  AC_CHECK_TOOL([STRIP], [strip], :)
-fi
-INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
-AC_SUBST([INSTALL_STRIP_PROGRAM])])
-
-# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 2
-
-# _AM_SUBST_NOTMAKE(VARIABLE)
-# ---------------------------
-# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
-# This macro is traced by Automake.
-AC_DEFUN([_AM_SUBST_NOTMAKE])
-
-# AM_SUBST_NOTMAKE(VARIABLE)
-# ---------------------------
-# Public sister of _AM_SUBST_NOTMAKE.
-AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
-
-# Check how to create a tarball.                            -*- Autoconf -*-
-
-# Copyright (C) 2004, 2005  Free Software Foundation, Inc.
-#
-# This file 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.
-
-# serial 2
-
-# _AM_PROG_TAR(FORMAT)
-# --------------------
-# Check how to create a tarball in format FORMAT.
-# FORMAT should be one of `v7', `ustar', or `pax'.
-#
-# Substitute a variable $(am__tar) that is a command
-# writing to stdout a FORMAT-tarball containing the directory
-# $tardir.
-#     tardir=directory && $(am__tar) > result.tar
-#
-# Substitute a variable $(am__untar) that extract such
-# a tarball read from stdin.
-#     $(am__untar) < result.tar
-AC_DEFUN([_AM_PROG_TAR],
-[# Always define AMTAR for backward compatibility.
-AM_MISSING_PROG([AMTAR], [tar])
-m4_if([$1], [v7],
-     [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
-     [m4_case([$1], [ustar],, [pax],,
-              [m4_fatal([Unknown tar format])])
-AC_MSG_CHECKING([how to create a $1 tar archive])
-# Loop over all known methods to create a tar archive until one works.
-_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
-_am_tools=${am_cv_prog_tar_$1-$_am_tools}
-# Do not fold the above two line into one, because Tru64 sh and
-# Solaris sh will not grok spaces in the rhs of `-'.
-for _am_tool in $_am_tools
-do
-  case $_am_tool in
-  gnutar)
-    for _am_tar in tar gnutar gtar;
-    do
-      AM_RUN_LOG([$_am_tar --version]) && break
-    done
-    am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
-    am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
-    am__untar="$_am_tar -xf -"
-    ;;
-  plaintar)
-    # Must skip GNU tar: if it does not support --format= it doesn't create
-    # ustar tarball either.
-    (tar --version) >/dev/null 2>&1 && continue
-    am__tar='tar chf - "$$tardir"'
-    am__tar_='tar chf - "$tardir"'
-    am__untar='tar xf -'
-    ;;
-  pax)
-    am__tar='pax -L -x $1 -w "$$tardir"'
-    am__tar_='pax -L -x $1 -w "$tardir"'
-    am__untar='pax -r'
-    ;;
-  cpio)
-    am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
-    am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
-    am__untar='cpio -i -H $1 -d'
-    ;;
-  none)
-    am__tar=false
-    am__tar_=false
-    am__untar=false
-    ;;
-  esac
-
-  # If the value was cached, stop now.  We just wanted to have am__tar
-  # and am__untar set.
-  test -n "${am_cv_prog_tar_$1}" && break
-
-  # tar/untar a dummy directory, and stop if the command works
-  rm -rf conftest.dir
-  mkdir conftest.dir
-  echo GrepMe > conftest.dir/file
-  AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
-  rm -rf conftest.dir
-  if test -s conftest.tar; then
-    AM_RUN_LOG([$am__untar <conftest.tar])
-    grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
-  fi
-done
-rm -rf conftest.dir
-
-AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
-AC_MSG_RESULT([$am_cv_prog_tar_$1])])
-AC_SUBST([am__tar])
-AC_SUBST([am__untar])
-]) # _AM_PROG_TAR
-
+      jmp_pc[0] = jmp_pc[0] + (uint32_t) b;
+    *aCode=tb1; return sz;
+  case c_jmpnjv:
+  case c_jxxv: 
+    p = (unsigned char *) map_va (pc + sz);
+    if (!p) { *aCode=c_ill; return 0; }
+    if (oper_mode) { jmp_pc[0]=*((uint32_t *)p); sz+=4; }
+    else {
+      jmp_pc[0]=(uint32_t) *((uint16_t *)p);
+      if ((jmp_pc[0]&0x8000)!=0) jmp_pc[0]|=0xffff0000;
+      sz+=2;
+    }
+    jmp_pc[0]+=(uint32_t) pc+(uint32_t) sz;
+#if ENABLE_DEBUG == 1
+    if ((jmp_pc[0]&0xff000000)!=0) {
+      print_save_insn (name, lw);
+      PRDEBUG(" 0x%x illegal ", (unsigned int) b);
+      PRDEBUG("jmp(cond) 0x%x (sz=%x,pc=%x,off=%x) ",
+	      jmp_pc[0], (unsigned int) sz,(unsigned int) pc,
+              (unsigned int) (jmp_pc[0]-(sz+pc)));
+    }
+#endif
+    *aCode=(tb1==c_jxxv ? c_jxx : tb1);
+    return sz;
+  case c_0f:
+    p = (unsigned char *) map_va (pc + sz);
+    if (!p) { *aCode=c_ill; return 0; }
+    b = p[0];
+    sz++;
+    tb1=opMap2[b];
+    goto redo_switch;
+  case c_jmpfap:
+    sz+=4; if(oper_mode) sz+=2;
+    *aCode=tb1; return sz;
+  case c_callfar:
+    sz+=4; if(oper_mode) sz+=2;
+    *aCode=tb1; return sz;
+  case c_retflw: case c_retnlw:
+    p = (unsigned char *) map_va (pc + sz);
+    if (!p) { *aCode=c_ill; return 0; }
+    jmp_pc[0]=*((uint16_t*) p);
+    sz+=2;
+    *aCode=tb1;
+#if ENABLE_DEBUG == 1
+    if (jmp_pc[0]>0x100 || jmp_pc[0]&3) {
+      print_save_insn (name, lw);
+      PRDEBUG(" 0x%x illegal ", (unsigned int) b);
+      PRDEBUG("ret dw 0x%x (sz=%x) ", (unsigned int) jmp_pc[0], (unsigned int) sz);
+    }
+#endif
+    return sz;
+  default:
+    PRDEBUG(" * opcode 0x%x (tbl=%d) unknown\n", (unsigned int) b, tb1);
+    sz=0; *aCode=c_ill; break;
+  }
+  return sz;
+}
+
+static void
+decode_mangle (FILE *fp, const char *n)
+{
+#ifdef HAVE_LIBMANGLE
+  libmangle_gc_context_t *gc = libmangle_generate_gc ();
+  libmangle_tokens_t ptok;
+#endif
+  if (!fp || !n || *n == 0)
+    return;
+#ifdef HAVE_LIBMANGLE
+  ptok = libmangle_decode_ms_name (gc, n);
+  if (ptok)
+    {
+      char *h = libmangle_sprint_decl (ptok);
+      if (h)
+	{
+	  fprintf (fp, "; %s\n", h);
+	  free (h);
+	}
+    }
+  libmangle_release_gc (gc);
+#endif
+}
gendef/config.h.in to gendef/gendef_def.c
--- a/gendef/config.h.in
+++ b/gendef/gendef_def.c
@@ -1,108 +1,311 @@
-/* config.h.in.  Generated from configure.ac by autoheader.  */
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define to 1 if you have the `mangle' library (-lmangle). */
-#undef HAVE_LIBMANGLE
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define to 1 if you have the `memset' function. */
-#undef HAVE_MEMSET
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the `strdup' function. */
-#undef HAVE_STRDUP
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the `strlwr' function. */
-#undef HAVE_STRLWR
-
-/* Define to 1 if you have the `strrchr' function. */
-#undef HAVE_STRRCHR
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the home page for this package. */
-#undef PACKAGE_URL
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* Version number of package */
-#undef VERSION
-
-/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
-   <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
-   #define below would cause a syntax error. */
-#undef _UINT32_T
-
-/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
-   <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
-   #define below would cause a syntax error. */
-#undef _UINT64_T
-
-/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>,
-   <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
-   #define below would cause a syntax error. */
-#undef _UINT8_T
-
-/* Define to the type of a signed integer type of width exactly 32 bits if
-   such a type exists and the standard includes do not define it. */
-#undef int32_t
-
-/* Define to `unsigned int' if <sys/types.h> does not define. */
-#undef size_t
-
-/* Define to the type of an unsigned integer type of width exactly 16 bits if
-   such a type exists and the standard includes do not define it. */
-#undef uint16_t
-
-/* Define to the type of an unsigned integer type of width exactly 32 bits if
-   such a type exists and the standard includes do not define it. */
-#undef uint32_t
-
-/* Define to the type of an unsigned integer type of width exactly 64 bits if
-   such a type exists and the standard includes do not define it. */
-#undef uint64_t
-
-/* Define to the type of an unsigned integer type of width exactly 8 bits if
-   such a type exists and the standard includes do not define it. */
-#undef uint8_t
+/*
+   Copyright (c) 2009, 2010 mingw-w64 project
+
+   Contributing authors: Kai Tietz, Jonathan Yong
+
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included in
+   all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <string.h>
+#include "compat_string.h"
+#include "gendef.h"
+
+typedef struct sImpDef {
+  struct sImpDef *next;
+  char *name;
+  char *data;
+  size_t length;
+} sImpDef;
+
+static sImpDef *theImpDef = NULL;
+
+typedef struct sDefPaths {
+  struct sDefPaths *next;
+  char path[1];
+} sDefPaths;
+
+static sDefPaths *thePathDefs;
+
+static int find_path_def (const char *path);
+static int add_path_def (const char *path);
+
+static sImpDef *is_def_loaded (const char *);
+static sImpDef *gendef_loaddef (const char *);
+static FILE *fopen_def (const char *name);
+static uint32_t get_uint32_by_str (const char *txt);
+
+int
+gendef_getsymbol_info (const char *dllname, const char *symbolname, int *isData, uint32_t *at)
+{
+  char *r1 = NULL, *r2 = NULL, *def;
+  sImpDef *id;
+  size_t symlen;
+  int ret = 0;
+
+  if (!dllname)
+    return 0;
+  if (!symbolname || *symbolname == 0)
+    {
+      char *h = strchr (dllname, '.');
+      if (!h)
+	return 0;
+      r1 = strdup (h + 1);
+      if (*r1 == '#')
+	{
+	  r2 = (char *) malloc (strlen (r1) + 5);
+	  sprintf (r2, "ord_%s", r1 + 1);
+	  free (r1);
+	  r1 = r2;
+	}
+      symbolname = r1;
+      r2 = strdup (dllname);
+      strcpy (strchr (r2, '.'), ".dll");
+      dllname = r2;
+    }
+  def = (char *) malloc (strlen (dllname) + 4);
+  strcpy (def, dllname);
+  strlwr (def);
+  if (strchr (def, '.') == NULL)
+    strcat (def, ".def");
+  else
+    strcpy (strchr (def, '.'), ".def");
+  symlen = strlen (symbolname);
+  id = gendef_loaddef (def);
+  if (id)
+    {
+      char *t = id->data;
+      while (t != NULL && *t != 0)
+	{
+	  t = strchr (t, '\n');
+	  if (t)
+	    t++;
+	  if (t && strncmp (t, symbolname, symlen) == 0)
+	    {
+	      if ((t[symlen] > 0 && t[symlen] <= 0x20) || t[symlen] == '@')
+		{
+		  t += symlen + 1;
+		  *at = get_uint32_by_str (t);
+		  while (*t != 0 && *t != '\n')
+		    {
+		      if (!strncmp (t, "DATA", 4))
+			{
+			  *isData = 1;
+			  break;
+			}
+		      t++;
+		    }
+		  ret = 1;
+		  break;
+		}
+
+	    }
+	}
+    }
+  if (def)
+    free (def);
+  if (r2 != NULL && r1 != r2)
+    free (r2);
+  if (r1 != NULL)
+    free (r1);
+  return ret;
+}
+
+static FILE *
+fopen_def (const char *name)
+{
+  sDefPaths *l = thePathDefs;
+  FILE *fp;
+  if ((fp = fopen (name, "rb")) != NULL)
+    return fp;
+  while (l != NULL)
+    {
+      char *h = (char *) malloc (strlen (name) + strlen (l->path) + 1);
+      if (h)
+	{
+	  strcpy (h, l->path);
+	  strcat (h, name);
+	  fp = fopen (h, "rb");
+	  free (h);
+	  if (fp)
+	    return fp;
+	}
+      l = l->next;
+    }
+  return NULL;
+}
+
+static sImpDef *
+gendef_loaddef (const char *name)
+{
+  sImpDef *n;
+  FILE *fp;
+  char *lname;
+  size_t len;
+  char *txt;
+  if (!name || *name == 0)
+    return NULL;
+  lname = strdup (name);
+  if (!lname)
+    return NULL;
+  strlwr (lname);
+  n = is_def_loaded (lname);
+  if (n)
+    {
+      free (lname);
+      return n;
+    }
+  fp = fopen_def (name);
+  if (!fp)
+    {
+      free (lname);
+      return NULL;
+    }
+  fseek (fp, 0, SEEK_END);
+  len = (size_t) ftell (fp);
+  fseek (fp, 0, SEEK_SET);
+  txt = (char *) malloc (len + 1);
+  if (!txt)
+    {
+      fclose (fp);
+      free (lname);
+      return NULL;
+    }
+  if ((size_t) fread (txt, 1, len, fp) != len)
+    {
+      fclose (fp);
+      free (lname);
+      free (txt);
+      return NULL;
+    }
+  fclose (fp);
+  txt[len] = 0;
+
+  n = (sImpDef *) malloc (sizeof (sImpDef));
+  if (!n)
+    {
+      free (lname);
+      free (txt);
+      return NULL;
+    }
+  memset (n, 0, sizeof (sImpDef));
+  n->name = lname;
+  n->data = txt;
+  n->length = len;
+  n->next = theImpDef;
+  theImpDef = n;
+  return n;
+}
+
+static sImpDef *
+is_def_loaded (const char *dname)
+{
+  sImpDef *h = theImpDef;
+  while (h != NULL)
+    {
+      if (!strcasecmp (h->name, dname))
+	break;
+      h = h->next;
+    }
+  return h;
+}
+
+static uint32_t
+get_uint32_by_str (const char *txt)
+{
+  uint32_t ret = 0;
+  while (*txt != 0 && *txt >= '0' && *txt <= '9')
+    {
+      ret *= 10;
+      ret += (uint32_t) (txt[0] - '0');
+      ++txt;
+    }
+  return ret;
+}
+
+int
+gendef_addpath_def (const char *path)
+{
+  if (find_path_def (path))
+    return 1;
+  return add_path_def (path);
+}
+
+static int
+find_path_def (const char *path)
+{
+  char *h, *p;
+  sDefPaths *l = thePathDefs;
+  if (!l)
+    return 0;
+  h = (char *) malloc (strlen (path) + 2);
+  if (!h)
+    return 0;
+  strcpy (h, path);
+  for (p = h; *p != 0; p++)
+    if (p[0] == '\\')
+      p[0] = '/';
+  if (p != h && p[-1] != '/')
+    strcat (p, "/");
+  while (l != NULL)
+    {
+      if (!strcmp (l->path, h))
+        {
+	  free (h);
+	  return 1;
+        }
+      l = l->next;
+    }
+  free (h);
+  return 0;
+}
+
+static int
+add_path_def (const char *path)
+{
+  char *h, *p;
+  sDefPaths *l;
+  h = (char *) malloc (strlen (path) + 2);
+  if (!h)
+    return 0;
+  strcpy (h, path);
+  for (p = h; *p != 0; p++)
+    if (p[0] == '\\')
+      p[0] = '/';
+  if (p != h && p[-1] != '/')
+    strcat (p, "/");
+  l = (sDefPaths *) malloc (sizeof (sDefPaths) + strlen (h) + 1);
+  if (!l)
+    {
+      free (h);
+      return 0;
+    }
+  memset (l, 0, sizeof (sDefPaths));
+  strcpy (l->path, h);
+  free (h);
+  l->next = thePathDefs;
+  thePathDefs = l;
+  return 1;
+}
+
1 2 3 4 > >> (Page 1 of 4)