Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

0 terminated?

Posted on 2011-10-10
2
Medium Priority
?
342 Views
Last Modified: 2012-05-12
The following code outputs the first two letters of a file called test.txt.
test.txt has the letters abcd and nothing else in it.
When I display the ab with StdOut there is no error message but I have cause to wonder... shouldn't that string be null terminated?
Should I be manually placing a 0 at the end of it?

  .486
  .model flat, stdcall
  option casemap :none

  include \masm32\include\windows.inc
  include \masm32\macros\macros.asm

  include \masm32\include\masm32.inc
  include \masm32\include\gdi32.inc
  include \masm32\include\user32.inc
  include \masm32\include\kernel32.inc.

  includelib \masm32\lib\masm32.lib
  includelib \masm32\lib\gdi32.lib
  includelib \masm32\lib\user32.lib
  includelib \masm32\lib\kernel32.lib

  .data    
    filename db "c:\masm32\assembly projects\fopen\test.txt",0    
    file_handle HANDLE ?
    file_buffer DWORD 256 dup (?)
    readC DW ?
  .code

start:
  invoke CreateFile,ADDR filename,GENERIC_READ,FILE_SHARE_READ,
                      NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
  mov file_handle,eax
  invoke ReadFile,file_handle,ADDR file_buffer,sizeof(BYTE)*2,ADDR readC,NULL
  invoke StdOut,ADDR file_buffer
  invoke CloseHandle,file_handle

  exit
end start

Open in new window

0
Comment
Question by:aiakonai
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 36947248
You read two bytes from the file, and place them in the buffer.

Nothing else is placed in the buffer, so it will contain those two bytes, and whatever happened to be in the buffer before the ReadFile call.

If you want it to be null terminated, then you have to add the '\0' byte yourself, as you correctly assume.
0
 

Author Closing Comment

by:aiakonai
ID: 36948380
Thanks. I'm still new to 32 bit assembly ... just making sure I know is what I know.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this step by step method when setting up QuickBooks Online. They will allow you to explore the various features of the advanced settings available to you.
Are you a startup company? Being a startup, you may be using shared hosting, or maybe even dedicated hosting. But have you ever given a thought to using cloud computing now? Yes, don’t be surprised, it is possible for startups to opt for cloud compu…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question