역할분담에서 각자가 짠 기드라 스크립트를 CLI 상에서 한 번의 수행으로 efi를 분석할 수 있도록 하는 역할을 맡게 되었다.
따라서 기드라와 p코드, 스크립트를 우선 공부해보고, Ghidra-analyzeHeadless도 같이 공부해야 할 예정
기드라 & p-code

ovmf의 dxe드라이버(DevicePathDxe_body.efi)를 기드라로 열어 높은 모습

listing field에서 p코드로 보이게끔 설정해 놓은 상태
p코드는
(node1) = OPERATION (node2), (node3)
위와 같은 구조를 지니고 있고, node2와 node3를 연산(operate)하여 node1에 넣는 3-address code와 비슷한 구조를 지닌다.
또 각각의 노드는
(kind, offset, size)로 구성되어 있다.
- kind: register(레지스터), const(상수), memory(메모리), unique(임시변수)
- offset : 해당 공간 내의 오프셋
- size : 데이터의 크기(byte 기준)
- 1 = 1byte, 4 = dword, 8 = qword
operation은 https://ghidra.re/ghidra_docs/languages/html/pcodedescription.html 공식 문서 참조(설명이 기깔나게 되어있다)

예시로 이와 같은 P코드가 있다면
- 첫 번째 줄은 register[0x38]의 8바이트 값을 unique[0x7e000](임시 변수)로 복사
- 두 번째 줄은 unique[0x7e000] < register[0x10] 비교
위와 같이 해석할 수 있을 것이다.
ghidra script
스크립트 메니저에 들어가서

새로운 스크립트 작성을 시작

FUN_0000039a라는 함수의 라인 번호를 찾는 script를 작성해 보았다(똑같이 나오는 게 정상)
#TODO write a description for this script
#@author
#@category _NEW_
#@keybinding
#@menupath
#@toolbar
#@runtime Jython
#TODO Add User Code Here
# -*- coding: utf-8 -*-
# Find FUN_0000039a function entry point (Fixed)
#@category Custom
#@author User
def find_function_line(func_name):
currentProgram = getCurrentProgram()
fm = currentProgram.getFunctionManager()
# Extract hex address from FUN_0000039a -> 0000039a
addr_str = func_name.split('_')[1]
try:
addr = toAddr(addr_str) # Only 1 argument!
func = fm.getFunctionAt(addr)
except:
println("Invalid address: {}".format(addr_str))
return
if func is None:
println("Function '{}' not found at {}.".format(func_name, addr_str))
return
entry_point = func.getEntryPoint()
println("Function '{}' found!".format(func_name))
println("Entry Point Address (Line): {}".format(entry_point))
# Jump to the function
goTo(entry_point)
find_function_line("FUN_0000039a")


원래 한글을 포함 시켰는데, 인코딩 에러가 발생하였다.
해결 방식에 대해서 고민해야 할 듯하다.
'졸업프로젝트' 카테고리의 다른 글
| 취약점이 반영된 검증용 드라이버... 을! 만들어 봤읍니다. (0) | 2026.02.25 |
|---|---|
| ghidra headless 사용 (0) | 2026.02.13 |
| 사전공부 5 (0) | 2026.01.30 |
| 사전공부 4 (0) | 2026.01.23 |
| 사전공부 3 (0) | 2026.01.16 |