Giter Site home page Giter Site logo

weiju2's Introduction

WeiJu2

The first scriptable xposed module, provides a new way to change the application behavior.

Powered by Lua and made with โ™ฅ

Features

  • Lua scripting
  • Simple and intuitive hook API
  • AI assistant
  • Share your package with others by publish it at WeiJu2-Scripts

Q&A

How to write a hook?

-- You can import any java class
local Toast = import("android.widget.Toast")
local Activity = import("android.app.Activity")
local Bundle = import("android.os.Bundle")
local StringBuilder = import("java.lang.StringBuilder")

-- Hook a method
hook {
  class = Activity,
  returns = void,
  method = "onCreate",
  params = {
    Bundle
  },
  after = function(this, params)
    -- This will call the `StringBuilder(CharSequence seq)` constructor
    -- to instantiate a StringBuilder object
    local sb = StringBuilder("Hello, ")
    sb:append("WeiJu2")
  
    Toast:makeText(this, sb:toString(), Toast.LENGTH_SHORT):show()
    --              ^
    -- Note: `this` is the Activity instance
  end,
}

-- Hook a constructor
local View = import("android.view.View")
local Context = import("android.content.Context")
local AttributeSet = import("android.util.AttributeSet")

hook {
  class = View,
  params = {
    Context,
    AttributeSet,
    int
  },
  after = function(this, params)
  
  end,
}

How to modify class fields?

-- With the `import` function you can bind any java class, and access all the fields and methods that defined
-- in that class. No more `XposedHelper.setStaticObjectField(Build.class, "DEVICE", "coral")` much cleaner!
local Build = import("android.os.Build")

Build.DEVICE = "coral"
Build.PRODUCT = "coral"
Build.MODEL = "Google Pixel 4XL"
Build.BRAND = "google"
Build.MANUFACTURER = "google"
Build.VERSION.RELEASE = "13"

How to import a package?

require("ikws4.system_variable").setup {
  -- config goes here
}

How to create a package?

A basic package template:

--[=[ 
@metadata
  return {
    name = "your_package",
    author = "you",
    version = "1.0.0",
    description = "Describle your package",
    example = [[
      -- you can provide an example here for others to reference
    ]]
  }
@end
--]=]

local config = {
}

local M = {}

M.setup = function(opts)
  config = table.extend(config, opts or {})
  
  -- write hook here
end

return M

How to get the result in after hook?

hook {
  class = String,
  returns = char,
  method = "charAt",
  params = {
    int
  },
  after = function(this, params, ret)
    print("return value: " .. ret)
    -- make it always return 'a'
    return string.byte("a")
  end
}

Want to share your work with others? Create a PR at WeiJu2-Scripts.

API

import

--- Examples:
---   local StringBuilder = import("java.lang.StringBuilder")
---   local my_string_builder = StringBuilder("hi")
---   print(my_string_builder:toString())
---
--- @param class_name string
--- @return Class
function import(class_name) end

object

--- Examples:
---   local Runnable = import("java.lang.Runnable")
---   local my_runnable = object(Runnable, {
---     run = function(this)
---     
---     end
---   })
---   my_runnable:run()
---
--- @param class Class
--- @param proxy table<string, function>
--- @return Class
function object(class, proxy) end

hook

--- Exampels:
---   local View = import("android.view.View")
---   local Context = import("android.content.Context")
---   local AttributeSet = import("android.util.AttributeSet")
---
---   hook {
---     class = View,
---     params = {
---       Context,
---       AttributeSet,
---       int
---     },
---     after = function(this, params)
---       -- Add your own logic after constructor is called
---        
---     end
---   }
---
---   local Canvas = import("android.graphics.Canvas")
---
---   hook {
---     class = View,
---     returns = void,
---     method = "onDraw",
---     params = {
---       Canvas
---     },
---     after = function(this, params)
---       local canvas = params[1]
---       -- Using canvas to draw anything you want
---     
---     end
---   }
---
--- @param config table This table accepts the following keys
---                     - class: (Class) The hook target.
---                     - returns: (nil|Class) The method return type.
---                     - method: (string) The method name.
---                     - params: (nil|table) The method argument types, can be nil if there is no argument.
---                     - before: (nil|function) Executed before the method is called.
---                     - after: (nil|function) Executed after the method is called.
---                     - replace: (nil|function) A simple version of `before`, use to rewrite the whole method.
--- @return Unhook
function hook(config) end

Auto imported common java types

These types are common used in scripts, therefore we auto imported them for you, View Source.

byte
short
int
long
float
double
char
boolean
void

String
List

Screenshots

weiju2's People

Contributors

ikws4 avatar vd171 avatar xerta555 avatar orstudio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.