Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2025-05-15 - State Feedback for Native Library Loading
**Learning:** For actions that change the global state of the application (like loading a native library or initializing a hook), providing only a Toast is insufficient because the button remains interactive, which can lead to confusion or redundant calls.
**Action:** Disable the triggering button and update its text (e.g., from "load lib.so" to "lib.so loaded") immediately upon success to provide persistent, clear state feedback and prevent redundant interactions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.bytedance.shadowhook.ShadowHook;
import com.bytedance.shadowhook.systest.SysTest;
Expand All @@ -50,37 +52,49 @@ protected void onCreate(Bundle savedInstanceState) {

public void onUnitTestHookSymAddrClick(View view) {
NativeHandler.nativeHookSymAddr(Build.VERSION.SDK_INT);
Toast.makeText(this, "Hook by symbol address", Toast.LENGTH_SHORT).show();
}

public void onUnitTestHookSymNameClick(View view) {
NativeHandler.nativeHookSymName(Build.VERSION.SDK_INT);
Toast.makeText(this, "Hook by symbol name", Toast.LENGTH_SHORT).show();
}

public void onUnitTestUnhookClick(View view) {
NativeHandler.nativeUnhook();
Toast.makeText(this, "Unhook", Toast.LENGTH_SHORT).show();
}

public void onUnitTestLoadClick(View view) {
if(!hookee2Loaded) {
hookee2Loaded = true;
System.loadLibrary("hookee2");
if (view instanceof Button) {
((Button) view).setEnabled(false);
((Button) view).setText("libhookee2.so loaded");
}
Toast.makeText(this, "libhookee2.so loaded", Toast.LENGTH_SHORT).show();
}
}

public void onUnitTestRunClick(View view) {
NativeHandler.nativeRun(hookee2Loaded);
Toast.makeText(this, "Unit test run", Toast.LENGTH_SHORT).show();
}

public void onSystemTestHookClick(View view) {
SysTest.hook();
Toast.makeText(this, "System test hook", Toast.LENGTH_SHORT).show();
}

public void onSystemTestUnhookClick(View view) {
SysTest.unhook();
Toast.makeText(this, "System test unhook", Toast.LENGTH_SHORT).show();
}

public void onSystemTestRunClick(View view) {
SysTest.run();
Toast.makeText(this, "System test run", Toast.LENGTH_SHORT).show();
}

public void onGetRecordsClick(View view) {
Expand All @@ -90,12 +104,14 @@ public void onGetRecordsClick(View view) {
for (String line : records.split("\n")) {
Log.i(tag, line);
}
Toast.makeText(this, "Records printed to logcat", Toast.LENGTH_SHORT).show();
}
}

public void onDumpRecordsClick(View view) {
String pathname = getApplicationContext().getFilesDir() + "/shadowhook_records.txt";
NativeHandler.nativeDumpRecords(pathname);
Toast.makeText(this, "Records dumped to " + pathname, Toast.LENGTH_LONG).show();

BufferedReader br = null;
try {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:padding="16dp">

<TextView style="@style/Theme.TextView.Top"
android:text="adb logcat -b main -s shadowhook_tag" />
Expand Down