Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to add new instruction with dexlib2?

Featured Replies

Posted

I try to add new instruction,

// old

const/v4 v?, 0x0

// new

const/v4 v?, 0x0
const-string v?, "Hello" // new instruction

can someone help me, adding instruction without duplicate register number?

  • Author

@CodeExplorer

I try with this code:

private static MethodImplementation addNewInstructions(@Nonnull MethodImplementation implementation) {

		MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);

		List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
		
		for (int i = 0; i < instructions.size(); i++) {
			
			Instruction instruction = instructions.get(i);
			
			if (instruction instanceof ReferenceInstruction) {

				if (((ReferenceInstruction) instruction).getReferenceType() == ReferenceType.METHOD) {

					Opcode opcode = instruction.getOpcode();

					if (!opcode.name.endsWith("range")) {
						mutableImplementation.addInstruction(i++, new BuilderInstruction21c(Opcode.CONST_STRING,
								0, new ImmutableStringReference("Hello World"))); // look
					}
				}
			}
		}

		return mutableImplementation;
	}

after :

// before

.line 54
iget-object v0, p0, Lapp/test/MainActivity;->ed:Landroid/widget/TextView;


// after

.line 54
iget-object v0, p0, Lapp/test/MainActivity;->ed:Landroid/widget/TextView; // v0 already register

const-string v0, "Hello World" // v0 duplicate register

If i storing a new value in it, I'll be clobbering any value that was already there, and later code that expects the previous value will likely fail.

Edited by Modify

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.