Showing posts with label desktop. Show all posts
Showing posts with label desktop. Show all posts

Monday, January 28, 2019

ClassModifier : Utility to easily modify your Java class files

Modify your Java class files easy with an interactive GUI.

Since it is not possible to edit a class file directly, this tool changes the class file to Smali version which is editable. After making the required changes, this tool converts the modified Smali to the modified Class file.
Features:
  • Modify a given Java class file
  • Allows Pen-tester to verify if their java desktop application is safe from Auth bypass
  • Can help you change the logical behavior of a Jar file by modifying a class
  • You can override private methods, change access modifier for variables of a class using ClassModifier.
  • Many other possibilities....

Download ClassModifier:



How to Use:

java -jar ClassModifier.jar

Menu:

File
  1. Open class (CTRL+O)- Takes the input class which need to be modified
  2. Open Project (CTRL+P)– You can reopen the project created using this feature.
  3. Save & Convert (CTRL+S) – Saves & Convert the code to modified Class and Smali file
  4. Export Class (CTRL+E) – Export modified class
  5. Java 2 Smali Helper - Opens a tab where you can write any Java code which on saving will show its equivalent Smali code
  6. Smali 2 Java code - Opens a tab where you can write any Smali code which on saving will show its equivalent Java code
Edit
  1. Increase Code FontSize (CTRL+I) – Allows you to increase font size of shown code.
  2. Decrease Code FontSize (CTRL+D) – Allows you to decrease the font size of shown code.
  3. Remove all tabs – Removes all currently shown tabs.
Decompiler
  1. Change Decompiler – Allows you to switch between jadx and jd-cli decompilers.

Help
  1. Update Software – Helps you to update the current software if any update is available
  2. How to use Class Modifier– Contains the documentation of this tool

Toolbar
  1. Allows you to find in current code/replace/replaceAll/find all class

ClassModifier_lib Folder

  1. It comes along with the software
  2. Contains the helper jars used by program
  3. ClassModifier_lib\userLibrary is automatically added in classpath while compiling code. If you wish to compile your code using external jars then place those external jars inside ClassModifier_lib\userLibrary

How to Use:
  • Open the Java class to be Modified
  • On opening, ClassModifier will open the Smali version of the class file
  • Edit the smali file and make the required changes
  • Save the smali file 
  • Modified java class file will be created which can be anytime exported using the File -> Export Class button.
  • Since Smali editing can be difficult, 2 options are provided - Java 2 Smali Helper and vice-versa.
  • As name suggests, Java 2 Smali Helper lets you see the Smali equivalent code for the input Java code.
  • Similarly, Smali 2 Java Helper lets you see the Java equivalent code for the input Smali code.

Screenshot:




Note: This software is meant for educational purpose only. Don't use it for any illegal activity.

Saturday, November 19, 2016

Play Movies & Videos on Desktop Wallpaper using Java

This blog post will help you play movie/video on your desktop wallpaper.

Langauge Used:
Java & C++

Git Location:
https://github.com/csanuragjain/extra/tree/master/DesktopMovieWallpaper

Working Software:

Part 1 https://github.com/csanuragjain/extra/blob/master/DesktopMovieWallpaper/Working%20Software/Working%20Software.z01?raw=true
Part 2
https://github.com/csanuragjain/extra/blob/master/DesktopMovieWallpaper/Working%20Software/Working%20Software.zip?raw=true

Download both part and use winzip or winrar to extract.

Concept:

1) We ask user the video which he would like to set as desktop wallpaper
2) Now we convert the video to images using tutorial http://cooltrickshome.blogspot.com/2016/11/convert-movie-to-images-using-java.html
3) Assume step 2 converted the video to 100 images.
4) We will start a loop and set desktop wallpaper all the 100 images found in step 3 one by one.
5) Overall effect is a movie playing in desktop wallpaper

Note:
1) This program converts the video to images. The overall converted images will be of size greater than the video. Make sure you have sufficient space if you are trying to convert a big video.

Pom Dependency:
Please add the below pom dependency from https://mvnrepository.com/artifact/org.bytedeco/javacv :
 <dependency>  
   <groupId>org.bytedeco</groupId>  
   <artifactId>javacv</artifactId>  
   <version>1.0</version>  
 </dependency>  

Java Program:
Main method:
      public static void main(String[] args) throws InterruptedException, Exception, IOException {  
           Scanner s=new Scanner(System.in);  
            System.out.println("Enter the path of mp4 (for eg c:\\test.mp4)");  
            String mp4Path=s.nextLine();  
            File imgPath=new File("convert");  
            imgPath.delete();  
            imgPath.mkdirs();  
            String imagePath=imgPath.getAbsolutePath();  
            convertMovietoJPG(mp4Path, imagePath,"jpg",3);  
            System.out.println("Conversion complete. Please find the images at "+imagePath);  
            changeDesktopWallpaper(imagePath,5000);  
      }  

How it works:
1) We make a scanner object to read user input
2) We ask user to enter path of mp4 file
3) We make a new folder named convert in current project directory. This will be the directory where images extracted from video would be kept
4) We call convertMovietoJPG method which converts the mp4 to images. I kept frametoJump as 3 but you may change it as per your requirement. More details on this http://cooltrickshome.blogspot.com/2016/11/convert-movie-to-images-using-java.html
5) Finally we call changeDesktopWallpaper which will set the images extracted from movie as wallpaper one by one giving a movie effect.
6) First argument defines the path containing the converted image and 5000 represents the millisecond after which video will start replay after it completes.

convertMovietoJPG method:
       public static void convertMovietoJPG(String mp4Path, String imagePath, String imgType, int frameJump) throws Exception, IOException  
       {  
                 Java2DFrameConverter converter = new Java2DFrameConverter();  
          FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(mp4Path);  
          frameGrabber.start();  
          Frame frame;  
          double frameRate=frameGrabber.getFrameRate();  
          int imgNum=0;  
          System.out.println("Video has "+frameGrabber.getLengthInFrames()+" frames and has frame rate of "+frameRate);  
          try {           
            for(int ii=1;ii<=frameGrabber.getLengthInFrames();ii++){  
            imgNum++;       
            frameGrabber.setFrameNumber(ii);  
            frame = frameGrabber.grab();  
            BufferedImage bi = converter.convert(frame);  
            String path = imagePath+File.separator+imgNum+".jpg";  
            ImageIO.write(bi,imgType, new File(path));  
            ii+=frameJump;  
            }  
            frameGrabber.stop();  
          } catch (Exception e) {  
            e.printStackTrace();  
          }  
        }  


How it works:
1) Already covered the explanation at http://cooltrickshome.blogspot.com/2016/11/convert-movie-to-images-using-java.html

changeDesktopWallpaper method:
      public static void changeDesktopWallpaper(String path, int sleepTime) throws InterruptedException  
      {  
           System.out.println("Starting to replay video after every "+(sleepTime/1000)+"s");  
           File f=new File(path);  
           File[] filePath=f.listFiles();  
           while(true)  
           {  
           for(int i=1;i<=filePath.length;i++)  
           {       
           changeWallpaper(path+"\\"+i+".jpg");  
           }  
           Thread.sleep(sleepTime);  
           }  
      }  


How it works:
1) We point file array on all the images extracted from video
2) For each image we call changeWallpaper which changes the wallpaper to that image.
3) Once all images are complete it waits for sleepTime and then restarts from step2

C++ Program:

wallpaperchanger.h
 /* DO NOT EDIT THIS FILE - it is machine generated */  
 #include <jni.h>  
 /* Header for class com_cooltrickshome_DesktopMovieWallpaper */  
 #ifndef _Included_com_cooltrickshome_DesktopMovieWallpaper  
 #define _Included_com_cooltrickshome_DesktopMovieWallpaper  
 #ifdef __cplusplus  
 extern "C" {  
 #endif  
 /*  
  * Class:   com_cooltrickshome_DesktopMovieWallpaper  
  * Method:  changeWallpaper  
  * Signature: (Ljava/lang/String;)I  
  */  
 JNIEXPORT jint JNICALL Java_com_cooltrickshome_DesktopMovieWallpaper_changeWallpaper  
  (JNIEnv *, jclass, jstring);  
 #ifdef __cplusplus  
 }  
 #endif  
 #endif  

wallpaperchanger.cpp
  #include <iostream>  
  #include <windows.h>  
  #include <fstream>  
  #include <cstdlib>  
  #include <jni.h>  
  #include "wallpaperchanger.h"  
  JNIEXPORT jint JNICALL Java_com_cooltrickshome_DesktopMovieWallpaper_changeWallpaper  
  (JNIEnv *env, jclass, jstring wallpaper){  
  const char *wallpaper_file = env->GetStringUTFChars(wallpaper, JNI_FALSE);  
  int return_value = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void *)wallpaper_file, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);  
  env->ReleaseStringUTFChars(wallpaper, wallpaper_file);  
  }  

How it works:
1) changeWallpaper method used by Java is defined in wallpaperchanger.dll which is created using wallpaperchanger.h & wallpaperchanger.cpp (Conversion from cpp & h to dll is explained at https://cooltrickshome.blogspot.in/2016/11/creating-your-personal-keylogger-from.html)
2) For cpp code, wallpaper variable contains the path of the wallpaper which is passed by Java
3) First we need to convert it to const char* which is done using env->GetStringUTFChars
4) SystemParametersInfo method is used to convert the wallpaper. We pass the desktop wallpaper path in it to change the wallpaper
5) Now we release the converted string.

Output:
 Enter the path of mp4 (for eg c:\test.mp4)  
 C:\Users\anjain\Desktop\images\rough\1.mp4  
 Video has 132 frames and has frame rate of 25.0  
 Conversion complete. Please find the images at C:\Users\anjain\workspace\BrowserMobProxy\cooltrickshome\convert  
 Starting to replay video after every 5s  

Full Program:

DesktopMovieWallpaper.java
 package com.cooltrickshome;  
 import java.awt.image.BufferedImage;  
 import java.io.File;  
 import java.io.IOException;  
 import java.util.Scanner;  
 import javax.imageio.ImageIO;  
 import org.bytedeco.javacv.FFmpegFrameGrabber;  
 import org.bytedeco.javacv.Frame;  
 import org.bytedeco.javacv.Java2DFrameConverter;  
 import org.bytedeco.javacv.FrameGrabber.Exception;  
 public class DesktopMovieWallpaper {  
      public static native int changeWallpaper(String path);  
      static  
   {  
     System.loadLibrary("wallpaperchanger");  
   }  
      public static void changeDesktopWallpaper(String path, int sleepTime) throws InterruptedException  
      {  
           System.out.println("Starting to replay video after every "+(sleepTime/1000)+"s");  
           File f=new File(path);  
           File[] filePath=f.listFiles();  
           while(true)  
           {  
           for(int i=1;i<=filePath.length;i++)  
           {       
           changeWallpaper(path+"\\"+i+".jpg");  
           }  
           Thread.sleep(sleepTime);  
           }  
      }  
       public static void convertMovietoJPG(String mp4Path, String imagePath, String imgType, int frameJump) throws Exception, IOException  
       {  
                 Java2DFrameConverter converter = new Java2DFrameConverter();  
          FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(mp4Path);  
          frameGrabber.start();  
          Frame frame;  
          double frameRate=frameGrabber.getFrameRate();  
          int imgNum=0;  
          System.out.println("Video has "+frameGrabber.getLengthInFrames()+" frames and has frame rate of "+frameRate);  
          try {           
            for(int ii=1;ii<=frameGrabber.getLengthInFrames();ii++){  
            imgNum++;       
            frameGrabber.setFrameNumber(ii);  
            frame = frameGrabber.grab();  
            BufferedImage bi = converter.convert(frame);  
            String path = imagePath+File.separator+imgNum+".jpg";  
            ImageIO.write(bi,imgType, new File(path));  
            ii+=frameJump;  
            }  
            frameGrabber.stop();  
          } catch (Exception e) {  
            e.printStackTrace();  
          }  
        }  
      public static void main(String[] args) throws InterruptedException, Exception, IOException {  
           Scanner s=new Scanner(System.in);  
            System.out.println("Enter the path of mp4 (for eg c:\\test.mp4)");  
            String mp4Path=s.nextLine();  
            File imgPath=new File("convert");  
            imgPath.delete();  
            imgPath.mkdirs();  
            String imagePath=imgPath.getAbsolutePath();  
            convertMovietoJPG(mp4Path, imagePath,"jpg",3);  
            System.out.println("Conversion complete. Please find the images at "+imagePath);  
            changeDesktopWallpaper(imagePath,5000);  
      }  
 }  

wallpaperchanger.h
 /* DO NOT EDIT THIS FILE - it is machine generated */  
 #include <jni.h>  
 /* Header for class com_cooltrickshome_DesktopMovieWallpaper */  
 #ifndef _Included_com_cooltrickshome_DesktopMovieWallpaper  
 #define _Included_com_cooltrickshome_DesktopMovieWallpaper  
 #ifdef __cplusplus  
 extern "C" {  
 #endif  
 /*  
  * Class:   com_cooltrickshome_DesktopMovieWallpaper  
  * Method:  changeWallpaper  
  * Signature: (Ljava/lang/String;)I  
  */  
 JNIEXPORT jint JNICALL Java_com_cooltrickshome_DesktopMovieWallpaper_changeWallpaper  
  (JNIEnv *, jclass, jstring);  
 #ifdef __cplusplus  
 }  
 #endif  
 #endif  

wallpaperchanger.cpp
  #include <iostream>  
  #include <windows.h>  
  #include <fstream>  
  #include <cstdlib>  
  #include <jni.h>  
  #include "wallpaperchanger.h"  
  JNIEXPORT jint JNICALL Java_com_cooltrickshome_DesktopMovieWallpaper_changeWallpaper  
  (JNIEnv *env, jclass, jstring wallpaper){  
  const char *wallpaper_file = env->GetStringUTFChars(wallpaper, JNI_FALSE);  
  int return_value = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void *)wallpaper_file, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);  
  env->ReleaseStringUTFChars(wallpaper, wallpaper_file);  
  }  

Hope it helps :)

Sunday, November 13, 2016

Create Desktop Screenshot Maker Software using Java

In this blog post we will learn to create a Java program which can take screenshots from your desktop. It will also support taking screenshots of a selected region.

Features of the software:
1) Take Screenshots of a selected region or fullscreen
2) You can press F6 to start taking Screenshots and F8 to exit from the application
3) Once you press F6, just select the screenshot region by dragging your mouse and a screenshot would be created for selected region.
4) All screenshots are kept at same directory from where program is run

Logic Used:
1) Java can take screenshots using Robot class
2) It can act on custom key like F6 & F8 using JNI (https://cooltrickshome.blogspot.in/2016/11/creating-your-personal-keylogger-from.html)
3) Challenge is how we can make user select region of a screen for which he want to take screenshot.
 A) We take the full size screenshot of the user screen and show the same screenshot as background image of a full window JFrame.
 B) When user drags the region, he is actually dragging the region from the background image of a JFrame. Hence we can show a rectangle for the selection region.

Running Software:

Please find a working copy of the software at:
https://github.com/csanuragjain/recorder/blob/master/DesktopScreenshotMaker/Software/DesktopScreenshotMaker.zip?raw=true

Unzip it and then Use below command to run (make sure you use 64 bit java)
 java -jar DesktopScreenshotMaker.jar  

Source Code:
https://github.com/csanuragjain/recorder/tree/master/DesktopScreenshotMaker/Code

Language Used:
Java, C++

C++ Usage:

C++ captures all the user keys and passes them to Java using JNI (Already discussed in https://cooltrickshome.blogspot.in/2016/11/creating-your-personal-keylogger-from.html)
When user press F6 then Java program starts the screen capture module and likewise when it receives F8 then it exits.

Java Usage:

DesktopScreenshot.java

Variables:
 public class DesktopScreenshot implements MouseListener,  
           MouseMotionListener {  
      int drag_status = 0;  
      int c1;  
      int c2;  
      int c3;  
      int c4;  
      JFrame frame=null;  
      static int counter=0;  
      JLabel background=null;  
      static  
      {  
           System.loadLibrary("MyLogger");  
      }  
      public static native int GetKey();  

Explanation:
1) drag_status tells if mouse is currently dragging a region or not
2) c1,c2,c3,c4 defines the coordinate of the region for which screenshot would be taken
3)  Screenshot are saved as screenshot<counter>.jpg so counter will help naming screenshot files.
4) MyLogger is the dll which is tracking the user key input
5) GetKey gives the key input by user.

Main method:
      public static void main(String args[]) throws AWTException, IOException, InterruptedException  
      {  
           DesktopScreenshot ds=new DesktopScreenshot();  
           System.out.println("Press F6 and then drag your mouse to take screenshot. For exiting press F8");  
           while(true)  
           {  
           int d=GetKey();  
           if(d==117)  
           {  
                ds.getImage();  
           }  
           else  
                if(d==119)  
                {  
                     System.exit(0);  
                }  
           }  
      }  

Explanation:
1) We make an infinite loop and keep track of all user key pressed
2) If key input is 117 which is the code for F6 then we call the screenshot maker module getImage
3) If key input is 119 which is code for F8 then program exits using System.exit

getImage method:
      public void getImage() throws AWTException, IOException, InterruptedException {  
           Dimension size = Toolkit.getDefaultToolkit().getScreenSize();  
        Robot robot = new Robot();  
        BufferedImage img = robot.createScreenCapture(new Rectangle(size));  
        ImagePanel panel = new ImagePanel(img);  
        frame=new JFrame();  
        frame.add(panel);  
        frame.setLocation(0, 0);  
        frame.setSize(size);  
        frame.setLayout(new FlowLayout());  
        frame.setUndecorated(true);  
        frame.setVisible(true);  
        frame.addMouseListener(this);  
        frame.addMouseMotionListener(this);  
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);  
      }  

Explanation:
1) Toolkit.getDefaultToolkit().getScreenSize() is used to determine the size of screen
2) Now we use the createScreenCapture method of Robot class to capture the screen. Full screen would be captured since we pass the size to be screen size
3) We have made a custom ImagePanel class which would add the screenshot captured on a Frame
4) Now we create a frame and add the panel containing the screenshot of the screen.
5) We set the function setUndecorated to true so that the frame appears without any title bar
6) We add mouse listener so that user can crop the regions from the screenshot in the frame as discussed later.

Mouse events:
      public void mouseClicked(MouseEvent arg0) {  
      }  
      public void mouseEntered(MouseEvent arg0) {  
      }  
      public void mouseExited(MouseEvent arg0) {  
      }  
      public void mouseMoved(MouseEvent arg0) {  
      }  
      public void mousePressed(MouseEvent arg0) {  
           paint();  
           this.c1 = arg0.getX();  
           this.c2 = arg0.getY();  
      }  
      public void mouseDragged(MouseEvent arg0) {  
           paint();  
           this.drag_status = 1;  
           this.c3 = arg0.getX();  
           this.c4 = arg0.getY();  
      }  
      public void mouseReleased(MouseEvent arg0) {  
           paint();  
           if (this.drag_status == 1) {  
                this.c3 = arg0.getX();  
                this.c4 = arg0.getY();  
                try {  
                     draggedScreen();  
                } catch (Exception e) {  
                     e.printStackTrace();  
                }  
           }  
      }  
      public void paint() {  
           Graphics g = frame.getGraphics();  
           frame.repaint();  
           int w = this.c1 - this.c3;  
           int h = this.c2 - this.c4;  
           w *= -1;  
           h *= -1;  
           if (w < 0) {  
                w *= -1;  
           }  
           g.drawRect(this.c1, this.c2, w, h);  
      }  
      public void draggedScreen() throws Exception {  
           int w = this.c1 - this.c3;  
           int h = this.c2 - this.c4;  
           w *= -1;  
           h *= -1;  
           Robot robot = new Robot();  
           BufferedImage img = robot.createScreenCapture(new Rectangle(this.c1,  
                     this.c2, w, h));  
           counter++;  
           File save_path = new File("screenshot"+counter+".jpg");  
           ImageIO.write(img, "JPG", save_path);  
           c1=0;  
           c2=0;  
           c3=0;  
           c4=0;       
           frame.disable();  
           frame.dispose();  
           new File("desktop.jpg").delete();  
      }  

Explanation:
1) When mouse is pressed we record the starting coordinate in c1 & c2
2) When mouse is dragged then we record the ending coordinate in c3 & c4. We call the paint method which starts drawing the rectangle to show the selected region described by (c1,c2) & (c3,c4)
3) When mouse is released we get the final region for which screenshot need to taken and update c3 and c4.
4) We call draggedScreen method which simply takes the screenshot of the region selected by user and saves it using ImageIO write method.

ImagePanel.java
 package com.cooltrickshome;  
 import java.awt.Dimension;  
 import java.awt.Graphics;  
 import java.awt.Image;  
 import javax.swing.ImageIcon;  
 import javax.swing.JPanel;  
 class ImagePanel  
  extends JPanel  
 {  
  private Image img;  
  public ImagePanel(String img)  
  {  
   this(new ImageIcon(img).getImage());  
  }  
  public ImagePanel(Image img)  
  {  
   this.img = img;  
   Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));  
   setPreferredSize(size);  
   setMinimumSize(size);  
   setMaximumSize(size);  
   setSize(size);  
   setLayout(null);  
  }  
  public void paintComponent(Graphics g)  
  {  
   g.drawImage(this.img, 0, 0, null);  
  }  
 }  

Explanation:
1) We determine the height and width of the image passed
2) We make the JPanel with same size
3) We draw the image over JPanel using Graphics drawImage method.

Sample Screenshot:


Full Code:
DesktopScreenshot.java
 package com.cooltrickshome;  
 import java.awt.AWTException;  
 import java.awt.Dimension;  
 import java.awt.FlowLayout;  
 import java.awt.Graphics;  
 import java.awt.Rectangle;  
 import java.awt.Robot;  
 import java.awt.Toolkit;  
 import java.awt.event.MouseEvent;  
 import java.awt.event.MouseListener;  
 import java.awt.event.MouseMotionListener;  
 import java.awt.image.BufferedImage;  
 import java.io.File;  
 import java.io.IOException;  
 import javax.imageio.ImageIO;  
 import javax.swing.JFrame;  
 import javax.swing.JLabel;  
 public class DesktopScreenshot implements MouseListener,  
           MouseMotionListener {  
      int drag_status = 0;  
      int c1;  
      int c2;  
      int c3;  
      int c4;  
      JFrame frame=null;  
      static int counter=0;  
      JLabel background=null;  
      static  
      {  
           System.loadLibrary("MyLogger");  
      }  
      public static native int GetKey();  
      /**  
       * @param args  
       * @throws AWTException   
       * @throws IOException   
       * @throws InterruptedException   
       */  
      public static void main(String args[]) throws AWTException, IOException, InterruptedException  
      {  
           DesktopScreenshot ds=new DesktopScreenshot();  
           System.out.println("Press F6 and then drag your mouse to take screenshot. For exiting press F8");  
           while(true)  
           {  
           int d=GetKey();  
           if(d==117)  
           {  
                ds.getImage();  
           }  
           else  
                if(d==119)  
                {  
                     System.exit(0);  
                }  
           }  
      }  
      public void getImage() throws AWTException, IOException, InterruptedException {  
           Dimension size = Toolkit.getDefaultToolkit().getScreenSize();  
        Robot robot = new Robot();  
        BufferedImage img = robot.createScreenCapture(new Rectangle(size));  
        ImagePanel panel = new ImagePanel(img);  
        frame=new JFrame();  
        frame.add(panel);  
        frame.setLocation(0, 0);  
        frame.setSize(size);  
        frame.setLayout(new FlowLayout());  
        frame.setUndecorated(true);  
        frame.setVisible(true);  
        frame.addMouseListener(this);  
        frame.addMouseMotionListener(this);  
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);  
      }  
      public void draggedScreen() throws Exception {  
           int w = this.c1 - this.c3;  
           int h = this.c2 - this.c4;  
           w *= -1;  
           h *= -1;  
           Robot robot = new Robot();  
           BufferedImage img = robot.createScreenCapture(new Rectangle(this.c1,  
                     this.c2, w, h));  
           counter++;  
           File save_path = new File("screenshot"+counter+".jpg");  
           ImageIO.write(img, "JPG", save_path);  
           c1=0;  
           c2=0;  
           c3=0;  
           c4=0;       
           frame.disable();  
           frame.dispose();  
           new File("desktop.jpg").delete();  
      }  
      public void mouseClicked(MouseEvent arg0) {  
      }  
      public void mouseEntered(MouseEvent arg0) {  
      }  
      public void mouseExited(MouseEvent arg0) {  
      }  
      public void mousePressed(MouseEvent arg0) {  
           paint();  
           this.c1 = arg0.getX();  
           this.c2 = arg0.getY();  
      }  
      public void mouseReleased(MouseEvent arg0) {  
           paint();  
           if (this.drag_status == 1) {  
                this.c3 = arg0.getX();  
                this.c4 = arg0.getY();  
                try {  
                     draggedScreen();  
                } catch (Exception e) {  
                     e.printStackTrace();  
                }  
           }  
      }  
      public void mouseDragged(MouseEvent arg0) {  
           paint();  
           this.drag_status = 1;  
           this.c3 = arg0.getX();  
           this.c4 = arg0.getY();  
      }  
      public void mouseMoved(MouseEvent arg0) {  
      }  
      public void paint() {  
           Graphics g = frame.getGraphics();  
           frame.repaint();  
           int w = this.c1 - this.c3;  
           int h = this.c2 - this.c4;  
           w *= -1;  
           h *= -1;  
           if (w < 0) {  
                w *= -1;  
           }  
           g.drawRect(this.c1, this.c2, w, h);  
      }  
 }  

ImagePanel.java
 package com.cooltrickshome;  
 import java.awt.Dimension;  
 import java.awt.Graphics;  
 import java.awt.Image;  
 import javax.swing.ImageIcon;  
 import javax.swing.JPanel;  
 class ImagePanel  
  extends JPanel  
 {  
  private Image img;  
  public ImagePanel(String img)  
  {  
   this(new ImageIcon(img).getImage());  
  }  
  public ImagePanel(Image img)  
  {  
   this.img = img;  
   Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));  
   setPreferredSize(size);  
   setMinimumSize(size);  
   setMaximumSize(size);  
   setSize(size);  
   setLayout(null);  
  }  
  public void paintComponent(Graphics g)  
  {  
   g.drawImage(this.img, 0, 0, null);  
  }  
 }  

DLL:
https://github.com/csanuragjain/recorder/blob/master/DesktopScreenshotMaker/Code/dll/MyLogger.dll?raw=true

Hope it helps :)