1 package obj
2
3 import (
4 `os`
5 `os/exec`
6 `testing`
7
8 `github.com/davecgh/go-spew/spew`
9 `github.com/stretchr/testify/require`
10 )
11
12 func TestMachO_Create(t *testing.T) {
13 fp, err := os.CreateTemp("", "macho_out-")
14 require.NoError(t, err)
15 code := []byte {
16 0x48, 0xc7, 0xc7, 0x01, 0x00, 0x00, 0x00,
17 0x48, 0x8d, 0x35, 0x1b, 0x00, 0x00, 0x00,
18 0x48, 0xc7, 0xc2, 0x0e, 0x00, 0x00, 0x00,
19 0x48, 0xc7, 0xc0, 0x04, 0x00, 0x00, 0x02,
20 0x0f, 0x05,
21 0x31, 0xff,
22 0x48, 0xc7, 0xc0, 0x01, 0x00, 0x00, 0x02,
23 0x0f, 0x05,
24 'h', 'e', 'l', 'l', 'o', ',', ' ',
25 'w', 'o', 'r', 'l', 'd', '\r', '\n',
26 }
27 err = assembleMachO(fp, code, 0, 0)
28 require.NoError(t, err)
29 err = fp.Close()
30 require.NoError(t, err)
31 err = os.Chmod(fp.Name(), 0755)
32 require.NoError(t, err)
33 println("Saved to", fp.Name())
34 out, err := exec.Command(fp.Name()).Output()
35 require.NoError(t, err)
36 spew.Dump(out)
37 require.Equal(t, []byte("hello, world\r\n"), out)
38 err = os.Remove(fp.Name())
39 require.NoError(t, err)
40 }
41
View as plain text