Needing some guidance

Reply

Join Date: Aug 2008
Posts: 55
Reputation: RayvenHawk is an unknown quantity at this point 
Solved Threads: 1
RayvenHawk RayvenHawk is offline Offline
Junior Poster in Training

Needing some guidance

 
0
  #1
23 Days Ago
To be upfront and all, this is indeed a homework assignment. But I'm not looking for anyone to write the code I need just help me with a few functions I'm needing to use (the book is VERY vague on how to use these instructions).

Assignment is open an encrypted file, decrypt it and then send it to a new text file.

Ok so far I have this

  1. .data
  2. BUFFER_SIZE = 5000
  3. buffer BYTE BUFFER_SIZE DUP(?)
  4. filename BYTE "myfile.txt",0 (this is coming from my book)
  5.  
  6. .code
  7. mov edx,OFFSET filename
  8. call OpenInputFile
  9. mov edx,OFFSET buffer
  10. mov ecx,BUFFER_SIZE
  11. call ReadFromFile
  12. call WriteToFile

As I said the book is extremly vague on how these instructions truly work. My question is what is the normal procedure to open a file, read it and then output it to a new file?
Last edited by RayvenHawk; 23 Days Ago at 2:06 pm.
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."

Programmers - Making other people rich for over 50yrs.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 33
Reputation: dan63043 is an unknown quantity at this point 
Solved Threads: 4
dan63043 dan63043 is offline Offline
Light Poster
 
0
  #2
23 Days Ago
Those functions could be in some library that I don't have, but perhaps writing those functions is the REAL assignment.

Could you give us some idea what assembler you use, on what operating system, etc? Maybe even the name of the course and book would give us a hint on helping you.

So far, your post doesn't give some of us enough info, unless those functions happen to belong to a package that someone else recognizes.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 55
Reputation: RayvenHawk is an unknown quantity at this point 
Solved Threads: 1
RayvenHawk RayvenHawk is offline Offline
Junior Poster in Training
 
0
  #3
23 Days Ago
Originally Posted by dan63043 View Post
Those functions could be in some library that I don't have, but perhaps writing those functions is the REAL assignment.

Could you give us some idea what assembler you use, on what operating system, etc? Maybe even the name of the course and book would give us a hint on helping you.

So far, your post doesn't give some of us enough info, unless those functions happen to belong to a package that someone else recognizes.
I'm using MASM. The book is Assembly Language for Intel-Based Computers 5th Edition.

The functions are built into the irvine32.lib, so writing the functions isn't part of the assignment.
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."

Programmers - Making other people rich for over 50yrs.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 33
Reputation: dan63043 is an unknown quantity at this point 
Solved Threads: 4
dan63043 dan63043 is offline Offline
Light Poster
 
0
  #4
23 Days Ago
Goto http://cis.ysu.edu/~rick/class3714/ch5.html and search for OpenInputFile and you will find the three functions documented near one another.

I see that you need to use EAX after that first call, the rest should follow naturally from the info at that URL. Give it a go, and let us know how it goes.

I have seen a lot of motion in the direction of making assembler behave similarly to other languages. Hard to say, but that irvine package might even ship with something similar to function prototypes to point you in the right direction. I have some masm stuff like that.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 55
Reputation: RayvenHawk is an unknown quantity at this point 
Solved Threads: 1
RayvenHawk RayvenHawk is offline Offline
Junior Poster in Training
 
0
  #5
22 Days Ago
Originally Posted by dan63043 View Post
Goto http://cis.ysu.edu/~rick/class3714/ch5.html and search for OpenInputFile and you will find the three functions documented near one another.

I see that you need to use EAX after that first call, the rest should follow naturally from the info at that URL. Give it a go, and let us know how it goes.

I have seen a lot of motion in the direction of making assembler behave similarly to other languages. Hard to say, but that irvine package might even ship with something similar to function prototypes to point you in the right direction. I have some masm stuff like that.
Dan,

Thanks for that link it really helped. I was able to read in a file and output it to a new one. Now I'm needing a little help with the 2nd half of the assignment.

We were given an encrypted file and we need to read it in and decrypt it using XOR (and the HEX decode number).

What's happening is it exports to a file, but it's a mixture of useless words and still some special characters. It's suppose to be a question for us to answer. Can you look at my code and see where I'm making my mistake?

  1. INCLUDE Irvine32.inc
  2. .data
  3. BUFFER_SIZE = 5000
  4. buffer BYTE BUFFER_SIZE DUP(?)
  5. robert BYTE "inputfile.txt",0
  6. filenam BYTE "testing.txt",0
  7. fileHandle DWORD ?
  8. bytesRead DWORD ?
  9. a1 DWORD ?
  10.  
  11. .code
  12. main PROC
  13.  
  14. ;--------------------------------------------------------;
  15. ; Open File ;
  16. ;--------------------------------------------------------;
  17. mov edx,OFFSET robert
  18. call OpenInputFile
  19. mov fileHandle,eax
  20.  
  21. ;--------------------------------------------------------;
  22. ; Read file content into buffer ;
  23. ;--------------------------------------------------------;
  24. mov eax,fileHandle
  25. mov edx,OFFSET buffer
  26. mov ecx,BUFFER_SIZE
  27. call ReadFromFile
  28. mov bytesRead,eax
  29. mov eax,bytesRead
  30.  
  31. ;-------------------------------------------------------;
  32. ; Copy content of buffer and decrypt ;
  33. ;-------------------------------------------------------;
  34. mov a1,edx
  35. xor a1,0ffh
  36.  
  37. ;--------------------------------------------------------;
  38. ; Create output file and write buffer to file ;
  39. ;--------------------------------------------------------;
  40. mov edx, OFFSET filenam
  41. call CreateOutputFile
  42. mov fileHandle,eax
  43. mov eax,fileHandle
  44. mov edx,OFFSET buffer
  45. mov edx, a1 ; Copy decryted information into EDX
  46. mov ecx,BUFFER_SIZE
  47. call WriteToFile
  48. mov bytesRead,eax
  49.  
  50.  
  51. call CloseFile ; Close file
  52.  
  53. exit
  54. main ENDP
  55.  
  56. END main

Thanks.
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."

Programmers - Making other people rich for over 50yrs.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 33
Reputation: dan63043 is an unknown quantity at this point 
Solved Threads: 4
dan63043 dan63043 is offline Offline
Light Poster
 
0
  #6
22 Days Ago
A few items:

You XOR a DWORD with 0ffh, but you need to XOR each byte in the buffer, not some randomly chosen DWORD in memory.

So, point something at your buffer and XOR byte-wise for the length of the bufffer.

I see a general misunderstanding of the "write" function call when you put the offset to the buffer in edx, then immediately put your a1 variable into edx. Now the function could point at just about anything and start printing garbage.

Another thing. If your file is over 5000 bytes long, your program is inadequate. It should sit in a loop, reading and writing until it reaches the end-of-file (EOF).
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 55
Reputation: RayvenHawk is an unknown quantity at this point 
Solved Threads: 1
RayvenHawk RayvenHawk is offline Offline
Junior Poster in Training
 
0
  #7
21 Days Ago
Originally Posted by dan63043 View Post
A few items:

You XOR a DWORD with 0ffh, but you need to XOR each byte in the buffer, not some randomly chosen DWORD in memory.

So, point something at your buffer and XOR byte-wise for the length of the bufffer.

I see a general misunderstanding of the "write" function call when you put the offset to the buffer in edx, then immediately put your a1 variable into edx. Now the function could point at just about anything and start printing garbage.

Another thing. If your file is over 5000 bytes long, your program is inadequate. It should sit in a loop, reading and writing until it reaches the end-of-file (EOF).
Ok I'm tired of waiting for the professor to get back to me, so can you give me an example of how to use the XOR in the context I need? Not asking for you to give me the code to solve my assignment, but something that would give me a better understanding of how to use XOR for this purpose. Honestly the book only gives about 2 lines to discuss how it works but no useful examples on how to use it.
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."

Programmers - Making other people rich for over 50yrs.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 33
Reputation: dan63043 is an unknown quantity at this point 
Solved Threads: 4
dan63043 dan63043 is offline Offline
Light Poster
 
0
  #8
21 Days Ago
I don't have an assembler on this box, so I wrote this in the old MS-DOS debug command. That's why it looks a little funny, isn't optimal, whatever, but hey, we're just making the best of a bad situation.

I did this by word-sized chunks, not bytes.

  1. 0B0E:0100 B90300 MOV CX,0003
  2. 0B0E:0103 BB0002 MOV BX,0200
  3. 0B0E:0106 8B07 MOV AX,[BX]
  4. 0B0E:0108 35FFFF XOR AX,FFFF
  5. 0B0E:010B 8907 MOV [BX],AX
  6. 0B0E:010D 43 INC BX
  7. 0B0E:010E 43 INC BX
  8. 0B0E:010F 49 DEC CX
  9. 0B0E:0110 75F4 JNZ 0106
  10. 0B0E:0112 C3 RET

The data at start is the first six characters starting at 200h:
0B0E:0200 9E 9D 9C 9B 9A 99 <= unprintable chars.
After running:
0B0E:0200 61 62 63 64 65 66 <= abcdef
Last edited by dan63043; 21 Days Ago at 2:19 am. Reason: spelling
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC