package zzz.ksoft.smscopier;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity{
/** Called when the activity is first created. */
public boolean auth = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView buyeremail, buyernumber;
setContentView(R.layout.main);
buyeremail = (TextView)findViewById(R.id.buyeremail);
buyernumber = (TextView) findViewById(R.id.receiverphonenumber) ;
TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
final String phoneNumber = manager.getLine1Number();
AccountManager mgr = AccountManager.get(this);
Account[] accts = mgr.getAccounts();
final int count = accts.length;
Account acct = null;
String tmpStr = "";
String tmpnumberstr=phoneNumber;
for(int i=0;i<count;i++) {
acct = accts[i];
// Toast.makeText(this, "eclair account - name="+acct.name+", type="+acct.type, Toast.LENGTH_LONG).show();
Log.d("ACCT", "eclair account - name="+acct.name+", type="+acct.type);
// txt.setText("acct.name : " + acct.name + ", acct.type : " + acct.type);
if(acct.type.equals ("com.google")){
tmpStr += "구글 계정 "+i+":" + acct.name + ", acct.type : " + acct.type + "\n";
}
}
buyernumber.setText(tmpnumberstr);
buyeremail.setText(tmpStr);
final String buyeremailstr;
final String buyernumberstr;
String buyerauthstr;
byte[] buyeremailbyte;
byte[] buyernumberbyte;
byte[] buyerauthbyte;
final String buyerauthmd5;
final String receivedauthcode;
buyernumberstr = buyernumber.getText().toString();
buyeremailstr = buyeremail.getText().toString();
buyerauthstr = buyeremail+buyernumberstr;
buyerauthmd5 =MD5.MD5(buyeremailstr+buyernumberstr);
Button authmake=(Button) findViewById(R.id.button1);
final EditText receivedauth = (EditText) this.findViewById(R.id.hashcode);
receivedauthcode=receivedauth.getText().toString();
authmake.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String str[] = {
buyeremailstr,
buyernumberstr,
receivedauthcode
};
if(buyerauthmd5 == receivedauthcode){
for(int i = 0; i<2;i++){
String nLine= "\n";
File outputFile = new File("/sdcard/kdy/auth/keylog.txt");
FileOutputStream outStream;
try {
outStream = new FileOutputStream(outputFile);
outStream.write(str[i] .getBytes(),0,str[i] .length());
outStream.write(nLine.getBytes(),0,nLine.length());
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else{
}
}
});
}
public static class MD5 {
public static String MD5(String md5hash) {
byte[] bpara = new byte[md5hash.length()];
byte[] rethash;
int i;
for (i=0; i < md5hash.length(); i++)
bpara[i] = (byte)(md5hash.charAt(i) & 0xff );
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
rethash = md5.digest(bpara);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
}
StringBuffer r = new StringBuffer(32);
for (i=0; i < rethash.length; i++) {
String x = Integer.toHexString(rethash[i] & 0xff).toUpperCase();
if (x.length()<2)
r.append("0");
r.append(x);
}
return r.toString();
}
}
}
왜 아무 반응이 없을까여;;;;ㅠㅠ