這裏開發使用的Android studio,使用的模擬器爲:
Pixel 2 API 22也就是Android 5的系統。
這裏演示下開發的程序:
這裏模擬了下激活程序,用戶名是用戶自己輸入的,密碼是用戶名轉md5後所有奇數項。也就是說123456789的密碼爲:323b453885f5181f的奇數項。
關鍵代碼如下:
package com.example.crakdemo1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText eidt_userName = (EditText)findViewById(R.id.userName);
final EditText eidt_sn = (EditText)findViewById(R.id.password);
Button btn_register = (Button)findViewById(R.id.button);
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!checkSN(eidt_userName.getText().toString().trim(), eidt_sn.getText().toString().trim())){
Toast.makeText(MainActivity.this, R.string.unsuccessed, Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this, R.string.successed, Toast.LENGTH_SHORT).show();
}
}
});
}
public static String bytesToHex(byte[] bytes) {
StringBuilder buf = new StringBuilder(bytes.length * 2);
for(byte b : bytes) { // 使用String的format方法進行轉換
buf.append(String.format("%02x", new Integer(b & 0xff)));
}
return buf.toString();
}
private boolean checkSN(String userName, String sn){
try {
if((userName == null) || (userName.length() == 0)){
return false;
}
if((sn == null)){
return false;
}
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.reset();
digest.update(userName.getBytes());
byte[] bytes = digest.digest();
String hexStr = bytesToHex(bytes);
StringBuffer sb = new StringBuffer();
for(int i = 0; i < hexStr.length(); i+=2){
sb.append(hexStr.charAt(i));
}
String userSN = sb.toString();
if(!userSN.equalsIgnoreCase(sn)){
return false;
}
}
catch (NoSuchAlgorithmException e){
e.printStackTrace();
return false;
}
return true;
}
}
上面這個程序源碼打包下載地址:
https://github.com/fengfanchen/AndroidReverse/tree/master/CrakDemo1
先說一個工具:
ApkTool是跨平臺apk文件反編譯工具,生成smali格式的反彙編代碼。
下面是破解自己寫的程序,首先是要使用Android studio進行apk的生成:
在app下的build的outputs中apk中debug會有打包好的app,將這個拿到,然後新建文件夾,將其放進去:
運行命令:
apktool d ./app-debug.apk -o outdir
這裏我使用了notepad++進行查找:
從中可以看到開發時候彈出的失敗對應的英文名稱爲unsuccessed,再繼續查這個!!
其中對應的地址爲:
0x7f0c001f,再繼續查這個!!
從上面的文件可以看到已經定位到ManActivity$1.smali文件了。從中可以看到這樣的代碼:
當個if-nez v0, : cond_0。
這裏在cond_0中0x7f0c001e對應的是成功,所以關鍵點就是這裏了。if-nez爲if-not-equal-zero則調到cond_0,所以將其改爲if-eqz
下面是從新編譯APK並簽名
回編譯:
apktool b outdir
將其考到signapk文件夾中,進行簽名
上面這個signapk.jar.zip可以在Android系統中找,也可以在網上去下載。我是在網上下載的。配置好環境變量,開始重新簽名:
signapk app-debug.apk app.apk
使用adb進行安裝:
adb install app.apk
這樣再次進入就是破解版的了!!