missing number features due to compiler using LEA to load constants
See original GitHub issueSummary
Compilers may setup API call constants via offsets instead of numbers (see examples below). I’ve seen this especially in 64-bit code using the LEA
instruction.
It’s not ideal to manually account for things like this in rules as seen in https://github.com/fireeye/capa-rules/pull/122.
With some more research we can also come up with better ways to recognize such cases and only report number features accordingly.
Motivation
Per https://github.com/fireeye/capa-rules/pull/122#discussion_r489615545:
xor edx, edx ; pszRootPath
xor ecx, ecx ; hwnd
lea r8d, [rdx+7] ; dwFlags <-------
call cs:SHEmptyRecycleBinW
Another example:
.text:000000018000F0D1 lea r9d, [rsi+40h] ; flProtect <-------
.text:000000018000F0D5 xor ecx, ecx ; lpAddress
.text:000000018000F0D7 mov [rsp+0A8h+arg_0], rbp
.text:000000018000F0DF mov r8d, 3000h ; flAllocationType
.text:000000018000F0E5 mov edx, [rbp+50h] ; dwSize
.text:000000018000F0E8 call cs:VirtualAlloc
Describe alternatives you’ve considered
- Ignore edge cases like these
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
What's the purpose of the LEA instruction? - Stack Overflow
As others have pointed out, LEA (load effective address) is often used as a "trick" to do certain computations, but that's not its...
Read more >Using the LEA instruction for arbitrary arithmetic
This is the Load Effective Address instruction, which the documentation says is used to "compute an effective memory address". But your code ...
Read more >Sigma16 User Guide
Registers, constants, and arithmetic ; The architecture has a register file ; A computer program is a sequence of instructions ; Sigma16 performs ......
Read more >22C:60 Notes, Chapter 5 - University of Iowa
In fact, we now have two ways to load a 32-bit constant into a register. We can either assemble that constant in memory,...
Read more >2. Optimizing subroutines in assembly language - Agner Fog
8 Making function libraries compatible with multiple compilers ... loads the address of array A into register RBX by using a LEA instruction....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I encountered this when I was working on Luhn variations. https://github.com/fireeye/capa-rules/pull/52/files
We ended up merging the rule with 2 conditions, 1 account for the
LEA
and the other accounting for the regular numeric operation.I think you have an interesting question, but I’m not sure what the best answer is.
This is just to contribute more data to the issue so it can help steer a decision.
this proposal was agreed to verbally by @mr-tz @mike-hunhoff during our weekly call