;steganography
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
readfileheader proto :DWORD
crunch proto :DWORD
.const
IDMOPEN equ 1
IDMSAVE equ 2
IDMEXIT equ 3
.DATA
ClassName db "minnclass",0
AppName db "stegano",0
filename db "canyoumodified.bmp",0
msgboxtext db "canyoumodified.bmp verdur ad vera i sama directory",0
msgboxcaption db "bullarinn thinn",0
filename2 db "canyoumodi.txt"
.DATA?
hinstance HINSTANCE ?
hfile HANDLE ?
hfile2 HANDLE ?
hmemory HANDLE ?
pmemory DWORD ?
hmemory2 HANDLE ?
pmemory2 DWORD ?
isfile bool ?
readb DWORD ?
filesize DWORD ?
infoofset DWORD ?
eof DWORD ?
buff BYTE ?
.CODE
start:
invoke GetModuleHandle, NULL
mov hinstance,eax
invoke WinMain, hinstance, NULL, NULL, SW_SHOWDEFAULT
invoke ExitProcess, eax
WinMain proc hinst:HINSTANCE,hPrevInst:HINSTANCE,cmdl:LPSTR,cmds:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hinstance
pop wc.hInstance
mov wc.hbrBackground, COLOR_WINDOW+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL,IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx, NULL,\
ADDR ClassName,\
ADDR AppName,\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
NULL,\
NULL,\
hinst,\
NULL
mov hwnd,eax
invoke ShowWindow, hwnd,cmds
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hwnd:HWND, umsg:UINT, wparam:WPARAM, lparam:LPARAM
.if umsg==WM_CREATE
invoke CreateFile, addr filename,\
GENERIC_READ or GENERIC_WRITE,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
.if eax == -1
invoke MessageBox,NULL , addr msgboxtext, addr msgboxcaption, MB_OK
invoke SendMessage,hwnd,WM_DESTROY,NULL,NULL
.else
mov hfile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,80000
mov hmemory,eax
invoke GlobalLock,hmemory
mov pmemory,eax
invoke ReadFile , hfile, pmemory,79542,addr readb,NULL
invoke CloseHandle,hfile
invoke crunch,pmemory
invoke SendMessage,hwnd,WM_DESTROY,NULL,NULL
.endif
.elseif umsg==WM_DESTROY
invoke PostQuitMessage, NULL
invoke GlobalUnlock,pmemory
invoke GlobalFree,hmemory
.ELSE
invoke DefWindowProc, hwnd, umsg, wparam, lparam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
readfileheader proc fpointer:DWORD
mov eax,fpointer
add eax,2
mov ebx, [eax]
mov filesize, ebx
mov infoofset,54
ret
readfileheader endp
crunch proc fpointer1:DWORD
invoke CreateFile,addr filename2, GENERIC_READ or GENERIC_WRITE,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
.if eax==-1
invoke MessageBox,NULL,addr msgboxcaption,addr msgboxcaption,MB_OK
.else
mov hfile2,eax
.endif
mov eax,fpointer1
add eax,readb
mov eof,eax
;invoke WriteFile, hfile2 , eof, 54, addr readb,NULL
mov ebx, fpointer1
add ebx, 54
loop1:
mov al,[ebx]
and al,1
shl al,7
mov cl,al
mov al,[ebx+1]
and al,1
shl al,6
add cl,al
mov al,[ebx+2]
and al,1
shl al,5
add cl,al
mov al,[ebx+3]
and al,1
shl al,4
add cl,al
mov al,[ebx+4]
and al,1
shl al,3
add cl,al
mov al,[ebx+5]
and al,1
shl al,2
add cl,al
mov al,[ebx+6]
and al,1
shl al,1
add cl,al
mov al,[ebx+7]
and al,1
;shl al,0
add cl,al
mov buff,cl
add ebx,8
invoke WriteFile, hfile2 , addr buff, 1,addr readb,NULL
.if ebx <= eof
jmp loop1
.endif
invoke CloseHandle,hfile2
ret
crunch endp
end start
#include <stdio.h>
// bmp-24.h
typedef struct {
unsigned short type; /* Should be 'BM' */
unsigned int size; /* File size */
unsigned short int reserved1, reserved2;
unsigned int offset; /* Offset to image data */
} __attribute__ ((packed)) HEADER;
typedef struct {
unsigned int size; /* Header size in bytes */
int width,height; /* Width and height of image */
unsigned short int planes; /* Number of colour planes */
unsigned short int bits; /* Bits per pixel */
unsigned int compression; /* Compression type */
unsigned int imagesize; /* Image size in bytes */
int xresolution,yresolution; /* Pixels per meter */
unsigned int ncolours; /* Number of colours */
unsigned int importantcolours; /* Important colours */
} __attribute__ ((packed)) INFOHEADER;
// These are basically copy/pasted from http://astronomy.swin.edu.au/~pbourke/dataformats/bmp/
// Didn't see the need to type them myself when they'd look exactly the same.
typedef unsigned int UINT;
UINT fb (UINT, UINT ); // FlipBit
UINT gb (UINT, UINT ); // GetBit..
void db (UINT); // DisplayBit .. Notað í debugging.
int main(int argc, char **argv)
{
// Við þurfum þessa til að lesa skránna rétt..
HEADER *hdr;
INFOHEADER *ihdr;
// buffer og pointer þurfum við til að fikta við skránna
char *buffer, *pointer;
// Size fyrir stærð á skrá
// x, y, z = indexing tölur
// msize = stærð gagna sem á að ná frá skránni.
// curr = sá stafur sem er verið að ná í frá skrá.
UINT size = 0, x, y, z, msize = 0, curr = 0;
// Skráar.. bendill ?
FILE *in;
// Viljum að þetta virki..
if(argc < 3)
{
printf("Usage:\n");
printf("\tgetsteg infile size\n\n");
printf("\tinfile - File you want to recover the message from.\n");
printf("\tsize - Size of message.\n\n");
return -1;
}
msize = atoi(argv[2]);
in = fopen(argv[1], "r+b");
// Enn og aftur, þetta á að virka.. Engar ímyndaðar skrár.
if(in == (FILE*)NULL)
{
printf("Unable to open file.\n");
return -1;
}
// Fá stærð skráarinnar..
fseek(in, 0, SEEK_END);
size = ftell(in);
rewind(in);
// .. skapa pláss fyrir hana ..
buffer = (char*)malloc(sizeof(char) * size);
// .. og lesa hana.
fread(buffer, sizeof(char), size, in);
fclose(in);
// Smá pointer galdrar þarna.
hdr = (HEADER*)buffer;
ihdr = (INFOHEADER*)(buffer+sizeof(HEADER));
pointer = buffer+hdr->offset;
// Helst hafa skrá sem er 24 bita BMP, ekki annað.
if(hdr->type != 0x4d42 || ihdr->bits != 24)
{
printf("Invalid file format.. Exiting.\n");
return -1;
}
// lykkja sem nær gögnunum fyrir okkur.
y = 7;
for(x = 0; x < msize; x++)
{
curr = 0;
for(z = 0; z < 8; z++)
{
if(gb(*pointer, 0) != gb(curr, y)) curr = fb(curr, y);
y--;
pointer++;
}
y = 7;
putchar(curr);
}
// Finito.
free(buffer);
buffer = NULL;
return 0;
}
void db (UINT x)
{
int i;
for(i = 7; i >= 0; i--)
(x & (1<<i)) ? putch('1') : putch('0');
putch('\n');
}
// Flips a bit n in value x.
UINT fb (UINT x, UINT n)
{
return x ^ (1<<n);
}
// Gets the value of a bit n in a value x.
UINT gb (UINT x, UINT n)
{
if(x & 1<<n) return 1;
return 0;
}