【错误记录】Android NDK 编译报错 ( no known conversion from ‘unsigned char *‘ to ‘const char *‘ )

文章目录

一、报错信息

二、解决方案





一、报错信息


在 Visual Studio 2019 中编译 Android NDK , 构建方式参考 【Android 逆向】Android 进程注入工具开发 ( Visual Studio 开发 Android NDK 应用 | 使用 Makefile 构建 Android 平台 NDK 应用 ) 博客 ;


报错信息如下 :


命令行报错信息 :


已启动生成…
1>------ 已启动生成: 项目: magic, 配置: Debug Win32 ------
1>[x86] Install        : libbridge.so => ../Debug/x86/libbridge.so
1>[x86] Install        : cmd => ../Debug/x86/cmd
1>[x86] Compile++      : native <= native.cpp
1>./native/native.cpp(428,14): warning G0C39A92D: 'SearchCode' has C-linkage specified, but returns user-defined type 'std::string' (aka 'basic_string<char>') which is incompatible with C [-Wreturn-type-c-linkage]
1>        std::string SearchCode(unsigned char* data,unsigned size){
1>                    ^
1>./native/native.cpp(442,15): error GEF7559A7: no matching function for call to 'search_string'
1>                                strOut += search_string(pModuleName, ver[i].address(), ver[i].realSize() + ver[i].address(),
1>                                          ^~~~~~~~~~~~~
1>./native/native.cpp:40:13: note: candidate function not viable: no known conversion from 'unsigned char *' to 'const char *' for 4th argument
1>std::string search_string(const char* module, unsigned begin, unsigned end, const char* data, size_t size) {
1>            ^
1>1 warning and 1 error generated.
1>make: *** [obj/local/x86/objs/native/native/native.o] Error 1
1>D:\001_Develop\017_Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(46,5): error MSB3073: 命令“"D:\001_Develop\001_SDK\Sdk\ndk\android-ndk-r14b\build\ndk-build.cmd" NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk NDK_APPLICATION_MK=Application.mk ”已退出,代码为 2。
1>已完成生成项目“magic.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

【错误记录】Android NDK 编译报错 ( no known conversion from ‘unsigned char *‘ to ‘const char *‘ )


Visual Studio 中的报错信息 :



【错误记录】Android NDK 编译报错 ( no known conversion from ‘unsigned char *‘ to ‘const char *‘ )





二、解决方案


search_string 函数定义如下 :


std::string search_string(const char* module, unsigned begin, unsigned end, 
        const char* data, size_t size) {
    ...
}


上述函数第 4 44 个参数是 const char* data , 类型是 const char* ;


函数调用时 , 在 const char* data 参数位置 , 传入了 unsigned char* 类型的数据 ;


std::string SearchCode(unsigned char* data,unsigned size){
  std::string strOut;
 
  strOut += search_string(pModuleName, ver[i].address(), ver[i].realSize() + ver[i].address(),
        data, size);
  return strOut;
    }


使用 reinterpret_cast<type-id> (expression) 进行强转 , 将 unsigned char* 类型的数据 强制转换为 const char* 类型 ;


修改后 :


std::string SearchCode(unsigned char* data,unsigned size){
  std::string strOut;
 
  strOut += search_string(pModuleName, ver[i].address(), ver[i].realSize() + ver[i].address(),
        reinterpret_cast<const char*>(data), size);
  return strOut;
    }


重新编译项目 :


已启动生成…
1>------ 已启动生成: 项目: magic, 配置: Debug Win32 ------
1>[x86] Install        : libbridge.so => ../Debug/x86/libbridge.so
1>[x86] Install        : cmd => ../Debug/x86/cmd
1>[x86] Compile++      : native <= native.cpp
1>./native/native.cpp(428,14): warning G0C39A92D: 'SearchCode' has C-linkage specified, but returns user-defined type 'std::string' (aka 'basic_string<char>') which is incompatible with C [-Wreturn-type-c-linkage]
1>        std::string SearchCode(unsigned char* data,unsigned size){
1>                    ^
1>1 warning generated.
1>[x86] SharedLibrary  : libnative.so
1>[x86] Install        : libnative.so => ../Debug/x86/libnative.so
1>[x86] Install        : tool => ../Debug/x86/tool
1>已完成生成项目“magic.vcxproj”的操作。
========== 生成: 成功 1 个,失败 0 个,最新 0 个,跳过 0 个 ==========

【错误记录】Android NDK 编译报错 ( no known conversion from ‘unsigned char *‘ to ‘const char *‘ )

上一篇:国航爆账号串联漏洞,可“无限”获取他人航班信息


下一篇:[软考考点解析]软件设计师--C程序存储空间