ext4 解包和打包
2020-5-14
环境:
Ubuntu
解包工具:
sudo apt-get install android-tools-fsutils
转换文件:
simg2img rootfs_256M.ext4 rootfs_256M
挂载
mkdir /tmp/rootfs
mount -o loop rootfs_256M /tmp/rootfs
修改
重新打包
make_ext4fs -l XXXXM -s rootfs_256M.ext4 /tmp/rootfs
IDEA导入jave-1.0.2 xuggle-xuggler-5.4
2020-1-3
1.配置pom.xml
<dependency>
<groupId>it.sauronsoftware</groupId>
<artifactId>jave</artifactId>
<version>1.0.2</version>
</dependency>
<!--xuggle依赖-->
<dependency>
<groupId>xuggle</groupId>
<artifactId>xuggle-xuggler</artifactId>
<version>5.4</version>
</dependency>
2. 从网上下载jave-1.0.2 xuggle-xuggler-5.4
http://www.sauronsoftware.it/projects/jave/download.php
https://mvnrepository.com/artifact/xuggle/xuggle-xuggler/5.4
3. 拷贝对应的jar文件到目录中
C:\Program Files\JetBrains\apache-maven-3.5.0\repo\it\sauronsoftware\jave\1.0.2
C:\Program Files\JetBrains\apache-maven-3.5.0\repo\xuggle\xuggle-xuggler\5.4
windows 与 USB设备进行数据交换实现
2019-12-5 C++
需求:上位机通过USB与下位机进行数据交互
实现:
打开设备:
static LONG HidOpen(DWORD HidUsbMian, DWORD HidUsbSub)
{
//hid设备GUID
CString strHidPath(_T(""));
HDEVINFO deviceInfoSet = INVALID_HANDLE_VALUE;
PSP_DEVICE_INTERFACE_DETAIL_DATA pDeviceInterfaceDetailData = NULL;
SP_DEVINFO_DATA devinfoData;
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
ZeroMemory(&deviceInterfaceData, sizeof(SP_DEVICE_INTERFACE_DATA));
ZeroMemory(&devinfoData, sizeof(SP_DEVINFO_DATA));
devinfoData.cbSize = sizeof(SP_DEVINFO_DATA);
deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
GUID interfaceClassGuid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30} };
deviceInfoSet = SetupDiGetClassDevsA(&interfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
int deviceIndex = 0;
BOOL bExit = FALSE;
for ( ; bExit == FALSE; )
{
do
{
HANDLE writeHandle = INVALID_HANDLE_VALUE;
DWORD dwRequiredSize = 0;
BOOL res = SetupDiEnumDeviceInterfaces(deviceInfoSet,
NULL,
&interfaceClassGuid,
deviceIndex,
&deviceInterfaceData);
if (res == FALSE)
{
bExit = TRUE;
break;
}
BOOL bFind = FALSE;
for (int i = 0; ; ++i)
{
TCHAR szDriverName[MAX_PATH] = { 0 };
res = SetupDiEnumDeviceInfo(deviceInfoSet, i, &devinfoData);
if (res == FALSE)
{
break;
}
res = SetupDiGetDeviceRegistryProperty(deviceInfoSet, &devinfoData,
SPDRP_CLASS, NULL, reinterpret_cast<PBYTE>(szDriverName), sizeof(szDriverName), NULL);
if (res == FALSE)
{
break;
}
if (_tcscmp(szDriverName, _T("HIDClass")) == 0)
{
res = SetupDiGetDeviceRegistryProperty(deviceInfoSet, &devinfoData,
SPDRP_DRIVER, NULL, reinterpret_cast<PBYTE>(szDriverName), sizeof(szDriverName), NULL);
if (res == TRUE)
{
bFind = TRUE;
break;
}
}
}
//不是有效的设备的继续
if (FALSE == bFind)
{
break;
}
res = SetupDiGetDeviceInterfaceDetail(deviceInfoSet,
&deviceInterfaceData,
NULL,
0,
&dwRequiredSize,
NULL);
pDeviceInterfaceDetailData = reinterpret_cast<PSP_DEVICE_INTERFACE_DETAIL_DATA>(malloc(dwRequiredSize));
pDeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
res = SetupDiGetDeviceInterfaceDetail(deviceInfoSet,
&deviceInterfaceData,
pDeviceInterfaceDetailData,
dwRequiredSize,
NULL,
NULL);
writeHandle = CreateFile(pDeviceInterfaceDetailData->DevicePath, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
/*FILE_FLAG_OVERLAPPED,/*FILE_ATTRIBUTE_NORMAL,*/
if (writeHandle == INVALID_HANDLE_VALUE)
{
break;
}
HIDD_ATTRIBUTES attrib;
attrib.Size = sizeof(HIDD_ATTRIBUTES);
HidD_GetAttributes(writeHandle, &attrib);
/*
if ((HidUsbMian == 0x0 || attrib.VendorID == HidUsbMian)
&& (HidUsbSub == 0x0 || attrib.ProductID == HidUsbSub))
*/
if (attrib.VendorID == HidUsbMian && attrib.ProductID == HidUsbSub)
{
strHidPath = pDeviceInterfaceDetailData->DevicePath;
}
CloseHandle(writeHandle);
} while (0);
if (pDeviceInterfaceDetailData != NULL)
{
free(pDeviceInterfaceDetailData);
pDeviceInterfaceDetailData = NULL;
}
if (strHidPath != _T(""))
{
break;
}
++deviceIndex;
}
if (strHidPath == _T(""))
{
return 0;
}
HANDLE openHandle = CreateFile(strHidPath,
GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, 0);
HANDLE readHandle = CreateFile(strHidPath,
GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
0, 0);
/*FILE_FLAG_OVERLAPPED,/*FILE_ATTRIBUTE_NORMAL,*/
if (openHandle == INVALID_HANDLE_VALUE)
{
return NULL;
}
do
{
PHIDP_PREPARSED_DATA ppData = NULL;
HIDP_CAPS caps;
if (0)//0 == HidD_SetNumInputBuffers(openHandle, 512))
{
::OutputDebugString(_T("-------------HidD_SetNumInputBuffers Failed-------\r\n"));
break;
}
if (0 == HidD_GetPreparsedData(openHandle, &ppData))
{
::OutputDebugString(_T("-------------HidD_GetPreparsedData Failed-------\r\n"));
break;
}
NTSTATUS ntStatus = HidP_GetCaps(ppData, &caps);
if (ntStatus != HIDP_STATUS_SUCCESS)
{
::OutputDebugString(_T("-------------HidP_GetCaps Failed-------\r\n"));
break;
}
{
CString strMsg(_T(""));
strMsg.Format(_T("--Input Length[%d]---Output Length[%d]----\r\n"), caps.InputReportByteLength, caps.OutputReportByteLength);
::OutputDebugString(strMsg);
}
HidD_FreePreparsedData(ppData);
PHidDevice dev = NewHidDevice();
if (dev != NULL)
{
dev->deviceHandle = openHandle;
dev->deviceReadHandle = readHandle;
int nBufLen = (strHidPath.GetLength() + 1);
dev->devicePath = new TCHAR[nBufLen];
if (dev->devicePath != NULL)
{
memset(dev->devicePath, 0, nBufLen * sizeof(TCHAR));
_tcscpy_s(dev->devicePath, nBufLen, strHidPath.GetString());
}
}
return reinterpret_cast<long>(dev);
} while (0);
if (openHandle != INVALID_HANDLE_VALUE)
{
CloseHandle(openHandle);
openHandle = INVALID_HANDLE_VALUE;
}
if (readHandle != INVALID_HANDLE_VALUE)
{
CloseHandle(readHandle);
readHandle = INVALID_HANDLE_VALUE;
}
return 0;
}
读数据:
ReadFile(handle, buf, 18, &dwReaded, NULL) ;
写数据:
OVERLAPPED ol;
memset(&ol, 0, sizeof(OVERLAPPED));
ol.hEvent = ::CreateEventA(NULL, TRUE, FALSE, NULL);
do
{
int nCurLen = nBufSize >= 8 ? 8 : nBufSize;
memset(buf, 0, 11);
buf[0] = 0x00;
buf[1] = LOBYTE(nCurLen);
buf[2] = 0x00;
memcpy(buf + 3, pTmp, nCurLen);
ResetEvent(ol.hEvent);
BOOL bRet = WriteFile(dev->deviceHandle, reinterpret_cast<LPVOID>(buf), 11, &dwWrited, &ol);
if (bRet == FALSE)
{
DWORD dwTmp = 0;
GetOverlappedResult(dev->deviceHandle, &ol, &dwTmp, TRUE);
}
pTmp += nCurLen;
nBufSize -= nCurLen;
} while (nBufSize > 0);
if (ol.hEvent != NULL)
{
CloseHandle(ol.hEvent);
}
坑1:
传输大数据时,在有的电脑,会出现卡死情况
解决方式:
读跟写句柄分开创建,具体原因不明
MFC 函数注入
2019-11-22 C++
问题:
USB 通信DLL代码找不到,无法知道通信协议
解决思路:
注入windows相关接口,查看通信过程中发送的协议
实现代码:比如注入CreateFile
typedef HANDLE(WINAPI * Real_CreateFile) (
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile);
1. 保存函数调用地址
BYTE g_oldJmp[6] = { 0 };
BYTE g_jmp[6] = { 0 };
2. 实现注入函数 执行函数前先恢复原接口函数地址,执行完再设置为更改后的地址
HANDLE WINAPI Routed_CreateFile(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
CStringW strTmp(lpFileName);
HANDLE handle = NULL;
VirtualProtect((LPVOID)g_pOrigCreateFile, 6, g_myProtect, NULL); //ReadWrite again
memcpy(g_pOrigCreateFile, g_oldJmp, 6); //Unhook API
handle = CreateFileW(strTmp.GetString(), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
memcpy(g_pOrigCreateFile, g_jmp, 6); //Rehook API
VirtualProtect((LPVOID)g_pOrigCreateFile, 6, g_oldProtect, NULL); //Normal setts
CStringW strMsg(_T(""));
strMsg.Format(L"%s %x %x %x %x %x\r\n", strTmp.GetString(), dwDesiredAccess, dwShareMode, handle, dwCreationDisposition, dwFlagsAndAttributes);
::OutputDebugStringW(strMsg);
return handle;
}
//注入接口
void BeginRedirect(LPVOID newFunction, LPVOID oldFunction, BYTE *jmp, BYTE *oldJmp)
{
BYTE tempJMP[6] = {0xE9, 0x90, 0x90, 0x90, 0x90, 0xC3};
memcpy(jmp, tempJMP, 6);
DWORD dwJMPSize = (reinterpret_cast<DWORD>(newFunction) - reinterpret_cast<DWORD>(oldFunction) - 5);
VirtualProtect(oldFunction, 6, PAGE_EXECUTE_READWRITE, &g_oldProtect);
//Change memory settings to make sure we can write the JMP in
memcpy(oldJmp, oldFunction, 6); //Copy old bytes before writing JMP
memcpy(&jmp[1], &dwJMPSize, 4); //Write the address to JMP to
memcpy(oldFunction, jmp, 6); //Write it in process memory
VirtualProtect((LPVOID)oldFunction, 6, g_oldProtect, NULL); //Change
}
//初始化
g_pOrigCreateFile = reinterpret_cast<Real_CreateFile>(GetProcAddress(GetModuleHandle("Kernel32.dll"), "CreateFileW"));
if (g_pOrigCreateFile != NULL)
{
BeginRedirect(Routed_CreateFile, g_pOrigCreateFile, g_jmp, g_oldJmp);
}
局域网内异常DHCP服务器查找
2019-4-27
现象:
公司内部局域网突然上不了网,使用ipconfig查看了下IP,非路由器分配的
故障排查:
1. 启动wireshark,输入过滤条件bootp
2. 接入网线
3. 查看wireshark抓包到的DHCP ACK源MAC地址
4. 查看公司内部谁的电脑MAC地址与之相同,关闭DHCP服务
标签: DHCP
海康威视GB28181视频流接收解析显示
2019-3-1
海康威视国标GB28181获取视频流并显示
环境:
MFC,jRtp,ffmpeg,sdl2.0,eXosip,
海康威视摄像头:DS-2CD3T27EDWD-L
思路:
利用eXosip实现sip服务端及客户端,实现GB28181协议交互
利用jRtp接收摄像头rtp视频流
利用ffmpeg解码视频流(由于海康威视ps视频流里面含有一些私有协议会导致花屏,因此这边需要先把ps流解析成H264视频流)
利用sdl显示视频
wireshark抓包数据获取rtsp请求的视频流
2019-1-17 C++
lua脚本下载:https://github.com/volvet/h264extractor
1. 安装wireshark软件
2. 编辑wireshark安装目录底下的init.lua,设置disable_lua = false;
3. 在init.lua的最后加上dofile(DATA_DIR.."rtp_h264_extractor.lua")
4. 把rtp_h264_extractor.lua放在wireshark同一路径下
5. 打开wireshark抓取的网络数据流
6.设置过滤条件分析:如rtsp.method == "PLAY" && ip.src == 1.1.1.1
获取ip地址为1.1.1.1请求的所有rtsp视频流
7.通过tcp端口获取要分析的视频流的所有交互数据:如tcp.port == 57109
获取通过57109该端口交互的rtsp视频流数据
8.导出该视频流数据:文件->导出特定分组 All packets Displayed
9.查看导出的数据视频流编码格式:
查找抓包数据服务端对客户端DESCRIBE请求的回复数据包,找到Media Attribute节点
查看编码是否H264,及type值 如96,如是H264则继续往下
10.设置H264的编码载体类型
编辑->首选项->Protocols->H264设置H264 dynamic payload types为96
11.导出H264数据裸流:工具->Extract h264 stream from RTP
12.在数据流的同一目录底下生成dump.264
13.打开vlc,设置分流器为H264
工具->偏好设置->全部(出来高级偏好设置)->输入/编解码器->分流器->分流模块->H264
14.编号生成的dump.264文件
CStdioFile Unicode ReadString 读取汉字乱码
2018-10-21 C++
1. Unicode 模式下ReadString 需要使用typebinary读取文本,中文才不会乱码
CStdioFile file;
if (file.Open(filePath, CFile::modeRead | CFile::typeBinary) == TRUE){
CString strLine(_T(""));
WORD sign;
file.Read(&sign, 2);
while (file.ReadString(strLine))
{
m_listInfo.InsertString(m_listInfo.GetCount(), strLine);
}
file.Close();
}
标签: MFC StdioFile ReadString
MFC CEdit背景透明,文字透明实现
2018-6-17
需求:不规则输入框实现
实现:
1. 响应对话框的WM_CTLCOLOR消息
获取EDIT对应的窗口背景色,设置画刷为NULL
if (nCtlColor == CTLCOLOR_EDIT)
{
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkMode(TRANSPARENT);
CDC* dc = GetDC();
CRect rc;
pWnd->GetWindowRect(rc);
ScreenToClient(rc);
pDC->BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCCOPY);
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
2. 响应EN_CHANGE消息
获取控件所在的位置,通知窗口进行刷新
CRect rc;
GetDlgItem(IDC_EDIT_USER_NAME)->GetWindowRect(&rc);
ScreenToClient(&rc);
InvalidateRect(&rc, TRUE);
Parasoft c++test 9.6安装使用导引交叉编译
2018-5-12
Parasoft c++test 9.6安装使用导引
参考:https://blog.csdn.net/flyoxs/article/details/53524044
参考: https://docs.parasoft.com/display/CPPDESKE1033
安装
直接照文档一步步安装,略过
通用过程
1. 创建C++ Test测试项目
1.VS项目
2.linux MakeFile项目
使用cpptestscan工具生成BDF文件
2.运行分析
3.复查结果
生成BDF文件
修改Makefile ,在CC/CXX前添加cpptestscan完成路径
自定义编译器
针对嵌入式代码,找不到合适的编译器,需要自己创建创建编译器
步骤:
https://docs.parasoft.com/display/CPPDESKE1033/Configuring+Testing+with+the+Cross+Compiler
注:不知道交叉编译的GCC版本的话选择最新的GCC 如(4.9.x),
如选择的GCC版本低于交叉编译器的GCC版本,可能会实际编译通过但是CPPC++Test编译报错!
修改项目编译器
BugDetective
可能出现错误结果
1. __atomic_fetch_add" is undefined
自定义编译器对应的gcc版本太低
2. 类成员变量申明时直接初始化报错
自定义编译器对应的gcc版本太低