Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Prefetch input queue
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==x86 example code== <syntaxhighlight lang=nasm> code_starts_here: mov bx, ahead mov word ptr cs:[bx], 9090h ahead: jmp near to_the_end ; Some other code to_the_end: </syntaxhighlight> This [[self-modifying code|self-modifying]] program will overwrite the ''jmp to_the_end'' with two [[NOP (code)|NOP]]s (which is encoded as ''0x9090''). The jump ''jmp near to_the_end'' is assembled into two bytes of machine code, so the two NOPs will just overwrite this jump and nothing else. (That is, the jump is replaced with a do-nothing-code.) Because the machine code of the jump is already read into the PIQ, and probably also already executed by the processor ([[superscalar]] processors execute several instructions at once, but they "pretend" that they don't because of the need for [[backward compatibility]]), the change of the code will not have any change of the execution flow. ===Example program to detect size=== This is an example [[NASM (computer program)|NASM]]-[[syntax]] [[Self-modifying code|self-modifying]] [[x86]]-[[assembly language]] algorithm that determines the size of the PIQ: <syntaxhighlight lang=nasm> code_starts_here: xor bx, bx ; zero register bx xor ax, ax ; zero register ax mov dx, cs mov [code_segment], dx ; "calculate" codeseg in the far jump below (edx here too) around: cmp ax, 1 ; check if ax has been altered je found_size ; 0x90 = opcode "nop" (NO oPeration) mov byte [nop_field+bx], 0x90 inc bx db 0xEA ; 0xEA = opcode "far jump" dw flush_queue ; should be followed by offset (rm = "dw", pm = "dd") code_segment: dw 0 ; and then the code segment (calculated above) flush_queue: ; 0x40 = opcode "inc ax" (INCrease ax) mov byte [nop_field+bx], 0x40 nop_field: times 256 nop jmp around found_size: ; ; register bx now contains the size of the PIQ ; this code is for [[real mode]] and [[16-bit protected mode]], but it could easily be changed into ; running for [[32-bit protected mode]] as well. just change the "dw" for ; the offset to "dd". you need also change dx to edx at the top as ; well. (dw and dx = 16 bit addressing, dd and edx = 32 bit addressing) ; </syntaxhighlight> What this code does is basically that it changes the execution flow, and determines by [[brute-force search|brute force]] how large the PIQ is. "How far away do I have to change the code in front of me for it to affect me?" If it is too near (it is already in the PIQ) the update will not have any effect. If it is far enough, the change of the code will affect the program and the program has then found the size of the processor's PIQ. If this code is being executed under multitasking OS, the [[context switch]] may lead to the wrong value.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)