All Projects → LianjiaTech → Beike_AspectD

LianjiaTech / Beike_AspectD

Licence: MIT License
Flutter AOP framework.(Flutter面向切面库, 最新适配Flutter v2.5.3, null-safety)

Programming Languages

dart
5743 projects
TeX
3793 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects
python
139335 projects - #7 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Beike AspectD

Stinger
Stinger is a high-efficiency library with great compatibility, for aop in Objective-C, using libffi instead of Objective-C message forwarding. It is 20+ times faster than the Aspects, from message-sending to Aspect-oriented code ends.
Stars: ✭ 845 (+2066.67%)
Mutual labels:  hook, aop
Swifthook
A library to hook methods in Swift and Objective-C.
Stars: ✭ 93 (+138.46%)
Mutual labels:  hook, aop
Epic
Dynamic java method AOP hook for Android(continution of Dexposed on ART), Supporting 5.0~11
Stars: ✭ 3,434 (+8705.13%)
Mutual labels:  hook, aop
AspecTS
An aspect-oriented programming library implemented in TypeScript
Stars: ✭ 21 (-46.15%)
Mutual labels:  aspect, aop
Norns
dotnet core aop static weaving on roslyn
Stars: ✭ 23 (-41.03%)
Mutual labels:  aspect, aop
Virtualxposed
A simple app to use Xposed without root, unlock the bootloader or modify system image, etc.
Stars: ✭ 12,648 (+32330.77%)
Mutual labels:  hook, aop
Sandhook
Android ART Hook/Native Inline Hook/Single Instruction Hook - support 4.4 - 11.0 32/64 bit - Xposed API Compat
Stars: ✭ 1,172 (+2905.13%)
Mutual labels:  hook, aop
Cauldron
C# Toolkit
Stars: ✭ 68 (+74.36%)
Mutual labels:  aspect, aop
Pine
Dynamic java method hook framework on ART.
Stars: ✭ 171 (+338.46%)
Mutual labels:  hook, aop
Easyrouter
A simple android framework used to route activity or action with url.
Stars: ✭ 164 (+320.51%)
Mutual labels:  hook, aop
NCop
Composite-aspect oriented framework for .NET
Stars: ✭ 30 (-23.08%)
Mutual labels:  aspect, aop
aspectgo
Aspect-Oriented Programming framework for Go
Stars: ✭ 62 (+58.97%)
Mutual labels:  hook, aop
react-hook-layout
Layouts in React.
Stars: ✭ 16 (-58.97%)
Mutual labels:  hook
OTE-MTL
Code and dataset for Findings of EMNLP 2020 paper titled "A Multi-task Learning Framework for Opinion Triplet Extraction"
Stars: ✭ 32 (-17.95%)
Mutual labels:  aspect
SunnyBeach
阳光沙滩APP
Stars: ✭ 60 (+53.85%)
Mutual labels:  aop
entangle
Global state management tool for react hooks inspired by RecoilJS and Jotai using proxies.
Stars: ✭ 26 (-33.33%)
Mutual labels:  hook
redux-tools
Redux tools to speed up development.
Stars: ✭ 16 (-58.97%)
Mutual labels:  hook
conventional-commits
A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook plugin!
Stars: ✭ 128 (+228.21%)
Mutual labels:  hook
sudohulk
try privilege escalation changing sudo command
Stars: ✭ 114 (+192.31%)
Mutual labels:  hook
transition-hook
☄️ An extremely light-weight react transition animation hook which is simpler and easier to use than react-transition-group
Stars: ✭ 250 (+541.03%)
Mutual labels:  hook

Language: English | 中文简体

Beike_AspectD

This is a fork of AspectD.

Beike_AspectD is an aop framework for dart. AspectD has provide developers call/execute/inject grammer to manipulate the dart code. Besides that, Beike_AspectD also provides

  • Support add grammer to add function to classes.
  • Support field get grammer to exchange the field get call.
  • Support null-safety(null-safety/2.5.3 branch).
  • Support flutter web.

What can we use Beike_AspectD for?

Beike has used Beike_AspectD in many packages.

  • Event tracking.
  • Json to model.
  • Performance monitoring.
  • Flutter framework bug fixing.

Installation

1. Apply flutter_tools.patch.

cd ...path/to/flutter/packages/flutter_tools/
git apply --3way path-for-beike_aspectd-package/inner/flutter_tools.patch
rm ../../bin/cache/flutter_tools.stamp

Next time when you build your project, flutter tools will build automatically.

2. Add Beike_AspectD to your yaml.

dependencies:
   beike_aspectd:
     git:
         url: https://github.com/LianjiaTech/Beike_AspectD.git
         ref: 2.5.3

3. Add aop_config.yaml to your flutter project.

Add a file named aop_config.yaml to your flutter project's root directory(the same directory as pubspec.yaml).

You can copy the file from the example of Beike_AspectD. The content of the file are as follow

flutter_tools_hook:
  - project_name: 'beike_aspectd'
    exec_path: 'bin/starter.snapshot'

Flutter_tools will check the file to find if Beike_AspectD is enabled. And it will get the starter.snapshot to process the dill file.

4. Write your hook file and import the file.

hook_example.dart(aop implementation)

import 'package:beike_aspectd/aspectd.dart';

@Aspect()
@pragma("vm:entry-point")
class CallDemo {
  @pragma("vm:entry-point")
  CallDemo();

 //实例方法
 @Call("package:example/main.dart", "_MyHomePageState",
     "-_incrementCounter")
 @pragma("vm:entry-point")
 void _incrementCounter4(PointCut pointcut) {
   print('call instance method2!');
   pointcut.proceed();
 }
}

As hook_example.dart is not used in your project, we should import it in the project, or it will be tree shaked while compiling.

For example, we can import the file in main.dart.

// ignore: unused_import
import 'package:example/hook_example.dart';

Tutorial

In addition to the 3 ways(call/execute/inject) to do AOP programming AspectD provide us, Beike_AspectD also provide add/field get manipulation.

add

Add a method to a class, support class name regex, support super class filter.

  @Add("package:.+\\.dart", ".*", isRegex: true)
  @pragma("vm:entry-point")
  dynamic getBasicInfo(PointCut pointCut) {
    return pointCut?.sourceInfos ?? {};
  }

Code above add getBasicInfo() method to all the classes, you can use your own regex and superCls parameter to filter classes. We can call the function using the following code.

    dynamic self = someinstance;
    Map info = self.getBasicInfo(PointCut.pointCut());

field get

Every callsites of the a field will be manipulated.

 @pragma("vm:entry-point")
 @FieldGet('package:example/main.dart', 'MyApp', 'field', false)
 static String exchange2(PointCut pointCut) {
    return 'Beike_Aspectd';
}

Suppose MyApp class has a property called field, by using the the above code, when calling the property field, it will always return string 'Beike_Aspectd'.

Compatibility

Currently Beike_Aspectd support flutter 1.22.4 , 2.2.2 and 2.5.3.

Q&A

  • How to know if my code is hooked successfully?
    1. First you need to download the dart-sdk and checkout to the corresponding revision of flutter. The revision of dart can be found at path_to_flutter/bin/cache/dart-sdk/revision.
    2. Run the following command.
    path_to_flutter/bin/cache/dart-sdk/bin/dart  path_to_dart/pkg/vm/bin/dump_kernel.dart path_to_your_project/.dart_tool/flutter_build/***/app.dill output_path/out.dill.txt
    1. Open output_path/out.dill.txt file, check if your code is hook.

Contact

If you have any question, please feel free to file a issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].