|
|
|
|
#1 |
|
Junior Member
Join Date: May 2014
Posts: 22
|
Reading physical drive
Good day!
I'm trying to read a physical drive, but I get an error. Please tell me how to do it? code: ReadFile must return non-zero, but it returns 0 and GetLastError returns 80. Thanks for your help! |
|
|
|
|
|
#2 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
You've used ?e for your ReadFile call which means $5 contains the last error code already. Calling GetLastError yourself will not return what you expect as something else since your System call (or even the System plug-in itself) will have either cleared or set the last error code. Use i .s on the end of your ReadFile call instead of ?e (or use i .r5 and remove the Pop $5).
Stu |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: May 2014
Posts: 22
|
Afrow UK, thank you. If I replace it to next code:
code: When "$5" = "error". |
|
|
|
|
|
#4 |
|
Major Dude
Join Date: Feb 2007
Posts: 672
|
A physical drive is named: \\.\PhysicalDrive... (so a dot instead of questionmark)
And as you have to escape the backslash, use code: |
|
|
|
|
|
#5 | |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Quote:
Stu |
|
|
|
|
|
|
#6 | |
|
Major Dude
Join Date: Feb 2007
Posts: 672
|
Quote:
Anyway, this is where I got the idea of escaping: http://forums.winamp.com/showpost.ph...41&postcount=2 It seems to have been working for f0rt |
|
|
|
|
|
|
#7 | |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Quote:
Stu |
|
|
|
|
|
|
#8 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Remove the space after ReadFile and before the (.
Stu |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: May 2014
Posts: 22
|
|
|
|
|
|
|
#10 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
I don't think this is possible any more:
http://support.microsoft.com/kb/942448 What exactly are you trying to do? Stu |
|
|
|
|
|
#11 |
|
Junior Member
Join Date: May 2014
Posts: 22
|
I'm trying read drive on WinXP, but function must work on any system. I think this KB does not matter, because there is considered newer systems. In addition exists utilities that successfully read and write drive on any system, but don't have all needed functions, which can be implemented independently.
This is for the treatment of drives from viruses in MBR and similar work. Now I use a third-party utility, but its capabilities are not always enough and want the flexibility to manage data. |
|
|
|
|
|
#12 | |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Quote:
In order to access a disk directly on Vista and above it looks like you will need to be running as LOCAL SYSTEM, e.g. as a Windows service (or you can use PsExec). Stu |
|
|
|
|
|
|
#13 | ||
|
Junior Member
Join Date: May 2014
Posts: 22
|
Quote:
Quote:
Thank you all for your help, it is very valuable. |
||
|
|
|
|
|
#14 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Does it work on XP but not on 7? Or does it work on neither?
This is the my code (ReadFile fails with 87 - invalid parameter). Stucode: |
|
|
|
|
|
#16 | |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Quote:
Stu |
|
|
|
|
|
|
#18 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
System::Call "kernel32::ReadFile(i r2, t .r0, i 32, i .r4, i 0) ?e" should probably be *i.r4.
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#19 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
|
|
|
|
|
|
#21 | |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
Quote:
Writing this type of low-level code with the system plugin is not a good idea, working with binary data or whatever you are reading is painful. What are you really trying to do? Detect the filesystem type or something else? IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
|
#22 |
|
Junior Member
Join Date: May 2014
Posts: 22
|
Anders, thank you very much. The problem was that my request is less 512 bytes.
As I said before, it's for the treatment of MBR viruses. My project antisms.com (for now only in Russian, sorry) written on NSIS, and I thank very much all contributors of this forum. |
|
|
|
|
|
#23 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
Well, I think it would be much better to write a plugin, I don't see how all that system::call code is going to be manageable when the codebase gets larger...
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#24 |
|
Junior Member
Join Date: May 2014
Posts: 22
|
Personally for me, much better to use WinAPI, because I do not know C, and any changes I make in the code immediately, without waiting for the author of the plugin.
|
|
|
|
|
|
#25 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
IMHO you basically have to understand C and the WinAPI to really use the system plugin. You have to be able to transform the function declarations listed on MSDN or in a .h file and convert it to system syntax and you have to understand how C strings work and how pointers work if you are going to be reading anything other than strings from a text file.
Messing with the MBR is not something most people should be doing and certainly not if you don't have a basic understanding of C and it's structure layout/padding semantics and how it differs from the system plugin struct syntax. Also, as you have seen, reading from a disk at this low level might have alignment and/or buffer restrictions, you cannot just treat it as a normal file. I personally would not trust a MBR tool if I knew it was written in NSIS. IntOp $PostCount $PostCount + 1 |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|