• AWE需要为Windows group/user加一个"SE_LOCK_MEMROY"的privilege,该死的vista home edition居然没有!真的是欺负我们这些没钱买正版的老实人,伤心之余决定写个工具来配置

选择1:Gpedit的IGroupPolicyObject来编辑,可惜MSDN的东西太省略了,程序写了一半[p->getReg….],忽然发现下面不晓得郎格用Com的接口了[PS:我看到网上有人在问,为什么Gpedit实例化出错,一个原因某牛已经说过了[头文件的一个宏要补上,编译选项吧],另一个原因MSDN上说得很清楚,这个COM是一个单线程套间,所以,你晓得郎格做了萨!]可惜了,如果用这个,那就爽了[PS:这个针对AD的选项确实有问题,那是由于Vista Home版本的问题,与编程接口无关]

选择2:这条路是光明大道,LSA编程,LSA API威力强大,如果Lsass的代理对象你都能抓住,那还有什么不能做到的!具体编程细节就不说了,可以去查MSDN LSA相关部分,如果要做这个,最好对安全呀,令牌呀,特权呀,还有什么imperation之类有个概念,不然被别人黑了不关我的事情哈!为了练习下P/Invoke编程,本菜决定写个WinForm来补上Vista Home Edition的这点缺陷!

顺便提下,其实这样做完全没有必要[如果你只是想让AWE跑起来的话],可以直接用ShellExecuteEx提升权限,管理员当然强大的多哟。当然做一个工具的目的,主要是扫下那些特权,主要是比较危险的几个特权,看有没有赋予什么不安全账户。主要的API有:LSAopenpolicy, LSAEnumarateion….,[太多了]

  • 早上把上次给简他们的程序看料下,想起原来第一次看COM和ATL的时候,现在回头来看,当初真的没懂2成也!当然在.Net里面调用COM已经有CCW,RCW来封装帮我们做了[下层的tlbix***.exe],也可以用API来实现。但有的时候COM默认封装会有问题,我估计是DISPID的查找过程出错,上次那个问题,别人在。Net的实现里面就是直接用dispid绑定的,叹气!看来没有idl文件有的时候出了问题也不晓得怎么解决也!
  • 最后发现L-GAME已经让我有心理阴影了,还是切道菜题吧!不过好像这道题目又太菜了,一次就过了!俄,明天多做几道吧,今天被COM搞郁闷了!其实今天一直想问彭代毅,如果只给你一个Dll,我怎么来导出他的idl呢?似乎没什么办法,本菜流口水惭愧中!

那道菜题:[PS:我没有按字典排序的,懒得排了,没提起做题的兴趣]

Problem A – Bandwidth

Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and an ordering on the elements in V, then the bandwidth of a node v is defined as the maximum distance in the ordering between v and any node to which it is connected in the graph. The bandwidth of the ordering is then defined as the maximum of the individual bandwidths.

Write a program that will find the ordering of a graph that minimises the bandwidth.

Input will consist of a series of graphs. Each graph will appear on a line by itself. The entire file will be terminated by a line consisting of a single #. For each graph, the input will consist of a series of records separated by ‘;’. Each record will consist of a node name (a single upper case character in the the range ‘A’ to ‘Z’), followed by a ‘:’ and at least one of its neighbours. The graph will contain no more than 8 nodes.

Output will consist of one line for each graph, listing the ordering of the nodes followed by an arrow (->) and the bandwidth for that ordering. All items must be separated from their neighbours by exactly one space. If more than one ordering produces the same bandwidth, then choose the smallest in lexicographic ordering, that is the one that would appear first in an alphabetic listing.

Sample input
A:FB;B:GC;D:GC;F:AGH;E:HD
#
Sample output
A B C F G D H E -> 3
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
const int MAXCH=26;
char Arc[MAXCH][MAXCH], Clist[MAXCH], Best[MAXCH];
int Ind[MAXCH], Count[MAXCH], bestS, size;//current index for char
//reset
inline void init(){
    memset((void*)&Arc[0][0], 0, MAXCH*MAXCH);
    memset((void*)Clist, 0, MAXCH);
    memset((void*)Best, 0, MAXCH);
    memset((void*)Ind, 0xff, MAXCH*sizeof(int));
    memset((void*)Count, 0, MAXCH*sizeof(int));
    bestS=INT_MAX,size=0;
}
void backtrack(int depth, int maxlen);
//implemenation
void backtrack(int depth, int maxlen){
    if(depth==size){//last item
        if(maxlen<bestS){
            bestS=maxlen;
            memcpy((void*)Best, (void*)Clist, size);
        }
        return;
    }
    //cut-off branches
    for(int i=depth; i<size; i++){
        if(i!=depth){
            Clist[i]^=Clist[depth], Clist[depth]^=Clist[i], Clist[i]^=Clist[depth];
            Ind[i]^=Ind[depth], Ind[depth]^=Ind[i], Ind[i]^=Ind[depth];
        }
        //[0,depth-1] vs depth
        int clen=INT_MIN, total=0;
        for(int i=0; i<depth; i++){//Clist[i] vs Clist[depth]
            if(Arc[Clist[i]-'A'][Clist[depth]-'A']!=0){
                int temp=abs(Ind[Clist[i]-'A']-Ind[Clist[depth]-'A']);
                if(temp>clen) clen=temp;
                total++;
            }
        }
        //cut-off branches
        if(clen<bestS&&Count[depth]-total<bestS){
            if(clen>maxlen)
                backtrack(depth+1, clen);
            else backtrack(depth+1, maxlen);
        }
        //recovery
        if(i!=depth){
            Clist[i]^=Clist[depth], Clist[depth]^=Clist[i], Clist[i]^=Clist[depth];
            Ind[i]^=Ind[depth], Ind[depth]^=Ind[i], Ind[i]^=Ind[depth];
        }
    }
}
#define fbase
int main()
{
    #ifdef fbase
    ifstream in("input.txt");
    if(!in) return EXIT_FAILURE;
    cin.rdbuf(in.rdbuf());
    #endif
    //implementation
    char c,pre=NULL;
    init();
    while((c=cin.get())!=EOF){
        if(c=='\n'||c=='#'){
            //calculate
            if(size>0){
                backtrack(0, INT_MIN);
                for(int i=0; i<size; i++) cout<<Best[i]<<" ";
                cout<<" -> "<<bestS<<endl;
                //reset
                pre=NULL;
                init();
            }
        }
        if(c==':') continue;
        if(c==';') pre=NULL;
        if(c>'A'-1&&c<'Z'+1){
            if(!pre){
                pre=c;
                if(Ind[c-'A']==-1)//not exists
                    Clist[size++]=c,Ind[c-'A']=size-1;//insert sorting,字典序要在这里改
            }
            else{//pre exists
                Arc[c-'A'][pre-'A']=Arc[pre-'A'][c-'A']=1,Count[pre-'A']++,Count[c-'A']++;
                if(Ind[c-'A']==-1)
                    Clist[size++]=c,Ind[c-'A']=size-1;//insert sorting,字典序要在这里改

            }
        }
    }
    #ifdef fbase
    in.close();
    #endif
    return 0;
}
#undef fbase

Advertisements