Copy raw file image
-
ReadAllBytes as the name implies reads all bytes, regardless of what they should be interpreted as. Its up to you to then translate them into whatever it is you wish.
If the post was helpful, please vote, eh! Current activities: Playing Star Craft II. Don't bother me, eh? Now and forever, defiant to the end. What is Multiple Sclerosis[^]?
-
I ran a simple experiement, read all byte of HelloWorld.exe and write it to second file - it didn't run and OS complained invalid image
dev
-
I ran a simple experiement, read all byte of HelloWorld.exe and write it to second file - it didn't run and OS complained invalid image
dev
How did you write the new file? Post your code snipplet.
-
hello How can you copy raw file image into a byte[]? I've tried, File.Open, then read bytes with different encoding - no luck Should I try http://msdn.microsoft.com/en-us/library/a4b8basy.aspx[^] Thanks
dev
what do you mean by "raw file image"? is it a file containing an image (i.e. header plus pixel data)? is it a file containing the raw data of an image (i.e. pixel data only)? is it the "image" of an executaable? you can read( or write) all the bytes of a file at once using File.ReadAllBytes (WriteAllBytes). If you don't want to have them all at once in memory, use a BinaryReader (BinaryWriter). And what do you mean by "encoding"? if it refers to the Encoding class, that one only applies to text. if it refers to the way pixels get represented, that one is called PixelFormat. Please learn to ask questions properly. And don't say "it didn't run and OS complained invalid image", show the code and the exact compile-time or run-time error message(s). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
This won't work - I need raw file image, include header + data http://www.michaelyip.me.uk/projects/SaCF.pdf[^]
dev
Yeah, it will work since I used it to read and parse PE format executables myself.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
I ran a simple experiement, read all byte of HelloWorld.exe and write it to second file - it didn't run and OS complained invalid image
dev
Then you did something else wrong in your code. Post the read and write sections and we may be able to tell you where that is.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
hello How can you copy raw file image into a byte[]? I've tried, File.Open, then read bytes with different encoding - no luck Should I try http://msdn.microsoft.com/en-us/library/a4b8basy.aspx[^] Thanks
dev
If I'm right then he asks for a way to read all the file data plus the file system (NTFS as example) specific information. On a hard disk there are also a file header / footer for every file. Now this data he wants to read (and maybe) write. 1. Handle a file is the wrong approach you have to handle the file system in your case. 2. There is no class (or?) to read/write from/to the hard disk at this i/o level in C#. 3. Take a look at CreateFile. There is a possibility to read the physical disk.
Greetings Covean
-
what do you mean by "raw file image"? is it a file containing an image (i.e. header plus pixel data)? is it a file containing the raw data of an image (i.e. pixel data only)? is it the "image" of an executaable? you can read( or write) all the bytes of a file at once using File.ReadAllBytes (WriteAllBytes). If you don't want to have them all at once in memory, use a BinaryReader (BinaryWriter). And what do you mean by "encoding"? if it refers to the Encoding class, that one only applies to text. if it refers to the way pixels get represented, that one is called PixelFormat. Please learn to ask questions properly. And don't say "it didn't run and OS complained invalid image", show the code and the exact compile-time or run-time error message(s). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
thanks yes you understand me - i will post the code but you're suggesting this can't be done in dotnet?
dev
No I do not understand you, you fail to provide necessary information and ask a clear question. And no I did not suggest anything would be possible or impossible, as it is still completely unclear what you want in the first place. Now stop reading things that are not present; and start providing information that is necessary but missing. :mad:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
No I do not understand you, you fail to provide necessary information and ask a clear question. And no I did not suggest anything would be possible or impossible, as it is still completely unclear what you want in the first place. Now stop reading things that are not present; and start providing information that is necessary but missing. :mad:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
If I'm right then he asks for a way to read all the file data plus the file system (NTFS as example) specific information. On a hard disk there are also a file header / footer for every file. Now this data he wants to read (and maybe) write. 1. Handle a file is the wrong approach you have to handle the file system in your case. 2. There is no class (or?) to read/write from/to the hard disk at this i/o level in C#. 3. Take a look at CreateFile. There is a possibility to read the physical disk.
Greetings Covean
-
Please don't remove any messages that have been replied to. It is against the forum guidelines as it results in messy threads. Yours said: thanks yes you understand me - i will post the code but you're suggesting this can't be done in dotnet? which is what you also replied to Covean !?!?!? X|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
thanks yes you understand me - i will post the code but you're suggesting this can't be done in dotnet?
dev
He didn't "understand" you. He frickin' guessed at it using the link you posted and your replies in this thread. I took a look at the link and guessed that you were trying to read the entire contents of the file, uninterpreted, because of the HexEdit screen shots in the link and your mentioning of using Encoding to read the file. You made no mention at all of what you were ultimately trying to do with this information. Luc is correct. You still don't know how to ask a question in a format that is answerable, nor do you provide any of the details to questions that would fill in the missing bits of information critical to giving you the correct answer on the first try. You've demonstrated a history of this. People have to constantly guess at what you're talking about.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
thanks yes you understand me - i will post the code but you're suggesting this can't be done in dotnet?
dev
This can be done in .NET / C# by using PInvoke. But on the other hand I think that accessing the file system directly from C# should be avoided. If you have problems to get started with this, google for "PInvoke" and try to figure out how to call Windows API from within C#. PS: To get a better start with this forum and all those helper/cpians here, please read the pinned forum guidelines at the start and try to think about / rephrase your question. One more sentences could avoid further inquiry.
Greetings Covean
-
This can be done in .NET / C# by using PInvoke. But on the other hand I think that accessing the file system directly from C# should be avoided. If you have problems to get started with this, google for "PInvoke" and try to figure out how to call Windows API from within C#. PS: To get a better start with this forum and all those helper/cpians here, please read the pinned forum guidelines at the start and try to think about / rephrase your question. One more sentences could avoid further inquiry.
Greetings Covean
-
Please don't remove any messages that have been replied to. It is against the forum guidelines as it results in messy threads. Yours said: thanks yes you understand me - i will post the code but you're suggesting this can't be done in dotnet? which is what you also replied to Covean !?!?!? X|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
He didn't "understand" you. He frickin' guessed at it using the link you posted and your replies in this thread. I took a look at the link and guessed that you were trying to read the entire contents of the file, uninterpreted, because of the HexEdit screen shots in the link and your mentioning of using Encoding to read the file. You made no mention at all of what you were ultimately trying to do with this information. Luc is correct. You still don't know how to ask a question in a format that is answerable, nor do you provide any of the details to questions that would fill in the missing bits of information critical to giving you the correct answer on the first try. You've demonstrated a history of this. People have to constantly guess at what you're talking about.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
screw you sis go find someone else to argue with, if you don't know the sh*t, don't litter the forum pass on to another thread which you actually have something to offer
dev
The only way someone can actually offer you anything useful is if they take a wild ass guess at what your trying to do.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
The only way someone can actually offer you anything useful is if they take a wild ass guess at what your trying to do.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
@devvvy: YOU don´t understand: You were asked to provide the piece of code making troubles .... you didn´t, instead you started to moan ... ANYWAY:
byte[] an_image = File.ReadAllBytes("hello_world.exe");
File.WriteAllBytes("another_hello_world.exe", an_image);No P/Invoke, not really difficult ...