On 10 May 2017 at 13:15, 'Qin Zhao' via Dr. Memory Users
<
drmemor...@googlegroups.com> wrote:
> On Wed, May 10, 2017 at 4:17 AM, Mateusz Łoskot <
mat...@loskot.net> wrote:
>>
>> Basically, I've been unable to make Dr. Memory call my DrMemFuzzFunc.
>> I've tried number of ways to run "c:\Program Files (x86)\Dr.
>> Memory\bin\drmemory.exe":
>>
>> -fuzz_module DrFuzzTest.exe -fuzz_function DrMemFuzzFunc
>> -fuzz_target "<main>!DrMemFuzzFunc|2|0|1|100" -- DrFuzzTest.exe
>
>
> Xref [1], you do not need use -fuzz_function and -fuzz_target at the same
> time.
Yes, that is clear to me.
The two lines above indicate two separate command lines I used to run
drmemory.exe.
Sorry for confusion.
>> I also tried to inspect .exe with symquery.exe --searchall
>> and search for my DrMemFuzzFunc,
>> but nothing is being found. So, I can't figure out what offset should
>> I used to try -fuzz_offset insted of -fuzz_function.
>
>
> Are you sure the function is not optimized away by the compiler, since that
> function is not called anywhere.
>> Could anyone point out what am I missing, what doing wrong?
>
>
> You should let your code to call the DrMemFuzzFunc somewhere, once DrMemory
> see the function being called, it will be fuzzed there.
Right, even if I build non-optimised configuration, I have modified
my sample according to your suggestion.
/***************************************************************/
#include <stddef.h>
#include <stdio.h>
bool FuzzMe(unsigned char *data, size_t dataSize)
{
return dataSize > 0 &&
data[0] == 'F' &&
data[1] == 'U' &&
data[2] == 'Z' &&
data[3] == 'Z'; // :‑<
}
extern "C"
void DrMemFuzzFunc(unsigned char *data, size_t dataSize)
{
FuzzMe(data, dataSize);
}
int main()
{
unsigned char data[] = "FUZZ";
DrMemFuzzFunc(data, 3);
return 0;
}
/***************************************************************/
Unfortunately, I'm still getting "NO ERRORS FOUND" report.
Also, symquery does not find any functions like DrMemFuzzFunc
=============================================================
cl.exe /Zi /W4 /Ob0 /Oy- /EHsc /MDd /D"_DEBUG" DrFuzzTest.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x86
.\DrFuzzTest.exe
"c:\Program Files (x86)\Dr. Memory\bin\drmemory.exe" -fuzz
-fuzz_module DrFuzzTest.exe -fuzz_function DrMemFuzzFunc
~~Dr.M~~ Dr. Memory version 1.11.0
~~Dr.M~~ Running "DrFuzzTest.exe -fuzz_function DrMemFuzzFunc"
~~Dr.M~~
~~Dr.M~~ NO ERRORS FOUND:
~~Dr.M~~ 0 unique, 0 total unaddressable access(es)
~~Dr.M~~ 0 unique, 0 total uninitialized access(es)
~~Dr.M~~ 0 unique, 0 total invalid heap argument(s)
~~Dr.M~~ 0 unique, 0 total GDI usage error(s)
~~Dr.M~~ 0 unique, 0 total handle leak(s)
~~Dr.M~~ 0 unique, 0 total warning(s)
~~Dr.M~~ 0 unique, 0 total, 0 byte(s) of leak(s)
~~Dr.M~~ 0 unique, 0 total, 0 byte(s) of possible leak(s)
~~Dr.M~~ ERRORS IGNORED:
~~Dr.M~~ 6 potential error(s) (suspected false positives)
~~Dr.M~~ (details: C:\Users\mateuszl\AppData\Roaming\Dr.
Memory\DrMemory-DrFuzzTest.exe.19568.000\potential_errors.txt)
~~Dr.M~~ 17 unique, 29 total, 15438 byte(s) of
still-reachable allocation(s)
~~Dr.M~~ (re-run with "-show_reachable" for details)
~~Dr.M~~ Details: C:\Users\mateuszl\AppData\Roaming\Dr.
Memory\DrMemory-DrFuzzTest.exe.19568.000\results.txt
=============================================================
>> Other Dr. Memory/Fuzz usage examples [3] I found seem to be focused on
>> Linux,
>> not Windows. Obviously, module exports work differently with Linux
>> binaries.
>> Is it necessary to __declspec(dllexport) the DrMemFuzzFunc?
>
>
> Yes, we need the find the function in the binary. Or you could specify the
> address instead.
So, does it mean __declspec(dllexport) is required for look-up by name?
For the updated sample above and CL.EXE command line specified above,
now symquery can find my DrMemFuzzFunc
"c:\Program Files (x86)\Dr. Memory\bin\symquery.exe" -e DrFuzzTest.exe
-v --searchall -s DrMemFuzzFunc
<debug info: type=PDB, has symbols, has line numbers>
DrMemFuzzFunc +0x1410-0x1425
DrMemFuzzFunc +0x1410-0x1410
and addr2line-like look-up seems working:
"c:\Program Files (x86)\Dr. Memory\bin\symquery.exe" -e DrFuzzTest.exe
-v -a 0x1410
<debug info: type=PDB, has symbols, has line numbers>
d:\workshop\drfuzztest\drfuzztest.cpp:19+0x0
However, -fuzz_offset also gives no errors like DrMemFuzzFunc would
have not been fuzzed at all
"c:\Program Files (x86)\Dr. Memory\bin\drmemory.exe" -fuzz
-fuzz_module DrFuzzTest.exe -fuzz_offset 0x1410
To summary:
- the sample program is fixed
- CL.exe command line is right (follows [1])
and seems I'm getting closer to successful run but still missing
something important.
May I ask for help?
[1]
http://drmemory.org/docs/page_prep.html