看雪软件安全论坛



返回   看雪软件安全论坛 > 软件安全 > 『安全编程论坛』

『安全编程论坛』 原『Win32/Win64编程』 版块,讨论编程技术,稍侧重安全技术相关的编程

Expired Thread 该主题: "【求助】如何通过文件句柄得到文件路径?" 因在一年内没有任何回复而自动关闭。
如果您还对该主题感兴趣或者想参与对此主题的讨论,请您重新发表一篇相关的新主题。

发表新主题 关闭主题
 
主题工具 显示模式
雪天使
级别:2 | 在线时长:16小时 | 升级还需:5小时级别:2 | 在线时长:16小时 | 升级还需:5小时

初级会员
初级会员

资 料:
注册日期: Jun 2007
帖子: 22 雪天使 品行端正
精华: 0
现金: 101 Kx
1 旧 2008-01-05, 19:15:42 默认 【求助】如何通过文件句柄得到文件路径?
雪天使 当前离线

初学HOOK挂钩,尝试挂钩WriteFile函数,以下是该函数原形
function WriteFile(hFile: THandle; const Buffer; nNumberOfBytesToWrite: DWORD; var lpNumberOfBytesWritten: DWORD; lpOverlapped: POverlapped): BOOL; stdcall;
如何通过文件句柄hFile得到文件路径?Delphi语言实现...

回复时引用此帖 返回顶端
shoooo
级别:40 | 在线时长:1784小时 | 升级还需:61小时级别:40 | 在线时长:1784小时 | 升级还需:61小时级别:40 | 在线时长:1784小时 | 升级还需:61小时级别:40 | 在线时长:1784小时 | 升级还需:61小时

shoooo 的头像

BAN

资 料:
注册日期: Nov 2004
帖子: 2,026 shoooo 不日成名
精华: 16
现金: 200 Kx
2 旧 2008-01-05, 20:00:25 默认
shoooo 当前离线

我只会这样

代码:
#include <windows.h>
#pragma comment(lib, "ntdll.lib")
#pragma comment(linker, "/subsystem:windows")
#pragma comment(linker, "/entry:start")
#pragma comment(linker, "/filealign:0x200")


typedef struct _IO_STATUS_BLOCK
{
    LONG Status;
    LONG Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;

typedef struct _FILE_NAME_INFORMATION
{
  ULONG FileNameLength;
  WCHAR FileName[MAX_PATH];
} FILE_NAME_INFORMATION;

__declspec(dllimport) LONG __stdcall ZwQueryInformationFile(
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID FileInformation,
IN ULONG FileInformationLength,
IN ULONG FileInformationClass
);


void start()
{
  char  szFileName[MAX_PATH];
  HANDLE  hFile;
  IO_STATUS_BLOCK  isb;
  FILE_NAME_INFORMATION fni;
  


  GetModuleFileName(NULL, szFileName, MAX_PATH);
  hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  if (hFile != (HANDLE)-1)
  {
    if (ZwQueryInformationFile(hFile, &isb, &fni, sizeof(fni), 9) == 0)
    {
      fni.FileName[fni.FileNameLength/2] = 0;
      MessageBoxW(0, fni.FileName, L"hFile", 0);

    }
    CloseHandle(hFile);

  }
  ExitProcess(0);
}
我感觉应该从取得对象信息来弄这块会好一些

------下载此贴附件最少需要拥有2Kx,方有下载权限。------
上传的附件
文件类型: rar hFile.rar (1.3 KB, 36 次下载) 下载此附件需要消耗2Kx,下载中会自动扣除。
回复时引用此帖 返回顶端
炉子
级别:12 | 在线时长:205小时 | 升级还需:16小时级别:12 | 在线时长:205小时 | 升级还需:16小时级别:12 | 在线时长:205小时 | 升级还需:16小时

炉子 的头像

普通会员
普通会员

资 料:
注册日期: Jul 2007
帖子: 309 炉子 品行端正
精华: 3
现金: 30 Kx
3 旧 2008-01-05, 20:42:47 默认
帅哥 炉子 当前在线

俺也是ZwQueryInformationFile

回复时引用此帖 返回顶端
雪天使
级别:2 | 在线时长:16小时 | 升级还需:5小时级别:2 | 在线时长:16小时 | 升级还需:5小时

初级会员
初级会员

资 料:
注册日期: Jun 2007
帖子: 22 雪天使 品行端正
精华: 0
现金: 101 Kx
4 旧 2008-01-06, 19:19:07 默认
雪天使 当前离线

GetFileInformationByHandle函数可以得到文件的相关信息,不过得不到文件的路径.
还有楼上的代码是C的,看不懂.哪位大牛帮忙翻译一下?

回复时引用此帖 返回顶端
foxabu
级别:16 | 在线时长:324小时 | 升级还需:33小时

foxabu 的头像

高级会员
高级会员

资 料:
注册日期: Oct 2005
帖子: 1,093 foxabu 品行端正
精华: 13
现金: 206 Kx
5 旧 2008-01-06, 19:50:36 默认
foxabu 当前离线

引用:
最初由 雪天使发布 查看帖子
GetFileInformationByHandle函数可以得到文件的相关信息,不过得不到文件的路径.
还有楼上的代码是C的,看不懂.哪位大牛帮忙翻译一下?
GetFileInformationByHandleEx Function

Retrieves file information for the specified file.


BOOL WINAPI GetFileInformationByHandleEx(
  __in          HANDLE hFile,
  __in          FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
  __out         LPVOID lpFileInformation,
  __in          DWORD dwBufferSize
);

Parameters
hFile 
A handle to the file. 

This handle should not be a pipe handle. The GetFileInformationByHandleEx function does not work with pipe handles.

FileInformationClass 
The type of information to be returned to the calling application. For a list of values, see FILE_INFO_BY_HANDLE_CLASS.

lpFileInformation 
A pointer to the buffer that receives the requested file information. The structure that is returned corresponds to the class that is specified by FileInformationClass.

FileInformationClass FileInformation structure returned 
FileBasicInfo  FILE_BASIC_INFO 
FileStandardInfo FILE_STANDARD_INFO 
FileNameInfo FILE_NAME_INFO 
FileStreamInfo FILE_STREAM_INFO 
FileCompressionInfo FILE_COMPRESSION_INFO 
FileAttributeTagInfo FILE_ATTRIBUTE_TAG_INFO 
FileIdBothDirectoryInfo FILE_ID_BOTH_DIR_INFO 
FileIdBothDirectoryRestartInfo FILE_ID_BOTH_DIR_INFO 

dwBufferSize 
The size of the lpFileInformation buffer, in bytes.

Return Value
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.

Remarks
If FileInformationClass is FileStreamInfo and the calls succeed but no streams are returned, the error that is returned by GetLastError is ERROR_HANDLE_EOF.

Certain file information classes behave slightly differently on different operating system releases. These classes are supported by the underlying drivers, and any information they return is subject to change between operating system releases.

This function is declared in Fileextd.h and implemented in Fileextd.lib; both are available for download at MSDN on the Win32 FileID API Library page.

Transacted Operations
If there is a transaction bound to the thread at the time of the call, then the function returns the compressed file size of the isolated file view.

Requirements

这个函数貌似可以返回。。 只是我感觉你的SDK 里面没有的可能性极大。 

回复时引用此帖 返回顶端
发表新主题 关闭主题

书签
Expired Thread 该主题: "【求助】如何通过文件句柄得到文件路径?" 因在一年内没有任何回复而自动关闭。
如果您还对该主题感兴趣或者想参与对此主题的讨论,请您重新发表一篇相关的新主题。


主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子
论坛启用 BB 代码
论坛启用 表情符号
论坛跳转

相似的主题
主题 主题作者 版面 回复 最后发表
【求助】已知TEdit、TComboBox类控件句柄如何进行控件通讯?采用SDK的C方式 mycaipeng 『安全编程论坛』 3 2007-12-17 22:29:58
【求助】如何得到其他程序的窗口句柄 Troy 『求助问答区』 1 2007-09-14 09:47:01
【求助】如何通过VC编程卸载其它进程的DLL模块? HSXiaogang 『安全编程论坛』 6 2007-08-27 16:34:32
【求助】如何通过堆栈逆向寻找关键 HaiNaby 『软件调试论坛』 10 2007-07-09 12:48:04
【求助】HOOK NTCreateProcess后得到EXE文件名 langouster 『软件调试论坛』 10 2007-05-26 02:45:14


所有时间均为北京时间。现在的时间是 22:04:06


©2000-2010 PEdiy.com All rights reserved.By PEDIY
Powered by vBulletin ®Jelsoft Enterprises Ltd. 增强包制作PHP源动力.界面支持standme Studio.