Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In my code, my flags are not correct, nor is ESP. Is there a way to fix the code without changing the ShowFlags MACRO. It

In my code, my flags are not correct, nor is ESP. Is there a way to fix the code without changing the ShowFlags MACRO. It needs to remain as such. ShowFlag MACRO flagName,shiftCount
LOCAL flagStr, flagVal, L1
.data
flagStr BYTE" &flagName="
flagVal BYTE?,0
.code
push eax
push edx
mov eax,eflags ; retrieve the flags
mov flagVal,'1'
shr eax,shiftCount ; shift into carry flag
jc L1
mov flagVal,'0'
L1:
mov edx,OFFSET flagStr ; display flag name and value
call WriteString
pop edx
pop eax
ENDM INCLUDE asmlib.inc
.data
EAXStr BYTE "EAX: ",0
EBXStr BYTE "EBX: ",0
ECXStr BYTE "ECX: ",0
EDXStr BYTE "EDX: ",0
ESIStr BYTE "ESI: ",0
EDIStr BYTE "EDI: ",0
EBPStr BYTE "EBP: ",0
ESPStr BYTE "ESP: ",0
EIPStr BYTE "EIP: ",0
EFLStr BYTE "EFL: ",0
eflags DWORD 0
.code
ShowFlag MACRO flagName, shiftCount
LOCAL flagStr, flagVal, L1
.data
flagStr BYTE " &flagName=",0
flagVal BYTE ?,0
.code
push eax
push edx
mov eax, eflags
mov flagVal, '1'
shr eax, shiftCount
jc L1
mov flagVal, '0'
L1:
mov edx, OFFSET flagStr
call writeString
mov al, flagVal
call writeChar
pop edx
pop eax
ENDM
Tab MACRO
push eax
mov al,09h
call writeChar
pop eax
ENDM
showRegister PROC regName:PTR BYTE, regValue:DWORD
pushad
mov edx, regName
call writeString
mov eax, regValue
call writeHex
Tab
popad
ret
showRegister ENDP
dumpRegisters PROC
pushad
pushfd
invoke showRegister, ADDR EAXStr, eax
invoke showRegister, ADDR EBXStr, ebx
invoke showRegister, ADDR ECXStr, ecx
invoke showRegister, ADDR EDXStr, edx
invoke showRegister, ADDR ESIStr, esi
invoke showRegister, ADDR EDIStr, edi
invoke showRegister, ADDR EBPStr, ebp
push ebp
mov ebp,esp
invoke showRegister, ADDR ESPStr, eax
mov eax,ebx
mov esp,ebp
pop ebp
call GetEIP
GetEIP:
pop eax
mov eax, [esp +36]
invoke showRegister, ADDR EIPStr, eax
mov eax, eflags
invoke showRegister, ADDR EFLStr, eax
ShowFlag CF,0
ShowFlag SF,7
ShowFlag ZF,6
ShowFlag OF,11
ShowFlag AF,4
ShowFlag PF,2
popfd
popad
ret
dumpRegisters ENDP
main PROC
pushfd
pop eflags
call dumpRegisters
exit
main ENDP
END main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

Students also viewed these Databases questions

Question

1 What are the three key facets of HRP?

Answered: 1 week ago