Smart Auto Replier reborn

I hate throwing away good things. Lately I was doing backup of my hard drive and I noticed a bunch of code I wrote in 2004 known as Smart Auto Replier plugin for Miranda. To my surprise it was quite big amount of code and it was pity to let it just fade away.

Given the fact that many things have changed in the last 8 years, and the code from 2004 looks just awful for me, I decided to boost it with some interesting idea and base it on top of ugly existing code :). I said to myself, that when doing auto replying, people would most likely need some level of flexibility, so that they will be able to make different conditions based on different input data. The best way to implement this is to implement a programming language inside SAR. However, I have just a 30 minutes of free time per normal day, so re-implementing a wheel is not the best way for me.

This is how I decided to hook-in Lua programming language into SAR. Lua is fast and well-known and can provide a huge level of customization to SAR. User will be able to set different conditions as well as write/read to files, and with time I will develop more functionality regarding conditions part. So, starting from now, SAR will have basically one script function which will get’s executed when you write a message to a client equipped with SAR:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)
    this:SendMessage(hUser, "Here is my autoreply!")
end

As you can see, the function this.SAR accepts a few parameters: this, hUser, szMessage, szUser, szProtocol. These parameters are actually indicating the input to function, so you can set different conditions which will let you to auto reply in a smart way. For example, let’s assume that you want to auto reply only to a user named “Sad”. In this way, your SAR function should look like this:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)    
    if szUser == "Sad"
    then
        this:SendMessage(hUser, "you are user Sad")
    else
        this:SendMessage(hUser, "you are not user Sad you are: ")
        this:SendMessage(hUser, szUser)
    end
end

Now, assume you want to reply only if user is writing you from ICQ protocol. This is easy with Lua: you can combine code as a blocks:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)    
    if szUser == "Sad"
    then
        this:SendMessage(hUser, "you are user Sad")
    else
        this:SendMessage(hUser, "you are not user Sad you are: ")
        this:SendMessage(hUser, szUser)
    end

    index = string.find(szProtocol, "ICQ")
    if index == nil
    then
        this:SendMessage(hUser, "you are not writing from ICQ protocol")
    else
        this:SendMessage(hUser, "you are writing via ICQ protocol")
    end
end

The best way to master SAR is to check the documentation for Lua: http://www.lua.org/docs.html. I agree that it may be not very user friendly to start from reading the docs for Lua, but on the other hand, I am trying to cover basic things which already may work out for newbies and provide them a good start.

Starting from now, SAR will have it’s own official forum where questions should be asked: http://shcherbyna.com/forum/viewforum.php?f=8. Do now hesitate to ask anything, I will try to be responsive. (well, still remember about 30 minutes per day … :))

Despite that, SAR will have it’s own web-page which will list all configuration options and well-known scripts: http://www.shcherbyna.com/?page_id=1747

GPLing oldish code

Back in 2004 I did a small plugin for Miranda IM messenger which was providing auto replying facility. I uploaded it to Miranda database and since that time it had ~ 40 000 of downloads. Some people were inspired with it and based on it some other plugins: Simple Auto Replier

Recently I came across this code and decided to make it GPL and put in Google Code project. Here it is: http://code.google.com/p/smart-auto-replier/

It was fun to look at my own code which is 8 years old.

KMail: “Signing failed: Bad passphrase” message in Debian 6 Squeeze KDE

I was recently trying to setup automatic signing of messages in KMail and I hit a problem : each time I am sending something, I got the message “Signing failed: Bad passphrase” without any opportunity to enter passphrase for my private key. It looks like this:

 

It seems like you have to specify proper path to pinentry-program in your configuration. Do the following:

1. Find out the exact path to pinentry-gtk-2:

$ whereis pinentry-gtk-2 
pinentry-gtk-2: /usr/bin/pinentry-gtk-2 /usr/share/man/man1/pinentry-gtk-2.1.gz

As you can see, in my case the path is /usr/bin/pinentry-gtk-2

2. Edit file ~/.gnupg/gpg.conf by uncommeting # use-agent so it becomes use-agent

3. Create file ~/.gnupg/gpg-agent.conf and put into the path to pinentry-gtk-2. Here is content of my ~/.gnupg/gpg-agent.conf:

$ more ~/.gnupg/gpg-agent.conf
pinentry-program /usr/bin/pinentry-gtk-2

Make sure that you put the proper path (the one from Step 1)

4. Reboot machine and try to send something from KMail. It should work now.

Compiling kext for Intel82566mm under Lion 10.7.2 64-bit

I was recently playing with Intel 82566MM device driver for Mac OS X based on the e1000e open source project and noticed that the driver is really targeted for 10.6 and is unable to compile easily under Lion 10.7.2.

I decided to play a little bit and compile it for Lion 10.7.2 x64 bit. Here it is: modified package which compiles under Lion 10.7.2 x64 with already pre-compiled kext file.

Things mostly changed in Makefile:

1) Added “-arch x86_64 -isysroot ${SYSROOT} -mmacosx-version-min=10.7 -Xlinker -kext”

2) Set proper SDK path and paths for gcc & g++

3) Modified some warnings in Intel82566MM.cpp which end up like errors during build in 10.7.2

Changing background color of iGoogle or Google pages?

I noticed that since the beginning Google is not allowing to change background colour of it’s pages. It is pity, as if you take for example DuckDuckGo you are able to modify the background color easialy: DuckDuckGo Settings page. Moreover, you can easily specify to use always HTTPS, which is not yet the case for Google.

I prefer usually gray colors, as the white color is too bright for my eyes. Background with C4C4C4 seems to be ideal for me, and since I am fun of customization, I guess, I will have to use DuckDuckGo for a while 🙂

Not Idle Task tool for Linux

Since I am using Debian most of my free time, I decided to re-write Not Idle Task tool for Linux. Voilà:

If you have no idea what the “Not Idle Task” tool does, please consult the following page: http://www.shcherbyna.com/?page_id=1382

This version is tested in Debian 6 x86_64 and Fedora 16 x86_64 and is supposed to work in KDE based distributions. I have some ideas about Windows and Mac OS X support, and I guess I will release versions for these operating systems soon.

This software is GPL, you can find the sources here. You can download binary for x64 version of KDE distributions here.

Have fun!

Happy New Year! (2)

New machine, up-to-date, one week old. Was running happily until BSOD occured 🙂

BugCheck E0010002, {fffffa800703a000, c, 205, 94e}

Probably caused by : nusb3xhc.sys ( nusb3xhc+14bbc )

Followup: MachineOwner
---------

0: kd> !analyze -v
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************

Unknown bugcheck code (e0010002)
Unknown bugcheck description
Arguments:
Arg1: fffffa800703a000
Arg2: 000000000000000c
Arg3: 0000000000000205
Arg4: 000000000000094e

Debugging Details:
------------------


CUSTOMER_CRASH_COUNT:  1

DEFAULT_BUCKET_ID:  VISTA_DRIVER_FAULT

BUGCHECK_STR:  0xE0010002

PROCESS_NAME:  System

CURRENT_IRQL:  0

LAST_CONTROL_TRANSFER:  from fffff880064f1bbc to fffff80002c81c40

STACK_TEXT:  
fffff880`035c49f8 fffff880`064f1bbc : 00000000`e0010002 fffffa80`0703a000 00000000`0000000c 00000000`00000205 : nt!KeBugCheckEx
fffff880`035c4a00 00000000`e0010002 : fffffa80`0703a000 00000000`0000000c 00000000`00000205 00000000`0000094e : nusb3xhc+0x14bbc
fffff880`035c4a08 fffffa80`0703a000 : 00000000`0000000c 00000000`00000205 00000000`0000094e 00000000`00000000 : 0xe0010002
fffff880`035c4a10 00000000`0000000c : 00000000`00000205 00000000`0000094e 00000000`00000000 00000000`00000000 : 0xfffffa80`0703a000
fffff880`035c4a18 00000000`00000205 : 00000000`0000094e 00000000`00000000 00000000`00000000 fffff880`064dec19 : 0xc
fffff880`035c4a20 00000000`0000094e : 00000000`00000000 00000000`00000000 fffff880`064dec19 fffffa80`00000205 : 0x205
fffff880`035c4a28 00000000`00000000 : 00000000`00000000 fffff880`064dec19 fffffa80`00000205 fffffa80`0703a000 : 0x94e


STACK_COMMAND:  kb

FOLLOWUP_IP: 
nusb3xhc+14bbc
fffff880`064f1bbc ??              ???

SYMBOL_STACK_INDEX:  1

SYMBOL_NAME:  nusb3xhc+14bbc

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: nusb3xhc

IMAGE_NAME:  nusb3xhc.sys

DEBUG_FLR_IMAGE_TIMESTAMP:  4da56d4d

FAILURE_BUCKET_ID:  X64_0xE0010002_nusb3xhc+14bbc

BUCKET_ID:  X64_0xE0010002_nusb3xhc+14bbc

Followup: MachineOwner
---------
0: kd> lmv m nusb*
start             end                 module name
fffff880`064dd000 fffff880`06515000   nusb3xhc T (no symbols)           
    Loaded symbol image file: nusb3xhc.sys
    Image path: \SystemRoot\system32\drivers\nusb3xhc.sys
    Image name: nusb3xhc.sys
    Timestamp:        Wed Apr 13 11:30:53 2011 (4DA56D4D)
    CheckSum:         000377C3
    ImageSize:        00038000
    Translations:     0000.04b0 0000.04e4 0409.04b0 0409.04e4

I wonder, why do I attract these things? 🙂 I was even trying to keep this machine out of my drivers to make sure my code does not cause problems ))

Configuring Hamachi autostart under Debian 6 x86_64

I guess most of you know what VPN is and how it may be useful for you. Among different VPN solutions, Hamachi seems to be the most popular and easy to use for home users. You can easially install it in Windows or Mac and create/join VPN network just in a few clicks. Under Linux, however, things are going less smoothly.

First, it is not open source 🙁 However, you can download binaries for Linux for free: http://files.hamachi.cc/linux/ (x86 version only). If by some reason you cannot download files from Hamachi ftp, you can try my blog file storage.

So, download the file hamachi-0.9.9.9-20-lnx.tar.gz to your machine and untar it. Read readme file and perform the installation:

(do this as sudo)

$ sudo apt-get install ia32-libs
$ sudo make install
$ sudo tuncfg

(do this as regular user)

$ hamachi-init
$ hamachi start
$ hamachi login

Now you have a choice. You can either use Hamachi via command line (check README file) or you can download a GUI tool which replicates the UI of a Windows version: hamachi-gui. Download file hamachi-gui_0.9.5-0_i386-gutsy.deb or hamachi-gui_0.9.5-0_amd64-gutsy.deb depending on architecture of your distribution and install it using dpkg -i command, i.e.:

$sudo dpkg -i hamachi-gui_0.9.5-0_amd64-gutsy.deb

Now search “Hamachi” in your program list in section “Internet”. You can do most of the things you can do in Windows version: create networks, join networks, modify your computer name, etc.

However, if you reboot your computer, Hamachi would not autostart. You will have to manually start it via “hamachi start” each time which is quite uncomfortable 🙂 You can solve this problem by editing your /etc/rc.local file and starting there “tuncfg” as a root and “hamachi start” as a regular user:

/sbin/tuncfg
/bin/su - USERNAME -c "hamachi start"
exit 0

Store this in your /etc/rc.local and make sure you set USERNAME to a name of your user, and after reboot everything will be autostarted properly.

CdRom is not detected in Debian installer

When playing with different linux distributions I am using unetbootin tool to “flash” linux iso file on a USB flash drive, so I can boot from USB flash drive and avoid burning real CD or DVD disk.

This way it is cheaper & faster. However, recently I noticed that the latest Debian isos (6.0.3) are not working properly with unetbootin: during installation the installer complains that it cannot detect CdRom. And so it fails.

However, there is a workaround. Once installer complains about absence of CdRom, it shows you a screen of options where you can select “Execute shell” option. You can pick-up this options and perform the actual mount in shell window:

 # mount -t vfat /dev/sdb /cdrom

In this particular scenario /dev/sdb is my flash drive which is “flashed” with debian-6.0.3-amd64-CD-1.iso. The device /dev/sdb may be different for you, so pay attention to this.

After you successfully mounted /dev/sdb to /cdrom hit exit and retry again the “Detect CdRom task” in installer. It should work this time. So, do everything as usual – configure disk layout, specify passwords for root and users, etc and let it go.

For me it went well and installed base system, however it failed at “configuration of packages” task. Trying to re-mount disk did not help, so I choose to install GRUB and let the installer finish the job without actually installing the rest packages.

In the end installer asks you to reboot, and when you reboot you see a fancy command line prompt and absolutely no indication of kde or gnome desktop. Well, this is fixable 🙂

At this point, once you have base system, you can just configure apt to point to regional servers and install the require packages from command line. This way it is more fun 🙂

So, the file of interest is /etc/apt/sources.list – it tells apt where to get packages from. Because your installer did not work properly, most likely the sources.list file will just contain a reference to CdRom, which is not what we want.

You can generate a default debian sources.list file for your regional servers using http://debgen.simplylinux.ch/. Follow the form and specify the following details:

1. Select your country (for me it is Ukraine)

2. Select your release (for me it is squeeze stable)

3. Debian Branches (I use only main, i.e., free packages only)

4. Debian Updates (select all items)

Click “Generate list” button and it will generate your list which looks like this for me:

#############################################################
################### OFFICIAL DEBIAN REPOS ###################
#############################################################

###### Debian Main Repos
deb http://ftp.ua.debian.org/debian/ squeeze main 
deb-src http://ftp.ua.debian.org/debian/ squeeze main 

###### Debian Update Repos
deb http://security.debian.org/ squeeze/updates main 
deb http://ftp.ua.debian.org/debian/ squeeze-proposed-updates main 
deb-src http://security.debian.org/ squeeze/updates main 
deb-src http://ftp.ua.debian.org/debian/ squeeze-proposed-updates main

Now, store this data in /etc/apt/sources.list file and perform the apt-get update in shell:

sudo apt-get update

Now you your apt knows where to get packages from and it’s time to install kde desktop:

sudo aptitude install kde-desktop

It will take a while to download packages and install them. After everything is finished, reboot machine and login to your KDE 🙂

Disabling “kexec” kernel reboot in Debian

Have you noticed that by default Debian actually does not reboot machine when you try to reboot? Instead it uses kexec to “restart” the kernel.

This is not very useful sometimes, because in some cases if you have multiple operating system installed, and you need to boot one of these, you’d prefer actual reboot really to happen so you can select target OS from grub menu. In order to make this, you need to uninstall kexec-tools package:

sudo apt-get remove kexec-tools

After uninstallation of kexec-tools your reboots will actually become reboots.

Mac OS X vs Windows kernel development

I always thought that Mac OS is something poorly documented and developing kernel modules under “Mac” will be hard & complex. Until I actually tried it. It turns out, many things under Mac are actually more simple than under Windows.

Just to give you some thoughts:

On Mac OS X:

1. If you are going to write kernel module for Mac you are free to use standrad IDE called xCode to develop & compile code.

On Windows:

1. You have to download DDK or WDK and use command line tools to develop kernel driver. You can trick Visual Studio to use ddkbuild.bat, but this is unsupported way. Good luck making IntelliSense to work. It took Microsoft quite some time to make WDK for Windows 8 to be integrated in Visual Studio.

On Mac OS X:

2. You have nice documentation to start from for newbies, samples and explanations.

On Windows:

2. You have some documentation and samples dir in WDK dir, however, this is rather “see and figure out how it works on your own” approach. It is just different.

On Mac OS X:

3. If you are confused about some piece of functionality, you are free to see how it is implemented in BSD kernel or pick-up any module from http://opensource.apple.com/ and see how it is done.

On Windows:

3. If you have some questions and you cannot find any replies, feel free to take Ida Pro and go start disassembling binaries. Takes more time, and is not a very pleasant process.

Among things which annoy me is, of course, legal restriction not to use Mac OS X in virtual machines (VmWare, VirtualBox), thus making the driver debugging only on physical machine. I used to have dozens of Windows vms with dozens of snapshots ready to be restored and debugged via WinDbg.

In general, from developers point of view, it seems like Apple has invested a lot into usability of documentation, samples and even code writing to make it nice & easy to use. Well done.

Buying Russian watches from www.vostok-inc.com

I have always been dreaming about owning “Vostok” watches when I was a kid. Back in those days, Soviet Union was still alive, and finding Vostok “Komandirskie” or “Amfibiya” was quite hard 🙂 Now, when everyone has swiss or japanease quartz watches, owning a pair of Russian/Soviet made mechanical watches might be not a bad idea.

So, I started to search and I finally came up with the website of a Vostok factory: www.vostok-inc.com situated in Russia. Contacted them via “Contact” page asking if they ship outside Russian, and voila:

Two weeks later I finally got my watches delivered at home. I am very happy with their services as they suggested multiple options to pay for the watches including paying by Visa via 2Checkout.com. They sent the watches and gave me the post tracking number which allowed me to trace the package in Russia untill it reaches Moscow (takes 6 days) and then I used my country post web site to trace it till it came to my doors.

I recommend using www.vostok-inc.com for purchasing watches as you can buy there watches directly from factory, thus it is cheaper and more secure.

P.S. If you wish to see high resolution pictures, feel free to click on this links: image 1, image 2, image 3.

Just another blog … forum

I have noticed that some of my posts have big amount of comments (> 100), and sometimes it is hard to navigate thru them as well as to make a proper notification system when someone posts something, so I’ve decided to create a forum instead: http://www.shcherbyna.com/forum/

I guess it’s pretty raw, and I have not thought well about all possible forums to create, but you can already use it and post your questions there.

Starting from now, all questions will have to be asked in forum rather than in “comments section”. Have fun!

Using USB Hub with Asus RT-N16

I was always wondering if it is possible to use USB Hub (without external power supply) with Asus RT-N16 and the answer is yes:

My RT-N16 has one USB port occupied by printer, and in another port I have USB 2.0 Hub which has currently one port busy: flash drive which hosts partitions used for ipkg. From time to time I attach to hub an external USB drive and this also works well.

100 thousands hits and counting!

According to clustmaps my blog has collected more than 100 000 visitors since July 2008. Can’t say this is fully my reward, as Neil’s Matthews articles on RT-N16 has brought more than 40k hits here. Thank you, Neil!

Anyway, it does not take much time to realize that niche topics are completely non popular, and once you start to write something which is useful for most of the people they find a way to your blog.

Mystery of RuntimeExceptionHelperModules in WerRegisterRuntimeExceptionModule(…) function

I guess this happens to everyone: you need to write a test project to see if some features work and you’re stuck in poor documentation and google has no examples for you …

Recently I was trying to call WerRegisterRuntimeExceptionModule(…) to register my custom exception filtering module and I was stuck in registering module as specified in documentation. Documentation says:

However, it actually leaves more questions such as:

1. What is the preferred key to store the value, HKLM or HKCU?

2. What is exact format of the value, is it [Name of Dll + Path of Dll], or a subkey should be created?

3. If subkey RuntimeExceptionHelperModules should be created, what should be the names of the values? Name of dll? Or full path?

Unfortunately, documentation leaves out these details thus making people to lose their time trying to find out replies to these questions using “try & see” approach. Well, the situation does not look hopeless. In order to find answers to these questions you will need some disassembler, for example, IDA Pro.

If I fire up my file manager (Far) and make a search on all files in System32 folder by searching string “RuntimeExceptionHelperModules” I got the following:

So, I got three binaries from my search. Now you have to analyse all of them to see if they have something useful. I started from WerFault.exe and I guess I have found something interesting:


.text:0102F251 lea eax, [ebp+LibFileName] 
.text:0102F257 push eax 
.text:0102F258 mov ecx, ebx 
.text:0102F25A call ?IsHelperModuleInstalled@CRuntimePlugin@@AAEHPBG@Z ; CRuntimePlugin::IsHelperModuleInstalled(ushort const *) 

As you can see above, the function CRuntimePlugin::IsHelperModuleInstalled checks if module is properly registered. Let’s step in, and see where it looks for it:


.text:0102EC5F loc_102EC5F: ; CODE XREF: CRuntimePlugin::IsHelperModuleInstalled(ushort const *)+Aj 
.text:0102EC5F push eax 
.text:0102EC60 push eax 
.text:0102EC61 push eax 
.text:0102EC62 push 10h 
.text:0102EC64 push [ebp+arg_0] 
.text:0102EC67 push offset aSoftwareMicr_8 ; "Software\\Microsoft\\Windows\\Windows Erro"... 
.text:0102EC6C push 80000002h 
.text:0102EC71 call ds:__imp__RegGetValueW@28 ; RegGetValueW(x,x,x,x,x,x,x) 
.text:0102EC77 neg eax 
.text:0102EC79 sbb eax, eax 
.text:0102EC7B inc eax 

So, it get’s value at subkey “aSoftwareMicr_8”, let’s try to get more data about the subkey:


.text:010064F8 aSoftwareMicr_8:                        ; DATA XREF: CRuntimePlugin::IsHelperModuleInstalled(ushort const *)+3Co
.text:010064F8                 unicode 0, 
.text:010064F8                 unicode 0, ,0
.text:0100659A                 align 4

OK, we can see now that the key is Software\Microsoft\Windows\Windows Error Reporting\RuntimeExceptionHelperModules and 80000002h is HKEY_LOCAL_MACHINE. Now, when situation is more clear, you can try to register your exception module in the following key:

And make sure that WerExceptionModule.dll (this is my custom exception filter dll) is in system folder, so it will be properly found by WerFault.exe. OTOH, you can also specify path to dll instead, i.e.:

You have to keep in mind, however, that if you specify full path in registry, you should also specify it when calling WerRegisterRuntimeExceptionModule(…):


typedef HRESULT (WINAPI *p2WerRegisterRuntimeExceptionModule)(PCWSTR pwszOutOfProcessCallbackDll, PVOID pContext);

// get address of WerRegisterRuntimeExceptionModule in kernel32.dll
p2WerRegisterRuntimeExceptionModule fproc = (p2WerRegisterRuntimeExceptionModule)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "WerRegisterRuntimeExceptionModule");

// register exception filter dll
HRESULT hr = fproc(TEXT("C:\\MyFolder\\WerExceptionModule.dll"), NULL);

// simulate crash:
char *sz = NULL;
*sz = 4;

How to enable autologin in Debian 6 Squeeze KDE

I guess you have noticed that in Debian 6 KDE the check “Enable Auto-Login” is disabled:

However you can re-run systemsettings as root and set this check on. First, make sure that you grant everyone to access X server:

volodymyr@sv1:~$ xhost +
access control disabled, clients can connect from any host

And now you can run systemsettings as root:

volodymyr@sv1:~$ sudo systemsettings

It will look now like this:

Click Apply, reboot machine and see if it works.

How to install packages from sid in Debian 6 Squeeze

Sometimes you need to install specific package from sid in Debian. There might be different reasons for this, for example, you need to install gcc-4.5 and g++-4.5 because you need to compile special software and it requires some extra gcc features.

At the current moment, gcc-4.5 is not included in stable release of Debian 6, so I guess it might be a good example to start from. First, you need to locate sid repository for the package and for that you can use Debian package search: debian qa page

Now, by entering there gcc-4.5 and pressing “Go” button you will find out page for unstable repository: http://packages.debian.org/source/unstable/gcc-4.5. Click on any of subitems of package and pickup it’s architecture, for example, amd64. Here is the page we got: http://packages.debian.org/sid/amd64/g++-4.5/download

As you can see on the last page, it says that you can use the following mirror to get this package from sid:

deb http://ftp.de.debian.org/debian sid main

Edit your file /etc/apt/sources.list and add the mirror above. Close editor and save changes and update your apt database:

sudo apt-get update

Now you can install gcc-4.5 and g++-4.5 using the following command:

sudo apt-get install gcc-4.5 g++-4.5

After everything is installed, edit again your /etc/apt/sources.list and comment-out or remove “deb http://ftp.de.debian.org/debian sid main” and update your apt:

sudo apt-get update

You’re done.