()
| 183 | * Generate a Frida hook for the method at the current cursor line. |
| 184 | */ |
| 185 | export async function generateHook(): Promise<void> { |
| 186 | const editor = vscode.window.activeTextEditor; |
| 187 | if (!editor || editor.document.languageId !== "smali") { |
| 188 | vscode.window.showWarningMessage( |
| 189 | "APKLab: Open a .smali file to generate Frida hooks.", |
| 190 | ); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | const document = editor.document; |
| 195 | const line = document.lineAt(editor.selection.active.line); |
| 196 | const lineText = line.text.trim(); |
| 197 | |
| 198 | // Walk up to find the enclosing .method if cursor isn't on one |
| 199 | let methodLine = lineText; |
| 200 | if (!methodLine.startsWith(".method ")) { |
| 201 | for (let i = editor.selection.active.line; i >= 0; i--) { |
| 202 | const l = document.lineAt(i).text.trim(); |
| 203 | if (l.startsWith(".method ")) { |
| 204 | methodLine = l; |
| 205 | break; |
| 206 | } |
| 207 | if ( |
| 208 | l.startsWith(".end method") && |
| 209 | i < editor.selection.active.line |
| 210 | ) { |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | if (!methodLine.startsWith(".method ")) { |
| 217 | vscode.window.showWarningMessage( |
| 218 | "APKLab: Place cursor on or inside a .method to generate a Frida hook.", |
| 219 | ); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | const className = getClassNameFromDocument(document); |
| 224 | const method = parseMethodFromLine(methodLine, className); |
| 225 | if (!method) { |
| 226 | vscode.window.showWarningMessage( |
| 227 | "APKLab: Could not parse method signature.", |
| 228 | ); |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | const hookCode = generateFridaHook(method); |
| 233 | const projectRoot = findProjectRoot(document.uri.fsPath); |
| 234 | if (!projectRoot) { |
| 235 | vscode.window.showWarningMessage( |
| 236 | "APKLab: No APKTool project found.", |
| 237 | ); |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | const hooksFile = path.join(projectRoot, FRIDA_HOOKS_FILENAME); |
| 242 | const separator = fs.existsSync(hooksFile) ? "\n\n" : ""; |
nothing calls this directly
no test coverage detected