/** dumpsam.c Dumpsam file (only for Windows) for samdump2 3.x This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. Copyright (C) 2009 Cedric Tissieres */ #ifdef WIN32 #include #include #include #include #include #ifndef WIN32 #include "ntdll.h" #else #include #include #endif /***********************************************************/ /* code from http://www.ivanlef0u.tuxfamily.org/?p=77 */ ULONG EnablePrivilege(char *Privilege) { HANDLE hToken; ULONG Ret=1; TOKEN_PRIVILEGES TP; if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) { printf("Error with OpenProcessToken: %d\n", (int)GetLastError()); Ret=0; goto bye; } if(!LookupPrivilegeValue(NULL, Privilege, &TP.Privileges[0].Luid)) { printf("Error with LookupPrivilegeValue: %d\n", (int)GetLastError()); Ret=0; goto bye; } TP.PrivilegeCount=1; TP.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; if(!AdjustTokenPrivileges(hToken, 0, &TP, 0, NULL, NULL)) { printf("Error with AdjustTokenPrivileges: %d\n", (int)GetLastError()); Ret=0; goto bye; } bye: if(hToken) CloseHandle(hToken); return Ret; } /***********************************************************/ /* code from http://www.ivanlef0u.tuxfamily.org/?p=77 */ void hexdump(unsigned char *data, unsigned int amount) { unsigned int dp, p; const char trans[] = "................................ !\"#$%&'()*+,-./0123456789" ":;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm" "nopqrstuvwxyz{|}~...................................." "....................................................." "........................................"; for (dp = 1; dp <= amount; dp++) { printf ("%02x ", data[dp-1]); if ((dp % 8) == 0) printf (" "); if ((dp % 16) == 0) { printf ("| "); p = dp; for (dp -= 16; dp < p; dp++) printf ("%c", trans[data[dp]]); printf ("\n"); } } if ((amount % 16) != 0) { p = dp = 16 - (amount % 16); for (dp = p; dp > 0; dp--) { printf (" "); if (((dp % 8) == 0) && (p != 8)) printf (" "); } printf (" | "); for (dp = (amount - (16 - p)); dp < amount; dp++) printf ("%c", trans[data[dp]]); } printf ("\n"); return ; } /***********************************************************/ /* code from http://www.ivanlef0u.tuxfamily.org/?p=77 */ int GetFileLCN(HANDLE hFile, int64_t *location, char *error) { ULONG Status; IO_STATUS_BLOCK IoBlock; unsigned char *temp; STARTING_VCN_INPUT_BUFFER VCN; RETRIEVAL_POINTERS_BUFFER Buff; memset(&VCN, 0, sizeof(STARTING_VCN_INPUT_BUFFER)); temp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 0x10000); Status=NtFsControlFile(hFile, NULL, NULL, NULL, &IoBlock, FSCTL_GET_RETRIEVAL_POINTERS, &VCN, sizeof(STARTING_VCN_INPUT_BUFFER), &Buff, sizeof(RETRIEVAL_POINTERS_BUFFER)); if(!NT_SUCCESS(Status)) { sprintf(error,"Error with NtFsControlFile : 0x%x\n", (int)Status); return -1; } // printf("ExtentCount : %d\n", Buff.ExtentCount); *location = Buff.Extents[0].Lcn.QuadPart; /* for(i=0; i