irc

彼节者有间,而刀刃者无厚;以无厚入有间,恢恢乎其于游刃必有余地矣!

导航

测试文章

测试文章

C:\Windows\system32\userinit.exe,
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

httpiportal.nebuinfo.comEmployeehome


0018FAA8   0066DC58  ASCII "7748354003921836E2D157255E2C1081"

  1 #include "stdafx.h"
  2 #include "helper.h"
  3 #include <Windows.h>
  4 
  5 //_taccess 需要
  6 #include  <io.h>
  7 #include  <stdio.h>
  8 #include  <stdlib.h>
  9 #include "IniUtil.h"
 10 
 11 inline string ValueToIP(const int& nValue)
 12 {
 13     //数值转化为IP
 14     //没有格式检查
 15     //返回值就是结果
 16 
 17     char strTemp[20];
 18     sprintf_s(strTemp, 20, "%d.%d.%d.%d",
 19         (nValue&0x000000ff),
 20         (nValue&0x0000ff00)>>8,
 21         (nValue&0x00ff0000)>>16,
 22          (nValue&0xff000000)>>24);
 23 
 24     return string(strTemp);
 25 }
 26 
 27 unsigned int IPToValue(const string& strIP)
 28 {
 29     //IP转化为数值
 30     //没有格式检查
 31     //返回值就是结果
 32     //// ip去零
 33     //string strMinusZeroIP;
 34     //MinusZeroIP(strIP, strMinusZeroIP);
 35 
 36     int a[4];
 37     string IP = strIP;
 38     string strTemp;
 39     size_t pos;
 40     size_t i=3;
 41 
 42     do
 43     {
 44         pos = IP.find(".");
 45 
 46         if(pos != string::npos)
 47         {
 48             strTemp = IP.substr(0,pos);
 49             a[i] = atoi(strTemp.c_str());
 50             i--;
 51             IP.erase(0,pos+1);
 52         }
 53         else
 54         {
 55             strTemp = IP;
 56             a[i] = atoi(strTemp.c_str());
 57             break;
 58         }
 59 
 60     }while(1);
 61 
 62     unsigned int nResult = (a[3]<<24) + (a[2]<<16)+ (a[1]<<8) + a[0];
 63     return nResult;
 64 }
 65 
 66 //如果字符串长度小于3则前面加零 补足三位
 67 void RuleString(string& strInIP)
 68 {
 69     size_t sizetLen = strInIP.length();
 70     if (sizetLen<3)
 71     {
 72         strInIP.insert(0, 3-sizetLen, '0');
 73     }
 74 }
 75 
 76 //IP字符串加0
 77 void AddZeroIP(string strInIP, string& strOutIP)
 78 {
 79     if (!strInIP.length()) return;
 80     string strFront;
 81     string strBack = strInIP;
 82     size_t sizetPos = strBack.find('.');
 83     //如果没找到
 84     if (string::npos == sizetPos)
 85     {
 86         RuleString(strBack);
 87         strOutIP.append(strBack, 0, strBack.length());
 88         return;
 89     }
 90     strFront.append(strBack, 0, sizetPos);
 91     RuleString(strFront);
 92     strFront.append(1, '.');
 93     strBack.erase(0, sizetPos+1);
 94 
 95     AddZeroIP(strBack, strFront);    
 96 
 97     strOutIP.append(strFront, 0, strFront.length());
 98 }
 99 
100 //字符串前面去零
101 void StringFrontMinusZero(string& strIN)
102 {
103     if ('0' != strIN.at(0)) return;
104     strIN.assign(strIN, 1, strIN.length());
105     StringFrontMinusZero(strIN);
106 }
107 //IP字符串去0
108 void MinusZeroIP(string strInIP, string& strOutIP)
109 {
110     if (!strInIP.length()) return;
111     string strFront;
112     string strBack = strInIP;
113     size_t sizetPos = strBack.find('.');
114     //如果没找到
115     if (string::npos == sizetPos)
116     {
117         StringFrontMinusZero(strBack);
118         strOutIP.append(strBack, 0, strBack.length());
119         return;
120     }
121     strFront.append(strBack, 0, sizetPos+1);
122     StringFrontMinusZero(strFront);
123     strBack.erase(0, sizetPos+1);
124 
125     MinusZeroIP(strBack, strFront);    
126 
127     strOutIP.append(strFront, 0, strFront.length());
128 }
129 
130 string ValueToIPZero(const int& nValue)
131 {
132     string strIPZero;
133     string strIP = ValueToIP(nValue);
134     //TracePrint(LOG_INFO, "ValueToIPZero IPValue:%02hhx; IP:%s!!!\r\n", nValue, strIP.c_str());
135     AddZeroIP(strIP, strIPZero);
136     return strIPZero;
137 }
138 
139 bool CheckIsIP(const TCHAR *pszInIP)
140 {
141     int iNumCount = 0, iDotCount = 0;
142 
143     for (int i=0; i <(int)_tcsclen(pszInIP); i++) 
144     {
145         if (iNumCount > 3)
146         {
147             return false;
148         }
149 
150         if (!(pszInIP[i] >= '0' && pszInIP[i] <= '9' )) 
151         {
152             if ( pszInIP[i] != '.' ) 
153             {
154                 return false;
155             }
156 
157             iNumCount = 0;
158             iDotCount++;
159             continue;
160         }
161 
162         iNumCount++;
163     }
164 
165     if (iDotCount != 3 ) 
166     {
167         return false;
168     }
169 
170     return true;
171 }
172 
173 //获取当前程序所在目录 成功返回true,失败返回false
174 bool GetExePath(TCHAR* ptInPath)
175 {
176     TCHAR* ptTem = NULL;
177     TCHAR tszTemp[MAX_PATH] = {0};
178     //获取当前目录  //这里是获取当前进程文件的完整路径 
179     if (!GetModuleFileName(NULL, tszTemp, MAX_PATH) && ptInPath)
180         return false; 
181 
182     ptTem = _tcsrchr(tszTemp, _T('\\'));
183     memcpy(ptInPath, tszTemp, (_tcslen(tszTemp)-_tcslen(ptTem))*sizeof(TCHAR));
184     return true;
185 }
186 
187 //检查当前目录需要的文件夹是否存在,如果不存在返回false,存在返回true
188 bool CheckDirExist(const TCHAR* ptInPath)
189 {
190     //方法1
191     if (!ptInPath || _tcsclen(ptInPath)<2)    
192     {
193         return false;
194     }
195 
196     //检验路径是否存在
197     DWORD dwFileAttributes = GetFileAttributes(ptInPath);
198     if (INVALID_FILE_ATTRIBUTES == dwFileAttributes)  
199     {  
200         return false;  
201     }
202 
203     if (!(dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
204     {
205         return false;
206     }
207 
208     //方法2
209     //if(0 != _taccess(ptInPath, 0)) return false;
210     return true;
211 }
212 
213 //获取父目录路径
214 bool GetParentPath(const TCHAR* ptInPath, TCHAR* pOutParentPath)
215 {
216     int iLen = 0;    
217     TCHAR* ptTemp = NULL;        
218     TCHAR tszPath[MAX_PATH] = {0};        //当前路径 子目录
219     _tcscpy_s(tszPath, ptInPath);         //存放要创建的目录字符串
220 
221     //检查参数是否正确
222     if (!tszPath || _tcsclen(tszPath)<4)
223         return false;
224 
225     //在这里去掉尾部为'\\'的字符
226     if (_T('\\') == tszPath[_tcsclen(tszPath)-1])
227     {
228         tszPath[_tcsclen(tszPath)-1] = 0;
229     }
230 
231     ptTemp = _tcsrchr(tszPath, _T('\\'));  //从尾部查找字符 取得子目录名(不包括路径)
232     if (!ptTemp)
233     {
234         return false;
235     }
236     iLen = _tcsclen(ptTemp);
237     _tcsncpy_s(pOutParentPath, MAX_PATH, tszPath, _tcsclen(tszPath)-iLen); //得到父目录路径
238 
239     return true;
240 }
241 
242 bool ExtractFileName(const TCHAR* ptInPath, TCHAR* pOutFileName)
243 {
244     int iLen = 0;    
245     TCHAR* ptTemp = NULL;        
246     TCHAR tszPath[MAX_PATH] = {0};        //当前路径 子目录
247     _tcscpy_s(tszPath, ptInPath);         //存放要创建的目录字符串
248 
249     //检查参数是否正确
250     if (!tszPath || _tcsclen(tszPath)<4)
251         return false;
252 
253     //在这里去掉尾部为'\\'的字符
254     if (_T('\\') == tszPath[_tcsclen(tszPath)-1])
255     {
256         tszPath[_tcsclen(tszPath)-1] = 0;
257     }
258 
259     ptTemp = _tcsrchr(tszPath, _T('\\'));
260     if (!ptTemp)
261     {
262         return false;
263     }
264     //ptTemp = _tcschr(tszPath, _T('\\'));  //返回tszPath中的第一个字符'\\'的位置开始的字符串的指针,如果没有发现返回NULL
265     //iLen = _tcsclen(ptTemp);
266     _tcsncpy_s(pOutFileName, MAX_PATH, ptTemp+1, _tcsclen(ptTemp)-1); //得到父目录路径
267 
268     return true;
269 }
270 
271 //创建多级目录,成功返回true, 失败返回false
272 //const TCHAR* ptInPath 路径名, bool bIsFileName true 包括文件名的路径名 false 不包括文件名的路径名
273 bool CreateMultipleDirectory(const TCHAR* ptInPath, bool bIsFileName)
274 {
275     int iLen = 0;    
276     TCHAR* ptTemp = NULL;        
277     TCHAR tszPath[MAX_PATH] = {0};        //当前路径 子目录
278     TCHAR tszTemPath[MAX_PATH] = {0};     //父目录
279     _tcscpy_s(tszPath, ptInPath);         //存放要创建的目录字符串
280 
281     //取得不包括文件名的完整路径
282     if (bIsFileName)
283     {
284         if (!GetParentPath(ptInPath, tszPath)) return false;
285     }
286     else
287         _tcscpy_s(tszPath, ptInPath);
288 
289     //取得父路径
290     if (!GetParentPath(tszPath, tszTemPath)) return false;
291 
292     //检验父级路径是否存在          
293     if (CheckDirExist(tszTemPath))
294     {   //如果存在则检查子目录
295         if (CheckDirExist(tszPath)) return true;
296         if (!CreateDirectory(tszPath, NULL))
297         {    //创建文件夹失败
298             //::MessageBox(NULL, tszPath, _T("创建文件夹失败!!!!!"), MB_OK);
299             //TRACE("^&^! CreateDirectory 创建目录出错,Path:%s;Error Code:%d;!!!\r\n", tszPath, GetLastError());
300             return false;
301         }
302 
303         SetFileAttributes(tszPath, FILE_ATTRIBUTE_NORMAL);            
304     }    
305     else
306     {    //如果不存在则递归父级路径
307         if (!CreateMultipleDirectory(tszTemPath, false))    return false;
308 
309         //父目录创建完毕则继续创建子目录
310         if (!CreateMultipleDirectory(tszPath, false))    return false;                        
311     }
312     return true;
313 }

 



Themida/WinLicense V2.1.0.0 + -> Sign. By.soysuace[clg] *
Themida/WinLicense V2.1.0.0 + -> Sign. By.soysuace[clg] *

UPX 2.93 - 3.00 [LZMA] -> Markus Oberhumer, Laszlo Molnar & John Reiser *

0018F43C   002E64D8  ASCII "363506"

0018F428   02201218  ASCII E8,"G"

 

posted on 2014-12-30 16:22  irc  阅读(334)  评论(0)    收藏  举报

Top