Skip to content

Twitter icon Follow me?

22 Jan CNet gives FreeFixer 5 stars: http://t.co/vyaH6pdF

21 Jan Dreamhost hacked: http://t.co/OpgQQz5N

16 Oct FreeFixer now supports Windows 8: http://t.co/PQLgEB3V

05 Oct Windows 8, VMWare, HAL_INITIALIZATION_FAILED, VirtualBox and broken network bridging. http://t.co/SqHlq45C

02 Oct My code that verifies a file's signature using catalog files and WinVerifyTrust don't work on Windows 8. Investigating...

01 Oct Starting to port FreeFixer to Windows 8.

30 Sep Installing Windows 8 Developer preview.

31 Aug Adolist v0.12 up and running. You can now edit your todos. http://t.co/sb2PhCb

28 Aug Testing the WTL splitter and how to add it to a dialog application.

09 Aug This morning's project. Shows the current week in Swedish :) http://t.co/VZhxQKP

09 Aug FreeFixer v0.59 released. Anyone had a chance to try it? http://t.co/PMFGdtJ

22 Jun Running FreeFixer v0.59 on some real world malware. So far so good.

13 Jun Adding "$err, hr" in Visual Studio's watch window will show the value of GetLastError() and the associated error message.

29 May I've just uploaded a minor update at adolist.com. Anyone had the chance to try it? http://www.adolist.com/

09 May What do you think about my latest project? http://www.adolist.com

13 Mar Draggable button using JQuery. Cannot get it to work.

27 Jan www.qooqlle.com.. Anyone know how this start page gets its way into the machines out there?

07 June 2010

Crash in CDHtmlDialog's OnInitDialog method

Recently I implemented a crash report system for FreeFixer which allows the user to upload the FreeFixer memory dump for analysis. A memory dump is generated if an unhandled exception occur, such as an access violation exception, or if the application triggers an ASSERT. With the help of the memory dump, FreeFixer's executable file, and the symbols, I can see exactly where in the code the problem occur. This have been quite useful to track down some bugs.

Today I downloaded the 10 dumps generated from FreeFixer v0.58 for analysis. There has been approximately 20.000 downloads since the release of FreeFixer v0.58 three weeks ago. There are two bugs that has been around for some time where I've not found any fix.

Five of the dumps highlights a problem that appears during initialization. FreeFixer's user interface is built with a CDHtmlDialog. When the application starts, I call the dialog's DoModal() method, which later on calls my OnInitDialog() method, which immediately calls CDHtmlDialog::OnInitDialog.


BOOL CDHtmlDialog::OnInitDialog()
{
	AfxEnableControlContainer();

	CDialog::OnInitDialog();

	RECT rectClient;
	GetClientRect(&rectClient);

	// if we've been created from the dynamic template
	// set the caption
	if (!m_lpszTemplateName)
		SetWindowText(m_strDlgCaption);

	// check if there is a browser control on the dialog
	// already
	CWnd *pCtrl = GetDlgItem(AFX_IDC_BROWSER);
	LPUNKNOWN lpUnk;
	if (pCtrl)
	{
		lpUnk = pCtrl->GetControlUnknown();
		if (lpUnk && SUCCEEDED(lpUnk->QueryInterface(IID_IWebBrowser2, (void **) &m_pBrowserApp)))
		{
			m_wndBrowser.Attach(pCtrl->m_hWnd);
			m_bAttachedControl = TRUE;
		}
	}
	if (m_pBrowserApp == NULL)
	{
		// create the control window
		m_wndBrowser.CreateControl(CLSID_WebBrowser, NULL,
					WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDC_BROWSER);
		lpUnk = m_wndBrowser.GetControlUnknown();
boom->		if (FAILED(lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp)))
		{
			m_wndBrowser.DestroyWindow();
			DestroyWindow();
			return TRUE;
		}

In the code listed above, m_wndBrowser.GetControlUnknown() returns NULL and is assigned to the lpUnk variable, and later on a call to lpUnk->QueryInterface is done. There we have an access violation exception. Unfortunately I've not been able to figure out why does problem appear, and why it only appears in 1 out of 4000 downloads. Do you know of a solution to this problem? Please let me know.

There are a few suggestions available to fix this problem, such as calling CoInitialize(NULL) or AfxEnableControlContainer() in the application's InitInstance() method. However, none of these fixes has solved the problem:

The 5 remaining dumps is related to FreeFixer's code that extracts icons from executable files which are displayed in the scan result. The code goes something like this:


HMODULE module = LoadLibraryEx(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
if (!module) return;

[..do some work on the module..]

const BOOL result = FreeLibrary(module);
ASSERT(result);

The result from FreeLibrary is passed to the ASSERT macro since I assume it is programming error if FreeLibrary fails when passed a valid HMODULE. However, the assertion is triggered, approximately once every 4000 downloads. Unfortunately I don't have the file name of the module that the code loads which probably would give some hints why the problem occur. Another interesting observation is that all five dumps shows that the machines where running the BitDefender anti-virus. Anyone else noticed this problem?

Permalink | Comments

23 April 2009

Porting Native API calls to Windows 7

I'm currently porting FreeFixer for the Windows 7 platform. Luckily the different flavors of Windows does not differ that much from one release to another, so most of the unit tests worked without any changes to the existing code.

There's one piece of code that needed an update though, and it's the rootkit detection plugin, which in its current state detects hidden processes. This plugin uses the Windows Native API. The Native API is incompletely documented and used internally by the Windows NT operating systems (NT, XP, 2000, Vista, Win7, etc). FreeFixer calls the Native API by putting the system calls index in the eax register, and then using sysenter or int 2Eh depending on the platform. By using this procedure, FreeFixer can bypass some of the rootkit hooking techniques that hide running processes.

There is one problem though, the system call index numbers have changed from release to release, and Windows 7 was not exception, so the code needed an update. The following lists some of the index numbers for the Windows 7 platform:

NtQuerySystemInformation  = 0x106
NtQueryInformationProcess = 0xe4
NtReadVirtualMemory       = 0x105
NtOpenProcess             = 0xbf

Hope this helps if you are porting your Native API calls to Windows 7.

Permalink | Comments

20 February 2009

OpenProcess and Audiodg.exe

I'm currently working on getting my malware removal tool FreeFixer up and running on the Windows Vista platform. FreeFixer woks by scanning the registry and the file system to find unwanted software. It is also enumerating processes, their file names and their modules. This is were I ran into some minor problem. On Windows XP I had previously obtained the SeDebugPrivilege privilege (defined as SE_DEBUG_NAME) and then opened all processes with the OpenProcess system call and passing PROCESS_QUERY_INFORMATION | PROCESS_VM_READ as the requested access. However, on Windows Vista OpenProcess failed on Audiodg.exe, with the ERROR_ACCESS_DENIED error code.

Audiodg.exe - a protected process

Windows Vista introduced a new type of process, the protected process. Protected processes are there to enhance support for digital rights management functionality in Windows Vista. [1]

A typical protected process does not allow injecting a thread into the process, accessing virtual memory of process, debugging the process, duplicate handles of the process, changing the quota or working set of a process.
You cannot open a typical protected process with PROCESS_QUERY_INFORMATION nor PROCESS_VM_READ. Luckily Vista introduced the PROCESS_QUERY_LIMITED_INFORMATION, which is a limited version of the PROCESS_QUERY_INFORMATION access right. This will allow you to open the process with OpenProcess and at least get the full path of the protected process. I think - please correct me if I'm wrong - that it's not possible to enumerate the modules of audiodg.exe from without the help of a kernel-mode component?

Permalink | Comments

How to toggle tab size in Visual Studio using a macro

Here's a code snippet that toggles the C/C++ editor's tab size between 2, 4 and 8:

' Author: Roger Karlsson
' http://rogerkarlsson.com/blogs/programming/toggle-tab-size/
Public Module ToggleTabSize

    ' Toggle the C/C++ editor's tab size between 2, 4 and 8.
    Sub Toggle()
        Dim props As EnvDTE.Properties = DTE.Properties("TextEditor", "C/C++")
        Dim ts As EnvDTE.Property
        Dim ins As EnvDTE.Property

        ts = props.Item("TabSize")
        ins = props.Item("IndentSize")

        If ts.Value = 2 Then
            ts.Value = 4
            ins.Value = 4
        ElseIf ts.Value = 4 Then
            ts.Value = 8
            ins.Value = 8
        Else
            ts.Value = 2
            ins.Value = 2
        End If
    End Sub

End Module

Permalink | Comments