游戏逆向——找call练习 汇编实现

简介

主要练习找到功能 call 后如何写成程序,使用 win32汇编实现,大家可以选择自己喜欢的语言实现(c++、e语言、python等),如果对 win32汇编不感兴趣就可以退出了
用汇编去实现这些功能非常方便,几乎就是复制粘贴。

任务

在这里插入图片描述
实现这 4 个功能 call

找 call

  1. ollydbg 附加这个程序
  2. 下断点(bp send)
  3. 执行任意功能(普攻)
  4. ctrl+F9 回到程序地址
  5. 跟踪代码

由于比较简单,就不演示了,以下列出功能 call 的地址

  • 普攻
    在这里插入图片描述

  • 魔法
    在这里插入图片描述

  • 群攻
    在这里插入图片描述

  • 死亡
    在这里插入图片描述

代码实现

实现方法:

  1. 代码注入(使用更方便)
  2. dll 注入(写代码更方便)

本次使用 dll 注入
mfc dll 模板见上一篇文章 https://blog.csdn.net/weixin_44018458/article/details/108935929

test.asm

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Sample code for < Win32ASM Programming >
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 使用 nmake 或下列命令进行编译和链接:
; ml /c /coff test.asm
; Link  /subsystem:windows /Dll test.obj
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		.386
		.model flat, stdcall
		option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include		windows.inc
include		user32.inc
includelib	user32.lib
include		kernel32.inc
includelib	kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN	equ	1000h		;图标


;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		.data?
hInstance	dd	?
hWinMain	dd	?

IDC_ATTACK1	dd	?	;普攻
IDC_ATTACK2	dd	?	;魔法
IDC_ATTACK3	dd	?	;群攻
IDC_DEAD	dd	?	;死亡



		.const
szClassName	db	'RemoteClass',0
szCaptionMain	db	'练习找CALL_1 BY:程序_原',0
szButton	db	'Button',0
szAttack1	db	"普攻",0
szAttack2	db	"魔法",0
szAttack3	db	"群攻",0
szDead		db	"死亡",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 窗口过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcWinMain	proc	uses ebx edi esi,hWnd,uMsg,wParam,lParam
		local	i
		
		mov	eax,uMsg
		.if	eax ==	WM_CLOSE
			invoke	DestroyWindow,hWnd
			invoke	PostQuitMessage,NULL


		.elseif	eax ==	WM_COMMAND
			mov	eax,wParam
			.if	eax == IDC_ATTACK1
				; 普攻
				;****************************************************
				push	80000004h
				push	0
				push	00486085h
				push	10005h
				push	16010CC1h
				push	52010CBDh
				push	2
				mov	ebx,004063B0h
				mov	edi,00405C2Fh
				call	edi
				;*****************************************************

			.elseif	eax == IDC_ATTACK2
				; 魔法
				;****************************************************
				push    80000004h
				push    0
				push    485DECh
				push    10005h
				push    16010CC1h
				push    52010CBDh
				push    2
				mov     ebx, 4063B0h
				mov	edi,00405C2Fh
				call    edi
				;*****************************************************
		
			.elseif	eax == IDC_ATTACK3
				; 群攻
				;****************************************************
				push    80000004h
				push    0
				push    485D5Ah
				push    10005h
				push    16010CC1h
				push    52010CBDh
				push    2
				mov     ebx, 4063B0h
				mov	edi,00405C2Fh
				call    edi
				;****************************************************


			.elseif	eax == IDC_DEAD
				; 死亡
				;****************************************************
				push    80000004h
				push    0
				push    486055h
				push    10005h
				push    16010CC1h
				push    52010CBDh
				push    2
				mov     ebx, 4063B0h
				mov	edi,00405C2Fh
				call    edi
				;****************************************************

			.endif
			
		.else
			invoke	DefWindowProc,hWnd,uMsg,wParam,lParam
			ret
		.endif
;********************************************************************
		xor	eax,eax
		ret

_ProcWinMain	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain	proc	uses ebx esi edi _lParam
		local	@stWndClass:WNDCLASSEX
		local	@stMsg:MSG

		invoke	RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;********************************************************************
; 注册窗口类
;********************************************************************
		invoke	LoadCursor,0,IDC_ARROW
		mov	@stWndClass.hCursor,eax
		push	hInstance
		pop	@stWndClass.hInstance
		mov	@stWndClass.cbSize,sizeof WNDCLASSEX
		mov	@stWndClass.style,CS_HREDRAW or CS_VREDRAW
		mov	@stWndClass.lpfnWndProc,offset _ProcWinMain
		mov	@stWndClass.hbrBackground,COLOR_WINDOW + 1
		mov	@stWndClass.lpszClassName,offset szClassName
		invoke	RegisterClassEx,addr @stWndClass
;********************************************************************
; 建立并显示窗口
;********************************************************************
		invoke	CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaptionMain,\
			WS_OVERLAPPEDWINDOW,\
			100, 100,450, 250,\
			NULL,NULL,hInstance,NULL
		mov	hWinMain,eax
		
		;****************************************************
		;	创建按钮
		;****************************************************
		invoke	CreateWindowEx,NULL,offset szButton,offset szAttack1,\		;普攻
			WS_CHILD or WS_VISIBLE,\					
			50,40,80,40,\
			hWinMain,1,hInstance,NULL
		invoke	GetDlgCtrlID,eax
		mov	IDC_ATTACK1,eax

		invoke	CreateWindowEx,NULL,offset szButton,offset szAttack2,\		;魔法
			WS_CHILD or WS_VISIBLE,\					
			300,40,80,40,\
			hWinMain,2,hInstance,NULL
		invoke	GetDlgCtrlID,eax
		mov	IDC_ATTACK2,eax
		
		invoke	CreateWindowEx,NULL,offset szButton,offset szAttack3,\		;群攻
			WS_CHILD or WS_VISIBLE,\					
			50,140,80,40,\
			hWinMain,3,hInstance,NULL
		invoke	GetDlgCtrlID,eax
		mov	IDC_ATTACK3,eax

		invoke	CreateWindowEx,NULL,offset szButton,offset szDead,\		;死亡
			WS_CHILD or WS_VISIBLE,\					
			300,140,80,40,\
			hWinMain,4,hInstance,NULL
		invoke	GetDlgCtrlID,eax
		mov	IDC_DEAD,eax
		
		;****************************************************
		;	加载图标
		;****************************************************
		invoke	LoadIcon,hInstance,ICO_MAIN
		invoke	SendMessage,hWinMain,WM_SETICON,ICON_BIG,eax

		invoke	ShowWindow,hWinMain,SW_SHOWNORMAL
		invoke	UpdateWindow,hWinMain
;********************************************************************
; 消息循环
;********************************************************************
		.while	TRUE
			invoke	GetMessage,addr @stMsg,NULL,0,0
			.break	.if eax	== 0
			invoke	TranslateMessage,addr @stMsg
			invoke	DispatchMessage,addr @stMsg
		.endw
		ret

_WinMain	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DllEntry	proc	_hInstance,_dwReason,_dwReserved
		local	@dwThreadID

		.if	_dwReason == DLL_PROCESS_ATTACH
			push	_hInstance
			pop	hInstance
			invoke	CreateThread,NULL,0,offset _WinMain,NULL,\
				NULL,addr @dwThreadID
			invoke	CloseHandle,eax
		.endif
		mov	eax,TRUE
		ret

DllEntry	Endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		End	DllEntry

test.rc

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include		<resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define		ICO_MAIN	0x1000
ICO_MAIN	ICON		"Main.ico"

test.def

EXPORTS

Makefile

DLL = test
RES = $(DLL).res

ML_FLAG = /c /coff
LINK_FLAG = /subsystem:windows /Dll

####################################################
# 创建共享数据段的DLL时使用的连接选项
# LINK_FLAG = /subsystem:windows /Dll /section:.bss,S
####################################################

$(DLL).dll: $(DLL).obj $(DLL).def $(DLL).res
	Link  $(LINK_FLAG) /Def:$(DLL).def $(DLL).obj $(DLL).res

.asm.obj:
	ml $(ML_FLAG) $<
.rc.res:
	rc $<

clean:
	del *.obj
	del *.exp
	del *.lib
	del *.res

效果

  1. 打开任务管理器,找到程序的 pid
  2. 以超级管理员权限打开 dll注入工具
  3. 选中要注入的 dll,注入

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44018458/article/details/108933225
今日推荐