{"size": 2450, "ext": "js", "max_stars_repo_path": "frida-scripts/keyguard-credential-intent.js", "max_stars_repo_name": "FrenchYeti/android-keystore-audit", "max_stars_repo_stars_event_min_datetime": "2019-09-25T13:57:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T11:27:46.000Z", "max_issues_repo_path": "frida-scripts/keyguard-credential-intent.js", "max_issues_repo_name": "mwrlabs/android-keystore-audit", "max_issues_repo_issues_event_min_datetime": "2019-10-24T08:36:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T18:15:38.000Z", "max_forks_repo_path": "frida-scripts/keyguard-credential-intent.js", "max_forks_repo_name": "mwrlabs/android-keystore-audit", "max_forks_repo_forks_event_min_datetime": "2019-09-25T09:17:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T03:12:44.000Z"}
{"max_stars_count": 145, "max_issues_count": 8, "max_forks_count": 46, "avg_line_length": 33.1081081081, "max_line_length": 111, "alphanum_fraction": 0.6342857143}
/*
	KeyGuard script which can send a 'createConfirmDeviceCredentialIntent' for invoking a device unlock screen
	Can be used to manually unlock keys which do not have a setUserAuthenticationValidityDurationSeconds set to -1
*/

console.log("Keyguard Script Loaded");
var activitiesList = [];

Java.perform(function () {
    	var activityCls = Java.use("android.app.Activity");
    	activityCls['onCreate'].overload('android.os.Bundle').implementation = function(a1) {
    	activitiesList.push(this);
    	console.log("Acitivity: "+ this);
        return this.onCreate(a1);
    }   
	
});

function showKeyguard()
{
	Java.perform(function () {
		var ActivityThread = Java.use("android.app.ActivityThread");
		var application = ActivityThread.currentApplication().getApplicationContext();
		var REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 1;
		var KEYGUARD_SERVICE = "keyguard";
		var mKeyguardManagerCls = Java.use("android.app.KeyguardManager");
		var mKeyguardManager = application.getSystemService(KEYGUARD_SERVICE)
		var intent = mKeyguardManagerCls['createConfirmDeviceCredentialIntent'].call(mKeyguardManager,null, null);
		console.log("HERE " + activitiesList[0]);
		activitiesList[0].startActivityForResult(null,intent,REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS,null);
	});
}

/*
* List Activity instances collected in activitiesList   
*/
function ListActivities()
{
    Java.perform(function () {
        for(i=0; i < activitiesList.length; i++)
        {
            console.log( "["+i+"] "+activitiesList[i]);
        } 
    });
    return "[done]";
}

function back(idx)
{
	Java.perform(function () {
		console.log("HERE " + activitiesList[idx]);

			var Runnable = Java.use('java.lang.Runnable');
        	var Runner = Java.registerClass({
                name: 'com.MWR.Runner',
                implements: [Runnable],
                methods: {
                    run: function () 
                        {
                        	activityCls = Java.use("android.app.Activity");
                        	activityCls['onBackPressed'].call(activitiesList[idx]);
							//activitiesList[idx].this$0.value.onBackPressed();
                        }
                }
            });

            var Handler = Java.use('android.os.Handler');
            var Looper = Java.use('android.os.Looper'); 
            var loop = Looper.getMainLooper();
            var handler = Handler.$new(loop);
            handler.post(Runner.$new());		
	});
}
