NuLL3rr0r

The blog of Mohammad S. Babaei

Wifi Fix for Asus Google Nexus 7 Cellular, When SIM-Card Is Inserted

As a Nexus 7 tablet user I’ve been struggling with my Nexus 7 WiFi from the moment that I’ve owned it. It was originally released with Android 4.2.0 installed. Nonetheless, Android 4.2.1 and 4.2.2 didn’t get me anywhere with the WiFi issue. In fact, you may have suffered from this issue, and are already familiar with. After inserting a SIM-Card into the device, Android asks to restart the device. However, after rebooting you will notice the WiFi module won’t work. No matter how hard you try it won’t see any WiFi network while keeps saying “WPS failed. Please try again in a few minutes”. Even tried an open unencrypted WiFi without any luck. In fact, the only solution that worked for me was removing the SIM-Card completely and do a factory reset.

Also as you may have noticed, it’s been quiet some time since an issue has been opened on Google Code around this issue on Nexus 4, Nexus 7 and Nexus 10 devices. Unfortunately, it seems that Google doesn’t care about this issue at all, and they closed the issue while ago. Even worse, they won’t allow comments any more (At the time of this writing there are 1223 comments on the issue which shows how serious the situation is).

Anyway, if you’re one of the sufferers from this issue, still there may be some good news for you. It appears that the root of all evil is inserting a non-U.S. SIM-Card on your device. Hopefully, I suddenly came across an Android application called WiFi Fix for Android 4.x by Fardjad Davari, which completely solved the problem for me. It’s been a week since I tried this application and found no more issue with my WiFi.

In fact, the process is very easy and straightforward to follow. Here is what worked for me on Nexus 7 with latest CyanogenMod 10.1 nightly builds (It may work on Nexus 4 or Nexus 10, too):

Getting Real IP Addresses Using Nginx and CloudFlare

OK, I suppose you know what CloudFlare is, and are familiar with Nginx configuration process, before we proceed any further. Just in case you don’t know, CloudFlare offers free and commercial, cloud-based services to help secure and accelerate websites. The thing is, I’m really satisfied with the services they offer except a repellent issue about logging the real IP address of your website’s visitors. Since CloudFlare acts as a reverse proxy, all connections come from CloudFlare’s IP addresses, not the real visitors anymore. Anyway, using Nginx there’s a simple workaround for this issue, which I’ll describe in the rest of this post.

Colors Talk: A Colorful Terminal / Console

If you’ve ever used a GNU Gentoo or Funtoo Linux variant, or a live version of any of them, you may have noticed their eye-catching colorful terminal or console. Whether you’re on a virtual console or one of KDE, GNOME, XFCE, LXDE terminal apps.

A Colorful Xfce4 Terminal on FreeBSD (Bash)

A Colorful Xfce4 Terminal on FreeBSD (Bash)

The default Xfce4 Terminal on FreeBSD (sh/csh)

The default Xfce4 Terminal on FreeBSD (sh csh)

When I’ve migrated from Funtoo to FreeBSD, the one thing that I’ve missed so badly was its colorful terminal. The nice thing about these colors is taht they always give you some valuable hints, e.g., currently you’re root user or a regular user, the file is a symlink (Symbolic link), executable or just a regular file.

Well, it’s pretty easy to have your own colorful terminal or console, once you’ve found out how Gentoo and Funtoo did that. Fortunately, it works on *BSD and all other Linux distros as well. So, stay with me and I’ll describe the process in the following.

Nano, Syntax Highlighting

GNU nano is my favorite text editor while I’m on console. Although, it doesn’t offer syntax highlighting by default, it comes with a decent set of syntax highlighting files. Usually, these files are exist in /usr/local/share/nano or /usr/share/nano, depending on your distro’s preference. You can enable syntax highlighting for your prefered language(s) by including related file(s) with .nanorc extension in your ~/.nanorc file.

~/.nanorc - FreeBSD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
include "/usr/local/share/nano/asm.nanorc"
include "/usr/local/share/nano/awk.nanorc"
include "/usr/local/share/nano/c.nanorc"
include "/usr/local/share/nano/cmake.nanorc"
include "/usr/local/share/nano/css.nanorc"
include "/usr/local/share/nano/debian.nanorc"
include "/usr/local/share/nano/fortran.nanorc"
include "/usr/local/share/nano/gentoo.nanorc"
include "/usr/local/share/nano/groff.nanorc"
include "/usr/local/share/nano/html.nanorc"
include "/usr/local/share/nano/java.nanorc"
include "/usr/local/share/nano/makefile.nanorc"
include "/usr/local/share/nano/man.nanorc"
include "/usr/local/share/nano/mgp.nanorc"
include "/usr/local/share/nano/mutt.nanorc"
include "/usr/local/share/nano/nanorc.nanorc"
include "/usr/local/share/nano/objc.nanorc"
include "/usr/local/share/nano/ocaml.nanorc"
include "/usr/local/share/nano/patch.nanorc"
include "/usr/local/share/nano/perl.nanorc"
include "/usr/local/share/nano/php.nanorc"
include "/usr/local/share/nano/pov.nanorc"
include "/usr/local/share/nano/python.nanorc"
include "/usr/local/share/nano/ruby.nanorc"
include "/usr/local/share/nano/sh.nanorc"
include "/usr/local/share/nano/tcl.nanorc"
include "/usr/local/share/nano/tex.nanorc"
include "/usr/local/share/nano/xml.nanorc"
~/.nanorc - Funtoo or Gentoo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
include "/usr/share/nano/asm.nanorc"
include "/usr/share/nano/awk.nanorc"
include "/usr/share/nano/c.nanorc"
include "/usr/share/nano/cmake.nanorc"
include "/usr/share/nano/css.nanorc"
include "/usr/share/nano/debian.nanorc"
include "/usr/share/nano/fortran.nanorc"
include "/usr/share/nano/gentoo.nanorc"
include "/usr/share/nano/groff.nanorc"
include "/usr/share/nano/html.nanorc"
include "/usr/share/nano/java.nanorc"
include "/usr/share/nano/makefile.nanorc"
include "/usr/share/nano/man.nanorc"
include "/usr/share/nano/mgp.nanorc"
include "/usr/share/nano/mutt.nanorc"
include "/usr/share/nano/nanorc.nanorc"
include "/usr/share/nano/objc.nanorc"
include "/usr/share/nano/ocaml.nanorc"
include "/usr/share/nano/patch.nanorc"
include "/usr/share/nano/perl.nanorc"
include "/usr/share/nano/php.nanorc"
include "/usr/share/nano/pov.nanorc"
include "/usr/share/nano/python.nanorc"
include "/usr/share/nano/ruby.nanorc"
include "/usr/share/nano/sh.nanorc"
include "/usr/share/nano/tcl.nanorc"
include "/usr/share/nano/tex.nanorc"
include "/usr/share/nano/xml.nanorc"

Note: If the file doesn’t exist, you should create it first:

1
$ touch ~/.nanorc

Nano, Do Not Wrap Text

GNU nano is my favorite text editor while I’m on console. However, there’s one thing about nano which annoys me: automatic text wrapping!

Hopefully, there are two simple ways to overcome this. By using either -w command-line argument, or set nowrap configuration command within the file ~/.nanorc.

1. The temporary solution by using -w command-line argument, which should be used each time you run nano:

1
$ nano -w /path/to/file

2. The permanent solution by setting off automatic text wrapping using the configuration command set nowrap, in the ~/.nanorc file:

~/.nanorc
1
set nowrap

Note: If the file doesn’t exist, you should create it first:

1
$ touch ~/.nanorc

Write Your Own Cross-platform Cryptographic Library

Previously I’ve described the process of building Crypto++ on both FreeBSD and Windows using the GCC, MinGW and VC++ compilers.

Now, we want to develop our own cross-platform cryptographic wrapper library around Crypto++. I’ve already uploaded the full source code to GitHub. You can find the link to the code on github at the end of this article.

Before you proceed, you have to build the Crypto++ library as I mentioned earlier here.

How to Build C++ Cryptographic Library, Crypto++

Crypto++ is an awesome free and open source C++ class library of cryptographic algorithms and schemes which fully supports 32-bit and 64-bit architectures for many major operating systems, including FreeBSD, Linux, Solaris, Windows, Mac OS X and iOS. Currently, Crypto++ officially supports the following compilers:

  • MSVC 6.0 – 2010
  • GCC 3.3 – 4.5
  • C++Builder 2010
  • Intel C++ Compiler 9 – 11.1
  • Sun Studio 12u1, Express 11/08, Express 06/10

The latest version at the time of this writing is 5.6.1.

In spite of the power that Crypto++ offers, building and using it can be a little bit tricky. In the following we will describe the process of building Crypto++ on both FreeBSD and Windows using the GCC, MinGW and VC++ compilers.

Should I Check if a Pointer Is NULL Before Deleting It?

Most of the time I see some C++ programers who check if a pointer is NULL befor deleting it.

1
2
3
4
if (ptr != NULL) {
    delete ptr;
    ptr = NULL;
}

Well, according to C++03 [ISO/IEC IS 14882:2003] §5.3.5/2 which explicitly states:

…if the value of the operand of delete is the null pointer the operation has no effect.

Therefore, deleting a NULL pointer has no effect (if the deallocation function is one supplied in the standard library), so it is not necessary to check for a NULL pointer before calling delete.

1
2
delete ptr;
ptr = NULL;
  • Note: Keep in mind that deleting a void* pointer results in undefined behavior whether it’s NULL or not.