@@ -9,6 +9,12 @@ import * as excludeModule from './page/exclude.js';
99export const modDir = '/data/adb/modules/KPatch-Next' ;
1010export const persistDir = '/data/adb/kp-next' ;
1111
12+ const rehookMode = [
13+ "disable" , // 0
14+ "target" , // 1
15+ "minimal" // 2
16+ ]
17+
1218export let superkey = localStorage . getItem ( 'kp-next_superkey' ) || '' ;
1319export let MAX_CHUNK_SIZE = 96 * 1024 ;
1420
@@ -23,6 +29,7 @@ async function updateStatus() {
2329 notInstalled . classList . add ( 'hidden' ) ;
2430 working . classList . remove ( 'hidden' ) ;
2531 kpmModule . refreshKpmList ( ) ;
32+ initRehook ( ) ;
2633 document . querySelector ( '#superkey md-outlined-text-field' ) . value = superkey ;
2734 installedOnly . forEach ( el => el . removeAttribute ( 'hidden' ) ) ;
2835 } else {
@@ -90,6 +97,49 @@ async function reboot(reason = "") {
9097 exec ( `/system/bin/svc power reboot ${ reason } || /system/bin/reboot ${ reason } ` ) ;
9198}
9299
100+ async function initRehook ( ) {
101+ const rehook = document . getElementById ( 'rehook' ) ;
102+ const rehookMenu = rehook . querySelector ( 'md-menu' ) ;
103+ const mode = await updateRehookStatus ( ) ;
104+ if ( mode ) rehook . onclick = ( ) => rehookMenu . open = ! rehookMenu . open ;
105+ rehookMenu . querySelectorAll ( 'md-menu-item' ) . forEach ( ( item , index ) => {
106+ item . onclick = ( ) => {
107+ setRehookMode ( index ) ;
108+ rehook . click ( ) ;
109+ }
110+ } ) ;
111+ }
112+
113+ async function updateRehookStatus ( ) {
114+ const rehook = document . getElementById ( 'rehook' ) ;
115+ const rehookText = rehook . querySelector ( '.menu-text' ) ;
116+ const rehookRipple = rehook . querySelector ( 'md-ripple' ) ;
117+
118+ let modeName = 'target' , modeId = null ;
119+
120+ const result = await exec ( `kpatch ${ escapeShell ( superkey ) } rehook_status` , { env : { PATH : `${ modDir } /bin` } } ) ;
121+ const mode = result . stdout . split ( '\n' ) . find ( line => line . includes ( 'mode: ' ) ) ;
122+ if ( mode ) {
123+ modeId = parseInt ( mode . split ( ':' ) [ 1 ] . trim ( ) ) ;
124+ modeName = rehookMode [ modeId ] ;
125+ }
126+ rehookText . textContent = getString ( 'label_rehook_mode_' + modeName ) ;
127+ rehookText . classList . toggle ( 'disabled' , ! mode ) ;
128+ rehookRipple . disabled = ! mode ;
129+
130+ return modeId !== null ;
131+ }
132+
133+ function setRehookMode ( mode ) {
134+ exec ( `kpatch ${ escapeShell ( superkey ) } rehook ${ mode } ` , { env : { PATH : `${ modDir } /bin` } } ) . then ( ( result ) => {
135+ if ( result . errno !== 0 ) {
136+ toast ( getString ( 'msg_error' , result . stderr ) ) ;
137+ return ;
138+ }
139+ updateRehookStatus ( ) ;
140+ } )
141+ }
142+
93143function getMaxChunkSize ( ) {
94144 exec ( 'getconf ARG_MAX' ) . then ( ( result ) => {
95145 try {
0 commit comments