七液 发表于 2013-2-8 15:21:02

api一日一练 第12天 (点评版)赠送 Delphi版+汇编版本

废话:
还是那句话使用GetCurrentDirectory来获取当前工作路径是不可靠的
这个是随时可以改变的而且是全局影响的,早期360可以用这招来进行
DLL欺骗现在倒是不可以了,但是用bat配合的话到也还是可以运作.
还是比较猥琐的.

Delphi版本
program Sdk12;

uses
Windows;

var
szPath: Array Of Char;
begin
ZeroMemory(@szPath, SizeOf(szPath));    //清零

//获取当前路径
GetCurrentDirectory(SizeOf(szPath), szPath);
MessageBox(0, szPath, 'xqmsyk.com', 0);

//设置当前路径
SetCurrentDirectory('c:\');

GetCurrentDirectory(SizeOf(szPath), szPath);
MessageBox(0, szPath, 'xqmsyk.com', 0);
end.
汇编版本
.686
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

INVALID_FILE_ATTRIBUTES        equ        -1

.data
        szFile                db        "c:\1", 0

        szCaption        db        "xqmsyk.com", 0

.code

WinMain proc
        LOCAL        @szPath: BYTE
       
        invoke        RtlZeroMemory, addr @szPath, sizeof @szPath
       
        ;        获取当前路径
        invoke        GetCurrentDirectory, sizeof @szPath, addr @szPath
        invoke        MessageBox, 0, addr @szPath, offset szCaption, 0

        ;        设置当前路径
        invoke        SetCurrentDirectory, offset szFile
       
        invoke        GetCurrentDirectory, sizeof @szPath, addr @szPath
        invoke        MessageBox, 0, addr @szPath, offset szCaption, 0

        ret

WinMain endp

start:
        invoke        WinMain
        ret
end start

echotxl 发表于 2013-4-6 14:24:31

感谢楼主的补充,,,严格要求自己。。。{:1_1:}
页: [1]
查看完整版本: api一日一练 第12天 (点评版)赠送 Delphi版+汇编版本