Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: %X format: an integer is required, not float #983

Closed
mr-tz opened this issue Apr 7, 2022 · 9 comments · Fixed by #986
Closed

TypeError: %X format: an integer is required, not float #983

mr-tz opened this issue Apr 7, 2022 · 9 comments · Fixed by #986
Assignees
Labels
bug Something isn't working dotnet
Milestone

Comments

@mr-tz
Copy link
Collaborator

mr-tz commented Apr 7, 2022

python scripts/show-features.py tests/data/1c444ebeba24dcba8628b7dfe5fec7c6.exe_ -f dotnet

insn: 0x000006a9: api(System.Windows.Forms.Control::SuspendLayout)
6.0
Traceback (most recent call last):
  File "scripts/show-features.py", line 231, in <module>
    sys.exit(main())
  File "scripts/show-features.py", line 154, in main
    print_features(functions, extractor)
  File "scripts/show-features.py", line 221, in print_features
    print("insn: 0x%08x: %s" % (va, feature))
  File "C:\Users\moritz.raabe\code\Exclusions\capa\capa\features\common.py", line 143, in __str__
    return "%s(%s)" % (self.name, self.get_value_str())
  File "C:\Users\moritz.raabe\code\Exclusions\capa\capa\features\insn.py", line 25, in get_value_str
    return capa.render.utils.hex(self.value)
  File "C:\Users\moritz.raabe\code\Exclusions\capa\capa\render\utils.py", line 29, in hex
    return "0x%X" % n
TypeError: %X format: an integer is required, not float

@mr-tz mr-tz added bug Something isn't working dotnet labels Apr 7, 2022
@williballenthin
Copy link
Collaborator

williballenthin commented Apr 7, 2022

interesting, do we need a few feature for "float"? or do we put floats into the existing "number" feature?

the latter seems more readable/easier, but a bit more tricky for our code to track int vs float. but i think this is quite doable.

@mike-hunhoff
Copy link
Collaborator

dncil emits float typed constants for IL_0007 and IL_000C per ECMA.

	// Token: 0x06000006 RID: 6 RVA: 0x0000249C File Offset: 0x0000069C
	.method private hidebysig 
		instance void InitializeComponent () cil managed 
	{
		// Header Size: 12 bytes
		// Code Size: 103 (0x67) bytes
		.maxstack 3

		/* 0x000006A8 02           */ IL_0000: ldarg.0
		/* 0x000006A9 283100000A   */ IL_0001: call      instance void [System.Windows.Forms]System.Windows.Forms.Control::SuspendLayout()
		/* 0x000006AE 02           */ IL_0006: ldarg.0
		/* 0x000006AF 220000C040   */ IL_0007: ldc.r4    6
		/* 0x000006B4 2200005041   */ IL_000C: ldc.r4    13
		/* 0x000006B9 733200000A   */ IL_0011: newobj    instance void [System.Drawing]System.Drawing.SizeF::.ctor(float32, float32)
		/* 0x000006BE 283300000A   */ IL_0016: call      instance void [System.Windows.Forms]System.Windows.Forms.ContainerControl::set_AutoScaleDimensions(valuetype [System.Drawing]
...

@mike-hunhoff
Copy link
Collaborator

0x22 | ldc.r4 <float32 (num)> | Push num of type float32 onto the stack as F. | Base instruction
0x23 | ldc.r8 <float64 (num)> | Push num of type float64 onto the stack as F. | Base instruction

@williballenthin
Copy link
Collaborator

williballenthin commented Apr 7, 2022

in theory we could be extracting floats from intel code today, but we just dont for no good reason except lack of interest.

@mike-hunhoff
Copy link
Collaborator

I vote we group int and float under number to avoid over complicating rule syntax.

@mike-hunhoff
Copy link
Collaborator

but unsure how/if this complicates the matching engine.

@williballenthin
Copy link
Collaborator

i dont think it will make matching hard, just a matter of keeping the types straight throughout the codebase. its a good opportunity to update our type annotations.

@williballenthin williballenthin self-assigned this Apr 7, 2022
@mike-hunhoff mike-hunhoff added this to the 4.0.0 milestone May 2, 2022
@mr-tz
Copy link
Collaborator Author

mr-tz commented May 25, 2022

I'd say just cast to an int for now.

@williballenthin
Copy link
Collaborator

but unsure how/if this complicates the matching engine.

I don't believe the matching engine changes, assuming we're not considering 0 to be the same as 0.0 (different types).

I had updated the type annotations in #986 and mypy is happy, so I think its a pretty trivial change to add support here.

Lets add a test case to demonstrate the functionality, and if that works, support floats. If not, we can invest time in this later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dotnet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants