首页
社区
课程
招聘
[求助]请问,如何把一个.C文件编译成.SYS文件
发表于: 2008-1-23 09:08 11653

[求助]请问,如何把一个.C文件编译成.SYS文件

2008-1-23 09:08
11653
脱离编译器的
手工编译的
能实现吗

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (26)
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
2
脱离编译器。。。  向lz鞠躬
2008-1-23 09:47
0
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
不好意思,说错了,我是指脱离VC等IDE的,
我是想问,如何用CL LINK 等命令行工具来手工编译
2008-1-23 09:49
0
雪    币: 223
活跃值: (10)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
4
ddk===>build
2008-1-23 10:20
0
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
5
DDK有 Windows XX(2K/XP/2K3 etc) YYY(Checked/Free) Build Environment
2008-1-23 11:07
0
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
6
写好了makefile然后进build environment然后输入build
2008-1-23 11:07
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
7
还有个source哦~
2008-1-23 16:02
0
雪    币: 109
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
脱离编译器的,改扩展名吧
2008-1-23 17:36
0
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
9
恩  还有个source
2008-1-24 04:46
0
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
我现在想编译MS的例子,请问该如何做:
SOURCE文件内容
TARGETNAME=SerEnum
TARGETPATH=obj
TARGETTYPE=DRIVER

MSC_WARNING_LEVEL=-W3 -WX

SOURCES= pnp.c \
         enum.c \
         serenum.rc \
         serenum.c \
         string.c \
         power.c \
         log.c

PRECOMPILED_INCLUDE=pch.h
PRECOMPILED_PCH=pch.pch
PRECOMPILED_OBJ=pch.obj
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
MAKEFILE文件内容

#############################################################################
#
#       Copyright (C) Microsoft Corporation 1998, 1999
#       All Rights Reserved.
#
#############################################################################

#
# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source
# file to this component.  This file merely indirects to the real make file
# that is shared by all the driver components of Windows NT
#

!INCLUDE $(NTMAKEENV)\makefile.def

例子路径:
D:\WINDDK\2600\src\kernel\serenum

路径下所有文件:
D:\WINDDK\2600\src\kernel\serenum 的目录

2006-04-27  09:26    <DIR>          .
2006-04-27  09:26    <DIR>          ..
2001-08-17  12:51            47,121 enum.c
2001-08-17  12:51             3,184 log.c
2001-08-17  12:51               313 serenum.rc
2001-08-17  12:51               310 sources
2001-08-17  12:51            21,793 string.c
2001-08-17  12:51               950 log.h
2001-08-17  12:51               519 makefile
2001-08-17  12:51               195 pch.h
2001-08-17  12:51            44,242 pnp.c
2001-08-17  12:51             6,916 power.c
2001-08-17  12:51            16,613 serenum.c
2001-08-17  12:51            14,366 serenum.h
2001-08-17  12:51             2,381 serenum.htm

              13 个文件        158,903 字节
               2 个目录  8,943,468,544 可用字节

请问,我该如何做,才能弄出那个SYS文件来呢
2008-1-24 09:12
0
雪    币: 454
活跃值: (1673)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
11
在开始菜单选择进入你要build的cmd环境,然后cd到SOURCE文件所在的目录,输入build命令即可
2008-1-24 09:22
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
12
嗯,就是这样的呀
StarsunYzL说得完全正确~
2008-1-24 09:24
0
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
非常感谢
请问,这个SYS就是最终我们所求的吗???
D:\WINDDK\2600\src\kernel\serenum\objchk\i386 的目录

008-01-24  09:24    <DIR>          .
008-01-24  09:24    <DIR>          ..
008-01-24  09:24         1,204,304 pch.pch
008-01-24  09:24           188,367 pch.obj
008-01-24  09:24             1,260 serenum.res
008-01-24  09:24            34,862 pnp.obj
008-01-24  09:24            43,610 enum.obj
008-01-24  09:24            17,368 serenum.obj
008-01-24  09:24            26,946 string.obj
008-01-24  09:24             8,248 power.obj
008-01-24  09:24             5,252 log.obj
008-01-24  09:24            42,368 SerEnum.sys
008-01-24  09:24           281,600 SerEnum.pdb
             11 个文件      1,854,185 字节
              2 个目录  8,941,174,784 可用字节
其他那些文件是不是都是没有用的中间文件呢???????????
2008-1-24 09:28
0
雪    币: 454
活跃值: (1673)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
14
嗯,基本上其它文件不会用到,不过调试的时候有pdb文件最好
2008-1-24 09:34
0
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
恩,谢谢,困惑好些天的问题终于得到解决

(PS:类似这样的超级EASY的问题,网上搜不到,书上也不写,郁闷啊)
2008-1-24 09:37
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
16
网上搜的到的.

嘿嘿,你木有搜到关键词
2008-1-24 09:48
0
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
17
HELLOWORD 驱动程序:
DDK FOR XP
原程序:HELLOWORD.CPP
//一定要的头文件,声明了函数模块和变量:
#include "ntddk.h"

/***************************************************************
函数名称:DriverEntry()
功能描述:WDM程序入口(原来的WinMain被换成了DriverEntry,也是驱动程序的大门)
***************************************************************/
//extern "C"是必须的,表示“用C链接”
extern "C"
NTSTATUS DriverEntry(     IN PDRIVER_OBJECT DriverObject, //IN 是一个关键字表示这是一个输 入参数,PDRIVER_OBJECT是一个数据结构的指针,就像PCHAR一样,这个数据结构是什么样子的,后面我会列出来。她描述了一个驱动设备对象。
                         IN PUNICODE_STRING RegistryPath)//参数RegistryPath指定了驱动程序注册表健的路径,因为驱动程序安装后总会在系统注册表里留下一点东西的。
{
    DbgPrint("驱动加载了....");
    //返回一个NTSTATUS值STATUS_SUCCESS。几乎所有的驱动程序例程都必须返回一个NTSTATUS值,这些值在NTSTATUS.H DDK头文件中有详细的定义。
    return STATUS_SUCCESS;
}
SOURCE文件
TARGETNAME=helloword
TARGETPATH=obj
TARGETTYPE=DRIVER

MSC_WARNING_LEVEL=-W3 -WX

SOURCES= helloword.cpp

从MS的示例代码中COPY了一个MAKEFILE

准备工作完成,接下来的BUILD
请看提示信息
G:\mytest>build
BUILD: Object root set to: ==> objchk
BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
BUILD: /i switch ignored
BUILD: Compile and Link for i386
BUILD: Loading D:\WINDDK\2600\build.dat...
BUILD: Computing Include file dependencies:
BUILD: Examining g:\mytest directory for files to compile.
    g:\mytest - 1 source files (16 lines)
BUILD: Saving D:\WINDDK\2600\build.dat...
BUILD: Compiling g:\mytest directory
Compiling - helloword.cpp for i386
d:\winddk\2600\inc\ddk\wxp\ntddk.h(2152) : error C2220: warning treated as error
- no object file generated
d:\winddk\2600\inc\ddk\wxp\ntddk.h(2152) : error C4162: '_ReturnAddress' : no fu
nction with C linkage found
d:\winddk\2600\inc\ddk\wxp\ntddk.h(6852) : error C4162: '_InterlockedExchange' :
no function with C linkage found
d:\winddk\2600\inc\ddk\wxp\ntddk.h(6878) : error C4162: '_InterlockedIncrement'
: no function with C linkage found
d:\winddk\2600\inc\ddk\wxp\ntddk.h(6891) : error C4162: '_InterlockedDecrement'
: no function with C linkage found
d:\winddk\2600\inc\ddk\wxp\ntddk.h(6905) : error C4162: '_InterlockedExchangeAdd
' : no function with C linkage found
d:\winddk\2600\inc\ddk\wxp\ntddk.h(6935) : error C4162: '_InterlockedCompareExch
ange' : no function with C linkage found
d:\winddk\2600\inc\ddk\wxp\ntddk.h(6987) : error C4162: '_InterlockedOr' : no fu
nction with C linkage found
d:\winddk\2600\inc\ddk\wxp\ntddk.h(6997) : error C4162: '_InterlockedAnd' : no f
unction with C linkage found
d:\winddk\2600\inc\ddk\wxp\ntddk.h(7007) : error C4162: '_InterlockedXor' : no f
unction with C linkage found
BUILD: Compile errors: not linking g:\mytest directory
BUILD: Done

    2 files compiled - 10 Errors

G:\mytest>G:\mytest>build
'G:\mytest' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Object root set to: ==> objchk
拒绝访问。

G:\mytest>BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: /i switch ignored
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Compile and Link for i386
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Loading D:\WINDDK\2600\build.dat...
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Computing Include file dependencies:
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Examining g:\mytest directory for files to compile.
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>    g:\mytest - 1 source files (16 lines)
'g:\mytest' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Saving D:\WINDDK\2600\build.dat...
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Compiling g:\mytest directory
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>Compiling - helloword.cpp for i386
'Compiling' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(2152) : error C2220: warning treated as error

G:\mytest> - no object file generated
'-' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(2152) : error C4162: '_ReturnAddress' : no fu

G:\mytest>nction with C linkage found
'nction' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6852) : error C4162: '_InterlockedExchange' :

G:\mytest> no function with C linkage found
'no' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6878) : error C4162: '_InterlockedIncrement'

G:\mytest>: no function with C linkage found
G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6891) : error C4162: '_InterlockedDecrement'

G:\mytest>: no function with C linkage found
G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6905) : error C4162: '_InterlockedExchangeAdd

G:\mytest>' : no function with C linkage found
''' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6935) : error C4162: '_InterlockedCompareExch

G:\mytest>ange' : no function with C linkage found
'ange'' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6987) : error C4162: '_InterlockedOr' : no fu

G:\mytest>nction with C linkage found
'nction' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6997) : error C4162: '_InterlockedAnd' : no f

G:\mytest>unction with C linkage found
'unction' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(7007) : error C4162: '_InterlockedXor' : no f

G:\mytest>unction with C linkage found
'unction' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Compile errors: not linking g:\mytest directory
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Done
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>
G:\mytest>    2 files compiled - 10 Errors
'2' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>G:\mytest>build
'G:\mytest' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Object root set to: ==> objchk
拒绝访问。

G:\mytest>BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: /i switch ignored
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Compile and Link for i386
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Loading D:\WINDDK\2600\build.dat...
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Computing Include file dependencies:
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Examining g:\mytest directory for files to compile.
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>    g:\mytest - 1 source files (16 lines)
'g:\mytest' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Saving D:\WINDDK\2600\build.dat...
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Compiling g:\mytest directory
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>Compiling - helloword.cpp for i386
'Compiling' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(2152) : error C2220: warning treated as error

G:\mytest> - no object file generated
'-' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(2152) : error C4162: '_ReturnAddress' : no fu

G:\mytest>nction with C linkage found
'nction' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6852) : error C4162: '_InterlockedExchange' :

G:\mytest> no function with C linkage found
'no' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6878) : error C4162: '_InterlockedIncrement'

G:\mytest>: no function with C linkage found
G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6891) : error C4162: '_InterlockedDecrement'

G:\mytest>: no function with C linkage found
G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6905) : error C4162: '_InterlockedExchangeAdd

G:\mytest>' : no function with C linkage found
''' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6935) : error C4162: '_InterlockedCompareExch

G:\mytest>ange' : no function with C linkage found
'ange'' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6987) : error C4162: '_InterlockedOr' : no fu

G:\mytest>nction with C linkage found
'nction' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(6997) : error C4162: '_InterlockedAnd' : no f

G:\mytest>unction with C linkage found
'unction' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>d:\winddk\2600\inc\ddk\wxp\ntddk.h(7007) : error C4162: '_InterlockedXor' : no f

G:\mytest>unction with C linkage found
'unction' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Compile errors: not linking g:\mytest directory
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>BUILD: Done
'BUILD:' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>
G:\mytest>    2 files compiled - 10 Errors
'2' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\mytest>
2008-1-24 10:15
0
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
18
#include "ntddk.h"
也要extern "C"

一般sys就用.c写吧。。
2008-1-24 14:59
0
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
19
现在的问题是这样的
G:\mytest>build
BUILD: Object root set to: ==> objchk
BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
BUILD: /i switch ignored
BUILD: Compile and Link for i386
BUILD: Loading D:\WINDDK\2600\build.dat...
BUILD: Computing Include file dependencies:
BUILD: Examining g:\mytest directory for files to compile.
    g:\mytest - 1 source files (9 lines)
BUILD: Saving D:\WINDDK\2600\build.dat...
BUILD: Compiling g:\mytest directory
Compiling - helloword.c for i386
helloword.c(1) : error C2059: syntax error : 'string'
d:\winddk\2600\inc\crt\excpt.h(82) : error C2143: syntax error : missing '{' before '__cdecl'
d:\winddk\2600\inc\wxp\ntdef.h(1471) : error C2143: syntax error : missing ')' before '*'
d:\winddk\2600\inc\wxp\ntdef.h(1471) : error C2143: syntax error : missing '{' before '*'
d:\winddk\2600\inc\wxp\ntdef.h(1471) : error C2059: syntax error : ')'
helloword.c(4) : error C2059: syntax error : 'string'
BUILD: Compile errors: not linking g:\mytest directory
BUILD: Done

    2 files compiled - 6 Errors -     9 LPS

//////////////////////////////////////////////////////////////////////////////////////////////////
原文件如下:
extern "C"
#include "ntddk.h"

extern "C"
NTSTATUS DriverEntry(     IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
    DbgPrint("驱动加载了....");
    return STATUS_SUCCESS;
}

扩展名也改为.C了,同时更改了SOURCE文件
2008-1-24 15:19
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
20
#ifdef __cplusplus
extern "C" {
#endif


.

字不少拉.还不让回复!
2008-1-24 15:46
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
21
如果定义了C++格式,那么你需要申明成C的调用,编译器才不会在你滴函数前头乱加东西。让它老老实实的按你滴意思去做~

懂了不?

你滴 {} 木有加呀
2008-1-24 15:48
0
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
22
真是气死人:
一生气,直接
#include "ntddk.h"

NTSTATUS DriverEntry(     IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
    DbgPrint("驱动加载了....");
    return STATUS_SUCCESS;
}
然后BUILD,然后OK,晕晕的
2008-1-24 16:28
0
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
23
现在SYS也编译成功了,打开DBGVIEW
然后安装服务,并启动服务,可是DBGVIEW里怎么什么信息都没有呢???
2008-1-24 16:40
0
雪    币: 109
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
24
DBGVIEW要capture kernel....
2008-1-24 17:14
0
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
25
其实直接写成aaa.c这样文件名(注意扩展名)  就不用extern半天了。
ps#20:大概是quote不算字数吧。。 呵呵,dz就不算quote的字数(算下限的时候不算,算上限的时候算-___-!!!)
2008-1-24 18:04
0
游客
登录 | 注册 方可回帖
返回
//