EOF ASCII / HEX код в текстовых файлах

6827
Abraham

Насколько известно, в конце всех файлов, особенно текстовых, есть шестнадцатеричный код для символа EOF или NULL . И когда мы хотим написать программу и прочитать содержимое текстового файла, мы отправляем функцию чтения, пока не получим этот шестнадцатеричный код EOF.

Мой вопрос: я скачал несколько инструментов, чтобы увидеть шестнадцатеричное представление текстового файла. но я не вижу шестнадцатеричный код для EOF (конец файла / NULL) или EOT (конец текста)


ASCII / Hex кодовые таблицы:

enter image description here

Это выходные данные инструментов просмотра Hex:

enter image description here


Примечание. Мой входной файл - это текстовый файл, содержимое которого имеет вид «Где шестнадцатеричный код« EOF »?»

1

2 ответа на вопрос

1
duDE

No, EOF is not a special character, lol :)

Take a look: http://www.cplusplus.com/reference/cstdio/EOF/

It is basically a macro:

End-of-File It is a macro definition of type int that expands into a negative integral constant expression (generally, -1). It is used as the value returned by several functions in header <cstdio> to indicate that the End-of-File has been reached or to signal some other failure conditions. It is also used as the value to represent an invalid character. In C++, this macro corresponds to the value of char_traits<char>::eof(). 

That means, the API try to read a line of file, get -1 and returns EOF. In contrast to EOF, the CR/LF are such special characters, you can see them in the HEX Editor if you have some line breaks:

'\n' or '0x0A' (10 in decimal) -> This character is called "Line Feed" (LF). '\r' or '0x0D' (13 in decimal) -> This one is called "Carriage return" (CR). 

Apart of the files, there is a '\0' character on the end of the array of character in memory, it marks the end of the string. Without it, the computer has no way to know how long that group of characters goes. When you print/copy/whatever a string, it just keeps printing/copying chars until it finds that null char... that's when it knows to stop.

Maybe you mean this one NULL?

Я написал программу, которая искала в текстовом файле символ «А». И если в тексте нет буквы «А», переместите файл в специальный каталог. Я хочу знать, есть ли способ обмануть мою программу? например, «добавить шестнадцатеричный код NULL / EOF / EOT в середине моего входного текста»? Я хочу знать, есть ли какой-либо способ обмануть программу, только изменив текстовый файл? Предположим, что они не могут устанавливать или редактировать что-либо на хосте (что моя программа на нем установлена). Спасибо Abraham 9 лет назад 0
Если вы используете функцию `read ()` в двоичном режиме или даже в режиме перевода строки - и больше ничего не указано в документации по этой функции - тогда мой вывод таков; ничто не может обмануть это. ** Но чтобы быть более уверенным в фактическом случае для себя, используя свои инструменты, вам необходимо ПРОВЕРИТЬ это путем тестирования. ** - фактическая ситуация полностью зависит от того, как написан код инструмента и / или поставщика библиотеки - и там Я могу только догадываться, как и все остальные. Hannu 9 лет назад 0
Да, есть способ - ваша программа может быть разобрана: http://en.wikibooks.org/wiki/X86_Disassembly/Objects_and_Classes duDE 9 лет назад 0
1
Hannu

Traditionally, in some contexts there is a End-of-file 'character' - MS-DOS / CMD.EXE uses CTRL+Z - Linux uses CTRL+D

CTRL-Z is code 26, CTRL-D is code 4 in the ASCII table.

These are still in use in situations when you use stdin (in the meaning as applied in "C" programming and general console/tty IO).

e.g.

C:\> copy con myFile.txt This is text to go into the file.Enter CTRL+Z C:\> type myFile.txt This is text to go into the file. C:\> 

The very same sequence works in Linux'en with the difference that you start with

$ cat >myFile 

and end with CTRL+D, then cat myFile.txt instead of type.

... If you're programming though, you will hardly see any effects of these characters.
I am at this writing not aware of any function call that would stop at these characters.
Read the documentation for your software / library - if there is no statement about the effect of these, then you're not likely to see anything strange happen.

Line endings - CR and LF combinations, code 13 and 10 - is a bit different though, it can get quite messy if you transfer TEXT files from one system to another. unix2dos and dos2unix are shell commands available on Linux'en - for this purpose.

Sample bash session:

$ echo -e "First line\n\x04Second line." First line Second line. $ echo -e "First line\n\x04Second line." | od -t x1z 0000000 46 69 72 73 74 20 6c 69 6e 65 0a 04 53 65 63 6f >First line..Seco< 0000020 6e 64 20 6c 69 6e 65 2e 0a >nd line..< 0000031 $ echo -e "First line\n\x04Second line." | grep line First line Second line. $ cat >myFile.txt Check this out $ cat myFile.txt Check this out $ 
не могли бы вы взглянуть на мой комментарий ниже предыдущего ответа? (ниже ** duDE ** ответ). Спасибо Abraham 9 лет назад 0