Skip to content

Commit

Permalink
Fix assert in example and build for r2pipeNative
Browse files Browse the repository at this point in the history
* r2pipe module is broken on latest Swift, still needs a rework
  • Loading branch information
radare committed Aug 20, 2023
1 parent 398b80e commit ceddc28
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions swift/r2pipeNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class R2PipeNative {
private var inHandle:FileHandle? = nil;

init?(file:String?) {
let outHandle: FileHandle;
var outHandle: FileHandle;
outHandle = pipe.fileHandleForReading
if file == nil {
#if USE_ENV_PIPE
let dict = ProcessInfo.processInfo.environment
Expand Down Expand Up @@ -85,7 +86,7 @@ data.withUnsafeBytes {(bytes: UnsafePointer<UInt8>)->Void in
// skip
self.initState = false;
} else {
let newData = Data(bytes: bytes, length:foundTerminatorAt);
let newData = Data(bytes: bytes, count:foundTerminatorAt);
if let str = String(data: data, encoding: .utf8) {
self.bufferedString += str as String;
self.runCallback (self.bufferedString);
Expand All @@ -99,7 +100,7 @@ data.withUnsafeBytes {(bytes: UnsafePointer<UInt8>)->Void in
// let newBytes = UnsafePointer<UInt8>(data.withUnsafeBytes) + foundTerminatorAt + 1;
let newBytes = bytes + foundTerminatorAt + 1;
let k = data.count - foundTerminatorAt - 1;
data = Data(bytes: newBytes, length: k);
data = Data(bytes: newBytes, count: k);
pointer = UnsafePointer<UInt8>(newBytes)
buffer = UnsafeBufferPointer<UInt8>(start:pointer, count:k)

Expand Down
1 change: 1 addition & 0 deletions swift/r2plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ all:
swiftc $(CFLAGS) -o main struct.c coreplugin.swift main.swift
mkdir -p $(shell r2 -H R2_USER_PLUGINS)
cp -f libr2swift.dylib $(shell r2 -H R2_USER_PLUGINS)
r2 -qc 'swift jeje' /bin/ls
11 changes: 7 additions & 4 deletions swift/r2plugin/coreplugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ public func r2swift_cmd(_core: UnsafeMutableRawPointer, cmd: UnsafePointer<CChar
let res = core.cmd("x")
print("This is your favourite Swift command BEGIN\n \(str) \(res) END")

let j = core.cmdj("ij")
if let j = core.cmdj("ij") {
let j_bin = j.value(forKey:"bin") as? NSDictionary
if j_bin != nil {
let j_bin_arch = j_bin!.value(forKey:"arch")!
print("arch=\(j_bin_arch)")
}
}
//print("Json \(String(describing:j))")
let j_bin = j!.value(forKey:"bin")! as? NSDictionary
//print("jbin \(String(describing:j_bin))")
let j_bin_arch = j_bin!.value(forKey:"arch")!
print("arch=\(j_bin_arch)")
}
return 0
}

0 comments on commit ceddc28

Please sign in to comment.