Skip to content

Commit ff0eca7

Browse files
committed
Make function receiveMessage more clear
1 parent f549039 commit ff0eca7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

quark/script/frida/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,30 @@ def stopWatchingMethodCall(
5959
if methodId in self.watchedMethods:
6060
del self.watchedMethods[methodId]
6161

62-
def receiveMessage(self, messageFromFridaAgent: dict, _) -> None:
63-
if messageFromFridaAgent["type"] == "error":
64-
errorDescription = messageFromFridaAgent["description"]
62+
def handleCapturedEvent(self, eventWrapperFromFrida: dict, _) -> None:
6563
"""Send the event captured by Frida to the corresponding
6664
buffers.
6765
6866
:param eventWrapperFromFrida: python dict containing captured events
6967
"""
68+
if eventWrapperFromFrida["type"] == "error":
69+
errorDescription = eventWrapperFromFrida["description"]
7070
print(errorDescription, file=sys.stderr)
7171
return
7272

73-
receivedEvent = json.loads(messageFromFridaAgent["payload"])
73+
methodCallEvent = json.loads(eventWrapperFromFrida["payload"])
7474

75-
eventType = receivedEvent.get("type", None)
75+
eventType = methodCallEvent.get("type", None)
7676

7777
if eventType == "CallCaptured":
78-
methodId = tuple(receivedEvent["identifier"][0:2])
78+
methodId = tuple(methodCallEvent["identifier"][0:2])
7979

8080
if methodId in self.watchedMethods:
8181
messageBuffer = self.watchedMethods[methodId]
82-
messageBuffer.append(receivedEvent)
82+
messageBuffer.append(methodCallEvent)
8383

8484
elif eventType == "FailedToWatch":
85-
methodId = tuple(receivedEvent["identifier"])
85+
methodId = tuple(methodCallEvent["identifier"])
8686
self.watchedMethods.pop(methodId)
8787

8888

@@ -128,7 +128,7 @@ def _injectAgent(frida: FridaSession) -> MethodCallEventDispatcher:
128128

129129
with open(pathToFridaAgentSource, "r") as fridaAgentSource:
130130
fridaAgent = dispatcher.frida.create_script(fridaAgentSource.read())
131-
fridaAgent.on("message", dispatcher.receiveMessage)
131+
fridaAgent.on("message", dispatcher.handleCapturedEvent)
132132
fridaAgent.load()
133133
dispatcher.script = fridaAgent
134134

tests/script/test_frida.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def testStartWatchingMethodFailed(dispatcherThatHooksOneMethod):
8787
),
8888
}
8989

90-
dispatcher.receiveMessage(failedToWatchMessage, None)
90+
dispatcher.handleCapturedEvent(failedToWatchMessage, None)
9191

9292
assert (
9393
dispatcher._getMethodIdentifier(targetMethod, methodParamTypes)
@@ -147,7 +147,7 @@ def testDispatchCallMessage(dispatcherThatHooksOneMethod):
147147
"payload": json.dumps(expectedEvent),
148148
}
149149

150-
dispatcher.receiveMessage(callMessage, None)
150+
dispatcher.handleCapturedEvent(callMessage, None)
151151

152152
assert expectedEvent in buffer
153153

@@ -157,7 +157,7 @@ def testDispatchErrorMessage(dispatcherThatHooksOneMethod, capsys):
157157

158158
errorMessage = {"type": "error", "description": "Any description."}
159159

160-
dispatcher.receiveMessage(errorMessage, None)
160+
dispatcher.handleCapturedEvent(errorMessage, None)
161161

162162
captured = capsys.readouterr()
163163

0 commit comments

Comments
 (0)