‘壹’ 如何在centos6.5的kvm虚拟机中永久激活windows2008
一、激活原理
目前激活Windows7/Windows2008的各种方法充斥互联网,但公认比较完美的激活方式是将品牌机(例如DELL、LENOVO等)的SLIC信息表刷写进需要安装Windows系统的计算机BIOS中,将该计算机“仿真”为品牌机,然后安装微软的OEM版Windows7/Windows2008并自动激活。
相信喜欢搞破解的童鞋都应该知道其中的奥秘,微软和PC厂商为了减轻对于操作系统的激活负荷,对大多数品牌机实行了有别于联网激活的“SLIC激活机制”:当Windows操作系统启动时,就会自行读取本机BIOS中的SLIC信息表,以及操作系统的“OEM密钥”和“OEM证书”,如果三者完全吻合、验证一致,Windows7/Windows2008系统就会被识别为自动激活的OEM版本。
笔者研究发现,Windows2012(注意不是Windows2012_R2,下同)与以往激活Windows7/Windows2008的方式类似,依然可以采用刷写BIOS中SLIC信息表安装OEM版系统的方式实现永久激活,只不过激活Windows2012需要SLIC2.2版,经测试SLIC2.2能够向下兼容SLIC2.1/2.0。
众所周知,虚拟机软件也是有BIOS的,目前市场上常见的虚拟机软件,如VMware、Xen、Kvm等均通过软件仿真的方式“模拟”硬件BIOS。既然可以采用刷写计算机硬件BIOS的方式实现永久激活,那么如果能够将SLIC2.2信息表通过软件再编译方式“灌入”虚拟机的BIOS中,然后再安装Windows2012的OEM版本,不就可以与刷写BIOS硬件实现自动激活“异曲同工”了吗?
二、核心问题
激活原理已经非常明确了,现在的关键问题是如何重新编译Linux虚拟机的问题了,这涉及Linux内核的重新编译,一些菜鸟可能望而生畏,尽管编译 Linux全部内核确实需要较高的技术水平,但重新编译Linux的BIOS难度并不高,初学者也可以轻松实现。本文以Linux的常见版本CentOs6.5为例,详细讲解重新编译KVM虚拟机BIOS的步骤。本文的方法同样适用Ubuntu等 Linux版本。
CentOs6.5虚拟机KVM的BIOS实际是一个二进制的可执行文件,默认安装路径为/usr/share/seabios/bios.bin。笔者研究发现,KVM虚拟机BIOS使用的是开源软件 seabios,该软件的源代码可以在互联网上找到,开源组织也制作了为seabios软件增加相应SLIC信息表的补丁包,下载seabios的源代码并打上该补丁包,然后重新编译并替换Linux默认的bios.bin文件,就可以将虚拟机“仿真”为品牌机,然后自动激活OEM版的Windows2012系统了,这种激活方式是永久激活,激活后的Windows2012可以打上微软的后续补丁且绝对不会被封杀。
三、详细步骤
1.获取SLIC2.2信息表。当前SLIC2.1的信息表网上很容易找到,SLIC2.2的信息表不多,比较容易找到的是DELL 版的SLIC2.2信息表。当然也可以找一台预装了Windows2012的品牌机(市面上比较常见的是DELL的机器),然后使用SLIC_Toolkit3.2工具导出该机器的SLIC表。SLIC2.1/2.2表为二进制文件,长度均为374字节(这一点一定要注意)。
2.安装CentOs6.5_x64版操作系统。记得把gcc安装上,然后将上一步已经获取的SLIC2.2表拷贝在/ opt目录中(假定文件名称为DELL_SLIC2.2.BIN)。
3.在root用户下安装git,、iasl及所有依赖包。
#yum install git
#yum install iasl //这是必须安装的包
4.使用git获取sealic项目的源码。
# mkdir bios //目录可以自己随便建
#cd bios
#git clone git://github.com/ghuntley/seaslic //获取源代码
#ls -ls
Seaslic //用git软件获取源代码后会有多出一个目录
# cd seaslic
#ls
patch.sh README.markdown seabios.patch seabios.submole
//该目录共包含三个文件和一个子目录,其中子目录seabios.submole需要删除掉,用我们后面下载的内容重建。
#rm -rf seabios.submole
5.从地址code.coreboot.org/p/seabios下载的SeaBios的源码并解压。注意源代码一定要下载1.7.3.2版本的,这一点也很关键,千万不能搞错了。
#tar xzvf seabios-1.7.3.2.tar.gz 解压在/bios目录下。
6.重建seabios.submole
#cd /bios
# cp –r seabios-1.7.3.2 seaslic/seabios.submole
# cd seaslic
# ls
patch.sh README.markdown seabios.patch seabios.submole
进入我们重建的seabios.submole目录,可以发现有bios的源代码存在:
# cd seabios.submole
# ls
COPYING COPYING.LESSER Makefile README README.CSM src TODO tools vgasrc
# cd src
可以发现seabios的源代码,我们需要重新编译这些源代码,生成新的bios.bin 文件,用于替代CentOs6.5系统自带的bios.bin。
7.查看/bios/seaslic /patch.sh文件。这是一个批处理文件,只有2行有用。用Linux的命令方式执行,为防止输入错误,最好从patch.sh中复制粘贴后在root用户下执行:
①将SLIC2.2文件转换为C语言包含文件格式(acpi-slic.hex)的命令:
#xxd -i /opt/DELL_SLIC2.2.BIN | grep -v -E "len "| sed 's/unsigned char.*/static char SLIC[] = {/' > seabios.submole/src/acpi-slic.hex
说明:这条命令执行后将会把SLIC2.2表(即/opt/DELL_SLIC2.2.BIN文件)转换为C语言包含文件格式(文件名../src/acpi-slic.hex),并以数组形式存在。这一步非常非常关键,转换完成的acpi-slic.hex文件应为2333字节。如果本条命令执行不成功的话,编译出来的bios.bin文件不会包含SLIC2.2信息,也就无法实现激活了。
②为acpi.c 文件打补丁的命令:
# cd /bios/seaslic /seabios.submole
#patch -p1 < ../seabios.patch
说明:这条语句执行后将给../ src/acpi.c 文件打上补丁,执行后系统将会提示:
Hunk #1 succeeded at 20 with fuzz 2 (offset -194 lines).
Hunk #2 succeeded at 37 with fuzz 2 (offset -194 lines).
Hunk #3 succeeded at 631 with fuzz 2 (offset -205 lines).
注意:至此我们的准备工作已经全部完成了,下面将重新编译生成新的bios了。
8.重新编译生成bios.bin文件
# cd /bios/seaslic /seabios.submole
#make //编译需要花几十秒钟吧,应提示无错误、无警告,否则可能需要仔细检查以上步骤。
查看..seabios.submole/out/bios.bin
看到最后生成的结果了吧,会在..seabios.submole/out/中多出一个bios.bin文件,这个文件就是我们重新编译生成的虚拟机的bios,将用来替换KVM的系统原有的bios.bin文件。
说明:这里编译生成bios.bin文件包含有DELL品牌机的SLIC2.2,可以激活DELL的Windows2012_OEM版。同理,我们只要找到其他品牌机的SLIC2.2信息表,重新编译后就可以安装激活其他品牌机的OEM版Windows7/2008/2012(SLIC2.1只能支持Vista/Win7/2008,不支持 Win2012;SLIC2.2则支持XP/Vista以及Win2008/2012并兼容SLIC2.1),与刷写计算机硬件BIOS实现自动激活的方式相比,采用这种方式激活Windows的风险为零,非常适合批量激活虚拟机的Windows2008/Windows2012。
9.替换CentOs6.5系统默认的bios.bin文件
# cp out/bios.bin /usr/share/seabios/bios.bin
#reboot //重新启动一下宿主机,然后再重新启动Windows虚拟机,在启动KVM虚拟机的时候,可以发现虚拟机的bios 已经更新为最新版本了。
10.激活windows2012
至此KVM虚拟机的bios已经重新配置完成,在KVM中启动WINDOWS客户机,然后利用SLIC_Toolkit3.2工具检查SLIC,会发现你的SLIC信息已经获取成功,如果你安装的是OEM版本的 Win2008/2012的话,无需输入key和证书就能自动激活。你可以从网上网络如下OEM镜像(我已试验过可自动激活):
(1)Lenovo的OEM版Windows2008_R2镜像:
Windows_Server-2008_R2_ENT_OEM.iso或者
Win_Server_08_R2_SP1_33in1.iso
(2)Dell的OEM版Windows2012镜像:
Ser2012_ST_DA_OEM.iso
(3)如果你手上暂时没有OEM版的话,也不要紧,可以用slmgr命令手工增加证书及OEM序列号也可以激活Windows2008/20012。直接用管理员身份进入命令行模式:
①slmgr -ilc DELL2.2.XRM-MS //这里找到的是DELL计算机的Windows2012版OEM证书。
②接下来就是写入注册号了:
slmgr -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
说明:下面是我从网上找到的 OEM版序列号(经测试可以激活):
Windows Server 2012 Standard DELL OEM KEY
2G9DG-XKFR6-VG8D3-DN9T9-CDG98
Windows Server 2012 Datacenter DELL OEM KEY
2BVGY-TNRWK-6927W-866R9-66J3H
Windows Server 2008 R2 Standard DELL OEM KEY
D7TCH-6P8JP-KRG4P-VJKYY-P9GFF
Windows Server 2008 R2 Enterprise DELL OEM KEY
BKCJJ-J6G9Y-4P7YF-8D4J7-7TCWD
③执行slmgr –dlv //显示全部激活信息
④执行slmgr -xpr //显示Windows2008/2012已经永久激活。
‘贰’ 如何实现android蓝牙自动配对连接
望你踩呐我的回答
下面是自动配对的代码
Mainfest,xml注册
<receiver android:name="." >
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
</intent-filter>
</receiver>
自己在收到广播时处理并将预先输入的密码设置进去
public class extends BroadcastReceiver
{
String strPsw = "0";
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
if (intent.getAction().equals(
"android.bluetooth.device.action.PAIRING_REQUEST"))
{
BluetoothDevice btDevice = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// byte[] pinBytes = BluetoothDevice.convertPinToBytes("1234");
// device.setPin(pinBytes);
Log.i("tag11111", "ddd");
try
{
ClsUtils.setPin(btDevice.getClass(), btDevice, strPsw); // 手机和蓝牙采集器配对
ClsUtils.createBond(btDevice.getClass(), btDevice);
ClsUtils.cancelPairingUserInput(btDevice.getClass(), btDevice);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
<b>/************************************ 蓝牙配对函数 * **************/
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import android.bluetooth.BluetoothDevice;
import android.util.Log;
public class ClsUtils
{
/**
* 与设备配对 参考源码:platform/packages/apps/Settings.git
* /Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
*/
static public boolean createBond(Class btClass, BluetoothDevice btDevice)
throws Exception
{
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);
return returnValue.booleanValue();
}
/**
* 与设备解除配对 参考源码:platform/packages/apps/Settings.git
* /Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
*/
static public boolean removeBond(Class btClass, BluetoothDevice btDevice)
throws Exception
{
Method removeBondMethod = btClass.getMethod("removeBond");
Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice);
return returnValue.booleanValue();
}
static public boolean setPin(Class btClass, BluetoothDevice btDevice,
String str) throws Exception
{
try
{
Method removeBondMethod = btClass.getDeclaredMethod("setPin",
new Class[]
{byte[].class});
Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice,
new Object[]
{str.getBytes()});
Log.e("returnValue", "" + returnValue);
}
catch (SecurityException e)
{
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
// 取消用户输入
static public boolean cancelPairingUserInput(Class btClass,
BluetoothDevice device)
throws Exception
{
Method createBondMethod = btClass.getMethod("cancelPairingUserInput");
// cancelBondProcess()
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}
// 取消配对
static public boolean cancelBondProcess(Class btClass,
BluetoothDevice device)
throws Exception
{
Method createBondMethod = btClass.getMethod("cancelBondProcess");
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}
/**
*
* @param clsShow
*/
static public void printAllInform(Class clsShow)
{
try
{
// 取得所有方法
Method[] hideMethod = clsShow.getMethods();
int i = 0;
for (; i < hideMethod.length; i++)
{
Log.e("method name", hideMethod[i].getName() + ";and the i is:"
+ i);
}
// 取得所有常量
Field[] allFields = clsShow.getFields();
for (i = 0; i < allFields.length; i++)
{
Log.e("Field name", allFields[i].getName());
}
}
catch (SecurityException e)
{
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}</b>
执行时直接使用:
<b>public static boolean pair(String strAddr, String strPsw)
{
boolean result = false;
BluetoothAdapter bluetoothAdapter = BluetoothAdapter
.getDefaultAdapter();
bluetoothAdapter.cancelDiscovery();
if (!bluetoothAdapter.isEnabled())
{
bluetoothAdapter.enable();
}
if (!BluetoothAdapter.checkBluetoothAddress(strAddr))
{ // 检查蓝牙地址是否有效
Log.d("mylog", "devAdd un effient!");
}
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(strAddr);
if (device.getBondState() != BluetoothDevice.BOND_BONDED)
{
try
{
Log.d("mylog", "NOT BOND_BONDED");
ClsUtils.setPin(device.getClass(), device, strPsw); // 手机和蓝牙采集器配对
ClsUtils.createBond(device.getClass(), device);
remoteDevice = device; // 配对完毕就把这个设备对象传给全局的remoteDevice
result = true;
}
catch (Exception e)
{
// TODO Auto-generated catch block
Log.d("mylog", "setPiN failed!");
e.printStackTrace();
} //
}
else
{
Log.d("mylog", "HAS BOND_BONDED");
try
{
ClsUtils.createBond(device.getClass(), device);
ClsUtils.setPin(device.getClass(), device, strPsw); // 手机和蓝牙采集器配对
ClsUtils.createBond(device.getClass(), device);
remoteDevice = device; // 如果绑定成功,就直接把这个设备对象传给全局的remoteDevice
result = true;
}
catch (Exception e)
{
// TODO Auto-generated catch block
Log.d("mylog", "setPiN failed!");
e.printStackTrace();
}
}
return result;
}</b>
‘叁’ 严重: Servlet.service() for servlet jsp threw exception
出现此错误一般都是在jsp中使用了输出流(如输出图片验证码,文件下载等),
没有妥善处理好的原因。
具体的原因就是
在tomcat中jsp编译成servlet之后在函数_jspService(HttpServletRequest request, HttpServletResponse response)的最后
有一段这样的代码
finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
}
这里是在释放在jsp中使用的对象,会调用response.getWriter(),因为这个方法是和
response.getOutputStream()相冲突的!所以会出现以上这个异常。
然后当然是要提出解决的办法,其实挺简单的(并不是和某些朋友说的那样--
将jsp内的所有空格和回车符号所有都删除掉),
在使用完输出流以后调用以下两行代码即可:
out.clear();
out = pageContext.pushBody();
最后这里是一个输出彩色验证码例子(这样的例子几乎随处可见)
imag.jsp
<%@ page import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%@ page import="java.io.OutputStream" %>
<%!
Color getRandColor(int fc,int bc){
Random random = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
%>
<%
try{
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
OutputStream os=response.getOutputStream();
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.setColor(getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}
String sRand="";
for (int j=0;j<4;j++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(rand,13*j+6,16);
}
session.setAttribute("rand",sRand);
g.dispose();
ImageIO.write(image, "JPEG",os);
os.flush();
os.close();
os=null;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
catch(IllegalStateException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}%>
如有不足之处,欢迎斧正!
2
getOutputStream() has already been called for this response问题的解决
在jsp向页面输出图片的时候,使用response.getOutputStream()会有这样的提示:java.lang.IllegalStateException:getOutputStream() has already been called for this response,会抛出Exception
原因一:
JSP默认的输出流为PrintWriter ,即<% %>以外的东西所默认的输出方式,如果你尝试在JSP中使用ServletOutputStream就会引起错误.要嘛直接改用Servlet输出(复写service方法),要嘛删除除%><%中的任何东西
(包括HTML标签,空格,回车等东西)应该就可以。
对于这样的情况应该这样来解决,删除%><%之间的所有内容包括空格和换行符,最后也要消除空格和换行符,
最好再加上一句response.reset()。
原因二:
在J2EE的API参考里有这么个:
ServletResponse的getWriter()方法里会抛出这个异常,
IllegalStateException - if the getOutputStream method has already been called
for this response object
而它的getOutputStream()方法里会抛出这个异常.
IllegalStateException - if the getOutputStream method has already been called for this response object
并且两者的函数申明里都有这么样的一句
Either this method or getOutputStream() may be called to write the body, not both.
Either this method or getWriter() may be called to write the body, not both.
以上说明也解释了为什么在往页面中写入图片的时候要使用如下循环格式
OutputStream output=response.getOutputStream();
while((len=in.read(b)) >0)
{
output.write(b,0,len);
}
output.flush();
而不是把response.getOutputStream().write()放到循环体内
在页面中直接写:
<body bgcolor="#ffffff">
<h1>
<%
response.getOutputStream();
%>
</h1>
</body>
将会出现错误消息如下:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.catalina.connector.Response.getWriter(Response.java:604)
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)