Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for agents generated with frida-compile #35

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sidecar",
"version": "1.0.22",
"version": "1.1.2",
"description": "Sidecar is for easy hook/call in-process functions with TypeScript annotations.",
"type": "module",
"exports": {
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/agent/build-agent-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/agent/templates/agent.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const __sidecar__moduleBaseAddress = Module.getBaseAddress('{{{ moduleName }}}')
* File: "templates/agent.mustache"
* > Variable: "initAgentScript"
***********************************/
;;;
{{{ initAgentScript }}}
;;;

/********************************************
* File: "templates/agent.mustache"
Expand Down
2 changes: 1 addition & 1 deletion src/agent/templates/interceptors-agent.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion src/agent/templates/native-functions-agent.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ const __sidecar__{{ name }}_Function_wrapper = function (...args) {
'{{ name }}(%s)',
args.join(', '),
)
return {{ target.funcName }}(...args)
return {{ namespace }}{{ target.funcName }}(...args)
}
1 change: 1 addition & 0 deletions src/decorators/sidecar/build-sidecar-metadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ test('@Sidecar() buildSidecarMetadata()', async t => {
},
},
],
namespace: undefined,
nativeFunctionList: [
{
address: {
Expand Down
3 changes: 3 additions & 0 deletions src/decorators/sidecar/build-sidecar-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

interface BuildSidecarMetadataOptions {
initAgentScript? : string,
namespace? : string,
sidecarTarget? : SidecarTarget,
}

Expand Down Expand Up @@ -124,6 +125,7 @@ function buildSidecarMetadata <T extends {

const {
initAgentScript,
namespace,
sidecarTarget,
} = options

Expand All @@ -132,6 +134,7 @@ function buildSidecarMetadata <T extends {
return {
initAgentScript,
interceptorList,
namespace,
nativeFunctionList,
sidecarTarget: normalizedTarget,
}
Expand Down
2 changes: 2 additions & 0 deletions src/decorators/sidecar/metadata-sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface SidecarMetadata {
nativeFunctionList : SidecarMetadataFunctionTypeDescription[],
interceptorList : SidecarMetadataFunctionTypeDescription[],
initAgentScript? : string,

namespace? : string,
sidecarTarget? : SidecarTargetObj,
}

Expand Down
1 change: 1 addition & 0 deletions src/decorators/sidecar/sidecar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ test('@Sidecar() viewMetadata()', async t => {
},
},
],
namespace: undefined,
nativeFunctionList: [
{
address: {
Expand Down
10 changes: 8 additions & 2 deletions src/decorators/sidecar/sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ import type {
function Sidecar (
sidecarTarget : SidecarTarget,
initAgentScript? : string,
namespace? : string,
) {
log.verbose('Sidecar', '@Sidecar(%s%s)',
log.verbose('Sidecar', '@Sidecar(%s%s%s)',
Array.isArray(sidecarTarget)
? JSON.stringify(sidecarTarget)
: sidecarTarget,
initAgentScript
? `, "${initAgentScript.substr(0, 20)}..."`
: '',
namespace
? `, "${namespace}"`
: '',
)

return classDecorator
Expand All @@ -37,11 +41,12 @@ function Sidecar (
Klass: T,
) {
log.verbose('Sidecar',
'@Sidecar(%s%s) classDecorator(%s)',
'@Sidecar(%s%s%s) classDecorator(%s)',
Array.isArray(sidecarTarget)
? JSON.stringify(sidecarTarget)
: (sidecarTarget || ''),
`"${initAgentScript?.substr(0, 20)}..."` || '',
namespace ? `, "${namespace}"` : '',
Klass.name,
)

Expand All @@ -52,6 +57,7 @@ function Sidecar (

const meta = buildSidecarMetadata(Klass, {
initAgentScript,
namespace,
sidecarTarget,
})

Expand Down