/*
exe2com - exe2bin replacement by Chris Dunford/Cove Software
usage: exe2com [/I] infile [outfile]
usage is the same as exe2bin except:
1. Output defaults to COM rather than BIN
2. Binary fixup option not supported
3. Checksum not verified
4. Provides more useful error messages and a warning if a
COM file is being created with initial IP != 0x100
5. /I switch provides EXE file info instead of converting
Compiler notes:
This source was written for Microsoft C version 5.0. It
should be reasonably portable. Watch out for fseek();
what it returns seems to vary widely between compilers.
To compile with MSC, use:
cl exe2com.c (no switches necessary)
We have checked that the source (as of version 1.04) compiles
without error under Turbo C 1.5. It appears to operate correctly,
but we ran only some quick tests; there may be subtle errors here.
The original version of this program was knocked together in about
an hour in response to the removal of EXE2BIN from the standard DOS
distribution disks. Improvements/corrections are encouraged, but
please try to coordinate public releases through me.
Program donated to the public domain by the author.
cjd 4/17/87
Version history
---------------
Version 1.04 03/02/88 (CJD)
Cleaned up some ugly code from the original quickie. Added
/I (info) switch. In previous versions, we defined an
error code for nonzero CS but didn't actually check it; now
we do. Source will now compile under either Microsoft C or
Turbo C.
Version 1.03 12/30/87 (CJD)
C86 version converted to Microsoft C (5.0) by Chris
Dunford. Increased size of I/O buffer to 4K to improve
speed; EXE2COM 1.03 is twice as fast as 1.02 and is now
slightly faster than EXE2BIN. The C86 version will no
longer be distributed.
Version 1.02 11/22/87
by Chris Blum (CompuServe 76625,1041)
Fix for even 512-byte boundary file losing last 512 bytes.
Also corrected signon per request of Chris Dunford (his name
was lost in the translation to Turbo C). Version 1.02
existed in both Turbo C and C86 versions, although only
the C86 executable was "officially" distributed.
Version 1.01 was a Turbo C conversion.
Version 1.00 04/17/87
Original C86 version by Chris Dunford
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
/* Version coding */
#define MAJVER 1
#define MINVER 0
#define REVISION 4
/* Conversion error codes */
#define BADREAD 0
#define BADWRITE 1
#define BADSIG 2
#define HASRELO 3
#define HAS_SS 4
#define HAS_CS 5
#define BAD_IP 6
#define TOO_BIG 7
/* This must be the last code */
#define UNKNOWN 8
/* Define size of console output buffer */
#define CONBUFSIZ 2048
/*
** Define structure of fixed-format part of EXE file header
*/
struct exe_header {
char exe_sig[2]; /* EXE file signature: "MZ" */
unsigned excess, /* Image size mod 512 (valid bytes in last page) */
pages, /* # 512-byte pages in image */
relo_ct, /* Count of relocation table entries */
hdr_size, /* Size of header, in paragraphs */
min_mem, /* Min required memory */
max_mem, /* Max required memory */
ss, /* Stack seg offset in load module */
sp, /* Initial value of SP */
cksum, /* File checksum */
ip, /* Initial value of IP */
cs, /* CS offset in load module */
relo_start, /* Offset of first relo item */
ovl_num; /* Overlay number */
} xh;
FILE *fi, /* Input file stream */
*fo; /* Output file stream */
char fin[129], /* Input file name */
fon[129]; /* Output file name */
int info=0; /* Nonzero if /I found */
char buf[CONBUFSIZ]; /* printf I/O buffer */
char defext[] = ".com"; /* Default output extension - change if you want */
unsigned long code_start, /* Offset of program image in EXE file */
code_size; /* Size of program image, in bytes */
/* Function prototypes */
void init (unsigned, char *[]);
void read_hdr (void);
void disp_info (void);
void convert (void);
void err_xit (unsigned);
void usage (void);
/*
** program mainline
*/
main(argc, argv)
unsigned argc;
char *argv[];
{
init (argc, argv);
read_hdr ();
if (info)
disp_info ();
else
convert ();
}
/*
** Initialize - parse arguments, get filenames, open/create files
*/
void init (argc, argv)
unsigned argc;
char **argv;
{
char c, *cp;
int i;
/* Set up buffered output, display logo */
setvbuf (stdout, buf, _IOFBF, CONBUFSIZ);
printf ("exe2com %u.%u%u by Chris Dunford/The Cove Software Group/n",
MAJVER, MINVER, REVISION);
/* Get arguments */
cp = *(++argv);
for (i=1; i < argc; i++) {
while ( (cp = strchr (cp, '/')) != (char *) NULL) {
*cp++ = '/0';
c = *cp++;
switch (toupper (c)) {
case 'I':
info = 1;
break;
default:
usage ();
}
}
if (**argv)
if (fin[0] == '/0')
strcpy (fin, strlwr (*argv));
else if (fon[0] == '/0')
strcpy (fon, strlwr (*argv));
else
usage ();
cp = *(++argv);
}
/* Check to ensure that an input filename was found *.
if (fin[0] == '/0') usage ();
/* If the input file has no extension, add .EXE */
if (strchr (fin, '.') == (char *) NULL)
strcat (fin, ".exe");
/* Copy input name to output if unspecified */
if (fon[0] == '/0')
strcpy (fon, fin);
/* Check output extension--change EXE to COM, or add COM */
if ((cp = strchr (fon, '.')) == (char *) NULL)
strcat (fon, defext);
else if (strcmp (cp, ".exe") == 0)
strcpy (cp, defext);
/* Try to open input file */
if ((fi = fopen (fin, "rb")) == (FILE *) NULL) {
fprintf (stderr, "exe2com: can't find input file %s/n", fin);
exit (1);
}
/* Try to create output file, if INFO not requested */
if (!info)
if ((fo = fopen (fon, "wb")) == (FILE *) NULL) {
fprintf (stderr, "exe2com: can't open output file %s/n", fin);
exit (1);
}
}
/*
** usage display
*/
void usage (void)
{
fprintf (stderr, "usage: exe2com [/I] infile [outfile]/n");
exit (1);
}
/*
** Read and check the EXE file header
*/
void read_hdr(void)
{
char *cp;
/* Read the formatted portion of the header */
if (!fread (&xh, sizeof (struct exe_header), 1, fi))
err_xit (BADREAD);
/* Check for "MZ" signature */
if (strncmp (xh.exe_sig, "MZ", 2))
err_xit (BADSIG);
/* Compute offset of program image in module, and program size.
**
** The program size is computed as follows; it cannot exceed 64K bytes:
** 512 * (# EXE pages - 1)
** + valid bytes in last EXE page
** - offset of program image in EXE file
**
** Note that if the IP is nonzero, we will skip the first
** IP bytes of the program image, and copy IP bytes fewer
** than the actual size.
*/
code_start = ((unsigned long) xh.hdr_size) << 4;
code_size = (unsigned long) (xh.pages-1) * 512
+ (xh.excess ? xh.excess : 512) /* fixed 11/19/87 - CJB */
- code_start;
/* Don't check anything else if /I requested */
if (info) return;
/* Check header; to be convertible, must have:
** -- no relocatable items
** -- no stack segment
** -- no code segment
** -- IP == 0 or 100
** -- code size < 65536
*/
if (xh.relo_ct)
err_xit (HASRELO);
if (xh.ss || xh.sp)
err_xit (HAS_SS);
if (xh.cs)
err_xit (HAS_CS);
if (xh.ip != 0 && xh.ip != 0x100)
err_xit (BAD_IP);
if (code_size > 65536L)
err_xit (TOO_BIG);
/* Issue a warning if COM file and IP != 0x100 */
if (!strcmp (strchr (fon, '.'), ".com") && xh.ip != 0x100)
fprintf (stderr, "exe2com warning: COM file, initial IP not 100H/n");
}
/*
** /i output: display EXE file info
*/
void disp_info (void)
{
char *cp;
unsigned long k;
cp = strrchr (fin, '//');
if (!cp) cp = strchr (fin, ':');
cp = cp ? cp++ : fin;
printf ("/n%-20s (hex) (dec)/n",cp);
k = (unsigned long) (xh.pages-1) * 512 + (xh.excess ? xh.excess : 512);
printf (" EXE file size %5lX %7lu/n", k, k);
printf (" EXE header size (para) %4X %7u/n", xh.hdr_size, xh.hdr_size);
putchar (code_size > 65536L ? '*' : ' ');
printf (" Program image size (bytes) %5lX %7lu/n", code_size, code_size);
k = (unsigned long) xh.min_mem * 16 + code_size;
printf (" Minimum load size (bytes) %5lX %7lu/n", k, k);
printf (" Min allocation (para) %4X %7u/n", xh.min_mem, xh.min_mem);
printf (" Max allocation (para) %4X %7u/n", xh.max_mem, xh.max_mem);
putchar (xh.cs || (xh.ip != 0x100) ? '*' : ' ');
printf (" Initial CS:IP %04X:%04X/n", xh.cs, xh.ip);
putchar (xh.ss || xh.sp ? '*' : ' ');
printf (" Initial SS:SP %04X:%04X %7u (stack size)/n", xh.ss, xh.sp, xh.sp);
putchar (xh.relo_ct ? '*' : ' ');
printf (" Relocation count %4X %7u/n", xh.relo_ct, xh.relo_ct);
printf (" Relo table start %04X %7u/n", xh.relo_start, xh.relo_start);
printf (" EXE file checksum %04X %7u/n", xh.cksum, xh.cksum);
printf (" Overlay number %4X %7u/n", xh.ovl_num, xh.ovl_num);
printf ("* = this item prevents conversion to BIN/COM/n");
}
/*
** Convert the file. Nothing to do, really, other than
** reading the image (which follows the header), and
** dumping it back out to disk.
*/
void convert (void)
{
#define BUFSIZE 16384
static char buffer[BUFSIZE]; /* Forces buffer out of program stack */
unsigned bsize;
/* Seek to start of program image, skipping IP bytes */
if (fseek (fi, code_start+xh.ip, 0))
err_xit (BADREAD);
/* Read blocks and copy to output */
for (code_size -= xh.ip; code_size; code_size -= bsize) {
/* Set count of bytes to read/write */
bsize = code_size > BUFSIZE ? BUFSIZE : code_size;
/* Read and write block */
if (!fread (buffer, bsize, 1, fi))
err_xit (BADREAD);
if (!fwrite (buffer, bsize, 1, fo))
err_xit (BADWRITE);
}
/* All done, close the two files */
fclose (fi);
fclose (fo);
}
/*
** Display an error message, delete output file, exit.
*/
void err_xit (code)
unsigned code;
{
static char *msg[UNKNOWN+1] = {
"error reading EXE header",
"error writing output file",
"invalid EXE file signature",
"EXE has relocatable items",
"EXE has stack segment",
"EXE has nonzero CS",
"IP not 0 or 100H",
"program exceeds 64K",
"unknown internal error"
};
if (code > UNKNOWN) code = UNKNOWN;
fprintf (stderr, "exe2com: %s, can't convert/n", msg[code]);
/* Close two files and delete partial output */
fclose (fi);
fclose (fo);
unlink (fon);
/* Exit with errorlevel 1 */
exit (1);
}
相关推荐
深入DOS:exe2bin与exe2com转换工具的源代码解析
DOS(磁盘操作系统)是个人计算机历史上早期的操作系统之一,其文件格式对于理解旧有软件的兼容性至关重要。DOS文件格式包括了多种类型,其中.exe和.bin是两种常见而有区别的文件类型。.exe文件是可执行文件格式,它包含了程序的代码和数据,可以通过操作系统的加载程序来执行。.bin文件是二进制文件,通常包含原始数据,可以是代码片段,也可以是其他类型的二进制数据。要进行.exe到.bin的转换,首先需要一个能够解析.exe文件结构的工具源程序。
80x86 汇编语言编程:EXE2COM
在 DOS 系统中,有三种程序文件,扩展名分别是:EXE、COM、BAT。在 DOS 提示符后面,键入程序名(不用键入.扩展名)再回车,DOS 即可执行该程序。各扩展名,分别代表一类程序。 BAT:称为批处理文件; COM:称为命令文件; EXE:称为可执行文件。其中 EXE 文件的功能最为强大。而 COM 文件则是短小精悍,调入内存并开始执行,其速度,要比 EXE 文件的速度更快。但是,随
dos下exe2bin exe2com的工具源程序
dos下exe2bin 和 exe2com的工具源程序
C# 从源码生成EXE
using Microsoft.CSharp; using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; ...
EXE2BAT BAT2EXE等类似转换工具
EXE2BAT BAT2EXE等类似转换工具集合 内容: bat2com.exe bat2exe.EXE bat2exec.COM bin2txt.exe com2exe.exe exe2batnet.exe exe2bin.exe exe2bmp.exe EXE2COM.C EXE2COM.doc EXE2COM.EXE exe2hex.exe exe2vbs.exe obj2asm.zip txt2exe.EXE txttoexe.rar
bat2com和com2exe
用于格式转化,用的时候进入bat2com com2exe的目录中
Source Code of exe2com
http://blog.csdn.net/AloneSword/archive/2004/08/26/85392.aspx /* exe2com - exe2bin replacement by Chris Dunford/Cove Software usage: exe2com [/I] infile [outfile] usage is the same as
EXE2COM汇编工具
汇编转换工具.可以把exe文件转换成。com文件。运行速度更快
代码 阅读器:SI (Source Insight)、vscode(Visual Studio Code)、code-server、Visual Studio、OpenGrok
代码 阅读器:IDE、SI (Source Insight)、OpenGrok
bat2com2exe批处理文件转换成可执行的文件
bat2com2exe批处理文件转换成可执行的文件 bat2com2exe批处理文件转换成可执行的文件bat2com2exe批处理文件转换成可执行的文件 免分的
bat2com com2exe
资源内容:里面有个文件 BAT2COM COM2EXE 功能:将bat转换成com文件,再将com文件转换成exe文件。 使用方法:BAT2COM test.bat --> 生成 test.com COM2EXE test.com --> 生成 test.exe 需要转2次即可
Windows CE 3.0 Source Code 免微软passport登陆下载
以下资源来自 http://com.6to23.com/ 免微软passport登陆下载地址连接:wince30_src.zipWindows CE 3.0 Source Code (zip: 3.28 MB zip file; sorce: 5.03 MB executable file) 原下载页面:Windows CE 3.
车载测试面试题总结
首先确认是什么问题,如果是测试软件的问题就先确定自己的测试方法有没有问题,如果没有问题,那就是测试软件的问题,这时候就需要提bug 进行跟踪,(比如BCM测试的时候,先明确测试的输入,对输入)进行需求分析,然后设计测试用例,进行用例评审,评审完执行测试用例形成最终的版本,台架分为:hil(黑尔)台架,单个控制器的台架、整车台架、车身台架、动力系统台架等,主要验证其功能,或者实车无法满足的测试环境。这个人不可能一直,点击几千次或者多少次几个小时连续点击,人不可能一直在点。因为要模拟一下这个稳定性,
Win11下用WSL2部署Claude Code编程副驾驶全指南
Claude Code是一款基于Anthropic API的AI代码助手CLI工具,其核心依赖Linux内核环境下的Rust编译二进制模块(claude-native),无法在Windows原生命令行直接运行。原理上需通过WSL2提供合规的Linux执行层,并配合Node.js v20+、npm全局路径隔离、可信镜像源及环境变量注入等工程配置,实现ABI兼容与安全调用。技术价值在于将大模型能力深度集成至本地开发流,支持秒级代码重构、跨语言转换与自然语言生成,显著提升学生、运营、设计师等非专业开发者的真实编码
eNSP-Pro配置又丢了?手把手教你用导出功能防患于未然
本文详细介绍了eNSP-Pro配置防丢失的全套方案,包括运行时内存、虚拟存储设备和宿主机文件系统的配置存储机制,以及多维度备份策略和特殊场景下的恢复技巧。通过优化保存流程、自动化定时导出和版本化管理,帮助网络工程师有效防止配置丢失,提升工作效率。
ISP调试工程师相关面试问题_001
Qualcomm、MTK等ISP pipeline的框架原理及算法原理,还有调试经验。
Kimi Code CLI:Windows与WSL2下的AI编程助手命令行工具
命令行工具(CLI)作为开发者效率提升的核心组件,通过脚本化操作实现开发流程自动化。AI编程助手通过自然语言处理技术,将开发者的意图转化为可执行代码,显著降低编码门槛。Kimi Code CLI创新性地将两者结合,为Windows/WSL2环境提供终端直达的AI编程支持。该工具特别适合快速原型开发、代码片段生成和重复性任务自动化场景,支持通过PowerShell或WSL2终端直接调用。典型应用包括实时代码生成、技术文档查询和算法实现优化,开发者可结合VS Code插件实现更流畅的IDE集成体验。
[明道云] -基础教学1- 创建第一个工作表:从 0 到实用
明道云工作表相当于数据库表,是存储业务数据的核心组件。创建工作表主要有两种方式:1)从空白新建,通过添加字段(最多200个)、设置属性、配置表单样式;2)从Excel导入,需选择sheet、配置字段映射。创建后系统自动生成默认视图,支持多种视图形式(看板/日历等)。建议设置合适的标题字段和关联关系,初学者可在一小时内完成基础应用搭建。后续可扩展权限控制、工作流自动化等功能。
1103



被折叠的 条评论
为什么被折叠?



