This is the second time I am working on 7-Zip and each time I want to debug it, I have a hard time compiling it. Hence documenting this here since the online docs are abit vague and not straight forward.
CPP\Build.mak file[Truncated]
- CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ $(CFLAGS_WARN_LEVEL) -WX -EHsc -Gy -GR- -GF
+ CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ $(CFLAGS_WARN_LEVEL) -WX -EHsc -Gy -GR- -GF -Zi
[Truncated]
!IF "$(PLATFORM)" == "x64"
- CFLAGS_O1 = $(CFLAGS) -O1
+ CFLAGS_O1 = $(CFLAGS) -Od
!ELSE
- CFLAGS_O1 = $(CFLAGS) -O1
+ CFLAGS_O1 = $(CFLAGS) -Od
!ENDIF
- CFLAGS_O2 = $(CFLAGS) -O2
+ CFLAGS_O2 = $(CFLAGS) -Od
- LFLAGS = $(LFLAGS) -nologo -OPT:REF -OPT:ICF -INCREMENTAL:NO
+ LFLAGS = $(LFLAGS) -nologo -OPT:REF -OPT:ICF -INCREMENTAL:NO -DEBUG
[Truncated]
> where cl
C:\...\bin\Hostx64\x64\cl.exe
CPP\7zip folder.# command to build
> nmake NEW_COMPILER=1 MY_STATIC_LINK=1
# Command to clean the build
> cd Bundles\Format7z && nmake clean && cd ..\Alone && nmake clean && cd ..\..\UI\FileManager && nmake clean && cd ..\GUI && nmake clean && cd ..\..\
Done!!
Debugging command with the new WinDbg from Microsoft store.
> "C:\Users\<USER>\AppData\Local\Microsoft\WindowsApps\WinDbgX.exe" -c "!gflag -htc -hfc -hpc" "D:\
Shared\Targets\7-Zip\7z2409-vulnerable-src\CPP\7zip\UI\Console\x64\7z.exe" x demo2.zip
Now, you are ready to debug 7-Zip with source code available.