Sign in to follow this  
Followers 0
Ravenlark

DLL Call to determine file encryption

9 posts in this topic

#1 ·  Posted (edited)

I have been trying to figure out how to use DLLCall to get encryption attributes.

I can make the DLL run, but I have no idea how to get the returned list of values; all it returns is 1 for successfull.

The MSDN documentation is:

The FileEncryptionStatus function retrieves the encryption status of the specified file.


BOOL FileEncryptionStatus(
  LPCTSTR lpFileName,
  LPDWORD lpStatus
);

Parameters
lpFileName 
[in] Pointer to a null-terminated string that specifies the name of the file. 
lpStatus 
[out] Pointer to a variable that receives the encryption status of the file. This parameter can be one of the following values. Value Meaning 
FILE_ENCRYPTABLE The file can be encrypted. 
FILE_IS_ENCRYPTED The file is encrypted. 
FILE_READ_ONLY The file is a read-only file. 
FILE_ROOT_DIR The file is a root directory. Root directories cannot be encrypted. 
FILE_SYSTEM_ATTR The file is a system file. System files cannot be encrypted. 
FILE_SYSTEM_DIR The file is a system directory. System directories cannot be encrypted. 
FILE_SYSTEM_NOT_SUPPORT The file system does not support file encryption. 
FILE_UNKNOWN The encryption status is unknown. The file may be encrypted. 
FILE_USER_DISALLOWED Reserved for future use. 

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

My DLLCall:

$Result = DllCall("Advapi32.dll","int","FileEncryptionStatus","str","C:\Anyfile","str","")

The second parameter is a pointer to a variable to hold the returned result, but I have no clue how to make that work after reading the DLLCall thread and the Beta documentation. Anyone have any ideas?

Thanks.

Edited by Ravenlark

Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain

Share this post


Link to post
Share on other sites



I have been trying to figure out how to use DLLCall to get encryption attributes.

I can make the DLL run, but I have no idea how to get the returned list of values; all it returns is 1 for successfull.

The MSDN documentation is:

The FileEncryptionStatus function retrieves the encryption status of the specified file.
BOOL FileEncryptionStatus(
  LPCTSTR lpFileName,
  LPDWORD lpStatus
);

Parameters
lpFileName 
[in] Pointer to a null-terminated string that specifies the name of the file. 
lpStatus 
[out] Pointer to a variable that receives the encryption status of the file. This parameter can be one of the following values. Value Meaning 
FILE_ENCRYPTABLE The file can be encrypted. 
FILE_IS_ENCRYPTED The file is encrypted. 
FILE_READ_ONLY The file is a read-only file. 
FILE_ROOT_DIR The file is a root directory. Root directories cannot be encrypted. 
FILE_SYSTEM_ATTR The file is a system file. System files cannot be encrypted. 
FILE_SYSTEM_DIR The file is a system directory. System directories cannot be encrypted. 
FILE_SYSTEM_NOT_SUPPORT The file system does not support file encryption. 
FILE_UNKNOWN The encryption status is unknown. The file may be encrypted. 
FILE_USER_DISALLOWED Reserved for future use. 

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

My DLLCall:

$Result = DllCall("Advapi32.dll","int","FileEncryptionStatus","str","C:\Anyfile","str","")

The second parameter is a pointer to a variable to hold the returned result, but I have no clue how to make that work after reading the DLLCall thread and the Beta documentation. Anyone have any ideas?

Thanks.

I would imagine that would be under $Result[2].

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I would imagine that would be under $Result[2].

I thought so too, but it returns a little square box for some reason; is it possible the return value is in Unicode and the msgbox cannot process it?

Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Global Const $FILE_ENCRYPTABLE          =   0
Global Const $FILE_IS_ENCRYPTED         =   1
Global Const $FILE_READ_ONLY            =   8
Global Const $FILE_ROOT_DIR             =   3
Global Const $FILE_SYSTEM_ATTR          =   2
Global Const $FILE_SYSTEM_DIR           =   4
Global Const $FILE_SYSTEM_NOT_SUPPORT   =   6
Global Const $FILE_UNKNOWN              =   5
Global Const $FILE_USER_DISALLOWED      =   7
$Location = @DesktopDir & 'test.txt'
$Result = DllCall("Advapi32.dll","int","FileEncryptionStatus","ptr",$Location,"ptr",0)
MsgBox(0,'', $Result[2])
Try that. You had 'str' it states it's a pointer.

Edit:

Blah, useless post, it's failing for me lol.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Global $enc_status[9] = ["FILE_ENCRYPTABLE","FILE_IS_ENCRYPTED", "FILE_SYSTEM_ATTR", "FILE_ROOT_DIR", _
    "FILE_SYSTEM_DIR", "FILE_UNKNOWN", "FILE_SYSTEM_NOT_SUPPORT", "FILE_USER_DISALLOWED", "FILE_READ_ONLY"]
$message = "choose a file."

$var = FileOpenDialog($message, ".", "All (*.*)", 1 + 2)

If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
    
    $p = DllStructCreate("int")
    $Result = DllCall("Advapi32.dll", "int", "FileEncryptionStatus", "str", $var, "ptr", DllStructGetPtr($p))
    If $Result[0] = 0 Then
        _GetLastErrorMessage("Error")
    Else
        MsgBox(0, "test", $enc_status[DllStructGetData($p, 1)])
    EndIf
EndIf
;===============================================
;    _GetLastErrorMessage($DisplayMsgBox="")
;    Format the last windows error as a string and return it
;    if $DisplayMsgBox <> "" Then it will display a message box w/ the error
;    Return        Window's error as a string
;===============================================
Func _GetLastErrorMessage($DisplayMsgBox = "")
    Local $ret, $s
    Local $p = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
    
    If @error Then Return ""
    
    $ret = DllCall("Kernel32.dll", "int", "GetLastError")
    
    $ret = DllCall("kernel32.dll", "int", "FormatMessage", _
            "int", $FORMAT_MESSAGE_FROM_SYSTEM, _
            "ptr", 0, _
            "int", $ret[0], _
            "int", 0, _
            "ptr", DllStructGetPtr($p), _
            "int", 4096, _
            "ptr", 0)
    $s = DllStructGetData($p, 1)
    If $DisplayMsgBox <> "" Then MsgBox(0, "_GetLastErrorMessage", $DisplayMsgBox & @CRLF & $s)
    Return $s
EndFunc   ;==>_GetLastErrorMessage

Edit: updated with array instead of constants.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Ha!! I never get them when I have to use DLLStructCreate(), nice one Gary!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Global $enc_status[9] = ["FILE_ENCRYPTABLE","FILE_IS_ENCRYPTED", "FILE_SYSTEM_ATTR", "FILE_ROOT_DIR", _
    "FILE_SYSTEM_DIR", "FILE_UNKNOWN", "FILE_SYSTEM_NOT_SUPPORT", "FILE_USER_DISALLOWED", "FILE_READ_ONLY"]
$message = "choose a file."

$var = FileOpenDialog($message, ".", "All (*.*)", 1 + 2)

If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
    
    $p = DllStructCreate("int")
    $Result = DllCall("Advapi32.dll", "int", "FileEncryptionStatus", "str", $var, "ptr", DllStructGetPtr($p))
    If $Result[0] = 0 Then
        _GetLastErrorMessage("Error")
    Else
        MsgBox(0, "test", $enc_status[DllStructGetData($p, 1)])
    EndIf
EndIf
;===============================================
;    _GetLastErrorMessage($DisplayMsgBox="")
;    Format the last windows error as a string and return it
;    if $DisplayMsgBox <> "" Then it will display a message box w/ the error
;    Return        Window's error as a string
;===============================================
Func _GetLastErrorMessage($DisplayMsgBox = "")
    Local $ret, $s
    Local $p = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
    
    If @error Then Return ""
    
    $ret = DllCall("Kernel32.dll", "int", "GetLastError")
    
    $ret = DllCall("kernel32.dll", "int", "FormatMessage", _
            "int", $FORMAT_MESSAGE_FROM_SYSTEM, _
            "ptr", 0, _
            "int", $ret[0], _
            "int", 0, _
            "ptr", DllStructGetPtr($p), _
            "int", 4096, _
            "ptr", 0)
    $s = DllStructGetData($p, 1)
    If $DisplayMsgBox <> "" Then MsgBox(0, "_GetLastErrorMessage", $DisplayMsgBox & @CRLF & $s)
    Return $s
EndFunc   ;==>_GetLastErrorMessage

Edit: updated with array instead of constants.

Wow. Its going to take me a bit to fully understand what I am doing with this, but it works. Thanks gafrost.

Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

instead of a struct why not just use int_ptr ?

Global $enc_status[9] = ["FILE_ENCRYPTABLE","FILE_IS_ENCRYPTED", "FILE_SYSTEM_ATTR", "FILE_ROOT_DIR", _
    "FILE_SYSTEM_DIR", "FILE_UNKNOWN", "FILE_SYSTEM_NOT_SUPPORT", "FILE_USER_DISALLOWED", "FILE_READ_ONLY"]
$message = "choose a file."

$var = FileOpenDialog($message, ".", "All (*.*)", 1 + 2)

If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
   
    $Result = DllCall("Advapi32.dll", "int", "FileEncryptionStatus", "str", $var, "int_ptr", 0)
    If $Result[0] = 0 Then
        _GetLastErrorMessage("Error")
    Else
        MsgBox(0, "test", $enc_status[$Result[2]])
    EndIf
EndIf
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

instead of a struct why not just use int_ptr ?

Global $enc_status[9] = ["FILE_ENCRYPTABLE","FILE_IS_ENCRYPTED", "FILE_SYSTEM_ATTR", "FILE_ROOT_DIR", _
    "FILE_SYSTEM_DIR", "FILE_UNKNOWN", "FILE_SYSTEM_NOT_SUPPORT", "FILE_USER_DISALLOWED", "FILE_READ_ONLY"]
$message = "choose a file."

$var = FileOpenDialog($message, ".", "All (*.*)", 1 + 2)

If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
   
    $Result = DllCall("Advapi32.dll", "int", "FileEncryptionStatus", "str", $var, "int_ptr", 0)
    If $Result[0] = 0 Then
        _GetLastErrorMessage("Error")
    Else
        MsgBox(0, "test", $enc_status[$Result[2]])
    EndIf
EndIf
That'll work also, forgot about the int_ptr for dllcall

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0