collab/polyglot-riscv-arm
what if the same machine code was valid riscv and arm asm
git clone https://git.julia.blue/collab/polyglot-riscv-arm
885cc4e
main
1#include <fcntl.h> 2#include <capstone/capstone.h> 3#include <string.h> 4#include <unistd.h> 5#include <stdint.h> 6#include <sys/mman.h> 7 8int main (int argc ,char * argv []) { 9csh handle ; 10if (cs_open (CS_ARCH_AARCH64 ,CS_MODE_ARM ,& handle )!= CS_ERR_OK ) { 11fprintf (stderr ,"could not open arm64 disassembler\n" ); 12return 1 ; 13 } 14size_t n_verify = 0x0ffffffffULL + 1 ; 15int fd = open (argv [1 ],O_RDWR ); 16if (fd < 0 ) { 17perror ("open" ); 18 } 19 20int16_t * data = mmap (NULL ,n_verify * sizeof (int16_t ),PROT_READ |PROT_WRITE ,MAP_SHARED ,fd ,0 ); 21if (data == (int16_t * )-1 ) { 22perror ("mmap" ); 23 } 24 25size_t size = sizeof (uint32_t ); 26for (size_t i = 0 ;i < n_verify ;i ++ ) { 27if (i %10000000 == 0 ) { 28printf ("%.3f\n" , (float )i / (float )n_verify * 100 ); 29 } 30if (data [i ]!= -1 ) { 31cs_insn * insn ; 32uint32_t idat = (uint32_t )i ; 33size_t count = cs_disasm (handle , (const uint8_t * )& idat ,size ,0 ,1 ,& insn ); 34if (count != 1 ) { 35data [i ]= -1 ; 36continue ; 37 } 38cs_free (insn ,1 ); 39 } 40 } 41close (fd ); 42 43return 0 ; 44}