From 3a54e605cfc0315fac5e41864279907b98174382 Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Fri, 15 Apr 2022 03:26:59 +0800 Subject: [PATCH 1/8] feat: :sparkles: add agent namespace to support frida-compile 1. use ts to write agent 2. export function and hook in ts 3. use `frida-compile -s namespace` to make agent.js 4. use `@Sidecar(target, agentScript, 'namespace')` 5. run Fixes: #33 --- src/agent/build-agent-source.ts | 2 ++ src/agent/templates/interceptors-agent.mustache | 2 +- src/agent/templates/native-functions-agent.mustache | 2 +- src/decorators/sidecar/build-sidecar-metadata.ts | 3 +++ src/decorators/sidecar/metadata-sidecar.ts | 2 ++ src/decorators/sidecar/sidecar.ts | 10 ++++++++-- 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/agent/build-agent-source.ts b/src/agent/build-agent-source.ts index 68ec08d..6e79cde 100644 --- a/src/agent/build-agent-source.ts +++ b/src/agent/build-agent-source.ts @@ -16,6 +16,8 @@ async function buildAgentSource (metadata: SidecarMetadata) { const agentMustache = partialLookup(AGENT_MUSTACHE) const view = wrapView(metadata) + // FIX namespace + view.namespace = view.namespace ? `${view.namespace}.` : '' const source = await Mustache.render( agentMustache, diff --git a/src/agent/templates/interceptors-agent.mustache b/src/agent/templates/interceptors-agent.mustache index 447dc96..fd93626 100644 --- a/src/agent/templates/interceptors-agent.mustache +++ b/src/agent/templates/interceptors-agent.mustache @@ -46,7 +46,7 @@ * which means it should not contains any logic code, it should just be a stub. */ Interceptor.replace( - {{ target.funcName }}, + {{ namespace }}{{ target.funcName }}, nativeCallback, ) diff --git a/src/agent/templates/native-functions-agent.mustache b/src/agent/templates/native-functions-agent.mustache index b04a539..3938e0d 100644 --- a/src/agent/templates/native-functions-agent.mustache +++ b/src/agent/templates/native-functions-agent.mustache @@ -13,5 +13,5 @@ const __sidecar__{{ name }}_Function_wrapper = function (...args) { '{{ name }}(%s)', args.join(', '), ) - return {{ target.funcName }}(...args) + return {{ namespace }}{{ target.funcName }}(...args) } diff --git a/src/decorators/sidecar/build-sidecar-metadata.ts b/src/decorators/sidecar/build-sidecar-metadata.ts index 23179ff..9659667 100644 --- a/src/decorators/sidecar/build-sidecar-metadata.ts +++ b/src/decorators/sidecar/build-sidecar-metadata.ts @@ -21,6 +21,7 @@ import { interface BuildSidecarMetadataOptions { initAgentScript? : string, + namespace? : string, sidecarTarget? : SidecarTarget, } @@ -124,6 +125,7 @@ function buildSidecarMetadata Date: Fri, 15 Apr 2022 03:33:44 +0800 Subject: [PATCH 2/8] 1.0.23 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f1028ae..5780e7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sidecar", - "version": "1.0.22", + "version": "1.0.23", "description": "Sidecar is for easy hook/call in-process functions with TypeScript annotations.", "type": "module", "exports": { From e6de506bcb7f839bc93e35f274bd3d999e374515 Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Fri, 15 Apr 2022 03:34:11 +0800 Subject: [PATCH 3/8] 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5780e7c..cfff892 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sidecar", - "version": "1.0.23", + "version": "1.1.0", "description": "Sidecar is for easy hook/call in-process functions with TypeScript annotations.", "type": "module", "exports": { From 2cc7795d16acb7513cd2e1975b7087ce631a443e Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Fri, 15 Apr 2022 15:32:16 +0800 Subject: [PATCH 4/8] fix: :bug: Add a semicolon to make sure the agent code works --- src/agent/templates/agent.mustache | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/agent/templates/agent.mustache b/src/agent/templates/agent.mustache index 39c8f8d..5310254 100644 --- a/src/agent/templates/agent.mustache +++ b/src/agent/templates/agent.mustache @@ -40,7 +40,9 @@ const __sidecar__moduleBaseAddress = Module.getBaseAddress('{{{ moduleName }}}') * File: "templates/agent.mustache" * > Variable: "initAgentScript" ***********************************/ +;;; {{{ initAgentScript }}} +;;; /******************************************** * File: "templates/agent.mustache" From 20027fdc7353178d40e9e5f1f7bf3692cef8a0ee Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Fri, 15 Apr 2022 15:34:23 +0800 Subject: [PATCH 5/8] chore: :arrow_up: upgrade @chatie/git-scripts to 0.7.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cfff892..3579761 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "homepage": "https://github.com/huan/sidecar#readme", "devDependencies": { "@chatie/eslint-config": "^1.0.4", - "@chatie/git-scripts": "^0.6.2", + "@chatie/git-scripts": "^0.7.7", "@chatie/semver": "^0.4.7", "@chatie/tsconfig": "^4.5.3", "@types/mustache": "^4.1.2", From 3ba03ad44eda9b732da52b6c1936f3999ab51f2c Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Fri, 15 Apr 2022 15:35:03 +0800 Subject: [PATCH 6/8] 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3579761..24c39ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sidecar", - "version": "1.1.0", + "version": "1.1.1", "description": "Sidecar is for easy hook/call in-process functions with TypeScript annotations.", "type": "module", "exports": { From 60718df19094c167db47a6f60bf175e4e1ebc94b Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Sun, 24 Apr 2022 23:48:22 +0800 Subject: [PATCH 7/8] test: --- src/decorators/sidecar/build-sidecar-metadata.spec.ts | 1 + src/decorators/sidecar/sidecar.spec.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/decorators/sidecar/build-sidecar-metadata.spec.ts b/src/decorators/sidecar/build-sidecar-metadata.spec.ts index 6bf0d5d..ca89889 100755 --- a/src/decorators/sidecar/build-sidecar-metadata.spec.ts +++ b/src/decorators/sidecar/build-sidecar-metadata.spec.ts @@ -68,6 +68,7 @@ test('@Sidecar() buildSidecarMetadata()', async t => { }, }, ], + namespace: undefined, nativeFunctionList: [ { address: { diff --git a/src/decorators/sidecar/sidecar.spec.ts b/src/decorators/sidecar/sidecar.spec.ts index af474f3..d0a82ff 100755 --- a/src/decorators/sidecar/sidecar.spec.ts +++ b/src/decorators/sidecar/sidecar.spec.ts @@ -66,6 +66,7 @@ test('@Sidecar() viewMetadata()', async t => { }, }, ], + namespace: undefined, nativeFunctionList: [ { address: { From f76fc1a22c6245bbc5a0e3e52424841c455d210a Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Sun, 24 Apr 2022 23:48:45 +0800 Subject: [PATCH 8/8] 1.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 24c39ea..4bbeabf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sidecar", - "version": "1.1.1", + "version": "1.1.2", "description": "Sidecar is for easy hook/call in-process functions with TypeScript annotations.", "type": "module", "exports": {