Dec 18 2011

Compiling LyX on Mac

When you learn mathematics at the university, and you are a bit of computer’s freak, you will probably want to take lecture notes on the computer.

You are all probably familiar with $latex \LaTeX$ (if not, well… It’s the standard way to write type equations). The best editor for LaTeX is LyX (Well, maybe best is a strong word, The less of all evil is much better).

Recently I’ve bought a new MacBook Air (Mac OS X Lion version 10.7.2. i7 processor), And I’m using it in the university to take some lecture notes. Unfortunately, the LyX release version for mac is a little bit buggy… (for example, when you try to open a file when another file is open it fails most of the time, and if you insist LyX will probably crash. Some characters, such as $latex \Omega$, are not being displayed on editor mode). So I’ve decided to download the source code from their SVN and compile the latest development version.

To make a long story short, I’ve encountered a lot of errors, And I’ve decided to list them here so if you will get them you will be able to solve them much quicker than me.

First error – ICONV_CONST not defined

The first error I’ve encountered was the following:

docstream.cpp: In member function ‘std::codecvt_base::result<unnamed>::iconv_codecvt_facet::do_iconv(void*, const char**, size_t*, char**, size_t*) const’:
docstream.cpp:264: error: expected `>' before ‘ICONV_CONST’
docstream.cpp:264: error: expected `(' before ‘ICONV_CONST’
docstream.cpp:264: error: ‘ICONV_CONST’ was not declared in this scope
docstream.cpp:264: error: expected primary-expression before ‘>’ token

Here the solution is simple. The problem is that the configure doesn’t config the ICONV_CONST properly. The solution to edit the config.h file located in the lyx-devel directory, and add the following line:

#define ICONV_CONST

And now it will work wonderfully.

Second error – Undefined symbols for arh

The second error was much more annoying, and I’ve even destroyed my Mac by mistake while trying to solve it (Had to reinstall it). The solution is a bit more difficult, but no worries.

The error I got, was the following linking error:

Undefined symbols for architecture x86_64:
  "_libiconv_open", referenced from:
      lyx::IconvProcessor::init()     in liblyxsupport.a(unicode.o)
      (anonymous namespace)::iconv_codecvt_facet::iconv_codecvt_facet(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode, unsigned long)in liblyxsupport.a(docstream.o)
  "_libiconv", referenced from:
      lyx::IconvProcessor::convert(char const*, unsigned long, char*, unsigned long)in liblyxsupport.a(unicode.o)
      (anonymous namespace)::iconv_codecvt_facet::do_out(__mbstate_t&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&) constin liblyxsupport.a(docstream.o)
      (anonymous namespace)::iconv_codecvt_facet::do_in(__mbstate_t&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&) constin liblyxsupport.a(docstream.o)
  "_libiconv_close", referenced from:
      lyx::IconvProcessor::convert(char const*, unsigned long, char*, unsigned long)in liblyxsupport.a(unicode.o)
      lyx::IconvProcessor::Impl::~Impl()in liblyxsupport.a(unicode.o)
      (anonymous namespace)::iconv_codecvt_facet::~iconv_codecvt_facet()in liblyxsupport.a(docstream.o)
      (anonymous namespace)::iconv_codecvt_facet::~iconv_codecvt_facet()in liblyxsupport.a(docstream.o)
ld: symbol(s) not found for architecture x86_64

There seems to be a problem with the built-in libiconv library that comes with the OS. The solution was to get the latest source code from GNU, and installing it.

The way to install it is as follows:

Download the archive file, open a terminal in the folder with the archive and type the following commands:

tar -xzvf libiconv-1.14.tar.gz
cd libiconv-1.14

./configure '--prefix=/usr/local' 'CC=gcc -arch i386 -arch x86_64' 'CXX=g++ -arch i386 -arch x86_64' 'CPP=gcc -E' 'CXXCPP=g++ -E'

make
sudo make install

Note: It is very important NOT to install the lib to “/usr/lib“. but to “/usr/local/lib” (That’s they way I’ve messed up my all OS, and it wouldn’t boot afterwards).

After installing the libiconv, you will need to configure and install LyX  using the following commands (assuming you are in the lyx-devel directory):

LDFLAGS="-L/usr/local/lib" ./configure --with-version-suffix=-2.0 --with-libiconv-prefix=/usr/local --with-x=no --disable-stdlib-debug

make
make install

Note: You will probably encounter again the first error I had, because running the configure recreate the config.h file. Just reedit the config.h file as mentioned in the last section.

And that’s it!

It seems like in the current development version the opening bug is fixed, but the missing symbols are still missing. Hopefully it will be fixed soon (I’m looking into it).


Dec 2 2011

Cracking “Rav-Kav” (Part I)

Yesterday at the university, I’ve got my brand new “Rav-Kav” (רב-קו) card. I was really happy when I discovered that mine was one of those “smart card with the golden chip on it”. Because I’ve got a software on my computer at home, that uses smart-card as a dongle, therefore, I’ve got a smart-card reader back at home.

Rav-Kav card

My first task, was to find out how to communicate with the smart-card. A quick google search and I’ve found the wonderful python module pyscard which allows me to send and receive APDU commands to/from the smart card. My second task was to read a bit about smart cards, and the commands they use. Again, google came up handy, and I’ve found the following site which describing more-or-less every command and response you are likely to get from the little shiny card.

The first thing you need to understand, A smart-card is not a flash drive! A smart-card is a microprocessor, It has it’s own operating system, and it communicates with the device using it (my computer for example) using the T=0 protocol. Meaning: You can’t read and write whatever you want into it.

For those of you who reads this article only to get “free rides”: No, I don’t believe I’ll be able to add “free rides” to my “Rav-Kav” card, because those things are usually very protected (and even if I could, it will be illegal to use it and sharing the information), but it’s quite interesting to check what kind of information is stored in this little piece.

When I plugged the card and connected to it, the ATR was: “3B 6F 00 00 80 5A 0A 07 06 20 04 2C 02 63 EE FF 82 90 00”. But I’m not sure if that means anything….

The first thing I tried was to map all the command classes available for this card.
I’ve scanned the classes simply by trying a random command in all the possible classes (256 possibilities), and ignored all the classes that returned “0x6e – Class not supported“. I’ve found out that the only available classes are 0x80, 0x94. And that all the interesting commands shown on chapter 6 can be found on the 0x94 class.

The next thing I did was to “brute force” the file-system under the master-file using the SELECT command. And I got the following list:

0x0002
0x0003
0x2000
0x2001
0x2004
0x2010
0x2020
0x202a
0x202b
0x202c
0x202d
0x2030
0x2040
0x2050
0x2069
0x206a
0x20f0
0x2100
0x2101
0x2104
0x2110
0x2120
0x2140
0x2150
0x2169
0x21f0
0x2f10
0x3f04
0xfeff

I’m not sure yet which one of those is an EF (normal file) and which one if a DF (a directory). But I’ll find those out next time. Stay tuned.


Nov 11 2011

Happy HDLC Day!

011.11.110

Today is the HDLC day!

For those of you who doesn’t know, the frame delimiter in HDLC is the bit sequence 01111110.

(Thanks to Yoni Ho)