KANAL Mod


Author: David Zimmer
Date: 09.04.16 - 4:27am



I use the krypto analyzer plugin KANAL by Snaker allot. Its a small dll plugin that was designed to work with the PeID packer identifier. It is so handy that I actually use it in MAP and have an option to launch it on the file hash form.

One feature that I always wished it had, was the ability to copy all of the results to the clipboard. I poked around inside v2.7 a little bit, and it turns out if you right click on and entry it will copy the offset. Thats cool, but I want the whole thing text and all

I was not able to find the source to it, but with a couple small tweaks I was able to get what I wanted. Here's how.

First its upx compressed, so unpack it. Then open it up in reshacker and check out the dialog resource. Here I edited the script to include a new line
CONTROL "C&opy", 1022, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
 83, 112, 45, 13 , 0x00020000
This adds a copy button to the center of the form. Perfect. click the compile resource button and then save. The form now has a new button on it.

Now we need to handle the button events since KANAL knows nothing about it. We can do this through subclassing. Since the plugin is an in process dll we do not have to do anything funny, just subclass the form and watch for WM_COMMAND messages.

Before we get to the next step, we need to back track a second. PeID uses a cdecl api for its plugins. VB6 only has native support for stdcall. The first trick is actually just to launch the plugin. We have to build a small asm thunk in a RWE memory allocation and then call it using CallWindowProc

push asm(), "B8 " & lng2Hex(lpfn)    'B8 90807000    MOV EAX,708090
push asm(), "FF D0"                  'FFD0           CALL EAX
push asm(), "83 C4 " & Hex(argSize)  '83 C4 XX       add esp, XX     'cleanup args
push asm(), "C2 10 00"               'C2 10 00       retn 10h        'cleanup our callwindowproc args
Now KANAL uses a modal dialog and VB6 is single threaded. So once we launch it execution does not return back to our VB6 code until the dialog closes. In order to get around this, just before we launch the plugin we start up a timer.

Below is the timer proc which scans for the KANAL window and subclasses it. Below that you can also see how we handle the subclass message. When we receive the BN_CLICKED and our button ID in wParam, then we find the treeview child window on the form, and extract the treeview contents using the winapi.

Dim kanal As CWindow

Private Sub Timer2_Timer()
        
    Dim c As Collection
    Dim w As Cwindow
    
    'Debug.Print "Timer2"
    
    If Timer2.Tag = 3 Then
        Timer2.enabled = False
        Exit Sub
    End If
    
    Timer2.Tag = Timer2.Tag + 1 '3 attempts...
    
    Set c = ChildWindows()
    For Each w In c
        If VBA.Left(w.Caption, 5) = "KANAL" Then
            'Debug.Print Now & " - found kanal window attaching to " & w.hwnd & " (" & Hex(w.hwnd) & " )"
            Set kanal = w
            subclass.AttachMessage w.hwnd, WM_COMMAND
            'Debug.Print "Disabling timer now..."
            Timer2.enabled = False
            Exit Sub
        End If
    Next
    
End Sub

Private Sub subclass_MessageReceived(hwnd As Long, wMsg As Long, wParam As Long, lParam As Long, ...
        
        Dim c2 As Collection, wTv As Cwindow, tmp As String
        
        'we hooked WM_COMMAND for the kanal window
        'we are looking for BN_Clicked in the hiword of wParam and our button id (1022) in the low word
        'since bn_clicked = 0 we are going to take a shortcut and just look for 1022 in wparam
        
        'Debug.Print Now & " - received WM_COMMAND message for hwnd " & hwnd & " wParam = " & wParam
        
        If wParam = 1022 Then 'our new copy button
            If kanal Is Nothing Then Exit Sub
            If kanal.isValid Then
                Set wTv = kanal.FindChild("SysTreeView32")
                If wTv.isValid Then
                     Set c2 = wTv.CopyRemoteTreeView()
                     tmp = ColToStr(c2)
                     Clipboard.Clear
                     Clipboard.SetText tmp
                     'kanal.CloseWindow
                     MsgBox "Saved " & Len(tmp) & " bytes!", vbInformation
                End If
            End If
        End If

End Sub


while the code looks pretty concise and compact, there is actually allot going on behind the scenes in all of the library functions. Its all open source though so feel free to wade through it.

Turns out it was wasnt to bad to add this wish list feature even without the source code to the plugin. Software re-engineering is fun ;)






Comments: (1)

On 09.13.16 - 12:22pm Dave wrote:
doh! it turns out my version of Kanal is old and he has added an export button now!. To make it even worse, I looked in VT and v2.9 was first seen in 2007! Holy crap how time flies.

I might switch to using v2.9 in MAP, but I will probably leave this post up since its a fun technique. If the code is taken out of MAP, you can still find it in commit ee0189

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 91 + 27 = ? followed by the letter: M 



About Me
More Blogs
Main Site
Posts: (All)
2023 ( 4 )
2022 ( 5 )
2021 ( 2 )
2020 ( 5 )
2019 ( 6 )
2017 ( 5 )
2016 (4)
     KANAL Mod
     Decoders again
     CDO.Message Breakpoints
     SysAnalyzer Updates
2015 (5)
     SysAnalyzer and Site Updates
     crazy decoder
     ida js w/dbg
     flash patching #2
     JS Graphing
2014 (5)
     Delphi IDA Plugin
     scdbg IDA integration
     API Hash Database
     Winmerge plugin
     IDACompare Updates
2013 ( 9 )
2012 ( 13 )
2011 ( 19 )
2010 ( 11 )
2009 ( 1 )