Tuesday, August 25, 2020

Searching a Youtube Video and its linked playlist

 This was an issue till I stumbled across this nice and simple solution from Google.

Assume that you came across this video

https://www.youtube.com/watch?v=OeFhI8wVXjw

and interested to see all other related videos. Related videos are usually linked with a playlist by the content creators. So, how do you find  which playlist this video is linked to?

Simple.

First, the part after "?v=" is the Video ID. We need to use that in our search.

Go to google search bar, and type as below. Explanations later.

 
site:youtube.com inurl:(OeFhI8wVXjw list)
 

This will give you the link to the video. If you check the URLs of the search result, it will show the playlist it is part of. Just open the video, and it will open along with the playlist to the right-side of the webpage.

Wednesday, April 08, 2020

Handling SendMessage from DLLs to WPF C# Application

This is my take on the code flow of handling an WPF C# app which handles messages sent to it from a DLL. I started searching on this due to an personal requirement to send messages from the DLL loaded by the WPF App.

First, let me setup the DLL. SendMessage is a Win32 API, and hence, it needs to be imported like this
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, string wParam, IntPtr lParam);
While there are many ways (better ways too) to get mainWindow handles, I just passed through the first function I use to store them for later use. Here's the full DLL code
    public class mainDLL
    {
        IntPtr hwnd = IntPtr.Zero;

        [DllImport("User32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int wMsg, string wParam, IntPtr lParam);

        public void InitFunction(IntPtr pval)
        {
            hwnd = pval;            
        }

        public void msgthread()
        {
            for (int i = 0; i < 5; i++)
            {
                string sz = "Counter :" + i.ToString();
                Thread.Sleep(1000);
                SendMessage(hwnd, 0x112, sz, IntPtr.Zero);
            }
        }

        public void MsgFunction()
        {
            Thread mythread = new Thread(new ThreadStart(msgthread));
            mythread.Start();
        }
    }
For the calling application, declare the relevant variables.
        // DLL relevant variables
        private Assembly DllAssembly;
        Type mydlltype;
        object InstanceType;

        MethodInfo miInitFn;
        MethodInfo miMsgFn;
The main DLL setting up
    if (File.Exists(@"sendmsgDLL.dll"))
            {
                DllAssembly = Assembly.LoadFrom(@"sendmsgDLL.dll");
                
                mydlltype = DllAssembly.GetType("sendmsgDLL.mainDLL");
                InstanceType = Activator.CreateInstance(mydlltype);
                miInitFn = mydlltype.GetMethod("InitFunction");
                miMsgFn = mydlltype.GetMethod("MsgFunction");


                var myHandle = new WindowInteropHelper(this).EnsureHandle();
                HwndSource source = HwndSource.FromHwnd(myHandle);
                source.AddHook(WndProc);
            }
And the corresponding WndProc method to capture the message sent to the application. Here, we are using the msg value of 0x112. do not values lower than 0x100, as they will be used by the system. The captured message is dumped into a RichTextBox's AppendText
    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {            
            if (msg == 0x112)
            {
                string szt = Marshal.PtrToStringAnsi(wParam);
                rtbMainDisplay.AppendText (szt + "\n");
            }

            return IntPtr.Zero;
        }
And on a button click, launch the DLL functions
   private void bnStartTests_Click(object sender, RoutedEventArgs e)
        {
            // Get the handle of this window

            var newHandle = new WindowInteropHelper(this).Handle;

            miInitFn.Invoke(InstanceType, new object[] { newHandle });
            miMsgFn.Invoke(InstanceType, null);
        }

Thursday, May 22, 2014

Customizing Grub2 with grub-customizer

A re-post (copy-paste actually) of a good post on how to customize grub2 menu. I am re-posting as I have lost many good posts, as the sites I linked to had become defunct, losing out on good content.

The tool in question is called Grub Customizer, created by Daniel Richter. He’s provided a PPA to make installing the tool quick and easy.

Open a terminal window (Ctrl+Alt+T or Applications > Accessories > Terminal) and type in the following commands.


sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer



grub-customizer should show in the Unity search now (in Ubuntu)


or you can open it from command line by typing


gksudo grub-customizer



click on and edit away...!!!

Source: howtogeek

Sunday, May 11, 2014

MAC address spoofing - Linux

It is too easy than I expected. Just download "macchanger" source from gnu's FTP site.

Now.
Step 1: doing a "ifconfig" should give you all the system's interfaces, and their corresponding IP addresses. In my case, I had only one, and it was something like below.

# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:23:3f:15:cc:dc
          inet addr:10.151.50.15  Bcast:10.151.255.255  Mask:255.255.0.0
          inet6 addr: ef80::250:8ecf:6df3:3731/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Memory:ee000000-ee020000

Our focus is on changing the "HWaddr" here.

Note: To me, I had to just unlink the physical cable once to effect the changes, although another time, just disabling the network through software and re-enabling them worked out fine. So, ensure to try both options before posting a  "not working" post.

To generate a random HW address, just type



# macchanger -r eth0
Current MAC:   00:23:3f:15:cc:dc (unknown)
Permanent MAC: 00:23:3f:15:cc:dc (unknown)
New MAC:       53:de:bc:8f:28:dc (unknown)

To update a specific HW address, type


macchanger --mac=23:0d:fc:41:c5:8b eth1

Current MAC:   00:23:3f:15:cc:dc (unknown)
Permanent MAC: 00:23:3f:15:cc:dc (unknown)
Faked MAC:     b2:aa:0e:56:ed:f7 (unknown)

And to reset, type
macchanger -p eth1

Current MAC:   b2:aa:0e:56:ed:f7 (unknown)
Permanent MAC: 00:23:3f:15:cc:dc (unknown)
Faked MAC:     00:23:3f:15:cc:dc (unknown)

My source ref: http://linuxconfig.org/change-mac-address-with-macchanger-linux-command

Monday, October 01, 2012

xmmcc exe keylogger virus cleanup

When I connected a pen drive to my PC, I found that the pendrive's root directory had two files, although I had never copied them 
1. xmmcc.exe 
2. Autorun.inf




I tried deleting them, but as soon as they were deleted, they came back within a second automatically. After some googling, I found that it was a keystroke logger virus.I could not find proper steps in a single place (must be bad googling), so here I am consolidating all steps I followed to clean the virus.

Step 1:
Using Process Explorer, I found that there were two "services.exe" running. One had the company name as "Microsoft Corporation", but the other file did not have any detail displayed under the "Description" column. Also, it had the same icon I saw in the pendrive (of two fingers pressing the keyboard). I first killed the process.


Step 2:
In the following folder, there were 3 files.
C:\Windows

1. xmmcc.exe
2. services.exe (with the same finger icon).
3. hardshad.log

One more verification point for the exe file is that the properties of the EXE file shows the original name as "hardshad.exe".
The file "hardshad.log" contains all the keystroke made by the  user since the time the virus got installed.

I deleted all 3 files.

Step 3:
Opened registry (regedit.exe).
Selected the root node. Then, searched for "xmmcc"..
It showed many entries, most of them pointing to drives allocated to pendrives. I deleted them all, except one. which showed

"explorer.exe xmmcc.exe"

Here, I opened the value entry, and removed only the "xmmc.exe" and left the "explorer.exe" as it is.

After I rebooted the system, the virus was no longer present.

Saturday, March 31, 2012

Disappeared Window decorators

In Ubuntu 10.04 that I have at home, one fine day, the resize options together with the minimize, maximize and close buttons were AWOL; well not exactly awol, i cudnt find them on the windows. The ever faithful Google helped. I just had to type
compiz --replace
and all were reinstated and back in action. It just restarts all windows without any changes to the contents in them.

Monday, December 12, 2011

Microsoft Picture Fax Viewer problem

With picasa and a host of other picture viewing programs, the default image viewer Microsoft's Picture and Fax Viewer kind of went into oblivion for me. One fine day, I wanted to use it for viewing images (out of pure nostalgia) and found out that it was not getting listed at all in my "Open with" menu. I also was not able to find it through any program. After googling, I found out that it is actually a DLL, shimgvw.dll and needs to be launched with rundll32.exe. So, I tried that. I typed

rundll32 shimgvw.dll,ImageView_Fullscreen

both in "Run" prompt as well as from the command line. Both gave me an error. "Missing entry ImageView_Fullscreen". None of the forums seem to have given a solution to fix this issue. After some more unlucky searches, I ended up with this command to be run. In the command line, run "regsvr32 /i shimgvw.dll" (without the quotes). It should say "registered successfully". Voila, my problem was solved. The viewer started appearing in my right click menu. I still do not know how it vanished in the first place. But, atleast I know how to bring it back.

Friday, May 27, 2011

Disappeared Window Manager

I use Ubuntu 10.04 at home. I am a GNOME guy since the days of RHL 9. One day, suddenly, all of a sudden, the maximize, minimize and close icons on all my windows just disappeared. Just like that. Didnt know what hit me. I had to go to the menu item, and close it. Then Googling, I found out that there is this guy called "metacity", a window manager, who is incharge of these kinds of stuff in the GUI for GNOME. From this link, I found out how to give it a boot, and bring back my lifesavers.

All you had to do is:

1. Check if its already running
ps aux | grep metacity


2. Then, if its not (even if its running), just load it.
sudo metacity


3. If it gives an error like "Window manager warning: Screen 0 on display ":0.0" already has a window manager;", then just force it

 sudo metacity --replace


There is a catch here. this will occupy a terminal window. So, I'd suggest, you give the system a restart, if you arent into anything utterly serious.

I expertly went ahead and killed that process, and my whole GUI went for a toss. Nothing worked (except the mouse). So, I had to run to my second login screen, do a
kill -9 METACITY-PID
of the metacity manager, and restart it with
sudo metacity --display=:0.0 --replace


And then, after I had saved my documents, I restarted the system. All is well, that restarted well.


Source link

Friday, September 17, 2010

Disable Autorun for USB Pen drives and CD Drives

Disabling autorun for USB drives prevents a lot of virus from jumping into the system as most of the "small" guys use the AutoRun feature to trigger themselves. There is a way to disable it completely.

Click "Start / Run" and type "gpedit.msc". It should open a windows like the one below

(Click on it to open a bigger image).


In that go to the branch on the left hand side frame following the below path

"Local Computer Policy / Computer Configuration / Administrative Templates / System"

Clicking on "System" will list lots of items on the right window. One of them is "Turn Off Autoplay".

Double click on that, make sure to select "Enabled" radio button and on the list box below, select "All Drives".

This should disable Autorun in all usb and cd/dvd drives on the system.

Rebooting Mac

Mac has the uncanny habit of screwing itself up (atleast mine does) and then not telling the user what happened. Let me explain. All of a sudden, the initial grey screen comes up with the loading "rotator" thingy. And thats about it. Nothing more happens. And when I force shutdown and restart, it does not actually start from the beginning, meaning it does not do a "CHUNNNGGG" chime sound when restarting.

And again, the cloud was the Good Samaritan (who else is there). Pressing the keyboard combination of "Command(Apple)-Option-P-R" and holding it like that (NB: it needs some skill to hold this key combination) until the chime sounds twice should resolve the issue. But, my machine seems to be a bit more adamant than that. Even though I have "CHUNNNG"ed it, it still stops are the rotator screen. :-( Will update the post as and when I find a solution.

Source: TUAW

Thursday, April 29, 2010

Control characters in source file after ftp

<p align="justify">My friend had a problem with a Linux file. he had ftp'd a file from windows into Linux. Now, every line in that file has a ^M at its end. He wanted a way to avoid it, and/or remove the control characters from such files.

Browsing thru the web, there were multiple answers provided.

1. While uploading via ftp, use the ASCII mode, not the binary mode. This will translate the line ends properly. Binary mode is to be used for programs and archive files only (like zip, tar, etc..)
2. dos2unix (and its complementary unix2dos utility)
3. cat file | tr -d "\r" > newfile
4. sed 's/.$//' infile.txt > outfile.txt
5. col -bx < oldfile > newfile

Disclaimer: I have not tried this in any of the ways mentioned. I am just listing it for easy access only.</p>

Saturday, November 14, 2009

xp disk defragmenter does not analyze or defrag

My system (as usual) was starting too sluggishly for my liking to start the defragmentation. But, when I clicked "Analyze" or "Defrag", nothing happened. I mean, absolutely nothing. No error messages. Not even a warning. Something in the lines of "hey moron, you are doing something wrong here" would have been more appropriate. Well, like any dumb user, I entered the realm of Google, and ended up triggering the defrag.exe from the command prompt. There, I got something. "Windows cannot connect to the Disk Defragmenter engine". Now, if only I KNEW where and how the hell I kick start that damn engine. Once again Larry ewing's nerds helped me from yonder. It seemed that the "DCOM Server Process Launcher" was not running. It had to be kick started for the defragger to skate board on. So, I clicked "Start/Run" and typed in "services.msc" and opened the services window. (the more normal way would be to go to My Computer, right click on it, Manage, and click services, bah, am a lazy guy). Kick started it, (but it acutally didnt. I had to set the mode to "Automatic" and restart the system). Then, I launched our guy, and voila, we are up and running.... Okay, he is working RIGHT NOW. Off I go. Tata

Thursday, August 06, 2009

Mouse scroll in VB6 IDE

VB6 had the dubious distinction of the only IDE without a supported mouse scroll in the code window. Fortunately, in true Microsoft style, they have given workarounds and patches to overcome this disability. Check this Microsoft's link on how to enable/activate mouse scrolling in the VB IDE

Friday, June 19, 2009

How to Enable Tooltip for Dialog Controls

Lets get things straight. You want the user to be more dumb and want him/her to get an idea of what he wants to do with all the controls on his screen without reading the help file? Then dive right in. Else, Ciao. Have a good day.



Step 1: Enable the tooltip command using the command EnableToolTips (TRUE). Ideal location to include this line would be in your class' init routine CYourClass::InitDialog.

Step 2: Windows sends the tooltip related controls in TTN_NEEDTEXT message. We need to handle this. Add the following code to enable your handler in the MessageMap function

BEGIN_MESSAGE_MAP(CMyClassDlg, CDialog)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipNotify)
END_MESSAGE_MAP()


Step 3: Declare the handler function in your header.
afx_msg bool OnToolTipNotify( UINT id, NMHDR* pNMHDR, 
LRESULT* pResult );


Step 4: We are near. Just add then handler code in your cpp. Below is a sample of the same

bool CMyClassDlg::OnToolTipNotify( 
UINT id, NMHDR* pNMHDR, LRESULT* pResult )
{
// Get the tooltip structure.
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;

// Actually the idFrom holds Control's handle.
UINT CtrlHandle = pNMHDR->idFrom;

// Check once again that the
// idFrom holds handle itself.
if (pTTT->uFlags & TTF_IDISHWND)
{
// Get the control's ID.
UINT nID = ::GetDlgCtrlID( HWND( CtrlHandle ));

// Now you have the ID. depends on control,
// set your tooltip message.
switch( nID )
{
case ID_BUTTON1:
// Set the tooltip text.
pTTT->lpszText = _T("First Button");
break;

case ID_EDIT1:
// Set the tooltip text.
pTTT->lpszText = _T("First Edit Box");
break;

default:
// Set the tooltip text.
pTTT->lpszText = _T("Tooltips everywhere!!!");
break;
}

return TRUE;
}

// Not handled.
return FALSE;
}

Friday, October 17, 2008

No Help inside VC IDE

I recently implemented the Help feature for an application. But, pressing F1 key or clicking on the corresponding button did not work out at all. No help window popped up. After much googling, I fell on this. This does not work when the application is run from inside the VC IDE. So, I went to the Debug directory and launched the application from there. Voila, help worked. But, still when pressing F1 key, I was getting an error message stating the the HLP file was missing. So, in order to disable that, the ON_WM_HELPINFO needed to be handled. Once that is done, the unwanted error message stops showing its ugly face.

Thursday, September 25, 2008

Adding accelerator keys in VC

A microsoft support link shows in a pretty straightforward way how to implement an accelrator key. Have a go

Getting the hyper link to work in CRichEditCtrl

Trying to get a mouse click to work in RichEdit and not succeeding? I faced a similar issue and ended up with this flow

Set the SetEventMask for your m_MyRichEdit (this is my control variable for the CRichEditCtrl class) to understand links
m_MyRichEdit.SetEventMask( \
m_MyRichEdit.GetEventMask() | ENM_MOUSEEVENTS)
Now, add a override function for OnNotify in your class. In the .h file, add
afx_msg BOOL OnNotify (WPARAM wParam, \
LPARAM lParam, LRESULT *pResult);
Add the corresponding function similar to the one below
BOOL CParentDlg:: OnNotify (WPARAM wParam, LPARAM lParam, LRESULT * pResult) 
{

if (LOWORD (wParam) == IDC_RICHEDIT)
{
MSGFILTER * mf = (MSGFILTER *) lParam;
switch (mf-> msg)
{
case WM_LBUTTONUP:
ENLINK *p_EnLink;
p_EnLink = (ENLINK *)lParam;
m_MyRichEdit.SetSel (p_EnLink->chrg);
CString szLinkString = m_RichEdit.GetSelText ();
break;
)
)

return CDialog:: OnNotify (wParam, lParam, pResult);
)
Now, your szLinkString will have the data you need to manipulate. You can use this with the ShellExecute function to popup whatever you want.

On, by the way, you need to add RTF content if you intend to make that identifiable. It goes something like
CString szT = "{\\rtf1 \\par http " + szAppendString + " \\par}";
My above code will popup a http link using which I Open it in ShellExecute

Tuesday, September 02, 2008

Auto Complete in VC++ 6

When the "Auto Complete" (Complete Word) feature of VC (6 in my case) stops working, all you need to do is
1. close the project
2. Go to the project directory
3. Remove the .ncb file in the directory
4. Re-open the project

Voila, its working !!!
(atleast it started working for me).

Ensoy

Wednesday, August 27, 2008

CTreeCtrl and Checkboxes

While working with CTreeCtrl with checkboxes, I came across these 2 issues

1. You would have set TVS_CHECKBOXES in the .rc file. Then during InitDialog, if
m_myTreeVar.SetCheck( hTreeWnd, TRUE)

is called, it will not work as expected. But, when the same line is called anywhere else later, it will work. To workaround this issue, the following two lines need to be added to simulate a removal/addition of the checkboxes flag at the beginning of InitDialog

m_myTree.ModifyStyle( TVS_CHECKBOXES, 0 );
m_myTree.ModifyStyle( 0, TVS_CHECKBOXES );

2. With the CTreeCtrl, when trying to get the handle of a "clicked" item using hittest, I fell on an issue that it was returning the handle of the NEXT item on the list and not the one which i clicked. The code is as below
 DWORD pos = GetMessagePos();
CPoint pt(LOWORD(pos), HIWORD(pos));
ScreenToClient(&pt);
UINT uFlags = 0;
HTREEITEM hItem = m_MainTree.HitTest(pt, &uFlags);


The above code returned the handle of the next list item from the one clicked. To fix the same, I just modified the "ScreenToClient" as below
m_myTree.ScreenToClient(&pt); 

and Voila!!! it worked!

Wednesday, May 28, 2008

Writing VB.Net app with c or C++ Dll

Added for my reconnaissance.

Step 1. Create a VC project (I used VC++ 6). An empty win32 DLL. The main things are below

Step 1a: For all the functions that needs to be exported, add "_stdcall" before their declaration and definition. For ex, I added
long _stdcall MyExportedFunction(int myinteger)

One VERY IMPORTANT thing to note. The return has to be something other than void as this causes an incompatibility between the DLL and the VB and the application will end up crashing.

Step 1b: Make sure to have a .def added to the VC project. The contents of my def file are


 MyVCLibrary.def : Declares the module parameters for the DLL.
LIBRARY "MyVCLibrary"
DESCRIPTION 'My VC Library DLL'

EXPORTS
; Explicit exports can go here
MyExportedFunction
My exported function prototype is
long _stdcall MyExportedFunction(int);

Now, thats it for the DLL. Compile and get it ready.

Step 2a: Create the VB.NET (I used Visual Studio 2008). In the Form Class, create a declaration as below (in a single line)


Declare Function MyExportedFunction Lib 
"MyVCLibrary.dll" (ByVal pcFilePath As Integer
) As Long

Step 2b: Call the function as below
Call MyExportedFunction(10)
. That's about pretty much to it.