دو قطعه کد برنامه ویندوزی
۱۳۹۱/۰۴/۱۵
ExeStrip: این برنامه Header/Stup
[داس] رو از فایل های Exe جدا می کنه.
BootSectorWriter: این برنامه 512 بایت از داده یا فایل رو روی سکتور بوت Write می کنه. (هارددیسک و فلاپی دیسک)
ExeStrip
این برنامه Header/Stup
[داس] رو از فایل های Exe جدا می کنه.
که برای ساختن image های باینری(خارج از محیط فایلهای exe)، کاهش حجم فایل اجرایی، حذف اطلاعات شناسایی، مقابله با آنتی ویروس های ساده، تولید کدهای بوت سکتور(MBR)، سرآغاز شل ها(Shell) و غیره... ازش استفاده میشه:
// Usage: ExeStrip.exe <SourceFile> <DestinationFile> <HeaderFile>
#if !defined(_MAC) && !defined(_WIN32)
#error"Only Mac or Win32 platforms supported."
#endif
#if !defined(__cplusplus)
#error"Only C++ source/compiler are allowed."
#endif
#ifdef _MSC_VER
#if (_MSC_VER > 1000)
#pragma once
#endif
#endif
#include <stdlib.h>
#include <stdio.h>
// For non-standard compilers.
#if !defined(NULL)
#define const NULL((void *) 0)
#endif
static void showBanner(void);
static void showBanner()
{
system("ClS");
printf("\n ------------------------------------------------------------\n");
printf(" Description: Strips the [DOS] header/stub of an exe file(To create binary images, making boot sector(MBR) codes, shells and...)\n");
printf(" Usage: ExeStrip.exe <SourceFile> <DestinationFile> <HeaderFile>\n");
printf(" ------------------------------------------------------------\n");
_beep(500,100);
return;
}
void main(int argc, char *argv[])
{
if ((argc <= 3) || (argv[1][0] == '?'))
{
showBanner();
return;
}
static FILE *fil_Source, *fil_Strip, *fil_Header;
printf("\n Opening/Reading '%s'...", argv[1]);
if ((fil_Source = fopen(argv[1], "rb")) == NULL)
{
printf(" [Error] Not found\n");
_beep(100, 100);
return;
}
printf(" [Done]\n Writing buffer '%s'...", argv[2]);
if ((fil_Strip = fopen(argv[2], "wb")) == NULL)
{
printf(" [Error]\n");
_beep(100, 100);
return;
}
printf(" [Done]\n Writing buffer '%s'...", argv[3]);
if ((fil_Header = fopen(argv[3], "wb")) == NULL)
{
printf(" [Error]\n");
_beep(100, 100);
return;
}
static char* Chr_Buffer = new char[512];
printf(" [Done]\n Reads 512 bytes of '%s'...", argv[1]);
fread(Chr_Buffer, 512, sizeof(char), fil_Source);
printf(" [Done]\n Writes 512 bytes into the '%s'...", argv[3]);
fwrite(Chr_Buffer, sizeof(char), 512, fil_Header);
printf(" [Done]\n Closing '%s'...", argv[3]);
fclose(fil_Header);
printf(" [Done]\n Writing rest of the binary to '%s'...", argv[2]);
while (!feof(fil_Source))
{
fputc(fgetc(fil_Source), fil_Strip);
}
printf(" [Done]\n Closing '%s' and '%s'...", argv[1], argv[2]);
fclose(fil_Source);
fclose(fil_Strip);
free(Chr_Buffer);
printf(" [Done]\n Operation completed successfully.\n");
_beep(1000, 100);
return;
}
BootSectorWriter
این برنامه 512 بایت از داده یا فایل رو روی سکتور بوت Write می کنه. (هارددیسک و فلاپی دیسک)
این یکی داخل Borland C++ نوشته شده - چون VS هدر BIOS خوبی نداره:
// Usage: BSW.exe <InputFile>
#if !defined(_MAC) && !defined(_WIN32)
#error"Only Mac or Win32 platforms supported."
#endif
#if !defined(__cplusplus)
#error"Only C++ source/compiler are allowed."
#endif
#include <stdio.h>
#include <bios.h>
#pragma comment(lib, "BIOS.lib")
#if !defined NULL
#define NULL ((void *) 0)
#endif
#define FDD1 0x0 // FDD A
#define FDD2 0x1 // FDD B
#define HDD1 0x80
#define HDD2 0x81
#define HDD3 0x82
void main(int argc, char* argv[])
{
if (argc < 1)
{
system("ClS");
printf("\n ------------------------------------------------------------\n");
printf("\n BSW.exe <InputFile>\n");
printf(" ------------------------------------------------------------\n");
_beep(500, 100);
return;
}
printf("\n Opening/Reading '%s'...", argv[1]);
FILE *fil_Input = fopen(argv[1], "rb");
if (!fil_Input || (fil_Input == NULL))
{
printf(" [Error] Not found.\n");
_beep(100, 100);
return;
}
char chr_Buffer[512];
printf(" [Done]\n Reads 512 bytes of '%s'...", argv[1]);
fread(&chr_Buffer, 512, 1, fil_Input);
int int_Result;
printf(" [Done]\n Writing buffer...");
// API: int biosdisk(int __cmd, int __drive, int __head, int __track, int __sector, int __nsects, void *__buffer)
int_Result = biosdisk(3, FDD1, 0, 0, 1, 1, chr_Buffer);
if (int_Result == 0)
{
printf(" [Error] #%i\n", int_Result);
_beep(100, 100);
return;
}
printf(" [Done]\n Closing file...");
fclose(fil_Input);
printf(" [Done]\n Operation completed successfully.\n");
_beep(1000, 100);
return;
اگر قبلا در بیان ثبت نام کرده اید لطفا ابتدا وارد شوید، در غیر این صورت می توانید ثبت نام کنید.