create account

Get File Size with Kernel32 Api and Ntdll Api (Native Api) by ntstatus

View this thread on: hive.blogpeakd.comecency.com
· @ntstatus · (edited)
Get File Size with Kernel32 Api and Ntdll Api (Native Api)
[![filesize.png](https://images.ecency.com/DQmdNkymP4P4Q5MW94vmE3SVCySnupQefhL4nnHpHugUJsq/filesize.png)](https://d.tube/v/ntstatus01/QmVSBghLksnen6swvTrQ1DLbCMUXR6RW6vLN1hEMv2TiA4)

[DTube Video Link](https://d.tube/#!/v/ntstatus01/QmVSBghLksnen6swvTrQ1DLbCMUXR6RW6vLN1hEMv2TiA4)
```
#pragma comment(lib, "ntdll.lib") 

#include <Windows.h>
#include <winternl.h>

#define FileStandardInformation 5

typedef struct _FILE_STANDARD_INFORMATION {
 LARGE_INTEGER AllocationSize;
 LARGE_INTEGER EndOfFile;// file size
 ULONG         NumberOfLinks;
 BOOLEAN       DeletePending;
 BOOLEAN       Directory;
} FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;

BOOL GetFileSizeNtdll(PCWSTR path, PLARGE_INTEGER pFSize)
{
 UNICODE_STRING pathUniStr;
 OBJECT_ATTRIBUTES obja;
 IO_STATUS_BLOCK iost;
 HANDLE hFile;
 FILE_STANDARD_INFORMATION fileStInfo;

 RtlDosPathNameToNtPathName_U(path, &pathUniStr, NULL, NULL);
 InitializeObjectAttributes(&obja, &pathUniStr, OBJ_CASE_INSENSITIVE, NULL, NULL);
 if (!NT_SUCCESS(NtCreateFile(&hFile, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &obja, &iost, NULL, 0, 0, FILE_OPEN, 0, NULL, 0)))
  return FALSE;
 if (!NT_SUCCESS(NtQueryInformationFile(hFile, &iost, &fileStInfo, sizeof(fileStInfo), FileStandardInformation)))
  return FALSE;
 *pFSize = fileStInfo.EndOfFile;
 NtClose(hFile);
}
BOOL GetFileSizeKernel32(PCWSTR path, PLARGE_INTEGER pFSize)
{
 HANDLE hFile;
 BOOL ret;
 if ((hFile = CreateFileW(path, FILE_READ_ATTRIBUTES | SYNCHRONIZE, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
  return FALSE;
 ret= GetFileSizeEx(hFile, pFSize);
 CloseHandle(hFile);
 return ret;
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
 LARGE_INTEGER fSize1,fSize2;

 //Method 1
 GetFileSizeKernel32(L"C:\\Users\\la\\Desktop\\test.txt",&fSize1);

 //Method 2
 GetFileSizeNtdll(L"C:\\Users\\la\\Desktop\\test.txt", &fSize2);
 return 0;
}
```

Please Vote this post if you like it.
Please Follow me if you like my posts.
If you have any questions about this post, ask in comments.
Follow me on : 
     [DTube](https://d.tube/#!/c/ntstatus01)
👍  ,
👎  
properties (23)
authorntstatus
permlinkget-file-size-with-kernel32
categoryprogramming
json_metadata{"links":["https://d.tube/v/ntstatus01/QmVSBghLksnen6swvTrQ1DLbCMUXR6RW6vLN1hEMv2TiA4","https://d.tube/#!/v/ntstatus01/QmVSBghLksnen6swvTrQ1DLbCMUXR6RW6vLN1hEMv2TiA4","https://d.tube/#!/c/ntstatus01"],"tags":["programming","windows","dtube"],"app":"ecency/3.0.19-vision","format":"markdown+html","image":["https://images.ecency.com/DQmdNkymP4P4Q5MW94vmE3SVCySnupQefhL4nnHpHugUJsq/filesize.png"]}
created2021-09-17 19:44:18
last_update2021-09-22 20:40:03
depth0
children1
last_payout2021-09-24 19:44:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,122
author_reputation5,617,331,478
root_title"Get File Size with Kernel32 Api and Ntdll Api (Native Api)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,364,506
net_rshares6,678,891,954
author_curate_reward""
vote details (3)
@gangstalking ·
Electronic-terrorism, voice to skull and neuro monitoring on Hive and Steem. You can ignore this, but your going to wish you didnt soon. This is happening whether you believe it or not. https://ecency.com/fyrstikken/@fairandbalanced/i-am-the-only-motherfucker-on-the-internet-pointing-to-a-direct-source-for-voice-to-skull-electronic-terrorism
👎  ,
properties (23)
authorgangstalking
permlinkre-ntstatus-get-file-size-with-kernel32-20210918t163340012z
categoryprogramming
json_metadata{"app":"hive-bot/0.6.3"}
created2021-09-18 16:33:42
last_update2021-09-18 16:33:42
depth1
children0
last_payout2021-09-25 16:33:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length343
author_reputation-67,597,107,868,724
root_title"Get File Size with Kernel32 Api and Ntdll Api (Native Api)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,384,823
net_rshares-28,119,345,314
author_curate_reward""
vote details (2)