Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1547259
  • 博文数量: 596
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 173
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-06 15:50
个人简介

在线笔记

文章分类

全部博文(596)

文章存档

2016年(1)

2015年(104)

2014年(228)

2013年(226)

2012年(26)

2011年(11)

分类: Windows平台

2014-08-24 12:17:54

WDK 7.1


  1. //makefile
  2. !INCLUDE $(NTMAKEENV)\makefile.def

  1. //sources
  2. TARGETNAME=demo
  3. TARGETPATH=obj
  4. TARGETTYPE=PROGRAM
  5. UMTYPE=nt
  6. USE_NTDLL=1

  7. MINWIN_SDK_LIB_PATH=$(SDK_LIB_PATH)
  8. INCLUDES=$(DDK_INC_PATH)

  9. SOURCES=native.c

  1. //native.c
  2. #include "ntddk.h"
  3. #include "stdio.h"
  4. #include "native.h"

  5. HANDLE Heap;


  6. void NtProcessStartup( PSTARTUP_ARGUMENT Argument )
  7. {
  8.     PUNICODE_STRING commandLine;
  9.     PWCHAR stringBuffer, argPtr;
  10.     UNICODE_STRING helloWord;
  11.     RTL_HEAP_DEFINITION heapParams;

  12.     //init
  13.     //
  14.     memset(&heapParams, 0, sizeof(RTL_HEAP_DEFINITION));
  15.     heapParams.Length = sizeof(RTL_HEAP_DEFINITION);
  16.     Heap = RtlCreateHeap(2, 0, 0x100000, 0x1000, 0, &heapParams);

  17.     commandLine = &Argument->Environment->CommandLine;

  18.     argPtr = commandLine->Buffer;
  19.     while (*argPtr != L' ') argPtr++;
  20.     argPtr++;

  21.     stringBuffer = RtlAllocateHeap(Heap, 0, 256);
  22.     swprintf(stringBuffer, L"\n%s", argPtr);
  23.     helloWord.Buffer = stringBuffer;
  24.     helloWord.Length = wcslen(stringBuffer) * sizeof(WCHAR);
  25.     helloWord.MaximumLength = helloWord.Length + sizeof(WCHAR);
  26.     NtDisplayString(&helloWord);

  27.     //free
  28.     RtlFreeHeap(Heap, 0, stringBuffer);

  29.     NtTerminateProcess(NtCurrentProcess(), 0);
  30. }


  1. //native.h
  2. typedef struct {
  3.     ULONG Unknown[21];
  4.     UNICODE_STRING CommandLine;
  5.     UNICODE_STRING ImageFile;
  6. }ENVIRONMENT_INFORMATION, *PENVIRONMENT_INFORMATION;

  7. typedef struct {
  8.     ULONG Unknown[3];
  9.     PENVIRONMENT_INFORMATION Environment;
  10. }STARTUP_ARGUMENT, *PSTARTUP_ARGUMENT;

  11. typedef struct {
  12.     ULONG Length;
  13.     ULONG Unknown[11];
  14. }RTL_HEAP_DEFINITION, *PRTL_HEAP_DEFINITION;

  15. NTSTATUS
  16. NTAPI
  17. NtDisplayString(
  18.         PUNICODE_STRING String
  19.         );

  20. NTSTATUS
  21. NTAPI
  22. NtTerminateProcess(
  23.         HANDLE ProcessHandle,
  24.         LONG ExitStatus
  25.         );


  26. HANDLE
  27. NTAPI
  28. RtlCreateHeap(
  29.         ULONG Flags,
  30.         PVOID BaseAddress,
  31.         ULONG SizeToReserve,
  32.         ULONG SizeToCommit,
  33.         PVOID Unknown,
  34.         PRTL_HEAP_DEFINITION Definition
  35.         );

  36. PVOID
  37. NTAPI
  38. RtlAllocateHeap(
  39.         HANDLE Heap,
  40.         ULONG Flags,
  41.         ULONG Size
  42.         );


  43. BOOLEAN
  44. NTAPI
  45. RtlFreeHeap(
  46.         HANDLE Heap,
  47.         ULONG Flags,
  48.         PVOID Address
  49.         )




参考:
http://www.cnblogs.com/BoyXiao/archive/2011/09/21/2183059.html
阅读(926) | 评论(0) | 转发(0) |
0

上一篇:RDP的AERO

下一篇:情人节

给主人留下些什么吧!~~