question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Solving for wcscmp

See original GitHub issue

Can’t seem to print stdin even after a path with scanf is found. Probably related to #113.

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

# Author: David Manouchehri <manouchehri@protonmail.com>
# Modern Binary Exploitation
# http://security.cs.rpi.edu/courses/binexp-spring2015/

import angr

FIND_ADDR = 0x080484d7 # mov dword [esp], str.Congrats_ ; [0x80485e5:4]=0x676e6f43 LEA str.Congrats_ ; "Congrats!" @ 0x80485e5
AVOID_ADDR = 0x080484eb # mov dword [esp], str.Wrong_ ; [0x80485ef:4]=0x6e6f7257 LEA str.Wrong_ ; "Wrong!" @ 0x80485ef


def main():
    proj = angr.Project('crackme0x00b', load_options={"auto_load_libs": False}) 

    path = proj.factory.path()
    path.state.options.discard("LAZY_SOLVES")


    path_group = proj.factory.path_group(path)
    path_group.explore(find=FIND_ADDR, avoid=AVOID_ADDR) 
    return path_group.found[0].state.posix.dumps(0).split('\0')[0]
    # simuvex.s_errors.SimFileError: no content in file /dev/stdin

def test():
    assert main() == 'w0wgreat'
    """
    [0x080483e0]> px 32 @ obj.pass.1964
    - offset -   0 1  2 3  4 5  6 7  8 9  A B  C D  E F  0123456789ABCDEF
    0x0804a040  7700 0000 3000 0000 7700 0000 6700 0000  w...0...w...g...
    0x0804a050  7200 0000 6500 0000 6100 0000 7400 0000  r...e...a...t...
    """

if __name__ == '__main__':
    print(main())

"""
[0x080483e0]> pdf @ main
            ;-- main:
β•’ (fcn) sym.main 101
β”‚           ; var int arg_4h @ esp+0x4
β”‚           ; var int arg_1ch @ esp+0x1c
β”‚           ; UNKNOWN XREF from 0x080483f8 (entry0)
β”‚           ; DATA XREF from 0x080483f7 (entry0)
β”‚           0x08048494      55             push ebp
β”‚           0x08048495      89e5           mov ebp, esp
β”‚           0x08048497      83e4f0         and esp, 0xfffffff0
β”‚           0x0804849a      83c480         add esp, -0x80
β”‚           ; JMP XREF from 0x080484f7 (sym.main)
β”‚       β”Œβ”€> 0x0804849d      b8d0850408     mov eax, str.Enter_password: ; "Enter password: " @ 0x80485d0
β”‚       β”‚   0x080484a2      890424         mov dword [esp], eax
β”‚       β”‚   0x080484a5      e8d6feffff     call sym.imp.printf
β”‚       β”‚   0x080484aa      b8e1850408     mov eax, 0x80485e1
β”‚       β”‚   0x080484af      8d54241c       lea edx, [esp + arg_1ch]    ; 0x1c
β”‚       β”‚   0x080484b3      89542404       mov dword [esp + arg_4h], edx
β”‚       β”‚   0x080484b7      890424         mov dword [esp], eax
β”‚       β”‚   0x080484ba      e811ffffff     call sym.imp.__isoc99_scanf
β”‚       β”‚   0x080484bf      8d44241c       lea eax, [esp + arg_1ch]    ; 0x1c
β”‚       β”‚   0x080484c3      89442404       mov dword [esp + arg_4h], eax
β”‚       β”‚   0x080484c7      c7042440a004.  mov dword [esp], obj.pass.1964 ; [0x804a040:4]=119 LEA obj.pass.1964 ; "w" @ 0x804a040
β”‚       β”‚   0x080484ce      e8bdfeffff     call sym.imp.wcscmp
β”‚       β”‚   0x080484d3      85c0           test eax, eax
β”‚      β”Œβ”€β”€< 0x080484d5      7514           jne 0x80484eb
β”‚      β”‚β”‚   0x080484d7      c70424e58504.  mov dword [esp], str.Congrats_ ; [0x80485e5:4]=0x676e6f43 LEA str.Congrats_ ; "Congrats!" @ 0x80485e5
β”‚      β”‚β”‚   0x080484de      e8bdfeffff     call sym.imp.puts
β”‚      β”‚β”‚   0x080484e3      90             nop
β”‚      β”‚β”‚   0x080484e4      b800000000     mov eax, 0
β”‚      β”‚β”‚   0x080484e9      c9             leave
β”‚      β”‚β”‚   0x080484ea      c3             ret
β”‚      └──> 0x080484eb      c70424ef8504.  mov dword [esp], str.Wrong_ ; [0x80485ef:4]=0x6e6f7257 LEA str.Wrong_ ; "Wrong!" @ 0x80485ef
β”‚       β”‚   0x080484f2      e8a9feffff     call sym.imp.puts
β•˜       └─< 0x080484f7      eba4           jmp 0x804849d

"""

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:26 (25 by maintainers)

github_iconTop GitHub Comments

1reaction
ltfishcommented, May 25, 2016

Should be the same problem as reported here: https://github.com/angr/angr/issues/110

I’ll update this issue when the commit of SimuVEX is merged and released.

0reactions
glen-maccommented, Mar 13, 2017

Was reversing the same binary and had the same issue.

Have latest release on pip of angr, seems this is still an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

wcscmp() function in C++ with Examples - GeeksforGeeks
The wcscmp() function is used to compares two null terminating wide string and this comparison is done lexicographically. Syntax: int wcscmp(Β ...
Read more >
What is wcscmp in C? - Educative.io
Learn the 24 patterns to solve any coding interview question without getting lost ... The wcscmp function in C lexicographically compares two wide...
Read more >
wcscmp() β€” Compare Wide-Character Strings - IBM
The wcscmp() function compares two wide-character strings. The wcscmp() function operates on null-ended wchar_t strings; string arguments to this functionΒ ...
Read more >
Why wcscmp() returns True when two strings are different?
The wcscmp() function returns an integer value, not a bool value. If the two strings are equal, it returns the integer value 0....
Read more >
[Solved] How to compare BSTR with char* - CodeProject
So you must compare with a wide string and use a string compare function: C++. if (0 == wcscmp(var, L"a")) printf("they are equal\n");....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found