10
May
2009
I finally graduated from UTSA with my bachelors in Computer science with a concentration in Information Security. I also finished my open water scuba certification this weekend and I leave for Mexico in two weeks. Now I can finally take a break.
wootz
Posted in Fact and Truth | No Comments »
27
Apr
2009
I say this pretty much every day. It is like a broken record, it really stresses me. I say if something is broken and doesn’t work correctly fix it right?
Sign, stay tuned for some really cool malware analysis stuff I have been working on since december.
Tags: Malware, rand()
Posted in Fact and Truth | No Comments »
25
Sep
2008
I seem to always need this skeleton code to build a window but I can never seem to memorize the whole thing. I figured I would post it here to make it easier for me to find.
/**
* SimpleWindow v1.0
* @file
*
* 09-24-2008: JPH - Created.
*
* @author Jacob Hammack
*/
#include <windows.h>
/**
* Forces the compiler to link these libraries
*
*/
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "kernel32.lib")
/**
* WindowsMessageLoop processes
*
* @author Jacob Hammack
*/
LRESULT CALLBACK WindowsMessageLoop(HWND WindowHandle, UINT Message, WPARAM WindowParameters, LPARAM MoreWindowsParameters)
{
switch(Message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
return 0;
case WM_SIZE:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(WindowHandle, Message, WindowParameters, MoreWindowsParameters);
}
/**
* WinMain is the main() equivilent for a windows program, execution starts here.
*
* @author Jacob Hammack
*/
int WINAPI WinMain (HINSTANCE CurrentInstance, HINSTANCE PreviousInstance, PSTR CommandLine, int CommandShow)
{
static TCHAR ApplicationName[] = TEXT("SimpleWindow");
HWND WindowHandle;
MSG Message;
WNDCLASS WindowsClass;
WindowsClass.style = CS_HREDRAW | CS_VREDRAW;
WindowsClass.lpfnWndProc = WindowsMessageLoop;
WindowsClass.cbClsExtra = 0;
WindowsClass.cbWndExtra = 0;
WindowsClass.hInstance = CurrentInstance;
WindowsClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WindowsClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WindowsClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
WindowsClass.lpszMenuName = NULL;
WindowsClass.lpszClassName = ApplicationName;
if(!RegisterClass(&WindowsClass))
{
MessageBox(NULL, TEXT("Unable to create a window."), ApplicationName, MB_ICONERROR);
return 0;
}
WindowHandle = CreateWindow(ApplicationName, /* Window Class Name*/
TEXT("Simple Window"), /* Window Caption */
WS_OVERLAPPEDWINDOW, /* Window Style*/
CW_USEDEFAULT, /* Initial X position*/
CW_USEDEFAULT, /* Initial Y position */
300, /* Initial Width of the window*/
100, /* Initial Height of the window */
NULL, /* Parent Window Handle */
NULL, /* Window Menu Handle */
CurrentInstance, /* Instance of the Program Handle*/
NULL); /* Window Creation Parameters */
ShowWindow(WindowHandle, CommandShow);
UpdateWindow(WindowHandle);
while(GetMessage(&Message, NULL, 0, 0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
CC=cl
CFLAGS= /nologo /MT /O2 /TC
LINKS=/link /OUT:simplewindow.exe /SUBSYSTEM:WINDOWS
all: simplewindow
simplewindow: simplewindow.c
$(CC) $(CFLAGS) simplewindow.c $(LINKS)
clean:
del *.exe; del *.obj
Tags: C, GUI, Win32
Posted in C, Win32 | No Comments »
4
Sep
2008
This is a tool I wrote for windows, that will list all of the drives currently mounted. I didn’t know of a better way to show this information from the command line. I might add volume names later
/**
* Drivelist v1.0.1
* @file
*
* 05-25-2008: JPH - Created.
* 08-22-2008: JPH - Added case 0, 1 and 6 to the switch of types.
*
* @author Jacob Hammack
*/
#include <windows.h>
#include <stdio.h>
/**
* List's and prints all mounted drives and their drive type.
*
* @author Jacob Hammack
*/
void ListMountedDrives(void)
{
char Buffer[MAX_PATH];
char *DriveLetter;
int DriveType;
GetLogicalDriveStrings(MAX_PATH, Buffer);
DriveLetter = Buffer;
while (*DriveLetter)
{
if(*DriveLetter == 0)
{
break;
}
DriveType = GetDriveType(DriveLetter);
switch(DriveType)
{
case 0:
printf("%s\tUnknown Type\n", DriveLetter);
break;
case 1:
printf("%s\tInvalid Root Path\n", DriveLetter);
break;
case 2:
printf("%s\tRemoveable Drive\n", DriveLetter);
break;
case 3:
printf("%s\tFixed Drive\n", DriveLetter);
break;
case 4:
printf("%s\tNetwork Drive\n", DriveLetter);
break;
case 5:
printf("%s\tCD-ROM Drive\n", DriveLetter);
break;
case 6:
printf("%s\tRam Drive\n", DriveLetter);
break;
}
DriveLetter = &DriveLetter[strlen(DriveLetter) + 1];
}
}
/**
* Main entry point for the DriveList Application.
*
* @author Jacob Hammack
*/
int main(int argc, char *argv[])
{
printf("Drivelist v1.0.1\nJacob Hammack\nhttp://www.hammackj.com\n\n");
ListMountedDrives();
return 0;
}
CC=cl
CFLAGS= /nologo /MT /O2 /TC
LINKS=/link kernel32.lib /OUT:dl.exe /SUBSYSTEM:CONSOLE
all: drivelist
drivelist: drivelist.c
$(CC) $(CFLAGS) drivelist.c $(LINKS)
clean:
del *.exe; del *.obj
C:\drivelist>dl.exe
Drivelist v1.0.1
Jacob Hammack
http://www.hammackj.com
A:\ Removeable Drive
C:\ Fixed Drive
D:\ Fixed Drive
E:\ CD-ROM Drive
Z:\ Network Drive
C:\drivelist>
Tags: C, Win32
Posted in C, Win32 | No Comments »
27
Jun
2008
In a few of the tools that I have written, I have needed to list the windows file system recursively. While .Net makes this much easier, all of the tools I write are in win32 C. Hopefully this will help someone else, as when I looked for information on this I did not find very much.
static void RecurseFileSystem(TCHAR *StartingPath)
{
HANDLE CurrentFileHandle;
WIN32_FIND_DATA FileInformation;
TCHAR CurrentFileName[MAX_PATH];
TCHAR m_szFolderInitialPath[MAX_PATH];
TCHAR wildCard[MAX_PATH] = TEXT("\\*.*");
_tcscpy_s(CurrentFileName, MAX_PATH, StartingPath);
_tcscpy_s(m_szFolderInitialPath, MAX_PATH, StartingPath);
_tcsncat_s(m_szFolderInitialPath, MAX_PATH, wildCard, MAX_PATH);
CurrentFileHandle = FindFirstFile(m_szFolderInitialPath, &FileInformation);
if(CurrentFileHandle != INVALID_HANDLE_VALUE)
{
do
{
if((_tcscmp( FileInformation.cFileName, TEXT(".") ) != 0) && (_tcscmp(FileInformation.cFileName, TEXT("..")) != 0))
{
_tcscpy_s(CurrentFileName, MAX_PATH, StartingPath);
_tcsncat_s(CurrentFileName, MAX_PATH, TEXT("\\/**/"), MAX_PATH);
_tcsncat_s(CurrentFileName, MAX_PATH, FileInformation.cFileName, MAX_PATH);
if(FileInformation.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
{
//For some odd reason wordpress dies if i remove the space in the function call below..
RecurseFileSystem (CurrentFileName);
}
else
{
/* Do action on file here! */
}
}
}
while(FindNextFile(CurrentFileHandle, &FileInformation) == TRUE);
FindClose(CurrentFileHandle);
}
}
Tags: Win32
Posted in Win32 | No Comments »