From 250da628eeb6c5f2f7ab7d79f75d84d58e752689 Mon Sep 17 00:00:00 2001 From: fish-sauce Date: Mon, 18 Nov 2024 10:46:57 -0600 Subject: [PATCH 1/2] Fix: pass primitive pid to memory limit request --- ios/dtx_codec/channel.go | 21 +++++++++++++++++++-- ios/instruments/processcontrol.go | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ios/dtx_codec/channel.go b/ios/dtx_codec/channel.go index 700b7973..cb9cfc8a 100644 --- a/ios/dtx_codec/channel.go +++ b/ios/dtx_codec/channel.go @@ -49,19 +49,36 @@ func (d *Channel) ReceiveMethodCall(selector string) Message { // MethodCall is the standard DTX style remote method invocation pattern. The ObjectiveC Selector goes as a NSKeyedArchiver.archived NSString into the // DTXMessage payload, and the arguments are separately NSKeyArchiver.archived and put into the Auxiliary DTXPrimitiveDictionary. It returns the response message and an error. func (d *Channel) MethodCall(selector string, args ...interface{}) (Message, error) { - payload, _ := nskeyedarchiver.ArchiveBin(selector) auxiliary := NewPrimitiveDictionary() for _, arg := range args { auxiliary.AddNsKeyedArchivedObject(arg) } + + return d.methodCallWithReply(selector, auxiliary) +} + +// MethodCallPrimitive is a DTX style remote method invocation pattern. The ObjectiveC Selector goes as a NSKeyedArchiver.archived NSString into the +// DTXMessage payload, and the primitive arguments put into the Auxiliary DTXPrimitiveDictionary. It returns the response message and an error. +func (d *Channel) MethodCallPrimitive(selector string, args ...int) (Message, error) { + auxiliary := NewPrimitiveDictionary() + for _, arg := range args { + auxiliary.AddInt32(arg) + } + + return d.methodCallWithReply(selector, auxiliary) +} + +func (d *Channel) methodCallWithReply(selector string, auxiliary PrimitiveDictionary) (Message, error) { + payload, _ := nskeyedarchiver.ArchiveBin(selector) msg, err := d.SendAndAwaitReply(true, Methodinvocation, payload, auxiliary) if err != nil { log.WithFields(log.Fields{"channel_id": d.channelName, "error": err, "methodselector": selector}).Info("failed starting invoking method") return msg, err } if msg.HasError() { - return msg, fmt.Errorf("Failed invoking method '%s' with error: %s", selector, msg.Payload[0]) + return msg, fmt.Errorf("failed invoking method '%s' with error: %s", selector, msg.Payload[0]) } + return msg, nil } diff --git a/ios/instruments/processcontrol.go b/ios/instruments/processcontrol.go index eb115366..f33a10e4 100644 --- a/ios/instruments/processcontrol.go +++ b/ios/instruments/processcontrol.go @@ -64,7 +64,7 @@ func NewProcessControl(device ios.DeviceEntry) (*ProcessControl, error) { // DisableMemoryLimit disables the memory limit of a process. func (p ProcessControl) DisableMemoryLimit(pid uint64) (bool, error) { - msg, err := p.processControlChannel.MethodCall("requestDisableMemoryLimitsForPid:", pid) + msg, err := p.processControlChannel.MethodCallPrimitive("requestDisableMemoryLimitsForPid:", int(pid)) if err != nil { return false, err } From cac11249540470bcc5df30e433e8f68318561c60 Mon Sep 17 00:00:00 2001 From: fish-sauce Date: Tue, 19 Nov 2024 07:18:13 -0600 Subject: [PATCH 2/2] simplify reading --- ios/dtx_codec/channel.go | 11 +++-------- ios/instruments/processcontrol.go | 4 +++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ios/dtx_codec/channel.go b/ios/dtx_codec/channel.go index cb9cfc8a..bba99765 100644 --- a/ios/dtx_codec/channel.go +++ b/ios/dtx_codec/channel.go @@ -57,15 +57,10 @@ func (d *Channel) MethodCall(selector string, args ...interface{}) (Message, err return d.methodCallWithReply(selector, auxiliary) } -// MethodCallPrimitive is a DTX style remote method invocation pattern. The ObjectiveC Selector goes as a NSKeyedArchiver.archived NSString into the +// MethodCallWithAuxiliary is a DTX style remote method invocation pattern. The ObjectiveC Selector goes as a NSKeyedArchiver.archived NSString into the // DTXMessage payload, and the primitive arguments put into the Auxiliary DTXPrimitiveDictionary. It returns the response message and an error. -func (d *Channel) MethodCallPrimitive(selector string, args ...int) (Message, error) { - auxiliary := NewPrimitiveDictionary() - for _, arg := range args { - auxiliary.AddInt32(arg) - } - - return d.methodCallWithReply(selector, auxiliary) +func (d *Channel) MethodCallWithAuxiliary(selector string, aux PrimitiveDictionary) (Message, error) { + return d.methodCallWithReply(selector, aux) } func (d *Channel) methodCallWithReply(selector string, auxiliary PrimitiveDictionary) (Message, error) { diff --git a/ios/instruments/processcontrol.go b/ios/instruments/processcontrol.go index f33a10e4..b0118804 100644 --- a/ios/instruments/processcontrol.go +++ b/ios/instruments/processcontrol.go @@ -64,7 +64,9 @@ func NewProcessControl(device ios.DeviceEntry) (*ProcessControl, error) { // DisableMemoryLimit disables the memory limit of a process. func (p ProcessControl) DisableMemoryLimit(pid uint64) (bool, error) { - msg, err := p.processControlChannel.MethodCallPrimitive("requestDisableMemoryLimitsForPid:", int(pid)) + aux := dtx.NewPrimitiveDictionary() + aux.AddInt32(int(pid)) + msg, err := p.processControlChannel.MethodCallWithAuxiliary("requestDisableMemoryLimitsForPid:", aux) if err != nil { return false, err }