Thursday, June 18, 2015

run idascript script to batch files

Problem


I had idapython script for extracting some data from file. And a lot of files, where from needed to extract these data.

Code


"C:\Program Files (x86)\IDA 6.8\idaw.exe" -Lfilename.log -A -S_try_script.py filename

it will open 'filename' in console ida and run script '_try_script.py'. In this script 'main' must be like that:

if __name__ == '__main__':
    idaapi.autoWait()
    my_analyze_func()
    Exit(0)


it waits to complete autoanalysis, executes script and exit. Ida console log will be in 'filename.log'.
So, you can use it from batch handling of the files.

self-unpacking archives from cmd

Problem


Recently I've needed to pack several files (exe+dll) into one executable, which after unpacking of content will run one of unpacked files. And do this with several bunches of files - so, console commands needed - not gui. It's some constant executable need to test with different dll


Tools

  • 7z
  • 7zS.sfx (I've found it in something like 7z-extra-922.7z)
  • Python


Action


First of all - you need to make file config.txt where you write program name, which must be run after unpacking (in my case I've needed to make dll think it's in IE, so my program name is 'iexplore.exe', but it's just executable, which loads 'current.dll' and waits)

;!@Install@!UTF-8!
Title="7-Zip 4.00"
Directory=""
RunProgram="%%T\\iexplore.exe"
;!@InstallEnd@!


it must be in UTF-8, so you can save it in UTF-8 from notepad.exe, for example.

and here are python script, where you can find all necessary tools & keys:

import shutil    # copy2
import os

filenames = [
'dll_00.dll',
'dll_01.dll',
'dll_02.dll',
]

def run():
    for filename in filenames:
        shutil.copy2(filename, './current.dll')
        os.system('"C:\\Program Files\\7-Zip\\7z.exe" a archive.7z ./iexplore.exe ./current.dll')
       
        destination = open(filename+'.sfx.exe', 'wb')
        shutil.copyfileobj(open(r"D:\tools\7z-extra-920\7zS.sfx", 'rb'), destination)
        shutil.copyfileobj(open(r"config.txt", 'rb'), destination)
        shutil.copyfileobj(open(r"archive.7z", 'rb'), destination)
        destination.close()
       
        os.system('sfx_handler '+filename+'.sfx.exe')
        os.remove('archive.7z')
        os.remove('current.dll')

if __name__ == '__main__':
    run()

build sigc++ in visual studio

Problem


I need to compile static x64 library sigc++ with static runtime in Visual Studio 2013. It's required to compile glibmm.


Tools and versions:
  • sigc++ 2.4.1 (will also note of 2.0.6 version)
  • visual studio 2013
  • cygwin (32-bits in my case)

Action


1. At http://libsigc.sourceforge.net/stable.shtml find link on ftp & download some (for today last version - 2.4.1).
2. open Cygwin.bat
3. go to dir with sigc++
4. ./configure
5. in 'sigc++config.h' comment '#  define SIGC_DLL 1'it needs only if you want to build static library. __declspec(dllimport) from defines will fail building otherwise.
be attentive - there are as minimum two files, where you must to do it:
- libsigc++-2.4.1\sigc++config.h
- libsigc++-2.4.1\MSVC_Net2010\sigc++config.h
6. open 'D:\tmp\libraries\libsigc++-2.4.1\MSVC_Net2010\libsigc++2.sln'
7. in 'project settings -> general' of the project 'libsigc++' set 'static library'
8. set runtime library /MT or /MTd in:
  • all projects properties
  • in all files in project libsigc++
  • in property sheets 'Upgrade from VC 7.1', 'Microsoft.Cpp.x64.user'
9. build
here will built a lot of exe - no one must crashes


Note for those who builds it for glibmm


You need to compile it also with cygwin (it will be required by glibmm to generate some source files). So, open x32 cygwin (don't know if x64 cygwin will works - on some another projects it didn't work), go to directory with sources (for example it's 'd:/projects/libraries/libxmlplusplus/libsig++-2.4.1'), and exec:
./configure --prefix=d:/projects/libraries/libxmlplusplus/libsigc++-2.4.1/_cygwin
make
make install

and copy
    D:\projects\libraries\libxmlplusplus\libsigc++-2.4.1\sigc++config.h
to
    D:\projects\libraries\libxmlplusplus\libsigc++-2.4.1\_cygwin\include\sigc++-2.0\sigc++config.h
and don't forget check - '#  define SIGC_DLL 1' must be commented.

Note of version 2.0.6.

After ./configure you need to make several addition steps:
  • add path to sigc++ library into 'additional include directories' in every test project
  • insert '#include <cstddef>' into the beginning of files: signal_base.h, signal.h
  • in 'test_deduce_result_type' replace "main()" to "int main()" & insert "return 0;" into the end of main function.
  • also maybe you will need to comment define 'SIGC_TYPEDEF_REDEFINE_ALLOWED'.
  • replace sig++config.h in root sig++ directory by file sig++config.h from MSVC_Net2003 directory.
Msys built 2.0.6 correctly.
Also interesting - in the internet people advices open solution file after ./configure & make, but I've found make don't change source files - so, you don't need to call 'make' - only './configure'.

build glib in Visual Studio

Problem.


I've needed to build glib (actually finally I want to get libxml++, and glib is one of dependencies). Will do it static library with static runtime (/MT and /MTd) x64. Firstly I wanted to build only part of glib, but finally I built whole library successfully.

Tools and versions (my case):

  • Visual Studio 2013
  • Python (I have python 2.7)
  • Perl (I have ActivePerl x64) 
  • git client
  • x32 cygwin
  • far manager
  • notepad++
  • Compiled intl (version 20090911) in Visual Studio 2013 - [link]
  • Compiled pcre (version 8.37) in Visual Studio 2013 - [link]
  • Compiled libffi (version 3.2.1) in Visual Studio 2013 - [link]
  • Compiled zlib (version 1.2.8) in Visual Studio 2013 - [link]
glib version - it's near 2.45.3
Date: (02.07.2015 14:06:17)
Commit hash: e337fe31637fe868ab94b488caf9b4898a2a1040
just last commit from git for the moment of compilation.

Action


1. git clone git://git.gnome.org/glib

2. open x32 cygwin - Cygwin.bat

3. go to dir with glib sources

4. replace all '\r' to '' in files (I did it in notepad++):
  • autogen.sh
  • configure.ac
5. exec in cygwin:
  • ./autogen.sh
  • cd ./gio
  • make
it must finishes with error, but it will create file 'gdbus-daemon-generated.c' - it's everything what we need.
Now we don't need cygwin - can close it.

6.exec python script (I did it with python 2.7), located in 'glib/build/win32':
python setup.py --perl=C:\Perl64\bin\perl.exe

it's like ./configure. For example, it copies config.h.win32 to config.h with replacing some substrings to real value (for example - @MAJOR_VERSION@ to concrete number) - without it visual studio can't find config.h. Also here are exists './glib/win32-fixup.pl', but you don't need touch this file - I think it's deprecated.
But it's not fully-functional configure, bcs it doesn't create file 'gdbus-daemon-generated.c', and we still need to exec autogen & make before it.

7. open ./glib/build/win32/vs10/glib.sln


8. choose mode x64 (I will consider modes Debug_ExtPCRE and Release_ExtPCRE)

9. in project properties, general -> change 'dynamic library' to 'static library' for projects:
  • gio
  • glib
  • gmodule
  • gobject 
  • gthread

10. open 'property sheets' and delete all 'user macros' in sheet named 'glibgensrcsprops'

11. Create two property sheets - one for release x64, another for debug x64. I assume all 4 dependency libraries located in 'D:\projects\libraries\libxmlplusplus' and built by my instructions.

Release_ExtPCRE x64:
  • additional include directories
    • D:\projects\libraries\libxmlplusplus\intl\_build_x64_static_release_mt\include
    • D:\projects\libraries\libxmlplusplus\pcre-8.37\_build_x64_static_release_mt\include
    • D:\projects\libraries\libxmlplusplus\libffi-3.2.1\_build_x64_static_release_mt\include
    • D:\projects\libraries\libxmlplusplus\zlib-1.2.8\_build_x64_static_release_mt\include
  • additional library directories
    • D:\projects\libraries\libxmlplusplus\intl\_build_x64_static_release_mt\lib
    • D:\projects\libraries\libxmlplusplus\pcre-8.37\_build_x64_static_release_mt\Release
    • D:\projects\libraries\libxmlplusplus\libffi-3.2.1\_build_x64_static_release_mt\.libs
    • D:\projects\libraries\libxmlplusplus\zlib-1.2.8\_build_x64_static_release_mt\lib
  • input 
    • ws2_32.lib
    • winmm.lib
    • libffi_convenience.lib
    • Iphlpapi.lib
    • Dnsapi.lib
    • zlib.lib
    • pcre.lib
 Debug_ExtPCRE x64:
  • additional include directories
    • D:\projects\libraries\libxmlplusplus\intl\_build_x64_static_debug_mtd\include
    • D:\projects\libraries\libxmlplusplus\pcre-8.37\_build_x64_static_debug_mtd\include
    • D:\projects\libraries\libxmlplusplus\libffi-3.2.1\_build_x64_static_debug_mtd\include
    • D:\projects\libraries\libxmlplusplus\zlib-1.2.8\_build_x64_static_debug_mtd\include
  • additional library directories
    • D:\projects\libraries\libxmlplusplus\intl\_build_x64_static_debug_mtd\lib
    • D:\projects\libraries\libxmlplusplus\pcre-8.37\_build_x64_static_debug_mtd\Debug
    • D:\projects\libraries\libxmlplusplus\libffi-3.2.1\_build_x64_static_debug_mtd\.libs
    • D:\projects\libraries\libxmlplusplus\zlib-1.2.8\_build_x64_static_debug_mtd\lib
  • input 
    • ws2_32.lib
    • winmm.lib
    • libffi_convenience.lib
    • Iphlpapi.lib
    • Dnsapi.lib
    • zlib.lib
    • pcred.lib
add this property lists to every project in solution



12. Set static runtime (/MT and /MTd accordingly) for all projects except:
  • glib-install
  • gspawn-win32-helper
  • gspawn-win32-helper-console
glib-install - it's some strange thing - without code. gspawn-win32-helper and gspawn-win32-helper-console required some function (__wgetmainargs), which present only in dinamic library.

13. The goal of this step - get rid from dll export (if you don't do it - executables, which use libxml++ will have export O_o. So, you need make several replaces.
in 'glib\glib\gtypes.h':
  • '#          define GLIB_VAR __declspec(dllexport)' -> '#          define GLIB_VAR extern'
  • '#        define GLIB_VAR extern __declspec(dllimport)' -> '#        define GLIB_VAR extern'
in 'glib\config.h':
  • '#define _GLIB_EXTERN __declspec (dllexport) extern' -> '#define _GLIB_EXTERN extern'
in 'glib\gobject\gparamspecs.h' :
  • '#          define GOBJECT_VAR __declspec(dllexport)' -> '#          define GOBJECT_VAR extern'
  • #        define GOBJECT_VAR extern __declspec(dllimport)' -> '#        define GOBJECT_VAR extern'
14. find property sheet 'glibbuilddefinesprops' (for example, it's property sheet of 'glib-compile-resources' project), open 'user macros' and delete:
DllExportDefines    Dll_EXPORT


15. And finally one dirty hack) The point is - looks like glib usually used on Windows only as dynamic library. In dynamic libraries on Windows exists function DllMain, which in glib implemented to fill some internal structure with pointers to internal functions. When you build this library as static, there are no called DllMain, this structure is not initialized (filled by zeros), and glibmm has some global object, and everything crashes into constructor of this object, because it calles some glib function, and executed 'call' by address zero.
So, the point of my dirty hack is - initialize this internal structure in the first glib function, which called from glibmm.
so, in file glib -> glib_init.c


BOOL WINAPI DllMain (HINSTANCE hinstDLL,
                     DWORD     fdwReason,
                     LPVOID    lpvReserved);

HMODULE glib_dll;

BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
         DWORD     fdwReason,
         LPVOID    lpvReserved)
{
  switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
      glib_dll = hinstDLL;
      g_clock_win32_init ();
#ifdef THREADS_WIN32
      g_thread_win32_init ();
#endif
      glib_init ();
      break;

    case DLL_THREAD_DETACH:
#ifdef THREADS_WIN32
      g_thread_win32_thread_detach ();
#endif
      break;

    default:
      /* do nothing */
      ;
    }

  return TRUE;
}


replace by

HMODULE glib_dll;

int is_glib_initialized = 0;

void
glib_init_ctor (void)
{
    if (is_glib_initialized == 0)
    {
        glib_dll = 0;
        g_clock_win32_init ();
        g_thread_win32_init ();
        glib_init ();
        is_glib_initialized = 1;
    }
}


and in glib -> gthread-win32.c

void
g_mutex_init (GMutex *mutex)
{
  g_thread_impl_vtable.InitializeSRWLock (mutex);
}


replace by

extern void glib_init_ctor(void);
void
g_mutex_init (GMutex *mutex)
{
  glib_init_ctor();
  g_thread_impl_vtable.InitializeSRWLock (mutex);
}


16. build all

unsuccessful can be only: gspawn-win32-helper and gspawn-win32-helper-console. It's okay.

    Possible errors for googling people


    problem - you didn't called 'setup.py'  
    -----------------------------------------------
    1>  Copying config.h from config.h.win32...
    1>  The system cannot find the file specified
    -----------------------------------------------
    what to do - step 2 in this post

    Saturday, June 13, 2015

    proxy-libintl note

    proxy-libintl - it's tiny library for glib - used for it's internal purposes - as proxy library. It consists of 2 files: libintl.h and libintl.c. To build this library - just create 'static library' visual studio project (name it 'intl', bcs glib wait file intl.lib), add these files to project, set mode & settings (/MT & /MTd in my case) and just build it.
    Download sources you can here.

    Also you can copy symbols to the library (without it you will receive warnings later). For example, if you put lib file into subdirectories _build_x64_static_debug_mtd/lib and _build_x64_static_release_mt/lib, you can copy
    intl\intl\x64\Debug\vc120.pdb
        to
    intl\_build_x64_static_debug_mtd\lib\vc120.pdb
    and
    intl\intl\x64\Release\vc120.pdb
        to
    intl\_build_x64_static_release_mt\lib\vc120.pdb

    building libffi on windows by visual studio

    problem


    It's not trivial task - build libffi by visual studio.


    tools & versions


    What do you need to build libffi on windows:
    • Visual Studio (2013 in my case)
    • Cygwin 32-bits (I don't know why but cygwin64 doesn't work)

    problem solving in a short for x64

    0. Download and unpack (I'm using FAR manager for unpacking) libffi sources.
    1. Run "VS2013 x64 Native Tools Command Prompt"
    2. Open in it Cygwin.bat, for example:
        c:\cygwin\Cygwin.bat
    3. Go to directory with sources, for example:
        cd d:/tmp/libraries/libffi-3.2.1
    4. Make directory for building and go to it, for example:
        mkdir build-x64
        cd ./build-x64
    5. Then you need to configure, and here you need decide which runtime do you want - dynamic (/MD) or static (/MT)
        dynamic (/MD): ../configure CC="../msvcc.sh -m64" CXX="../msvcc.sh -m64" LD=link CPP="cl -nologo -EP" --build=x86_64-unknown-cygwin
        static release (/MT): ../configure CC="../msvcc.sh -DUSE_STATIC_RTL -m64" CXX="../msvcc.sh -DUSE_STATIC_RTL -m64" LD=link CPP="cl -nologo -EP" --build=x86_64-unknown-cygwin
        static debug (/MTd): ../configure CC="../msvcc.sh -DUSE_STATIC_RTL -DUSE_DEBUG_RTL -m64" CXX="../msvcc.sh -DUSE_STATIC_RTL -DUSE_DEBUG_RTL -m64" LD=link CPP="cl -nologo -EP" --build=x86_64-unknown-cygwin
    6. Then in ./include/ffitarget.h will be symlink (visual studio don't understand symlinks) - and this symlink has some strange access rights, so, for example in FAR manager (not in this cygwin console) do the next:
        - delete './include/ffitarget.h'
        - copy '../src/x86/ffitarget.h' to './include/ffitarget.h'
    7. And in this ffitarget.h file you need to comment define '#define FFI_TARGET_HAS_COMPLEX_TYPE'
    8. Using any text editor - in 'libffi-3.2.1\src\x86\win64.S' replace 'jmp SHORT' to 'jmp' under labels:
        'ret_uint16$:'
        'ret_sint16$:'
    9. make
    10. In subdirectory ./.libs you will get files.


    problem solving in a short for x86


    0. Download and unpack (I'm using FAR manager for unpacking) libffi sources.
    1. Run "VS2013 x86 Native Tools Command Prompt"
    2. Open in it Cygwin.bat, for example:
        c:\cygwin\Cygwin.bat
    3. Go to directory with sources, for example:
        cd d:/tmp/libraries/libffi-3.2.1
    4. Make directory for building and go to it, for example:
        mkdir build-x86
        cd ./build-x86
    5. Then you need to configure, and here you need decide which runtime do you want - dynamic (/MD) or static (/MT)
        dynamic: .../configure CC="../msvcc.sh" CXX="../msvcc.sh" LD=link CPP="cl -nologo -EP" --build=i686-unknown-cygwin
        static: ../configure CC="../msvcc.sh -DUSE_STATIC_RTL" CXX="../msvcc.sh -DUSE_STATIC_RTL" LD=link CPP="cl -nologo -EP" --build=i686-unknown-cygwin
    6. Then in ./include/ffitarget.h will be symlink, and visual studio don't understand symlinks - so, replace it by real file.    cp ../src/x86/ffitarget.h ./include
    7. And in this ffitarget.h file you need to comment define '#define FFI_TARGET_HAS_COMPLEX_TYPE'
    8. make
    9. In subdirectory ./.libs you will get files.


    useful sources and links

    0. 'README' file in sources gives you couple advices, but it's not enough
    1. This guy also gives good advices - [link], I've backuped it [here]


    possible errors (for googling people)

    1) if you open cygwin64\Cygwin.bat instead of cygwin\Cygwin.bat
        -----------------------------------------------------------------------------
        checking how to run the C++ preprocessor... /lib/cpp
        configure: error: in `/cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64':
        configure: error: C++ preprocessor "/lib/cpp" fails sanity check
        See `config.log' for more details
        -----------------------------------------------------------------------------
        what to do - use 32-bits cygwin

    2) if you set --build=i686... instead of --build=x86_64..., when you want x64 binaries
        -----------------------------------------------------------------------------
        ml -nologo -safeseh -c  ./win32.asm
        ../msvcc.sh: line 241: ml: command not found
        Makefile:1338: ошибка выполнения рецепта для цели <src/x86/win32.lo>
        make[2]: *** [src/x86/win32.lo] Ошибка 1
        make[2]: выход из каталога </cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64>
        Makefile:1596: ошибка выполнения рецепта для цели <all-recursive>
        make[1]: *** [all-recursive] Ошибка 1
        make[1]: выход из каталога </cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64>
        Makefile:730: ошибка выполнения рецепта для цели <all>
        make: *** [all] Ошибка 2
        -----------------------------------------------------------------------------

        what to do - use --build=i686-unknown-cygwin

    3) if you forgot replace symlink by real file
        -----------------------------------------------------------------------------
        include\ffitarget.h(1) : error C2059: syntax error : '!'
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\crtdefs.h(642) : error C2081: 'uintptr_t' : name in formal parameter list illegal
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\stddef.h(71) : error C2143: syntax error : missing '{' before '__cdecl'
        include\ffi.h(223) : error C2016: C requires that a struct or union has at least one member
        include\ffi.h(223) : error C2061: syntax error : identifier 'ffi_abi'
        include\ffi.h(232) : error C2059: syntax error : '}'
        include\ffi.h(240) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(240) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(241) : error C2146: syntax error : missing ';' before identifier 'abi'
        include\ffi.h(242) : error C2059: syntax error : 'type'
        include\ffi.h(246) : error C2059: syntax error : ')'
        include\ffi.h(263) : error C2016: C requires that a struct or union has at least one member
        include\ffi.h(263) : error C2061: syntax error : identifier 'ffi_sarg'
        include\ffi.h(264) : error C2061: syntax error : identifier 'uint'
        include\ffi.h(264) : error C2059: syntax error : ';'
        include\ffi.h(268) : error C2059: syntax error : '}'
        include\ffi.h(281) : error C2061: syntax error : identifier 'ffi_java_raw'
        include\ffi.h(281) : error C2059: syntax error : ';'
        include\ffi.h(285) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(285) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(286) : error C2059: syntax error : 'type'
        include\ffi.h(290) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(290) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(290) : error C2059: syntax error : 'type'
        include\ffi.h(290) : error C2059: syntax error : ')'
        include\ffi.h(291) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(291) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(291) : error C2143: syntax error : missing ';' before '*'
        include\ffi.h(291) : error C2059: syntax error : 'type'
        include\ffi.h(291) : error C2059: syntax error : ')'
        include\ffi.h(292) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(292) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(292) : error C2059: syntax error : ')'
        include\ffi.h(298) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(298) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(299) : error C2059: syntax error : 'type'
        include\ffi.h(303) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(303) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(303) : error C2059: syntax error : 'type'
        include\ffi.h(303) : error C2059: syntax error : ')'
        include\ffi.h(304) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(304) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(304) : error C2143: syntax error : missing ';' before '*'
        include\ffi.h(304) : error C2059: syntax error : 'type'
        include\ffi.h(304) : error C2059: syntax error : ')'
        include\ffi.h(305) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(305) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(305) : error C2059: syntax error : ')'
        include\ffi.h(433) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(433) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(434) : error C2146: syntax error : missing ';' before identifier 'abi'
        include\ffi.h(435) : error C2059: syntax error : 'type'
        include\ffi.h(437) : error C2059: syntax error : ')'
        include\ffi.h(439) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(439) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(440) : error C2146: syntax error : missing ';' before identifier 'abi'
        include\ffi.h(441) : error C2059: syntax error : 'type'
        include\ffi.h(444) : error C2059: syntax error : ')'
        include\ffi.h(446) : error C2143: syntax error : missing ')' before '*'
        include\ffi.h(446) : error C2143: syntax error : missing '{' before '*'
        include\ffi.h(447) : error C2059: syntax error : 'type'
        ../include\ffi_common.h(81) : error C2143: syntax error : missing ')' before '*'
        ../include\ffi_common.h(81) : error C2143: syntax error : missing '{' before '*'
        ../include\ffi_common.h(81) : error C2059: syntax error : ')'
        ../include\ffi_common.h(82) : error C2143: syntax error : missing ')' before '*'
        ../include\ffi_common.h(82) : error C2143: syntax error : missing '{' before '*'
        ../include\ffi_common.h(83) : error C2059: syntax error : 'type'
        ../include\ffi_common.h(83) : error C2059: syntax error : ')'
        ../include\ffi_common.h(88) : error C2016: C requires that a struct or union has at least one member
        ../include\ffi_common.h(88) : error C2061: syntax error : identifier 'ffi_cif'
        ../include\ffi_common.h(91) : error C2059: syntax error : '}'
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\stdlib.h(235) : error C2081: 'uintptr_t' : name in formal parameter list illegal
        ../src/prep_cif.c(107) : error C2143: syntax error : missing ')' before '*'
        ../src/prep_cif.c(107) : error C2143: syntax error : missing '{' before '*'
        ../src/prep_cif.c(107) : error C2146: syntax error : missing ';' before identifier 'abi'
        ../src/prep_cif.c(108) : error C2059: syntax error : 'type'
        ../src/prep_cif.c(111) : error C2059: syntax error : ')'
        ../src/prep_cif.c(226) : error C2143: syntax error : missing ')' before '*'
        ../src/prep_cif.c(226) : error C2143: syntax error : missing '{' before '*'
        ../src/prep_cif.c(226) : error C2146: syntax error : missing ';' before identifier 'abi'
        ../src/prep_cif.c(226) : error C2059: syntax error : 'type'
        ../src/prep_cif.c(227) : error C2059: syntax error : ')'
        ../src/prep_cif.c(232) : error C2143: syntax error : missing ')' before '*'
        ../src/prep_cif.c(232) : error C2143: syntax error : missing '{' before '*'
        ../src/prep_cif.c(233) : error C2146: syntax error : missing ';' before identifier 'abi'
        ../src/prep_cif.c(234) : error C2059: syntax error : 'type'
        ../src/prep_cif.c(237) : error C2059: syntax error : ')'
        libtool: compile: mv -f "prep_cif.obj" "src/.libs/prep_cif.obj"
        mv: cannot stat 'prep_cif.obj': No such file or directory
        Makefile:1362: ошибка выполнения рецепта для цели <src/prep_cif.lo>
        make[2]: *** [src/prep_cif.lo] Ошибка 1
        make[2]: выход из каталога </cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64>
        Makefile:1596: ошибка выполнения рецепта для цели <all-recursive>
        make[1]: *** [all-recursive] Ошибка 1
        make[1]: выход из каталога </cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64>
        Makefile:730: ошибка выполнения рецепта для цели <all>
        make: *** [all] Ошибка 2
        -----------------------------------------------------------------------------
        what to do - replace symlink by real file.

    4) if you forgot to comment FFI_TARGET_HAS_COMPLEX_TYPE
        -----------------------------------------------------------------------------
        ../src/types.c(101) : error C2061: syntax error : identifier '_Complex'
        ../src/types.c(101) : error C2059: syntax error : '}'
        ../src/types.c(101) : error C2065: '_Complex' : undeclared identifier
        ../src/types.c(101) : error C2143: syntax error : missing ')' before 'type'
        ../src/types.c(101) : error C2059: syntax error : ')'
        ../src/types.c(102) : fatal error C1903: unable to recover from previous error(s); stopping compilation
        libtool: compile: mv -f "types.obj" "src/.libs/types.obj"
        mv: cannot stat 'types.obj': No such file or directory
        Makefile:1362: ошибка выполнения рецепта для цели <src/types.lo>
        make[2]: *** [src/types.lo] Ошибка 1
        make[2]: выход из каталога </cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64>
        Makefile:1596: ошибка выполнения рецепта для цели <all-recursive>
        make[1]: *** [all-recursive] Ошибка 1
        make[1]: выход из каталога </cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64>
        Makefile:730: ошибка выполнения рецепта для цели <all>
        make: *** [all] Ошибка 2
        -----------------------------------------------------------------------------




        what to do - comment FFI_TARGET_HAS_COMPLEX_TYPE

    5) if you forgot to replace replace two 'jmp short' to 'jmp'
        -----------------------------------------------------------------------------
        ml64 -nologo  -c  ./win64.asm
         Assembling: ./win64.asm
        ./win64.asm(1029) : error A2075:jump destination too far : by 20 byte(s)
        ./win64.asm(1038) : error A2075:jump destination too far : by 1 byte(s)
        Makefile:1338: ошибка выполнения рецепта для цели <src/x86/win64.lo>
        make[2]: *** [src/x86/win64.lo] Ошибка 1
        make[2]: выход из каталога </cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64>
        Makefile:1596: ошибка выполнения рецепта для цели <all-recursive>
        make[1]: *** [all-recursive] Ошибка 1
        make[1]: выход из каталога </cygdrive/d/tmp/libraries/libffi-3.2.1/build-x64>
        Makefile:730: ошибка выполнения рецепта для цели <all>
        make: *** [all] Ошибка 2
        -----------------------------------------------------------------------------
        what to do - replace two 'jmp short' to 'jmp'
    .

    tinyxpath building note

    Go to link, download & unpack sources.
    In tinyxml.h before '#ifdef TIXML_USE_STL' insert '#define TIXML_USE_STL'.
    Headers can be copied to ./include directory
    Open ./tinyxpath_lib/tinyxpath_lib.vcproj
    Choose mode & settings and build.

    note of /MT x64 static zlib compiling

    Go to http://www.zlib.net/
    Download & unpack the latest stable release - it's near phrase "The current release is publicly available here"
    Open in text editor 'win32\Makefile.msc', replace -MD to -MT
    Open "VS2013 x64 Native Tools Command Prompt", set current directory to unpacked zlib dir.
    Exec 'nmake -f win32/Makefile.msc'
    After that you will see new files with extentions:
    • obj
    • pdb
    • exe
    • exp
    • lib
    • dll
    • res
    which you can move somewhere.

    Friday, June 12, 2015

    building libxml2 in visual studio 2013

    How to build release & debug x64 static libraries with /MT or /MTd runtime consequently.
    Build without dependencies (as I understand here can be somehow optional included icu & zlib libraries).


    1) download sources
    git clone git://git.gnome.org/libxml2

    2) configure and make.
    Open visual studio console (if you open x32 console - it builds x32 library, if x64 - it builds x64 library). Go to libxml2/win32 and enter:
    cscript.exe configure.js iconv=no compiler=msvc cruntime=/MT  debug=no  prefix="..\_build_x64_static_release_mt" static=yes
    nmake Makefile.msvc libxml install
    nmake clean
    cscript.exe configure.js iconv=no compiler=msvc cruntime=/MTd debug=yes prefix="..\_build_x64_static_debug_mtd"  static=yes
    nmake Makefile.msvc libxml install


    'debug=yes' means generate unoptimized code and generate debug symbols.
    'debug=no' means generate optimized code and not to generate debug symbols.
    such 'prefix' values put include/library/binary files into the directory in the root of your libxml2 with good name.

    3) If you want to use libxml only as static library - you can define LIBXML_STATIC in it's headers. You need to do it with headers:
    • threads.h
    • xmlexports.h
    • xmlwin32version.h
     In these files you need before first occurrence LIBXML_STATIC insert something like
    #ifndef LIBXML_STATIC
    #define LIBXML_STATIC
    #endif

    iconv on windows

    I've needed to build static x64 library libiconv on windows - found two useful links. Leave it here. On June 2015 this article & project builds last version of iconv library.
    Article with describing of building - link.
    Project for visual studio, made by this article - link. It already has settings for lot of building variants - and static x64 too.

    libiconv is widespreaded unix gnu library for conversion between encodings. iconv - console utility, which uses this library. Mostly I encountered with it in gunwin32 utils - no one util will work without this dll. But also it appears as dependency in some gnu projects - for example, libxml (added: it's appeared that libxml builds successfully without libiconv - don't know why - either icov optional, or iconv embedded into libxml).