How can I write the null character on a Macbook Pro?

7

1

How can I write a null character on a Macbook Pro? I'd prefer to use just the keyboard or something that I can reach everywhere, without using a third-party program.

Filip Haglund

Posted 2011-06-05T18:38:48.417

Reputation: 1 150

Type null character in terminal – phuclv – 2016-11-17T16:52:12.793

2Most application will not read this properly so I think it would help if you could say how you want to use this. e.g. terminal can use this in one way but GUI apps will differ – user151019 – 2011-06-05T20:30:17.693

Please uncheck my answer so I can delete it. – KCotreau – 2011-06-06T11:28:20.390

Why would any user on any OS want to input the null character ??? – LatinSuD – 2011-06-06T12:50:33.910

2@LatinSUD Bug exploitation, software testing, binary file editing, to name just a few. – Daniel Beck – 2011-06-06T13:03:42.297

Answers

6

You can do this with the Unicode Hex Input method (enable it in System Preferences -> Language & Text pane -> Input Sources tab, then select it from the menu item) by holding Option and typing "0000".

Warning: the null character is not allowed in C-language strings (it's used to indicate the end of the string), so not all programs will cope with it. In TextEdit, for example, you can insert a null into a document, but when you save the document it'll only save the part before the null.

Gordon Davisson

Posted 2011-06-05T18:38:48.417

Reputation: 28 538

Can't find that setting, maybe it's because i don't have numpad? alt+numbers just writes special chars as usual.

your warning: That's exactly what i am gonna use it for. Buffer overflowing and null-injecting my own programs. – Filip Haglund – 2011-06-06T08:19:30.767

@Filip Haglund: which setting can't you find, the setting in System Preferences or the menu item? Also, which version of Mac OS X (and language), as I think they got moved around between versions. – Gordon Davisson – 2011-06-06T15:31:49.077

davisson Got it. Didn't take it far enough in my head to translate it before searching for it. Can't get it to write null in terminal though... It did type it in safari search-box tho :) google missed half my search and url shows %00 :D – Filip Haglund – 2011-06-06T20:33:26.343

1@Filip Haglund: Good; I'll skip the screenshots I was working on (since I don't know Swedish at all, getting them was a little fun...) BTW, null seems to work OK as far as Terminal itself is concerned, but (for example) bash won't let me include it directly in a command line. If you type it into xxd's stdin, though, it shows a null byte just as expected. – Gordon Davisson – 2011-06-06T20:58:09.717

sure does :) tnx – Filip Haglund – 2011-06-07T14:26:27.190

3

Depends on your terminal, in Terminal.app and Iterm2 you can use ^@ (Ctrl+Shift+2). See here.

zeekay

Posted 2011-06-05T18:38:48.417

Reputation: 166

I'm not talking about just terminal. Also, i can't get it to work. Do you have an example where it doesn't give me a beep error? – Filip Haglund – 2011-06-05T19:44:02.957

1@Filip I have no idea what application you are trying to use, so no I don't. Maybe you should rework your question and include more detail. Perhaps there is even another way to accomplish whatever you are after. – zeekay – 2011-06-05T20:19:38.120

i tried it in terminal, with a beep-error as a result. I would like a general way to be able to write it, just like i can write other chars in windows using alt-combinations. I am using the swedish version of mac os x if that matters. – Filip Haglund – 2011-06-05T20:34:22.310

@Filip I'm not sure why that would matter? Works fine with Terminal.app and Iterm2 by default, from what I can tell. – zeekay – 2011-06-05T22:54:43.767

It doesn't work in terminal.app, from what i can tell :/ I think the swedish keyboard layout is messing with me. – Filip Haglund – 2011-06-06T08:33:46.460