c++编写SO供懒人精灵读取屏幕数据插件源码

[复制链接]
查看7614 | 回复28 | 2021-8-19 23:28:45 | 显示全部楼层 |阅读模式
采用C++编写SO给懒人调用API



  1. #include <map>
  2. #include <string>
  3. #include <vector>
  4. #include <list>
  5. #include <sys/socket.h>
  6. #include <netinet/in.h>
  7. #include <linux/if.h>
  8. #include <linux/sockios.h>
  9. #include <arpa/inet.h>
  10. #include <semaphore.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <unistd.h>
  15. #include <sys/wait.h>
  16. #include <sys/types.h>
  17. #include <fcntl.h>
  18. #include <android/log.h>
  19. #include <pthread.h>

  20. extern "C"
  21. {
  22.         #include <math.h>
  23.         #include <lua.h>
  24.         #include <lauxlib.h>
  25.         #include <lualib.h>
  26.         #include <lr.h>
  27. };
  28. using namespace std;

  29. void  LOGD(const char* fmt,...){
  30.     char str[4096];
  31.     va_list ap;
  32.     int ret;
  33.     va_start(ap, fmt);
  34.     ret = vsnprintf(str, 4096, fmt, ap);
  35.     if (ret >= 4096)
  36.         return;
  37.     __android_log_print(ANDROID_LOG_DEBUG, "LR", "%s",str);
  38. }

  39. static int lrGetPixel(lua_State *L){
  40.         int ret = 0;
  41.         luaL_checktype(L, 1, LUA_TNUMBER);//参数安全检查
  42.         luaL_checktype(L, 2, LUA_TNUMBER);
  43.         int x = (int)lua_tonumber(L,1);
  44.         int y = (int)lua_tonumber(L,2);
  45.         int w,h;
  46.         int* ptr = (int*)lrGetScreenPixel(0,0,0,0,&w,&h);//获取屏幕数据
  47.         LOGD("ret:%p %d %d",ptr,w,h);
  48.         if(ptr){
  49.                 if(x < w && y < h){
  50.                         uint8_t* argb = (uint8_t*)&ptr[y * w + x];
  51.                         lua_pushinteger(L,argb[0]);
  52.                         lua_pushinteger(L,argb[1]);
  53.                         lua_pushinteger(L,argb[2]);
  54.                         ret = 3;
  55.                 }
  56.                 lrRelease(ptr);//一定要记得释放内存
  57.         }
  58.         return ret;
  59. }


  60. static const struct luaL_Reg R[] = {
  61.     {"lrGetPixel" ,  lrGetPixel},
  62.     {NULL, NULL}
  63. };

  64. extern "C"{
  65.         LR_API int luaopen_liblrapi(lua_State*L)
  66.         {
  67.                 luaL_newlib(L, R);
  68.                 LOGD("load lrapilib");
  69.                  return 1;
  70.         }
  71. }
复制代码



c 读取屏幕数据插件源码.zip

229.76 KB, 阅读权限: 10, 下载次数: 74

售价: 10 金钱  [记录]

回复

使用道具 举报

aa627816231 | 2021-11-25 21:04:25 | 显示全部楼层
膜拜创始人
回复

使用道具 举报

小靖 | 2021-12-17 21:35:27 | 显示全部楼层
⁶⁶⁶⁶⁶     卧槽⁶⁶⁶⁶⁶⁶    666 ⁶⁶⁶⁶⁶⁶    ⁶⁶⁶⁶⁶⁶     ⁶⁶66⁶⁶⁶⁶     ⁶⁶⁶⁶⁶⁶卧槽    ⁶⁶666⁶⁶⁶⁶⁶⁶⁶⁶⁶卧槽   ⁶⁶⁶⁶⁶⁶    ⁶⁶66⁶⁶⁶⁶     卧槽⁶⁶⁶⁶⁶⁶     ⁶6666⁶⁶666牛逼!
回复

使用道具 举报

free1234 | 2021-12-23 16:21:43 | 显示全部楼层
牛逼666......
回复

使用道具 举报

jayxtxk | 2022-1-5 19:37:35 | 显示全部楼层
这是做什么用的呢
回复

使用道具 举报

zklr00001 | 2022-1-5 19:48:33 | 显示全部楼层
厉害,顶顶定
回复

使用道具 举报

592530326 | 2022-1-20 10:14:47 | 显示全部楼层
回复

使用道具 举报

lyxqge | 2022-4-18 15:42:37 | 显示全部楼层

膜拜创始人,用做什么滴?
回复

使用道具 举报

1105455693 | 2022-4-20 14:15:52 | 显示全部楼层

6666666666666666666666666
回复

使用道具 举报

wangqunmen | 2022-4-28 18:08:53 | 显示全部楼层

6666666666666666666666666
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则