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.