It can get dicey if you end up copying actual machine code, even if you translate it in to something higher level. One way round this is clean room design: https://en.wikipedia.org/wiki/Clean_room_design
Many EULAs state that there will be no attempt by the user to reverse engineering the workings of the program. How would that fit with clean room implementations?