Live data from Hacker News

Reversing Go Binaries Like a Pro

rednaga.io

11–20 of 28 posts

Re: Reversing Go Binaries Like a Pro

#12
post #11

Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? In other words, in a:="b"+"c" IOW, does it implement the Slemiel's painting algorithm or not?

I'm not sure I 100% understand your question, but in Go a string is a two-word struct.

    type string struct {
        data unsafe.Pointer
        len int
    }
The C version would be

    typedef struct string {
        const *char data;
        int len;
    } string;
Edit: oh, ok. I Googled the "painting algorithm" reference. I swear I had read that before :-)

Re: Reversing Go Binaries Like a Pro

#14
post #11

Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? In other words, in a:="b"+"c" IOW, does it implement the Slemiel's painting algorithm or not?

>Just curious, is a Go string a C string inside (rune array + nil) or a proper class array?

I can't imagine how you would even implement a string as anything other than a rune array.

Even a Pascal string is just the string length followed by characters.

Re: Reversing Go Binaries Like a Pro

#16
post #14
post #11

Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? In other words, in a:="b"+"c" IOW, does it implement the Slemiel's painting algorithm or not?

>Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? I can't imagine how you would even implement a string as anything other than a rune array. Even a Pascal string is just the string length followed by characters.

as C does: with a \00 end marker.

Re: Reversing Go Binaries Like a Pro

#17
post #14
post #11

Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? In other words, in a:="b"+"c" IOW, does it implement the Slemiel's painting algorithm or not?

>Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? I can't imagine how you would even implement a string as anything other than a rune array. Even a Pascal string is just the string length followed by characters.

> I can't imagine how you would even implement a string as anything other than a rune array.

You can also implement strings using a tree data structure. We do this in an implementation of Ruby that I work on because it can make concatenation faster.

Re: Reversing Go Binaries Like a Pro

#18
post #14
post #11

Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? In other words, in a:="b"+"c" IOW, does it implement the Slemiel's painting algorithm or not?

>Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? I can't imagine how you would even implement a string as anything other than a rune array. Even a Pascal string is just the string length followed by characters.

A text editor edits a (potentially very long) string, but apart from, possibly, the likes of Notepad, none of them store that string as a single byte array.

So, look at text editor data structures for other representations. Examples:

- https://en.wikipedia.org/wiki/Gap_buffer

- https://en.wikipedia.org/wiki/Rope_(computer_science)

- https://en.wikipedia.org/wiki/Piece_table

Re: Reversing Go Binaries Like a Pro

#19
post #11

Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? In other words, in a:="b"+"c" IOW, does it implement the Slemiel's painting algorithm or not?

I'm not sure I 100% understand your question, but in Go a string is a two-word struct. type string struct { data unsafe.Pointer len int } The C version would be typedef struct string { const *char data; int len; } string; Edit: oh, ok. I Googled the "painting algorithm" reference. I swear I had read that before :-)

If you consider googling it too: http://wiki.c2.com/?ShlemielThePainter

Re: Reversing Go Binaries Like a Pro

#20
post #14
post #11

Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? In other words, in a:="b"+"c" IOW, does it implement the Slemiel's painting algorithm or not?

>Just curious, is a Go string a C string inside (rune array + nil) or a proper class array? I can't imagine how you would even implement a string as anything other than a rune array. Even a Pascal string is just the string length followed by characters.

In Haskell strings are lists of characters (https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-S...). I hear not everyone is thrilled with the performance implications. :)

Also not a Haskell programmer, and really not meaning to criticize. Haskell seems awesome and I should learn it some day.

Post reply on HN