微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

这个非虚函数被反编译后怎么办?

如何解决这个非虚函数被反编译后怎么办?

所以我决定尝试 Ghidra 反编译/反汇编一个带有虚函数和非虚函数的简单 C++ 类。然而;反编译让我有点困惑。下面,是我的来源和我的反编译。我不明白的是为什么对非虚函数调用包含诸如打印字符串和这 3 个其他奇怪参数之类的参数。这些其他参数是什么?我只能假设其中一个是“This”指针?如果有,另外两个是什么?

编译在visual studio 2k17 x64 release no pdb

来源

Try

    Dim Request As WebRequest
    Dim WResponse As WebResponse
    Dim DataStream As Stream
    Dim Reader As StreamReader
    Dim SoapByte() As Byte
    Dim SoapStr As String

    SoapStr = "Pretty sure this SoapStr is valid"

    SoapByte = System.Text.Encoding.UTF8.GetBytes(SoapStr)

    Request = WebRequest.Create("url goes here")
    Request.Headers.Add("SOAPAction","same to here")

    Request.ContentType = "text/xml; charset=utf-8"
    Request.ContentLength = SoapByte.Length
    Request.Method = "POST"

    DataStream = Request.GetRequestStream()
    DataStream.Write(SoapByte,SoapByte.Length)

    WResponse = Request.GetResponse()
    DataStream = WResponse.GetResponseStream()

    Reader = New StreamReader(DataStream)
    'Dim SD2Request As String = Reader.ReadToEnd()
    'Response.Write(Response)

    DataStream.Close()
    Reader.Close()
    Response.Close()

Catch ex As WebException
    Dim err As String = New System.IO.StreamReader(ex.Response.GetResponseStream()).ReadToEnd()
    Response.Write(err)
    '& "<br/>Status Code: " & Response.StatusCode & " " & Response.StatusDescription)
End Try

反编译

#include <iostream>
#include <stdio.h>

class Person
{
public:
    Person(int val)
    {
        myval = val;
    }

    void PersonFunction()
    {
        printf("this is a person func/n");
    }

    virtual void PersonFunction2()
    {
        printf("this is a person func2/n");
    }

protected:
    int myval = 5;
};

int main(int argc,char** argv)
{
    Person * person = new Person(10);
    std::cout << "Hello World!\n";
    person->PersonFunction();
    person->PersonFunction2();
}

谁能解释一下接受我的字符串和三个参数的函数是怎么回事?参数是什么?为什么要传递字符串?

解决方法

所以看起来 MSVC++ 编译器刚刚优化并将 printf 直接内联到 main 中。 这就是 printf 在带有 vaargs 的情况下的样子:

_Check_return_opt_
_CRT_STDIO_INLINE int __CRTDECL printf(
    _In_z_ _Printf_format_string_ char const* const _Format,...)
#if defined _NO_CRT_STDIO_INLINE
;
#else
{
    int _Result;
    va_list _ArgList;
    __crt_va_start(_ArgList,_Format);
    _Result = _vfprintf_l(stdout,_Format,NULL,_ArgList);
    __crt_va_end(_ArgList);
    return _Result;
}
#endif

_Check_return_opt_
_CRT_STDIO_INLINE int __CRTDECL _vfprintf_l(
    _Inout_  FILE*       const _Stream,_In_z_   char const* const _Format,_In_opt_ _locale_t   const _Locale,va_list           _ArgList
    )
#if defined _NO_CRT_STDIO_INLINE
;
#else
{
    return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS,_Stream,_Locale,_ArgList);
}
#endif

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。