1+ package org .csploit .android ;
2+
3+ import android .annotation .SuppressLint ;
4+ import android .content .Context ;
5+ import android .content .Intent ;
6+ import android .content .SharedPreferences ;
7+ import android .os .Bundle ;
8+ import android .support .annotation .Nullable ;
9+ import android .support .v4 .app .Fragment ;
10+ import android .support .v4 .content .ContextCompat ;
11+ import android .support .v7 .app .AppCompatActivity ;
12+ import android .view .LayoutInflater ;
13+ import android .view .MenuItem ;
14+ import android .view .View ;
15+ import android .view .ViewGroup ;
16+ import android .widget .AdapterView ;
17+ import android .widget .ArrayAdapter ;
18+ import android .widget .ImageView ;
19+ import android .widget .ListView ;
20+ import android .widget .TextView ;
21+ import android .widget .Toast ;
22+
23+ import org .csploit .android .core .Plugin ;
24+ import org .csploit .android .core .System ;
25+ import org .csploit .android .gui .dialogs .FinishDialog ;
26+ import org .csploit .android .net .Target ;
27+
28+ import java .util .ArrayList ;
29+
30+ public class ActionFragment extends Fragment {
31+
32+ private ArrayList <Plugin > mAvailable = null ;
33+ private ListView theList ;
34+ private Target mTarget ;
35+
36+
37+ @ Nullable
38+ @ Override
39+ public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
40+ super .onCreate (savedInstanceState );
41+ setHasOptionsMenu (true );
42+ return inflater .inflate (R .layout .actions_layout , container , false );
43+ }
44+
45+ @ Override
46+ public void onViewCreated (View v , Bundle savedInstanceState ) {
47+ SharedPreferences themePrefs = getActivity ().getSharedPreferences ("THEME" , 0 );
48+ Boolean isDark = themePrefs .getBoolean ("isDark" , false );
49+ if (isDark ) {
50+ getActivity ().setTheme (R .style .DarkTheme );
51+ v .setBackgroundColor (ContextCompat .getColor (getActivity (), R .color .background_window_dark ));
52+ }
53+ else {
54+ getActivity ().setTheme (R .style .AppTheme );
55+ v .setBackgroundColor (ContextCompat .getColor (getActivity (), R .color .background_window ));
56+ }
57+ mTarget = org .csploit .android .core .System .getCurrentTarget ();
58+
59+ if (mTarget != null ) {
60+ getActivity ().setTitle ("cSploit > " + mTarget );
61+ ((AppCompatActivity ) getActivity ()).getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
62+ theList = (ListView ) getActivity ().findViewById (R .id .android_list );
63+ mAvailable = System .getPluginsForTarget ();
64+ ActionsAdapter mActionsAdapter = new ActionsAdapter ();
65+ theList .setAdapter (mActionsAdapter );
66+ theList .setOnItemClickListener (new ListView .OnItemClickListener () {
67+ @ Override
68+ public void onItemClick (AdapterView <?> parent , View view , int position , long id ) {
69+
70+ if (System .checkNetworking (getActivity ())) {
71+ Plugin plugin = mAvailable .get (position );
72+ System .setCurrentPlugin (plugin );
73+
74+ if (plugin .hasLayoutToShow ()) {
75+ Toast .makeText (getActivity (), getString (R .string .selected ) + getString (plugin .getName ()), Toast .LENGTH_SHORT ).show ();
76+
77+ startActivity (new Intent (
78+ getActivity (),
79+ plugin .getClass ()
80+ ));
81+ getActivity ().overridePendingTransition (R .anim .fadeout , R .anim .fadein );
82+ } else
83+ plugin .onActionClick (getActivity ().getApplicationContext ());
84+ }
85+ }
86+ });
87+ } else {
88+ new FinishDialog (getString (R .string .warning ), getString (R .string .something_went_wrong ), getActivity ()).show ();
89+ }
90+ }
91+
92+
93+ @ Override
94+ public boolean onOptionsItemSelected (MenuItem item ) {
95+ switch (item .getItemId ()) {
96+ case android .R .id .home :
97+
98+ getActivity ().onBackPressed ();
99+
100+ return true ;
101+
102+ default :
103+ return super .onOptionsItemSelected (item );
104+ }
105+ }
106+
107+ public void onBackPressed () {
108+ getActivity ().finish ();
109+ getActivity ().overridePendingTransition (R .anim .fadeout , R .anim .fadein );
110+ }
111+
112+ public class ActionsAdapter extends ArrayAdapter <Plugin > {
113+ public ActionsAdapter () {
114+ super (getActivity (), R .layout .actions_list_item , mAvailable );
115+ }
116+
117+ @ SuppressLint ("NewApi" )
118+ @ Override
119+ public View getView (int position , View convertView , ViewGroup parent ) {
120+ View row = convertView ;
121+ ActionHolder holder ;
122+
123+ if (row == null ) {
124+ LayoutInflater inflater = (LayoutInflater ) getActivity ().getSystemService (Context .LAYOUT_INFLATER_SERVICE );
125+ row = inflater .inflate (R .layout .actions_list_item , parent , false );
126+ if (getActivity ().getSharedPreferences ("THEME" , 0 ).getBoolean ("isDark" , false ))
127+ row .setBackgroundResource (R .drawable .card_background_dark );
128+ holder = new ActionHolder ();
129+
130+ holder .icon = (ImageView ) (row != null ? row .findViewById (R .id .actionIcon ) : null );
131+ holder .name = (TextView ) (row != null ? row .findViewById (R .id .actionName ) : null );
132+ holder .description = (TextView ) (row != null ? row .findViewById (R .id .actionDescription ) : null );
133+ if (row != null ) row .setTag (holder );
134+
135+ } else holder = (ActionHolder ) row .getTag ();
136+
137+ Plugin action = mAvailable .get (position );
138+
139+ holder .icon .setImageResource (action .getIconResourceId ());
140+ holder .name .setText (getString (action .getName ()));
141+ holder .description .setText (getString (action .getDescription ()));
142+
143+ return row ;
144+ }
145+
146+ public class ActionHolder {
147+ ImageView icon ;
148+ TextView name ;
149+ TextView description ;
150+ }
151+ }
152+
153+ }
0 commit comments