Atitit. 注冊表操作查詢 修改 api與工具總結 java c# php js python 病毒木馬的原理
這個cli工具接口有,優先使用,jreg的要調用dll了,麻煩的..
Jreg的要調用dll了,麻煩
作者:: ★(attilax)>>> 綽號:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿爾 拉帕努伊 ) 漢字名:艾龍, EMAIL:[email protected]
轉載請注明來源: http://www.cnblogs.com/attilax/
D:\>reg query hklm\software\TTT
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\software\TTT
Name REG_SZ TTT BLOG
EMail REG_SZ [email protected]
URL REG_SZ http://www.taoyoyo.net/ttt/
Type REG_DWORD 0x2
2,查詢特定項
D:\>reg query hklm\software\ttt /v url
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\software\ttt
url REG_SZ http://www.taoyoyo.net/ttt/
這裡最難的是如何取得我們想要的字符串呢,困惑了好長時間,終於找到方法了。
原來也沒有別的好辦法,只能用find,for循環來截取我們需要的內容。(下面的例子如果看不懂,請參考本博客另外的文章:DOS循環-bat/批處理for命令詳解之二)
例如我們要得到url的鍵值: http://www.taoyoyo.net/ttt/,可以用以下腳本:
復制代碼 代碼如下:
@ECHO OFF
for /f "tokens=1,2,3,4,*" %%i in ('reg query "HKEY_LOCAL_MACHINE\software\ttt" ^| find /i "URL"') do SET "pURL=%%k"
echo TTT BLOG的URL值為:%pURL%
package aaaAddr;
import java.util.List;
import java.util.Map;
import jdk.nashorn.internal.ir.Terminal;
import com.attilax.json.AtiJson;
import com.attilax.lang.YamlAtiX;
import com.attilax.lang.text.strUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.registry.RegistryKey;
import com.registry.RegistryValue;
/** aaaAddr.SysServiceUtil.getList
* @author [email protected]
*/
public class SysServiceUtil {
// "HKEY_LOCAL_MACHINE"
public static final RegistryKey LOCALMACHINE = RegistryKey
.getRootKeyForIndex(RegistryKey.HKEY_LOCAL_MACHINE_INDEX);
// "HKEY_LOCAL_MACHINESystemCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp"
public static final RegistryKey rdpKey = null;
// = new RegistryKey(LOCALMACHINE,
// "\System\CurrentControlSet\Control\Terminal
// Server\WinStations\RDP-Tcp\");
/**
* 獲得 windows server 中的 terminal server 的端口 也就是遠程桌面服務的端口
*
* @return
*/
public static long getTerminalServerPort() {
long port = -1;
if (rdpKey.hasValues()) {
RegistryValue portNumber = rdpKey.getValue("PortNumber");
System.out.println(portNumber.toString()); // Name: PortNumber Type:
// REG_DWORD Value: 3389
String value = portNumber.toString();
port = Long.valueOf(value.substring(value.lastIndexOf(": ") + 2));
System.out.println("port: " + port);
}
return port;
}
public static void main(String[] args) {
SysServiceUtil sysx = new SysServiceUtil();
List li = sysx.getList();
System.out.println(AtiJson.gson(li));
}
/**
* attilax 2016年4月12日 下午2:35:10
*
* @return
*/
@SuppressWarnings("all")
public List getList() {
// getTerminalServerPort();
String roottype = "1:man,2:auto,3:manType3,4:disable";
Map roottype_m = YamlAtiX.getMap_fromTxt(roottype);
RegistryKey k = new RegistryKey(LOCALMACHINE,
"SYSTEM\\CurrentControlSet\\services");
//todox drektly use fullpath se ,get retu is empty in get subkey..zihao use jeig locamacie var mode..
// System.out.println( AtiJson.toJson(k));
/*
*
* { "hKey": -2147483647, "name": "services", "path":
* "HKEY_CURRENT_USER\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet",
* "handles": [], "created": false, "level": 4, "lastError": 0,
* "view64": 256 }
*/
// k.g
List<RegistryKey> li = k.getSubKeys();
// k.getSubKeys(".NETFramework")
// k.getSubKeyNames()
// k.getNumberOfSubKeys()
System.out.println(li.size());
List<Map> li_r = Lists.newLinkedList();
int i = 0;
for (RegistryKey registryKey : li) {
try {
i++;
System.out.println(i);
// System.out.println( AtiJson.toJson(registryKey));
System.out.println(registryKey.getName());
if (registryKey.getName().equals("AcpiPmi"))
System.out.println("dbg");
Map m = Maps.newLinkedHashMap();
if (registryKey.getValue("Description") != null) {
RegistryValue v = registryKey.getValue("Description");
byte[] byteData = v.getByteData();
// Object s = strUtil.from_wz_encode( byteData,"gbk");
Object s = strUtil.from_wz_encode(byteData,
"UnicodeLittleUnmarked");
m.put("Description", s);
}
m.put("name", registryKey.getName());
if (registryKey.getValue("DisplayName") != null) {
RegistryValue v = registryKey.getValue("DisplayName");
// v.getName() ==DisplayName
// v.toString()
byte[] byteData = v.getByteData();
Object s = strUtil.from_wz_encode(byteData,
"UnicodeLittleUnmarked");
m.put("DisplayName", s);
}
if (registryKey.getValue("ImagePath") != null)
m.put("ImagePath", strUtil.from_wz_encode(registryKey
.getValue("ImagePath").getByteData(),
"UnicodeLittleUnmarked"));
m.put("Start", getReg_dword(registryKey.getValue("Start") ));
if(m.get("Start")!=null)
m.put("StartTxt", roottype_m.get(m.get("Start")));
// //if DelayedAutostart=1 and auto ,then auto delaye start
m.put("DelayedAutostart",getReg_dword(registryKey.getValue("DelayedAutostart") ));
li_r.add(m);
} catch (Exception e) {
e.printStackTrace();
}
//
}
System.out.println("--ok");
return li_r;
}
/**
attilax 2016年4月12日 下午4:59:53
* @param string
* @return
*/
private Object getReg_dword(RegistryValue regVal) {
if (regVal != null) {
byte[] a=regVal
.getByteData();
return strUtil.from(a[0]);
}
return regVal;
}
}
批處理操作注冊表完全攻略(讀取注冊表-寫入注冊表等)_DOS-BAT_.htm