Sunday 27 September 2015

HB Blog 95: How To Compile SQL Statement Into Reusable Pre-compiled Statement Object???

Database transactions are slow and in situations where there is need for thousands of records have to be inserted, inserting each record takes a lot of time and valuable resources.
Basically, insert() is convenience method for inserting a row into the database. But, for saving time and valuable resources we can use compile statement().  It compiles an SQL statement into a reusable pre-compiled statement object.

SQLite provides methods in SQLiteDatabase class can be used to make all the insert calls in the same batch in a single transaction. Start a transaction by calling the beginTransaction() method. Perform the database operations and then call the setTransactionSuccessful() to commit the transaction. Once the transaction is complete call the endTransaction() function.
    beginTransaction();
    compileStatement(String sql)
    setTransactionSuccessful();
    endTransaction();

Here is the standard idiom for transactions:
db.compileStatement (String sql)
db.beginTransaction();
try {
...
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}

Refer the below link for complete sample code:-
Download Sample Code
Download Apk File
Have a look on few code snippets,

MainActivity.java
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
package com.databasecompilestatement_as;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import com.dbUtils.DBManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;

public class MainActivity extends Activity {
    private ArrayAdapter<String> arrayAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button insert_raw_query = (Button) findViewById(R.id.insert_raw_query);
        Button insert_compile_statement = (Button) findViewById(R.id.insert_compile_statement);
        Button save_to_sdcard = (Button) findViewById(R.id.save_to_sdcard);
        ListView listView=(ListView)findViewById(R.id.listView);
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, arrayList);
        listView.setAdapter(arrayAdapter);

        final DBManager dbManager = new DBManager(MainActivity.this);
        insert_raw_query.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                long startTime = System.currentTimeMillis();
                dbManager.insertRawQuery(MainActivity.this);
                long diff = System.currentTimeMillis() - startTime;
                String result="insertRawQuery time diff: " + diff;
                arrayAdapter.add(String.valueOf(result));
            }
        });

        insert_compile_statement.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                long startTime = System.currentTimeMillis();
                dbManager.insertCompileStatement(MainActivity.this);
                long diff = System.currentTimeMillis() - startTime;
                String result="insertCompileStatement time diff: " + diff;
                arrayAdapter.add(result);
            }
        });


        save_to_sdcard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveDatabaseToSdcard(MainActivity.this);
            }
        });
    }

    /**
     * save Database To Sdcard
     *
     * @param context
     */
    public static void saveDatabaseToSdcard(Context context) {
        try {
            InputStream myInput = new FileInputStream("/data/data/com.databasecompilestatement_as/databases/" + "hbdemodb.db");

            File file = new File(Environment.getExternalStorageDirectory().getPath() + "/" + "hbdemodb.db");
            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                }
            }

            OutputStream myOutput = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + "/" + "hbdemodb.db");

            byte[] buffer = new byte[1024];
            int length;
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }

            //Close the streams
            myOutput.flush();
            myOutput.close();
            myInput.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

ApplicationClass.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.dbUtils;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

/**
 * This is application class is used to declare global variable at application level.
 * Created by harshalb
 */
public class ApplicationClass extends Application {
    private SQLiteDatabase mSqLiteDatabase;

    @Override
    public void onCreate() {
        DBHelper dbHelper = new DBHelper(getApplicationContext());
        mSqLiteDatabase = dbHelper.getWritableDatabase();
        super.onCreate();
    }


    /**
     * This method is used to get database object.
     *
     * @return SQLiteDatabase
     */
    public SQLiteDatabase getReadableDatabase() {
        if (mSqLiteDatabase == null || mSqLiteDatabase.isOpen() == false) {
            DBHelper dbHelper = new DBHelper(getApplicationContext());
            mSqLiteDatabase = dbHelper.getReadableDatabase();
        }

        return mSqLiteDatabase;
    }

    /**
     * This method is used to get database object.
     *
     * @return SQLiteDatabase
     */
    public SQLiteDatabase getWritableDatabase() {
        if (mSqLiteDatabase == null || mSqLiteDatabase.isOpen() == false) {
            DBHelper dbHelper = new DBHelper(getApplicationContext());
            mSqLiteDatabase = dbHelper.getWritableDatabase();
        }
        return mSqLiteDatabase;
    }

    /**
     * This method is used to close database object.
     */
    public void closeDB() {
        if (mSqLiteDatabase != null)
            mSqLiteDatabase.close();
    }
}

DBHelper.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.dbUtils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * The DB helper class used to create database.
 * Created by harshalb
 */
public class DBHelper extends SQLiteOpenHelper {
    public static String DATABASE_NAME = "hbdemodb.db";
    static int DATABASE_VERSION = 1;

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(DatabasePojo.CREATE_TABLE_QUERY);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        super.onDowngrade(db, oldVersion, newVersion);
    }

    public void restoreDatabase() {
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + DatabasePojo.TABLENAME);
        sqLiteDatabase.execSQL(DatabasePojo.CREATE_TABLE_QUERY);
        sqLiteDatabase.close();
    }
}

DatabasePojo.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
package com.dbUtils;

/**
 * This is database pojo class.
 * Created by harshalb
 */
public class DatabasePojo {

    public static String TABLENAME = "hbdemoTable";
    public static String CREATE_TABLE_QUERY = "CREATE TABLE IF NOT EXISTS " + TABLENAME + " ("
//            + "_id INTEGER PRIMARY KEY, " //Don't remove this column.
            + "name VARCHAR, "
            + "surname VARCHAR, "
            + "result VARCHAR "
            + ")";
    public int name;
    public int surname;
    public int result;
}

DBManager.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.dbUtils;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;


/**
 * This is a manager class used to manage database related information.
 * Created by harshalb
 */
public class DBManager {
    Context mContext;

    public DBManager(Context context) {
        this.mContext = context;
    }

    public void insertRawQuery(Context context) {
        ApplicationClass applicationClass = (ApplicationClass) context.getApplicationContext();
        SQLiteDatabase sqLiteDatabase = applicationClass.getWritableDatabase();

        for (int i = 0; i < 100; i++) {
            ContentValues values = new ContentValues();
            values.put("name", "rawname" + i);
            values.put("surname", "rawsurname" + i);
            values.put("result", i * i);
            sqLiteDatabase.insert(DatabasePojo.TABLENAME, null, values);
        }
    }

    public void insertCompileStatement(Context context) {
        ApplicationClass applicationClass = (ApplicationClass) context.getApplicationContext();
        SQLiteDatabase sqLiteDatabase = applicationClass.getWritableDatabase();
        String sql = "INSERT INTO " + DatabasePojo.TABLENAME + " VALUES (?,?,?);";
        SQLiteStatement statement = sqLiteDatabase.compileStatement(sql);
        sqLiteDatabase.beginTransaction();
        for (int i = 0; i < 100; i++) {
            statement.clearBindings();
            statement.bindString(1, "name" + i);
            statement.bindString(2, "surname" + i);
            statement.bindLong(3, i * i);
            statement.execute();
        }
        sqLiteDatabase.setTransactionSuccessful();
        sqLiteDatabase.endTransaction();
    }

}

activity_main.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:id="@+id/insert_raw_query"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Insert Raw Query" />

    <Button
        android:id="@+id/insert_compile_statement"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Insert Compile Statement" />

    <Button
        android:id="@+id/save_to_sdcard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Save To Sdcard" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:layout_gravity="center_horizontal" />


</LinearLayout>

AndroidManifest.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.databasecompilestatement_as">

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21"></uses-sdk>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:name="com.dbUtils.ApplicationClass"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Sunday 13 September 2015

HB Blog 94: MoPub - Mobile Ad Server Integration In Android And iOS.

MoPub is a hosted ad serving solution built specifically for mobile publishers. It helps to grow your mobile advertising business with powerful ad management. etc.
In this post, I will show how to integrate MoPub ads in Android as well as iOS.
For Android,
Here are the basic integration steps: -
  1.     Check out the files from our repository.
  2.     Add our SDK (and dependencies) to your project.
  3.     Create ad units in your app.
Download the MoPub Android SDK: -
The MoPub SDK is distributed as source code that you must include in your application.
MoPub Android Full SDK.zip
Includes everything you need to serve HTML and MRAID MoPub advertisements and built-in support for the Millennial Media ad network - including the required third party binaries.

Using Gradle: -
Open your project's settings.gradle file and make sure the MoPub SDK is included as a module:
include ':app', ':mopub-sdk'
Open your project's build.gradle file and add jcenter as a repository and the MoPub SDK as a dependency:
repositories {
    jcenter()
}
...
dependencies {
    compile project(':mopub-sdk')
...
}

This is required in order to resolve the MoPub SDK's compile time dependency on com.mopub.volley:mopub-volley:1.1.0.
Follow the instructions on the Android Developer Site for setting up Google Play Services. It is always recommend to use the latest version of Google Play Services. 

Load banner ads in your app: -
1. Check your AndroidManifest.xml file.
Add following permissions,
1
2
3
4
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You’ll also need to include the following custom Activities (even though you won’t instantiate them directly):
1
2
3
4
<activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.common.MoPubBrowser" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
2. Define a slot for your banner ad in your layout XML.
The MoPub SDK provides a custom View subclass, MoPubView, that handles requesting and loading ads.
Include this XML block to your Activity’s or Fragment’s layout.
1
2
3
4
<com.mopub.mobileads.MoPubView
    android:id="@+id/adview"
    android:layout_width="fill_parent"
    android:layout_height="50dp"/>
3. Load an ad into the banner slot.
In your Activity or Fragment code, declare an instance variable for your MoPubView:
private MoPubView moPubView;
You should already have created an ad unit on MoPub’s site and received an Ad Unit ID. You’ll use it now to identify that ad unit in your app and request ads from MoPub that are relevant for your users.
In your Activity’s onCreate() or your Fragment’s onCreateView() method, set your MoPubView’s Ad Unit ID, then simply call loadAd() to fetch and display the ad:
1
2
3
4
5
...
moPubView = (MoPubView) findViewById(R.id.adview);
moPubView.setAdUnitId("xxxxxxxxxxx"); // Enter your Ad Unit ID from www.mopub.com
moPubView.loadAd();
...
When the hosting Activity or Fragment is destroyed, be sure to also destroy the MoPubView by calling:
1
moPubView.destroy();

Additional Listener Interface: - MoPubView provides a listener interface, BannerAdListener, which you can use to stay informed about ad lifecycle events. 
BannerAdListener includes the following methods:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// Sent when the banner has successfully retrieved an ad.
public void onBannerLoaded(MoPubView banner);
// Sent when the banner has failed to retrieve an ad. You can use the MoPubErrorCode value to diagnose the cause of failure.
public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode);
// Sent when the user has tapped on the banner.
public void onBannerClicked(MoPubView banner);
// Sent when the banner has just taken over the screen.
public void onBannerExpanded(MoPubView banner);
// Sent when an expanded banner has collapsed back to its original size.
public void onBannerCollapsed(MoPubView banner);

For iOS,
Here are the basic integration steps: -
  1.     Download the MoPub SDK
  2.     Add the SDK to your Xcode project.
  3.     Create and use a Banner or Interstitial ad.
Download the MoPub iOS SDK: -
The MoPub SDK is distributed as source code that you must include in your application.
MoPub Full SDK.zip
Includes everything you need to serve HTML and MRAID MoPub advertisiments and built-in support for three major third party ad networks - iAd, Google AdMob, and Millennial Media - including the required third party binaries.

Using CocoaPods: -
The MoPub SDK is available through Cocoapods, a popular dependency management system for Objective-C projects.
To download and incorporate the MoPub SDK into your project using Cocoapods, add the following line to your project's podfile:
pod 'mopub-ios-sdk'
After running pod install (if you’re setting up Cocoapods for the first time) or pod update (if you’re adding MoPub to an existing Cocoapods project), your project will be ready to use the base MoPub SDK.

Load banner ads in your app: -
You can create an ad unit (a space for ads) on the MoPub online dashboard. Upon your first visit, you'll be prompted to register your application and set up an ad unit. Afterwards, you can retrieve your ad unit ID by clicking "Get code snippet" in the top right corner of the ad unit page.
Adding a banner to your application takes only a few, easy steps:
  1.     In your view controller's header file: Import the MPAdView.h header file and declare an MPAdView *adView property. Declare that your view controller implements the MPAdViewDelegate protocol.
  2.     In your view controller's implementation file, instantiate an MPAdView, passing in your ad unit ID. This is typically done in -viewDidLoad.
  3.     Register your view controller as the adView's delegate.
  4.     Set the adView's frame and add the adView to your controller's view hierarchy.
  5.     Center the adViewon screen to account for iPhone 6 and iPhone 6 plus
  6.     Implement the -viewControllerForPresentingModalView MPAdViewDelegate method. The adView will use the view controller returned by this method to present modals when tapped. Typically your controller can simply return self.
  7.     Finally, load an ad by sending adView the -loadAd message.
// MyViewController.h
1
2
3
4
5
#import "MPAdView.h"

@interface MyViewController : UIViewController <MPAdViewDelegate>
@property (nonatomic) MPAdView *adView;
@end

// MyViewController.m
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#import "MyViewController.h"

@implementation MyViewController

- (void)viewDidLoad {
    // ... your other -viewDidLoad code ...

    self.adView = [[MPAdView alloc] initWithAdUnitId:@"<YOUR_ADUNIT_ID_HERE>"
                                                 size:MOPUB_BANNER_SIZE];
    self.adView.delegate = self;
    self.adView.frame = CGRectMake((self.view.bounds.size.width - MOPUB_BANNER_SIZE.width) / 2, 
                                  self.view.bounds.size.height - MOPUB_BANNER_SIZE.height,
                                  MOPUB_BANNER_SIZE.width, MOPUB_BANNER_SIZE.height);
    [self.view addSubview:self.adView];
    [self.adView loadAd];
    [super viewDidLoad];
}

#pragma mark - <MPAdViewDelegate>
- (UIViewController *)viewControllerForPresentingModalView {
    return self;
}

...
@end

Additional Delegate Callbacks: -
MPAdViewDelegate includes a variety of optional callbacks you can use to be notified of events, e.g. when an ad has successfully loaded, or when the ad is about to present or dismiss a modal view. Check out the MPAdViewDelegate protocol in MPAdview.h for a list of these methods.
1
2
 // Called when the banner has successfully retrieved an ad.
-adViewDidLoadAd:

Saturday 5 September 2015

HB Blog 93: Google Brillo - Operating System For Internet Of Things.

Project Brillo is an Android-based embedded operating system platform by Google. It is aimed to be used with low-power and memory constrained IoT devices. The Internet of Things (IoT, sometimes Internet of Everything) is the network of physical objects or "things" embedded with electronics, software, sensors, and connectivity to enable objects to exchange data with the manufacturer, operator and/or other connected devices based on the infrastructure of International Telecommunication Union's Global Standards Initiative. The Internet of Things allows objects to be sensed and controlled remotely across existing network infrastructure, creating opportunities for more direct integration between the physical world and computer-based systems, and resulting in improved efficiency, accuracy and economic benefit.
Project Brillo: -
Brillo extends the Android platform to all your connected devices, so they are easy to set up and work seamlessly with each other and your smartphone. Since, it is based on the lower levels of Android, you can choose from a wide range of hardware platforms and silicon vendors. Basically, hardware systems will controlled and communicate with each other such as door locks, heater & cooler systems, etc. in single language medium to communicate with each other. It supports Wi-Fi and Bluetooth Low Energy to connect to various, random objects in your home that allow Android connectivity.
OEM's will build devices quickly and securely, without having to worry about software updates. Just need to add a compatibility library to connect with Brillo devices over Weave. For developers it extends the reach of their apps to the physical world. They need app to control multiple devices in the home and work environments, leveraging Google services such as voice actions. Finally, all Brillo devices(hardware systems) will move ahead of different hardware barriers and will communicate with each other in single language medium known as Weaver. 
Weaver Language: -
Weave is a universal language that all devices that Project Brillo use. It provides seamless and secure communication between devices both locally and through the cloud. It’s integrated into Google Play services, so support is built-in to Android and also easily available for iOS. This program will drive interoperability and quality through a certification program that device makers must adhere to. As part of this program, It provides a core set of schemas that will enable apps and devices to seamlessly interact with each other. Weaver language will act as  a medium to communicate Brillo devices with phone and access data over cloud system.

Friday 4 September 2015

HB Blog 92: ProRAT - Remote Administration Tool.

ProRat is a Remote Administration Tool made by PRO Group. It was written in C programming language and its capable to work with all windows operating systems. It is made for remoting your own computers from other computers. It is a Microsoft Windows based backdoor trojan horse, more commonly known as a RAT (Remote Administration Tool). As with other trojan horses it uses a client and server. It opens a port on the computer which allows the client to perform numerous operations on the server (the machine being controlled).
Features of ProRAT:-
ProRat allows many malicious actions on the victim's machine. Some of its abilities include:
    Logging keystrokes
    Full control over files
    Drive formatting
    Open/close CD tray
    Hide taskbar, desktop, and start button
    Writing on-screen
    Movement of cursor
    Feed the cat
    Take screenshots
    View system information
    View webcam
    Download & run files
    Password Protect your bound server from being used by anyone else
It also has a server creator which features that allow it to be undetected by antivirus and firewall software, and also allow it to stealthily run in the background.

How to remotely control computers using ProRAT: -
  1. Download ProRat. Once it is downloaded right click on the folder and choose to extract it, antivirus will detect it as trojan but it is a false positive detection. Open up the program.
  2. Next create the actual Trojan file. Click on Create and choose Create ProRat Server.
  3. Next put in your IP address so the server could connect to you. If you don’t know your IP address click on the little arrow to have it filled in for you automatically. Next put in your e-mail so that when and if a victim gets infected it will send you a message.
  4. Click on the General Settings button to continue. Choose the server port the program will connect through, the password you will be asked to enter when the victim is infected and you wish to connect with them, and the victim name. You can see ProRat has the ability to disable the windows firewall and hide itself from being displayed in the task manager.
  5. Click on the Bind with File button to continue. Here you will have the option to bind the trojan server file with another file. Remember a trojan can only be executed if a human runs it. So by binding it with a legitimate file like a text document or a game, the chances of someone clicking it go up. Check the bind option and select a file to bind it to.
  6. Click on the Server Extensions button to continue. Choose what kind of server file togenerate. Mostly exe’s looks suspicious so it would be smart to change it. Click on Server Icon to continue. Here you will choose an icon for your server file to have. The icons help mask what the file actually is.
  7. Finally click on Create Server to, you guessed it, create the server file.
  8. Once the trojan runs on victims computer the attacker would then get a message telling him that victim was infected. He would then connect to computer by typing in my IP address, port and clicking Connect. He will be asked for the password that he made when he created the server. Once he types it in, he will be connected to victims computer and have full controlover it.
How to protect/secure computers from ProRAT:-
  1. First thing you need do is reboot the computer in Safe Mode with Networking to avoid Trojan Prorat from loading at start-up.
  2. Remove all media such as floppy drive, cd, dvd, and USB devices. Then, restart the computer.
  3. Once Windows is running under Safe Mode with Networking, open your antivirus program and download the most recent update. This method ensures that your antivirus program can detect even newer variants of Trojan Prorat.
  4. Once updating is finished, run a full system scan. After the scan, delete all infected items. If unable to clean or delete, better place the threat in quarantine.
  5. In future, try not to click or open unknown files or links.

Tuesday 1 September 2015

HB Blog 91: Android Studio's Attractive Features.

Android Studio is the official IDE for Android application development, based on IntelliJ IDEA.
Android Studio offers:
    Flexible Gradle-based build system
    Build variants and multiple apk file generation
    Code templates to help you build common app features
    Rich layout editor with support for drag and drop theme editing
    lint tools to catch performance, usability, version compatibility, and other problems
    ProGuard and app-signing capabilities
    Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and App Engine
    And much more.


Most attractive features of android studio from a developer perspective are as follows:-

1)Android Studio allows you to work with layouts in both a Design View. Easily select and preview layout changes for different device images, display densities, UI modes, locales, and Android versions (multi-API version rendering).
From the Design View, you can drag and drop elements from the Palette to the Preview or Component Tree. The Text View allows you to directly edit the XML settings, while previewing the device display.
It updates preview of the layout xml while creating UI which provides read–eval–print loop (REPL) kind of features.

2)Android Studio provides a memory and CPU monitor view so you can more easily monitor your app's performance and memory usage to track CPU usage, find deallocated objects, locate memory leaks, and track the amount of memory the connected device is using. With your app running on a device or emulator, click the Android tab in the lower left corner of the runtime window to launch the Android runtime window. Click the Memory or CPU tab.
When you're monitoring memory usage in Android Studio you can, at the same time, initiate garbage collection and dump the Java heap to a heap snapshot in an Android-specific HPROF binary format file. The HPROF viewer displays classes, instances of each class, and a reference tree to help you track memory usage and find memory leaks.
Android Studio allows you to track memory allocation as it monitors memory use. Tracking memory allocation allows you to monitor where objects are being allocated when you perform certain actions. Knowing these allocations enables you to adjust the method calls related to those actions to optimize your app's performance and memory use.

3)Android Studio projects contain a top-level build file and a build file for each module. The build files are called build.gradle, and they are plain text files that use Groovy syntax to configure the build with the elements provided by the Android plugin for Gradle. In most cases, you only need to edit the build files at the module level. For example, the build file for the app module in the BuildSystemExample project looks like this:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(":lib")
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

 4)The build system can help you create different versions of the same application from a single project. This is useful when you have a demo version and a paid version of your app, or if you want to distribute multiple APKs for different device configurations on Google Play.
The build system uses product flavors to create different product versions of your app. Each product version of your app can have different features or device requirements. The build system also uses build types to apply different build and packaging settings to each product version. Each product flavor and build type combination forms a build variant. The build system generates a different APK for each build variant of your app.
To define two product flavors, edit the build file for the app module to add the following configuration:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
...
android {
    ...
    defaultConfig { ... }
    signingConfigs { ... }
    buildTypes { ... }
    productFlavors {
        demo {
            applicationId "com.buildsystemexample.app.demo"
            versionName "1.0-demo"
        }
        full {
            applicationId "com.buildsystemexample.app.full"
            versionName "1.0-full"
        }
    }
}
...
The product flavor definitions support the same properties as the defaultConfig element. The base configuration for all flavors is specified in defaultConfig, and each flavor overrides any default values. The build file above uses the applicationId property to assign a different package name to each flavor: since each flavor definition creates a different app, they each need a distinct package name.

5)With smart rendering, Android Studio displays links for quick fixes to rendering errors. For example, if you add a button to the layout without specifying the width and height attributes, Android Studio displays the rendering message Automatically add all missing attributes. Clicking the message adds the missing attributes to the layout.
While debugging, you can now right-click on bitmap variables in your app and invoke View Bitmap. This fetches the associated data from the debugged process and renders the bitmap in the debugger.
When referencing images and icons in your code, a preview of the image or icon appears (in actual size at different densities) in the code margin to help you verify the image or icon reference. Pressing F1 with the preview image or icon selected displays resource asset details, such as the dp settings.