Skip to content

Instantly share code, notes, and snippets.

@sunflsks
Last active January 12, 2024 07:09
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunflsks/00fe7c740f3b1d9668f55dff80707d03 to your computer and use it in GitHub Desktop.
Save sunflsks/00fe7c740f3b1d9668f55dff80707d03 to your computer and use it in GitHub Desktop.
convert an x86 bin to an arm through oahd-helper
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
void help(char* curbin) {
fprintf(stderr, "%s x86_bin arm64_output\n", curbin);
}
int main(int argc, char** argv) {
printf("this will sigbus but the bin might be valid\n");
if (argc < 3) {
help(argv[0]);
return 1;
}
int x86fd = open(argv[1], O_RDONLY);
if (x86fd < 0) {
perror("x86fd");
return 2;
}
int armfd = open(argv[2], O_CREAT | O_WRONLY, 0755);
if (armfd < 0) {
perror("armfd");
return 2;
}
char* x86fdstr = calloc(2048, 1);
char* armfdstr = calloc(2048, 1);
sprintf(x86fdstr, "%d", x86fd);
sprintf(armfdstr, "%d", armfd);
char* args[] = {
"oahd-helper",
x86fdstr,
armfdstr,
NULL,
};
execv("/usr/libexec/rosetta/oahd-helper", args);
perror("execve");
}
@MagerValp
Copy link

Bash version because why not:

#!/bin/bash

exec 3< "$1"
exec 4> "$2"

/usr/libexec/rosetta/oahd-helper 3 4

@sunflsks
Copy link
Author

Oh wow, that's really concise haha. Definitely a better solution IMO if you don't need/want to deal with C

@Codezigineer
Copy link

Version that runs it natively instead of just transpiling it because why not:

#!/bin/bash

exec 3< "$1"
binary="$(mktemp)"

/usr/libexec/rosetta/oahd-helper 3 $binary; chmod +x $binary; exec $binary; rm -rf $binary

@PlugNPush
Copy link

Hi, I'm late with this, but I can't get it to work. I tried to build the c code, as well as using bash:

./oahd-wrapper /Users/plugn/Downloads/mybinary /Users/plugn/Downloads/mybinary-arm

exec 3< "/Users/plugn/Downloads/mybinary"
exec 4> "/Users/plugn/Downloads/mybinary-arm" 
/usr/libexec/rosetta/oahd-helper 3 4

mybinary is about 13.6MB, and the newly created mybinary-arm contains exactly Zero bytes in both cases. Am I missing something? Note that mybinary is a binary containing both x86_64 and i386 architectures.

@PlugNPush
Copy link

PlugNPush commented Nov 3, 2023

Nevermind, turns out my binary needed to be inside MyApp.app/Contents/MacOS/mybinary, not elsewhere.

My next question would be, can this converted binary be run in any way? Opening it will kill it immediately due to it having no signature, and trying to give it a signature results into the following error:

codesign -s "-" --verbose --force Downloads/MyApp.app/Contents/MacOS/mybinary-arm Downloads/MyApp.app/Contents/MacOS/mybinary-arm: main executable failed strict validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment