Firefox Nightly in Visual Studio

Building Firefox nightly

The Mozilla’s documentation about compiling Firefox is pretty straightforward. On Windows, you basically need just

  1. Build prerequisities which mostly means some Visual Studio edition + MozillaBuild package.
  2. Second step is just to go to extracted MozillaBuild package folder and start apropriate command prompt (bash + some paths).
  3. In this new command window, get sources using hg (Mercurial client, which is part of MozillaBuild package & paths).
  4. Set to some folder where you would like to deploy Firefox sources and start hg. The command is:

    hg clone https://hg.mozilla.org/mozilla-central

  5. start the build in using:
    ./mach build
  6. Start the built Firefox, using
    ./mach run

Using Firefox nightly from Visual Studio

Now you should have Firefox running, built by the Mozilla scripts. There is no way how to build everything in Visual Studio, but you can open the browser in that and debug it. Its limited to just browser itself and some internal libraries are not included, for example NSS (library serving the work with HTTPS). To generate the Visual Studio project you need to return to your MozillaBuild prompt, (you should sill be in your mozilla sources folder) and enter:

./mach build-backend -b VisualStudio

after this command, you will get a .sln file generated in your Firefox sources folder under

.\obj-i686-pc-mingw32\msvc\mozilla.sln

You can open this in Visual Studio (2013 in my case) without a problem.

Enable logging of LOG messages

When you will be looking at code you will find, that there is a pretty amount of log messages being logged using LOG or LOG3 macros. These are actually logging if you enable logging for your module. If you want to log everything, just set these Windows variables before starting new firefox.exe:
set NSPR_LOG_FILE=%TEMP%\fflog.txt
set NSPR_LOG_MODULES=all:5

Then the log file is generated under %TEMP%\fflog.txt. To open just use

notepad.exe %TEMP%\fflog.txt

Debugging Firefox in Visual Studio

Its actually not a big deal, just attach your Visual Studio to running firefox.exe and set a breakpoint and you are good to go.

Testing HTTP 2.0 in a browser

You most probably already know how the good old buddy HTTP works. Its very simple, very straightforward and also very old. After some evolution, started by Google with SPDY, we currently have draft of a IETF standard for v 2.0 of this protocol, called also HTTP/2. All this evolution was driven by the desire to make web page loading faster and eventually to reduce the data amounts downloaded on our phones.

The best way is to try. The http2 Implementations tracking page shows that there is a Microsoft implementation, revealing a HTTP/2 supporting server url at:

https://h2duo.cloudapp.net/

Also, the current Firefox Nightly can be enabled to support this version. The steps to enable Http/2 in it are to open about:config and switch these two to true:

  • network.http.spdy.enabled.http2draft
  • security.ssl.enable_alpn

When enabled in FF Nightly, you can navigate to

https://h2duo.cloudapp.net/Mux

Which is a page showing one of HTTP/2 advantages called Multiplexing, which is ability to download large amount of resources simultaneously. The testing page should load he left image much faster. Also when you look at the request, you will see HTTP 2.0, like on following screen.

http2Server

ManualResetEvent vs AutoResetEvent

I want to signal all of my threads waiting for WaitHandle and move them from the Wait Queue to Ready Queue.

There is a small, but significant difference between these two. The main difference comes from the names, when in AutoResetEvent signales (releases) one thread, waiting in the Wait queue and then automatically returns to non-signaled state. Strictly said:
AutoResetEvent will pick and signal just for one thread of more waiting threads.

In the other hand, using ManualResetEvent, you have much more control over the situation. When some thread (producer) will signal (Set), all waiting threads are signaled (released) and enqued to the Ready Queue. Which means they continue from their Wait command.
In this situation you are getting more control in your hands to pick up, which of the waiting threads should take the resource, or process some workitem. The rest of threads can be put in consequent waiting if needed.

Example:

I have a bunch of threads, which are waiting for signal.

First lets try what happens with AutoResetEvent:

image
Clearly shows how just first thread is signalled

ManualResetEvent example

image
This looks much better, all the waiting threads received the signal

And finally, the code which produced this:

class Program
    {
        static ManualResetEvent mre;
        static void Main(string[] args)
        {
            mre = new ManualResetEvent(false);
            var maxT = 3;
            var threads = new List();
            for (int i = 0; i < maxT; i++)
			{
                var t1 = new Thread(Program.T1Proc);
                t1.Start(i);
                threads.Add(t1);
			}
            Thread.Sleep(1000);
            Console.WriteLine("Sleeping for 1 sec");
            Thread.Sleep(1000);
            Console.WriteLine("Setting..");
            mre.Set();
            Console.ReadLine();
        }
        static void T1Proc(object state)
        {
            Console.WriteLine(" thread " + state + " waiting");
            bool received = mre.WaitOne(5000);
            if (received)
                Console.WriteLine(" thread " + state + " received signal");
            else
                Console.WriteLine(" thread " + state + " not received signal");
        }
    }

How to reset OpenWrt root password

It turned out that after few months of using my OpenWrt properly, I have completelly lost my root password and couldn’t connect to my router’s OpenWrt LuCi.

Fortuantelly, OpenWrt has a failsafe mode, where you can set things back up.

How to get to OpenWrt Failsafe mode:

  1. Reset the router
  2. Wait for the DMZ light (Second left light started blinking)
  3. Hold Router reset button for 2 seconds
  4. Connect your’r PC‘s Ethernet Cable to Router’s WAN port (You cannot access Failsafe when connected to any of LAN ports
  5. Set your PC IP Address to 192.168.1.2, NetMask to 255.255.255.0, GW to 192.168.1.1
  6. ipOpen Telnet connection to 192.168.1.1
  7. openwrt_failsafeType mount_root to mount your Router’s FS to Read/Write mode
  8. Type passwd to change root password
  9. openwrt_passwdSwich your LAN Ethernet cable from WAN port on Router back to some LAN one
  10. Restart the router

Deploying Express.js on Cloud9

Express.js (and probably most of other servers on Cloud 9) are being shielded by Cloud9 proxy. You usually cannot access them directly.
Anyway, according the Cloud9’s helping artice Can I use Cloud9 to do X the solution is following:
Start the ExpressJS to listen on Local IP and Local PORT, which are available, to start Express to listen use this:


// Cloud9 specific - needs to use defined port to listen
console.log("Starting to listen. ")

app.listen(process.env.PORT, process.env.IP);

You can then start Express.js normally like:

node myserver.js

I am starting server usually in new terminal window in Cloud9 and use bottom mini-terminal for tests, like:

markcz@demo-project:~/597752 (master) $ wget http://$IP:$PORT/getangularusers
--2013-09-11 07:06:12-- http://127.4.253.1:8080/getangularusers
Connecting to 127.4.253.1:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14 [text/html]
Saving to: “getangularusers.1”

100%[==============>] 14 –.-K/s in 0s

2013-09-11 07:06:12 (1.08 MB/s) – “getangularusers.1” saved [14/14]

Which successfully downloaded the response from private binding fine.

To test public available uri, you can easily open web browser using following format:

http://projectname.username.c9.io

My rest GET api path is /getangularusers and in my case it is publicised as

http://demo-project.markcz.c9.io/getangularusers

You cannot go inside C9 on different port then standard 80. And its being redirected to your local binding.

Please notice, that I am talking about standard HTTP port (80), in preview, you can get direct links to files hosted on Cloud9, but these are NOT your HTML pages hosted on a web server (Express).

 

 

I am going to describe in next article how to conigure static routing in Express to host your HTML files.

Summary:

1. Use Cloud9 predefined IP and PORT to point where Express is going to listen

2. To access from outside of Cloud9, use standard HTTP on 80, and with 3rd domain like hostname
(like http://demo-project.markcz.c9.io/getangularusers)

 

signtool.exe returned error 0x800700C1

To sign our binaries with Authenticode I am using Microsoft’s signtool. Unfortunatelly, it is not really descriptive in some error codes it returns.
In my case, I have been replacing resources in some native binaries, which were already signed. Of course, this will break existing Authenticode signature, but the signature is still there.
Signature is just one of sections in the EXE/DLL file and this section stays there, even if the file signature is invalid.

Signtool unfortunatelly cannot resign an file which is already signed and is always returning same error 0x800700C1.

SignTool Error: SignedCode::Sign returned error: 0x800700C1

This error is in fact ERROR_BAD_EXE_FORMAT.

So, I needed to remove existing signature from an binary file.
One interesting tool called delcert is already writen and works pretty nice to solve this and has source code included:

http://forum.xda-developers.com/showthread.php?p=2508061

After quick look into the C++ source, it is in fact does nothing magic. It is using Win32 API from ImageHlp library (which takes case of loading of binaries).
Interesting functions there are: ImageRemoveCertificate, which needs to be followed by MapAndLoad/UnMapAndLoad pair to clear section from PE headers.

After removing signature, signtool has no complains and signs the file nicely.

One step back to the ERROR_BAD_EXE_FORMAT error code
In your Microsoft SDK Program Files, you will probably have X86 and x64 versions of signtool (one in Program Files (x86), another in Program Files).
So depending on your binary bitness (32bit vx 64bit) you have to call proper signtool, otherwise you will get the original error.

To check the bitness, you can use dumpbin.exe which comes with Visual Studio (VC\bin folder) when you start it with
dumpbin.exe /headers myapp.exe
you should see a line like:
14C machine (x86)
or for 64bit version:
8664 machine (x64)

How to change Windows 8 product key

The way where in Windows 7 you could change your product key is not working anymore.

Instead, you need to use command line to change your product key in Windows 8:

open cmd.exe as Administrator (go to the start metro screen and search for cmd, then right click on cmd and in the bottom select Run as Administrator)

then type following:

slmgr.vbs -ipk PUT-YOUR-KEY-HERE

then, you should have your new key set properly. You can go ahead and try activation then.